astro 2.0.11 → 2.0.12
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/cli/check/index.js +2 -2
- package/dist/cli/index.js +2 -2
- package/dist/content/server-listeners.js +48 -4
- package/dist/content/types-generator.js +4 -4
- package/dist/content/utils.d.ts +6 -3
- package/dist/content/utils.js +19 -9
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/core/build/index.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/environment.js +1 -1
- package/dist/core/render/dev/resolve.d.ts +1 -1
- package/dist/core/render/dev/resolve.js +3 -3
- package/dist/core/sync/index.d.ts +14 -0
- package/dist/{cli → core}/sync/index.js +15 -5
- package/dist/core/util.d.ts +1 -1
- package/dist/core/util.js +7 -2
- package/package.json +1 -1
- package/dist/cli/sync/index.d.ts +0 -8
package/dist/cli/check/index.js
CHANGED
|
@@ -8,8 +8,8 @@ import { fileURLToPath, pathToFileURL } from "url";
|
|
|
8
8
|
import { printDiagnostic } from "./print.js";
|
|
9
9
|
async function check(settings, { logging }) {
|
|
10
10
|
console.log(bold("astro check"));
|
|
11
|
-
const {
|
|
12
|
-
const syncRet = await
|
|
11
|
+
const { syncCli } = await import("../../core/sync/index.js");
|
|
12
|
+
const syncRet = await syncCli(settings, { logging, fs });
|
|
13
13
|
if (syncRet === 1)
|
|
14
14
|
return syncRet;
|
|
15
15
|
const root = settings.config.root;
|
package/dist/cli/index.js
CHANGED
|
@@ -161,8 +161,8 @@ async function runCommand(cmd, flags) {
|
|
|
161
161
|
return process.exit(ret);
|
|
162
162
|
}
|
|
163
163
|
case "sync": {
|
|
164
|
-
const {
|
|
165
|
-
const ret = await
|
|
164
|
+
const { syncCli } = await import("../core/sync/index.js");
|
|
165
|
+
const ret = await syncCli(settings, { logging, fs });
|
|
166
166
|
return process.exit(ret);
|
|
167
167
|
}
|
|
168
168
|
case "preview": {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { cyan } from "kleur/colors";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { bold, cyan } from "kleur/colors";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { loadTSConfig } from "../core/config/tsconfig.js";
|
|
5
|
+
import { info, warn } from "../core/logger/core.js";
|
|
4
6
|
import { appendForwardSlash } from "../core/path.js";
|
|
5
7
|
import { createContentTypesGenerator } from "./types-generator.js";
|
|
6
8
|
import { getContentPaths, globalContentConfigObserver } from "./utils.js";
|
|
@@ -10,7 +12,10 @@ async function attachContentServerListeners({
|
|
|
10
12
|
logging,
|
|
11
13
|
settings
|
|
12
14
|
}) {
|
|
13
|
-
const contentPaths = getContentPaths(settings.config);
|
|
15
|
+
const contentPaths = getContentPaths(settings.config, fs);
|
|
16
|
+
const maybeTsConfigStats = getTSConfigStatsWhenAllowJsFalse({ contentPaths, settings });
|
|
17
|
+
if (maybeTsConfigStats)
|
|
18
|
+
warnAllowJsIsFalse({ ...maybeTsConfigStats, logging });
|
|
14
19
|
if (fs.existsSync(contentPaths.contentDir)) {
|
|
15
20
|
info(
|
|
16
21
|
logging,
|
|
@@ -60,6 +65,45 @@ async function attachContentServerListeners({
|
|
|
60
65
|
);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
68
|
+
function warnAllowJsIsFalse({
|
|
69
|
+
logging,
|
|
70
|
+
tsConfigFileName,
|
|
71
|
+
contentConfigFileName
|
|
72
|
+
}) {
|
|
73
|
+
if (!["info", "warn"].includes(logging.level))
|
|
74
|
+
warn(
|
|
75
|
+
logging,
|
|
76
|
+
"content",
|
|
77
|
+
`Make sure you have the ${bold("allowJs")} compiler option set to ${bold(
|
|
78
|
+
"true"
|
|
79
|
+
)} in your ${bold(tsConfigFileName)} file to have autocompletion in your ${bold(
|
|
80
|
+
contentConfigFileName
|
|
81
|
+
)} file.
|
|
82
|
+
See ${bold("https://www.typescriptlang.org/tsconfig#allowJs")} for more information.
|
|
83
|
+
`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
function getTSConfigStatsWhenAllowJsFalse({
|
|
87
|
+
contentPaths,
|
|
88
|
+
settings
|
|
89
|
+
}) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
const isContentConfigJsFile = [".js", ".mjs"].some(
|
|
92
|
+
(ext) => contentPaths.config.url.pathname.endsWith(ext)
|
|
93
|
+
);
|
|
94
|
+
if (!isContentConfigJsFile)
|
|
95
|
+
return;
|
|
96
|
+
const inputConfig = loadTSConfig(fileURLToPath(settings.config.root), false);
|
|
97
|
+
const tsConfigFileName = inputConfig.exists && inputConfig.path.split(path.sep).pop();
|
|
98
|
+
if (!tsConfigFileName)
|
|
99
|
+
return;
|
|
100
|
+
const contentConfigFileName = contentPaths.config.url.pathname.split(path.sep).pop();
|
|
101
|
+
const allowJSOption = (_b = (_a = inputConfig == null ? void 0 : inputConfig.config) == null ? void 0 : _a.compilerOptions) == null ? void 0 : _b.allowJs;
|
|
102
|
+
const hasAllowJs = allowJSOption === true || tsConfigFileName === "jsconfig.json" && allowJSOption !== false;
|
|
103
|
+
if (hasAllowJs)
|
|
104
|
+
return;
|
|
105
|
+
return { tsConfigFileName, contentConfigFileName };
|
|
106
|
+
}
|
|
63
107
|
export {
|
|
64
108
|
attachContentServerListeners
|
|
65
109
|
};
|
|
@@ -26,7 +26,7 @@ async function createContentTypesGenerator({
|
|
|
26
26
|
viteServer
|
|
27
27
|
}) {
|
|
28
28
|
const contentTypes = {};
|
|
29
|
-
const contentPaths = getContentPaths(settings.config);
|
|
29
|
+
const contentPaths = getContentPaths(settings.config, fs);
|
|
30
30
|
let events = [];
|
|
31
31
|
let debounceTimeout;
|
|
32
32
|
const contentTypesBase = await fs.promises.readFile(contentPaths.typesTemplate, "utf-8");
|
|
@@ -34,7 +34,7 @@ async function createContentTypesGenerator({
|
|
|
34
34
|
if (!fs.existsSync(contentPaths.contentDir)) {
|
|
35
35
|
return { typesGenerated: false, reason: "no-content-dir" };
|
|
36
36
|
}
|
|
37
|
-
events.push(handleEvent({ name: "add", entry: contentPaths.config }, { logLevel: "warn" }));
|
|
37
|
+
events.push(handleEvent({ name: "add", entry: contentPaths.config.url }, { logLevel: "warn" }));
|
|
38
38
|
const globResult = await glob("**", {
|
|
39
39
|
cwd: fileURLToPath(contentPaths.contentDir),
|
|
40
40
|
fs: {
|
|
@@ -43,7 +43,7 @@ async function createContentTypesGenerator({
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
const entries = globResult.map((e) => new URL(e, contentPaths.contentDir)).filter(
|
|
46
|
-
(e) => !e.href.startsWith(contentPaths.config.href)
|
|
46
|
+
(e) => !e.href.startsWith(contentPaths.config.url.href)
|
|
47
47
|
);
|
|
48
48
|
for (const entry of entries) {
|
|
49
49
|
events.push(handleEvent({ name: "add", entry }, { logLevel: "warn" }));
|
|
@@ -263,7 +263,7 @@ async function writeContentFiles({
|
|
|
263
263
|
fs.mkdirSync(contentPaths.cacheDir, { recursive: true });
|
|
264
264
|
}
|
|
265
265
|
let configPathRelativeToCacheDir = normalizePath(
|
|
266
|
-
path.relative(contentPaths.cacheDir.pathname, contentPaths.config.pathname)
|
|
266
|
+
path.relative(contentPaths.cacheDir.pathname, contentPaths.config.url.pathname)
|
|
267
267
|
);
|
|
268
268
|
if (!isRelativePath(configPathRelativeToCacheDir))
|
|
269
269
|
configPathRelativeToCacheDir = "./" + configPathRelativeToCacheDir;
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import matter from 'gray-matter';
|
|
3
|
-
import
|
|
3
|
+
import fsMod from 'node:fs';
|
|
4
4
|
import { ViteDevServer } from 'vite';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { AstroConfig, AstroSettings } from '../@types/astro.js';
|
|
@@ -103,7 +103,10 @@ export type ContentPaths = {
|
|
|
103
103
|
cacheDir: URL;
|
|
104
104
|
typesTemplate: URL;
|
|
105
105
|
virtualModTemplate: URL;
|
|
106
|
-
config:
|
|
106
|
+
config: {
|
|
107
|
+
exists: boolean;
|
|
108
|
+
url: URL;
|
|
109
|
+
};
|
|
107
110
|
};
|
|
108
|
-
export declare function getContentPaths({ srcDir, root
|
|
111
|
+
export declare function getContentPaths({ srcDir, root }: Pick<AstroConfig, 'root' | 'srcDir'>, fs?: typeof fsMod): ContentPaths;
|
|
109
112
|
export {};
|
package/dist/content/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { slug as githubSlug } from "github-slugger";
|
|
2
2
|
import matter from "gray-matter";
|
|
3
|
+
import fsMod from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
6
|
import { normalizePath } from "vite";
|
|
@@ -109,7 +110,7 @@ function getEntryType(entryPath, paths) {
|
|
|
109
110
|
return "ignored";
|
|
110
111
|
} else if (contentFileExts.includes(ext)) {
|
|
111
112
|
return "content";
|
|
112
|
-
} else if (fileUrl.href === paths.config.href) {
|
|
113
|
+
} else if (fileUrl.href === paths.config.url.href) {
|
|
113
114
|
return "config";
|
|
114
115
|
} else {
|
|
115
116
|
return "unsupported";
|
|
@@ -169,13 +170,13 @@ async function loadContentConfig({
|
|
|
169
170
|
settings,
|
|
170
171
|
viteServer
|
|
171
172
|
}) {
|
|
172
|
-
const contentPaths = getContentPaths(settings.config);
|
|
173
|
+
const contentPaths = getContentPaths(settings.config, fs);
|
|
173
174
|
let unparsedConfig;
|
|
174
|
-
if (!
|
|
175
|
+
if (!contentPaths.config.exists) {
|
|
175
176
|
return void 0;
|
|
176
177
|
}
|
|
177
178
|
try {
|
|
178
|
-
const configPathname = fileURLToPath(contentPaths.config);
|
|
179
|
+
const configPathname = fileURLToPath(contentPaths.config.url);
|
|
179
180
|
unparsedConfig = await viteServer.ssrLoadModule(configPathname);
|
|
180
181
|
} catch (e) {
|
|
181
182
|
throw e;
|
|
@@ -209,19 +210,28 @@ function contentObservable(initialCtx) {
|
|
|
209
210
|
subscribe
|
|
210
211
|
};
|
|
211
212
|
}
|
|
212
|
-
function getContentPaths({
|
|
213
|
-
srcDir
|
|
214
|
-
root
|
|
215
|
-
}) {
|
|
213
|
+
function getContentPaths({ srcDir, root }, fs = fsMod) {
|
|
214
|
+
const configStats = search(fs, srcDir);
|
|
216
215
|
const templateDir = new URL("../../src/content/template/", import.meta.url);
|
|
217
216
|
return {
|
|
218
217
|
cacheDir: new URL(".astro/", root),
|
|
219
218
|
contentDir: new URL("./content/", srcDir),
|
|
220
219
|
typesTemplate: new URL("types.d.ts", templateDir),
|
|
221
220
|
virtualModTemplate: new URL("virtual-mod.mjs", templateDir),
|
|
222
|
-
config:
|
|
221
|
+
config: configStats
|
|
223
222
|
};
|
|
224
223
|
}
|
|
224
|
+
function search(fs, srcDir) {
|
|
225
|
+
const paths = ["config.mjs", "config.js", "config.ts"].map(
|
|
226
|
+
(p) => new URL(`./content/${p}`, srcDir)
|
|
227
|
+
);
|
|
228
|
+
for (const file of paths) {
|
|
229
|
+
if (fs.existsSync(file)) {
|
|
230
|
+
return { exists: true, url: file };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { exists: false, url: paths[0] };
|
|
234
|
+
}
|
|
225
235
|
export {
|
|
226
236
|
NoCollectionError,
|
|
227
237
|
collectionConfigParser,
|
package/dist/core/build/index.js
CHANGED
|
@@ -54,7 +54,7 @@ class AstroBuilder {
|
|
|
54
54
|
{ settings: this.settings, logging, mode: "build" }
|
|
55
55
|
);
|
|
56
56
|
await runHookConfigDone({ settings: this.settings, logging });
|
|
57
|
-
const { sync } = await import("
|
|
57
|
+
const { sync } = await import("../sync/index.js");
|
|
58
58
|
const syncRet = await sync(this.settings, { logging, fs });
|
|
59
59
|
if (syncRet !== 0) {
|
|
60
60
|
return process.exit(syncRet);
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -31,7 +31,7 @@ async function dev(settings, options) {
|
|
|
31
31
|
isRestart: options.isRestart
|
|
32
32
|
})
|
|
33
33
|
);
|
|
34
|
-
const currentVersion = "2.0.
|
|
34
|
+
const currentVersion = "2.0.12";
|
|
35
35
|
if (currentVersion.includes("-")) {
|
|
36
36
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
37
37
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.0.
|
|
50
|
+
const version = "2.0.12";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
53
53
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -233,7 +233,7 @@ function printHelp({
|
|
|
233
233
|
message.push(
|
|
234
234
|
linebreak(),
|
|
235
235
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
236
|
-
`v${"2.0.
|
|
236
|
+
`v${"2.0.12"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -14,7 +14,7 @@ function createDevelopmentEnvironment(settings, logging, loader) {
|
|
|
14
14
|
},
|
|
15
15
|
mode,
|
|
16
16
|
renderers: [],
|
|
17
|
-
resolve: createResolve(loader),
|
|
17
|
+
resolve: createResolve(loader, settings.config.root),
|
|
18
18
|
routeCache: new RouteCache(logging, mode),
|
|
19
19
|
site: settings.config.site,
|
|
20
20
|
ssr: settings.config.output === "server",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ModuleLoader } from '../../module-loader/index';
|
|
2
|
-
export declare function createResolve(loader: ModuleLoader): (s: string) => Promise<string>;
|
|
2
|
+
export declare function createResolve(loader: ModuleLoader, root: URL): (s: string) => Promise<string>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { resolveIdToUrl } from "../../util.js";
|
|
2
|
-
function createResolve(loader) {
|
|
2
|
+
function createResolve(loader, root) {
|
|
3
3
|
return async function(s) {
|
|
4
|
-
const url = await resolveIdToUrl(loader, s);
|
|
5
|
-
if (url.startsWith("
|
|
4
|
+
const url = await resolveIdToUrl(loader, s, root);
|
|
5
|
+
if (url.startsWith("/") && url.endsWith(".jsx")) {
|
|
6
6
|
return url.slice(0, -4);
|
|
7
7
|
} else {
|
|
8
8
|
return url;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fsMod from 'node:fs';
|
|
3
|
+
import type { AstroSettings } from '../../@types/astro';
|
|
4
|
+
import { LogOptions } from '../logger/core.js';
|
|
5
|
+
type ProcessExit = 0 | 1;
|
|
6
|
+
export declare function syncCli(settings: AstroSettings, { logging, fs }: {
|
|
7
|
+
logging: LogOptions;
|
|
8
|
+
fs: typeof fsMod;
|
|
9
|
+
}): Promise<ProcessExit>;
|
|
10
|
+
export declare function sync(settings: AstroSettings, { logging, fs }: {
|
|
11
|
+
logging: LogOptions;
|
|
12
|
+
fs: typeof fsMod;
|
|
13
|
+
}): Promise<ProcessExit>;
|
|
14
|
+
export {};
|
|
@@ -3,11 +3,20 @@ import { performance } from "node:perf_hooks";
|
|
|
3
3
|
import { createServer } from "vite";
|
|
4
4
|
import { createContentTypesGenerator } from "../../content/index.js";
|
|
5
5
|
import { globalContentConfigObserver } from "../../content/utils.js";
|
|
6
|
-
import {
|
|
7
|
-
import { createVite } from "../../core/create-vite.js";
|
|
8
|
-
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
|
9
|
-
import { info } from "../../core/logger/core.js";
|
|
6
|
+
import { runHookConfigSetup } from "../../integrations/index.js";
|
|
10
7
|
import { setUpEnvTs } from "../../vite-plugin-inject-env-ts/index.js";
|
|
8
|
+
import { getTimeStat } from "../build/util.js";
|
|
9
|
+
import { createVite } from "../create-vite.js";
|
|
10
|
+
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
11
|
+
import { info } from "../logger/core.js";
|
|
12
|
+
async function syncCli(settings, { logging, fs }) {
|
|
13
|
+
const resolvedSettings = await runHookConfigSetup({
|
|
14
|
+
settings,
|
|
15
|
+
logging,
|
|
16
|
+
command: "build"
|
|
17
|
+
});
|
|
18
|
+
return sync(resolvedSettings, { logging, fs });
|
|
19
|
+
}
|
|
11
20
|
async function sync(settings, { logging, fs }) {
|
|
12
21
|
const timerStart = performance.now();
|
|
13
22
|
const tempViteServer = await createServer(
|
|
@@ -51,5 +60,6 @@ async function sync(settings, { logging, fs }) {
|
|
|
51
60
|
return 0;
|
|
52
61
|
}
|
|
53
62
|
export {
|
|
54
|
-
sync
|
|
63
|
+
sync,
|
|
64
|
+
syncCli
|
|
55
65
|
};
|
package/dist/core/util.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare function emoji(char: string, fallback: string): string;
|
|
|
42
42
|
* Simulate Vite's resolve and import analysis so we can import the id as an URL
|
|
43
43
|
* through a script tag or a dynamic import as-is.
|
|
44
44
|
*/
|
|
45
|
-
export declare function resolveIdToUrl(loader: ModuleLoader, id: string): Promise<string>;
|
|
45
|
+
export declare function resolveIdToUrl(loader: ModuleLoader, id: string, root?: URL): Promise<string>;
|
|
46
46
|
export declare function resolveJsToTs(filePath: string): string;
|
|
47
47
|
/**
|
|
48
48
|
* Resolve the hydration paths so that it can be imported in the client
|
package/dist/core/util.js
CHANGED
|
@@ -117,7 +117,7 @@ function relativeToSrcDir(config, idOrUrl) {
|
|
|
117
117
|
function emoji(char, fallback) {
|
|
118
118
|
return process.platform !== "win32" ? char : fallback;
|
|
119
119
|
}
|
|
120
|
-
async function resolveIdToUrl(loader, id) {
|
|
120
|
+
async function resolveIdToUrl(loader, id, root) {
|
|
121
121
|
let resultId = await loader.resolveId(id, void 0);
|
|
122
122
|
if (!resultId && id.endsWith(".jsx")) {
|
|
123
123
|
resultId = await loader.resolveId(id.slice(0, -4), void 0);
|
|
@@ -126,7 +126,12 @@ async function resolveIdToUrl(loader, id) {
|
|
|
126
126
|
return VALID_ID_PREFIX + id;
|
|
127
127
|
}
|
|
128
128
|
if (path.isAbsolute(resultId)) {
|
|
129
|
-
|
|
129
|
+
const normalizedRoot = root && normalizePath(fileURLToPath(root));
|
|
130
|
+
if (normalizedRoot && resultId.startsWith(normalizedRoot)) {
|
|
131
|
+
return resultId.slice(normalizedRoot.length - 1);
|
|
132
|
+
} else {
|
|
133
|
+
return "/@fs" + prependForwardSlash(resultId);
|
|
134
|
+
}
|
|
130
135
|
}
|
|
131
136
|
return VALID_ID_PREFIX + resultId;
|
|
132
137
|
}
|
package/package.json
CHANGED
package/dist/cli/sync/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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>;
|