astro 1.0.0-beta.2 → 1.0.0-beta.22
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/LICENSE +61 -0
- package/astro-jsx.d.ts +4 -1
- package/components/Code.astro +1 -1
- package/components/Shiki.js +24 -0
- package/dist/cli/index.js +47 -13
- package/dist/cli/open.js +26 -0
- package/dist/cli/telemetry.js +36 -0
- package/dist/core/add/index.js +3 -2
- package/dist/core/app/common.js +2 -0
- package/dist/core/app/index.js +8 -4
- package/dist/core/build/generate.js +8 -8
- package/dist/core/build/index.js +2 -3
- package/dist/core/build/internal.js +29 -4
- package/dist/core/build/static-build.js +8 -5
- package/dist/core/build/vite-plugin-pages.js +6 -9
- package/dist/core/build/vite-plugin-ssr.js +26 -14
- package/dist/core/config.js +52 -20
- package/dist/core/create-vite.js +4 -1
- package/dist/core/dev/index.js +3 -3
- package/dist/core/logger/core.js +1 -1
- package/dist/core/messages.js +40 -7
- package/dist/core/path.js +14 -10
- package/dist/core/preview/index.js +7 -0
- package/dist/core/render/core.js +2 -4
- package/dist/core/render/dev/css.js +11 -4
- package/dist/core/render/dev/index.js +20 -55
- package/dist/core/render/result.js +17 -30
- package/dist/core/render/route-cache.js +1 -3
- package/dist/core/request.js +31 -1
- package/dist/core/routing/manifest/create.js +2 -1
- package/dist/core/routing/manifest/serialization.js +5 -4
- package/dist/core/routing/params.js +12 -1
- package/dist/core/routing/validation.js +7 -0
- package/dist/core/util.js +2 -2
- package/dist/integrations/index.js +15 -1
- package/dist/runtime/client/hmr.js +23 -3
- package/dist/runtime/server/index.js +20 -14
- package/dist/types/@types/astro.d.ts +161 -37
- package/dist/types/cli/open.d.ts +2 -0
- package/dist/types/cli/telemetry.d.ts +7 -0
- package/dist/types/core/add/index.d.ts +3 -1
- package/dist/types/core/app/index.d.ts +2 -0
- package/dist/types/core/app/types.d.ts +6 -5
- package/dist/types/core/build/index.d.ts +3 -1
- package/dist/types/core/build/internal.d.ts +8 -13
- package/dist/types/core/build/vite-plugin-pages.d.ts +0 -2
- package/dist/types/core/config.d.ts +55 -25
- package/dist/types/core/dev/index.d.ts +3 -1
- package/dist/types/core/messages.d.ts +4 -3
- package/dist/types/core/path.d.ts +4 -3
- package/dist/types/core/preview/index.d.ts +3 -0
- package/dist/types/core/render/core.d.ts +3 -3
- package/dist/types/core/render/dev/css.d.ts +1 -1
- package/dist/types/core/render/result.d.ts +3 -3
- package/dist/types/core/request.d.ts +2 -1
- package/dist/types/core/routing/params.d.ts +6 -0
- package/dist/types/core/routing/validation.d.ts +2 -0
- package/dist/types/integrations/index.d.ts +7 -1
- package/dist/types/runtime/server/index.d.ts +1 -0
- package/dist/types/vite-plugin-build-css/index.d.ts +1 -4
- package/dist/vite-plugin-astro/compile.js +1 -1
- package/dist/vite-plugin-astro/hmr.js +11 -13
- package/dist/vite-plugin-astro/index.js +11 -2
- package/dist/vite-plugin-astro-server/index.js +26 -5
- package/dist/vite-plugin-build-css/index.js +13 -50
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +17 -18
- package/env.d.ts +16 -2
- package/package.json +39 -39
- package/dist/types/vite-plugin-build-html/add-rollup-input.d.ts +0 -2
- package/dist/types/vite-plugin-build-html/extract-assets.d.ts +0 -20
- package/dist/types/vite-plugin-build-html/index.d.ts +0 -18
- package/dist/types/vite-plugin-build-html/util.d.ts +0 -7
- package/dist/vite-plugin-build-html/add-rollup-input.js +0 -50
- package/dist/vite-plugin-build-html/extract-assets.js +0 -202
- package/dist/vite-plugin-build-html/index.js +0 -426
- package/dist/vite-plugin-build-html/util.js +0 -44
package/LICENSE
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Fred K. Schott
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
|
26
|
+
|
|
27
|
+
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
28
|
+
|
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
|
|
39
|
+
|
|
40
|
+
MIT License
|
|
41
|
+
|
|
42
|
+
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
43
|
+
|
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
45
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
46
|
+
in the Software without restriction, including without limitation the rights
|
|
47
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
48
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
49
|
+
furnished to do so, subject to the following conditions:
|
|
50
|
+
|
|
51
|
+
The above copyright notice and this permission notice shall be included in all
|
|
52
|
+
copies or substantial portions of the Software.
|
|
53
|
+
|
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
55
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
56
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
57
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
58
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
59
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
60
|
+
SOFTWARE.
|
|
61
|
+
"""
|
package/astro-jsx.d.ts
CHANGED
|
@@ -621,7 +621,10 @@ declare namespace astroHTML.JSX {
|
|
|
621
621
|
// - "number | string"
|
|
622
622
|
// - "string"
|
|
623
623
|
// - union of string literals
|
|
624
|
-
interface SVGAttributes<T extends EventTarget>
|
|
624
|
+
interface SVGAttributes<T extends EventTarget>
|
|
625
|
+
extends AriaAttributes,
|
|
626
|
+
DOMAttributes<T>,
|
|
627
|
+
AstroBuiltinAttributes {
|
|
625
628
|
// Attributes which also defined in HTMLAttributes
|
|
626
629
|
className?: string | undefined | null;
|
|
627
630
|
class?: string | undefined | null;
|
package/components/Code.astro
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getHighlighter as getShikiHighlighter } from 'shiki';
|
|
2
|
+
|
|
3
|
+
// Caches Promise<Highligher> for reuse when the same theme and langs are provided
|
|
4
|
+
const _resolvedHighlighters = new Map();
|
|
5
|
+
|
|
6
|
+
function stringify(opts) {
|
|
7
|
+
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
|
8
|
+
return JSON.stringify(opts, Object.keys(opts).sort());
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function getHighlighter(opts) {
|
|
12
|
+
const key = stringify(opts);
|
|
13
|
+
|
|
14
|
+
// Highlighter has already been requested, reuse the same instance
|
|
15
|
+
if (_resolvedHighlighters.has(key)) {
|
|
16
|
+
return _resolvedHighlighters.get(key);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Start the async getHighlighter call and cache the Promise
|
|
20
|
+
const highlighter = getShikiHighlighter(opts);
|
|
21
|
+
_resolvedHighlighters.set(key, highlighter);
|
|
22
|
+
|
|
23
|
+
return highlighter;
|
|
24
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as colors from "kleur/colors";
|
|
2
2
|
import yargs from "yargs-parser";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { AstroTelemetry } from "@astrojs/telemetry";
|
|
5
|
+
import * as event from "@astrojs/telemetry/events";
|
|
4
6
|
import { nodeLogDestination, enableVerboseLogging } from "../core/logger/node.js";
|
|
5
7
|
import build from "../core/build/index.js";
|
|
6
8
|
import add from "../core/add/index.js";
|
|
7
9
|
import devServer from "../core/dev/index.js";
|
|
8
10
|
import preview from "../core/preview/index.js";
|
|
9
11
|
import { check } from "./check.js";
|
|
12
|
+
import { openInBrowser } from "./open.js";
|
|
13
|
+
import * as telemetryHandler from "./telemetry.js";
|
|
10
14
|
import { loadConfig } from "../core/config.js";
|
|
11
15
|
import { printHelp, formatErrorMessage, formatConfigErrorMessage } from "../core/messages.js";
|
|
12
16
|
import { createSafeError } from "../core/util.js";
|
|
@@ -16,10 +20,12 @@ function printAstroHelp() {
|
|
|
16
20
|
headline: "Futuristic web development tool.",
|
|
17
21
|
commands: [
|
|
18
22
|
["add", "Add an integration to your configuration."],
|
|
23
|
+
["docs", "Launch Astro's Doc site directly from the terminal. "],
|
|
19
24
|
["dev", "Run Astro in development mode."],
|
|
20
25
|
["build", "Build a pre-compiled production-ready site."],
|
|
21
26
|
["preview", "Preview your build locally before deploying."],
|
|
22
27
|
["check", "Check your project for errors."],
|
|
28
|
+
["telemetry", "Enable/disable anonymous data collection."],
|
|
23
29
|
["--version", "Show the version number and exit."],
|
|
24
30
|
["--help", "Show this help message."]
|
|
25
31
|
],
|
|
@@ -27,8 +33,6 @@ function printAstroHelp() {
|
|
|
27
33
|
["--host [optional IP]", "Expose server on network"],
|
|
28
34
|
["--config <path>", "Specify the path to the Astro config file."],
|
|
29
35
|
["--root <path>", "Specify the path to the project root folder."],
|
|
30
|
-
["--legacy-build", "Use the build strategy prior to 0.24.0"],
|
|
31
|
-
["--experimental-ssr", "Enable SSR compilation fot 3rd-party adapters."],
|
|
32
36
|
["--drafts", "Include markdown draft pages in the build."],
|
|
33
37
|
["--verbose", "Enable verbose logging"],
|
|
34
38
|
["--silent", "Disable logging"]
|
|
@@ -36,7 +40,7 @@ function printAstroHelp() {
|
|
|
36
40
|
});
|
|
37
41
|
}
|
|
38
42
|
async function printVersion() {
|
|
39
|
-
const version = "1.0.0-beta.
|
|
43
|
+
const version = "1.0.0-beta.22";
|
|
40
44
|
console.log();
|
|
41
45
|
console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
|
|
42
46
|
}
|
|
@@ -44,17 +48,20 @@ function resolveCommand(flags) {
|
|
|
44
48
|
const cmd = flags._[2];
|
|
45
49
|
if (cmd === "add")
|
|
46
50
|
return "add";
|
|
51
|
+
if (cmd === "telemetry")
|
|
52
|
+
return "telemetry";
|
|
47
53
|
if (flags.version)
|
|
48
54
|
return "version";
|
|
49
55
|
else if (flags.help)
|
|
50
56
|
return "help";
|
|
51
|
-
const supportedCommands = /* @__PURE__ */ new Set(["dev", "build", "preview", "check"]);
|
|
57
|
+
const supportedCommands = /* @__PURE__ */ new Set(["dev", "build", "preview", "check", "docs"]);
|
|
52
58
|
if (supportedCommands.has(cmd)) {
|
|
53
59
|
return cmd;
|
|
54
60
|
}
|
|
55
61
|
return "help";
|
|
56
62
|
}
|
|
57
63
|
async function cli(args) {
|
|
64
|
+
var _a;
|
|
58
65
|
const flags = yargs(args);
|
|
59
66
|
const cmd = resolveCommand(flags);
|
|
60
67
|
const root = flags.root;
|
|
@@ -76,24 +83,33 @@ async function cli(args) {
|
|
|
76
83
|
} else if (flags.silent) {
|
|
77
84
|
logging.level = "silent";
|
|
78
85
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
const telemetry = new AstroTelemetry({ version: "1.0.0-beta.22" });
|
|
87
|
+
if (cmd === "telemetry") {
|
|
88
|
+
try {
|
|
89
|
+
const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
|
|
90
|
+
return await telemetryHandler.update(subcommand, { flags, telemetry });
|
|
91
|
+
} catch (err) {
|
|
92
|
+
return throwAndExit(err);
|
|
93
|
+
}
|
|
84
94
|
}
|
|
85
95
|
switch (cmd) {
|
|
86
96
|
case "add": {
|
|
87
97
|
try {
|
|
88
98
|
const packages = flags._.slice(3);
|
|
89
|
-
|
|
99
|
+
telemetry.record(event.eventCliSession({
|
|
100
|
+
astroVersion: "1.0.0-beta.22",
|
|
101
|
+
cliCommand: "add"
|
|
102
|
+
}));
|
|
103
|
+
return await add(packages, { cwd: root, flags, logging, telemetry });
|
|
90
104
|
} catch (err) {
|
|
91
105
|
return throwAndExit(err);
|
|
92
106
|
}
|
|
93
107
|
}
|
|
94
108
|
case "dev": {
|
|
95
109
|
try {
|
|
96
|
-
await
|
|
110
|
+
const config = await loadConfig({ cwd: root, flags, cmd });
|
|
111
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.22", cliCommand: "dev" }, config));
|
|
112
|
+
await devServer(config, { logging, telemetry });
|
|
97
113
|
return await new Promise(() => {
|
|
98
114
|
});
|
|
99
115
|
} catch (err) {
|
|
@@ -102,18 +118,36 @@ async function cli(args) {
|
|
|
102
118
|
}
|
|
103
119
|
case "build": {
|
|
104
120
|
try {
|
|
105
|
-
|
|
121
|
+
const config = await loadConfig({ cwd: root, flags, cmd });
|
|
122
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.22", cliCommand: "build" }, config));
|
|
123
|
+
return await build(config, { logging, telemetry });
|
|
106
124
|
} catch (err) {
|
|
107
125
|
return throwAndExit(err);
|
|
108
126
|
}
|
|
109
127
|
}
|
|
110
128
|
case "check": {
|
|
129
|
+
const config = await loadConfig({ cwd: root, flags, cmd });
|
|
130
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.22", cliCommand: "check" }, config));
|
|
111
131
|
const ret = await check(config);
|
|
112
132
|
return process.exit(ret);
|
|
113
133
|
}
|
|
114
134
|
case "preview": {
|
|
115
135
|
try {
|
|
116
|
-
|
|
136
|
+
const config = await loadConfig({ cwd: root, flags, cmd });
|
|
137
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.22", cliCommand: "preview" }, config));
|
|
138
|
+
const server = await preview(config, { logging, telemetry });
|
|
139
|
+
return await server.closed();
|
|
140
|
+
} catch (err) {
|
|
141
|
+
return throwAndExit(err);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
case "docs": {
|
|
145
|
+
try {
|
|
146
|
+
await telemetry.record(event.eventCliSession({
|
|
147
|
+
astroVersion: "1.0.0-beta.22",
|
|
148
|
+
cliCommand: "docs"
|
|
149
|
+
}));
|
|
150
|
+
return await openInBrowser("https://docs.astro.build/");
|
|
117
151
|
} catch (err) {
|
|
118
152
|
return throwAndExit(err);
|
|
119
153
|
}
|
package/dist/cli/open.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
const getPlatformSpecificCommand = () => {
|
|
3
|
+
const isGitPod = Boolean(process.env.GITPOD_REPO_ROOT);
|
|
4
|
+
const platform = isGitPod ? "gitpod" : process.platform;
|
|
5
|
+
switch (platform) {
|
|
6
|
+
case "android":
|
|
7
|
+
case "linux":
|
|
8
|
+
return ["xdg-open"];
|
|
9
|
+
case "darwin":
|
|
10
|
+
return ["open"];
|
|
11
|
+
case "win32":
|
|
12
|
+
return ["cmd", ["/c", "start"]];
|
|
13
|
+
case "gitpod":
|
|
14
|
+
return ["/ide/bin/remote-cli/gitpod-code", ["--openExternal"]];
|
|
15
|
+
default:
|
|
16
|
+
throw new Error(`It looks like your platform ("${platform}") isn't supported!
|
|
17
|
+
To view Astro's docs, please visit https://docs.astro.build`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
async function openInBrowser(url) {
|
|
21
|
+
const [command, args = []] = getPlatformSpecificCommand();
|
|
22
|
+
return execa(command, [...args, encodeURI(url)]);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
openInBrowser
|
|
26
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as msg from "../core/messages.js";
|
|
2
|
+
async function update(subcommand, { flags, telemetry }) {
|
|
3
|
+
const isValid = ["enable", "disable", "reset"].includes(subcommand);
|
|
4
|
+
if (flags.help || !isValid) {
|
|
5
|
+
msg.printHelp({
|
|
6
|
+
commandName: "astro telemetry",
|
|
7
|
+
usage: "<enable|disable|reset>",
|
|
8
|
+
commands: [
|
|
9
|
+
["enable", "Enable anonymous data collection."],
|
|
10
|
+
["disable", "Disable anonymous data collection."],
|
|
11
|
+
["reset", "Reset anonymous data collection settings."]
|
|
12
|
+
]
|
|
13
|
+
});
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
switch (subcommand) {
|
|
17
|
+
case "enable": {
|
|
18
|
+
telemetry.setEnabled(true);
|
|
19
|
+
console.log(msg.telemetryEnabled());
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
case "disable": {
|
|
23
|
+
telemetry.setEnabled(false);
|
|
24
|
+
console.log(msg.telemetryDisabled());
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
case "reset": {
|
|
28
|
+
telemetry.clear();
|
|
29
|
+
console.log(msg.telemetryReset());
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
update
|
|
36
|
+
};
|
package/dist/core/add/index.js
CHANGED
|
@@ -18,7 +18,8 @@ import { parseNpmName } from "../util.js";
|
|
|
18
18
|
import { wrapDefaultExport } from "./wrapper.js";
|
|
19
19
|
import { ensureImport } from "./imports.js";
|
|
20
20
|
import { t, parse, visit, generate } from "./babel.js";
|
|
21
|
-
|
|
21
|
+
import { appendForwardSlash } from "../path.js";
|
|
22
|
+
async function add(names, { cwd, flags, logging, telemetry }) {
|
|
22
23
|
if (flags.help) {
|
|
23
24
|
printHelp({
|
|
24
25
|
commandName: "astro add",
|
|
@@ -65,7 +66,7 @@ async function add(names, { cwd, flags, logging }) {
|
|
|
65
66
|
debug("add", `Found config at ${configURL}`);
|
|
66
67
|
} else {
|
|
67
68
|
info(logging, "add", `Unable to locate a config file, generating one for you.`);
|
|
68
|
-
configURL = new URL("./astro.config.mjs", root);
|
|
69
|
+
configURL = new URL("./astro.config.mjs", appendForwardSlash(root.href));
|
|
69
70
|
await fs.writeFile(fileURLToPath(configURL), CONSTS.CONFIG_STUB, { encoding: "utf-8" });
|
|
70
71
|
}
|
|
71
72
|
const integrations = await validateIntegrations(names);
|
package/dist/core/app/common.js
CHANGED
|
@@ -27,7 +27,9 @@ function deserializeManifest(serializedManifest) {
|
|
|
27
27
|
const route = serializedRoute;
|
|
28
28
|
route.routeData = deserializeRouteData(serializedRoute.routeData);
|
|
29
29
|
}
|
|
30
|
+
const assets = new Set(serializedManifest.assets);
|
|
30
31
|
return __spreadProps(__spreadValues({}, serializedManifest), {
|
|
32
|
+
assets,
|
|
31
33
|
routes
|
|
32
34
|
});
|
|
33
35
|
}
|
package/dist/core/app/index.js
CHANGED
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
createModuleScriptElementWithSrcSet
|
|
34
34
|
} from "../render/ssr-element.js";
|
|
35
35
|
import { prependForwardSlash } from "../path.js";
|
|
36
|
+
const pagesVirtualModuleId = "@astrojs-pages-virtual-entry";
|
|
37
|
+
const resolvedPagesVirtualModuleId = "\0" + pagesVirtualModuleId;
|
|
36
38
|
class App {
|
|
37
39
|
constructor(manifest) {
|
|
38
40
|
__privateAdd(this, _renderPage);
|
|
@@ -92,10 +94,9 @@ renderPage_fn = async function(request, routeData, mod) {
|
|
|
92
94
|
const links = createLinkStylesheetElementSet(info.links, manifest.site);
|
|
93
95
|
const scripts = createModuleScriptElementWithSrcSet(info.scripts, manifest.site);
|
|
94
96
|
const result = await render({
|
|
95
|
-
legacyBuild: false,
|
|
96
97
|
links,
|
|
97
98
|
logging: __privateGet(this, _logging),
|
|
98
|
-
|
|
99
|
+
markdown: manifest.markdown,
|
|
99
100
|
mod,
|
|
100
101
|
origin: url.origin,
|
|
101
102
|
pathname: url.pathname,
|
|
@@ -128,7 +129,7 @@ renderPage_fn = async function(request, routeData, mod) {
|
|
|
128
129
|
});
|
|
129
130
|
};
|
|
130
131
|
_callEndpoint = new WeakSet();
|
|
131
|
-
callEndpoint_fn = async function(request,
|
|
132
|
+
callEndpoint_fn = async function(request, routeData, mod) {
|
|
132
133
|
const url = new URL(request.url);
|
|
133
134
|
const handler = mod;
|
|
134
135
|
const result = await callEndpoint(handler, {
|
|
@@ -136,6 +137,7 @@ callEndpoint_fn = async function(request, _routeData, mod) {
|
|
|
136
137
|
origin: url.origin,
|
|
137
138
|
pathname: url.pathname,
|
|
138
139
|
request,
|
|
140
|
+
route: routeData,
|
|
139
141
|
routeCache: __privateGet(this, _routeCache),
|
|
140
142
|
ssr: true
|
|
141
143
|
});
|
|
@@ -158,5 +160,7 @@ callEndpoint_fn = async function(request, _routeData, mod) {
|
|
|
158
160
|
};
|
|
159
161
|
export {
|
|
160
162
|
App,
|
|
161
|
-
deserializeManifest
|
|
163
|
+
deserializeManifest,
|
|
164
|
+
pagesVirtualModuleId,
|
|
165
|
+
resolvedPagesVirtualModuleId
|
|
162
166
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import astroRemark from "@astrojs/markdown-remark";
|
|
2
1
|
import fs from "fs";
|
|
3
2
|
import { bgGreen, black, cyan, dim, green, magenta } from "kleur/colors";
|
|
4
3
|
import npath from "path";
|
|
5
4
|
import { fileURLToPath } from "url";
|
|
6
5
|
import { debug, info } from "../logger/core.js";
|
|
7
|
-
import { prependForwardSlash } from "../../core/path.js";
|
|
6
|
+
import { joinPaths, prependForwardSlash, removeLeadingForwardSlash } from "../../core/path.js";
|
|
8
7
|
import { BEFORE_HYDRATION_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
9
8
|
import { call as callEndpoint } from "../endpoint/index.js";
|
|
10
9
|
import { render } from "../render/core.js";
|
|
@@ -99,13 +98,14 @@ function addPageName(pathname, opts) {
|
|
|
99
98
|
opts.pageNames.push(pathname.replace(/\/?$/, "/").replace(/^\//, ""));
|
|
100
99
|
}
|
|
101
100
|
async function generatePath(pathname, opts, gopts) {
|
|
101
|
+
var _a;
|
|
102
102
|
const { astroConfig, logging, origin, routeCache } = opts;
|
|
103
103
|
const { mod, internals, linkIds, hoistedId, pageData, renderers } = gopts;
|
|
104
104
|
if (pageData.route.type === "page") {
|
|
105
105
|
addPageName(pathname, opts);
|
|
106
106
|
}
|
|
107
107
|
debug("build", `Generating: ${pathname}`);
|
|
108
|
-
const site = astroConfig.site;
|
|
108
|
+
const site = astroConfig.base !== "/" ? joinPaths(((_a = astroConfig.site) == null ? void 0 : _a.toString()) || "http://localhost/", astroConfig.base) : astroConfig.site;
|
|
109
109
|
const links = createLinkStylesheetElementSet(linkIds.reverse(), site);
|
|
110
110
|
const scripts = createModuleScriptElementWithSrcSet(hoistedId ? [hoistedId] : [], site);
|
|
111
111
|
for (const script of astroConfig._ctx.scripts) {
|
|
@@ -116,12 +116,12 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
const
|
|
119
|
+
const ssr = isBuildingToSSR(opts.astroConfig);
|
|
120
|
+
const url = new URL(opts.astroConfig.base + removeLeadingForwardSlash(pathname), origin);
|
|
120
121
|
const options = {
|
|
121
|
-
legacyBuild: false,
|
|
122
122
|
links,
|
|
123
123
|
logging,
|
|
124
|
-
|
|
124
|
+
markdown: astroConfig.markdown,
|
|
125
125
|
mod,
|
|
126
126
|
origin,
|
|
127
127
|
pathname,
|
|
@@ -139,11 +139,11 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
139
139
|
const fullyRelativePath = relPath[0] === "." ? relPath : "./" + relPath;
|
|
140
140
|
return fullyRelativePath;
|
|
141
141
|
},
|
|
142
|
-
request: createRequest({ url, headers: new Headers(), logging }),
|
|
142
|
+
request: createRequest({ url, headers: new Headers(), logging, ssr }),
|
|
143
143
|
route: pageData.route,
|
|
144
144
|
routeCache,
|
|
145
145
|
site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : astroConfig.site,
|
|
146
|
-
ssr
|
|
146
|
+
ssr
|
|
147
147
|
};
|
|
148
148
|
let body;
|
|
149
149
|
if (pageData.route.type === "endpoint") {
|
package/dist/core/build/index.js
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
timerMessage,
|
|
12
12
|
warnIfUsingExperimentalSSR
|
|
13
13
|
} from "../logger/core.js";
|
|
14
|
-
import { nodeLogOptions } from "../logger/node.js";
|
|
15
14
|
import { createRouteManifest } from "../routing/index.js";
|
|
16
15
|
import { collectPagesData } from "./page-data.js";
|
|
17
16
|
import { staticBuild } from "./static-build.js";
|
|
@@ -25,7 +24,7 @@ import {
|
|
|
25
24
|
import { getTimeStat } from "./util.js";
|
|
26
25
|
import { createSafeError, isBuildingToSSR } from "../util.js";
|
|
27
26
|
import { fixViteErrorMessage } from "../errors.js";
|
|
28
|
-
async function build(config, options
|
|
27
|
+
async function build(config, options) {
|
|
29
28
|
applyPolyfill();
|
|
30
29
|
const builder = new AstroBuilder(config, options);
|
|
31
30
|
await builder.run();
|
|
@@ -122,6 +121,7 @@ class AstroBuilder {
|
|
|
122
121
|
await viteServer.close();
|
|
123
122
|
await runHookBuildDone({
|
|
124
123
|
config: this.config,
|
|
124
|
+
buildConfig,
|
|
125
125
|
pages: pageNames,
|
|
126
126
|
routes: Object.values(allPages).map((pd) => pd.route)
|
|
127
127
|
});
|
|
@@ -150,7 +150,6 @@ class AstroBuilder {
|
|
|
150
150
|
pageCount,
|
|
151
151
|
buildMode
|
|
152
152
|
}) {
|
|
153
|
-
const buildTime = performance.now() - timeStart;
|
|
154
153
|
const total = getTimeStat(timeStart, performance.now());
|
|
155
154
|
let messages = [];
|
|
156
155
|
if (buildMode === "static") {
|
|
@@ -7,13 +7,11 @@ function createBuildInternals() {
|
|
|
7
7
|
const hoistedScriptIdToHoistedMap = /* @__PURE__ */ new Map();
|
|
8
8
|
return {
|
|
9
9
|
pureCSSChunks,
|
|
10
|
-
chunkToReferenceIdMap,
|
|
11
|
-
astroStyleMap,
|
|
12
|
-
astroPageStyleMap,
|
|
13
10
|
hoistedScriptIdToHoistedMap,
|
|
14
11
|
entrySpecifierToBundleMap: /* @__PURE__ */ new Map(),
|
|
15
12
|
pagesByComponent: /* @__PURE__ */ new Map(),
|
|
16
|
-
pagesByViteID: /* @__PURE__ */ new Map()
|
|
13
|
+
pagesByViteID: /* @__PURE__ */ new Map(),
|
|
14
|
+
pagesByClientOnly: /* @__PURE__ */ new Map()
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
17
|
function trackPageData(internals, component, pageData, componentModuleId, componentURL) {
|
|
@@ -21,6 +19,19 @@ function trackPageData(internals, component, pageData, componentModuleId, compon
|
|
|
21
19
|
internals.pagesByComponent.set(component, pageData);
|
|
22
20
|
internals.pagesByViteID.set(viteID(componentURL), pageData);
|
|
23
21
|
}
|
|
22
|
+
function trackClientOnlyPageDatas(internals, pageData, clientOnlys, astroConfig) {
|
|
23
|
+
for (const clientOnlyComponent of clientOnlys) {
|
|
24
|
+
const coPath = viteID(new URL("." + clientOnlyComponent, astroConfig.root));
|
|
25
|
+
let pageDataSet;
|
|
26
|
+
if (internals.pagesByClientOnly.has(coPath)) {
|
|
27
|
+
pageDataSet = internals.pagesByClientOnly.get(coPath);
|
|
28
|
+
} else {
|
|
29
|
+
pageDataSet = /* @__PURE__ */ new Set();
|
|
30
|
+
internals.pagesByClientOnly.set(coPath, pageDataSet);
|
|
31
|
+
}
|
|
32
|
+
pageDataSet.add(pageData);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
function* getPageDatasByChunk(internals, chunk) {
|
|
25
36
|
const pagesByViteID = internals.pagesByViteID;
|
|
26
37
|
for (const [modulePath] of Object.entries(chunk.modules)) {
|
|
@@ -29,6 +40,18 @@ function* getPageDatasByChunk(internals, chunk) {
|
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
}
|
|
43
|
+
function* getPageDatasByClientOnlyChunk(internals, chunk) {
|
|
44
|
+
const pagesByClientOnly = internals.pagesByClientOnly;
|
|
45
|
+
if (pagesByClientOnly.size) {
|
|
46
|
+
for (const [modulePath] of Object.entries(chunk.modules)) {
|
|
47
|
+
if (pagesByClientOnly.has(modulePath)) {
|
|
48
|
+
for (const pageData of pagesByClientOnly.get(modulePath)) {
|
|
49
|
+
yield pageData;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
32
55
|
function getPageDataByComponent(internals, component) {
|
|
33
56
|
if (internals.pagesByComponent.has(component)) {
|
|
34
57
|
return internals.pagesByComponent.get(component);
|
|
@@ -53,6 +76,8 @@ export {
|
|
|
53
76
|
getPageDataByComponent,
|
|
54
77
|
getPageDataByViteID,
|
|
55
78
|
getPageDatasByChunk,
|
|
79
|
+
getPageDatasByClientOnlyChunk,
|
|
56
80
|
hasPageDataByViteID,
|
|
81
|
+
trackClientOnlyPageDatas,
|
|
57
82
|
trackPageData
|
|
58
83
|
};
|
|
@@ -17,6 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { trackClientOnlyPageDatas } from "../../core/build/internal.js";
|
|
20
21
|
import glob from "fast-glob";
|
|
21
22
|
import fs from "fs";
|
|
22
23
|
import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
|
|
@@ -52,9 +53,11 @@ async function staticBuild(opts) {
|
|
|
52
53
|
if (pageData.route.type === "page") {
|
|
53
54
|
const [renderers, mod] = pageData.preload;
|
|
54
55
|
const metadata = mod.$$metadata;
|
|
56
|
+
const clientOnlys = Array.from(metadata.clientOnlyComponentPaths());
|
|
57
|
+
trackClientOnlyPageDatas(internals, pageData, clientOnlys, astroConfig);
|
|
55
58
|
const topLevelImports = /* @__PURE__ */ new Set([
|
|
56
59
|
...metadata.hydratedComponentPaths(),
|
|
57
|
-
...
|
|
60
|
+
...clientOnlys,
|
|
58
61
|
...metadata.hydrationDirectiveSpecifiers(),
|
|
59
62
|
...renderers.filter((renderer) => !!renderer.clientEntrypoint).map((renderer) => renderer.clientEntrypoint)
|
|
60
63
|
]);
|
|
@@ -121,7 +124,7 @@ async function ssrBuild(opts, internals, input) {
|
|
|
121
124
|
vitePluginPages(opts, internals),
|
|
122
125
|
rollupPluginAstroBuildCSS({
|
|
123
126
|
internals,
|
|
124
|
-
|
|
127
|
+
target: "server"
|
|
125
128
|
}),
|
|
126
129
|
...viteConfig.plugins || [],
|
|
127
130
|
isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter)
|
|
@@ -175,7 +178,7 @@ ${bgGreen(black(" building client "))}`);
|
|
|
175
178
|
vitePluginHoistedScripts(astroConfig, internals),
|
|
176
179
|
rollupPluginAstroBuildCSS({
|
|
177
180
|
internals,
|
|
178
|
-
|
|
181
|
+
target: "client"
|
|
179
182
|
}),
|
|
180
183
|
...viteConfig.plugins || []
|
|
181
184
|
],
|
|
@@ -204,11 +207,11 @@ async function copyFiles(fromFolder, toFolder) {
|
|
|
204
207
|
const files = await glob("**/*", {
|
|
205
208
|
cwd: fileURLToPath(fromFolder)
|
|
206
209
|
});
|
|
207
|
-
await fs.promises.mkdir(toFolder, { recursive: true });
|
|
208
210
|
await Promise.all(files.map(async (filename) => {
|
|
209
211
|
const from = new URL(filename, fromFolder);
|
|
210
212
|
const to = new URL(filename, toFolder);
|
|
211
|
-
|
|
213
|
+
const lastFolder = new URL("./", to);
|
|
214
|
+
return fs.promises.mkdir(lastFolder, { recursive: true }).then(() => fs.promises.copyFile(from, to));
|
|
212
215
|
}));
|
|
213
216
|
}
|
|
214
217
|
async function ssrMoveAssets(opts) {
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { addRollupInput } from "./add-rollup-input.js";
|
|
2
2
|
import { eachPageData } from "./internal.js";
|
|
3
3
|
import { isBuildingToSSR } from "../util.js";
|
|
4
|
-
|
|
5
|
-
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
4
|
+
import { resolvedPagesVirtualModuleId, pagesVirtualModuleId } from "../app/index.js";
|
|
6
5
|
function vitePluginPages(opts, internals) {
|
|
7
6
|
return {
|
|
8
7
|
name: "@astro/plugin-build-pages",
|
|
9
8
|
options(options) {
|
|
10
9
|
if (!isBuildingToSSR(opts.astroConfig)) {
|
|
11
|
-
return addRollupInput(options, [
|
|
10
|
+
return addRollupInput(options, [pagesVirtualModuleId]);
|
|
12
11
|
}
|
|
13
12
|
},
|
|
14
13
|
resolveId(id) {
|
|
15
|
-
if (id ===
|
|
16
|
-
return
|
|
14
|
+
if (id === pagesVirtualModuleId) {
|
|
15
|
+
return resolvedPagesVirtualModuleId;
|
|
17
16
|
}
|
|
18
17
|
},
|
|
19
18
|
load(id) {
|
|
20
|
-
if (id ===
|
|
19
|
+
if (id === resolvedPagesVirtualModuleId) {
|
|
21
20
|
let importMap = "";
|
|
22
21
|
let imports = [];
|
|
23
22
|
let i = 0;
|
|
@@ -31,7 +30,7 @@ function vitePluginPages(opts, internals) {
|
|
|
31
30
|
let rendererItems = "";
|
|
32
31
|
for (const renderer of opts.astroConfig._ctx.renderers) {
|
|
33
32
|
const variable = `_renderer${i}`;
|
|
34
|
-
imports.
|
|
33
|
+
imports.unshift(`import ${variable} from '${renderer.serverEntrypoint}';`);
|
|
35
34
|
rendererItems += `Object.assign(${JSON.stringify(renderer)}, { ssr: ${variable} }),`;
|
|
36
35
|
i++;
|
|
37
36
|
}
|
|
@@ -45,7 +44,5 @@ export const renderers = [${rendererItems}];`;
|
|
|
45
44
|
};
|
|
46
45
|
}
|
|
47
46
|
export {
|
|
48
|
-
resolvedVirtualModuleId,
|
|
49
|
-
virtualModuleId,
|
|
50
47
|
vitePluginPages
|
|
51
48
|
};
|