astro 1.1.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/astro.d.ts +2 -0
- package/dist/cli/index.js +56 -23
- package/dist/core/add/index.js +65 -64
- package/dist/core/build/generate.js +3 -1
- package/dist/core/build/vite-plugin-analyzer.js +7 -1
- package/dist/core/config.d.ts +6 -2
- package/dist/core/config.js +58 -37
- package/dist/core/dev/index.d.ts +1 -0
- package/dist/core/dev/index.js +4 -2
- package/dist/core/endpoint/dev/index.d.ts +2 -0
- package/dist/core/endpoint/index.d.ts +2 -0
- package/dist/core/endpoint/index.js +2 -1
- package/dist/core/messages.d.ts +2 -1
- package/dist/core/messages.js +5 -4
- package/dist/core/util.js +1 -1
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/vite-plugin-astro/hmr.js +2 -0
- package/package.json +2 -2
package/dist/@types/astro.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
|
|
3
4
|
import type * as babel from '@babel/core';
|
|
4
5
|
import type { AddressInfo } from 'net';
|
|
@@ -974,6 +975,7 @@ export interface APIContext {
|
|
|
974
975
|
}
|
|
975
976
|
export interface EndpointOutput {
|
|
976
977
|
body: Body;
|
|
978
|
+
encoding?: BufferEncoding;
|
|
977
979
|
}
|
|
978
980
|
export declare type APIRoute = (context: APIContext) => EndpointOutput | Response | Promise<EndpointOutput | Response>;
|
|
979
981
|
export interface EndpointHandler {
|
package/dist/cli/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import * as colors from "kleur/colors";
|
|
2
|
+
import { pathToFileURL } from "url";
|
|
3
|
+
import { normalizePath } from "vite";
|
|
2
4
|
import yargs from "yargs-parser";
|
|
3
5
|
import { z } from "zod";
|
|
4
6
|
import add from "../core/add/index.js";
|
|
5
7
|
import build from "../core/build/index.js";
|
|
6
|
-
import { openConfig } from "../core/config.js";
|
|
8
|
+
import { openConfig, resolveConfigPath, resolveFlags, resolveRoot } from "../core/config.js";
|
|
7
9
|
import devServer from "../core/dev/index.js";
|
|
8
10
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
9
|
-
import { debug,
|
|
11
|
+
import { debug, error, info } from "../core/logger/core.js";
|
|
10
12
|
import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
|
|
11
13
|
import { formatConfigErrorMessage, formatErrorMessage, printHelp } from "../core/messages.js";
|
|
14
|
+
import { appendForwardSlash } from "../core/path.js";
|
|
12
15
|
import preview from "../core/preview/index.js";
|
|
13
16
|
import { ASTRO_VERSION, createSafeError } from "../core/util.js";
|
|
14
17
|
import * as event from "../events/index.js";
|
|
@@ -62,6 +65,18 @@ function resolveCommand(flags) {
|
|
|
62
65
|
}
|
|
63
66
|
return "help";
|
|
64
67
|
}
|
|
68
|
+
async function handleConfigError(e, { cwd, flags, logging }) {
|
|
69
|
+
const path = await resolveConfigPath({ cwd, flags });
|
|
70
|
+
if (e instanceof Error) {
|
|
71
|
+
if (path) {
|
|
72
|
+
error(logging, "astro", `Unable to load ${colors.bold(path)}
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
console.error(
|
|
76
|
+
formatErrorMessage(collectErrorMetadata(e, path ? pathToFileURL(path) : void 0)) + "\n"
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
65
80
|
async function runCommand(cmd, flags) {
|
|
66
81
|
var _a;
|
|
67
82
|
const root = flags.root;
|
|
@@ -98,39 +113,57 @@ async function runCommand(cmd, flags) {
|
|
|
98
113
|
return await telemetryHandler.update(subcommand, { flags, telemetry });
|
|
99
114
|
}
|
|
100
115
|
}
|
|
101
|
-
let { astroConfig, userConfig
|
|
116
|
+
let { astroConfig, userConfig } = await openConfig({
|
|
102
117
|
cwd: root,
|
|
103
118
|
flags,
|
|
104
119
|
cmd,
|
|
105
120
|
logging
|
|
121
|
+
}).catch(async (e) => {
|
|
122
|
+
await handleConfigError(e, { cwd: root, flags, logging });
|
|
123
|
+
return {};
|
|
106
124
|
});
|
|
125
|
+
if (!astroConfig)
|
|
126
|
+
return;
|
|
107
127
|
telemetry.record(event.eventCliSession(cmd, userConfig, flags));
|
|
108
128
|
switch (cmd) {
|
|
109
129
|
case "dev": {
|
|
110
|
-
async function startDevServer() {
|
|
111
|
-
const { watcher, stop } = await devServer(astroConfig, { logging, telemetry });
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
async function startDevServer({ isRestart = false } = {}) {
|
|
131
|
+
const { watcher, stop } = await devServer(astroConfig, { logging, telemetry, isRestart });
|
|
132
|
+
let restartInFlight = false;
|
|
133
|
+
const configFlag = resolveFlags(flags).config;
|
|
134
|
+
const configFlagPath = configFlag ? await resolveConfigPath({ cwd: root, flags }) : void 0;
|
|
135
|
+
const resolvedRoot = appendForwardSlash(resolveRoot(root));
|
|
136
|
+
const handleServerRestart = (logMsg) => async function(changedFile) {
|
|
137
|
+
if (!restartInFlight && (configFlag ? configFlagPath && normalizePath(configFlagPath) === normalizePath(changedFile) : new RegExp(
|
|
138
|
+
`${normalizePath(resolvedRoot)}.*astro.config.((mjs)|(cjs)|(js)|(ts))$`
|
|
139
|
+
).test(normalizePath(changedFile)))) {
|
|
140
|
+
restartInFlight = true;
|
|
141
|
+
console.clear();
|
|
142
|
+
try {
|
|
143
|
+
const newConfig = await openConfig({
|
|
144
|
+
cwd: root,
|
|
145
|
+
flags,
|
|
146
|
+
cmd,
|
|
147
|
+
logging,
|
|
148
|
+
isConfigReload: true
|
|
149
|
+
});
|
|
150
|
+
info(logging, "astro", logMsg + "\n");
|
|
151
|
+
astroConfig = newConfig.astroConfig;
|
|
152
|
+
await stop();
|
|
153
|
+
await startDevServer({ isRestart: true });
|
|
154
|
+
} catch (e) {
|
|
155
|
+
await handleConfigError(e, { cwd: root, flags, logging });
|
|
127
156
|
await stop();
|
|
128
|
-
|
|
157
|
+
info(logging, "astro", "Continuing with previous valid configuration\n");
|
|
158
|
+
await startDevServer({ isRestart: true });
|
|
129
159
|
}
|
|
130
160
|
}
|
|
131
|
-
}
|
|
161
|
+
};
|
|
162
|
+
watcher.on("change", handleServerRestart("Configuration updated. Restarting..."));
|
|
163
|
+
watcher.on("unlink", handleServerRestart("Configuration removed. Restarting..."));
|
|
164
|
+
watcher.on("add", handleServerRestart("Configuration added. Restarting..."));
|
|
132
165
|
}
|
|
133
|
-
await startDevServer();
|
|
166
|
+
await startDevServer({ isRestart: false });
|
|
134
167
|
return await new Promise(() => {
|
|
135
168
|
});
|
|
136
169
|
}
|
package/dist/core/add/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from "path";
|
|
|
8
8
|
import preferredPM from "preferred-pm";
|
|
9
9
|
import prompts from "prompts";
|
|
10
10
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
11
|
-
import {
|
|
11
|
+
import { resolveConfigPath } from "../config.js";
|
|
12
12
|
import { debug, info } from "../logger/core.js";
|
|
13
13
|
import * as msg from "../messages.js";
|
|
14
14
|
import { printHelp } from "../messages.js";
|
|
@@ -80,15 +80,73 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
80
80
|
});
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
const integrationNames = names.map((name) => ALIASES.has(name) ? ALIASES.get(name) : name);
|
|
84
|
+
const integrations = await validateIntegrations(integrationNames);
|
|
85
|
+
let installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logging });
|
|
84
86
|
const root = pathToFileURL(cwd ? path.resolve(cwd) : process.cwd());
|
|
85
|
-
|
|
87
|
+
root.href = appendForwardSlash(root.href);
|
|
88
|
+
switch (installResult) {
|
|
89
|
+
case UpdateResult.updated: {
|
|
90
|
+
if (integrations.find((integration) => integration.id === "tailwind")) {
|
|
91
|
+
const possibleConfigFiles = [
|
|
92
|
+
"./tailwind.config.cjs",
|
|
93
|
+
"./tailwind.config.mjs",
|
|
94
|
+
"./tailwind.config.js"
|
|
95
|
+
].map((p) => fileURLToPath(new URL(p, root)));
|
|
96
|
+
let alreadyConfigured = false;
|
|
97
|
+
for (const possibleConfigPath of possibleConfigFiles) {
|
|
98
|
+
if (existsSync(possibleConfigPath)) {
|
|
99
|
+
alreadyConfigured = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!alreadyConfigured) {
|
|
104
|
+
info(
|
|
105
|
+
logging,
|
|
106
|
+
null,
|
|
107
|
+
`
|
|
108
|
+
${magenta(
|
|
109
|
+
`Astro will generate a minimal ${bold("./tailwind.config.cjs")} file.`
|
|
110
|
+
)}
|
|
111
|
+
`
|
|
112
|
+
);
|
|
113
|
+
if (await askToContinue({ flags })) {
|
|
114
|
+
await fs.writeFile(
|
|
115
|
+
fileURLToPath(new URL("./tailwind.config.cjs", root)),
|
|
116
|
+
TAILWIND_CONFIG_STUB,
|
|
117
|
+
{ encoding: "utf-8" }
|
|
118
|
+
);
|
|
119
|
+
debug("add", `Generated default ./tailwind.config.cjs file`);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
debug("add", `Using existing Tailwind configuration`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case UpdateResult.cancelled: {
|
|
128
|
+
info(
|
|
129
|
+
logging,
|
|
130
|
+
null,
|
|
131
|
+
msg.cancelled(
|
|
132
|
+
`Dependencies ${bold("NOT")} installed.`,
|
|
133
|
+
`Be sure to install them manually before continuing!`
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case UpdateResult.failure: {
|
|
139
|
+
throw createPrettyError(new Error(`Unable to install dependencies`));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const rawConfigPath = await resolveConfigPath({ cwd, flags });
|
|
143
|
+
let configURL = rawConfigPath ? pathToFileURL(rawConfigPath) : void 0;
|
|
86
144
|
applyPolyfill();
|
|
87
145
|
if (configURL) {
|
|
88
146
|
debug("add", `Found config at ${configURL}`);
|
|
89
147
|
} else {
|
|
90
148
|
info(logging, "add", `Unable to locate a config file, generating one for you.`);
|
|
91
|
-
configURL = new URL("./astro.config.mjs",
|
|
149
|
+
configURL = new URL("./astro.config.mjs", root);
|
|
92
150
|
await fs.writeFile(fileURLToPath(configURL), ASTRO_CONFIG_STUB, { encoding: "utf-8" });
|
|
93
151
|
}
|
|
94
152
|
if (configURL == null ? void 0 : configURL.pathname.endsWith("package.json")) {
|
|
@@ -96,8 +154,6 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
96
154
|
`Unable to use "astro add" with package.json configuration. Try migrating to \`astro.config.mjs\` and try again.`
|
|
97
155
|
);
|
|
98
156
|
}
|
|
99
|
-
const integrationNames = names.map((name) => ALIASES.has(name) ? ALIASES.get(name) : name);
|
|
100
|
-
const integrations = await validateIntegrations(integrationNames);
|
|
101
157
|
let ast = null;
|
|
102
158
|
try {
|
|
103
159
|
ast = await parseAstroConfig(configURL);
|
|
@@ -139,7 +195,6 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
139
195
|
throw createPrettyError(err);
|
|
140
196
|
}
|
|
141
197
|
let configResult;
|
|
142
|
-
let installResult;
|
|
143
198
|
if (ast) {
|
|
144
199
|
try {
|
|
145
200
|
configResult = await updateAstroConfig({
|
|
@@ -173,72 +228,18 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
173
228
|
}
|
|
174
229
|
}
|
|
175
230
|
info(logging, null, msg.success(`Configuration up-to-date.`));
|
|
176
|
-
|
|
231
|
+
return;
|
|
177
232
|
}
|
|
178
|
-
|
|
179
|
-
installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logging });
|
|
180
|
-
switch (installResult) {
|
|
181
|
-
case UpdateResult.updated: {
|
|
182
|
-
const len = integrations.length;
|
|
183
|
-
if (integrations.find((integration) => integration.id === "tailwind")) {
|
|
184
|
-
const possibleConfigFiles = [
|
|
185
|
-
"./tailwind.config.cjs",
|
|
186
|
-
"./tailwind.config.mjs",
|
|
187
|
-
"./tailwind.config.js"
|
|
188
|
-
].map((p) => fileURLToPath(new URL(p, configURL)));
|
|
189
|
-
let alreadyConfigured = false;
|
|
190
|
-
for (const possibleConfigPath of possibleConfigFiles) {
|
|
191
|
-
if (existsSync(possibleConfigPath)) {
|
|
192
|
-
alreadyConfigured = true;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (!alreadyConfigured) {
|
|
197
|
-
info(
|
|
198
|
-
logging,
|
|
199
|
-
null,
|
|
200
|
-
`
|
|
201
|
-
${magenta(
|
|
202
|
-
`Astro will generate a minimal ${bold("./tailwind.config.cjs")} file.`
|
|
203
|
-
)}
|
|
204
|
-
`
|
|
205
|
-
);
|
|
206
|
-
if (await askToContinue({ flags })) {
|
|
207
|
-
await fs.writeFile(
|
|
208
|
-
fileURLToPath(new URL("./tailwind.config.cjs", configURL)),
|
|
209
|
-
TAILWIND_CONFIG_STUB,
|
|
210
|
-
{ encoding: "utf-8" }
|
|
211
|
-
);
|
|
212
|
-
debug("add", `Generated default ./tailwind.config.cjs file`);
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
debug("add", `Using existing Tailwind configuration`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
233
|
+
default: {
|
|
218
234
|
const list = integrations.map((integration) => ` - ${integration.packageName}`).join("\n");
|
|
219
235
|
info(
|
|
220
236
|
logging,
|
|
221
237
|
null,
|
|
222
238
|
msg.success(
|
|
223
|
-
`Added the following integration${
|
|
239
|
+
`Added the following integration${integrations.length === 1 ? "" : "s"} to your project:
|
|
224
240
|
${list}`
|
|
225
241
|
)
|
|
226
242
|
);
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
case UpdateResult.cancelled: {
|
|
230
|
-
info(
|
|
231
|
-
logging,
|
|
232
|
-
null,
|
|
233
|
-
msg.cancelled(
|
|
234
|
-
`Dependencies ${bold("NOT")} installed.`,
|
|
235
|
-
`Be sure to install them manually before continuing!`
|
|
236
|
-
)
|
|
237
|
-
);
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
case UpdateResult.failure: {
|
|
241
|
-
throw createPrettyError(new Error(`Unable to install dependencies`));
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
245
|
}
|
|
@@ -260,12 +260,14 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
260
260
|
streaming: true
|
|
261
261
|
};
|
|
262
262
|
let body;
|
|
263
|
+
let encoding;
|
|
263
264
|
if (pageData.route.type === "endpoint") {
|
|
264
265
|
const result = await callEndpoint(mod, options);
|
|
265
266
|
if (result.type === "response") {
|
|
266
267
|
throw new Error(`Returning a Response from an endpoint is not supported in SSG mode.`);
|
|
267
268
|
}
|
|
268
269
|
body = result.body;
|
|
270
|
+
encoding = result.encoding;
|
|
269
271
|
} else {
|
|
270
272
|
const response = await render(options);
|
|
271
273
|
if (response.status !== 200 || !response.body) {
|
|
@@ -277,7 +279,7 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
277
279
|
const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
|
|
278
280
|
pageData.route.distURL = outFile;
|
|
279
281
|
await fs.promises.mkdir(outFolder, { recursive: true });
|
|
280
|
-
await fs.promises.writeFile(outFile, body, "utf-8");
|
|
282
|
+
await fs.promises.writeFile(outFile, body, encoding ?? "utf-8");
|
|
281
283
|
}
|
|
282
284
|
export {
|
|
283
285
|
chunkIsPage,
|
|
@@ -55,7 +55,7 @@ function vitePluginAnalyzer(internals) {
|
|
|
55
55
|
}
|
|
56
56
|
return {
|
|
57
57
|
name: "@astro/rollup-plugin-astro-analyzer",
|
|
58
|
-
generateBundle() {
|
|
58
|
+
async generateBundle() {
|
|
59
59
|
var _a;
|
|
60
60
|
const hoistScanner = hoistedScriptScanner();
|
|
61
61
|
const ids = this.getModuleIds();
|
|
@@ -75,6 +75,12 @@ function vitePluginAnalyzer(internals) {
|
|
|
75
75
|
const cid = c.resolvedPath ? decodeURI(c.resolvedPath) : c.specifier;
|
|
76
76
|
internals.discoveredClientOnlyComponents.add(cid);
|
|
77
77
|
clientOnlys.push(cid);
|
|
78
|
+
if (c.resolvedPath === c.specifier) {
|
|
79
|
+
const resolvedId = await this.resolve(c.specifier, id);
|
|
80
|
+
if (resolvedId) {
|
|
81
|
+
clientOnlys.push(resolvedId.id);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
78
84
|
}
|
|
79
85
|
for (const [pageInfo] of getTopLevelPages(id, this)) {
|
|
80
86
|
const pageData = getPageDataByViteID(internals, pageInfo.id);
|
package/dist/core/config.d.ts
CHANGED
|
@@ -235,22 +235,26 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
235
235
|
}>;
|
|
236
236
|
/** Turn raw config values into normalized values */
|
|
237
237
|
export declare function validateConfig(userConfig: any, root: string, cmd: string, logging: LogOptions): Promise<AstroConfig>;
|
|
238
|
+
/** Convert the generic "yargs" flag object into our own, custom TypeScript object. */
|
|
239
|
+
export declare function resolveFlags(flags: Partial<Flags>): CLIFlags;
|
|
240
|
+
export declare function resolveRoot(cwd?: string): string;
|
|
238
241
|
interface LoadConfigOptions {
|
|
239
242
|
cwd?: string;
|
|
240
243
|
flags?: Flags;
|
|
241
244
|
cmd: string;
|
|
242
245
|
validate?: boolean;
|
|
243
246
|
logging: LogOptions;
|
|
247
|
+
/** Invalidate when reloading a previously loaded config */
|
|
248
|
+
isConfigReload?: boolean;
|
|
244
249
|
}
|
|
245
250
|
/**
|
|
246
251
|
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
|
247
252
|
* Note: currently the same as loadConfig but only returns the `filePath`
|
|
248
253
|
* instead of the resolved config
|
|
249
254
|
*/
|
|
250
|
-
export declare function
|
|
255
|
+
export declare function resolveConfigPath(configOptions: Pick<LoadConfigOptions, 'cwd' | 'flags'>): Promise<string | undefined>;
|
|
251
256
|
interface OpenConfigResult {
|
|
252
257
|
userConfig: AstroUserConfig;
|
|
253
|
-
userConfigPath: string | undefined;
|
|
254
258
|
astroConfig: AstroConfig;
|
|
255
259
|
flags: CLIFlags;
|
|
256
260
|
root: string;
|
package/dist/core/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from "fs";
|
|
1
2
|
import load, { ProloadError, resolve } from "@proload/core";
|
|
2
3
|
import loadTypeScript from "@proload/plugin-tsm";
|
|
3
4
|
import * as colors from "kleur/colors";
|
|
@@ -224,6 +225,9 @@ function resolveFlags(flags) {
|
|
|
224
225
|
drafts: typeof flags.drafts === "boolean" ? flags.drafts : void 0
|
|
225
226
|
};
|
|
226
227
|
}
|
|
228
|
+
function resolveRoot(cwd) {
|
|
229
|
+
return cwd ? path.resolve(cwd) : process.cwd();
|
|
230
|
+
}
|
|
227
231
|
function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
228
232
|
astroConfig.server = astroConfig.server || {};
|
|
229
233
|
astroConfig.markdown = astroConfig.markdown || {};
|
|
@@ -239,38 +243,35 @@ function mergeCLIFlags(astroConfig, flags, cmd) {
|
|
|
239
243
|
}
|
|
240
244
|
return astroConfig;
|
|
241
245
|
}
|
|
242
|
-
async function
|
|
243
|
-
const root =
|
|
246
|
+
async function resolveConfigPath(configOptions) {
|
|
247
|
+
const root = resolveRoot(configOptions.cwd);
|
|
244
248
|
const flags = resolveFlags(configOptions.flags || {});
|
|
245
249
|
let userConfigPath;
|
|
246
250
|
if (flags == null ? void 0 : flags.config) {
|
|
247
251
|
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
|
248
252
|
userConfigPath = fileURLToPath(new URL(userConfigPath, `file://${root}/`));
|
|
249
253
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return
|
|
254
|
+
try {
|
|
255
|
+
const configPath = await resolve("astro", {
|
|
256
|
+
mustExist: !!userConfigPath,
|
|
257
|
+
cwd: root,
|
|
258
|
+
filePath: userConfigPath
|
|
259
|
+
});
|
|
260
|
+
return configPath;
|
|
261
|
+
} catch (e) {
|
|
262
|
+
if (e instanceof ProloadError && flags.config) {
|
|
263
|
+
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
|
|
264
|
+
}
|
|
265
|
+
throw e;
|
|
257
266
|
}
|
|
258
267
|
}
|
|
259
268
|
async function openConfig(configOptions) {
|
|
260
|
-
const root =
|
|
269
|
+
const root = resolveRoot(configOptions.cwd);
|
|
261
270
|
const flags = resolveFlags(configOptions.flags || {});
|
|
262
271
|
let userConfig = {};
|
|
263
|
-
|
|
264
|
-
if (flags == null ? void 0 : flags.config) {
|
|
265
|
-
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
|
266
|
-
userConfigPath = fileURLToPath(
|
|
267
|
-
new URL(userConfigPath, appendForwardSlash(pathToFileURL(root).toString()))
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
const config = await tryLoadConfig(configOptions, flags, userConfigPath, root);
|
|
272
|
+
const config = await tryLoadConfig(configOptions, flags, root);
|
|
271
273
|
if (config) {
|
|
272
274
|
userConfig = config.value;
|
|
273
|
-
userConfigPath = config.filePath;
|
|
274
275
|
}
|
|
275
276
|
const astroConfig = await resolveConfig(
|
|
276
277
|
userConfig,
|
|
@@ -282,56 +283,74 @@ async function openConfig(configOptions) {
|
|
|
282
283
|
return {
|
|
283
284
|
astroConfig,
|
|
284
285
|
userConfig,
|
|
285
|
-
userConfigPath,
|
|
286
286
|
flags,
|
|
287
287
|
root
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
|
-
async function tryLoadConfig(configOptions, flags,
|
|
290
|
+
async function tryLoadConfig(configOptions, flags, root) {
|
|
291
|
+
let finallyCleanup = async () => {
|
|
292
|
+
};
|
|
291
293
|
try {
|
|
294
|
+
let configPath = await resolveConfigPath({
|
|
295
|
+
cwd: configOptions.cwd,
|
|
296
|
+
flags: configOptions.flags
|
|
297
|
+
});
|
|
298
|
+
if (!configPath)
|
|
299
|
+
return void 0;
|
|
300
|
+
if (configOptions.isConfigReload) {
|
|
301
|
+
const tempConfigPath = path.join(
|
|
302
|
+
root,
|
|
303
|
+
`.temp.${Date.now()}.config${path.extname(configPath)}`
|
|
304
|
+
);
|
|
305
|
+
await fs.promises.writeFile(tempConfigPath, await fs.promises.readFile(configPath));
|
|
306
|
+
finallyCleanup = async () => {
|
|
307
|
+
try {
|
|
308
|
+
await fs.promises.unlink(tempConfigPath);
|
|
309
|
+
} catch {
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
configPath = tempConfigPath;
|
|
313
|
+
}
|
|
292
314
|
const config = await load("astro", {
|
|
293
|
-
mustExist: !!
|
|
315
|
+
mustExist: !!configPath,
|
|
294
316
|
cwd: root,
|
|
295
|
-
filePath:
|
|
317
|
+
filePath: configPath
|
|
296
318
|
});
|
|
297
319
|
return config;
|
|
298
320
|
} catch (e) {
|
|
299
321
|
if (e instanceof ProloadError && flags.config) {
|
|
300
322
|
throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
|
|
301
323
|
}
|
|
302
|
-
const
|
|
303
|
-
if (!
|
|
324
|
+
const configPath = await resolveConfigPath(configOptions);
|
|
325
|
+
if (!configPath) {
|
|
304
326
|
throw e;
|
|
305
327
|
}
|
|
306
328
|
const viteServer = await vite.createServer({
|
|
307
329
|
server: { middlewareMode: true, hmr: false },
|
|
330
|
+
optimizeDeps: { entries: [] },
|
|
331
|
+
clearScreen: false,
|
|
308
332
|
appType: "custom"
|
|
309
333
|
});
|
|
310
334
|
try {
|
|
311
|
-
const mod = await viteServer.ssrLoadModule(
|
|
335
|
+
const mod = await viteServer.ssrLoadModule(configPath);
|
|
312
336
|
if (mod == null ? void 0 : mod.default) {
|
|
313
337
|
return {
|
|
314
338
|
value: mod.default,
|
|
315
|
-
filePath:
|
|
339
|
+
filePath: configPath
|
|
316
340
|
};
|
|
317
341
|
}
|
|
318
342
|
} finally {
|
|
319
343
|
await viteServer.close();
|
|
320
344
|
}
|
|
345
|
+
} finally {
|
|
346
|
+
await finallyCleanup();
|
|
321
347
|
}
|
|
322
348
|
}
|
|
323
349
|
async function loadConfig(configOptions) {
|
|
324
|
-
const root =
|
|
350
|
+
const root = resolveRoot(configOptions.cwd);
|
|
325
351
|
const flags = resolveFlags(configOptions.flags || {});
|
|
326
352
|
let userConfig = {};
|
|
327
|
-
|
|
328
|
-
if (flags == null ? void 0 : flags.config) {
|
|
329
|
-
userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
|
|
330
|
-
userConfigPath = fileURLToPath(
|
|
331
|
-
new URL(userConfigPath, appendForwardSlash(pathToFileURL(root).toString()))
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
const config = await tryLoadConfig(configOptions, flags, userConfigPath, root);
|
|
353
|
+
const config = await tryLoadConfig(configOptions, flags, root);
|
|
335
354
|
if (config) {
|
|
336
355
|
userConfig = config.value;
|
|
337
356
|
}
|
|
@@ -380,6 +399,8 @@ export {
|
|
|
380
399
|
mergeConfig,
|
|
381
400
|
openConfig,
|
|
382
401
|
resolveConfig,
|
|
383
|
-
|
|
402
|
+
resolveConfigPath,
|
|
403
|
+
resolveFlags,
|
|
404
|
+
resolveRoot,
|
|
384
405
|
validateConfig
|
|
385
406
|
};
|
package/dist/core/dev/index.d.ts
CHANGED
package/dist/core/dev/index.js
CHANGED
|
@@ -18,6 +18,7 @@ async function dev(config, options) {
|
|
|
18
18
|
await options.telemetry.record([]);
|
|
19
19
|
config = await runHookConfigSetup({ config, command: "dev", logging: options.logging });
|
|
20
20
|
const { host, port } = config.server;
|
|
21
|
+
const { isRestart = false } = options;
|
|
21
22
|
const rendererClientEntries = config._ctx.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
|
|
22
23
|
const viteConfig = await createVite(
|
|
23
24
|
{
|
|
@@ -43,10 +44,11 @@ async function dev(config, options) {
|
|
|
43
44
|
config,
|
|
44
45
|
devServerAddressInfo,
|
|
45
46
|
site,
|
|
46
|
-
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
|
|
47
|
+
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https),
|
|
48
|
+
isRestart
|
|
47
49
|
})
|
|
48
50
|
);
|
|
49
|
-
const currentVersion = "1.
|
|
51
|
+
const currentVersion = "1.2.0";
|
|
50
52
|
if (currentVersion.includes("-")) {
|
|
51
53
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
52
54
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { SSROptions } from '../../render/dev';
|
|
2
3
|
export declare function call(ssrOpts: SSROptions): Promise<{
|
|
3
4
|
type: "simple";
|
|
4
5
|
body: string;
|
|
6
|
+
encoding?: BufferEncoding | undefined;
|
|
5
7
|
} | {
|
|
6
8
|
type: "response";
|
|
7
9
|
response: Response;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { EndpointHandler } from '../../@types/astro';
|
|
2
3
|
import type { RenderOptions } from '../render/core';
|
|
3
4
|
export declare type EndpointOptions = Pick<RenderOptions, 'logging' | 'origin' | 'request' | 'route' | 'routeCache' | 'pathname' | 'route' | 'site' | 'ssr' | 'status'>;
|
|
4
5
|
declare type EndpointCallResult = {
|
|
5
6
|
type: 'simple';
|
|
6
7
|
body: string;
|
|
8
|
+
encoding?: BufferEncoding;
|
|
7
9
|
} | {
|
|
8
10
|
type: 'response';
|
|
9
11
|
response: Response;
|
package/dist/core/messages.d.ts
CHANGED
|
@@ -17,12 +17,13 @@ export declare function hmr({ file, style }: {
|
|
|
17
17
|
style?: boolean;
|
|
18
18
|
}): string;
|
|
19
19
|
/** Display dev server host and startup time */
|
|
20
|
-
export declare function devStart({ startupTime, devServerAddressInfo, config, https, site, }: {
|
|
20
|
+
export declare function devStart({ startupTime, devServerAddressInfo, config, https, site, isRestart, }: {
|
|
21
21
|
startupTime: number;
|
|
22
22
|
devServerAddressInfo: AddressInfo;
|
|
23
23
|
config: AstroConfig;
|
|
24
24
|
https: boolean;
|
|
25
25
|
site: URL | undefined;
|
|
26
|
+
isRestart?: boolean;
|
|
26
27
|
}): string;
|
|
27
28
|
export declare function telemetryNotice(): string;
|
|
28
29
|
export declare function telemetryEnabled(): string;
|
package/dist/core/messages.js
CHANGED
|
@@ -44,9 +44,10 @@ function devStart({
|
|
|
44
44
|
devServerAddressInfo,
|
|
45
45
|
config,
|
|
46
46
|
https,
|
|
47
|
-
site
|
|
47
|
+
site,
|
|
48
|
+
isRestart = false
|
|
48
49
|
}) {
|
|
49
|
-
const version = "1.
|
|
50
|
+
const version = "1.2.0";
|
|
50
51
|
const rootPath = site ? site.pathname : "/";
|
|
51
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -77,7 +78,7 @@ function devStart({
|
|
|
77
78
|
}
|
|
78
79
|
const messages = [
|
|
79
80
|
`${emoji("\u{1F680} ", "")}${bgGreen(black(` astro `))} ${green(`v${version}`)} ${dim(
|
|
80
|
-
|
|
81
|
+
`${isRestart ? "re" : ""}started in ${Math.round(startupTime)}ms`
|
|
81
82
|
)}`,
|
|
82
83
|
"",
|
|
83
84
|
local,
|
|
@@ -225,7 +226,7 @@ function printHelp({
|
|
|
225
226
|
message.push(
|
|
226
227
|
linebreak(),
|
|
227
228
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
228
|
-
`v${"1.
|
|
229
|
+
`v${"1.2.0"}`
|
|
229
230
|
)} ${headline}`
|
|
230
231
|
);
|
|
231
232
|
}
|
package/dist/core/util.js
CHANGED
|
@@ -5,7 +5,7 @@ import resolve from "resolve";
|
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
8
|
-
const ASTRO_VERSION = "1.
|
|
8
|
+
const ASTRO_VERSION = "1.2.0";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
|
@@ -83,6 +83,8 @@ async function handleHotUpdate(ctx, { config, logging, compile }) {
|
|
|
83
83
|
}
|
|
84
84
|
const isSelfAccepting = mods.every((m) => m.isSelfAccepting || m.url.endsWith(".svelte"));
|
|
85
85
|
if (isSelfAccepting) {
|
|
86
|
+
if (/astro\.config\.[cm][jt]s$/.test(file))
|
|
87
|
+
return mods;
|
|
86
88
|
info(logging, "astro", msg.hmr({ file }));
|
|
87
89
|
} else {
|
|
88
90
|
info(logging, "astro", msg.reload({ file }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@babel/plugin-transform-react-jsx": "^7.17.12",
|
|
94
94
|
"@babel/traverse": "^7.18.2",
|
|
95
95
|
"@babel/types": "^7.18.4",
|
|
96
|
-
"@proload/core": "^0.3.
|
|
96
|
+
"@proload/core": "^0.3.3",
|
|
97
97
|
"@proload/plugin-tsm": "^0.2.1",
|
|
98
98
|
"@types/babel__core": "^7.1.19",
|
|
99
99
|
"@types/html-escaper": "^3.0.0",
|