astro 1.0.0-beta.72 → 1.0.0-beta.73
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-jsx.d.ts +12 -12
- package/astro.js +1 -1
- package/components/Code.astro +2 -2
- package/components/Debug.astro +11 -11
- package/dist/cli/check/index.js +68 -0
- package/dist/cli/check/print.js +87 -0
- package/dist/cli/index.js +1 -1
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/css.js +10 -37
- package/dist/core/render/dev/index.js +2 -2
- package/dist/core/render/dev/scripts.js +36 -0
- package/dist/core/render/dev/vite.js +38 -0
- package/dist/core/util.js +1 -1
- package/dist/jsx/babel.js +80 -8
- package/dist/jsx/server.js +2 -5
- package/dist/runtime/server/hydration.js +3 -0
- package/dist/runtime/server/index.js +4 -2
- package/dist/runtime/server/jsx.js +68 -28
- package/dist/runtime/server/metadata.js +0 -24
- package/dist/runtime/server/serialize.js +2 -2
- package/dist/types/@types/astro.d.ts +0 -1
- package/dist/types/cli/check/index.d.ts +2 -0
- package/dist/types/cli/check/print.d.ts +2 -0
- package/dist/types/core/render/dev/scripts.d.ts +3 -0
- package/dist/types/core/render/dev/vite.d.ts +3 -0
- package/dist/types/jsx/server.d.ts +1 -1
- package/dist/types/jsx-runtime/index.d.ts +2 -2
- package/dist/types/runtime/server/index.d.ts +1 -0
- package/dist/types/runtime/server/jsx.d.ts +2 -1
- package/dist/types/runtime/server/metadata.d.ts +0 -2
- package/dist/vite-plugin-env/index.js +2 -0
- package/dist/vite-plugin-jsx/index.js +13 -0
- package/dist/vite-plugin-markdown/index.js +3 -1
- package/package.json +6 -6
- package/dist/cli/check.js +0 -93
- package/dist/types/cli/check.d.ts +0 -3
package/astro-jsx.d.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts
|
|
11
11
|
*/
|
|
12
12
|
declare namespace astroHTML.JSX {
|
|
13
|
-
/* html jsx */
|
|
14
13
|
export type Child = Node | Node[] | string | number | boolean | null | undefined | unknown;
|
|
15
14
|
export type Children = Child | Child[];
|
|
16
15
|
|
|
@@ -24,17 +23,18 @@ declare namespace astroHTML.JSX {
|
|
|
24
23
|
children?: Children;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
type AstroBuiltinProps = import('astro').AstroBuiltinProps;
|
|
28
|
-
type AstroBuiltinAttributes = import('astro').AstroBuiltinAttributes;
|
|
29
|
-
type AstroDefineVarsAttribute = import('astro').AstroDefineVarsAttribute;
|
|
30
|
-
type AstroScriptAttributes = import('astro').AstroScriptAttributes &
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
type
|
|
26
|
+
type AstroBuiltinProps = import('./dist/types/@types/astro').AstroBuiltinProps;
|
|
27
|
+
type AstroBuiltinAttributes = import('./dist/types/@types/astro').AstroBuiltinAttributes;
|
|
28
|
+
type AstroDefineVarsAttribute = import('./dist/types/@types/astro').AstroDefineVarsAttribute;
|
|
29
|
+
type AstroScriptAttributes = import('./dist/types/@types/astro').AstroScriptAttributes &
|
|
30
|
+
AstroDefineVarsAttribute;
|
|
31
|
+
type AstroStyleAttributes = import('./dist/types/@types/astro').AstroStyleAttributes &
|
|
32
|
+
AstroDefineVarsAttribute;
|
|
33
|
+
|
|
34
|
+
// This is an unfortunate use of `any`, but unfortunately we can't make a type that works for every framework
|
|
35
|
+
// without importing every single framework's types (which comes with its own set of problems).
|
|
36
|
+
// Using any isn't that bad here however as in Astro files the return type of a component isn't relevant in most cases
|
|
37
|
+
type Element = HTMLElement | any;
|
|
38
38
|
|
|
39
39
|
interface DOMAttributes {
|
|
40
40
|
children?: Children;
|
package/astro.js
CHANGED
|
@@ -50,7 +50,7 @@ async function main() {
|
|
|
50
50
|
// it's okay to hard-code the valid Node versions here since they will not change over time.
|
|
51
51
|
if (typeof require === 'undefined') {
|
|
52
52
|
console.error(`\nNode.js v${version} is not supported by Astro!
|
|
53
|
-
Please upgrade to a version of Node.js with complete ESM support: "^14.
|
|
53
|
+
Please upgrade to a version of Node.js with complete ESM support: "^14.18.0 || >=16.12.0"\n`);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Not supported: Report the most helpful error message possible.
|
package/components/Code.astro
CHANGED
|
@@ -36,8 +36,8 @@ const { code, lang = 'plaintext', theme = 'github-dark', wrap = false } = Astro.
|
|
|
36
36
|
|
|
37
37
|
/** Replace the shiki class name with a custom astro class name. */
|
|
38
38
|
function repairShikiTheme(html: string): string {
|
|
39
|
-
// Replace "shiki" class naming with "astro"
|
|
40
|
-
html = html.replace('<pre class="shiki"', '<pre
|
|
39
|
+
// Replace "shiki" class naming with "astro"
|
|
40
|
+
html = html.replace('<pre class="shiki"', '<pre class="astro-code"');
|
|
41
41
|
// Replace "shiki" css variable naming with "astro".
|
|
42
42
|
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
|
43
43
|
// Handle code wrapping
|
package/components/Debug.astro
CHANGED
|
@@ -5,48 +5,48 @@ const key = Object.keys(Astro.props)[0];
|
|
|
5
5
|
const value = Astro.props[key];
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
<div class="debug">
|
|
9
|
-
<div class="debug-header">
|
|
10
|
-
<h2 class="debug-title"><span class="debug-label">Debug</span> <span class="debug-name">"{key}"</span></h2>
|
|
8
|
+
<div class="astro-debug">
|
|
9
|
+
<div class="astro-debug-header">
|
|
10
|
+
<h2 class="astro-debug-title"><span class="astro-debug-label">Debug</span> <span class="astro-debug-name">"{key}"</span></h2>
|
|
11
11
|
</div>
|
|
12
12
|
|
|
13
13
|
<Code code={JSON.stringify(value, null, 2)} />
|
|
14
14
|
</div>
|
|
15
15
|
|
|
16
|
-
<style>
|
|
17
|
-
.debug {
|
|
16
|
+
<style is:inline>
|
|
17
|
+
.astro-debug {
|
|
18
18
|
font-size: 14px;
|
|
19
19
|
padding: 1rem 1.5rem;
|
|
20
20
|
background: white;
|
|
21
21
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
.debug-header,
|
|
25
|
-
pre {
|
|
24
|
+
.astro-debug-header,
|
|
25
|
+
pre.astro-code {
|
|
26
26
|
margin: -1rem -1.5rem 1rem;
|
|
27
27
|
padding: 0.25rem 0.75rem;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
.debug-header {
|
|
30
|
+
.astro-debug-header {
|
|
31
31
|
background: #ff1639;
|
|
32
32
|
border-radius: 4px;
|
|
33
33
|
border-bottom-left-radius: 0;
|
|
34
34
|
border-bottom-right-radius: 0;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
.debug-title {
|
|
37
|
+
.astro-debug-title {
|
|
38
38
|
font-size: 1em;
|
|
39
39
|
color: white;
|
|
40
40
|
margin: 0.5em 0;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
.debug-label {
|
|
43
|
+
.astro-debug-label {
|
|
44
44
|
font-weight: bold;
|
|
45
45
|
text-transform: uppercase;
|
|
46
46
|
margin-right: 0.75em;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
pre {
|
|
49
|
+
pre.astro-code {
|
|
50
50
|
border: 1px solid #eee;
|
|
51
51
|
padding: 1rem 0.75rem;
|
|
52
52
|
border-radius: 4px;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AstroCheck, DiagnosticSeverity } from "@astrojs/language-server";
|
|
2
|
+
import glob from "fast-glob";
|
|
3
|
+
import * as fs from "fs";
|
|
4
|
+
import { bold, dim, red, yellow } from "kleur/colors";
|
|
5
|
+
import ora from "ora";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
|
+
import { printDiagnostic } from "./print.js";
|
|
8
|
+
async function check(astroConfig) {
|
|
9
|
+
console.log(bold("astro check"));
|
|
10
|
+
const root = astroConfig.root;
|
|
11
|
+
const spinner = ora(` Getting diagnostics for Astro files in ${fileURLToPath(root)}\u2026`).start();
|
|
12
|
+
let checker = new AstroCheck(root.toString());
|
|
13
|
+
const filesCount = await openAllDocuments(root, [], checker);
|
|
14
|
+
let diagnostics = await checker.getDiagnostics();
|
|
15
|
+
spinner.succeed();
|
|
16
|
+
let result = {
|
|
17
|
+
errors: 0,
|
|
18
|
+
warnings: 0,
|
|
19
|
+
hints: 0
|
|
20
|
+
};
|
|
21
|
+
diagnostics.forEach((diag) => {
|
|
22
|
+
diag.diagnostics.forEach((d) => {
|
|
23
|
+
console.log(printDiagnostic(diag.filePath, diag.text, d));
|
|
24
|
+
switch (d.severity) {
|
|
25
|
+
case DiagnosticSeverity.Error: {
|
|
26
|
+
result.errors++;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case DiagnosticSeverity.Warning: {
|
|
30
|
+
result.warnings++;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
case DiagnosticSeverity.Hint: {
|
|
34
|
+
result.hints++;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
console.log([
|
|
41
|
+
bold(`Result (${filesCount} file${filesCount === 1 ? "" : "s"}): `),
|
|
42
|
+
bold(red(`${result.errors} ${result.errors === 1 ? "error" : "errors"}`)),
|
|
43
|
+
bold(yellow(`${result.warnings} ${result.warnings === 1 ? "warning" : "warnings"}`)),
|
|
44
|
+
dim(`${result.hints} ${result.hints === 1 ? "hint" : "hints"}
|
|
45
|
+
`)
|
|
46
|
+
].join(`
|
|
47
|
+
${dim("-")} `));
|
|
48
|
+
const exitCode = result.errors ? 1 : 0;
|
|
49
|
+
return exitCode;
|
|
50
|
+
}
|
|
51
|
+
async function openAllDocuments(workspaceUri, filePathsToIgnore, checker) {
|
|
52
|
+
const files = await glob("**/*.astro", {
|
|
53
|
+
cwd: fileURLToPath(workspaceUri),
|
|
54
|
+
ignore: ["node_modules/**"].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`)),
|
|
55
|
+
absolute: true
|
|
56
|
+
});
|
|
57
|
+
for (const file of files) {
|
|
58
|
+
const text = fs.readFileSync(file, "utf-8");
|
|
59
|
+
checker.upsertDocument({
|
|
60
|
+
uri: pathToFileURL(file).toString(),
|
|
61
|
+
text
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return files.length;
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
check
|
|
68
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { DiagnosticSeverity, offsetAt } from "@astrojs/language-server";
|
|
2
|
+
import {
|
|
3
|
+
bgRed,
|
|
4
|
+
bgWhite,
|
|
5
|
+
bgYellow,
|
|
6
|
+
black,
|
|
7
|
+
bold,
|
|
8
|
+
cyan,
|
|
9
|
+
gray,
|
|
10
|
+
red,
|
|
11
|
+
white,
|
|
12
|
+
yellow
|
|
13
|
+
} from "kleur/colors";
|
|
14
|
+
import stringWidth from "string-width";
|
|
15
|
+
function printDiagnostic(filePath, text, diag) {
|
|
16
|
+
let result = [];
|
|
17
|
+
const realStartLine = diag.range.start.line + 1;
|
|
18
|
+
const realStartCharacter = diag.range.start.character + 1;
|
|
19
|
+
const IDEFilePath = `${bold(cyan(filePath))}:${bold(yellow(realStartLine))}:${bold(yellow(realStartCharacter))}`;
|
|
20
|
+
result.push(`${IDEFilePath} ${bold(getColorForSeverity(diag, getStringForSeverity(diag)))}: ${diag.message}`);
|
|
21
|
+
const previousLine = getLine(diag.range.start.line - 1, text);
|
|
22
|
+
if (previousLine) {
|
|
23
|
+
result.push(`${getPrintableLineNumber(realStartLine - 1)} ${gray(previousLine)}`);
|
|
24
|
+
}
|
|
25
|
+
const str = getLine(diag.range.start.line, text);
|
|
26
|
+
const lineNumStr = realStartLine.toString().padStart(2, "0");
|
|
27
|
+
const lineNumLen = lineNumStr.length;
|
|
28
|
+
result.push(`${getBackgroundForSeverity(diag, lineNumStr)} ${str}`);
|
|
29
|
+
const tildes = generateString("~", diag.range.end.character - diag.range.start.character);
|
|
30
|
+
const beforeChars = stringWidth(str.substring(0, diag.range.start.character));
|
|
31
|
+
const spaces = generateString(" ", beforeChars + lineNumLen - 1);
|
|
32
|
+
result.push(` ${spaces}${bold(getColorForSeverity(diag, tildes))}`);
|
|
33
|
+
const nextLine = getLine(diag.range.start.line + 1, text);
|
|
34
|
+
if (nextLine) {
|
|
35
|
+
result.push(`${getPrintableLineNumber(realStartLine + 1)} ${gray(nextLine)}`);
|
|
36
|
+
}
|
|
37
|
+
result.push("");
|
|
38
|
+
return result.join("\n");
|
|
39
|
+
}
|
|
40
|
+
function generateString(str, len) {
|
|
41
|
+
return Array.from({ length: len }, () => str).join("");
|
|
42
|
+
}
|
|
43
|
+
function getStringForSeverity(diag) {
|
|
44
|
+
switch (diag.severity) {
|
|
45
|
+
case DiagnosticSeverity.Error:
|
|
46
|
+
return "Error";
|
|
47
|
+
case DiagnosticSeverity.Warning:
|
|
48
|
+
return "Warning";
|
|
49
|
+
case DiagnosticSeverity.Hint:
|
|
50
|
+
return "Hint";
|
|
51
|
+
default:
|
|
52
|
+
return "Unknown";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function getColorForSeverity(diag, text) {
|
|
56
|
+
switch (diag.severity) {
|
|
57
|
+
case DiagnosticSeverity.Error:
|
|
58
|
+
return red(text);
|
|
59
|
+
case DiagnosticSeverity.Warning:
|
|
60
|
+
return yellow(text);
|
|
61
|
+
case DiagnosticSeverity.Hint:
|
|
62
|
+
return gray(text);
|
|
63
|
+
default:
|
|
64
|
+
return text;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getBackgroundForSeverity(diag, text) {
|
|
68
|
+
switch (diag.severity) {
|
|
69
|
+
case DiagnosticSeverity.Error:
|
|
70
|
+
return bgRed(white(text));
|
|
71
|
+
case DiagnosticSeverity.Warning:
|
|
72
|
+
return bgYellow(white(text));
|
|
73
|
+
case DiagnosticSeverity.Hint:
|
|
74
|
+
return bgWhite(black(text));
|
|
75
|
+
default:
|
|
76
|
+
return text;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function getPrintableLineNumber(line) {
|
|
80
|
+
return bgWhite(black(line.toString().padStart(2, "0")));
|
|
81
|
+
}
|
|
82
|
+
function getLine(line, text) {
|
|
83
|
+
return text.substring(offsetAt({ line, character: 0 }, text), offsetAt({ line, character: Number.MAX_SAFE_INTEGER }, text)).replace(/\t/g, " ").trimEnd();
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
printDiagnostic
|
|
87
|
+
};
|
package/dist/cli/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import preview from "../core/preview/index.js";
|
|
|
13
13
|
import { ASTRO_VERSION, createSafeError } from "../core/util.js";
|
|
14
14
|
import * as event from "../events/index.js";
|
|
15
15
|
import { eventConfigError, eventError, telemetry } from "../events/index.js";
|
|
16
|
-
import { check } from "./check.js";
|
|
16
|
+
import { check } from "./check/index.js";
|
|
17
17
|
import { openInBrowser } from "./open.js";
|
|
18
18
|
import * as telemetryHandler from "./telemetry.js";
|
|
19
19
|
function printAstroHelp() {
|
package/dist/core/dev/index.js
CHANGED
|
@@ -47,7 +47,7 @@ async function dev(config, options) {
|
|
|
47
47
|
site,
|
|
48
48
|
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
|
|
49
49
|
}));
|
|
50
|
-
const currentVersion = "1.0.0-beta.
|
|
50
|
+
const currentVersion = "1.0.0-beta.73";
|
|
51
51
|
if (currentVersion.includes("-")) {
|
|
52
52
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
53
53
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function devStart({
|
|
|
47
47
|
https,
|
|
48
48
|
site
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.0.0-beta.
|
|
50
|
+
const version = "1.0.0-beta.73";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -206,7 +206,7 @@ function printHelp({
|
|
|
206
206
|
};
|
|
207
207
|
let message = [];
|
|
208
208
|
if (headline) {
|
|
209
|
-
message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.
|
|
209
|
+
message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.73"}`)} ${headline}`);
|
|
210
210
|
}
|
|
211
211
|
if (usage) {
|
|
212
212
|
message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
|
|
@@ -1,48 +1,21 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { viteID } from "../../util.js";
|
|
3
3
|
import { STYLE_EXTENSIONS } from "../util.js";
|
|
4
|
-
|
|
4
|
+
import { crawlGraph } from "./vite.js";
|
|
5
5
|
async function getStylesForURL(filePath, viteServer, mode) {
|
|
6
|
+
var _a;
|
|
6
7
|
const importedCssUrls = /* @__PURE__ */ new Set();
|
|
7
8
|
const importedStylesMap = /* @__PURE__ */ new Map();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
continue;
|
|
9
|
+
for await (const importedModule of crawlGraph(viteServer, viteID(filePath), true)) {
|
|
10
|
+
const ext = path.extname(importedModule.url).toLowerCase();
|
|
11
|
+
if (STYLE_EXTENSIONS.has(ext)) {
|
|
12
|
+
if (mode === "development" && typeof ((_a = importedModule.ssrModule) == null ? void 0 : _a.default) === "string") {
|
|
13
|
+
importedStylesMap.set(importedModule.url, importedModule.ssrModule.default);
|
|
14
|
+
} else {
|
|
15
|
+
importedCssUrls.add(importedModule.url);
|
|
16
16
|
}
|
|
17
|
-
if (id === entry.id) {
|
|
18
|
-
scanned.add(id);
|
|
19
|
-
for (const importedModule of entry.importedModules) {
|
|
20
|
-
if (importedModule.id) {
|
|
21
|
-
const { pathname } = new URL(`file://${importedModule.id}`);
|
|
22
|
-
if (fileExtensionsToSSR.has(path.extname(pathname))) {
|
|
23
|
-
await viteServer.ssrLoadModule(importedModule.id);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
importedModules.add(importedModule);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (const importedModule of importedModules) {
|
|
31
|
-
if (!importedModule.id || scanned.has(importedModule.id)) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
const ext = path.extname(importedModule.url).toLowerCase();
|
|
35
|
-
if (STYLE_EXTENSIONS.has(ext)) {
|
|
36
|
-
if (mode === "development" && typeof ((_a = importedModule.ssrModule) == null ? void 0 : _a.default) === "string") {
|
|
37
|
-
importedStylesMap.set(importedModule.url, importedModule.ssrModule.default);
|
|
38
|
-
} else {
|
|
39
|
-
importedCssUrls.add(importedModule.url);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
await crawlCSS(importedModule.id, false, scanned);
|
|
43
17
|
}
|
|
44
18
|
}
|
|
45
|
-
await crawlCSS(viteID(filePath), true);
|
|
46
19
|
return {
|
|
47
20
|
urls: importedCssUrls,
|
|
48
21
|
stylesMap: importedStylesMap
|
|
@@ -2,10 +2,10 @@ import { fileURLToPath } from "url";
|
|
|
2
2
|
import { prependForwardSlash } from "../../../core/path.js";
|
|
3
3
|
import { isBuildingToSSR, isPage } from "../../util.js";
|
|
4
4
|
import { render as coreRender } from "../core.js";
|
|
5
|
-
import { createModuleScriptElementWithSrcSet } from "../ssr-element.js";
|
|
6
5
|
import { collectMdMetadata } from "../util.js";
|
|
7
6
|
import { getStylesForURL } from "./css.js";
|
|
8
7
|
import { resolveClientDevPath } from "./resolve.js";
|
|
8
|
+
import { getScriptsForURL } from "./scripts.js";
|
|
9
9
|
const svelteStylesRE = /svelte\?svelte&type=style/;
|
|
10
10
|
async function loadRenderer(viteServer, renderer) {
|
|
11
11
|
var _a;
|
|
@@ -45,7 +45,7 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
45
45
|
routeCache,
|
|
46
46
|
viteServer
|
|
47
47
|
} = ssrOpts;
|
|
48
|
-
const scripts =
|
|
48
|
+
const scripts = await getScriptsForURL(filePath, astroConfig, viteServer);
|
|
49
49
|
if (isPage(filePath, astroConfig) && mode === "development") {
|
|
50
50
|
scripts.add({
|
|
51
51
|
props: { type: "module", src: "/@vite/client" },
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import slash from "slash";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { viteID } from "../../util.js";
|
|
4
|
+
import { createModuleScriptElementWithSrc } from "../ssr-element.js";
|
|
5
|
+
import { crawlGraph } from "./vite.js";
|
|
6
|
+
async function getScriptsForURL(filePath, astroConfig, viteServer) {
|
|
7
|
+
const elements = /* @__PURE__ */ new Set();
|
|
8
|
+
const rootID = viteID(filePath);
|
|
9
|
+
let rootProjectFolder = slash(fileURLToPath(astroConfig.root));
|
|
10
|
+
const modInfo = viteServer.pluginContainer.getModuleInfo(rootID);
|
|
11
|
+
addHoistedScripts(elements, modInfo, rootProjectFolder);
|
|
12
|
+
for await (const moduleNode of crawlGraph(viteServer, rootID, true)) {
|
|
13
|
+
const id = moduleNode.id;
|
|
14
|
+
if (id) {
|
|
15
|
+
const info = viteServer.pluginContainer.getModuleInfo(id);
|
|
16
|
+
addHoistedScripts(elements, info, rootProjectFolder);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return elements;
|
|
20
|
+
}
|
|
21
|
+
function addHoistedScripts(set, info, rootProjectFolder) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (!((_a = info == null ? void 0 : info.meta) == null ? void 0 : _a.astro)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
let id = info.id;
|
|
27
|
+
const astro = (_b = info == null ? void 0 : info.meta) == null ? void 0 : _b.astro;
|
|
28
|
+
for (let i = 0; i < astro.scripts.length; i++) {
|
|
29
|
+
const scriptId = `${id}?astro&type=script&index=${i}&lang.ts`;
|
|
30
|
+
const element = createModuleScriptElementWithSrc(scriptId);
|
|
31
|
+
set.add(element);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
getScriptsForURL
|
|
36
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import npath from "path";
|
|
2
|
+
import { unwrapId } from "../../util.js";
|
|
3
|
+
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ".md"]);
|
|
4
|
+
async function* crawlGraph(viteServer, _id, isFile, scanned = /* @__PURE__ */ new Set()) {
|
|
5
|
+
const id = unwrapId(_id);
|
|
6
|
+
const importedModules = /* @__PURE__ */ new Set();
|
|
7
|
+
const moduleEntriesForId = isFile ? viteServer.moduleGraph.getModulesByFile(id) ?? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([viteServer.moduleGraph.getModuleById(id)]);
|
|
8
|
+
for (const entry of moduleEntriesForId) {
|
|
9
|
+
if (!entry) {
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (id === entry.id) {
|
|
13
|
+
scanned.add(id);
|
|
14
|
+
for (const importedModule of entry.importedModules) {
|
|
15
|
+
if (importedModule.id) {
|
|
16
|
+
const { pathname } = new URL(`file://${importedModule.id}`);
|
|
17
|
+
if (fileExtensionsToSSR.has(npath.extname(pathname))) {
|
|
18
|
+
const mod = viteServer.moduleGraph.getModuleById(importedModule.id);
|
|
19
|
+
if (!(mod == null ? void 0 : mod.ssrModule)) {
|
|
20
|
+
await viteServer.ssrLoadModule(importedModule.id);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
importedModules.add(importedModule);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
for (const importedModule of importedModules) {
|
|
29
|
+
if (!importedModule.id || scanned.has(importedModule.id)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
yield importedModule;
|
|
33
|
+
yield* crawlGraph(viteServer, importedModule.id, false, scanned);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
crawlGraph
|
|
38
|
+
};
|
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 { removeTrailingForwardSlash } from "./path.js";
|
|
8
|
-
const ASTRO_VERSION = "1.0.0-beta.
|
|
8
|
+
const ASTRO_VERSION = "1.0.0-beta.73";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
package/dist/jsx/babel.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { ClientOnlyPlaceholder } from "../runtime/server/index.js";
|
|
2
4
|
function isComponent(tagName) {
|
|
3
5
|
return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-zA-Z]/.test(tagName[0]);
|
|
4
6
|
}
|
|
@@ -10,6 +12,14 @@ function hasClientDirective(node) {
|
|
|
10
12
|
}
|
|
11
13
|
return false;
|
|
12
14
|
}
|
|
15
|
+
function isClientOnlyComponent(node) {
|
|
16
|
+
for (const attr of node.openingElement.attributes) {
|
|
17
|
+
if (attr.type === "JSXAttribute" && attr.name.type === "JSXNamespacedName") {
|
|
18
|
+
return jsxAttributeToString(attr) === "client:only";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
13
23
|
function getTagName(tag) {
|
|
14
24
|
const jsxName = tag.openingElement.name;
|
|
15
25
|
return jsxElementNameToString(jsxName);
|
|
@@ -32,10 +42,34 @@ function jsxAttributeToString(attr) {
|
|
|
32
42
|
function addClientMetadata(node, meta) {
|
|
33
43
|
const existingAttributes = node.openingElement.attributes.map((attr) => t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null);
|
|
34
44
|
if (!existingAttributes.find((attr) => attr === "client:component-path")) {
|
|
35
|
-
const componentPath = t.jsxAttribute(t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("component-path")),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
const componentPath = t.jsxAttribute(t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("component-path")), t.stringLiteral(meta.resolvedPath));
|
|
46
|
+
node.openingElement.attributes.push(componentPath);
|
|
47
|
+
}
|
|
48
|
+
if (!existingAttributes.find((attr) => attr === "client:component-export")) {
|
|
49
|
+
if (meta.name === "*") {
|
|
50
|
+
meta.name = getTagName(node).split(".").at(1);
|
|
51
|
+
}
|
|
52
|
+
const componentExport = t.jsxAttribute(t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("component-export")), t.stringLiteral(meta.name));
|
|
53
|
+
node.openingElement.attributes.push(componentExport);
|
|
54
|
+
}
|
|
55
|
+
if (!existingAttributes.find((attr) => attr === "client:component-hydration")) {
|
|
56
|
+
const staticMarker = t.jsxAttribute(t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("component-hydration")));
|
|
57
|
+
node.openingElement.attributes.push(staticMarker);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function addClientOnlyMetadata(node, meta) {
|
|
61
|
+
const tagName = getTagName(node);
|
|
62
|
+
node.openingElement = t.jsxOpeningElement(t.jsxIdentifier(ClientOnlyPlaceholder), node.openingElement.attributes);
|
|
63
|
+
if (node.closingElement) {
|
|
64
|
+
node.closingElement = t.jsxClosingElement(t.jsxIdentifier(ClientOnlyPlaceholder));
|
|
65
|
+
}
|
|
66
|
+
const existingAttributes = node.openingElement.attributes.map((attr) => t.isJSXAttribute(attr) ? jsxAttributeToString(attr) : null);
|
|
67
|
+
if (!existingAttributes.find((attr) => attr === "client:display-name")) {
|
|
68
|
+
const displayName = t.jsxAttribute(t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("display-name")), t.stringLiteral(tagName));
|
|
69
|
+
node.openingElement.attributes.push(displayName);
|
|
70
|
+
}
|
|
71
|
+
if (!existingAttributes.find((attr) => attr === "client:component-path")) {
|
|
72
|
+
const componentPath = t.jsxAttribute(t.jsxNamespacedName(t.jsxIdentifier("client"), t.jsxIdentifier("component-path")), t.stringLiteral(meta.resolvedPath));
|
|
39
73
|
node.openingElement.attributes.push(componentPath);
|
|
40
74
|
}
|
|
41
75
|
if (!existingAttributes.find((attr) => attr === "client:component-export")) {
|
|
@@ -53,8 +87,17 @@ function addClientMetadata(node, meta) {
|
|
|
53
87
|
function astroJSX() {
|
|
54
88
|
return {
|
|
55
89
|
visitor: {
|
|
56
|
-
Program
|
|
57
|
-
path
|
|
90
|
+
Program: {
|
|
91
|
+
enter(path, state) {
|
|
92
|
+
if (!state.file.metadata.astro) {
|
|
93
|
+
state.file.metadata.astro = {
|
|
94
|
+
clientOnlyComponents: [],
|
|
95
|
+
hydratedComponents: [],
|
|
96
|
+
scripts: []
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
path.node.body.splice(0, 0, t.importDeclaration([t.importSpecifier(t.identifier("Fragment"), t.identifier("Fragment"))], t.stringLiteral("astro/jsx-runtime")));
|
|
100
|
+
}
|
|
58
101
|
},
|
|
59
102
|
ImportDeclaration(path, state) {
|
|
60
103
|
const source = path.node.source.value;
|
|
@@ -92,8 +135,11 @@ function astroJSX() {
|
|
|
92
135
|
return;
|
|
93
136
|
if (!hasClientDirective(parentNode))
|
|
94
137
|
return;
|
|
138
|
+
const isClientOnly = isClientOnlyComponent(parentNode);
|
|
139
|
+
if (tagName === ClientOnlyPlaceholder)
|
|
140
|
+
return;
|
|
95
141
|
const imports = state.get("imports") ?? /* @__PURE__ */ new Map();
|
|
96
|
-
const namespace =
|
|
142
|
+
const namespace = tagName.split(".");
|
|
97
143
|
for (const [source, specs] of imports) {
|
|
98
144
|
for (const { imported, local } of specs) {
|
|
99
145
|
const reference = path.referencesImport(source, imported);
|
|
@@ -109,7 +155,33 @@ function astroJSX() {
|
|
|
109
155
|
}
|
|
110
156
|
const meta = path.getData("import");
|
|
111
157
|
if (meta) {
|
|
112
|
-
|
|
158
|
+
let resolvedPath;
|
|
159
|
+
if (meta.path.startsWith(".")) {
|
|
160
|
+
const fileURL = pathToFileURL(state.filename);
|
|
161
|
+
resolvedPath = `/@fs${new URL(meta.path, fileURL).pathname}`;
|
|
162
|
+
if (resolvedPath.endsWith(".jsx")) {
|
|
163
|
+
resolvedPath = resolvedPath.slice(0, -4);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
resolvedPath = meta.path;
|
|
167
|
+
}
|
|
168
|
+
if (isClientOnly) {
|
|
169
|
+
state.file.metadata.astro.clientOnlyComponents.push({
|
|
170
|
+
exportName: meta.name,
|
|
171
|
+
specifier: meta.name,
|
|
172
|
+
resolvedPath
|
|
173
|
+
});
|
|
174
|
+
meta.resolvedPath = resolvedPath;
|
|
175
|
+
addClientOnlyMetadata(parentNode, meta);
|
|
176
|
+
} else {
|
|
177
|
+
state.file.metadata.astro.hydratedComponents.push({
|
|
178
|
+
exportName: meta.name,
|
|
179
|
+
specifier: meta.name,
|
|
180
|
+
resolvedPath
|
|
181
|
+
});
|
|
182
|
+
meta.resolvedPath = resolvedPath;
|
|
183
|
+
addClientMetadata(parentNode, meta);
|
|
184
|
+
}
|
|
113
185
|
} else {
|
|
114
186
|
throw new Error(`Unable to match <${getTagName(parentNode)}> with client:* directive to an import statement!`);
|
|
115
187
|
}
|
package/dist/jsx/server.js
CHANGED
|
@@ -23,11 +23,8 @@ async function renderToStaticMarkup(Component, props = {}, { default: children =
|
|
|
23
23
|
slots[name] = value;
|
|
24
24
|
}
|
|
25
25
|
const { result } = this;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return { html };
|
|
29
|
-
} catch (e) {
|
|
30
|
-
}
|
|
26
|
+
const html = await renderJSX(result, jsx(Component, { ...props, ...slots, children }));
|
|
27
|
+
return { html };
|
|
31
28
|
}
|
|
32
29
|
var server_default = {
|
|
33
30
|
check,
|
|
@@ -93,7 +93,8 @@ function mergeSlots(...slotted) {
|
|
|
93
93
|
}
|
|
94
94
|
return slots;
|
|
95
95
|
}
|
|
96
|
-
const Fragment = Symbol("
|
|
96
|
+
const Fragment = Symbol.for("astro:fragment");
|
|
97
|
+
const ClientOnlyPlaceholder = "astro-client-only";
|
|
97
98
|
function guessRenderers(componentUrl) {
|
|
98
99
|
const extname = componentUrl == null ? void 0 : componentUrl.split(".").pop();
|
|
99
100
|
switch (extname) {
|
|
@@ -546,7 +547,7 @@ function renderHead(result) {
|
|
|
546
547
|
const styles = Array.from(result.styles).filter(uniqueElements).map((style) => renderElement("style", style));
|
|
547
548
|
result.styles.clear();
|
|
548
549
|
const scripts = Array.from(result.scripts).filter(uniqueElements).map((script, i) => {
|
|
549
|
-
return renderElement("script", script);
|
|
550
|
+
return renderElement("script", script, false);
|
|
550
551
|
});
|
|
551
552
|
const links = Array.from(result.links).filter(uniqueElements).map((link) => renderElement("link", link, false));
|
|
552
553
|
return markHTMLString(links.join("\n") + styles.join("\n") + scripts.join("\n"));
|
|
@@ -608,6 +609,7 @@ function renderElement(name, { props: _props, children = "" }, shouldEscape = tr
|
|
|
608
609
|
}
|
|
609
610
|
export {
|
|
610
611
|
AstroComponent,
|
|
612
|
+
ClientOnlyPlaceholder,
|
|
611
613
|
Fragment,
|
|
612
614
|
HTMLString2 as HTMLString,
|
|
613
615
|
addAttribute,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AstroJSX, isVNode } from "../../jsx-runtime/index.js";
|
|
2
2
|
import {
|
|
3
|
+
ClientOnlyPlaceholder,
|
|
3
4
|
escapeHTML,
|
|
4
|
-
Fragment,
|
|
5
5
|
HTMLString,
|
|
6
6
|
markHTMLString,
|
|
7
7
|
renderComponent,
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
spreadAttributes,
|
|
10
10
|
voidElementNames
|
|
11
11
|
} from "./index.js";
|
|
12
|
+
const skipAstroJSXCheck = /* @__PURE__ */ new WeakSet();
|
|
13
|
+
let originalConsoleError;
|
|
14
|
+
let consoleFilterRefs = 0;
|
|
12
15
|
async function renderJSX(result, vnode) {
|
|
13
16
|
switch (true) {
|
|
14
17
|
case vnode instanceof HTMLString:
|
|
@@ -17,30 +20,31 @@ async function renderJSX(result, vnode) {
|
|
|
17
20
|
return markHTMLString(escapeHTML(vnode));
|
|
18
21
|
case (!vnode && vnode !== 0):
|
|
19
22
|
return "";
|
|
20
|
-
case vnode.type === Fragment:
|
|
21
|
-
return renderJSX(result, vnode.props.children);
|
|
22
23
|
case Array.isArray(vnode):
|
|
23
24
|
return markHTMLString((await Promise.all(vnode.map((v) => renderJSX(result, v)))).join(""));
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
}
|
|
26
|
+
if (isVNode(vnode)) {
|
|
27
|
+
switch (true) {
|
|
28
|
+
case vnode.type === Symbol.for("astro:fragment"):
|
|
29
|
+
return renderJSX(result, vnode.props.children);
|
|
30
|
+
case vnode.type.isAstroComponentFactory: {
|
|
31
|
+
let props = {};
|
|
32
|
+
let slots = {};
|
|
33
|
+
for (const [key, value] of Object.entries(vnode.props ?? {})) {
|
|
34
|
+
if (key === "children" || value && typeof value === "object" && value["$$slot"]) {
|
|
35
|
+
slots[key === "children" ? "default" : key] = () => renderJSX(result, value);
|
|
36
|
+
} else {
|
|
37
|
+
props[key] = value;
|
|
38
|
+
}
|
|
32
39
|
}
|
|
40
|
+
return await renderToString(result, vnode.type, props, slots);
|
|
33
41
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (!vnode.type && vnode.type !== 0)
|
|
39
|
-
return "";
|
|
40
|
-
if (typeof vnode.type === "string") {
|
|
41
|
-
return await renderElement(result, vnode.type, vnode.props ?? {});
|
|
42
|
+
case (!vnode.type && vnode.type !== 0):
|
|
43
|
+
return "";
|
|
44
|
+
case (typeof vnode.type === "string" && vnode.type !== ClientOnlyPlaceholder):
|
|
45
|
+
return await renderElement(result, vnode.type, vnode.props ?? {});
|
|
42
46
|
}
|
|
43
|
-
if (
|
|
47
|
+
if (vnode.type) {
|
|
44
48
|
let extractSlots2 = function(child) {
|
|
45
49
|
if (Array.isArray(child)) {
|
|
46
50
|
return child.map((c) => extractSlots2(c));
|
|
@@ -56,14 +60,24 @@ async function renderJSX(result, vnode) {
|
|
|
56
60
|
slots.default.push(child);
|
|
57
61
|
};
|
|
58
62
|
var extractSlots = extractSlots2;
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if (typeof vnode.type === "function" && vnode.props["server:root"]) {
|
|
64
|
+
const output2 = await vnode.type(vnode.props ?? {});
|
|
65
|
+
return await renderJSX(result, output2);
|
|
66
|
+
}
|
|
67
|
+
if (typeof vnode.type === "function" && !skipAstroJSXCheck.has(vnode.type)) {
|
|
68
|
+
useConsoleFilter();
|
|
69
|
+
try {
|
|
70
|
+
const output2 = await vnode.type(vnode.props ?? {});
|
|
71
|
+
if (output2 && output2[AstroJSX]) {
|
|
72
|
+
return await renderJSX(result, output2);
|
|
73
|
+
} else if (!output2) {
|
|
74
|
+
return await renderJSX(result, output2);
|
|
75
|
+
}
|
|
76
|
+
} catch (e) {
|
|
77
|
+
skipAstroJSXCheck.add(vnode.type);
|
|
78
|
+
} finally {
|
|
79
|
+
finishUsingConsoleFilter();
|
|
65
80
|
}
|
|
66
|
-
} catch (e) {
|
|
67
81
|
}
|
|
68
82
|
const { children = null, ...props } = vnode.props ?? {};
|
|
69
83
|
const slots = {
|
|
@@ -73,7 +87,13 @@ async function renderJSX(result, vnode) {
|
|
|
73
87
|
for (const [key, value] of Object.entries(slots)) {
|
|
74
88
|
slots[key] = () => renderJSX(result, value);
|
|
75
89
|
}
|
|
76
|
-
|
|
90
|
+
let output;
|
|
91
|
+
if (vnode.type === ClientOnlyPlaceholder && vnode.props["client:only"]) {
|
|
92
|
+
output = await renderComponent(result, vnode.props["client:display-name"] ?? "", null, props, slots);
|
|
93
|
+
} else {
|
|
94
|
+
output = await renderComponent(result, typeof vnode.type === "function" ? vnode.type.name : vnode.type, vnode.type, props, slots);
|
|
95
|
+
}
|
|
96
|
+
return markHTMLString(output);
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
99
|
return markHTMLString(`${vnode}`);
|
|
@@ -81,6 +101,26 @@ async function renderJSX(result, vnode) {
|
|
|
81
101
|
async function renderElement(result, tag, { children, ...props }) {
|
|
82
102
|
return markHTMLString(`<${tag}${spreadAttributes(props)}${markHTMLString((children == null || children == "") && voidElementNames.test(tag) ? `/>` : `>${children == null ? "" : await renderJSX(result, children)}</${tag}>`)}`);
|
|
83
103
|
}
|
|
104
|
+
function useConsoleFilter() {
|
|
105
|
+
consoleFilterRefs++;
|
|
106
|
+
if (!originalConsoleError) {
|
|
107
|
+
originalConsoleError = console.error;
|
|
108
|
+
try {
|
|
109
|
+
console.error = filteredConsoleError;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function finishUsingConsoleFilter() {
|
|
115
|
+
consoleFilterRefs--;
|
|
116
|
+
}
|
|
117
|
+
function filteredConsoleError(msg, ...rest) {
|
|
118
|
+
if (consoleFilterRefs > 0 && typeof msg === "string") {
|
|
119
|
+
const isKnownReactHookError = msg.includes("Warning: Invalid hook call.") && msg.includes("https://reactjs.org/link/invalid-hook-call");
|
|
120
|
+
if (isKnownReactHookError)
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
84
124
|
export {
|
|
85
125
|
renderJSX
|
|
86
126
|
};
|
|
@@ -26,30 +26,6 @@ class Metadata {
|
|
|
26
26
|
const metadata = this.getComponentMetadata(Component);
|
|
27
27
|
return (metadata == null ? void 0 : metadata.componentExport) || null;
|
|
28
28
|
}
|
|
29
|
-
*hoistedScriptPaths() {
|
|
30
|
-
for (const metadata of this.deepMetadata()) {
|
|
31
|
-
let i = 0, pathname = metadata.mockURL.pathname;
|
|
32
|
-
while (i < metadata.hoisted.length) {
|
|
33
|
-
yield `${pathname.replace("/@fs", "")}?astro&type=script&index=${i}&lang.ts`;
|
|
34
|
-
i++;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
*deepMetadata() {
|
|
39
|
-
yield this;
|
|
40
|
-
const seen = /* @__PURE__ */ new Set();
|
|
41
|
-
for (const { module: mod } of this.modules) {
|
|
42
|
-
if (typeof mod.$$metadata !== "undefined") {
|
|
43
|
-
const md = mod.$$metadata;
|
|
44
|
-
for (const childMetdata of md.deepMetadata()) {
|
|
45
|
-
if (!seen.has(childMetdata)) {
|
|
46
|
-
seen.add(childMetdata);
|
|
47
|
-
yield childMetdata;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
29
|
getComponentMetadata(Component) {
|
|
54
30
|
if (this.metadataCache.has(Component)) {
|
|
55
31
|
return this.metadataCache.get(Component);
|
|
@@ -26,10 +26,10 @@ function convertToSerializedForm(value) {
|
|
|
26
26
|
return [PROP_TYPE.RegExp, value.source];
|
|
27
27
|
}
|
|
28
28
|
case "[object Map]": {
|
|
29
|
-
return [PROP_TYPE.Map, Array.from(value)];
|
|
29
|
+
return [PROP_TYPE.Map, JSON.stringify(serializeArray(Array.from(value)))];
|
|
30
30
|
}
|
|
31
31
|
case "[object Set]": {
|
|
32
|
-
return [PROP_TYPE.Set, Array.from(value)];
|
|
32
|
+
return [PROP_TYPE.Set, JSON.stringify(serializeArray(Array.from(value)))];
|
|
33
33
|
}
|
|
34
34
|
case "[object BigInt]": {
|
|
35
35
|
return [PROP_TYPE.BigInt, value.toString()];
|
|
@@ -10,7 +10,6 @@ import type { AstroConfigSchema } from '../core/config';
|
|
|
10
10
|
import type { ViteConfigWithSSR } from '../core/create-vite';
|
|
11
11
|
import type { AstroComponentFactory, Metadata } from '../runtime/server';
|
|
12
12
|
export type { SSRManifest } from '../core/app/types';
|
|
13
|
-
export type { AstroComponentFactory } from '../runtime/server';
|
|
14
13
|
export interface AstroBuiltinProps {
|
|
15
14
|
'client:load'?: boolean;
|
|
16
15
|
'client:idle'?: boolean;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import vite from 'vite';
|
|
2
|
+
/** recursively crawl the module graph to get all style files imported by parent id */
|
|
3
|
+
export declare function crawlGraph(viteServer: vite.ViteDevServer, _id: string, isFile: boolean, scanned?: Set<string>): AsyncGenerator<vite.ModuleNode, void, unknown>;
|
|
@@ -5,7 +5,7 @@ export declare function renderToStaticMarkup(this: any, Component: any, props?:
|
|
|
5
5
|
default?: null | undefined;
|
|
6
6
|
}): Promise<{
|
|
7
7
|
html: any;
|
|
8
|
-
}
|
|
8
|
+
}>;
|
|
9
9
|
declare const _default: {
|
|
10
10
|
check: typeof check;
|
|
11
11
|
renderToStaticMarkup: typeof renderToStaticMarkup;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Fragment } from '../runtime/server/index.js';
|
|
2
2
|
declare const AstroJSX = "astro:jsx";
|
|
3
|
-
interface AstroVNode {
|
|
3
|
+
export interface AstroVNode {
|
|
4
4
|
[AstroJSX]: boolean;
|
|
5
|
-
type: string | ((...args: any) => any)
|
|
5
|
+
type: string | ((...args: any) => any);
|
|
6
6
|
props: Record<string, any>;
|
|
7
7
|
}
|
|
8
8
|
export declare function isVNode(vnode: any): vnode is AstroVNode;
|
|
@@ -19,6 +19,7 @@ export declare function createComponent(cb: AstroComponentFactory): AstroCompone
|
|
|
19
19
|
export declare function renderSlot(_result: any, slotted: string, fallback?: any): Promise<string>;
|
|
20
20
|
export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
|
|
21
21
|
export declare const Fragment: unique symbol;
|
|
22
|
+
export declare const ClientOnlyPlaceholder = "astro-client-only";
|
|
22
23
|
export declare function renderComponent(result: SSRResult, displayName: string, Component: unknown, _props: Record<string | number, any>, slots?: any): Promise<string | AsyncIterable<string>>;
|
|
23
24
|
export declare function createAstro(filePathname: string, _site: string, projectRootStr: string): AstroGlobalPartial;
|
|
24
25
|
export declare function addAttribute(value: any, key: string, shouldEscape?: boolean): any;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { SSRResult } from '../../@types/astro.js';
|
|
2
|
+
export declare function renderJSX(result: SSRResult, vnode: any): Promise<any>;
|
|
@@ -21,8 +21,6 @@ export declare class Metadata {
|
|
|
21
21
|
resolvePath(specifier: string): string;
|
|
22
22
|
getPath(Component: any): string | null;
|
|
23
23
|
getExport(Component: any): string | null;
|
|
24
|
-
hoistedScriptPaths(): Generator<string, void, unknown>;
|
|
25
|
-
private deepMetadata;
|
|
26
24
|
private getComponentMetadata;
|
|
27
25
|
private findComponentMetadata;
|
|
28
26
|
}
|
|
@@ -58,6 +58,7 @@ function envVitePlugin({
|
|
|
58
58
|
if (privateEnv) {
|
|
59
59
|
privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : "undefined";
|
|
60
60
|
privateEnv.SSR = JSON.stringify(true);
|
|
61
|
+
privateEnv.BASE_URL = astroConfig.base ? `'${astroConfig.base}'` : void 0;
|
|
61
62
|
const entries = Object.entries(privateEnv).map(([key, value]) => [
|
|
62
63
|
`import.meta.env.${key}`,
|
|
63
64
|
value
|
|
@@ -66,6 +67,7 @@ function envVitePlugin({
|
|
|
66
67
|
replacements = Object.assign(replacements, {
|
|
67
68
|
"import.meta.env.SITE": astroConfig.site ? `'${astroConfig.site}'` : "undefined",
|
|
68
69
|
"import.meta.env.SSR": JSON.stringify(true),
|
|
70
|
+
"import.meta.env.BASE_URL": astroConfig.base ? `'${astroConfig.base}'` : void 0,
|
|
69
71
|
"import.meta.env": `({})`
|
|
70
72
|
});
|
|
71
73
|
pattern = new RegExp("(?<!(?<!\\.\\.)\\.)\\b(" + Object.keys(replacements).map((str) => {
|
|
@@ -47,6 +47,19 @@ async function transformJSX({
|
|
|
47
47
|
});
|
|
48
48
|
if (!result)
|
|
49
49
|
return null;
|
|
50
|
+
if (renderer.name === "astro:jsx") {
|
|
51
|
+
const { astro } = result.metadata;
|
|
52
|
+
return {
|
|
53
|
+
code: result.code || "",
|
|
54
|
+
map: result.map,
|
|
55
|
+
meta: {
|
|
56
|
+
astro,
|
|
57
|
+
vite: {
|
|
58
|
+
lang: "ts"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
50
63
|
return {
|
|
51
64
|
code: result.code || "",
|
|
52
65
|
map: result.map
|
|
@@ -83,7 +83,7 @@ function markdown({ config }) {
|
|
|
83
83
|
export function $$loadMetadata() {
|
|
84
84
|
return load().then((m) => m.$$metadata);
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
// Deferred
|
|
88
88
|
export default async function load() {
|
|
89
89
|
return (await import(${JSON.stringify(fileId + MARKDOWN_CONTENT_FLAG)}));
|
|
@@ -116,6 +116,8 @@ function markdown({ config }) {
|
|
|
116
116
|
let { code: astroResult, metadata } = renderResult;
|
|
117
117
|
const { layout = "", components = "", setup = "", ...content } = frontmatter;
|
|
118
118
|
content.astro = metadata;
|
|
119
|
+
content.url = getFileInfo(id, config).fileUrl;
|
|
120
|
+
content.file = filename;
|
|
119
121
|
const prelude = `---
|
|
120
122
|
import Slugger from 'github-slugger';
|
|
121
123
|
${layout ? `import Layout from '${layout}';` : ""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.73",
|
|
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",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
],
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@astrojs/compiler": "^0.19.0",
|
|
74
|
-
"@astrojs/language-server": "^0.
|
|
75
|
-
"@astrojs/markdown-remark": "^0.
|
|
76
|
-
"@astrojs/prism": "0.6.
|
|
77
|
-
"@astrojs/telemetry": "^0.4.
|
|
74
|
+
"@astrojs/language-server": "^0.20.0",
|
|
75
|
+
"@astrojs/markdown-remark": "^0.12.0",
|
|
76
|
+
"@astrojs/prism": "0.6.1",
|
|
77
|
+
"@astrojs/telemetry": "^0.4.1",
|
|
78
78
|
"@astrojs/webapi": "^0.12.0",
|
|
79
79
|
"@babel/core": "^7.18.2",
|
|
80
80
|
"@babel/generator": "^7.18.2",
|
|
@@ -158,7 +158,7 @@
|
|
|
158
158
|
"srcset-parse": "^1.1.0"
|
|
159
159
|
},
|
|
160
160
|
"engines": {
|
|
161
|
-
"node": "^14.
|
|
161
|
+
"node": "^14.18.0 || >=16.12.0",
|
|
162
162
|
"npm": ">=6.14.0"
|
|
163
163
|
},
|
|
164
164
|
"scripts": {
|
package/dist/cli/check.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { AstroCheck, DiagnosticSeverity } from "@astrojs/language-server";
|
|
2
|
-
import glob from "fast-glob";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { bgWhite, black, bold, cyan, red, yellow } from "kleur/colors";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { pathToFileURL } from "url";
|
|
7
|
-
async function openAllDocuments(workspaceUri, filePathsToIgnore, checker) {
|
|
8
|
-
const files = await glob("**/*.astro", {
|
|
9
|
-
cwd: workspaceUri.pathname,
|
|
10
|
-
ignore: ["node_modules/**"].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`))
|
|
11
|
-
});
|
|
12
|
-
const absFilePaths = files.map((f) => path.resolve(workspaceUri.pathname, f));
|
|
13
|
-
for (const absFilePath of absFilePaths) {
|
|
14
|
-
const text = fs.readFileSync(absFilePath, "utf-8");
|
|
15
|
-
checker.upsertDocument({
|
|
16
|
-
uri: pathToFileURL(absFilePath).toString(),
|
|
17
|
-
text
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function offsetAt({ line, character }, text) {
|
|
22
|
-
let i = 0;
|
|
23
|
-
let l = 0;
|
|
24
|
-
let c = 0;
|
|
25
|
-
while (i < text.length) {
|
|
26
|
-
if (l === line && c === character) {
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
let char = text[i];
|
|
30
|
-
switch (char) {
|
|
31
|
-
case "\n": {
|
|
32
|
-
l++;
|
|
33
|
-
c = 0;
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
default: {
|
|
37
|
-
c++;
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
i++;
|
|
42
|
-
}
|
|
43
|
-
return i;
|
|
44
|
-
}
|
|
45
|
-
function generateString(str, len) {
|
|
46
|
-
return Array.from({ length: len }, () => str).join("");
|
|
47
|
-
}
|
|
48
|
-
async function run() {
|
|
49
|
-
}
|
|
50
|
-
async function check(astroConfig) {
|
|
51
|
-
const root = astroConfig.root;
|
|
52
|
-
let checker = new AstroCheck(root.toString());
|
|
53
|
-
await openAllDocuments(root, [], checker);
|
|
54
|
-
let diagnostics = await checker.getDiagnostics();
|
|
55
|
-
let result = {
|
|
56
|
-
errors: 0,
|
|
57
|
-
warnings: 0
|
|
58
|
-
};
|
|
59
|
-
diagnostics.forEach((diag) => {
|
|
60
|
-
diag.diagnostics.forEach((d) => {
|
|
61
|
-
switch (d.severity) {
|
|
62
|
-
case DiagnosticSeverity.Error: {
|
|
63
|
-
console.error(`${bold(cyan(path.relative(root.pathname, diag.filePath)))}:${bold(yellow(d.range.start.line))}:${bold(yellow(d.range.start.character))} - ${d.message}`);
|
|
64
|
-
let startOffset = offsetAt({ line: d.range.start.line, character: 0 }, diag.text);
|
|
65
|
-
let endOffset = offsetAt({ line: d.range.start.line + 1, character: 0 }, diag.text);
|
|
66
|
-
let str = diag.text.substring(startOffset, endOffset - 1);
|
|
67
|
-
const lineNumStr = d.range.start.line.toString();
|
|
68
|
-
const lineNumLen = lineNumStr.length;
|
|
69
|
-
console.error(`${bgWhite(black(lineNumStr))} ${str}`);
|
|
70
|
-
let tildes = generateString("~", d.range.end.character - d.range.start.character);
|
|
71
|
-
let spaces = generateString(" ", d.range.start.character + lineNumLen - 1);
|
|
72
|
-
console.error(` ${spaces}${bold(red(tildes))}
|
|
73
|
-
`);
|
|
74
|
-
result.errors++;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
case DiagnosticSeverity.Warning: {
|
|
78
|
-
result.warnings++;
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
if (result.errors) {
|
|
85
|
-
console.error(`Found ${result.errors} errors.`);
|
|
86
|
-
}
|
|
87
|
-
const exitCode = result.errors ? 1 : 0;
|
|
88
|
-
return exitCode;
|
|
89
|
-
}
|
|
90
|
-
export {
|
|
91
|
-
check,
|
|
92
|
-
run
|
|
93
|
-
};
|