astro 1.7.2 → 1.8.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/dist/@types/astro.d.ts +20 -0
- package/dist/cli/index.js +8 -0
- package/dist/cli/sync/index.d.ts +8 -0
- package/dist/cli/sync/index.js +25 -0
- package/dist/content/index.d.ts +2 -0
- package/dist/content/index.js +6 -1
- package/dist/content/types-generator.d.ts +2 -3
- package/dist/content/types-generator.js +6 -4
- package/dist/content/vite-plugin-content-server.js +1 -2
- package/dist/core/build/generate.js +4 -1
- package/dist/core/build/vite-plugin-pages.js +2 -2
- package/dist/core/build/vite-plugin-ssr.js +4 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +1 -1
- package/dist/core/dev/container.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +22 -0
- package/dist/core/errors/errors-data.js +10 -0
- package/dist/core/errors/utils.d.ts +8 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/environment.js +4 -1
- package/dist/core/render/environment.js +4 -1
- package/dist/vite-plugin-astro-postprocess/index.js +28 -34
- package/dist/vite-plugin-env/index.js +2 -2
- package/dist/vite-plugin-markdown/index.js +5 -2
- package/dist/vite-plugin-markdown-legacy/index.js +7 -4
- package/package.json +4 -3
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
3
4
|
import type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
|
|
4
5
|
import type * as babel from '@babel/core';
|
|
6
|
+
import type { OutgoingHttpHeaders } from 'http';
|
|
5
7
|
import type { AddressInfo } from 'net';
|
|
6
8
|
import type { TsConfigJson } from 'tsconfig-resolver';
|
|
7
9
|
import type * as vite from 'vite';
|
|
@@ -287,6 +289,15 @@ declare type ServerConfig = {
|
|
|
287
289
|
* If the given port is already in use, Astro will automatically try the next available port.
|
|
288
290
|
*/
|
|
289
291
|
port?: number;
|
|
292
|
+
/**
|
|
293
|
+
* @name server.headers
|
|
294
|
+
* @typeraw {OutgoingHttpHeaders}
|
|
295
|
+
* @default `{}`
|
|
296
|
+
* @version 1.7.0
|
|
297
|
+
* @description
|
|
298
|
+
* Set custom HTTP response headers to be sent in `astro dev` and `astro preview`.
|
|
299
|
+
*/
|
|
300
|
+
headers?: OutgoingHttpHeaders;
|
|
290
301
|
};
|
|
291
302
|
export interface ViteUserConfig extends vite.UserConfig {
|
|
292
303
|
ssr?: vite.SSROptions;
|
|
@@ -618,6 +629,15 @@ export interface AstroUserConfig {
|
|
|
618
629
|
* }
|
|
619
630
|
* ```
|
|
620
631
|
*/
|
|
632
|
+
/**
|
|
633
|
+
* @docs
|
|
634
|
+
* @name server.headers
|
|
635
|
+
* @typeraw {OutgoingHttpHeaders}
|
|
636
|
+
* @default `{}`
|
|
637
|
+
* @version 1.7.0
|
|
638
|
+
* @description
|
|
639
|
+
* Set custom HTTP response headers to be sent in `astro dev` and `astro preview`.
|
|
640
|
+
*/
|
|
621
641
|
server?: ServerConfig | ((options: {
|
|
622
642
|
command: 'dev' | 'preview';
|
|
623
643
|
}) => ServerConfig);
|
package/dist/cli/index.js
CHANGED
|
@@ -31,6 +31,7 @@ function printAstroHelp() {
|
|
|
31
31
|
["dev", "Start the development server."],
|
|
32
32
|
["docs", "Open documentation in your web browser."],
|
|
33
33
|
["preview", "Preview your build locally."],
|
|
34
|
+
["sync", "Generate content collection types."],
|
|
34
35
|
["telemetry", "Configure telemetry settings."]
|
|
35
36
|
],
|
|
36
37
|
"Global Flags": [
|
|
@@ -54,6 +55,8 @@ function resolveCommand(flags) {
|
|
|
54
55
|
const cmd = flags._[2];
|
|
55
56
|
if (cmd === "add")
|
|
56
57
|
return "add";
|
|
58
|
+
if (cmd === "sync")
|
|
59
|
+
return "sync";
|
|
57
60
|
if (cmd === "telemetry")
|
|
58
61
|
return "telemetry";
|
|
59
62
|
if (flags.version)
|
|
@@ -153,6 +156,11 @@ async function runCommand(cmd, flags) {
|
|
|
153
156
|
const ret = await check(settings);
|
|
154
157
|
return process.exit(ret);
|
|
155
158
|
}
|
|
159
|
+
case "sync": {
|
|
160
|
+
const { sync } = await import("./sync/index.js");
|
|
161
|
+
const ret = await sync(settings, { logging, fs });
|
|
162
|
+
return process.exit(ret);
|
|
163
|
+
}
|
|
156
164
|
case "preview": {
|
|
157
165
|
const { default: preview } = await import("../core/preview/index.js");
|
|
158
166
|
const server = await preview(settings, { logging, telemetry });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fsMod from 'node:fs';
|
|
3
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
4
|
+
import { LogOptions } from '../../core/logger/core.js';
|
|
5
|
+
export declare function sync(settings: AstroSettings, { logging, fs }: {
|
|
6
|
+
logging: LogOptions;
|
|
7
|
+
fs: typeof fsMod;
|
|
8
|
+
}): Promise<0 | 1>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { dim } from "kleur/colors";
|
|
2
|
+
import { performance } from "node:perf_hooks";
|
|
3
|
+
import { contentObservable, createContentTypesGenerator } from "../../content/index.js";
|
|
4
|
+
import { getTimeStat } from "../../core/build/util.js";
|
|
5
|
+
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
6
|
+
import { info } from "../../core/logger/core.js";
|
|
7
|
+
async function sync(settings, { logging, fs }) {
|
|
8
|
+
const timerStart = performance.now();
|
|
9
|
+
try {
|
|
10
|
+
const contentTypesGenerator = await createContentTypesGenerator({
|
|
11
|
+
contentConfigObserver: contentObservable({ status: "loading" }),
|
|
12
|
+
logging,
|
|
13
|
+
fs,
|
|
14
|
+
settings
|
|
15
|
+
});
|
|
16
|
+
await contentTypesGenerator.init();
|
|
17
|
+
} catch (e) {
|
|
18
|
+
throw new AstroError(AstroErrorData.GenerateContentTypesError);
|
|
19
|
+
}
|
|
20
|
+
info(logging, "content", `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
sync
|
|
25
|
+
};
|
package/dist/content/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { createContentTypesGenerator } from './types-generator.js';
|
|
2
|
+
export { contentObservable, getContentPaths } from './utils.js';
|
|
1
3
|
export { astroBundleDelayedAssetPlugin, astroDelayedAssetPlugin, } from './vite-plugin-content-assets.js';
|
|
2
4
|
export { astroContentServerPlugin } from './vite-plugin-content-server.js';
|
|
3
5
|
export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
|
package/dist/content/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createContentTypesGenerator } from "./types-generator.js";
|
|
2
|
+
import { contentObservable, getContentPaths } from "./utils.js";
|
|
1
3
|
import {
|
|
2
4
|
astroBundleDelayedAssetPlugin,
|
|
3
5
|
astroDelayedAssetPlugin
|
|
@@ -8,5 +10,8 @@ export {
|
|
|
8
10
|
astroBundleDelayedAssetPlugin,
|
|
9
11
|
astroContentServerPlugin,
|
|
10
12
|
astroContentVirtualModPlugin,
|
|
11
|
-
astroDelayedAssetPlugin
|
|
13
|
+
astroDelayedAssetPlugin,
|
|
14
|
+
contentObservable,
|
|
15
|
+
createContentTypesGenerator,
|
|
16
|
+
getContentPaths
|
|
12
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import fsMod from 'node:fs';
|
|
2
|
+
import type fsMod from 'node:fs';
|
|
3
3
|
import type { AstroSettings } from '../@types/astro.js';
|
|
4
4
|
import { LogOptions } from '../core/logger/core.js';
|
|
5
5
|
import { ContentObservable, ContentPaths } from './utils.js';
|
|
@@ -18,13 +18,12 @@ export declare type GenerateContentTypes = {
|
|
|
18
18
|
queueEvent(event: RawContentEvent): void;
|
|
19
19
|
};
|
|
20
20
|
declare type CreateContentGeneratorParams = {
|
|
21
|
-
contentPaths: ContentPaths;
|
|
22
21
|
contentConfigObserver: ContentObservable;
|
|
23
22
|
logging: LogOptions;
|
|
24
23
|
settings: AstroSettings;
|
|
25
24
|
fs: typeof fsMod;
|
|
26
25
|
};
|
|
27
|
-
export declare function createContentTypesGenerator({
|
|
26
|
+
export declare function createContentTypesGenerator({ contentConfigObserver, fs, logging, settings, }: CreateContentGeneratorParams): Promise<GenerateContentTypes>;
|
|
28
27
|
export declare function getEntryInfo({ entry, contentDir, }: Pick<ContentPaths, 'contentDir'> & {
|
|
29
28
|
entry: URL;
|
|
30
29
|
}): EntryInfo | Error;
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import glob from "fast-glob";
|
|
2
2
|
import { cyan } from "kleur/colors";
|
|
3
|
-
import fsMod from "node:fs";
|
|
4
3
|
import * as path from "node:path";
|
|
5
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
5
|
import { normalizePath } from "vite";
|
|
7
6
|
import { info, warn } from "../core/logger/core.js";
|
|
8
7
|
import { appendForwardSlash, isRelativePath } from "../core/path.js";
|
|
9
8
|
import { contentFileExts, CONTENT_TYPES_FILE } from "./consts.js";
|
|
10
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getContentPaths,
|
|
11
|
+
loadContentConfig
|
|
12
|
+
} from "./utils.js";
|
|
11
13
|
class UnsupportedFileTypeError extends Error {
|
|
12
14
|
}
|
|
13
15
|
async function createContentTypesGenerator({
|
|
14
|
-
contentPaths,
|
|
15
16
|
contentConfigObserver,
|
|
16
17
|
fs,
|
|
17
18
|
logging,
|
|
18
19
|
settings
|
|
19
20
|
}) {
|
|
20
21
|
const contentTypes = {};
|
|
22
|
+
const contentPaths = getContentPaths({ srcDir: settings.config.srcDir });
|
|
21
23
|
let events = [];
|
|
22
24
|
let debounceTimeout;
|
|
23
|
-
const contentTypesBase = await
|
|
25
|
+
const contentTypesBase = await fs.promises.readFile(
|
|
24
26
|
new URL(CONTENT_TYPES_FILE, contentPaths.generatedInputDir),
|
|
25
27
|
"utf-8"
|
|
26
28
|
);
|
|
@@ -3,6 +3,7 @@ import * as colors from "kleur/colors";
|
|
|
3
3
|
import { bgGreen, black, cyan, dim, green, magenta } from "kleur/colors";
|
|
4
4
|
import npath from "path";
|
|
5
5
|
import { fileURLToPath } from "url";
|
|
6
|
+
import { getContentPaths } from "../../content/index.js";
|
|
6
7
|
import { hasPrerenderedPages } from "../../core/build/internal.js";
|
|
7
8
|
import {
|
|
8
9
|
prependForwardSlash,
|
|
@@ -237,7 +238,9 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
237
238
|
logging,
|
|
238
239
|
markdown: {
|
|
239
240
|
...settings.config.markdown,
|
|
240
|
-
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
|
|
241
|
+
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown,
|
|
242
|
+
isExperimentalContentCollections: settings.config.experimental.contentCollections,
|
|
243
|
+
contentDir: getContentPaths(settings.config).contentDir
|
|
241
244
|
},
|
|
242
245
|
mode: opts.mode,
|
|
243
246
|
renderers,
|
|
@@ -21,8 +21,8 @@ function vitePluginPages(opts, internals) {
|
|
|
21
21
|
let i = 0;
|
|
22
22
|
for (const pageData of eachPageData(internals)) {
|
|
23
23
|
const variable = `_page${i}`;
|
|
24
|
-
imports.push(`import * as ${variable} from
|
|
25
|
-
importMap += `[
|
|
24
|
+
imports.push(`import * as ${variable} from ${JSON.stringify(pageData.moduleSpecifier)};`);
|
|
25
|
+
importMap += `[${JSON.stringify(pageData.component)}, ${variable}],`;
|
|
26
26
|
i++;
|
|
27
27
|
}
|
|
28
28
|
i = 0;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import glob from "fast-glob";
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
+
import { getContentPaths } from "../../content/index.js";
|
|
4
5
|
import { runHookBuildSsr } from "../../integrations/index.js";
|
|
5
6
|
import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
6
7
|
import { pagesVirtualModuleId } from "../app/index.js";
|
|
@@ -168,7 +169,9 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
168
169
|
base: settings.config.base,
|
|
169
170
|
markdown: {
|
|
170
171
|
...settings.config.markdown,
|
|
171
|
-
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
|
|
172
|
+
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown,
|
|
173
|
+
isExperimentalContentCollections: settings.config.experimental.contentCollections,
|
|
174
|
+
contentDir: getContentPaths(settings.config).contentDir
|
|
172
175
|
},
|
|
173
176
|
pageMap: null,
|
|
174
177
|
renderers: [],
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -93,7 +93,7 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
|
|
|
93
93
|
root: fileURLToPath(settings.config.root),
|
|
94
94
|
envPrefix: "PUBLIC_",
|
|
95
95
|
define: {
|
|
96
|
-
"import.meta.env.SITE": settings.config.site ?
|
|
96
|
+
"import.meta.env.SITE": settings.config.site ? JSON.stringify(settings.config.site) : "undefined"
|
|
97
97
|
},
|
|
98
98
|
server: {
|
|
99
99
|
hmr: process.env.NODE_ENV === "test" || process.env.NODE_ENV === "production" ? false : void 0,
|
|
@@ -40,7 +40,7 @@ async function createContainer(params = {}) {
|
|
|
40
40
|
include: rendererClientEntries
|
|
41
41
|
},
|
|
42
42
|
define: {
|
|
43
|
-
"import.meta.env.BASE_URL": settings.config.base ?
|
|
43
|
+
"import.meta.env.BASE_URL": settings.config.base ? JSON.stringify(settings.config.base) : "undefined"
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
{ settings, logging, mode: "dev", fs }
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -30,7 +30,7 @@ async function dev(settings, options) {
|
|
|
30
30
|
isRestart: options.isRestart
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
|
-
const currentVersion = "1.
|
|
33
|
+
const currentVersion = "1.8.0";
|
|
34
34
|
if (currentVersion.includes("-")) {
|
|
35
35
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
36
36
|
}
|
|
@@ -479,6 +479,28 @@ export declare const AstroErrorData: {
|
|
|
479
479
|
readonly message: (legacyConfigKey: string) => string;
|
|
480
480
|
readonly hint: "Please update your configuration to the new format.\nSee https://astro.build/config for more information.";
|
|
481
481
|
};
|
|
482
|
+
/**
|
|
483
|
+
* @docs
|
|
484
|
+
* @kind heading
|
|
485
|
+
* @name CLI Errors
|
|
486
|
+
*/
|
|
487
|
+
readonly UnknownCLIError: {
|
|
488
|
+
readonly title: "Unknown CLI Error.";
|
|
489
|
+
readonly code: 8000;
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* @docs
|
|
493
|
+
* @description
|
|
494
|
+
* `astro sync` command failed to generate content collection types.
|
|
495
|
+
* @see
|
|
496
|
+
* - [Content collections documentation](https://docs.astro.build/en/guides/content-collections/)
|
|
497
|
+
*/
|
|
498
|
+
readonly GenerateContentTypesError: {
|
|
499
|
+
readonly title: "Failed to generate content types.";
|
|
500
|
+
readonly code: 8001;
|
|
501
|
+
readonly message: "`astro sync` command failed to generate content collection types.";
|
|
502
|
+
readonly hint: "Check your `src/content/config.*` file for typos.";
|
|
503
|
+
};
|
|
482
504
|
readonly UnknownError: {
|
|
483
505
|
readonly title: "Unknown Error.";
|
|
484
506
|
readonly code: 99999;
|
|
@@ -190,6 +190,16 @@ Expected \`true\` value but got \`${suffix}\`.`;
|
|
|
190
190
|
message: (legacyConfigKey) => `Legacy configuration detected: \`${legacyConfigKey}\`.`,
|
|
191
191
|
hint: "Please update your configuration to the new format.\nSee https://astro.build/config for more information."
|
|
192
192
|
},
|
|
193
|
+
UnknownCLIError: {
|
|
194
|
+
title: "Unknown CLI Error.",
|
|
195
|
+
code: 8e3
|
|
196
|
+
},
|
|
197
|
+
GenerateContentTypesError: {
|
|
198
|
+
title: "Failed to generate content types.",
|
|
199
|
+
code: 8001,
|
|
200
|
+
message: "`astro sync` command failed to generate content collection types.",
|
|
201
|
+
hint: "Check your `src/content/config.*` file for typos."
|
|
202
|
+
},
|
|
193
203
|
UnknownError: {
|
|
194
204
|
title: "Unknown Error.",
|
|
195
205
|
code: 99999
|
|
@@ -151,6 +151,14 @@ export declare function getErrorDataByCode(code: AstroErrorCodes | DiagnosticCod
|
|
|
151
151
|
readonly code: 7002;
|
|
152
152
|
readonly message: (legacyConfigKey: string) => string;
|
|
153
153
|
readonly hint: "Please update your configuration to the new format.\nSee https://astro.build/config for more information.";
|
|
154
|
+
} | {
|
|
155
|
+
readonly title: "Unknown CLI Error.";
|
|
156
|
+
readonly code: 8000;
|
|
157
|
+
} | {
|
|
158
|
+
readonly title: "Failed to generate content types.";
|
|
159
|
+
readonly code: 8001;
|
|
160
|
+
readonly message: "`astro sync` command failed to generate content collection types.";
|
|
161
|
+
readonly hint: "Check your `src/content/config.*` file for typos.";
|
|
154
162
|
} | {
|
|
155
163
|
readonly title: "Unknown Error.";
|
|
156
164
|
readonly code: 99999;
|
package/dist/core/messages.js
CHANGED
|
@@ -49,7 +49,7 @@ function serverStart({
|
|
|
49
49
|
site,
|
|
50
50
|
isRestart = false
|
|
51
51
|
}) {
|
|
52
|
-
const version = "1.
|
|
52
|
+
const version = "1.8.0";
|
|
53
53
|
const rootPath = site ? site.pathname : "/";
|
|
54
54
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
55
55
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -272,7 +272,7 @@ function printHelp({
|
|
|
272
272
|
message.push(
|
|
273
273
|
linebreak(),
|
|
274
274
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
275
|
-
`v${"1.
|
|
275
|
+
`v${"1.8.0"}`
|
|
276
276
|
)} ${headline}`
|
|
277
277
|
);
|
|
278
278
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getContentPaths } from "../../../content/index.js";
|
|
1
2
|
import { createEnvironment } from "../index.js";
|
|
2
3
|
import { RouteCache } from "../route-cache.js";
|
|
3
4
|
import { createResolve } from "./resolve.js";
|
|
@@ -9,7 +10,9 @@ function createDevelopmentEnvironment(settings, logging, loader) {
|
|
|
9
10
|
logging,
|
|
10
11
|
markdown: {
|
|
11
12
|
...settings.config.markdown,
|
|
12
|
-
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
|
|
13
|
+
isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown,
|
|
14
|
+
isExperimentalContentCollections: settings.config.experimental.contentCollections,
|
|
15
|
+
contentDir: getContentPaths(settings.config).contentDir
|
|
13
16
|
},
|
|
14
17
|
mode,
|
|
15
18
|
renderers: [],
|
|
@@ -6,7 +6,10 @@ function createBasicEnvironment(options) {
|
|
|
6
6
|
const mode = options.mode ?? "development";
|
|
7
7
|
return createEnvironment({
|
|
8
8
|
...options,
|
|
9
|
-
markdown:
|
|
9
|
+
markdown: {
|
|
10
|
+
...options.markdown ?? {},
|
|
11
|
+
contentDir: new URL("file:///src/content/")
|
|
12
|
+
},
|
|
10
13
|
mode,
|
|
11
14
|
renderers: options.renderers ?? [],
|
|
12
15
|
resolve: options.resolve ?? ((s) => Promise.resolve(s)),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { parse
|
|
2
|
-
import {
|
|
1
|
+
import { parse } from "acorn";
|
|
2
|
+
import { walk } from "estree-walker";
|
|
3
|
+
import MagicString from "magic-string";
|
|
3
4
|
import { isMarkdownFile } from "../core/util.js";
|
|
4
5
|
const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
|
|
5
6
|
function astro(_opts) {
|
|
@@ -12,43 +13,36 @@ function astro(_opts) {
|
|
|
12
13
|
if (!ASTRO_GLOB_REGEX.test(code)) {
|
|
13
14
|
return null;
|
|
14
15
|
}
|
|
16
|
+
let s;
|
|
15
17
|
const ast = parse(code, {
|
|
16
|
-
|
|
18
|
+
ecmaVersion: "latest",
|
|
19
|
+
sourceType: "module"
|
|
17
20
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
{
|
|
28
|
-
type: "CallExpression",
|
|
29
|
-
callee: {
|
|
30
|
-
type: "MemberExpression",
|
|
31
|
-
object: {
|
|
32
|
-
type: "MetaProperty",
|
|
33
|
-
meta: { type: "Identifier", name: "import" },
|
|
34
|
-
property: { type: "Identifier", name: "meta" }
|
|
35
|
-
},
|
|
36
|
-
property: { type: "Identifier", name: "glob" },
|
|
37
|
-
computed: false
|
|
38
|
-
},
|
|
39
|
-
arguments: [args]
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: "ArrowFunctionExpression",
|
|
43
|
-
body: args,
|
|
44
|
-
params: []
|
|
21
|
+
walk(ast, {
|
|
22
|
+
enter(node) {
|
|
23
|
+
if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.property.name === "glob" && (node.callee.object.name === "Astro" || node.callee.object.name === "Astro2") && node.arguments.length) {
|
|
24
|
+
const firstArgStart = node.arguments[0].start;
|
|
25
|
+
const firstArgEnd = node.arguments[0].end;
|
|
26
|
+
const lastArgEnd = node.arguments[node.arguments.length - 1].end;
|
|
27
|
+
let firstArg = code.slice(firstArgStart, firstArgEnd);
|
|
28
|
+
if (firstArg.startsWith("`") && firstArg.endsWith("`") && !firstArg.includes("${")) {
|
|
29
|
+
firstArg = JSON.stringify(firstArg.slice(1, -1));
|
|
45
30
|
}
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
s ?? (s = new MagicString(code));
|
|
32
|
+
s.overwrite(
|
|
33
|
+
firstArgStart,
|
|
34
|
+
lastArgEnd,
|
|
35
|
+
`import.meta.glob(${firstArg}), () => ${firstArg}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
48
38
|
}
|
|
49
39
|
});
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
if (s) {
|
|
41
|
+
return {
|
|
42
|
+
code: s.toString(),
|
|
43
|
+
map: s.generateMap()
|
|
44
|
+
};
|
|
45
|
+
}
|
|
52
46
|
}
|
|
53
47
|
};
|
|
54
48
|
}
|
|
@@ -21,9 +21,9 @@ function getPrivateEnv(viteConfig, astroConfig) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
privateEnv.SITE = astroConfig.site ?
|
|
24
|
+
privateEnv.SITE = astroConfig.site ? JSON.stringify(astroConfig.site) : "undefined";
|
|
25
25
|
privateEnv.SSR = JSON.stringify(true);
|
|
26
|
-
privateEnv.BASE_URL = astroConfig.base ?
|
|
26
|
+
privateEnv.BASE_URL = astroConfig.base ? JSON.stringify(astroConfig.base) : "undefined";
|
|
27
27
|
return privateEnv;
|
|
28
28
|
}
|
|
29
29
|
function getReferencedPrivateKeys(source, privateEnv) {
|
|
@@ -3,6 +3,7 @@ import fs from "fs";
|
|
|
3
3
|
import matter from "gray-matter";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
|
+
import { getContentPaths } from "../content/index.js";
|
|
6
7
|
import { AstroErrorData, MarkdownError } from "../core/errors/index.js";
|
|
7
8
|
import { warn } from "../core/logger/core.js";
|
|
8
9
|
import { isMarkdownFile } from "../core/util.js";
|
|
@@ -50,7 +51,9 @@ function markdown({ settings, logging }) {
|
|
|
50
51
|
const renderResult = await renderMarkdown(raw.content, {
|
|
51
52
|
...settings.config.markdown,
|
|
52
53
|
fileURL: new URL(`file://${fileId}`),
|
|
53
|
-
isAstroFlavoredMd: false
|
|
54
|
+
isAstroFlavoredMd: false,
|
|
55
|
+
isExperimentalContentCollections: settings.config.experimental.contentCollections,
|
|
56
|
+
contentDir: getContentPaths(settings.config).contentDir
|
|
54
57
|
});
|
|
55
58
|
const html = renderResult.code;
|
|
56
59
|
const { headings } = renderResult.metadata;
|
|
@@ -68,7 +71,7 @@ function markdown({ settings, logging }) {
|
|
|
68
71
|
);
|
|
69
72
|
}
|
|
70
73
|
const code = escapeViteEnvReferences(`
|
|
71
|
-
import { Fragment, jsx as h } from
|
|
74
|
+
import { Fragment, jsx as h } from ${JSON.stringify(astroJsxRuntimeModulePath)};
|
|
72
75
|
${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
|
|
73
76
|
|
|
74
77
|
const html = ${JSON.stringify(html)};
|
|
@@ -3,6 +3,7 @@ import fs from "fs";
|
|
|
3
3
|
import matter from "gray-matter";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { transformWithEsbuild } from "vite";
|
|
6
|
+
import { getContentPaths } from "../content/index.js";
|
|
6
7
|
import { pagesVirtualModuleId } from "../core/app/index.js";
|
|
7
8
|
import { cachedCompilation } from "../core/compile/index.js";
|
|
8
9
|
import { AstroErrorData, MarkdownError } from "../core/errors/index.js";
|
|
@@ -115,7 +116,9 @@ function markdown({ settings }) {
|
|
|
115
116
|
let renderResult = await renderMarkdown(markdownContent, {
|
|
116
117
|
...renderOpts,
|
|
117
118
|
fileURL: fileUrl,
|
|
118
|
-
isAstroFlavoredMd: true
|
|
119
|
+
isAstroFlavoredMd: true,
|
|
120
|
+
isExperimentalContentCollections: settings.config.experimental.contentCollections,
|
|
121
|
+
contentDir: getContentPaths(settings.config).contentDir
|
|
119
122
|
});
|
|
120
123
|
let { code: astroResult, metadata } = renderResult;
|
|
121
124
|
const { layout = "", components = "", setup = "", ...content } = frontmatter;
|
|
@@ -124,8 +127,8 @@ function markdown({ settings }) {
|
|
|
124
127
|
content.file = filename;
|
|
125
128
|
const prelude = `---
|
|
126
129
|
import Slugger from 'github-slugger';
|
|
127
|
-
${layout ? `import Layout from
|
|
128
|
-
${components ? `import * from
|
|
130
|
+
${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
|
|
131
|
+
${components ? `import * from ${JSON.stringify(components)};` : ""}
|
|
129
132
|
${setup}
|
|
130
133
|
|
|
131
134
|
const slugger = new Slugger();
|
|
@@ -142,7 +145,7 @@ Object.defineProperty($$content.astro, 'headers', {
|
|
|
142
145
|
}
|
|
143
146
|
});
|
|
144
147
|
---`;
|
|
145
|
-
const imports = `${layout ? `import Layout from
|
|
148
|
+
const imports = `${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
|
|
146
149
|
${setup}`.trim();
|
|
147
150
|
if (/\bLayout\b/.test(imports)) {
|
|
148
151
|
astroResult = `${prelude}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"dependencies": {
|
|
98
98
|
"@astrojs/compiler": "^0.31.0",
|
|
99
99
|
"@astrojs/language-server": "^0.28.3",
|
|
100
|
-
"@astrojs/markdown-remark": "^1.
|
|
100
|
+
"@astrojs/markdown-remark": "^1.2.0",
|
|
101
101
|
"@astrojs/telemetry": "^1.0.1",
|
|
102
102
|
"@astrojs/webapi": "^1.1.1",
|
|
103
103
|
"@babel/core": "^7.18.2",
|
|
@@ -111,6 +111,7 @@
|
|
|
111
111
|
"@types/babel__core": "^7.1.19",
|
|
112
112
|
"@types/html-escaper": "^3.0.0",
|
|
113
113
|
"@types/yargs-parser": "^21.0.0",
|
|
114
|
+
"acorn": "^8.8.1",
|
|
114
115
|
"boxen": "^6.2.1",
|
|
115
116
|
"ci-info": "^3.3.1",
|
|
116
117
|
"common-ancestor-path": "^1.0.1",
|
|
@@ -120,6 +121,7 @@
|
|
|
120
121
|
"devalue": "^4.2.0",
|
|
121
122
|
"diff": "^5.1.0",
|
|
122
123
|
"es-module-lexer": "^1.1.0",
|
|
124
|
+
"estree-walker": "^3.0.1",
|
|
123
125
|
"execa": "^6.1.0",
|
|
124
126
|
"fast-glob": "^3.2.11",
|
|
125
127
|
"github-slugger": "^1.4.0",
|
|
@@ -179,7 +181,6 @@
|
|
|
179
181
|
"@types/rimraf": "^3.0.2",
|
|
180
182
|
"@types/send": "^0.17.1",
|
|
181
183
|
"@types/unist": "^2.0.6",
|
|
182
|
-
"ast-types": "^0.14.2",
|
|
183
184
|
"astro-scripts": "0.0.9",
|
|
184
185
|
"chai": "^4.3.6",
|
|
185
186
|
"cheerio": "^1.0.0-rc.11",
|