astro 2.0.17 → 2.1.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/README.md +3 -3
- package/client-base.d.ts +27 -0
- package/client-image.d.ts +48 -0
- package/components/Image.astro +28 -0
- package/dist/@types/astro.d.ts +101 -1
- package/dist/assets/consts.d.ts +4 -0
- package/dist/assets/consts.js +20 -0
- package/dist/assets/image-endpoint.d.ts +5 -0
- package/dist/assets/image-endpoint.js +50 -0
- package/dist/assets/index.d.ts +4 -0
- package/dist/assets/index.js +10 -0
- package/dist/assets/internal.d.ts +36 -0
- package/dist/assets/internal.js +70 -0
- package/dist/assets/services/service.d.ts +71 -0
- package/dist/assets/services/service.js +88 -0
- package/dist/assets/services/sharp.d.ts +3 -0
- package/dist/assets/services/sharp.js +57 -0
- package/dist/assets/services/squoosh.d.ts +3 -0
- package/dist/assets/services/squoosh.js +56 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_enc.d.js +11 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +1628 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +1850 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/codecs.d.ts +158 -0
- package/dist/assets/services/vendor/squoosh/codecs.js +284 -0
- package/dist/assets/services/vendor/squoosh/copy-wasm.d.ts +1 -0
- package/dist/assets/services/vendor/squoosh/copy-wasm.js +24 -0
- package/dist/assets/services/vendor/squoosh/emscripten-types.d.js +0 -0
- package/dist/assets/services/vendor/squoosh/emscripten-utils.d.ts +9 -0
- package/dist/assets/services/vendor/squoosh/emscripten-utils.js +33 -0
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +4 -0
- package/dist/assets/services/vendor/squoosh/image-pool.js +94 -0
- package/dist/assets/services/vendor/squoosh/image.d.ts +14 -0
- package/dist/assets/services/vendor/squoosh/image.js +27 -0
- package/dist/assets/services/vendor/squoosh/image_data.d.ts +9 -0
- package/dist/assets/services/vendor/squoosh/image_data.js +22 -0
- package/dist/assets/services/vendor/squoosh/impl.d.ts +22 -0
- package/dist/assets/services/vendor/squoosh/impl.js +110 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_enc.d.js +11 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +1631 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +1737 -0
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.d.ts +10 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng.js +89 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.d.ts +15 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +138 -0
- package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.d.ts +15 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize.js +95 -0
- package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/utils/execOnce.d.ts +1 -0
- package/dist/assets/services/vendor/squoosh/utils/execOnce.js +14 -0
- package/dist/assets/services/vendor/squoosh/utils/workerPool.d.ts +22 -0
- package/dist/assets/services/vendor/squoosh/utils/workerPool.js +95 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_enc.d.js +4 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +1473 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm +0 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.d.ts +2 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +1640 -0
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm +0 -0
- package/dist/assets/types.d.ts +119 -0
- package/dist/assets/types.js +0 -0
- package/dist/assets/utils/etag.d.ts +12 -0
- package/dist/assets/utils/etag.js +28 -0
- package/dist/assets/utils/metadata.d.ts +6 -0
- package/dist/assets/utils/metadata.js +30 -0
- package/dist/assets/utils/queryParams.d.ts +2 -0
- package/dist/assets/utils/queryParams.js +16 -0
- package/dist/assets/utils/transformToPath.d.ts +2 -0
- package/dist/assets/utils/transformToPath.js +17 -0
- package/dist/assets/vite-plugin-assets.d.ts +5 -0
- package/dist/assets/vite-plugin-assets.js +187 -0
- package/dist/cli/check/index.d.ts +81 -2
- package/dist/cli/check/index.js +190 -44
- package/dist/cli/index.js +39 -16
- package/dist/cli/telemetry.js +1 -1
- package/dist/content/consts.d.ts +0 -1
- package/dist/content/consts.js +1 -3
- package/dist/content/internal.d.ts +7 -0
- package/dist/content/internal.js +27 -5
- package/dist/content/template/virtual-mod.d.mts +1 -0
- package/dist/content/types-generator.js +25 -10
- package/dist/content/utils.d.ts +16 -13
- package/dist/content/utils.js +29 -6
- package/dist/content/vite-plugin-content-assets.d.ts +3 -1
- package/dist/content/vite-plugin-content-assets.js +10 -6
- package/dist/content/vite-plugin-content-imports.js +54 -27
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -4
- package/dist/core/add/index.js +2 -1
- package/dist/core/app/index.js +104 -134
- package/dist/core/build/generate.js +30 -5
- package/dist/core/build/index.d.ts +2 -0
- package/dist/core/build/index.js +16 -0
- package/dist/core/build/plugins/plugin-ssr.js +3 -5
- package/dist/core/config/config.js +2 -1
- package/dist/core/config/schema.d.ts +64 -8
- package/dist/core/config/schema.js +17 -3
- package/dist/core/config/settings.js +4 -2
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +36 -68
- package/dist/core/create-vite.js +5 -1
- package/dist/core/dev/dev.d.ts +2 -2
- package/dist/core/dev/dev.js +24 -4
- package/dist/core/errors/dev/vite.js +6 -1
- package/dist/core/errors/errors-data.d.ts +17 -1
- package/dist/core/errors/errors-data.js +16 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/path.d.ts +1 -0
- package/dist/core/path.js +4 -0
- package/dist/core/preview/index.d.ts +3 -1
- package/dist/core/preview/index.js +16 -1
- package/dist/core/render/dev/css.js +2 -2
- package/dist/core/render/dev/environment.js +1 -5
- package/dist/core/render/environment.js +1 -2
- package/dist/core/render/result.js +13 -35
- package/dist/core/sync/index.d.ts +18 -5
- package/dist/core/sync/index.js +13 -1
- package/dist/integrations/index.js +12 -1
- package/dist/runtime/server/render/component.js +1 -1
- package/dist/runtime/server/response.js +11 -30
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.js +1 -1
- package/dist/vite-plugin-env/index.js +4 -4
- package/dist/vite-plugin-inject-env-ts/index.js +17 -2
- package/dist/vite-plugin-markdown/content-entry-type.d.ts +7 -0
- package/dist/vite-plugin-markdown/content-entry-type.js +39 -0
- package/dist/vite-plugin-markdown/index.js +70 -4
- package/dist/vite-plugin-ssr-manifest/index.d.ts +2 -0
- package/dist/vite-plugin-ssr-manifest/index.js +25 -0
- package/package.json +26 -9
- package/src/content/template/types.d.ts +18 -9
- package/src/content/template/virtual-mod.mjs +6 -0
- package/tsconfigs/base.json +6 -1
package/dist/cli/check/index.js
CHANGED
|
@@ -3,69 +3,208 @@ import glob from "fast-glob";
|
|
|
3
3
|
import * as fs from "fs";
|
|
4
4
|
import { bold, dim, red, yellow } from "kleur/colors";
|
|
5
5
|
import { createRequire } from "module";
|
|
6
|
+
import { join } from "node:path";
|
|
6
7
|
import ora from "ora";
|
|
7
8
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
9
|
+
import { debug, info } from "../../core/logger/core.js";
|
|
10
|
+
import { printHelp } from "../../core/messages.js";
|
|
8
11
|
import { printDiagnostic } from "./print.js";
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
var CheckResult = /* @__PURE__ */ ((CheckResult2) => {
|
|
13
|
+
CheckResult2[CheckResult2["ExitWithSuccess"] = 0] = "ExitWithSuccess";
|
|
14
|
+
CheckResult2[CheckResult2["ExitWithError"] = 1] = "ExitWithError";
|
|
15
|
+
CheckResult2[CheckResult2["Listen"] = 2] = "Listen";
|
|
16
|
+
return CheckResult2;
|
|
17
|
+
})(CheckResult || {});
|
|
18
|
+
const ASTRO_GLOB_PATTERN = "**/*.astro";
|
|
19
|
+
async function check(settings, { logging, flags }) {
|
|
20
|
+
if (flags.help || flags.h) {
|
|
21
|
+
printHelp({
|
|
22
|
+
commandName: "astro check",
|
|
23
|
+
usage: "[...flags]",
|
|
24
|
+
tables: {
|
|
25
|
+
Flags: [["--help (-h)", "See all available flags."]]
|
|
26
|
+
},
|
|
27
|
+
description: `Runs diagnostics against your project and reports errors to the console.`
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const checkFlags = parseFlags(flags);
|
|
32
|
+
if (checkFlags.watch) {
|
|
33
|
+
info(logging, "check", "Checking files in watch mode");
|
|
34
|
+
} else {
|
|
35
|
+
info(logging, "check", "Checking files");
|
|
36
|
+
}
|
|
11
37
|
const { syncCli } = await import("../../core/sync/index.js");
|
|
12
|
-
const syncRet = await syncCli(settings, { logging, fs });
|
|
13
|
-
if (syncRet === 1)
|
|
14
|
-
return syncRet;
|
|
15
38
|
const root = settings.config.root;
|
|
16
|
-
const spinner = ora(` Getting diagnostics for Astro files in ${fileURLToPath(root)}\u2026`).start();
|
|
17
39
|
const require2 = createRequire(import.meta.url);
|
|
18
|
-
|
|
40
|
+
const diagnosticChecker = new AstroCheck(
|
|
19
41
|
root.toString(),
|
|
20
|
-
require2.resolve("typescript/lib/tsserverlibrary.js", {
|
|
42
|
+
require2.resolve("typescript/lib/tsserverlibrary.js", {
|
|
43
|
+
paths: [root.toString()]
|
|
44
|
+
})
|
|
21
45
|
);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
return new AstroChecker({
|
|
47
|
+
syncCli,
|
|
48
|
+
settings,
|
|
49
|
+
fileSystem: fs,
|
|
50
|
+
logging,
|
|
51
|
+
diagnosticChecker,
|
|
52
|
+
isWatchMode: checkFlags.watch
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
class AstroChecker {
|
|
56
|
+
#diagnosticsChecker;
|
|
57
|
+
#shouldWatch;
|
|
58
|
+
#syncCli;
|
|
59
|
+
#settings;
|
|
60
|
+
#logging;
|
|
61
|
+
#fs;
|
|
62
|
+
#watcher;
|
|
63
|
+
#filesCount;
|
|
64
|
+
#updateDiagnostics;
|
|
65
|
+
constructor({
|
|
66
|
+
diagnosticChecker,
|
|
67
|
+
isWatchMode,
|
|
68
|
+
syncCli,
|
|
69
|
+
settings,
|
|
70
|
+
fileSystem,
|
|
71
|
+
logging
|
|
72
|
+
}) {
|
|
73
|
+
this.#diagnosticsChecker = diagnosticChecker;
|
|
74
|
+
this.#shouldWatch = isWatchMode;
|
|
75
|
+
this.#syncCli = syncCli;
|
|
76
|
+
this.#logging = logging;
|
|
77
|
+
this.#settings = settings;
|
|
78
|
+
this.#fs = fileSystem;
|
|
79
|
+
this.#filesCount = 0;
|
|
80
|
+
}
|
|
81
|
+
async check() {
|
|
82
|
+
return await this.#checkAllFiles(true);
|
|
83
|
+
}
|
|
84
|
+
async watch() {
|
|
85
|
+
await this.#checkAllFiles(true);
|
|
86
|
+
await this.#watch();
|
|
87
|
+
return 2 /* Listen */;
|
|
88
|
+
}
|
|
89
|
+
async stop() {
|
|
90
|
+
var _a;
|
|
91
|
+
await ((_a = this.#watcher) == null ? void 0 : _a.close());
|
|
92
|
+
}
|
|
93
|
+
get isWatchMode() {
|
|
94
|
+
return this.#shouldWatch;
|
|
95
|
+
}
|
|
96
|
+
async #openDocuments() {
|
|
97
|
+
this.#filesCount = await openAllDocuments(
|
|
98
|
+
this.#settings.config.root,
|
|
99
|
+
[],
|
|
100
|
+
this.#diagnosticsChecker
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
async #checkAllFiles(openDocuments) {
|
|
104
|
+
const processExit = await this.#syncCli(this.#settings, {
|
|
105
|
+
logging: this.#logging,
|
|
106
|
+
fs: this.#fs
|
|
107
|
+
});
|
|
108
|
+
if (processExit === 1)
|
|
109
|
+
return processExit;
|
|
110
|
+
let spinner = ora(
|
|
111
|
+
` Getting diagnostics for Astro files in ${fileURLToPath(this.#settings.config.root)}\u2026`
|
|
112
|
+
).start();
|
|
113
|
+
if (openDocuments) {
|
|
114
|
+
await this.#openDocuments();
|
|
115
|
+
}
|
|
116
|
+
let diagnostics = await this.#diagnosticsChecker.getDiagnostics();
|
|
117
|
+
spinner.succeed();
|
|
118
|
+
let brokenDownDiagnostics = this.#breakDownDiagnostics(diagnostics);
|
|
119
|
+
this.#logDiagnosticsSeverity(brokenDownDiagnostics);
|
|
120
|
+
return brokenDownDiagnostics.errors > 0 ? 1 /* ExitWithError */ : 0 /* ExitWithSuccess */;
|
|
121
|
+
}
|
|
122
|
+
#checkForDiagnostics() {
|
|
123
|
+
clearTimeout(this.#updateDiagnostics);
|
|
124
|
+
this.#updateDiagnostics = setTimeout(async () => await this.#checkAllFiles(false), 500);
|
|
125
|
+
}
|
|
126
|
+
async #watch() {
|
|
127
|
+
const { default: chokidar } = await import("chokidar");
|
|
128
|
+
this.#watcher = chokidar.watch(
|
|
129
|
+
join(fileURLToPath(this.#settings.config.root), ASTRO_GLOB_PATTERN),
|
|
130
|
+
{
|
|
131
|
+
ignored: ["**/node_modules/**"],
|
|
132
|
+
ignoreInitial: true
|
|
46
133
|
}
|
|
134
|
+
);
|
|
135
|
+
this.#watcher.on("add", (file) => {
|
|
136
|
+
this.#addDocument(file);
|
|
137
|
+
this.#filesCount += 1;
|
|
138
|
+
this.#checkForDiagnostics();
|
|
47
139
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
140
|
+
this.#watcher.on("change", (file) => {
|
|
141
|
+
this.#addDocument(file);
|
|
142
|
+
this.#checkForDiagnostics();
|
|
143
|
+
});
|
|
144
|
+
this.#watcher.on("unlink", (file) => {
|
|
145
|
+
this.#diagnosticsChecker.removeDocument(file);
|
|
146
|
+
this.#filesCount -= 1;
|
|
147
|
+
this.#checkForDiagnostics();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
#addDocument(filePath) {
|
|
151
|
+
const text = fs.readFileSync(filePath, "utf-8");
|
|
152
|
+
this.#diagnosticsChecker.upsertDocument({
|
|
153
|
+
uri: pathToFileURL(filePath).toString(),
|
|
154
|
+
text
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
#logDiagnosticsSeverity(result) {
|
|
158
|
+
info(
|
|
159
|
+
this.#logging,
|
|
160
|
+
"diagnostics",
|
|
161
|
+
[
|
|
162
|
+
bold(`Result (${this.#filesCount} file${this.#filesCount === 1 ? "" : "s"}): `),
|
|
163
|
+
bold(red(`${result.errors} ${result.errors === 1 ? "error" : "errors"}`)),
|
|
164
|
+
bold(yellow(`${result.warnings} ${result.warnings === 1 ? "warning" : "warnings"}`)),
|
|
165
|
+
dim(`${result.hints} ${result.hints === 1 ? "hint" : "hints"}
|
|
55
166
|
`)
|
|
56
|
-
|
|
167
|
+
].join(`
|
|
57
168
|
${dim("-")} `)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
#breakDownDiagnostics(diagnostics) {
|
|
172
|
+
let result = {
|
|
173
|
+
errors: 0,
|
|
174
|
+
warnings: 0,
|
|
175
|
+
hints: 0
|
|
176
|
+
};
|
|
177
|
+
diagnostics.forEach((diag) => {
|
|
178
|
+
diag.diagnostics.forEach((d) => {
|
|
179
|
+
info(this.#logging, "diagnostics", `
|
|
180
|
+
${printDiagnostic(diag.fileUri, diag.text, d)}`);
|
|
181
|
+
switch (d.severity) {
|
|
182
|
+
case DiagnosticSeverity.Error: {
|
|
183
|
+
result.errors++;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case DiagnosticSeverity.Warning: {
|
|
187
|
+
result.warnings++;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case DiagnosticSeverity.Hint: {
|
|
191
|
+
result.hints++;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
61
199
|
}
|
|
62
200
|
async function openAllDocuments(workspaceUri, filePathsToIgnore, checker) {
|
|
63
|
-
const files = await glob(
|
|
201
|
+
const files = await glob(ASTRO_GLOB_PATTERN, {
|
|
64
202
|
cwd: fileURLToPath(workspaceUri),
|
|
65
203
|
ignore: ["node_modules/**"].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`)),
|
|
66
204
|
absolute: true
|
|
67
205
|
});
|
|
68
206
|
for (const file of files) {
|
|
207
|
+
debug("check", `Adding file ${file} to the list of files to check.`);
|
|
69
208
|
const text = fs.readFileSync(file, "utf-8");
|
|
70
209
|
checker.upsertDocument({
|
|
71
210
|
uri: pathToFileURL(file).toString(),
|
|
@@ -74,6 +213,13 @@ async function openAllDocuments(workspaceUri, filePathsToIgnore, checker) {
|
|
|
74
213
|
}
|
|
75
214
|
return files.length;
|
|
76
215
|
}
|
|
216
|
+
function parseFlags(flags) {
|
|
217
|
+
return {
|
|
218
|
+
watch: flags.watch ?? false
|
|
219
|
+
};
|
|
220
|
+
}
|
|
77
221
|
export {
|
|
222
|
+
AstroChecker,
|
|
223
|
+
CheckResult,
|
|
78
224
|
check
|
|
79
225
|
};
|
package/dist/cli/index.js
CHANGED
|
@@ -53,17 +53,18 @@ async function printVersion() {
|
|
|
53
53
|
}
|
|
54
54
|
function resolveCommand(flags) {
|
|
55
55
|
const cmd = flags._[2];
|
|
56
|
-
if (cmd === "add")
|
|
57
|
-
return "add";
|
|
58
|
-
if (cmd === "sync")
|
|
59
|
-
return "sync";
|
|
60
|
-
if (cmd === "telemetry")
|
|
61
|
-
return "telemetry";
|
|
62
56
|
if (flags.version)
|
|
63
57
|
return "version";
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
const supportedCommands = /* @__PURE__ */ new Set([
|
|
59
|
+
"add",
|
|
60
|
+
"sync",
|
|
61
|
+
"telemetry",
|
|
62
|
+
"dev",
|
|
63
|
+
"build",
|
|
64
|
+
"preview",
|
|
65
|
+
"check",
|
|
66
|
+
"docs"
|
|
67
|
+
]);
|
|
67
68
|
if (supportedCommands.has(cmd)) {
|
|
68
69
|
return cmd;
|
|
69
70
|
}
|
|
@@ -109,6 +110,16 @@ async function runCommand(cmd, flags) {
|
|
|
109
110
|
}
|
|
110
111
|
case "docs": {
|
|
111
112
|
telemetry.record(event.eventCliSession(cmd));
|
|
113
|
+
if (flags.help || flags.h) {
|
|
114
|
+
printHelp({
|
|
115
|
+
commandName: "astro docs",
|
|
116
|
+
tables: {
|
|
117
|
+
Flags: [["--help (-h)", "See all available flags."]]
|
|
118
|
+
},
|
|
119
|
+
description: `Launches the Astro Docs website directly from the terminal.`
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
112
123
|
return await openInBrowser("https://docs.astro.build/");
|
|
113
124
|
}
|
|
114
125
|
case "telemetry": {
|
|
@@ -154,21 +165,33 @@ async function runCommand(cmd, flags) {
|
|
|
154
165
|
}
|
|
155
166
|
case "build": {
|
|
156
167
|
const { default: build } = await import("../core/build/index.js");
|
|
157
|
-
return await build(settings, {
|
|
168
|
+
return await build(settings, { flags, logging, telemetry, teardownCompiler: true });
|
|
158
169
|
}
|
|
159
170
|
case "check": {
|
|
160
|
-
const
|
|
161
|
-
|
|
171
|
+
const checkServer = await check(settings, { flags, logging });
|
|
172
|
+
if (checkServer) {
|
|
173
|
+
if (checkServer.isWatchMode) {
|
|
174
|
+
await checkServer.watch();
|
|
175
|
+
return await new Promise(() => {
|
|
176
|
+
});
|
|
177
|
+
} else {
|
|
178
|
+
let checkResult = await checkServer.check();
|
|
179
|
+
return process.exit(checkResult);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
162
182
|
}
|
|
163
183
|
case "sync": {
|
|
164
184
|
const { syncCli } = await import("../core/sync/index.js");
|
|
165
|
-
const
|
|
166
|
-
return process.exit(
|
|
185
|
+
const result = await syncCli(settings, { logging, fs, flags });
|
|
186
|
+
return process.exit(result);
|
|
167
187
|
}
|
|
168
188
|
case "preview": {
|
|
169
189
|
const { default: preview } = await import("../core/preview/index.js");
|
|
170
|
-
const server = await preview(settings, { logging, telemetry });
|
|
171
|
-
|
|
190
|
+
const server = await preview(settings, { logging, telemetry, flags });
|
|
191
|
+
if (server) {
|
|
192
|
+
return await server.closed();
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
172
195
|
}
|
|
173
196
|
}
|
|
174
197
|
throw new Error(`Error running ${cmd} -- no command found.`);
|
package/dist/cli/telemetry.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as msg from "../core/messages.js";
|
|
2
2
|
async function update(subcommand, { flags, telemetry }) {
|
|
3
3
|
const isValid = ["enable", "disable", "reset"].includes(subcommand);
|
|
4
|
-
if (flags.help || !isValid) {
|
|
4
|
+
if (flags.help || flags.h || !isValid) {
|
|
5
5
|
msg.printHelp({
|
|
6
6
|
commandName: "astro telemetry",
|
|
7
7
|
usage: "[command]",
|
package/dist/content/consts.d.ts
CHANGED
package/dist/content/consts.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const contentFileExts = [".md", ".mdx"];
|
|
2
1
|
const PROPAGATED_ASSET_FLAG = "astroPropagatedAssets";
|
|
3
2
|
const CONTENT_FLAG = "astroContent";
|
|
4
3
|
const VIRTUAL_MODULE_ID = "astro:content";
|
|
@@ -13,6 +12,5 @@ export {
|
|
|
13
12
|
PROPAGATED_ASSET_FLAG,
|
|
14
13
|
SCRIPTS_PLACEHOLDER,
|
|
15
14
|
STYLES_PLACEHOLDER,
|
|
16
|
-
VIRTUAL_MODULE_ID
|
|
17
|
-
contentFileExts
|
|
15
|
+
VIRTUAL_MODULE_ID
|
|
18
16
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Metadata } from '../assets/utils/metadata.js';
|
|
1
3
|
type GlobResult = Record<string, () => Promise<any>>;
|
|
2
4
|
type CollectionToEntryMap = Record<string, GlobResult>;
|
|
3
5
|
export declare function createCollectionToGlobResultMap({ globResult, contentDir, }: {
|
|
@@ -34,4 +36,9 @@ export declare function createGetEntryBySlug({ getCollection, collectionToRender
|
|
|
34
36
|
remarkPluginFrontmatter: any;
|
|
35
37
|
}>;
|
|
36
38
|
} | undefined>;
|
|
39
|
+
export declare function createImage(options: {
|
|
40
|
+
assetsDir: string;
|
|
41
|
+
}): () => z.ZodEffects<z.ZodString, (Metadata & {
|
|
42
|
+
__astro_asset: true;
|
|
43
|
+
}) | undefined, string>;
|
|
37
44
|
export {};
|
package/dist/content/internal.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { imageMetadata } from "../assets/utils/metadata.js";
|
|
1
3
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
2
4
|
import { prependForwardSlash } from "../core/path.js";
|
|
3
5
|
import {
|
|
@@ -23,7 +25,7 @@ function createCollectionToGlobResultMap({
|
|
|
23
25
|
continue;
|
|
24
26
|
const collection = segments[0];
|
|
25
27
|
const entryId = segments.slice(1).join("/");
|
|
26
|
-
collectionToGlobResultMap[collection]
|
|
28
|
+
collectionToGlobResultMap[collection] ??= {};
|
|
27
29
|
collectionToGlobResultMap[collection][entryId] = globResult[key];
|
|
28
30
|
}
|
|
29
31
|
return collectionToGlobResultMap;
|
|
@@ -98,7 +100,7 @@ async function render({
|
|
|
98
100
|
id,
|
|
99
101
|
collectionToRenderEntryMap
|
|
100
102
|
}) {
|
|
101
|
-
var _a;
|
|
103
|
+
var _a, _b;
|
|
102
104
|
const UnexpectedRenderError = new AstroError({
|
|
103
105
|
...AstroErrorData.UnknownContentCollectionError,
|
|
104
106
|
message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
|
|
@@ -153,12 +155,32 @@ async function render({
|
|
|
153
155
|
});
|
|
154
156
|
return {
|
|
155
157
|
Content,
|
|
156
|
-
headings: mod.getHeadings(),
|
|
157
|
-
remarkPluginFrontmatter: mod.frontmatter
|
|
158
|
+
headings: ((_b = mod.getHeadings) == null ? void 0 : _b.call(mod)) ?? [],
|
|
159
|
+
remarkPluginFrontmatter: mod.frontmatter ?? {}
|
|
158
160
|
};
|
|
159
161
|
}
|
|
162
|
+
function createImage(options) {
|
|
163
|
+
return () => {
|
|
164
|
+
if (options.assetsDir === "undefined") {
|
|
165
|
+
throw new Error("Enable `experimental.assets` in your Astro config to use image()");
|
|
166
|
+
}
|
|
167
|
+
return z.string().transform(async (imagePath) => {
|
|
168
|
+
const fullPath = new URL(imagePath, options.assetsDir);
|
|
169
|
+
return await getImageMetadata(fullPath);
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async function getImageMetadata(imagePath) {
|
|
174
|
+
const meta = await imageMetadata(imagePath);
|
|
175
|
+
if (!meta) {
|
|
176
|
+
return void 0;
|
|
177
|
+
}
|
|
178
|
+
delete meta.orientation;
|
|
179
|
+
return { ...meta, __astro_asset: true };
|
|
180
|
+
}
|
|
160
181
|
export {
|
|
161
182
|
createCollectionToGlobResultMap,
|
|
162
183
|
createGetCollection,
|
|
163
|
-
createGetEntryBySlug
|
|
184
|
+
createGetEntryBySlug,
|
|
185
|
+
createImage
|
|
164
186
|
};
|
|
@@ -8,6 +8,7 @@ import { info, warn } from "../core/logger/core.js";
|
|
|
8
8
|
import { isRelativePath } from "../core/path.js";
|
|
9
9
|
import { CONTENT_TYPES_FILE } from "./consts.js";
|
|
10
10
|
import {
|
|
11
|
+
getContentEntryExts,
|
|
11
12
|
getContentPaths,
|
|
12
13
|
getEntryInfo,
|
|
13
14
|
getEntrySlug,
|
|
@@ -27,9 +28,10 @@ async function createContentTypesGenerator({
|
|
|
27
28
|
}) {
|
|
28
29
|
const contentTypes = {};
|
|
29
30
|
const contentPaths = getContentPaths(settings.config, fs);
|
|
31
|
+
const contentEntryExts = getContentEntryExts(settings);
|
|
30
32
|
let events = [];
|
|
31
33
|
let debounceTimeout;
|
|
32
|
-
const
|
|
34
|
+
const typeTemplateContent = await fs.promises.readFile(contentPaths.typesTemplate, "utf-8");
|
|
33
35
|
async function init() {
|
|
34
36
|
if (!fs.existsSync(contentPaths.contentDir)) {
|
|
35
37
|
return { typesGenerated: false, reason: "no-content-dir" };
|
|
@@ -77,7 +79,7 @@ async function createContentTypesGenerator({
|
|
|
77
79
|
}
|
|
78
80
|
return { shouldGenerateTypes: true };
|
|
79
81
|
}
|
|
80
|
-
const fileType = getEntryType(fileURLToPath(event.entry), contentPaths);
|
|
82
|
+
const fileType = getEntryType(fileURLToPath(event.entry), contentPaths, contentEntryExts);
|
|
81
83
|
if (fileType === "ignored") {
|
|
82
84
|
return { shouldGenerateTypes: false };
|
|
83
85
|
}
|
|
@@ -204,8 +206,9 @@ async function createContentTypesGenerator({
|
|
|
204
206
|
fs,
|
|
205
207
|
contentTypes,
|
|
206
208
|
contentPaths,
|
|
207
|
-
|
|
208
|
-
contentConfig: observable.status === "loaded" ? observable.config : void 0
|
|
209
|
+
typeTemplateContent,
|
|
210
|
+
contentConfig: observable.status === "loaded" ? observable.config : void 0,
|
|
211
|
+
contentEntryTypes: settings.contentEntryTypes
|
|
209
212
|
});
|
|
210
213
|
if (observable.status === "loaded" && ["info", "warn"].includes(logLevel)) {
|
|
211
214
|
warnNonexistentCollections({
|
|
@@ -231,7 +234,7 @@ async function parseSlug({
|
|
|
231
234
|
}) {
|
|
232
235
|
const rawContents = await fs.promises.readFile(event.entry, "utf-8");
|
|
233
236
|
const { data: frontmatter } = parseFrontmatter(rawContents, fileURLToPath(event.entry));
|
|
234
|
-
return getEntrySlug({ ...entryInfo,
|
|
237
|
+
return getEntrySlug({ ...entryInfo, unvalidatedSlug: frontmatter.slug });
|
|
235
238
|
}
|
|
236
239
|
function setEntry(contentTypes, collectionKey, entryKey, slug) {
|
|
237
240
|
contentTypes[collectionKey][entryKey] = { slug };
|
|
@@ -243,7 +246,8 @@ async function writeContentFiles({
|
|
|
243
246
|
fs,
|
|
244
247
|
contentPaths,
|
|
245
248
|
contentTypes,
|
|
246
|
-
|
|
249
|
+
typeTemplateContent,
|
|
250
|
+
contentEntryTypes,
|
|
247
251
|
contentConfig
|
|
248
252
|
}) {
|
|
249
253
|
let contentTypesStr = "";
|
|
@@ -256,6 +260,9 @@ async function writeContentFiles({
|
|
|
256
260
|
for (const entryKey of entryKeys) {
|
|
257
261
|
const entryMetadata = contentTypes[collectionKey][entryKey];
|
|
258
262
|
const dataType = (collectionConfig == null ? void 0 : collectionConfig.schema) ? `InferEntrySchema<${collectionKey}>` : "any";
|
|
263
|
+
const renderType = `{ render(): Render[${JSON.stringify(
|
|
264
|
+
path.extname(JSON.parse(entryKey))
|
|
265
|
+
)}] }`;
|
|
259
266
|
const slugType = JSON.stringify(entryMetadata.slug);
|
|
260
267
|
contentTypesStr += `${entryKey}: {
|
|
261
268
|
id: ${entryKey},
|
|
@@ -263,7 +270,7 @@ async function writeContentFiles({
|
|
|
263
270
|
body: string,
|
|
264
271
|
collection: ${collectionKey},
|
|
265
272
|
data: ${dataType}
|
|
266
|
-
},
|
|
273
|
+
} & ${renderType},
|
|
267
274
|
`;
|
|
268
275
|
}
|
|
269
276
|
contentTypesStr += `},
|
|
@@ -280,12 +287,20 @@ async function writeContentFiles({
|
|
|
280
287
|
if (configPathRelativeToCacheDir.endsWith(".ts")) {
|
|
281
288
|
configPathRelativeToCacheDir = configPathRelativeToCacheDir.replace(/\.ts$/, "");
|
|
282
289
|
}
|
|
283
|
-
|
|
284
|
-
|
|
290
|
+
for (const contentEntryType of contentEntryTypes) {
|
|
291
|
+
if (contentEntryType.contentModuleTypes) {
|
|
292
|
+
typeTemplateContent = contentEntryType.contentModuleTypes + "\n" + typeTemplateContent;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
typeTemplateContent = typeTemplateContent.replace("// @@ENTRY_MAP@@", contentTypesStr);
|
|
296
|
+
typeTemplateContent = typeTemplateContent.replace(
|
|
285
297
|
"'@@CONTENT_CONFIG_TYPE@@'",
|
|
286
298
|
contentConfig ? `typeof import(${JSON.stringify(configPathRelativeToCacheDir)})` : "never"
|
|
287
299
|
);
|
|
288
|
-
await fs.promises.writeFile(
|
|
300
|
+
await fs.promises.writeFile(
|
|
301
|
+
new URL(CONTENT_TYPES_FILE, contentPaths.cacheDir),
|
|
302
|
+
typeTemplateContent
|
|
303
|
+
);
|
|
289
304
|
}
|
|
290
305
|
function warnNonexistentCollections({
|
|
291
306
|
contentConfig,
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -34,16 +34,9 @@ export declare const contentConfigParser: z.ZodObject<{
|
|
|
34
34
|
}>;
|
|
35
35
|
export type CollectionConfig = z.infer<typeof collectionConfigParser>;
|
|
36
36
|
export type ContentConfig = z.infer<typeof contentConfigParser>;
|
|
37
|
-
type
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
slug: string;
|
|
41
|
-
data: any;
|
|
42
|
-
body: string;
|
|
43
|
-
_internal: {
|
|
44
|
-
rawData: string;
|
|
45
|
-
filePath: string;
|
|
46
|
-
};
|
|
37
|
+
type EntryInternal = {
|
|
38
|
+
rawData: string;
|
|
39
|
+
filePath: string;
|
|
47
40
|
};
|
|
48
41
|
export type EntryInfo = {
|
|
49
42
|
id: string;
|
|
@@ -53,15 +46,24 @@ export type EntryInfo = {
|
|
|
53
46
|
export declare const msg: {
|
|
54
47
|
collectionConfigMissing: (collection: string) => string;
|
|
55
48
|
};
|
|
56
|
-
export declare function
|
|
57
|
-
export declare function
|
|
49
|
+
export declare function extractFrontmatterAssets(data: Record<string, any>): string[];
|
|
50
|
+
export declare function getEntrySlug({ id, collection, slug, unvalidatedSlug, }: EntryInfo & {
|
|
51
|
+
unvalidatedSlug?: unknown;
|
|
52
|
+
}): string;
|
|
53
|
+
export declare function getEntryData(entry: EntryInfo & {
|
|
54
|
+
unvalidatedData: Record<string, unknown>;
|
|
55
|
+
_internal: EntryInternal;
|
|
56
|
+
}, collectionConfig: CollectionConfig): Promise<{
|
|
57
|
+
[x: string]: unknown;
|
|
58
|
+
}>;
|
|
59
|
+
export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
|
|
58
60
|
export declare class NoCollectionError extends Error {
|
|
59
61
|
}
|
|
60
62
|
export declare function getEntryInfo(params: Pick<ContentPaths, 'contentDir'> & {
|
|
61
63
|
entry: URL;
|
|
62
64
|
allowFilesOutsideCollection?: true;
|
|
63
65
|
}): EntryInfo;
|
|
64
|
-
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'
|
|
66
|
+
export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[]): 'content' | 'config' | 'ignored' | 'unsupported';
|
|
65
67
|
/**
|
|
66
68
|
* Match YAML exception handling from Astro core errors
|
|
67
69
|
* @see 'astro/src/core/errors.ts'
|
|
@@ -100,6 +102,7 @@ export type ContentObservable = Observable<ContentCtx>;
|
|
|
100
102
|
export declare function contentObservable(initialCtx: ContentCtx): ContentObservable;
|
|
101
103
|
export type ContentPaths = {
|
|
102
104
|
contentDir: URL;
|
|
105
|
+
assetsDir: URL;
|
|
103
106
|
cacheDir: URL;
|
|
104
107
|
typesTemplate: URL;
|
|
105
108
|
virtualModTemplate: URL;
|