astro 2.9.7 → 3.0.0-beta.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/astro.js +2 -2
- package/components/ViewTransitions.astro +65 -12
- package/dist/@types/astro.d.ts +68 -7
- package/dist/@types/astro.js +1 -0
- package/dist/assets/generate.js +7 -3
- package/dist/assets/image-endpoint.d.ts +1 -1
- package/dist/assets/image-endpoint.js +3 -3
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/noop.d.ts +3 -0
- package/dist/assets/services/noop.js +17 -0
- package/dist/assets/services/vendor/squoosh/image_data.js +3 -0
- package/dist/assets/services/vendor/squoosh/impl.js +2 -3
- package/dist/assets/services/vendor/squoosh/utils/workerPool.js +4 -0
- package/dist/assets/vendor/image-size/types/tiff.js +1 -1
- package/dist/assets/vendor/queue/queue.d.ts +3 -3
- package/dist/assets/vite-plugin-assets.d.ts +1 -1
- package/dist/assets/vite-plugin-assets.js +1 -23
- package/dist/cli/add/index.js +6 -9
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/check/index.d.ts +2 -78
- package/dist/cli/check/index.js +23 -275
- package/dist/cli/dev/index.js +1 -1
- package/dist/cli/index.js +7 -13
- package/dist/cli/info/index.js +3 -4
- package/dist/cli/install-package.d.ts +7 -0
- package/dist/cli/install-package.js +102 -0
- package/dist/cli/preview/index.js +1 -1
- package/dist/cli/sync/index.js +1 -1
- package/dist/content/runtime-assets.js +1 -2
- package/dist/content/runtime.js +3 -5
- package/dist/content/server-listeners.js +1 -2
- package/dist/content/types-generator.js +8 -8
- package/dist/content/utils.js +3 -4
- package/dist/content/vite-plugin-content-assets.js +4 -6
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +5 -6
- package/dist/core/app/index.js +5 -3
- package/dist/core/app/node.d.ts +1 -1
- package/dist/core/app/node.js +7 -2
- package/dist/core/build/css-asset-name.js +2 -4
- package/dist/core/build/generate.js +10 -17
- package/dist/core/build/graph.js +3 -4
- package/dist/core/build/index.js +8 -1
- package/dist/core/build/internal.js +2 -2
- package/dist/core/build/plugin.js +2 -4
- package/dist/core/build/plugins/plugin-analyzer.js +6 -9
- package/dist/core/build/plugins/plugin-component-entry.js +2 -4
- package/dist/core/build/plugins/plugin-css.js +6 -9
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +2 -3
- package/dist/core/build/plugins/plugin-internals.js +1 -2
- package/dist/core/build/plugins/plugin-pages.js +5 -1
- package/dist/core/build/plugins/plugin-ssr.js +12 -8
- package/dist/core/build/static-build.js +8 -12
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/compile/compile.js +2 -1
- package/dist/core/compile/style.js +2 -3
- package/dist/core/config/schema.d.ts +8 -0
- package/dist/core/config/schema.js +11 -3
- package/dist/core/config/settings.js +3 -3
- package/dist/core/config/timer.js +5 -6
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.d.ts +5 -5
- package/dist/core/cookies/cookies.js +9 -9
- package/dist/core/create-vite.js +6 -28
- package/dist/core/dev/container.d.ts +0 -1
- package/dist/core/dev/container.js +0 -5
- package/dist/core/dev/dev.js +2 -3
- package/dist/core/dev/index.d.ts +1 -1
- package/dist/core/dev/index.js +1 -2
- package/dist/core/dev/restart.d.ts +1 -4
- package/dist/core/dev/restart.js +15 -19
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/endpoint/index.js +3 -4
- package/dist/core/errors/dev/utils.js +12 -16
- package/dist/core/errors/dev/vite.js +11 -13
- package/dist/core/errors/errors-data.d.ts +21 -0
- package/dist/core/errors/errors-data.js +21 -0
- package/dist/core/errors/errors.js +12 -17
- package/dist/core/errors/overlay.js +7 -8
- package/dist/core/errors/utils.js +1 -1
- package/dist/core/fs/index.js +1 -1
- package/dist/core/logger/console.js +1 -1
- package/dist/core/logger/core.d.ts +26 -6
- package/dist/core/logger/core.js +54 -8
- package/dist/core/logger/node.d.ts +4 -4
- package/dist/core/logger/node.js +6 -6
- package/dist/core/messages.js +4 -5
- package/dist/core/module-loader/vite.js +2 -2
- package/dist/core/polyfill.js +12 -4
- package/dist/core/redirects/helpers.js +3 -3
- package/dist/core/render/core.js +1 -4
- package/dist/core/render/params-and-props.js +2 -3
- package/dist/core/render/result.js +1 -2
- package/dist/core/render/route-cache.d.ts +1 -2
- package/dist/core/render/route-cache.js +6 -11
- package/dist/core/routing/manifest/create.js +2 -6
- package/dist/core/routing/params.js +1 -1
- package/dist/core/routing/validation.js +7 -8
- package/dist/core/sync/index.js +1 -1
- package/dist/core/util.js +1 -1
- package/dist/events/error.js +1 -1
- package/dist/events/session.js +12 -13
- package/dist/integrations/astroFeaturesValidation.d.ts +14 -0
- package/dist/integrations/astroFeaturesValidation.js +109 -0
- package/dist/integrations/index.d.ts +3 -1
- package/dist/integrations/index.js +96 -31
- package/dist/jsx/babel.js +1 -2
- package/dist/prerender/metadata.js +1 -2
- package/dist/runtime/client/hmr.js +1 -2
- package/dist/runtime/server/astro-component.js +1 -2
- package/dist/runtime/server/astro-island.js +53 -55
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.d.ts +2 -1
- package/dist/runtime/server/endpoint.js +21 -27
- package/dist/runtime/server/hydration.js +9 -0
- package/dist/runtime/server/jsx.js +3 -2
- package/dist/runtime/server/render/astro/instance.js +6 -3
- package/dist/runtime/server/render/astro/render-template.js +4 -3
- package/dist/runtime/server/render/astro/render.js +3 -3
- package/dist/runtime/server/render/common.js +1 -1
- package/dist/runtime/server/render/component.js +11 -13
- package/dist/runtime/server/render/dom.js +1 -1
- package/dist/runtime/server/render/page.js +2 -3
- package/dist/runtime/server/render/slot.js +2 -1
- package/dist/runtime/server/render/util.js +1 -2
- package/dist/runtime/server/transition.d.ts +1 -0
- package/dist/runtime/server/transition.js +1 -0
- package/dist/transitions/vite-plugin-transitions.js +1 -0
- package/dist/vite-plugin-astro/compile.js +2 -3
- package/dist/vite-plugin-astro/hmr.js +3 -5
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro/metadata.js +1 -2
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/base.js +1 -2
- package/dist/vite-plugin-astro-server/controller.js +2 -3
- package/dist/vite-plugin-astro-server/css.js +1 -1
- package/dist/vite-plugin-astro-server/request.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +1 -2
- package/dist/vite-plugin-astro-server/scripts.js +2 -3
- package/dist/vite-plugin-astro-server/vite.js +1 -1
- package/dist/vite-plugin-config-alias/index.js +1 -1
- package/dist/vite-plugin-env/index.js +2 -2
- package/dist/vite-plugin-head/index.js +4 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/index.js +1 -1
- package/dist/vite-plugin-html/transform/slots.js +5 -6
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-jsx/import-source.js +1 -2
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-jsx/tag.js +4 -6
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-scanner/index.js +2 -1
- package/dist/vite-plugin-scanner/scan.js +1 -1
- package/dist/vite-plugin-scripts/index.js +1 -1
- package/dist/vite-plugin-scripts/page-ssr.js +2 -2
- package/package.json +13 -22
- package/tsconfigs/base.json +8 -6
- package/tsconfigs/strict.json +2 -3
- package/dist/cli/check/print.d.ts +0 -2
- package/dist/cli/check/print.js +0 -95
|
@@ -1,78 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import type { Arguments as Flags } from 'yargs-parser';
|
|
5
|
-
import type { AstroSettings } from '../../@types/astro';
|
|
6
|
-
import type { LogOptions } from '../../core/logger/core.js';
|
|
7
|
-
import type { syncInternal } from '../../core/sync';
|
|
8
|
-
export type CheckPayload = {
|
|
9
|
-
/**
|
|
10
|
-
* Flags passed via CLI
|
|
11
|
-
*/
|
|
12
|
-
flags: Flags;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* Types of response emitted by the checker
|
|
17
|
-
*/
|
|
18
|
-
export declare enum CheckResult {
|
|
19
|
-
/**
|
|
20
|
-
* Operation finished without errors
|
|
21
|
-
*/
|
|
22
|
-
ExitWithSuccess = 0,
|
|
23
|
-
/**
|
|
24
|
-
* Operation finished with errors
|
|
25
|
-
*/
|
|
26
|
-
ExitWithError = 1,
|
|
27
|
-
/**
|
|
28
|
-
* The consumer should not terminate the operation
|
|
29
|
-
*/
|
|
30
|
-
Listen = 2
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Checks `.astro` files for possible errors.
|
|
34
|
-
*
|
|
35
|
-
* If the `--watch` flag is provided, the command runs indefinitely and provides diagnostics
|
|
36
|
-
* when `.astro` files are modified.
|
|
37
|
-
*
|
|
38
|
-
* Every time an astro files is modified, content collections are also generated.
|
|
39
|
-
*
|
|
40
|
-
* @param {CheckPayload} options Options passed {@link AstroChecker}
|
|
41
|
-
* @param {Flags} options.flags Flags coming from the CLI
|
|
42
|
-
*/
|
|
43
|
-
export declare function check({ flags }: CheckPayload): Promise<AstroChecker | undefined>;
|
|
44
|
-
type CheckerConstructor = {
|
|
45
|
-
diagnosticChecker: AstroCheck;
|
|
46
|
-
isWatchMode: boolean;
|
|
47
|
-
syncInternal: typeof syncInternal;
|
|
48
|
-
settings: Readonly<AstroSettings>;
|
|
49
|
-
logging: Readonly<LogOptions>;
|
|
50
|
-
fileSystem: typeof fs;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Responsible to check files - classic or watch mode - and report diagnostics.
|
|
54
|
-
*
|
|
55
|
-
* When in watch mode, the class does a whole check pass, and then starts watching files.
|
|
56
|
-
* When a change occurs to an `.astro` file, the checker builds content collections again and lint all the `.astro` files.
|
|
57
|
-
*/
|
|
58
|
-
export declare class AstroChecker {
|
|
59
|
-
#private;
|
|
60
|
-
constructor({ diagnosticChecker, isWatchMode, syncInternal, settings, fileSystem, logging, }: CheckerConstructor);
|
|
61
|
-
/**
|
|
62
|
-
* Check all `.astro` files once and then finishes the operation.
|
|
63
|
-
*/
|
|
64
|
-
check(): Promise<CheckResult>;
|
|
65
|
-
/**
|
|
66
|
-
* Check all `.astro` files and then start watching for changes.
|
|
67
|
-
*/
|
|
68
|
-
watch(): Promise<CheckResult>;
|
|
69
|
-
/**
|
|
70
|
-
* Stops the watch. It terminates the inner server.
|
|
71
|
-
*/
|
|
72
|
-
stop(): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Whether the checker should run in watch mode
|
|
75
|
-
*/
|
|
76
|
-
get isWatchMode(): boolean;
|
|
77
|
-
}
|
|
78
|
-
export {};
|
|
1
|
+
import type { Arguments } from 'yargs-parser';
|
|
2
|
+
export declare function check(flags: Arguments): Promise<boolean | void>;
|
package/dist/cli/check/index.js
CHANGED
|
@@ -1,282 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
-
import ora from "ora";
|
|
12
|
-
import { resolveConfig } from "../../core/config/config.js";
|
|
13
|
-
import { createNodeLogging } from "../../core/config/logging.js";
|
|
14
|
-
import { createSettings } from "../../core/config/settings.js";
|
|
15
|
-
import { debug, info } from "../../core/logger/core.js";
|
|
16
|
-
import { printHelp } from "../../core/messages.js";
|
|
17
|
-
import { eventCliSession, telemetry } from "../../events/index.js";
|
|
18
|
-
import { runHookConfigSetup } from "../../integrations/index.js";
|
|
19
|
-
import { flagsToAstroInlineConfig } from "../flags.js";
|
|
20
|
-
import { printDiagnostic } from "./print.js";
|
|
21
|
-
var CheckResult = /* @__PURE__ */ ((CheckResult2) => {
|
|
22
|
-
CheckResult2[CheckResult2["ExitWithSuccess"] = 0] = "ExitWithSuccess";
|
|
23
|
-
CheckResult2[CheckResult2["ExitWithError"] = 1] = "ExitWithError";
|
|
24
|
-
CheckResult2[CheckResult2["Listen"] = 2] = "Listen";
|
|
25
|
-
return CheckResult2;
|
|
26
|
-
})(CheckResult || {});
|
|
27
|
-
const ASTRO_GLOB_PATTERN = "**/*.astro";
|
|
28
|
-
async function check({ flags }) {
|
|
29
|
-
if (flags.help || flags.h) {
|
|
30
|
-
printHelp({
|
|
31
|
-
commandName: "astro check",
|
|
32
|
-
usage: "[...flags]",
|
|
33
|
-
tables: {
|
|
34
|
-
Flags: [
|
|
35
|
-
["--watch", "Watch Astro files for changes and re-run checks."],
|
|
36
|
-
["--help (-h)", "See all available flags."]
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
description: `Runs diagnostics against your project and reports errors to the console.`
|
|
40
|
-
});
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const inlineConfig = flagsToAstroInlineConfig(flags);
|
|
44
|
-
const logging = createNodeLogging(inlineConfig);
|
|
45
|
-
const { userConfig, astroConfig } = await resolveConfig(inlineConfig, "check");
|
|
46
|
-
telemetry.record(eventCliSession("check", userConfig, flags));
|
|
47
|
-
const settings = createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
|
48
|
-
const checkFlags = parseFlags(flags);
|
|
49
|
-
if (checkFlags.watch) {
|
|
50
|
-
info(logging, "check", "Checking files in watch mode");
|
|
51
|
-
} else {
|
|
52
|
-
info(logging, "check", "Checking files");
|
|
53
|
-
}
|
|
54
|
-
const { syncInternal } = await import("../../core/sync/index.js");
|
|
55
|
-
const root = settings.config.root;
|
|
56
|
-
const require2 = createRequire(import.meta.url);
|
|
57
|
-
const diagnosticChecker = new AstroCheck(
|
|
58
|
-
root.toString(),
|
|
59
|
-
require2.resolve("typescript/lib/tsserverlibrary.js", {
|
|
60
|
-
paths: [root.toString()]
|
|
61
|
-
})
|
|
62
|
-
);
|
|
63
|
-
return new AstroChecker({
|
|
64
|
-
syncInternal,
|
|
65
|
-
settings,
|
|
66
|
-
fileSystem: fs,
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { error, info } from "../../core/logger/core.js";
|
|
3
|
+
import { createLoggingFromFlags } from "../flags.js";
|
|
4
|
+
import { getPackage } from "../install-package.js";
|
|
5
|
+
async function check(flags) {
|
|
6
|
+
const logging = createLoggingFromFlags(flags);
|
|
7
|
+
const getPackageOpts = { skipAsk: flags.yes || flags.y, cwd: flags.root };
|
|
8
|
+
const checkPackage = await getPackage(
|
|
9
|
+
"@astrojs/check",
|
|
67
10
|
logging,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
#logging;
|
|
78
|
-
#fs;
|
|
79
|
-
#watcher;
|
|
80
|
-
#filesCount;
|
|
81
|
-
#updateDiagnostics;
|
|
82
|
-
constructor({
|
|
83
|
-
diagnosticChecker,
|
|
84
|
-
isWatchMode,
|
|
85
|
-
syncInternal,
|
|
86
|
-
settings,
|
|
87
|
-
fileSystem,
|
|
88
|
-
logging
|
|
89
|
-
}) {
|
|
90
|
-
this.#diagnosticsChecker = diagnosticChecker;
|
|
91
|
-
this.#shouldWatch = isWatchMode;
|
|
92
|
-
this.#syncInternal = syncInternal;
|
|
93
|
-
this.#logging = logging;
|
|
94
|
-
this.#settings = settings;
|
|
95
|
-
this.#fs = fileSystem;
|
|
96
|
-
this.#filesCount = 0;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Check all `.astro` files once and then finishes the operation.
|
|
100
|
-
*/
|
|
101
|
-
async check() {
|
|
102
|
-
return await this.#checkAllFiles(true);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Check all `.astro` files and then start watching for changes.
|
|
106
|
-
*/
|
|
107
|
-
async watch() {
|
|
108
|
-
await this.#checkAllFiles(true);
|
|
109
|
-
await this.#watch();
|
|
110
|
-
return 2 /* Listen */;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Stops the watch. It terminates the inner server.
|
|
114
|
-
*/
|
|
115
|
-
async stop() {
|
|
116
|
-
var _a;
|
|
117
|
-
await ((_a = this.#watcher) == null ? void 0 : _a.close());
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Whether the checker should run in watch mode
|
|
121
|
-
*/
|
|
122
|
-
get isWatchMode() {
|
|
123
|
-
return this.#shouldWatch;
|
|
124
|
-
}
|
|
125
|
-
async #openDocuments() {
|
|
126
|
-
this.#filesCount = await openAllDocuments(
|
|
127
|
-
this.#settings.config.root,
|
|
128
|
-
[],
|
|
129
|
-
this.#diagnosticsChecker
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Lint all `.astro` files, and report the result in console. Operations executed, in order:
|
|
134
|
-
* 1. Compile content collections.
|
|
135
|
-
* 2. Optionally, traverse the file system for `.astro` files and saves their paths.
|
|
136
|
-
* 3. Get diagnostics for said files and print the result in console.
|
|
137
|
-
*
|
|
138
|
-
* @param openDocuments Whether the operation should open all `.astro` files
|
|
139
|
-
*/
|
|
140
|
-
async #checkAllFiles(openDocuments) {
|
|
141
|
-
const syncSettings = await runHookConfigSetup({
|
|
142
|
-
settings: this.#settings,
|
|
143
|
-
logging: this.#logging,
|
|
144
|
-
command: "build"
|
|
145
|
-
});
|
|
146
|
-
const processExit = await this.#syncInternal(syncSettings, {
|
|
147
|
-
logging: this.#logging,
|
|
148
|
-
fs: this.#fs
|
|
149
|
-
});
|
|
150
|
-
if (processExit === 1)
|
|
151
|
-
return processExit;
|
|
152
|
-
let spinner = ora(
|
|
153
|
-
` Getting diagnostics for Astro files in ${fileURLToPath(this.#settings.config.root)}\u2026`
|
|
154
|
-
).start();
|
|
155
|
-
if (openDocuments) {
|
|
156
|
-
await this.#openDocuments();
|
|
157
|
-
}
|
|
158
|
-
let diagnostics = await this.#diagnosticsChecker.getDiagnostics();
|
|
159
|
-
spinner.succeed();
|
|
160
|
-
let brokenDownDiagnostics = this.#breakDownDiagnostics(diagnostics);
|
|
161
|
-
this.#logDiagnosticsSeverity(brokenDownDiagnostics);
|
|
162
|
-
return brokenDownDiagnostics.errors > 0 ? 1 /* ExitWithError */ : 0 /* ExitWithSuccess */;
|
|
163
|
-
}
|
|
164
|
-
#checkForDiagnostics() {
|
|
165
|
-
clearTimeout(this.#updateDiagnostics);
|
|
166
|
-
this.#updateDiagnostics = setTimeout(async () => await this.#checkAllFiles(false), 500);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* This function is responsible to attach events to the server watcher
|
|
170
|
-
*/
|
|
171
|
-
async #watch() {
|
|
172
|
-
const { default: chokidar } = await import("chokidar");
|
|
173
|
-
this.#watcher = chokidar.watch(
|
|
174
|
-
join(fileURLToPath(this.#settings.config.root), ASTRO_GLOB_PATTERN),
|
|
175
|
-
{
|
|
176
|
-
ignored: ["**/node_modules/**"],
|
|
177
|
-
ignoreInitial: true
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
this.#watcher.on("add", (file) => {
|
|
181
|
-
this.#addDocument(file);
|
|
182
|
-
this.#filesCount += 1;
|
|
183
|
-
this.#checkForDiagnostics();
|
|
184
|
-
});
|
|
185
|
-
this.#watcher.on("change", (file) => {
|
|
186
|
-
this.#addDocument(file);
|
|
187
|
-
this.#checkForDiagnostics();
|
|
188
|
-
});
|
|
189
|
-
this.#watcher.on("unlink", (file) => {
|
|
190
|
-
this.#diagnosticsChecker.removeDocument(file);
|
|
191
|
-
this.#filesCount -= 1;
|
|
192
|
-
this.#checkForDiagnostics();
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Add a document to the diagnostics checker
|
|
197
|
-
* @param filePath Path to the file
|
|
198
|
-
*/
|
|
199
|
-
#addDocument(filePath) {
|
|
200
|
-
const text = fs.readFileSync(filePath, "utf-8");
|
|
201
|
-
this.#diagnosticsChecker.upsertDocument({
|
|
202
|
-
uri: pathToFileURL(filePath).toString(),
|
|
203
|
-
text
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Logs the result of the various diagnostics
|
|
208
|
-
*
|
|
209
|
-
* @param result Result emitted by AstroChecker.#breakDownDiagnostics
|
|
210
|
-
*/
|
|
211
|
-
#logDiagnosticsSeverity(result) {
|
|
212
|
-
info(
|
|
213
|
-
this.#logging,
|
|
214
|
-
"diagnostics",
|
|
215
|
-
[
|
|
216
|
-
bold(`Result (${this.#filesCount} file${this.#filesCount === 1 ? "" : "s"}): `),
|
|
217
|
-
bold(red(`${result.errors} ${result.errors === 1 ? "error" : "errors"}`)),
|
|
218
|
-
bold(yellow(`${result.warnings} ${result.warnings === 1 ? "warning" : "warnings"}`)),
|
|
219
|
-
dim(`${result.hints} ${result.hints === 1 ? "hint" : "hints"}
|
|
220
|
-
`)
|
|
221
|
-
].join(`
|
|
222
|
-
${dim("-")} `)
|
|
11
|
+
getPackageOpts,
|
|
12
|
+
["typescript"]
|
|
13
|
+
);
|
|
14
|
+
const typescript = await getPackage("typescript", logging, getPackageOpts);
|
|
15
|
+
if (!checkPackage || !typescript) {
|
|
16
|
+
error(
|
|
17
|
+
logging,
|
|
18
|
+
"check",
|
|
19
|
+
"The `@astrojs/check` and `typescript` packages are required for this command to work. Please manually install them into your project and try again."
|
|
223
20
|
);
|
|
21
|
+
return;
|
|
224
22
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
let result = {
|
|
230
|
-
errors: 0,
|
|
231
|
-
warnings: 0,
|
|
232
|
-
hints: 0
|
|
233
|
-
};
|
|
234
|
-
diagnostics.forEach((diag) => {
|
|
235
|
-
diag.diagnostics.forEach((d) => {
|
|
236
|
-
info(this.#logging, "diagnostics", `
|
|
237
|
-
${printDiagnostic(diag.fileUri, diag.text, d)}`);
|
|
238
|
-
switch (d.severity) {
|
|
239
|
-
case DiagnosticSeverity.Error: {
|
|
240
|
-
result.errors++;
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
case DiagnosticSeverity.Warning: {
|
|
244
|
-
result.warnings++;
|
|
245
|
-
break;
|
|
246
|
-
}
|
|
247
|
-
case DiagnosticSeverity.Hint: {
|
|
248
|
-
result.hints++;
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
return result;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
async function openAllDocuments(workspaceUri, filePathsToIgnore, checker) {
|
|
258
|
-
const files = await glob(ASTRO_GLOB_PATTERN, {
|
|
259
|
-
cwd: fileURLToPath(workspaceUri),
|
|
260
|
-
ignore: ["node_modules/**"].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`)),
|
|
261
|
-
absolute: true
|
|
262
|
-
});
|
|
263
|
-
for (const file of files) {
|
|
264
|
-
debug("check", `Adding file ${file} to the list of files to check.`);
|
|
265
|
-
const text = fs.readFileSync(file, "utf-8");
|
|
266
|
-
checker.upsertDocument({
|
|
267
|
-
uri: pathToFileURL(file).toString(),
|
|
268
|
-
text
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
return files.length;
|
|
272
|
-
}
|
|
273
|
-
function parseFlags(flags) {
|
|
274
|
-
return {
|
|
275
|
-
watch: flags.watch ?? false
|
|
276
|
-
};
|
|
23
|
+
const { check: checker, parseArgsAsCheckConfig } = checkPackage;
|
|
24
|
+
const config = parseArgsAsCheckConfig(process.argv);
|
|
25
|
+
info(logging, "check", `Getting diagnostics for Astro files in ${path.resolve(config.root)}...`);
|
|
26
|
+
return await checker(config);
|
|
277
27
|
}
|
|
278
28
|
export {
|
|
279
|
-
AstroChecker,
|
|
280
|
-
CheckResult,
|
|
281
29
|
check
|
|
282
30
|
};
|
package/dist/cli/dev/index.js
CHANGED
|
@@ -9,7 +9,7 @@ async function dev({ flags }) {
|
|
|
9
9
|
usage: "[...flags]",
|
|
10
10
|
tables: {
|
|
11
11
|
Flags: [
|
|
12
|
-
["--port", `Specify which port to run on. Defaults to
|
|
12
|
+
["--port", `Specify which port to run on. Defaults to 4321.`],
|
|
13
13
|
["--host", `Listen on all addresses, including LAN and public addresses.`],
|
|
14
14
|
["--host <custom-address>", `Expose on a network IP address at <custom-address>`],
|
|
15
15
|
["--open", "Automatically open the app in the browser on server start"],
|
package/dist/cli/index.js
CHANGED
|
@@ -57,7 +57,6 @@ function resolveCommand(flags) {
|
|
|
57
57
|
return "help";
|
|
58
58
|
}
|
|
59
59
|
async function runCommand(cmd, flags) {
|
|
60
|
-
var _a;
|
|
61
60
|
switch (cmd) {
|
|
62
61
|
case "help":
|
|
63
62
|
await printAstroHelp();
|
|
@@ -77,7 +76,7 @@ async function runCommand(cmd, flags) {
|
|
|
77
76
|
}
|
|
78
77
|
case "telemetry": {
|
|
79
78
|
const { update } = await import("./telemetry/index.js");
|
|
80
|
-
const subcommand =
|
|
79
|
+
const subcommand = flags._[3]?.toString();
|
|
81
80
|
await update(subcommand, { flags });
|
|
82
81
|
return;
|
|
83
82
|
}
|
|
@@ -120,18 +119,13 @@ async function runCommand(cmd, flags) {
|
|
|
120
119
|
}
|
|
121
120
|
case "check": {
|
|
122
121
|
const { check } = await import("./check/index.js");
|
|
123
|
-
const checkServer = await check(
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
} else {
|
|
130
|
-
const checkResult = await checkServer.check();
|
|
131
|
-
return process.exit(checkResult);
|
|
132
|
-
}
|
|
122
|
+
const checkServer = await check(flags);
|
|
123
|
+
if (flags.watch) {
|
|
124
|
+
return await new Promise(() => {
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
return process.exit(checkServer ? 1 : 0);
|
|
133
128
|
}
|
|
134
|
-
return;
|
|
135
129
|
}
|
|
136
130
|
case "sync": {
|
|
137
131
|
const { sync } = await import("./sync/index.js");
|
package/dist/cli/info/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { resolveConfig } from "../../core/config/index.js";
|
|
|
5
5
|
import { ASTRO_VERSION } from "../../core/constants.js";
|
|
6
6
|
import { flagsToAstroInlineConfig } from "../flags.js";
|
|
7
7
|
async function printInfo({ flags }) {
|
|
8
|
-
var _a;
|
|
9
8
|
const inlineConfig = flagsToAstroInlineConfig(flags);
|
|
10
9
|
const packageManager = await whichPm(process.cwd());
|
|
11
10
|
let adapter = "Couldn't determine.";
|
|
@@ -17,16 +16,16 @@ async function printInfo({ flags }) {
|
|
|
17
16
|
}
|
|
18
17
|
try {
|
|
19
18
|
const { userConfig } = await resolveConfig(inlineConfig, "info");
|
|
20
|
-
if (
|
|
19
|
+
if (userConfig.adapter?.name) {
|
|
21
20
|
adapter = userConfig.adapter.name;
|
|
22
21
|
}
|
|
23
22
|
if (userConfig.integrations) {
|
|
24
|
-
integrations = (
|
|
23
|
+
integrations = (userConfig?.integrations ?? []).filter(Boolean).flat().map((i) => i?.name);
|
|
25
24
|
}
|
|
26
25
|
} catch (_e) {
|
|
27
26
|
}
|
|
28
27
|
console.log();
|
|
29
|
-
const packageManagerName =
|
|
28
|
+
const packageManagerName = packageManager?.name ?? "Couldn't determine.";
|
|
30
29
|
printRow("Astro version", `v${ASTRO_VERSION}`);
|
|
31
30
|
printRow("Package manager", packageManagerName);
|
|
32
31
|
printRow("Platform", platform());
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type LogOptions } from '../core/logger/core.js';
|
|
2
|
+
type GetPackageOptions = {
|
|
3
|
+
skipAsk?: boolean;
|
|
4
|
+
cwd?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function getPackage<T>(packageName: string, logging: LogOptions, options: GetPackageOptions, otherDeps?: string[]): Promise<T | undefined>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import boxen from "boxen";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import { bold, cyan, dim, magenta } from "kleur/colors";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import ora from "ora";
|
|
6
|
+
import prompts from "prompts";
|
|
7
|
+
import whichPm from "which-pm";
|
|
8
|
+
import { debug, info } from "../core/logger/core.js";
|
|
9
|
+
async function getPackage(packageName, logging, options, otherDeps = []) {
|
|
10
|
+
const require2 = createRequire(options.cwd ?? process.cwd());
|
|
11
|
+
let packageImport;
|
|
12
|
+
try {
|
|
13
|
+
require2.resolve(packageName);
|
|
14
|
+
packageImport = await import(packageName);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
info(
|
|
17
|
+
logging,
|
|
18
|
+
"",
|
|
19
|
+
`To continue, Astro requires the following dependency to be installed: ${bold(packageName)}.`
|
|
20
|
+
);
|
|
21
|
+
const result = await installPackage([packageName, ...otherDeps], options, logging);
|
|
22
|
+
if (result) {
|
|
23
|
+
packageImport = await import(packageName);
|
|
24
|
+
} else {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return packageImport;
|
|
29
|
+
}
|
|
30
|
+
function getInstallCommand(packages, packageManager) {
|
|
31
|
+
switch (packageManager) {
|
|
32
|
+
case "npm":
|
|
33
|
+
return { pm: "npm", command: "install", flags: [], dependencies: packages };
|
|
34
|
+
case "yarn":
|
|
35
|
+
return { pm: "yarn", command: "add", flags: [], dependencies: packages };
|
|
36
|
+
case "pnpm":
|
|
37
|
+
return { pm: "pnpm", command: "add", flags: [], dependencies: packages };
|
|
38
|
+
default:
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function installPackage(packageNames, options, logging) {
|
|
43
|
+
const cwd = options.cwd ?? process.cwd();
|
|
44
|
+
const packageManager = (await whichPm(cwd)).name ?? "npm";
|
|
45
|
+
const installCommand = getInstallCommand(packageNames, packageManager);
|
|
46
|
+
if (!installCommand) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}${[
|
|
50
|
+
"",
|
|
51
|
+
...installCommand.flags
|
|
52
|
+
].join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
|
|
53
|
+
const message = `
|
|
54
|
+
${boxen(coloredOutput, {
|
|
55
|
+
margin: 0.5,
|
|
56
|
+
padding: 0.5,
|
|
57
|
+
borderStyle: "round"
|
|
58
|
+
})}
|
|
59
|
+
`;
|
|
60
|
+
info(
|
|
61
|
+
logging,
|
|
62
|
+
null,
|
|
63
|
+
`
|
|
64
|
+
${magenta("Astro will run the following command:")}
|
|
65
|
+
${dim(
|
|
66
|
+
"If you skip this step, you can always run it yourself later"
|
|
67
|
+
)}
|
|
68
|
+
${message}`
|
|
69
|
+
);
|
|
70
|
+
let response;
|
|
71
|
+
if (options.skipAsk) {
|
|
72
|
+
response = true;
|
|
73
|
+
} else {
|
|
74
|
+
response = (await prompts({
|
|
75
|
+
type: "confirm",
|
|
76
|
+
name: "askToContinue",
|
|
77
|
+
message: "Continue?",
|
|
78
|
+
initial: true
|
|
79
|
+
})).askToContinue;
|
|
80
|
+
}
|
|
81
|
+
if (Boolean(response)) {
|
|
82
|
+
const spinner = ora("Installing dependencies...").start();
|
|
83
|
+
try {
|
|
84
|
+
await execa(
|
|
85
|
+
installCommand.pm,
|
|
86
|
+
[installCommand.command, ...installCommand.flags, ...installCommand.dependencies],
|
|
87
|
+
{ cwd }
|
|
88
|
+
);
|
|
89
|
+
spinner.succeed();
|
|
90
|
+
return true;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
debug("add", "Error installing dependencies", err);
|
|
93
|
+
spinner.fail();
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
getPackage
|
|
102
|
+
};
|
|
@@ -3,7 +3,7 @@ import { printHelp } from "../../core/messages.js";
|
|
|
3
3
|
import previewServer from "../../core/preview/index.js";
|
|
4
4
|
import { flagsToAstroInlineConfig } from "../flags.js";
|
|
5
5
|
async function preview({ flags }) {
|
|
6
|
-
if (
|
|
6
|
+
if (flags?.help || flags?.h) {
|
|
7
7
|
printHelp({
|
|
8
8
|
commandName: "astro preview",
|
|
9
9
|
usage: "[...flags]",
|
package/dist/cli/sync/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { printHelp } from "../../core/messages.js";
|
|
|
2
2
|
import { sync as _sync } from "../../core/sync/index.js";
|
|
3
3
|
import { flagsToAstroInlineConfig } from "../flags.js";
|
|
4
4
|
async function sync({ flags }) {
|
|
5
|
-
if (
|
|
5
|
+
if (flags?.help || flags?.h) {
|
|
6
6
|
printHelp({
|
|
7
7
|
commandName: "astro sync",
|
|
8
8
|
usage: "[...flags]",
|
|
@@ -3,8 +3,7 @@ import { emitESMImage } from "../assets/utils/emitAsset.js";
|
|
|
3
3
|
function createImage(pluginContext, entryFilePath) {
|
|
4
4
|
return () => {
|
|
5
5
|
return z.string().transform(async (imagePath, ctx) => {
|
|
6
|
-
|
|
7
|
-
const resolvedFilePath = (_a = await pluginContext.resolve(imagePath, entryFilePath)) == null ? void 0 : _a.id;
|
|
6
|
+
const resolvedFilePath = (await pluginContext.resolve(imagePath, entryFilePath))?.id;
|
|
8
7
|
const metadata = await emitESMImage(
|
|
9
8
|
resolvedFilePath,
|
|
10
9
|
pluginContext.meta.watchMode,
|
package/dist/content/runtime.js
CHANGED
|
@@ -112,8 +112,7 @@ function createGetDataEntryById({
|
|
|
112
112
|
dataCollectionToEntryMap
|
|
113
113
|
}) {
|
|
114
114
|
return async function getDataEntryById(collection, id) {
|
|
115
|
-
|
|
116
|
-
const lazyImport = (_a = dataCollectionToEntryMap[collection]) == null ? void 0 : _a[
|
|
115
|
+
const lazyImport = dataCollectionToEntryMap[collection]?.[
|
|
117
116
|
/*TODO: filePathToIdMap*/
|
|
118
117
|
id + ".json"
|
|
119
118
|
];
|
|
@@ -184,7 +183,6 @@ async function render({
|
|
|
184
183
|
id,
|
|
185
184
|
renderEntryImport
|
|
186
185
|
}) {
|
|
187
|
-
var _a, _b;
|
|
188
186
|
const UnexpectedRenderError = new AstroError({
|
|
189
187
|
...AstroErrorData.UnknownContentCollectionError,
|
|
190
188
|
message: `Unexpected error while rendering ${String(collection)} \u2192 ${String(id)}.`
|
|
@@ -246,13 +244,13 @@ async function render({
|
|
|
246
244
|
});
|
|
247
245
|
return {
|
|
248
246
|
Content,
|
|
249
|
-
headings:
|
|
247
|
+
headings: propagationMod.getHeadings?.() ?? [],
|
|
250
248
|
remarkPluginFrontmatter: propagationMod.frontmatter ?? {}
|
|
251
249
|
};
|
|
252
250
|
} else if (baseMod.Content && typeof baseMod.Content === "function") {
|
|
253
251
|
return {
|
|
254
252
|
Content: baseMod.Content,
|
|
255
|
-
headings:
|
|
253
|
+
headings: baseMod.getHeadings?.() ?? [],
|
|
256
254
|
remarkPluginFrontmatter: baseMod.frontmatter ?? {}
|
|
257
255
|
};
|
|
258
256
|
} else {
|
|
@@ -87,7 +87,6 @@ function getTSConfigStatsWhenAllowJsFalse({
|
|
|
87
87
|
contentPaths,
|
|
88
88
|
settings
|
|
89
89
|
}) {
|
|
90
|
-
var _a, _b;
|
|
91
90
|
const isContentConfigJsFile = [".js", ".mjs"].some(
|
|
92
91
|
(ext) => contentPaths.config.url.pathname.endsWith(ext)
|
|
93
92
|
);
|
|
@@ -98,7 +97,7 @@ function getTSConfigStatsWhenAllowJsFalse({
|
|
|
98
97
|
if (!tsConfigFileName)
|
|
99
98
|
return;
|
|
100
99
|
const contentConfigFileName = contentPaths.config.url.pathname.split(path.sep).pop();
|
|
101
|
-
const allowJSOption =
|
|
100
|
+
const allowJSOption = inputConfig?.config?.compilerOptions?.allowJs;
|
|
102
101
|
const hasAllowJs = allowJSOption === true || tsConfigFileName === "jsconfig.json" && allowJSOption !== false;
|
|
103
102
|
if (hasAllowJs)
|
|
104
103
|
return;
|