[ci] format
This commit is contained in:
parent
4299ab303b
commit
1e3550d5ac
4 changed files with 19 additions and 17 deletions
|
@ -67,7 +67,7 @@ export interface AstroGlobalPartial {
|
||||||
/** @deprecated Use `Astro.glob()` instead. */
|
/** @deprecated Use `Astro.glob()` instead. */
|
||||||
fetchContent(globStr: string): Promise<any[]>;
|
fetchContent(globStr: string): Promise<any[]>;
|
||||||
glob(globStr: `${any}.astro`): Promise<ComponentInstance[]>;
|
glob(globStr: `${any}.astro`): Promise<ComponentInstance[]>;
|
||||||
glob<T extends Record<string, any>>(globStr: `${any}.md`): Promise<MarkdownInstance<T>[]>;
|
glob<T extends Record<string, any>>(globStr: `${any}.md`): Promise<MarkdownInstance<T>[]>;
|
||||||
glob<T extends Record<string, any>>(globStr: string): Promise<T[]>;
|
glob<T extends Record<string, any>>(globStr: string): Promise<T[]>;
|
||||||
site: URL;
|
site: URL;
|
||||||
}
|
}
|
||||||
|
@ -517,7 +517,7 @@ export interface MarkdownInstance<T extends Record<string, any>> {
|
||||||
file: string;
|
file: string;
|
||||||
url: string | undefined;
|
url: string | undefined;
|
||||||
Content: AstroComponentFactory;
|
Content: AstroComponentFactory;
|
||||||
getHeaders(): Promise<{ depth: number, slug: string, text: string }[]>;
|
getHeaders(): Promise<{ depth: number; slug: string; text: string }[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: string | null) => void>;
|
export type GetHydrateCallback = () => Promise<(element: Element, innerHTML: string | null) => void>;
|
||||||
|
|
|
@ -291,7 +291,7 @@ function createAstroGlobFn() {
|
||||||
throw new Error(`Astro.glob(${JSON.stringify(globValue())}) - no matches found.`);
|
throw new Error(`Astro.glob(${JSON.stringify(globValue())}) - no matches found.`);
|
||||||
}
|
}
|
||||||
// Map over the `import()` promises, calling to load them.
|
// Map over the `import()` promises, calling to load them.
|
||||||
return Promise.all(allEntries.map(fn => fn()));
|
return Promise.all(allEntries.map((fn) => fn()));
|
||||||
};
|
};
|
||||||
// Cast the return type because the argument that the user sees (string) is different from the argument
|
// Cast the return type because the argument that the user sees (string) is different from the argument
|
||||||
// that the runtime sees post-compiler (Record<string, Module>).
|
// that the runtime sees post-compiler (Record<string, Module>).
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { parse as babelParser } from '@babel/parser';
|
import { parse as babelParser } from '@babel/parser';
|
||||||
import type { ArrowFunctionExpressionKind, CallExpressionKind, StringLiteralKind } from 'ast-types/gen/kinds';
|
import type { ArrowFunctionExpressionKind, CallExpressionKind, StringLiteralKind } from 'ast-types/gen/kinds';
|
||||||
import type { NodePath } from 'ast-types/lib/node-path';
|
import type { NodePath } from 'ast-types/lib/node-path';
|
||||||
import { parse, print, types, visit } from "recast";
|
import { parse, print, types, visit } from 'recast';
|
||||||
import type { Plugin } from 'vite';
|
import type { Plugin } from 'vite';
|
||||||
import type { AstroConfig } from '../@types/astro';
|
import type { AstroConfig } from '../@types/astro';
|
||||||
|
|
||||||
|
@ -53,21 +53,23 @@ export default function astro({ config }: AstroPluginOptions): Plugin {
|
||||||
// Wrap the `Astro.glob()` argument with `import.meta.glob`.
|
// Wrap the `Astro.glob()` argument with `import.meta.glob`.
|
||||||
const argsPath = path.get('arguments', 0) as NodePath;
|
const argsPath = path.get('arguments', 0) as NodePath;
|
||||||
const args = argsPath.value;
|
const args = argsPath.value;
|
||||||
argsPath.replace({
|
argsPath.replace(
|
||||||
type: 'CallExpression',
|
{
|
||||||
callee: {
|
type: 'CallExpression',
|
||||||
type: 'MemberExpression',
|
callee: {
|
||||||
object: { type: 'MetaProperty', meta: { type: 'Identifier', name: 'import' }, property: { type: 'Identifier', name: 'meta' } },
|
type: 'MemberExpression',
|
||||||
property: { type: 'Identifier', name: 'glob' },
|
object: { type: 'MetaProperty', meta: { type: 'Identifier', name: 'import' }, property: { type: 'Identifier', name: 'meta' } },
|
||||||
computed: false,
|
property: { type: 'Identifier', name: 'glob' },
|
||||||
},
|
computed: false,
|
||||||
arguments: [args],
|
},
|
||||||
} as CallExpressionKind,
|
arguments: [args],
|
||||||
|
} as CallExpressionKind,
|
||||||
{
|
{
|
||||||
type: 'ArrowFunctionExpression',
|
type: 'ArrowFunctionExpression',
|
||||||
body: args,
|
body: args,
|
||||||
params: []
|
params: [],
|
||||||
} as ArrowFunctionExpressionKind);
|
} as ArrowFunctionExpressionKind
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -76,7 +76,7 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
|
||||||
},
|
},
|
||||||
async load(id) {
|
async load(id) {
|
||||||
// A markdown file has been imported via ESM!
|
// A markdown file has been imported via ESM!
|
||||||
// Return the file's JS representation, including all Markdown
|
// Return the file's JS representation, including all Markdown
|
||||||
// frontmatter and a deferred `import() of the compiled markdown content.
|
// frontmatter and a deferred `import() of the compiled markdown content.
|
||||||
if (id.startsWith(VIRTUAL_MODULE_ID)) {
|
if (id.startsWith(VIRTUAL_MODULE_ID)) {
|
||||||
const sitePathname = config.buildOptions.site ? new URL(config.buildOptions.site).pathname : '/';
|
const sitePathname = config.buildOptions.site ? new URL(config.buildOptions.site).pathname : '/';
|
||||||
|
|
Loading…
Reference in a new issue