astro 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client-base.d.ts +98 -11
- package/dist/@types/astro.d.ts +9 -6
- package/dist/cli/index.js +2 -0
- package/dist/core/add/index.js +6 -1
- package/dist/core/build/vite-plugin-css.js +0 -23
- package/dist/core/compile/compile.js +7 -23
- package/dist/core/config/config.js +3 -0
- package/dist/core/config/settings.js +2 -1
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +11 -2
- package/dist/core/create-vite.js +22 -84
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.js +3 -1
- package/dist/core/render/dev/index.js +0 -8
- package/dist/core/render/dev/vite.js +2 -1
- package/dist/core/render/util.d.ts +0 -5
- package/dist/core/render/util.js +1 -47
- package/dist/core/routing/manifest/create.js +6 -1
- package/dist/core/util.d.ts +10 -1
- package/dist/core/util.js +27 -0
- package/dist/jsx/babel.js +3 -17
- package/dist/runtime/server/index.d.ts +0 -2
- package/dist/runtime/server/index.js +0 -2
- package/dist/vite-plugin-astro-postprocess/index.js +3 -25
- package/dist/vite-plugin-jsx/index.js +2 -2
- package/dist/vite-plugin-markdown/index.js +3 -2
- package/dist/vite-plugin-markdown-legacy/index.js +5 -7
- package/package.json +4 -2
- package/dist/runtime/server/metadata.d.ts +0 -29
- package/dist/runtime/server/metadata.js +0 -66
package/client-base.d.ts
CHANGED
|
@@ -1,19 +1,106 @@
|
|
|
1
1
|
/// <reference path="./import-meta.d.ts" />
|
|
2
2
|
|
|
3
|
+
type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
|
|
4
|
+
interface ExportedMarkdownModuleEntities {
|
|
5
|
+
frontmatter: MD['frontmatter'];
|
|
6
|
+
file: MD['file'];
|
|
7
|
+
url: MD['url'];
|
|
8
|
+
getHeadings: MD['getHeadings'];
|
|
9
|
+
/** @deprecated Renamed to `getHeadings()` */
|
|
10
|
+
getHeaders: () => void;
|
|
11
|
+
Content: MD['Content'];
|
|
12
|
+
rawContent: MD['rawContent'];
|
|
13
|
+
compiledContent: MD['compiledContent'];
|
|
14
|
+
load: MD['default'];
|
|
15
|
+
}
|
|
16
|
+
|
|
3
17
|
declare module '*.md' {
|
|
4
|
-
|
|
18
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
19
|
+
export const {
|
|
20
|
+
frontmatter,
|
|
21
|
+
file,
|
|
22
|
+
url,
|
|
23
|
+
getHeadings,
|
|
24
|
+
getHeaders,
|
|
25
|
+
Content,
|
|
26
|
+
rawContent,
|
|
27
|
+
compiledContent,
|
|
28
|
+
}: ExportedMarkdownModuleEntities;
|
|
29
|
+
export default load;
|
|
30
|
+
}
|
|
5
31
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
32
|
+
declare module '*.markdown' {
|
|
33
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
34
|
+
export const {
|
|
35
|
+
frontmatter,
|
|
36
|
+
file,
|
|
37
|
+
url,
|
|
38
|
+
getHeadings,
|
|
39
|
+
getHeaders,
|
|
40
|
+
Content,
|
|
41
|
+
rawContent,
|
|
42
|
+
compiledContent,
|
|
43
|
+
}: ExportedMarkdownModuleEntities;
|
|
44
|
+
export default load;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare module '*.mkdn' {
|
|
48
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
49
|
+
export const {
|
|
50
|
+
frontmatter,
|
|
51
|
+
file,
|
|
52
|
+
url,
|
|
53
|
+
getHeadings,
|
|
54
|
+
getHeaders,
|
|
55
|
+
Content,
|
|
56
|
+
rawContent,
|
|
57
|
+
compiledContent,
|
|
58
|
+
}: ExportedMarkdownModuleEntities;
|
|
59
|
+
export default load;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare module '*.mkd' {
|
|
63
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
64
|
+
export const {
|
|
65
|
+
frontmatter,
|
|
66
|
+
file,
|
|
67
|
+
url,
|
|
68
|
+
getHeadings,
|
|
69
|
+
getHeaders,
|
|
70
|
+
Content,
|
|
71
|
+
rawContent,
|
|
72
|
+
compiledContent,
|
|
73
|
+
}: ExportedMarkdownModuleEntities;
|
|
74
|
+
export default load;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare module '*.mdwn' {
|
|
78
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
79
|
+
export const {
|
|
80
|
+
frontmatter,
|
|
81
|
+
file,
|
|
82
|
+
url,
|
|
83
|
+
getHeadings,
|
|
84
|
+
getHeaders,
|
|
85
|
+
Content,
|
|
86
|
+
rawContent,
|
|
87
|
+
compiledContent,
|
|
88
|
+
}: ExportedMarkdownModuleEntities;
|
|
89
|
+
export default load;
|
|
90
|
+
}
|
|
15
91
|
|
|
16
|
-
|
|
92
|
+
declare module '*.mdown' {
|
|
93
|
+
const { load }: ExportedMarkdownModuleEntities;
|
|
94
|
+
export const {
|
|
95
|
+
frontmatter,
|
|
96
|
+
file,
|
|
97
|
+
url,
|
|
98
|
+
getHeadings,
|
|
99
|
+
getHeaders,
|
|
100
|
+
Content,
|
|
101
|
+
rawContent,
|
|
102
|
+
compiledContent,
|
|
103
|
+
}: ExportedMarkdownModuleEntities;
|
|
17
104
|
export default load;
|
|
18
105
|
}
|
|
19
106
|
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ import type { SerializedSSRManifest } from '../core/app/types';
|
|
|
10
10
|
import type { PageBuildData } from '../core/build/types';
|
|
11
11
|
import type { AstroConfigSchema } from '../core/config';
|
|
12
12
|
import type { AstroCookies } from '../core/cookies';
|
|
13
|
-
import type { AstroComponentFactory
|
|
13
|
+
import type { AstroComponentFactory } from '../runtime/server';
|
|
14
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
14
15
|
export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
|
|
15
16
|
export type { SSRManifest } from '../core/app/types';
|
|
16
17
|
export interface AstroBuiltinProps {
|
|
@@ -54,6 +55,7 @@ export interface AstroComponentMetadata {
|
|
|
54
55
|
export interface CLIFlags {
|
|
55
56
|
root?: string;
|
|
56
57
|
site?: string;
|
|
58
|
+
base?: string;
|
|
57
59
|
host?: string | boolean;
|
|
58
60
|
port?: number;
|
|
59
61
|
config?: string;
|
|
@@ -219,6 +221,8 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
|
|
|
219
221
|
render(slotName: string, args?: any[]): Promise<string>;
|
|
220
222
|
};
|
|
221
223
|
}
|
|
224
|
+
/** Union type of supported markdown file extensions */
|
|
225
|
+
declare type MarkdowFileExtension = typeof SUPPORTED_MARKDOWN_FILE_EXTENSIONS[number];
|
|
222
226
|
export interface AstroGlobalPartial {
|
|
223
227
|
/**
|
|
224
228
|
* @deprecated since version 0.24. See the {@link https://astro.build/deprecated/resolve upgrade guide} for more details.
|
|
@@ -237,7 +241,7 @@ export interface AstroGlobalPartial {
|
|
|
237
241
|
* [Astro reference](https://docs.astro.build/en/reference/api-reference/#astroglob)
|
|
238
242
|
*/
|
|
239
243
|
glob(globStr: `${any}.astro`): Promise<AstroInstance[]>;
|
|
240
|
-
glob<T extends Record<string, any>>(globStr: `${any}
|
|
244
|
+
glob<T extends Record<string, any>>(globStr: `${any}${MarkdowFileExtension}`): Promise<MarkdownInstance<T>[]>;
|
|
241
245
|
glob<T extends Record<string, any>>(globStr: `${any}.mdx`): Promise<MDXInstance<T>[]>;
|
|
242
246
|
glob<T extends Record<string, any>>(globStr: string): Promise<T[]>;
|
|
243
247
|
/**
|
|
@@ -675,7 +679,7 @@ export interface AstroUserConfig {
|
|
|
675
679
|
* Pass [remark plugins](https://github.com/remarkjs/remark) to customize how your Markdown is built. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
|
|
676
680
|
*
|
|
677
681
|
* :::caution
|
|
678
|
-
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the `extendDefaultPlugins` flag.
|
|
682
|
+
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the [`extendDefaultPlugins`](#markdownextenddefaultplugins) flag.
|
|
679
683
|
* :::
|
|
680
684
|
*
|
|
681
685
|
* ```js
|
|
@@ -696,7 +700,7 @@ export interface AstroUserConfig {
|
|
|
696
700
|
* Pass [rehype plugins](https://github.com/remarkjs/remark-rehype) to customize how your Markdown's output HTML is processed. You can import and apply the plugin function (recommended), or pass the plugin name as a string.
|
|
697
701
|
*
|
|
698
702
|
* :::caution
|
|
699
|
-
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the `extendDefaultPlugins` flag.
|
|
703
|
+
* Providing a list of plugins will **remove** our default plugins. To preserve these defaults, see the [`extendDefaultPlugins`](#markdownextenddefaultplugins) flag.
|
|
700
704
|
* :::
|
|
701
705
|
*
|
|
702
706
|
* ```js
|
|
@@ -816,7 +820,7 @@ export interface AstroUserConfig {
|
|
|
816
820
|
* @default `false`
|
|
817
821
|
* @version 1.0.0-rc.1
|
|
818
822
|
* @description
|
|
819
|
-
* Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` Markdown files.
|
|
823
|
+
* Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` (and alternative extensions for markdown files like ".markdown") Markdown files.
|
|
820
824
|
* In Astro `1.0.0-rc`, this original behavior was removed as the default, in favor of our new [MDX integration](/en/guides/integrations-guide/mdx/).
|
|
821
825
|
*
|
|
822
826
|
* To enable this behavior, set `legacy.astroFlavoredMarkdown` to `true` in your [`astro.config.mjs` configuration file](/en/guides/configuring-astro/#the-astro-config-file).
|
|
@@ -889,7 +893,6 @@ export interface AstroSettings {
|
|
|
889
893
|
export declare type AsyncRendererComponentFn<U> = (Component: any, props: any, slots: Record<string, string>, metadata?: AstroComponentMetadata) => Promise<U>;
|
|
890
894
|
/** Generic interface for a component (Astro, Svelte, React, etc.) */
|
|
891
895
|
export interface ComponentInstance {
|
|
892
|
-
$$metadata: Metadata;
|
|
893
896
|
default: AstroComponentFactory;
|
|
894
897
|
css?: string[];
|
|
895
898
|
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
|
package/dist/cli/index.js
CHANGED
|
@@ -44,6 +44,8 @@ function printAstroHelp() {
|
|
|
44
44
|
"Global Flags": [
|
|
45
45
|
["--config <path>", "Specify your config file."],
|
|
46
46
|
["--root <path>", "Specify your project root folder."],
|
|
47
|
+
["--site <url>", "Specify your project site."],
|
|
48
|
+
["--base <pathname>", "Specify your project base."],
|
|
47
49
|
["--verbose", "Enable verbose logging."],
|
|
48
50
|
["--silent", "Disable all logging."],
|
|
49
51
|
["--version", "Show the version number and exit."],
|
package/dist/core/add/index.js
CHANGED
|
@@ -545,6 +545,7 @@ async function validateIntegrations(integrations) {
|
|
|
545
545
|
try {
|
|
546
546
|
const integrationEntries = await Promise.all(
|
|
547
547
|
integrations.map(async (integration) => {
|
|
548
|
+
var _a;
|
|
548
549
|
const parsed = parseIntegrationName(integration);
|
|
549
550
|
if (!parsed) {
|
|
550
551
|
throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
|
|
@@ -594,8 +595,12 @@ async function validateIntegrations(integrations) {
|
|
|
594
595
|
[pkgJson["name"], `^${pkgJson["version"]}`]
|
|
595
596
|
];
|
|
596
597
|
if (pkgJson["peerDependencies"]) {
|
|
598
|
+
const meta = pkgJson["peerDependenciesMeta"] || {};
|
|
597
599
|
for (const peer in pkgJson["peerDependencies"]) {
|
|
598
|
-
|
|
600
|
+
const optional = ((_a = meta[peer]) == null ? void 0 : _a.optional) || false;
|
|
601
|
+
if (!optional) {
|
|
602
|
+
dependencies.push([peer, pkgJson["peerDependencies"][peer]]);
|
|
603
|
+
}
|
|
599
604
|
}
|
|
600
605
|
}
|
|
601
606
|
let integrationType;
|
|
@@ -161,29 +161,6 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
161
161
|
});
|
|
162
162
|
output.source = minifiedCSS;
|
|
163
163
|
}
|
|
164
|
-
} else if (output.type === "chunk") {
|
|
165
|
-
for (const [imp, bindings] of Object.entries(output.importedBindings)) {
|
|
166
|
-
if (imp.startsWith("chunks/") && !bundle[imp] && output.code.includes(imp)) {
|
|
167
|
-
const depChunk = {
|
|
168
|
-
type: "chunk",
|
|
169
|
-
fileName: imp,
|
|
170
|
-
name: imp,
|
|
171
|
-
facadeModuleId: imp,
|
|
172
|
-
code: `/* Pure CSS chunk ${imp} */ ${bindings.map((b) => `export const ${b} = {};`).join("")}`,
|
|
173
|
-
dynamicImports: [],
|
|
174
|
-
implicitlyLoadedBefore: [],
|
|
175
|
-
importedBindings: {},
|
|
176
|
-
imports: [],
|
|
177
|
-
referencedFiles: [],
|
|
178
|
-
exports: Array.from(bindings),
|
|
179
|
-
isDynamicEntry: false,
|
|
180
|
-
isEntry: false,
|
|
181
|
-
isImplicitEntry: false,
|
|
182
|
-
modules: {}
|
|
183
|
-
};
|
|
184
|
-
bundle[imp] = depChunk;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
164
|
}
|
|
188
165
|
}
|
|
189
166
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import { transform } from "@astrojs/compiler";
|
|
3
2
|
import { AstroErrorCodes } from "../errors.js";
|
|
4
|
-
import { prependForwardSlash
|
|
5
|
-
import { AggregateError,
|
|
3
|
+
import { prependForwardSlash } from "../path.js";
|
|
4
|
+
import { AggregateError, resolvePath, viteID } from "../util.js";
|
|
6
5
|
import { createStylePreprocessor } from "./style.js";
|
|
7
6
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
8
7
|
async function compile({
|
|
@@ -15,7 +14,7 @@ async function compile({
|
|
|
15
14
|
let cssDeps = /* @__PURE__ */ new Set();
|
|
16
15
|
let cssTransformErrors = [];
|
|
17
16
|
const transformResult = await transform(source, {
|
|
18
|
-
pathname:
|
|
17
|
+
pathname: filename,
|
|
19
18
|
projectRoot: config.root.toString(),
|
|
20
19
|
site: (_a = config.site) == null ? void 0 : _a.toString(),
|
|
21
20
|
sourcefile: filename,
|
|
@@ -24,7 +23,10 @@ async function compile({
|
|
|
24
23
|
viteID(new URL("../../runtime/server/index.js", import.meta.url))
|
|
25
24
|
)}`,
|
|
26
25
|
experimentalStaticExtraction: true,
|
|
27
|
-
preprocessStyle: createStylePreprocessor(transformStyle, cssDeps, cssTransformErrors)
|
|
26
|
+
preprocessStyle: createStylePreprocessor(transformStyle, cssDeps, cssTransformErrors),
|
|
27
|
+
async resolvePath(specifier) {
|
|
28
|
+
return resolvePath(specifier, filename);
|
|
29
|
+
}
|
|
28
30
|
}).catch((err) => {
|
|
29
31
|
err.code = err.code || AstroErrorCodes.UnknownCompilerError;
|
|
30
32
|
throw err;
|
|
@@ -54,24 +56,6 @@ async function compile({
|
|
|
54
56
|
value: source
|
|
55
57
|
}
|
|
56
58
|
});
|
|
57
|
-
for (const c of compileResult.clientOnlyComponents) {
|
|
58
|
-
c.resolvedPath = removeLeadingForwardSlashWindows(c.resolvedPath);
|
|
59
|
-
if (c.specifier.endsWith(".jsx") && !c.resolvedPath.endsWith(".jsx")) {
|
|
60
|
-
c.resolvedPath += ".jsx";
|
|
61
|
-
}
|
|
62
|
-
if (path.isAbsolute(c.resolvedPath)) {
|
|
63
|
-
c.resolvedPath = resolveJsToTs(c.resolvedPath);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
for (const c of compileResult.hydratedComponents) {
|
|
67
|
-
c.resolvedPath = removeLeadingForwardSlashWindows(c.resolvedPath);
|
|
68
|
-
if (c.specifier.endsWith(".jsx") && !c.resolvedPath.endsWith(".jsx")) {
|
|
69
|
-
c.resolvedPath += ".jsx";
|
|
70
|
-
}
|
|
71
|
-
if (path.isAbsolute(c.resolvedPath)) {
|
|
72
|
-
c.resolvedPath = resolveJsToTs(c.resolvedPath);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
59
|
return compileResult;
|
|
76
60
|
}
|
|
77
61
|
function isCached(config, filename) {
|
|
@@ -72,6 +72,7 @@ function resolveFlags(flags) {
|
|
|
72
72
|
return {
|
|
73
73
|
root: typeof flags.root === "string" ? flags.root : void 0,
|
|
74
74
|
site: typeof flags.site === "string" ? flags.site : void 0,
|
|
75
|
+
base: typeof flags.base === "string" ? flags.base : void 0,
|
|
75
76
|
port: typeof flags.port === "number" ? flags.port : void 0,
|
|
76
77
|
config: typeof flags.config === "string" ? flags.config : void 0,
|
|
77
78
|
host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
|
|
@@ -86,6 +87,8 @@ function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
|
86
87
|
astroConfig.markdown = astroConfig.markdown || {};
|
|
87
88
|
if (typeof flags.site === "string")
|
|
88
89
|
astroConfig.site = flags.site;
|
|
90
|
+
if (typeof flags.base === "string")
|
|
91
|
+
astroConfig.base = flags.base;
|
|
89
92
|
if (typeof flags.drafts === "boolean")
|
|
90
93
|
astroConfig.markdown.drafts = flags.drafts;
|
|
91
94
|
if (typeof flags.port === "number") {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./../constants.js";
|
|
1
2
|
import jsxRenderer from "../../jsx/renderer.js";
|
|
2
3
|
import { loadTSConfig } from "./tsconfig.js";
|
|
3
4
|
function createSettings(config, cwd) {
|
|
@@ -8,7 +9,7 @@ function createSettings(config, cwd) {
|
|
|
8
9
|
tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
|
|
9
10
|
adapter: void 0,
|
|
10
11
|
injectedRoutes: [],
|
|
11
|
-
pageExtensions: [".astro", ".
|
|
12
|
+
pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
|
|
12
13
|
renderers: [jsxRenderer],
|
|
13
14
|
scripts: [],
|
|
14
15
|
watchFiles: (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : []
|
package/dist/core/constants.d.ts
CHANGED
package/dist/core/constants.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
const ASTRO_VERSION = "1.
|
|
1
|
+
const ASTRO_VERSION = "1.6.0";
|
|
2
|
+
const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
|
|
3
|
+
".markdown",
|
|
4
|
+
".mdown",
|
|
5
|
+
".mkdn",
|
|
6
|
+
".mkd",
|
|
7
|
+
".mdwn",
|
|
8
|
+
".md"
|
|
9
|
+
];
|
|
2
10
|
export {
|
|
3
|
-
ASTRO_VERSION
|
|
11
|
+
ASTRO_VERSION,
|
|
12
|
+
SUPPORTED_MARKDOWN_FILE_EXTENSIONS
|
|
4
13
|
};
|
package/dist/core/create-vite.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { createRequire } from "module";
|
|
3
|
-
import path from "path";
|
|
4
1
|
import { fileURLToPath } from "url";
|
|
5
2
|
import * as vite from "vite";
|
|
3
|
+
import { crawlFrameworkPkgs } from "vitefu";
|
|
6
4
|
import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
|
|
7
5
|
import astroViteServerPlugin from "../vite-plugin-astro-server/index.js";
|
|
8
6
|
import astroVitePlugin from "../vite-plugin-astro/index.js";
|
|
@@ -35,7 +33,22 @@ function getSsrNoExternalDeps(projectRoot) {
|
|
|
35
33
|
return noExternalDeps;
|
|
36
34
|
}
|
|
37
35
|
async function createVite(commandConfig, { settings, logging, mode }) {
|
|
38
|
-
const
|
|
36
|
+
const astroPkgsConfig = await crawlFrameworkPkgs({
|
|
37
|
+
root: fileURLToPath(settings.config.root),
|
|
38
|
+
isBuild: mode === "build",
|
|
39
|
+
isFrameworkPkgByJson(pkgJson) {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
41
|
+
return ((_a = pkgJson.peerDependencies) == null ? void 0 : _a.astro) || ((_b = pkgJson.dependencies) == null ? void 0 : _b.astro) || ((_c = pkgJson.keywords) == null ? void 0 : _c.includes("astro")) || ((_d = pkgJson.keywords) == null ? void 0 : _d.includes("astro-component")) || /^(@[^\/]+\/)?astro\-/.test(pkgJson.name);
|
|
42
|
+
},
|
|
43
|
+
isFrameworkPkgByName(pkgName) {
|
|
44
|
+
const isNotAstroPkg = isCommonNotAstro(pkgName);
|
|
45
|
+
if (isNotAstroPkg) {
|
|
46
|
+
return false;
|
|
47
|
+
} else {
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
39
52
|
const commonConfig = {
|
|
40
53
|
cacheDir: fileURLToPath(new URL("./node_modules/.vite/", settings.config.root)),
|
|
41
54
|
clearScreen: false,
|
|
@@ -88,8 +101,11 @@ async function createVite(commandConfig, { settings, logging, mode }) {
|
|
|
88
101
|
conditions: ["astro"]
|
|
89
102
|
},
|
|
90
103
|
ssr: {
|
|
91
|
-
noExternal: [
|
|
92
|
-
|
|
104
|
+
noExternal: [
|
|
105
|
+
...getSsrNoExternalDeps(settings.config.root),
|
|
106
|
+
...astroPkgsConfig.ssr.noExternal
|
|
107
|
+
],
|
|
108
|
+
external: [...mode === "dev" ? ["shiki"] : [], ...astroPkgsConfig.ssr.external]
|
|
93
109
|
}
|
|
94
110
|
};
|
|
95
111
|
let result = commonConfig;
|
|
@@ -118,84 +134,6 @@ function sortPlugins(pluginOptions) {
|
|
|
118
134
|
pluginOptions.splice(mdxPluginIndex, 1);
|
|
119
135
|
pluginOptions.splice(jsxPluginIndex, 0, mdxPlugin);
|
|
120
136
|
}
|
|
121
|
-
async function getAstroPackages(settings) {
|
|
122
|
-
const { astroPackages } = new DependencyWalker(settings.config.root);
|
|
123
|
-
return astroPackages;
|
|
124
|
-
}
|
|
125
|
-
class DependencyWalker {
|
|
126
|
-
constructor(root) {
|
|
127
|
-
this.astroDeps = /* @__PURE__ */ new Set();
|
|
128
|
-
this.nonAstroDeps = /* @__PURE__ */ new Set();
|
|
129
|
-
const pkgUrl = new URL("./package.json", root);
|
|
130
|
-
this.require = createRequire(pkgUrl);
|
|
131
|
-
const pkgPath = fileURLToPath(pkgUrl);
|
|
132
|
-
if (!fs.existsSync(pkgPath))
|
|
133
|
-
return;
|
|
134
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
135
|
-
const deps = [
|
|
136
|
-
...Object.keys(pkg.dependencies || {}),
|
|
137
|
-
...Object.keys(pkg.devDependencies || {})
|
|
138
|
-
];
|
|
139
|
-
this.scanDependencies(deps);
|
|
140
|
-
}
|
|
141
|
-
get astroPackages() {
|
|
142
|
-
return Array.from(this.astroDeps);
|
|
143
|
-
}
|
|
144
|
-
seen(dep) {
|
|
145
|
-
return this.astroDeps.has(dep) || this.nonAstroDeps.has(dep);
|
|
146
|
-
}
|
|
147
|
-
readPkgJSON(dir) {
|
|
148
|
-
try {
|
|
149
|
-
const filePath = path.join(dir, "package.json");
|
|
150
|
-
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
151
|
-
} catch (e) {
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
resolvePkgJSON(dep) {
|
|
155
|
-
try {
|
|
156
|
-
const pkgJson = this.require(dep + "/package.json");
|
|
157
|
-
return pkgJson;
|
|
158
|
-
} catch (e) {
|
|
159
|
-
try {
|
|
160
|
-
let dir = path.dirname(this.require.resolve(dep));
|
|
161
|
-
while (dir) {
|
|
162
|
-
const pkgJSON = this.readPkgJSON(dir);
|
|
163
|
-
if (pkgJSON && pkgJSON.name === dep)
|
|
164
|
-
return pkgJSON;
|
|
165
|
-
const parentDir = path.dirname(dir);
|
|
166
|
-
if (parentDir === dir)
|
|
167
|
-
break;
|
|
168
|
-
dir = parentDir;
|
|
169
|
-
}
|
|
170
|
-
} catch {
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
scanDependencies(deps) {
|
|
175
|
-
const newDeps = [];
|
|
176
|
-
for (const dep of deps) {
|
|
177
|
-
if (isCommonNotAstro(dep)) {
|
|
178
|
-
this.nonAstroDeps.add(dep);
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
const pkgJson = this.resolvePkgJSON(dep);
|
|
182
|
-
if (!pkgJson) {
|
|
183
|
-
this.nonAstroDeps.add(dep);
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
const { dependencies = {}, peerDependencies = {}, keywords = [] } = pkgJson;
|
|
187
|
-
if (peerDependencies.astro || dependencies.astro || keywords.includes("astro") || keywords.includes("astro-component") || /^(@[^\/]+\/)?astro\-/.test(dep)) {
|
|
188
|
-
this.astroDeps.add(dep);
|
|
189
|
-
const unknownDependencies = Object.keys(dependencies).filter((d) => !this.seen(d));
|
|
190
|
-
newDeps.push(...unknownDependencies);
|
|
191
|
-
} else {
|
|
192
|
-
this.nonAstroDeps.add(dep);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (newDeps.length)
|
|
196
|
-
this.scanDependencies(newDeps);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
137
|
const COMMON_DEPENDENCIES_NOT_ASTRO = [
|
|
200
138
|
"autoprefixer",
|
|
201
139
|
"react",
|
package/dist/core/dev/index.js
CHANGED
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.
|
|
50
|
+
const version = "1.6.0";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -250,7 +250,7 @@ function printHelp({
|
|
|
250
250
|
message.push(
|
|
251
251
|
linebreak(),
|
|
252
252
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
253
|
-
`v${"1.
|
|
253
|
+
`v${"1.6.0"}`
|
|
254
254
|
)} ${headline}`
|
|
255
255
|
);
|
|
256
256
|
}
|
|
@@ -19,7 +19,9 @@ async function preview(_settings, { logging }) {
|
|
|
19
19
|
throw new Error(`[preview] No adapter found.`);
|
|
20
20
|
}
|
|
21
21
|
if (!settings.adapter.previewEntrypoint) {
|
|
22
|
-
throw new Error(
|
|
22
|
+
throw new Error(
|
|
23
|
+
`[preview] The ${settings.adapter.name} adapter does not support the preview command.`
|
|
24
|
+
);
|
|
23
25
|
}
|
|
24
26
|
const require2 = createRequire(settings.config.root);
|
|
25
27
|
const previewEntrypoint = require2.resolve(settings.adapter.previewEntrypoint);
|
|
@@ -3,7 +3,6 @@ import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
|
3
3
|
import { isPage, resolveIdToUrl } from "../../util.js";
|
|
4
4
|
import { createRenderContext, renderPage as coreRenderPage } from "../index.js";
|
|
5
5
|
import { filterFoundRenderers, loadRenderer } from "../renderer.js";
|
|
6
|
-
import { collectMdMetadata } from "../util.js";
|
|
7
6
|
import { getStylesForURL } from "./css.js";
|
|
8
7
|
import { getScriptsForURL } from "./scripts.js";
|
|
9
8
|
import { createDevelopmentEnvironment } from "./environment.js";
|
|
@@ -18,13 +17,6 @@ async function preload({
|
|
|
18
17
|
}) {
|
|
19
18
|
const renderers = await loadRenderers(env.viteServer, env.settings);
|
|
20
19
|
const mod = await env.viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
21
|
-
if (env.viteServer.config.mode === "development" || !(mod == null ? void 0 : mod.$$metadata)) {
|
|
22
|
-
return [renderers, mod];
|
|
23
|
-
}
|
|
24
|
-
const modGraph = await env.viteServer.moduleGraph.getModuleByUrl(fileURLToPath(filePath));
|
|
25
|
-
if (modGraph) {
|
|
26
|
-
await collectMdMetadata(mod.$$metadata, modGraph, env.viteServer);
|
|
27
|
-
}
|
|
28
20
|
return [renderers, mod];
|
|
29
21
|
}
|
|
30
22
|
async function getScriptsAndStyles({ env, filePath }) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import npath from "path";
|
|
2
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
2
3
|
import { unwrapId } from "../../util.js";
|
|
3
4
|
import { STYLE_EXTENSIONS } from "../util.js";
|
|
4
|
-
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro",
|
|
5
|
+
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
|
|
5
6
|
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
|
|
6
7
|
async function* crawlGraph(viteServer, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
|
|
7
8
|
const id = unwrapId(_id);
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import type { ModuleNode, ViteDevServer } from 'vite';
|
|
2
|
-
import type { Metadata } from '../../runtime/server/metadata.js';
|
|
3
|
-
/** Check if a URL is already valid */
|
|
4
|
-
export declare function isValidURL(url: string): boolean;
|
|
5
1
|
export declare const STYLE_EXTENSIONS: Set<string>;
|
|
6
2
|
export declare const isCSSRequest: (request: string) => boolean;
|
|
7
|
-
export declare function collectMdMetadata(metadata: Metadata, modGraph: ModuleNode, viteServer: ViteDevServer): Promise<void>;
|
package/dist/core/render/util.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
function isValidURL(url) {
|
|
2
|
-
try {
|
|
3
|
-
new URL(url);
|
|
4
|
-
return true;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
}
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
1
|
const STYLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
10
2
|
".css",
|
|
11
3
|
".pcss",
|
|
@@ -16,49 +8,11 @@ const STYLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
16
8
|
".stylus",
|
|
17
9
|
".less"
|
|
18
10
|
]);
|
|
19
|
-
const MARKDOWN_IMPORT_FLAG = "?mdImport";
|
|
20
11
|
const cssRe = new RegExp(
|
|
21
12
|
`\\.(${Array.from(STYLE_EXTENSIONS).map((s) => s.slice(1)).join("|")})($|\\?)`
|
|
22
13
|
);
|
|
23
14
|
const isCSSRequest = (request) => cssRe.test(request);
|
|
24
|
-
const seenMdMetadata = /* @__PURE__ */ new Set();
|
|
25
|
-
async function collectMdMetadata(metadata, modGraph, viteServer) {
|
|
26
|
-
const importedModules = [...(modGraph == null ? void 0 : modGraph.importedModules) ?? []];
|
|
27
|
-
await Promise.all(
|
|
28
|
-
importedModules.map(async (importedModule) => {
|
|
29
|
-
var _a, _b;
|
|
30
|
-
if (!importedModule.id || seenMdMetadata.has(importedModule.id))
|
|
31
|
-
return;
|
|
32
|
-
seenMdMetadata.add(importedModule.id);
|
|
33
|
-
await collectMdMetadata(metadata, importedModule, viteServer);
|
|
34
|
-
if (!((_a = importedModule == null ? void 0 : importedModule.id) == null ? void 0 : _a.endsWith(MARKDOWN_IMPORT_FLAG)))
|
|
35
|
-
return;
|
|
36
|
-
const mdSSRMod = await viteServer.ssrLoadModule(importedModule.id);
|
|
37
|
-
const mdMetadata = await ((_b = mdSSRMod.$$loadMetadata) == null ? void 0 : _b.call(mdSSRMod));
|
|
38
|
-
if (!mdMetadata)
|
|
39
|
-
return;
|
|
40
|
-
for (let mdMod of mdMetadata.modules) {
|
|
41
|
-
mdMod.specifier = mdMetadata.resolvePath(mdMod.specifier);
|
|
42
|
-
metadata.modules.push(mdMod);
|
|
43
|
-
}
|
|
44
|
-
for (let mdHoisted of mdMetadata.hoisted) {
|
|
45
|
-
metadata.hoisted.push(mdHoisted);
|
|
46
|
-
}
|
|
47
|
-
for (let mdHydrated of mdMetadata.hydratedComponents) {
|
|
48
|
-
metadata.hydratedComponents.push(mdHydrated);
|
|
49
|
-
}
|
|
50
|
-
for (let mdClientOnly of mdMetadata.clientOnlyComponents) {
|
|
51
|
-
metadata.clientOnlyComponents.push(mdClientOnly);
|
|
52
|
-
}
|
|
53
|
-
for (let mdHydrationDirective of mdMetadata.hydrationDirectives) {
|
|
54
|
-
metadata.hydrationDirectives.add(mdHydrationDirective);
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
15
|
export {
|
|
60
16
|
STYLE_EXTENSIONS,
|
|
61
|
-
|
|
62
|
-
isCSSRequest,
|
|
63
|
-
isValidURL
|
|
17
|
+
isCSSRequest
|
|
64
18
|
};
|
|
@@ -3,6 +3,7 @@ import { createRequire } from "module";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import slash from "slash";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
6
7
|
import { warn } from "../../logger/core.js";
|
|
7
8
|
import { removeLeadingForwardSlash } from "../../path.js";
|
|
8
9
|
import { resolvePages } from "../../util.js";
|
|
@@ -135,7 +136,11 @@ function createRouteManifest({ settings, cwd }, logging) {
|
|
|
135
136
|
var _a;
|
|
136
137
|
const components = [];
|
|
137
138
|
const routes = [];
|
|
138
|
-
const validPageExtensions = /* @__PURE__ */ new Set([
|
|
139
|
+
const validPageExtensions = /* @__PURE__ */ new Set([
|
|
140
|
+
".astro",
|
|
141
|
+
...SUPPORTED_MARKDOWN_FILE_EXTENSIONS,
|
|
142
|
+
...settings.pageExtensions
|
|
143
|
+
]);
|
|
139
144
|
const validEndpointExtensions = /* @__PURE__ */ new Set([".js", ".ts"]);
|
|
140
145
|
function walk(dir, parentSegments, parentParams) {
|
|
141
146
|
let items = [];
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ErrorPayload, ViteDevServer } from 'vite';
|
|
2
2
|
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
3
3
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
4
4
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
5
5
|
/** Cross-realm compatible URL */
|
|
6
6
|
export declare function isURL(value: unknown): value is URL;
|
|
7
|
+
/** Check if a file is a markdown file based on its extension */
|
|
8
|
+
export declare function isMarkdownFile(fileId: string, option: {
|
|
9
|
+
criteria: 'endsWith' | 'includes';
|
|
10
|
+
suffix?: string;
|
|
11
|
+
}): boolean;
|
|
7
12
|
/** Wraps an object in an array. If an array is passed, ignore it. */
|
|
8
13
|
export declare function arraify<T>(target: T | T[]): T[];
|
|
9
14
|
export declare function padMultilineString(source: string, n?: number): string;
|
|
@@ -45,4 +50,8 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
|
|
|
45
50
|
*/
|
|
46
51
|
export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
|
|
47
52
|
export declare function resolveJsToTs(filePath: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Resolve the hydration paths so that it can be imported in the client
|
|
55
|
+
*/
|
|
56
|
+
export declare function resolvePath(specifier: string, importer: string): string;
|
|
48
57
|
export declare const AggregateError: any;
|
package/dist/core/util.js
CHANGED
|
@@ -4,6 +4,8 @@ import path from "path";
|
|
|
4
4
|
import resolve from "resolve";
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
|
+
import { normalizePath } from "vite";
|
|
8
|
+
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./constants.js";
|
|
7
9
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
8
10
|
function isObject(value) {
|
|
9
11
|
return typeof value === "object" && value != null;
|
|
@@ -11,6 +13,21 @@ function isObject(value) {
|
|
|
11
13
|
function isURL(value) {
|
|
12
14
|
return Object.prototype.toString.call(value) === "[object URL]";
|
|
13
15
|
}
|
|
16
|
+
function isMarkdownFile(fileId, option) {
|
|
17
|
+
const _suffix = option.suffix ?? "";
|
|
18
|
+
if (option.criteria === "endsWith") {
|
|
19
|
+
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
20
|
+
if (fileId.endsWith(`${markdownFileExtension}${_suffix}`))
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
26
|
+
if (fileId.includes(`${markdownFileExtension}${_suffix}`))
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
14
31
|
function arraify(target) {
|
|
15
32
|
return Array.isArray(target) ? target : [target];
|
|
16
33
|
}
|
|
@@ -169,6 +186,14 @@ function resolveJsToTs(filePath) {
|
|
|
169
186
|
}
|
|
170
187
|
return filePath;
|
|
171
188
|
}
|
|
189
|
+
function resolvePath(specifier, importer) {
|
|
190
|
+
if (specifier.startsWith(".")) {
|
|
191
|
+
const absoluteSpecifier = path.resolve(path.dirname(importer), specifier);
|
|
192
|
+
return resolveJsToTs(normalizePath(absoluteSpecifier));
|
|
193
|
+
} else {
|
|
194
|
+
return specifier;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
172
197
|
const AggregateError = typeof globalThis.AggregateError !== "undefined" ? globalThis.AggregateError : class extends Error {
|
|
173
198
|
constructor(errors, message) {
|
|
174
199
|
super(message);
|
|
@@ -185,6 +210,7 @@ export {
|
|
|
185
210
|
emoji,
|
|
186
211
|
getLocalAddress,
|
|
187
212
|
getOutputFilename,
|
|
213
|
+
isMarkdownFile,
|
|
188
214
|
isModeServerWithNoAdapter,
|
|
189
215
|
isObject,
|
|
190
216
|
isPage,
|
|
@@ -196,6 +222,7 @@ export {
|
|
|
196
222
|
resolveIdToUrl,
|
|
197
223
|
resolveJsToTs,
|
|
198
224
|
resolvePages,
|
|
225
|
+
resolvePath,
|
|
199
226
|
unwrapId,
|
|
200
227
|
viteID
|
|
201
228
|
};
|
package/dist/jsx/babel.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
-
import
|
|
3
|
-
import { normalizePath } from "vite";
|
|
4
|
-
import { resolveJsToTs } from "../core/util.js";
|
|
2
|
+
import { resolvePath } from "../core/util.js";
|
|
5
3
|
import { HydrationDirectiveProps } from "../runtime/server/hydration.js";
|
|
6
4
|
const ClientOnlyPlaceholder = "astro-client-only";
|
|
7
5
|
function isComponent(tagName) {
|
|
@@ -194,13 +192,7 @@ function astroJSX() {
|
|
|
194
192
|
}
|
|
195
193
|
const meta = path.getData("import");
|
|
196
194
|
if (meta) {
|
|
197
|
-
|
|
198
|
-
if (meta.path.startsWith(".")) {
|
|
199
|
-
resolvedPath = normalizePath(npath.resolve(npath.dirname(state.filename), meta.path));
|
|
200
|
-
resolvedPath = resolveJsToTs(resolvedPath);
|
|
201
|
-
} else {
|
|
202
|
-
resolvedPath = meta.path;
|
|
203
|
-
}
|
|
195
|
+
const resolvedPath = resolvePath(meta.path, state.filename);
|
|
204
196
|
if (isClientOnly) {
|
|
205
197
|
state.file.metadata.astro.clientOnlyComponents.push({
|
|
206
198
|
exportName: meta.name,
|
|
@@ -270,13 +262,7 @@ function astroJSX() {
|
|
|
270
262
|
}
|
|
271
263
|
}
|
|
272
264
|
}
|
|
273
|
-
|
|
274
|
-
if (meta.path.startsWith(".")) {
|
|
275
|
-
resolvedPath = normalizePath(npath.resolve(npath.dirname(state.filename), meta.path));
|
|
276
|
-
resolvedPath = resolveJsToTs(resolvedPath);
|
|
277
|
-
} else {
|
|
278
|
-
resolvedPath = meta.path;
|
|
279
|
-
}
|
|
265
|
+
const resolvedPath = resolvePath(meta.path, state.filename);
|
|
280
266
|
if (isClientOnly) {
|
|
281
267
|
state.file.metadata.astro.clientOnlyComponents.push({
|
|
282
268
|
exportName: meta.name,
|
|
@@ -2,8 +2,6 @@ export { createAstro } from './astro-global.js';
|
|
|
2
2
|
export { renderEndpoint } from './endpoint.js';
|
|
3
3
|
export { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from './escape.js';
|
|
4
4
|
export { renderJSX } from './jsx.js';
|
|
5
|
-
export type { Metadata } from './metadata';
|
|
6
|
-
export { createMetadata } from './metadata.js';
|
|
7
5
|
export { addAttribute, defineScriptVars, Fragment, maybeRenderHead, renderAstroComponent, renderComponent, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, renderTemplate as render, renderTemplate, renderToString, stringifyChunk, voidElementNames, } from './render/index.js';
|
|
8
6
|
export type { AstroComponentFactory, RenderInstruction } from './render/index.js';
|
|
9
7
|
import type { AstroComponentFactory } from './render/index.js';
|
|
@@ -2,7 +2,6 @@ import { createAstro } from "./astro-global.js";
|
|
|
2
2
|
import { renderEndpoint } from "./endpoint.js";
|
|
3
3
|
import { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from "./escape.js";
|
|
4
4
|
import { renderJSX } from "./jsx.js";
|
|
5
|
-
import { createMetadata } from "./metadata.js";
|
|
6
5
|
import {
|
|
7
6
|
addAttribute,
|
|
8
7
|
defineScriptVars,
|
|
@@ -89,7 +88,6 @@ export {
|
|
|
89
88
|
addAttribute,
|
|
90
89
|
createAstro,
|
|
91
90
|
createComponent,
|
|
92
|
-
createMetadata,
|
|
93
91
|
defineScriptVars,
|
|
94
92
|
defineStyleVars,
|
|
95
93
|
escapeHTML,
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { parse as babelParser } from "@babel/parser";
|
|
2
|
-
import npath from "path";
|
|
3
2
|
import { parse, print, types, visit } from "recast";
|
|
4
|
-
import {
|
|
5
|
-
import { resolveJsToTs } from "../core/util.js";
|
|
3
|
+
import { isMarkdownFile } from "../core/util.js";
|
|
6
4
|
const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
|
|
7
|
-
const CLIENT_COMPONENT_PATH_REGEX = /['"]client:component-path['"]:/;
|
|
8
|
-
const validAstroGlobalNames = /* @__PURE__ */ new Set(["Astro", "Astro2"]);
|
|
9
5
|
function astro(_opts) {
|
|
10
6
|
return {
|
|
11
7
|
name: "astro:postprocess",
|
|
12
8
|
async transform(code, id) {
|
|
13
|
-
if (!id.endsWith(".astro") && !id
|
|
9
|
+
if (!id.endsWith(".astro") && !isMarkdownFile(id, { criteria: "endsWith" })) {
|
|
14
10
|
return null;
|
|
15
11
|
}
|
|
16
|
-
if (!ASTRO_GLOB_REGEX.test(code)
|
|
12
|
+
if (!ASTRO_GLOB_REGEX.test(code)) {
|
|
17
13
|
return null;
|
|
18
14
|
}
|
|
19
15
|
const ast = parse(code, {
|
|
@@ -49,24 +45,6 @@ function astro(_opts) {
|
|
|
49
45
|
}
|
|
50
46
|
);
|
|
51
47
|
return false;
|
|
52
|
-
},
|
|
53
|
-
visitObjectProperty: function(path) {
|
|
54
|
-
if (!types.namedTypes.StringLiteral.check(path.node.key) || path.node.key.value !== "client:component-path" || !types.namedTypes.StringLiteral.check(path.node.value)) {
|
|
55
|
-
this.traverse(path);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const valuePath = path.get("value");
|
|
59
|
-
let value = valuePath.value.value;
|
|
60
|
-
value = removeLeadingForwardSlashWindows(value);
|
|
61
|
-
if (code.includes(npath.basename(value) + ".jsx")) {
|
|
62
|
-
value += ".jsx";
|
|
63
|
-
}
|
|
64
|
-
value = resolveJsToTs(value);
|
|
65
|
-
valuePath.replace({
|
|
66
|
-
type: "StringLiteral",
|
|
67
|
-
value
|
|
68
|
-
});
|
|
69
|
-
return false;
|
|
70
48
|
}
|
|
71
49
|
});
|
|
72
50
|
const result = print(ast);
|
|
@@ -4,7 +4,7 @@ import esbuild from "esbuild";
|
|
|
4
4
|
import * as colors from "kleur/colors";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { error } from "../core/logger/core.js";
|
|
7
|
-
import { parseNpmName } from "../core/util.js";
|
|
7
|
+
import { isMarkdownFile, parseNpmName } from "../core/util.js";
|
|
8
8
|
import tagExportsPlugin from "./tag.js";
|
|
9
9
|
const JSX_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx", ".mdx"]);
|
|
10
10
|
const IMPORT_STATEMENTS = {
|
|
@@ -131,7 +131,7 @@ function jsx({ settings, logging }) {
|
|
|
131
131
|
return null;
|
|
132
132
|
}
|
|
133
133
|
const { mode } = viteConfig;
|
|
134
|
-
if (id.includes(".mdx") || id
|
|
134
|
+
if (id.includes(".mdx") || isMarkdownFile(id, { criteria: "includes" })) {
|
|
135
135
|
const { code: jsxCode2 } = await esbuild.transform(code, {
|
|
136
136
|
loader: getEsbuildLoader(path.extname(id)),
|
|
137
137
|
jsx: "preserve",
|
|
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
7
7
|
import { warn } from "../core/logger/core.js";
|
|
8
|
+
import { isMarkdownFile } from "../core/util.js";
|
|
8
9
|
import { getFileInfo, safelyGetAstroData } from "../vite-plugin-utils/index.js";
|
|
9
10
|
function safeMatter(source, id) {
|
|
10
11
|
try {
|
|
@@ -22,7 +23,7 @@ function markdown({ settings, logging }) {
|
|
|
22
23
|
enforce: "pre",
|
|
23
24
|
name: "astro:markdown",
|
|
24
25
|
async load(id) {
|
|
25
|
-
if (id
|
|
26
|
+
if (isMarkdownFile(id, { criteria: "endsWith" })) {
|
|
26
27
|
const { fileId, fileUrl } = getFileInfo(id, settings.config);
|
|
27
28
|
const rawFile = await fs.promises.readFile(fileId, "utf-8");
|
|
28
29
|
const raw = safeMatter(rawFile, id);
|
|
@@ -43,7 +44,7 @@ function markdown({ settings, logging }) {
|
|
|
43
44
|
warn(
|
|
44
45
|
logging,
|
|
45
46
|
"markdown",
|
|
46
|
-
`[${id}] Astro now supports MDX! Support for components in ".md" files using the "setup" frontmatter is no longer enabled by default. Migrate this file to MDX or add the "legacy.astroFlavoredMarkdown" config flag to re-enable support.`
|
|
47
|
+
`[${id}] Astro now supports MDX! Support for components in ".md" (or alternative extensions like ".markdown") files using the "setup" frontmatter is no longer enabled by default. Migrate this file to MDX or add the "legacy.astroFlavoredMarkdown" config flag to re-enable support.`
|
|
47
48
|
);
|
|
48
49
|
}
|
|
49
50
|
const code = escapeViteEnvReferences(`
|
|
@@ -7,6 +7,7 @@ import { fileURLToPath } from "url";
|
|
|
7
7
|
import { pagesVirtualModuleId } from "../core/app/index.js";
|
|
8
8
|
import { cachedCompilation } from "../core/compile/index.js";
|
|
9
9
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
10
|
+
import { isMarkdownFile } from "../core/util.js";
|
|
10
11
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
11
12
|
import {
|
|
12
13
|
createTransformStyles,
|
|
@@ -57,11 +58,11 @@ function markdown({ settings }) {
|
|
|
57
58
|
styleTransformer.viteDevServer = server;
|
|
58
59
|
},
|
|
59
60
|
async resolveId(id, importer, options) {
|
|
60
|
-
if (id
|
|
61
|
+
if (isMarkdownFile(id, { criteria: "endsWith", suffix: MARKDOWN_CONTENT_FLAG })) {
|
|
61
62
|
const resolvedId = await this.resolve(id, importer, { skipSelf: true, ...options });
|
|
62
63
|
return resolvedId == null ? void 0 : resolvedId.id.replace(MARKDOWN_CONTENT_FLAG, "");
|
|
63
64
|
}
|
|
64
|
-
if (id
|
|
65
|
+
if (isMarkdownFile(id, { criteria: "endsWith" }) && !isRootImport(importer)) {
|
|
65
66
|
const resolvedId = await this.resolve(id, importer, { skipSelf: true, ...options });
|
|
66
67
|
if (resolvedId) {
|
|
67
68
|
return resolvedId.id + MARKDOWN_IMPORT_FLAG;
|
|
@@ -70,7 +71,7 @@ function markdown({ settings }) {
|
|
|
70
71
|
return void 0;
|
|
71
72
|
},
|
|
72
73
|
async load(id, opts) {
|
|
73
|
-
if (id
|
|
74
|
+
if (isMarkdownFile(id, { criteria: "endsWith", suffix: MARKDOWN_IMPORT_FLAG })) {
|
|
74
75
|
const { fileId, fileUrl } = getFileInfo(id, config);
|
|
75
76
|
const source = await fs.promises.readFile(fileId, "utf8");
|
|
76
77
|
const { data: frontmatter, content: rawContent } = safeMatter(source, fileId);
|
|
@@ -86,9 +87,6 @@ function markdown({ settings }) {
|
|
|
86
87
|
export async function compiledContent() {
|
|
87
88
|
return load().then((m) => m.compiledContent());
|
|
88
89
|
}
|
|
89
|
-
export function $$loadMetadata() {
|
|
90
|
-
return load().then((m) => m.$$metadata);
|
|
91
|
-
}
|
|
92
90
|
|
|
93
91
|
// Deferred
|
|
94
92
|
export default async function load() {
|
|
@@ -108,7 +106,7 @@ function markdown({ settings }) {
|
|
|
108
106
|
map: null
|
|
109
107
|
};
|
|
110
108
|
}
|
|
111
|
-
if (id
|
|
109
|
+
if (isMarkdownFile(id, { criteria: "endsWith" })) {
|
|
112
110
|
const filename = normalizeFilename(id);
|
|
113
111
|
const source = await fs.promises.readFile(filename, "utf8");
|
|
114
112
|
const renderOpts = config.markdown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"default": "./astro.js"
|
|
30
30
|
},
|
|
31
31
|
"./env": "./env.d.ts",
|
|
32
|
+
"./types": "./types.d.ts",
|
|
32
33
|
"./client": "./client.d.ts",
|
|
33
34
|
"./client-base": "./client-base.d.ts",
|
|
34
35
|
"./import-meta": "./import-meta.d.ts",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
"vendor"
|
|
86
87
|
],
|
|
87
88
|
"dependencies": {
|
|
88
|
-
"@astrojs/compiler": "^0.
|
|
89
|
+
"@astrojs/compiler": "^0.28.0",
|
|
89
90
|
"@astrojs/language-server": "^0.26.2",
|
|
90
91
|
"@astrojs/markdown-remark": "^1.1.3",
|
|
91
92
|
"@astrojs/telemetry": "^1.0.1",
|
|
@@ -144,6 +145,7 @@
|
|
|
144
145
|
"unist-util-visit": "^4.1.0",
|
|
145
146
|
"vfile": "^5.3.2",
|
|
146
147
|
"vite": "~3.1.3",
|
|
148
|
+
"vitefu": "^0.1.0",
|
|
147
149
|
"yargs-parser": "^21.0.1",
|
|
148
150
|
"zod": "^3.17.3"
|
|
149
151
|
},
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
interface ModuleInfo {
|
|
2
|
-
module: Record<string, any>;
|
|
3
|
-
specifier: string;
|
|
4
|
-
}
|
|
5
|
-
interface CreateMetadataOptions {
|
|
6
|
-
modules: ModuleInfo[];
|
|
7
|
-
hydratedComponents: any[];
|
|
8
|
-
clientOnlyComponents: any[];
|
|
9
|
-
hydrationDirectives: Set<string>;
|
|
10
|
-
hoisted: any[];
|
|
11
|
-
}
|
|
12
|
-
export declare class Metadata {
|
|
13
|
-
filePath: string;
|
|
14
|
-
modules: ModuleInfo[];
|
|
15
|
-
hoisted: any[];
|
|
16
|
-
hydratedComponents: any[];
|
|
17
|
-
clientOnlyComponents: any[];
|
|
18
|
-
hydrationDirectives: Set<string>;
|
|
19
|
-
private mockURL;
|
|
20
|
-
private metadataCache;
|
|
21
|
-
constructor(filePathname: string, opts: CreateMetadataOptions);
|
|
22
|
-
resolvePath(specifier: string): string;
|
|
23
|
-
getPath(Component: any): string | null;
|
|
24
|
-
getExport(Component: any): string | null;
|
|
25
|
-
private getComponentMetadata;
|
|
26
|
-
private findComponentMetadata;
|
|
27
|
-
}
|
|
28
|
-
export declare function createMetadata(filePathname: string, options: CreateMetadataOptions): Metadata;
|
|
29
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { removeLeadingForwardSlashWindows } from "../../core/path.js";
|
|
2
|
-
class Metadata {
|
|
3
|
-
constructor(filePathname, opts) {
|
|
4
|
-
this.modules = opts.modules;
|
|
5
|
-
this.hoisted = opts.hoisted;
|
|
6
|
-
this.hydratedComponents = opts.hydratedComponents;
|
|
7
|
-
this.clientOnlyComponents = opts.clientOnlyComponents;
|
|
8
|
-
this.hydrationDirectives = opts.hydrationDirectives;
|
|
9
|
-
this.filePath = removeLeadingForwardSlashWindows(filePathname);
|
|
10
|
-
this.mockURL = new URL(filePathname, "http://example.com");
|
|
11
|
-
this.metadataCache = /* @__PURE__ */ new Map();
|
|
12
|
-
}
|
|
13
|
-
resolvePath(specifier) {
|
|
14
|
-
if (specifier.startsWith(".")) {
|
|
15
|
-
const url = new URL(specifier, this.mockURL);
|
|
16
|
-
return removeLeadingForwardSlashWindows(decodeURI(url.pathname));
|
|
17
|
-
} else {
|
|
18
|
-
return specifier;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
getPath(Component) {
|
|
22
|
-
const metadata = this.getComponentMetadata(Component);
|
|
23
|
-
return (metadata == null ? void 0 : metadata.componentUrl) || null;
|
|
24
|
-
}
|
|
25
|
-
getExport(Component) {
|
|
26
|
-
const metadata = this.getComponentMetadata(Component);
|
|
27
|
-
return (metadata == null ? void 0 : metadata.componentExport) || null;
|
|
28
|
-
}
|
|
29
|
-
getComponentMetadata(Component) {
|
|
30
|
-
if (this.metadataCache.has(Component)) {
|
|
31
|
-
return this.metadataCache.get(Component);
|
|
32
|
-
}
|
|
33
|
-
const metadata = this.findComponentMetadata(Component);
|
|
34
|
-
this.metadataCache.set(Component, metadata);
|
|
35
|
-
return metadata;
|
|
36
|
-
}
|
|
37
|
-
findComponentMetadata(Component) {
|
|
38
|
-
const isCustomElement = typeof Component === "string";
|
|
39
|
-
for (const { module, specifier } of this.modules) {
|
|
40
|
-
const id = this.resolvePath(specifier);
|
|
41
|
-
for (const [key, value] of Object.entries(module)) {
|
|
42
|
-
if (isCustomElement) {
|
|
43
|
-
if (key === "tagName" && Component === value) {
|
|
44
|
-
return {
|
|
45
|
-
componentExport: key,
|
|
46
|
-
componentUrl: id
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
} else if (Component === value) {
|
|
50
|
-
return {
|
|
51
|
-
componentExport: key,
|
|
52
|
-
componentUrl: id
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function createMetadata(filePathname, options) {
|
|
61
|
-
return new Metadata(filePathname, options);
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
Metadata,
|
|
65
|
-
createMetadata
|
|
66
|
-
};
|