astro 5.0.0-beta.2 → 5.0.0-beta.3
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/components/viewtransitions.css +10 -0
- package/dist/actions/consts.d.ts +1 -1
- package/dist/actions/consts.js +1 -1
- package/dist/cli/add/index.js +12 -14
- package/dist/cli/install-package.js +4 -4
- package/dist/content/consts.d.ts +5 -3
- package/dist/content/consts.js +7 -3
- package/dist/content/content-layer.js +4 -7
- package/dist/content/loaders/file.d.ts +9 -2
- package/dist/content/loaders/file.js +30 -14
- package/dist/content/types-generator.js +16 -13
- package/dist/content/utils.d.ts +1 -2
- package/dist/content/utils.js +2 -2
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -3
- package/dist/content/vite-plugin-content-virtual-mod.js +18 -75
- package/dist/core/app/index.d.ts +1 -1
- package/dist/core/build/generate.js +1 -1
- package/dist/core/build/index.js +1 -10
- package/dist/core/build/internal.d.ts +0 -2
- package/dist/core/build/internal.js +0 -2
- package/dist/core/build/plugins/index.js +0 -2
- package/dist/core/build/plugins/plugin-manifest.js +1 -1
- package/dist/core/build/static-build.d.ts +1 -1
- package/dist/core/build/static-build.js +6 -42
- package/dist/core/config/schema.d.ts +0 -17
- package/dist/core/config/schema.js +0 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +2 -1
- package/dist/core/errors/dev/utils.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/util.d.ts +0 -1
- package/dist/core/util.js +1 -6
- package/dist/env/constants.d.ts +1 -1
- package/dist/env/constants.js +1 -1
- package/dist/integrations/hooks.d.ts +2 -2
- package/dist/integrations/hooks.js +12 -10
- package/dist/jsx/rehype.js +6 -2
- package/dist/preferences/constants.d.ts +1 -0
- package/dist/preferences/constants.js +4 -0
- package/dist/preferences/store.js +2 -1
- package/dist/transitions/router.js +4 -3
- package/dist/types/public/config.d.ts +0 -18
- package/dist/types/public/integrations.d.ts +1 -1
- package/dist/vite-plugin-astro/index.js +0 -5
- package/dist/vite-plugin-astro-server/plugin.js +2 -1
- package/dist/vite-plugin-markdown/content-entry-type.js +4 -4
- package/dist/vite-plugin-markdown/index.js +1 -1
- package/package.json +20 -22
- package/dist/core/build/plugins/plugin-content.d.ts +0 -5
- package/dist/core/build/plugins/plugin-content.js +0 -394
|
@@ -10,12 +10,22 @@
|
|
|
10
10
|
@keyframes astroFadeIn {
|
|
11
11
|
from {
|
|
12
12
|
opacity: 0;
|
|
13
|
+
mix-blend-mode: plus-lighter;
|
|
14
|
+
}
|
|
15
|
+
to {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
mix-blend-mode: plus-lighter;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
@keyframes astroFadeOut {
|
|
22
|
+
from {
|
|
23
|
+
opacity: 1;
|
|
24
|
+
mix-blend-mode: plus-lighter;
|
|
25
|
+
}
|
|
17
26
|
to {
|
|
18
27
|
opacity: 0;
|
|
28
|
+
mix-blend-mode: plus-lighter;
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
|
package/dist/actions/consts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const VIRTUAL_MODULE_ID = "astro:actions";
|
|
2
2
|
export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
|
|
3
|
-
export declare const ACTIONS_TYPES_FILE = "
|
|
3
|
+
export declare const ACTIONS_TYPES_FILE = "actions.d.ts";
|
|
4
4
|
export declare const VIRTUAL_INTERNAL_MODULE_ID = "astro:internal-actions";
|
|
5
5
|
export declare const RESOLVED_VIRTUAL_INTERNAL_MODULE_ID = "\0astro:internal-actions";
|
|
6
6
|
export declare const NOOP_ACTIONS = "\0noop-actions";
|
package/dist/actions/consts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const VIRTUAL_MODULE_ID = "astro:actions";
|
|
2
2
|
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
3
|
-
const ACTIONS_TYPES_FILE = "
|
|
3
|
+
const ACTIONS_TYPES_FILE = "actions.d.ts";
|
|
4
4
|
const VIRTUAL_INTERNAL_MODULE_ID = "astro:internal-actions";
|
|
5
5
|
const RESOLVED_VIRTUAL_INTERNAL_MODULE_ID = "\0astro:internal-actions";
|
|
6
6
|
const NOOP_ACTIONS = "\0noop-actions";
|
package/dist/cli/add/index.js
CHANGED
|
@@ -6,11 +6,11 @@ import { diffWords } from "diff";
|
|
|
6
6
|
import { bold, cyan, dim, green, magenta, red, yellow } from "kleur/colors";
|
|
7
7
|
import { builders, generateCode, loadFile } from "magicast";
|
|
8
8
|
import { getDefaultExportOptions } from "magicast/helpers";
|
|
9
|
-
import ora from "ora";
|
|
10
9
|
import preferredPM from "preferred-pm";
|
|
11
10
|
import prompts from "prompts";
|
|
12
11
|
import maxSatisfying from "semver/ranges/max-satisfying.js";
|
|
13
12
|
import { exec } from "tinyexec";
|
|
13
|
+
import yoctoSpinner from "yocto-spinner";
|
|
14
14
|
import {
|
|
15
15
|
loadTSConfig,
|
|
16
16
|
resolveConfig,
|
|
@@ -381,9 +381,6 @@ function setAdapter(mod, adapter, exportName) {
|
|
|
381
381
|
from: exportName
|
|
382
382
|
});
|
|
383
383
|
}
|
|
384
|
-
if (!config.output) {
|
|
385
|
-
config.output = "server";
|
|
386
|
-
}
|
|
387
384
|
switch (adapter.id) {
|
|
388
385
|
case "node":
|
|
389
386
|
config.adapter = builders.functionCall(adapterId, { mode: "standalone" });
|
|
@@ -494,7 +491,8 @@ async function resolveRangeToInstallSpecifier(name, range) {
|
|
|
494
491
|
const versions = await fetchPackageVersions(name);
|
|
495
492
|
if (versions instanceof Error) return name;
|
|
496
493
|
const stableVersions = versions.filter((v) => !v.includes("-"));
|
|
497
|
-
const maxStable = maxSatisfying(stableVersions
|
|
494
|
+
const maxStable = maxSatisfying(stableVersions, range) ?? maxSatisfying(versions, range);
|
|
495
|
+
if (!maxStable) return name;
|
|
498
496
|
return `${name}@^${maxStable}`;
|
|
499
497
|
}
|
|
500
498
|
const INHERITED_FLAGS = /* @__PURE__ */ new Set([
|
|
@@ -545,7 +543,7 @@ ${boxen(coloredOutput, {
|
|
|
545
543
|
${message}`
|
|
546
544
|
);
|
|
547
545
|
if (await askToContinue({ flags })) {
|
|
548
|
-
const spinner =
|
|
546
|
+
const spinner = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
549
547
|
try {
|
|
550
548
|
await exec(
|
|
551
549
|
installCommand.pm,
|
|
@@ -563,10 +561,10 @@ ${message}`
|
|
|
563
561
|
}
|
|
564
562
|
}
|
|
565
563
|
);
|
|
566
|
-
spinner.
|
|
564
|
+
spinner.success();
|
|
567
565
|
return 1 /* updated */;
|
|
568
566
|
} catch (err) {
|
|
569
|
-
spinner.
|
|
567
|
+
spinner.error();
|
|
570
568
|
logger.debug("add", "Error installing dependencies", err);
|
|
571
569
|
console.error("\n", err.stdout || err.message, "\n");
|
|
572
570
|
return 3 /* failure */;
|
|
@@ -577,7 +575,7 @@ ${message}`
|
|
|
577
575
|
}
|
|
578
576
|
}
|
|
579
577
|
async function validateIntegrations(integrations) {
|
|
580
|
-
const spinner =
|
|
578
|
+
const spinner = yoctoSpinner({ text: "Resolving packages..." }).start();
|
|
581
579
|
try {
|
|
582
580
|
const integrationEntries = await Promise.all(
|
|
583
581
|
integrations.map(async (integration) => {
|
|
@@ -594,9 +592,9 @@ async function validateIntegrations(integrations) {
|
|
|
594
592
|
const firstPartyPkgCheck = await fetchPackageJson("@astrojs", name, tag);
|
|
595
593
|
if (firstPartyPkgCheck instanceof Error) {
|
|
596
594
|
if (firstPartyPkgCheck.message) {
|
|
597
|
-
spinner.
|
|
595
|
+
spinner.warning(yellow(firstPartyPkgCheck.message));
|
|
598
596
|
}
|
|
599
|
-
spinner.
|
|
597
|
+
spinner.warning(yellow(`${bold(integration)} is not an official Astro package.`));
|
|
600
598
|
const response = await prompts({
|
|
601
599
|
type: "confirm",
|
|
602
600
|
name: "askToContinue",
|
|
@@ -621,7 +619,7 @@ async function validateIntegrations(integrations) {
|
|
|
621
619
|
const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag);
|
|
622
620
|
if (thirdPartyPkgCheck instanceof Error) {
|
|
623
621
|
if (thirdPartyPkgCheck.message) {
|
|
624
|
-
spinner.
|
|
622
|
+
spinner.warning(yellow(thirdPartyPkgCheck.message));
|
|
625
623
|
}
|
|
626
624
|
throw new Error(`Unable to fetch ${bold(integration)}. Does the package exist?`);
|
|
627
625
|
} else {
|
|
@@ -661,11 +659,11 @@ async function validateIntegrations(integrations) {
|
|
|
661
659
|
return { id: integration, packageName, dependencies, type: integrationType };
|
|
662
660
|
})
|
|
663
661
|
);
|
|
664
|
-
spinner.
|
|
662
|
+
spinner.success();
|
|
665
663
|
return integrationEntries;
|
|
666
664
|
} catch (e) {
|
|
667
665
|
if (e instanceof Error) {
|
|
668
|
-
spinner.
|
|
666
|
+
spinner.error(e.message);
|
|
669
667
|
process.exit(1);
|
|
670
668
|
} else {
|
|
671
669
|
throw e;
|
|
@@ -2,11 +2,11 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import boxen from "boxen";
|
|
3
3
|
import ci from "ci-info";
|
|
4
4
|
import { bold, cyan, dim, magenta } from "kleur/colors";
|
|
5
|
-
import ora from "ora";
|
|
6
5
|
import preferredPM from "preferred-pm";
|
|
7
6
|
import prompts from "prompts";
|
|
8
7
|
import { exec } from "tinyexec";
|
|
9
8
|
import whichPm from "which-pm";
|
|
9
|
+
import yoctoSpinner from "yocto-spinner";
|
|
10
10
|
const require2 = createRequire(import.meta.url);
|
|
11
11
|
async function getPackage(packageName, logger, options, otherDeps = []) {
|
|
12
12
|
try {
|
|
@@ -104,18 +104,18 @@ ${message}`
|
|
|
104
104
|
})).askToContinue;
|
|
105
105
|
}
|
|
106
106
|
if (Boolean(response)) {
|
|
107
|
-
const spinner =
|
|
107
|
+
const spinner = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
|
108
108
|
try {
|
|
109
109
|
await exec(
|
|
110
110
|
installCommand.pm,
|
|
111
111
|
[installCommand.command, ...installCommand.flags, ...installCommand.dependencies],
|
|
112
112
|
{ nodeOptions: { cwd } }
|
|
113
113
|
);
|
|
114
|
-
spinner.
|
|
114
|
+
spinner.success();
|
|
115
115
|
return true;
|
|
116
116
|
} catch (err) {
|
|
117
117
|
logger.debug("add", "Error installing dependencies", err);
|
|
118
|
-
spinner.
|
|
118
|
+
spinner.error();
|
|
119
119
|
return false;
|
|
120
120
|
}
|
|
121
121
|
} else {
|
package/dist/content/consts.d.ts
CHANGED
|
@@ -17,8 +17,10 @@ export declare const LINKS_PLACEHOLDER = "@@ASTRO-LINKS@@";
|
|
|
17
17
|
export declare const STYLES_PLACEHOLDER = "@@ASTRO-STYLES@@";
|
|
18
18
|
export declare const IMAGE_IMPORT_PREFIX = "__ASTRO_IMAGE_";
|
|
19
19
|
export declare const CONTENT_FLAGS: readonly ["astroContentCollectionEntry", "astroRenderContent", "astroDataCollectionEntry", "astroPropagatedAssets", "astroContentImageFlag", "astroContentModuleFlag"];
|
|
20
|
-
export declare const CONTENT_TYPES_FILE = "
|
|
20
|
+
export declare const CONTENT_TYPES_FILE = "content.d.ts";
|
|
21
21
|
export declare const DATA_STORE_FILE = "data-store.json";
|
|
22
|
-
export declare const ASSET_IMPORTS_FILE = "assets.mjs";
|
|
23
|
-
export declare const MODULES_IMPORTS_FILE = "modules.mjs";
|
|
22
|
+
export declare const ASSET_IMPORTS_FILE = "content-assets.mjs";
|
|
23
|
+
export declare const MODULES_IMPORTS_FILE = "content-modules.mjs";
|
|
24
|
+
export declare const COLLECTIONS_MANIFEST_FILE = "collections/collections.json";
|
|
25
|
+
export declare const COLLECTIONS_DIR = "collections/";
|
|
24
26
|
export declare const CONTENT_LAYER_TYPE = "content_layer";
|
package/dist/content/consts.js
CHANGED
|
@@ -24,15 +24,19 @@ const CONTENT_FLAGS = [
|
|
|
24
24
|
CONTENT_IMAGE_FLAG,
|
|
25
25
|
CONTENT_MODULE_FLAG
|
|
26
26
|
];
|
|
27
|
-
const CONTENT_TYPES_FILE = "
|
|
27
|
+
const CONTENT_TYPES_FILE = "content.d.ts";
|
|
28
28
|
const DATA_STORE_FILE = "data-store.json";
|
|
29
|
-
const ASSET_IMPORTS_FILE = "assets.mjs";
|
|
30
|
-
const MODULES_IMPORTS_FILE = "modules.mjs";
|
|
29
|
+
const ASSET_IMPORTS_FILE = "content-assets.mjs";
|
|
30
|
+
const MODULES_IMPORTS_FILE = "content-modules.mjs";
|
|
31
|
+
const COLLECTIONS_MANIFEST_FILE = "collections/collections.json";
|
|
32
|
+
const COLLECTIONS_DIR = "collections/";
|
|
31
33
|
const CONTENT_LAYER_TYPE = "content_layer";
|
|
32
34
|
export {
|
|
33
35
|
ASSET_IMPORTS_FILE,
|
|
34
36
|
ASSET_IMPORTS_RESOLVED_STUB_ID,
|
|
35
37
|
ASSET_IMPORTS_VIRTUAL_ID,
|
|
38
|
+
COLLECTIONS_DIR,
|
|
39
|
+
COLLECTIONS_MANIFEST_FILE,
|
|
36
40
|
CONTENT_FLAG,
|
|
37
41
|
CONTENT_FLAGS,
|
|
38
42
|
CONTENT_IMAGE_FLAG,
|
|
@@ -4,6 +4,7 @@ import xxhash from "xxhash-wasm";
|
|
|
4
4
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
5
5
|
import {
|
|
6
6
|
ASSET_IMPORTS_FILE,
|
|
7
|
+
COLLECTIONS_MANIFEST_FILE,
|
|
7
8
|
CONTENT_LAYER_TYPE,
|
|
8
9
|
DATA_STORE_FILE,
|
|
9
10
|
MODULES_IMPORTS_FILE
|
|
@@ -159,14 +160,10 @@ class ContentLayer {
|
|
|
159
160
|
return collection.loader.load(context);
|
|
160
161
|
})
|
|
161
162
|
);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
163
|
+
await fs.mkdir(this.#settings.config.cacheDir, { recursive: true });
|
|
164
|
+
await fs.mkdir(this.#settings.dotAstroDir, { recursive: true });
|
|
165
165
|
const cacheFile = getDataStoreFile(this.#settings);
|
|
166
166
|
await this.#store.writeToDisk(cacheFile);
|
|
167
|
-
if (!existsSync(this.#settings.dotAstroDir)) {
|
|
168
|
-
await fs.mkdir(this.#settings.dotAstroDir, { recursive: true });
|
|
169
|
-
}
|
|
170
167
|
const assetImportsFile = new URL(ASSET_IMPORTS_FILE, this.#settings.dotAstroDir);
|
|
171
168
|
await this.#store.writeAssetImports(assetImportsFile);
|
|
172
169
|
const modulesImportsFile = new URL(MODULES_IMPORTS_FILE, this.#settings.dotAstroDir);
|
|
@@ -177,7 +174,7 @@ class ContentLayer {
|
|
|
177
174
|
}
|
|
178
175
|
}
|
|
179
176
|
async regenerateCollectionFileManifest() {
|
|
180
|
-
const collectionsManifest = new URL(
|
|
177
|
+
const collectionsManifest = new URL(COLLECTIONS_MANIFEST_FILE, this.#settings.dotAstroDir);
|
|
181
178
|
this.#logger.debug("content", "Regenerating collection file manifest");
|
|
182
179
|
if (existsSync(collectionsManifest)) {
|
|
183
180
|
try {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { Loader } from './types.js';
|
|
2
|
+
export interface FileOptions {
|
|
3
|
+
/**
|
|
4
|
+
* the parsing function to use for this data
|
|
5
|
+
* @default JSON.parse or yaml.load, depending on the extension of the file
|
|
6
|
+
* */
|
|
7
|
+
parser?: (text: string) => Record<string, Record<string, unknown>> | Array<Record<string, unknown>>;
|
|
8
|
+
}
|
|
2
9
|
/**
|
|
3
10
|
* Loads entries from a JSON file. The file must contain an array of objects that contain unique `id` fields, or an object with string keys.
|
|
4
|
-
* @todo Add support for other file types, such as YAML, CSV etc.
|
|
5
11
|
* @param fileName The path to the JSON file to load, relative to the content directory.
|
|
12
|
+
* @param options Additional options for the file loader
|
|
6
13
|
*/
|
|
7
|
-
export declare function file(fileName: string): Loader;
|
|
14
|
+
export declare function file(fileName: string, options?: FileOptions): Loader;
|
|
@@ -1,43 +1,59 @@
|
|
|
1
1
|
import { promises as fs, existsSync } from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import yaml from "js-yaml";
|
|
3
4
|
import { posixRelative } from "../utils.js";
|
|
4
|
-
function file(fileName) {
|
|
5
|
+
function file(fileName, options) {
|
|
5
6
|
if (fileName.includes("*")) {
|
|
6
7
|
throw new Error("Glob patterns are not supported in `file` loader. Use `glob` loader instead.");
|
|
7
8
|
}
|
|
9
|
+
let parse = null;
|
|
10
|
+
const ext = fileName.split(".").at(-1);
|
|
11
|
+
if (ext === "json") {
|
|
12
|
+
parse = JSON.parse;
|
|
13
|
+
} else if (ext === "yml" || ext === "yaml") {
|
|
14
|
+
parse = (text) => yaml.load(text, {
|
|
15
|
+
filename: fileName
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (options?.parser) parse = options.parser;
|
|
19
|
+
if (parse === null) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`No parser found for file '${fileName}'. Try passing a parser to the \`file\` loader.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
8
24
|
async function syncData(filePath, { logger, parseData, store, config }) {
|
|
9
|
-
let
|
|
25
|
+
let data;
|
|
10
26
|
try {
|
|
11
|
-
const
|
|
12
|
-
|
|
27
|
+
const contents = await fs.readFile(filePath, "utf-8");
|
|
28
|
+
data = parse(contents);
|
|
13
29
|
} catch (error) {
|
|
14
30
|
logger.error(`Error reading data from ${fileName}`);
|
|
15
31
|
logger.debug(error.message);
|
|
16
32
|
return;
|
|
17
33
|
}
|
|
18
34
|
const normalizedFilePath = posixRelative(fileURLToPath(config.root), filePath);
|
|
19
|
-
if (Array.isArray(
|
|
20
|
-
if (
|
|
35
|
+
if (Array.isArray(data)) {
|
|
36
|
+
if (data.length === 0) {
|
|
21
37
|
logger.warn(`No items found in ${fileName}`);
|
|
22
38
|
}
|
|
23
|
-
logger.debug(`Found ${
|
|
39
|
+
logger.debug(`Found ${data.length} item array in ${fileName}`);
|
|
24
40
|
store.clear();
|
|
25
|
-
for (const rawItem of
|
|
41
|
+
for (const rawItem of data) {
|
|
26
42
|
const id = (rawItem.id ?? rawItem.slug)?.toString();
|
|
27
43
|
if (!id) {
|
|
28
44
|
logger.error(`Item in ${fileName} is missing an id or slug field.`);
|
|
29
45
|
continue;
|
|
30
46
|
}
|
|
31
|
-
const
|
|
32
|
-
store.set({ id, data, filePath: normalizedFilePath });
|
|
47
|
+
const parsedData = await parseData({ id, data: rawItem, filePath });
|
|
48
|
+
store.set({ id, data: parsedData, filePath: normalizedFilePath });
|
|
33
49
|
}
|
|
34
|
-
} else if (typeof
|
|
35
|
-
const entries = Object.entries(
|
|
50
|
+
} else if (typeof data === "object") {
|
|
51
|
+
const entries = Object.entries(data);
|
|
36
52
|
logger.debug(`Found object with ${entries.length} entries in ${fileName}`);
|
|
37
53
|
store.clear();
|
|
38
54
|
for (const [id, rawItem] of entries) {
|
|
39
|
-
const
|
|
40
|
-
store.set({ id, data, filePath: normalizedFilePath });
|
|
55
|
+
const parsedData = await parseData({ id, data: rawItem, filePath });
|
|
56
|
+
store.set({ id, data: parsedData, filePath: normalizedFilePath });
|
|
41
57
|
}
|
|
42
58
|
} else {
|
|
43
59
|
logger.error(`Invalid data in ${fileName}. Must be an array or object.`);
|
|
@@ -9,7 +9,12 @@ import { printNode, zodToTs } from "zod-to-ts";
|
|
|
9
9
|
import { AstroError } from "../core/errors/errors.js";
|
|
10
10
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
11
11
|
import { isRelativePath } from "../core/path.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
COLLECTIONS_DIR,
|
|
14
|
+
CONTENT_LAYER_TYPE,
|
|
15
|
+
CONTENT_TYPES_FILE,
|
|
16
|
+
VIRTUAL_MODULE_ID
|
|
17
|
+
} from "./consts.js";
|
|
13
18
|
import {
|
|
14
19
|
getContentEntryIdAndSlug,
|
|
15
20
|
getContentPaths,
|
|
@@ -313,10 +318,8 @@ async function writeContentFiles({
|
|
|
313
318
|
}) {
|
|
314
319
|
let contentTypesStr = "";
|
|
315
320
|
let dataTypesStr = "";
|
|
316
|
-
const collectionSchemasDir = new URL(
|
|
317
|
-
|
|
318
|
-
fs.mkdirSync(collectionSchemasDir, { recursive: true });
|
|
319
|
-
}
|
|
321
|
+
const collectionSchemasDir = new URL(COLLECTIONS_DIR, settings.dotAstroDir);
|
|
322
|
+
fs.mkdirSync(collectionSchemasDir, { recursive: true });
|
|
320
323
|
for (const [collection, config] of Object.entries(contentConfig?.collections ?? {})) {
|
|
321
324
|
collectionEntryMap[JSON.stringify(collection)] ??= {
|
|
322
325
|
type: config.type,
|
|
@@ -391,7 +394,8 @@ async function writeContentFiles({
|
|
|
391
394
|
id: string;
|
|
392
395
|
collection: ${collectionKey};
|
|
393
396
|
data: ${dataType};
|
|
394
|
-
rendered?: RenderedContent
|
|
397
|
+
rendered?: RenderedContent;
|
|
398
|
+
filePath?: string
|
|
395
399
|
}>;
|
|
396
400
|
`;
|
|
397
401
|
break;
|
|
@@ -458,11 +462,8 @@ async function writeContentFiles({
|
|
|
458
462
|
JSON.stringify(contentCollectionManifest, null, 2)
|
|
459
463
|
);
|
|
460
464
|
}
|
|
461
|
-
if (!fs.existsSync(settings.dotAstroDir)) {
|
|
462
|
-
fs.mkdirSync(settings.dotAstroDir, { recursive: true });
|
|
463
|
-
}
|
|
464
465
|
const configPathRelativeToCacheDir = normalizeConfigPath(
|
|
465
|
-
|
|
466
|
+
settings.dotAstroDir.pathname,
|
|
466
467
|
contentPaths.config.url.pathname
|
|
467
468
|
);
|
|
468
469
|
for (const contentEntryType of contentEntryTypes) {
|
|
@@ -477,9 +478,11 @@ async function writeContentFiles({
|
|
|
477
478
|
contentConfig ? `typeof import(${configPathRelativeToCacheDir})` : "never"
|
|
478
479
|
);
|
|
479
480
|
if (settings.injectedTypes.some((t) => t.filename === CONTENT_TYPES_FILE)) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
481
|
+
await fs.promises.writeFile(
|
|
482
|
+
new URL(CONTENT_TYPES_FILE, settings.dotAstroDir),
|
|
483
|
+
typeTemplateContent,
|
|
484
|
+
"utf-8"
|
|
485
|
+
);
|
|
483
486
|
} else {
|
|
484
487
|
settings.injectedTypes.push({
|
|
485
488
|
filename: CONTENT_TYPES_FILE,
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fsMod from 'node:fs';
|
|
2
|
-
import matter from 'gray-matter';
|
|
3
2
|
import type { PluginContext } from 'rollup';
|
|
4
3
|
import type { ViteDevServer } from 'vite';
|
|
5
4
|
import { z } from 'zod';
|
|
@@ -498,7 +497,7 @@ export declare function getContentEntryIdAndSlug({ entry, contentDir, collection
|
|
|
498
497
|
slug: string;
|
|
499
498
|
};
|
|
500
499
|
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], dataFileExts: string[]): 'content' | 'data' | 'config' | 'ignored';
|
|
501
|
-
export declare function safeParseFrontmatter(source: string, id?: string):
|
|
500
|
+
export declare function safeParseFrontmatter(source: string, id?: string): import("@astrojs/markdown-remark").ParseFrontmatterResult;
|
|
502
501
|
/**
|
|
503
502
|
* The content config is loaded separately from other `src/` files.
|
|
504
503
|
* This global observable lets dependent plugins (like the content flag plugin)
|
package/dist/content/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fsMod from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { parseFrontmatter } from "@astrojs/markdown-remark";
|
|
4
5
|
import { slug as githubSlug } from "github-slugger";
|
|
5
|
-
import matter from "gray-matter";
|
|
6
6
|
import xxhash from "xxhash-wasm";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { AstroError, AstroErrorData, MarkdownError, errorMap } from "../core/errors/index.js";
|
|
@@ -321,7 +321,7 @@ function getYAMLErrorLine(rawData, objectKey) {
|
|
|
321
321
|
}
|
|
322
322
|
function safeParseFrontmatter(source, id) {
|
|
323
323
|
try {
|
|
324
|
-
return
|
|
324
|
+
return parseFrontmatter(source, { frontmatter: "empty-with-spaces" });
|
|
325
325
|
} catch (err) {
|
|
326
326
|
const markdownError = new MarkdownError({
|
|
327
327
|
name: "MarkdownError",
|
|
@@ -7,12 +7,10 @@ interface AstroContentVirtualModPluginParams {
|
|
|
7
7
|
fs: typeof nodeFs;
|
|
8
8
|
}
|
|
9
9
|
export declare function astroContentVirtualModPlugin({ settings, fs, }: AstroContentVirtualModPluginParams): Plugin;
|
|
10
|
-
export declare function generateContentEntryFile({ settings, lookupMap,
|
|
10
|
+
export declare function generateContentEntryFile({ settings, lookupMap, isClient, }: {
|
|
11
11
|
settings: AstroSettings;
|
|
12
12
|
fs: typeof nodeFs;
|
|
13
13
|
lookupMap: ContentLookupMap;
|
|
14
|
-
IS_DEV: boolean;
|
|
15
|
-
IS_SERVER: boolean;
|
|
16
14
|
isClient: boolean;
|
|
17
15
|
}): Promise<string>;
|
|
18
16
|
/**
|
|
@@ -4,9 +4,8 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
4
4
|
import { dataToEsm } from "@rollup/pluginutils";
|
|
5
5
|
import glob from "fast-glob";
|
|
6
6
|
import pLimit from "p-limit";
|
|
7
|
-
import { encodeName } from "../core/build/util.js";
|
|
8
7
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
|
-
import { appendForwardSlash
|
|
8
|
+
import { appendForwardSlash } from "../core/path.js";
|
|
10
9
|
import { rootRelativePath } from "../core/viteUtils.js";
|
|
11
10
|
import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
|
|
12
11
|
import {
|
|
@@ -42,7 +41,6 @@ function astroContentVirtualModPlugin({
|
|
|
42
41
|
fs
|
|
43
42
|
}) {
|
|
44
43
|
let IS_DEV = false;
|
|
45
|
-
const IS_SERVER = settings.buildOutput === "server";
|
|
46
44
|
let dataStoreFile;
|
|
47
45
|
return {
|
|
48
46
|
name: "astro-content-virtual-mod-plugin",
|
|
@@ -53,14 +51,7 @@ function astroContentVirtualModPlugin({
|
|
|
53
51
|
},
|
|
54
52
|
async resolveId(id) {
|
|
55
53
|
if (id === VIRTUAL_MODULE_ID) {
|
|
56
|
-
|
|
57
|
-
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
58
|
-
}
|
|
59
|
-
if (IS_DEV || IS_SERVER) {
|
|
60
|
-
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
61
|
-
} else {
|
|
62
|
-
return { id: RESOLVED_VIRTUAL_MODULE_ID, external: true };
|
|
63
|
-
}
|
|
54
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
64
55
|
}
|
|
65
56
|
if (id === DATA_STORE_VIRTUAL_ID) {
|
|
66
57
|
return RESOLVED_DATA_STORE_VIRTUAL_ID;
|
|
@@ -103,8 +94,6 @@ function astroContentVirtualModPlugin({
|
|
|
103
94
|
settings,
|
|
104
95
|
fs,
|
|
105
96
|
lookupMap,
|
|
106
|
-
IS_DEV,
|
|
107
|
-
IS_SERVER,
|
|
108
97
|
isClient
|
|
109
98
|
});
|
|
110
99
|
const astro = createDefaultAstroMetadata();
|
|
@@ -149,16 +138,6 @@ function astroContentVirtualModPlugin({
|
|
|
149
138
|
return fs.readFileSync(modules, "utf-8");
|
|
150
139
|
}
|
|
151
140
|
},
|
|
152
|
-
renderChunk(code, chunk) {
|
|
153
|
-
if (!settings.config.experimental.contentCollectionCache) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (code.includes(RESOLVED_VIRTUAL_MODULE_ID)) {
|
|
157
|
-
const depth = chunk.fileName.split("/").length - 1;
|
|
158
|
-
const prefix = depth > 0 ? "../".repeat(depth) : "./";
|
|
159
|
-
return code.replaceAll(RESOLVED_VIRTUAL_MODULE_ID, `${prefix}content/entry.mjs`);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
141
|
configureServer(server) {
|
|
163
142
|
const dataStorePath = fileURLToPath(dataStoreFile);
|
|
164
143
|
server.watcher.add(dataStorePath);
|
|
@@ -188,8 +167,6 @@ function astroContentVirtualModPlugin({
|
|
|
188
167
|
async function generateContentEntryFile({
|
|
189
168
|
settings,
|
|
190
169
|
lookupMap,
|
|
191
|
-
IS_DEV,
|
|
192
|
-
IS_SERVER,
|
|
193
170
|
isClient
|
|
194
171
|
}) {
|
|
195
172
|
const contentPaths = getContentPaths(settings.config);
|
|
@@ -197,32 +174,22 @@ async function generateContentEntryFile({
|
|
|
197
174
|
let contentEntryGlobResult;
|
|
198
175
|
let dataEntryGlobResult;
|
|
199
176
|
let renderEntryGlobResult;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
);
|
|
217
|
-
} else {
|
|
218
|
-
contentEntryGlobResult = getStringifiedCollectionFromLookup(
|
|
219
|
-
"content",
|
|
220
|
-
relContentDir,
|
|
221
|
-
lookupMap
|
|
222
|
-
);
|
|
223
|
-
dataEntryGlobResult = getStringifiedCollectionFromLookup("data", relContentDir, lookupMap);
|
|
224
|
-
renderEntryGlobResult = getStringifiedCollectionFromLookup("render", relContentDir, lookupMap);
|
|
225
|
-
}
|
|
177
|
+
const contentEntryConfigByExt = getEntryConfigByExtMap(settings.contentEntryTypes);
|
|
178
|
+
const contentEntryExts = [...contentEntryConfigByExt.keys()];
|
|
179
|
+
const dataEntryExts = getDataEntryExts(settings);
|
|
180
|
+
const createGlob = (value, flag) => `import.meta.glob(${JSON.stringify(value)}, { query: { ${flag}: true } })`;
|
|
181
|
+
contentEntryGlobResult = createGlob(
|
|
182
|
+
globWithUnderscoresIgnored(relContentDir, contentEntryExts),
|
|
183
|
+
CONTENT_FLAG
|
|
184
|
+
);
|
|
185
|
+
dataEntryGlobResult = createGlob(
|
|
186
|
+
globWithUnderscoresIgnored(relContentDir, dataEntryExts),
|
|
187
|
+
DATA_FLAG
|
|
188
|
+
);
|
|
189
|
+
renderEntryGlobResult = createGlob(
|
|
190
|
+
globWithUnderscoresIgnored(relContentDir, contentEntryExts),
|
|
191
|
+
CONTENT_RENDER_FLAG
|
|
192
|
+
);
|
|
226
193
|
let virtualModContents;
|
|
227
194
|
if (isClient) {
|
|
228
195
|
throw new AstroError({
|
|
@@ -234,30 +201,6 @@ async function generateContentEntryFile({
|
|
|
234
201
|
}
|
|
235
202
|
return virtualModContents;
|
|
236
203
|
}
|
|
237
|
-
function getStringifiedCollectionFromLookup(wantedType, relContentDir, lookupMap) {
|
|
238
|
-
let str = "{";
|
|
239
|
-
let normalize = (slug) => slug;
|
|
240
|
-
if (process.env.NODE_ENV === "production") {
|
|
241
|
-
const suffix = wantedType === "render" ? ".entry.mjs" : ".mjs";
|
|
242
|
-
normalize = (slug) => `${removeFileExtension(encodeName(slug)).replace(relContentDir, "./")}${suffix}`;
|
|
243
|
-
} else {
|
|
244
|
-
let suffix = "";
|
|
245
|
-
if (wantedType === "content") suffix = CONTENT_FLAG;
|
|
246
|
-
else if (wantedType === "data") suffix = DATA_FLAG;
|
|
247
|
-
else if (wantedType === "render") suffix = CONTENT_RENDER_FLAG;
|
|
248
|
-
normalize = (slug) => `${slug}?${suffix}`;
|
|
249
|
-
}
|
|
250
|
-
for (const { type, entries } of Object.values(lookupMap)) {
|
|
251
|
-
if (type === wantedType || wantedType === "render" && type === "content") {
|
|
252
|
-
for (const slug of Object.values(entries)) {
|
|
253
|
-
str += `
|
|
254
|
-
"${slug}": () => import("${normalize(slug)}"),`;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
str += "\n}";
|
|
259
|
-
return str;
|
|
260
|
-
}
|
|
261
204
|
async function generateLookupMap({
|
|
262
205
|
settings,
|
|
263
206
|
fs
|
package/dist/core/app/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export declare class App {
|
|
|
53
53
|
removeBase(pathname: string): string;
|
|
54
54
|
match(request: Request): RouteData | undefined;
|
|
55
55
|
render(request: Request, renderOptions?: RenderOptions): Promise<Response>;
|
|
56
|
-
setCookieHeaders(response: Response): Generator<string, string[],
|
|
56
|
+
setCookieHeaders(response: Response): Generator<string, string[], any>;
|
|
57
57
|
/**
|
|
58
58
|
* Reads all the cookies written by `Astro.cookie.set()` onto the passed response.
|
|
59
59
|
* For example,
|
|
@@ -384,7 +384,7 @@ function createBuildManifest(settings, internals, renderers, middleware, key) {
|
|
|
384
384
|
onRequest: middleware
|
|
385
385
|
};
|
|
386
386
|
},
|
|
387
|
-
checkOrigin: settings.config.security?.checkOrigin ?? false,
|
|
387
|
+
checkOrigin: (settings.config.security?.checkOrigin && settings.buildOutput === "server") ?? false,
|
|
388
388
|
key,
|
|
389
389
|
envGetSecretEnabled: false
|
|
390
390
|
};
|
package/dist/core/build/index.js
CHANGED
|
@@ -34,14 +34,6 @@ async function build(inlineConfig, options = {}) {
|
|
|
34
34
|
telemetry.record(eventCliSession("build", userConfig));
|
|
35
35
|
const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
|
36
36
|
if (inlineConfig.force) {
|
|
37
|
-
if (astroConfig.experimental.contentCollectionCache) {
|
|
38
|
-
const contentCacheDir = new URL("./content/", astroConfig.cacheDir);
|
|
39
|
-
if (fs.existsSync(contentCacheDir)) {
|
|
40
|
-
logger.debug("content", "clearing content cache");
|
|
41
|
-
await fs.promises.rm(contentCacheDir, { force: true, recursive: true });
|
|
42
|
-
logger.warn("content", "content cache cleared (force)");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
37
|
await clearContentLayerCache({ settings, logger, fs });
|
|
46
38
|
}
|
|
47
39
|
const builder = new AstroBuilder(settings, {
|
|
@@ -170,8 +162,7 @@ class AstroBuilder {
|
|
|
170
162
|
settings: this.settings,
|
|
171
163
|
pages: pageNames,
|
|
172
164
|
routes: Object.values(allPages).flat().map((pageData) => pageData.route).concat(hasServerIslands ? getServerIslandRouteData(this.settings.config) : []),
|
|
173
|
-
logging: this.logger
|
|
174
|
-
cacheManifest: internals.cacheManifestUsed
|
|
165
|
+
logging: this.logger
|
|
175
166
|
});
|
|
176
167
|
if (this.logger.level && levels[this.logger.level()] <= levels["info"]) {
|
|
177
168
|
await this.printStats({
|
|
@@ -58,8 +58,6 @@ export interface BuildInternals {
|
|
|
58
58
|
* These will be used as the top-level entrypoints for the client build.
|
|
59
59
|
*/
|
|
60
60
|
discoveredScripts: Set<string>;
|
|
61
|
-
cachedClientEntries: string[];
|
|
62
|
-
cacheManifestUsed: boolean;
|
|
63
61
|
/**
|
|
64
62
|
* Map of propagated module ids (usually something like `/Users/...blog.mdx?astroPropagatedAssets`)
|
|
65
63
|
* to a set of stylesheets that it uses.
|