astro 1.6.4 → 1.6.5
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/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/result.js +5 -6
- package/dist/runtime/server/render/common.d.ts +2 -1
- package/dist/runtime/server/render/common.js +12 -0
- package/dist/runtime/server/render/slot.d.ts +3 -0
- package/dist/runtime/server/render/slot.js +7 -0
- package/dist/vite-plugin-env/index.js +40 -64
- package/package.json +1 -1
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -30,7 +30,7 @@ async function dev(settings, options) {
|
|
|
30
30
|
isRestart: options.isRestart
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
|
-
const currentVersion = "1.6.
|
|
33
|
+
const currentVersion = "1.6.5";
|
|
34
34
|
if (currentVersion.includes("-")) {
|
|
35
35
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
36
36
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.6.
|
|
50
|
+
const version = "1.6.5";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -255,7 +255,7 @@ function printHelp({
|
|
|
255
255
|
message.push(
|
|
256
256
|
linebreak(),
|
|
257
257
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
258
|
-
`v${"1.6.
|
|
258
|
+
`v${"1.6.5"}`
|
|
259
259
|
)} ${headline}`
|
|
260
260
|
);
|
|
261
261
|
}
|
|
@@ -18,7 +18,7 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
18
18
|
};
|
|
19
19
|
var _cache, _result, _slots, _loggingOpts;
|
|
20
20
|
import { bold } from "kleur/colors";
|
|
21
|
-
import { renderSlot } from "../../runtime/server/index.js";
|
|
21
|
+
import { renderSlot, stringifyChunk } from "../../runtime/server/index.js";
|
|
22
22
|
import { renderJSX } from "../../runtime/server/jsx.js";
|
|
23
23
|
import { AstroCookies } from "../cookies/index.js";
|
|
24
24
|
import { warn } from "../logger/core.js";
|
|
@@ -102,12 +102,11 @@ Please update the name of this slot.`
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
const content = await renderSlot(__privateGet(this, _result), __privateGet(this, _slots)[name])
|
|
106
|
-
|
|
107
|
-
);
|
|
105
|
+
const content = await renderSlot(__privateGet(this, _result), __privateGet(this, _slots)[name]);
|
|
106
|
+
const outHTML = stringifyChunk(__privateGet(this, _result), content);
|
|
108
107
|
if (cacheable)
|
|
109
|
-
__privateGet(this, _cache).set(name,
|
|
110
|
-
return
|
|
108
|
+
__privateGet(this, _cache).set(name, outHTML);
|
|
109
|
+
return outHTML;
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
112
|
_cache = new WeakMap();
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SSRResult } from '../../../@types/astro';
|
|
2
2
|
import type { RenderInstruction } from './types.js';
|
|
3
3
|
import { HTMLBytes } from '../escape.js';
|
|
4
|
+
import { type SlotString } from './slot.js';
|
|
4
5
|
export declare const Fragment: unique symbol;
|
|
5
6
|
export declare const Renderer: unique symbol;
|
|
6
7
|
export declare const encoder: TextEncoder;
|
|
7
8
|
export declare const decoder: TextDecoder;
|
|
8
|
-
export declare function stringifyChunk(result: SSRResult, chunk: string | RenderInstruction): any;
|
|
9
|
+
export declare function stringifyChunk(result: SSRResult, chunk: string | SlotString | RenderInstruction): any;
|
|
9
10
|
export declare class HTMLParts {
|
|
10
11
|
parts: string;
|
|
11
12
|
constructor();
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
determinesIfNeedsDirectiveScript,
|
|
5
5
|
getPrescripts
|
|
6
6
|
} from "../scripts.js";
|
|
7
|
+
import { isSlotString } from "./slot.js";
|
|
7
8
|
const Fragment = Symbol.for("astro:fragment");
|
|
8
9
|
const Renderer = Symbol.for("astro:renderer");
|
|
9
10
|
const encoder = new TextEncoder();
|
|
@@ -23,6 +24,17 @@ function stringifyChunk(result, chunk) {
|
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
default: {
|
|
27
|
+
if (isSlotString(chunk)) {
|
|
28
|
+
let out = "";
|
|
29
|
+
const c = chunk;
|
|
30
|
+
if (c.instructions) {
|
|
31
|
+
for (const instr of c.instructions) {
|
|
32
|
+
out += stringifyChunk(result, instr);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
out += chunk.toString();
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
26
38
|
return chunk.toString();
|
|
27
39
|
}
|
|
28
40
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { SSRResult } from '../../../@types/astro.js';
|
|
2
2
|
import type { RenderInstruction } from './types.js';
|
|
3
3
|
import { HTMLString } from '../escape.js';
|
|
4
|
+
declare const slotString: unique symbol;
|
|
4
5
|
export declare class SlotString extends HTMLString {
|
|
5
6
|
instructions: null | RenderInstruction[];
|
|
7
|
+
[slotString]: boolean;
|
|
6
8
|
constructor(content: string, instructions: null | RenderInstruction[]);
|
|
7
9
|
}
|
|
10
|
+
export declare function isSlotString(str: string): str is any;
|
|
8
11
|
export declare function renderSlot(_result: any, slotted: string, fallback?: any): Promise<string>;
|
|
9
12
|
interface RenderSlotsResult {
|
|
10
13
|
slotInstructions: null | RenderInstruction[];
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { HTMLString, markHTMLString } from "../escape.js";
|
|
2
2
|
import { renderChild } from "./any.js";
|
|
3
|
+
const slotString = Symbol.for("astro:slot-string");
|
|
3
4
|
class SlotString extends HTMLString {
|
|
4
5
|
constructor(content, instructions) {
|
|
5
6
|
super(content);
|
|
6
7
|
this.instructions = instructions;
|
|
8
|
+
this[slotString] = true;
|
|
7
9
|
}
|
|
8
10
|
}
|
|
11
|
+
slotString;
|
|
12
|
+
function isSlotString(str) {
|
|
13
|
+
return !!str[slotString];
|
|
14
|
+
}
|
|
9
15
|
async function renderSlot(_result, slotted, fallback) {
|
|
10
16
|
if (slotted) {
|
|
11
17
|
let iterator = renderChild(slotted);
|
|
@@ -47,6 +53,7 @@ async function renderSlots(result, slots = {}) {
|
|
|
47
53
|
}
|
|
48
54
|
export {
|
|
49
55
|
SlotString,
|
|
56
|
+
isSlotString,
|
|
50
57
|
renderSlot,
|
|
51
58
|
renderSlots
|
|
52
59
|
};
|
|
@@ -11,27 +11,24 @@ function getPrivateEnv(viteConfig, astroConfig) {
|
|
|
11
11
|
viteConfig.envDir ?? fileURLToPath(astroConfig.root),
|
|
12
12
|
""
|
|
13
13
|
);
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const privateEnv = {};
|
|
15
|
+
for (const key in fullEnv) {
|
|
16
|
+
if (envPrefixes.every((prefix) => !key.startsWith(prefix))) {
|
|
17
|
+
if (typeof process.env[key] !== "undefined") {
|
|
18
|
+
privateEnv[key] = `process.env.${key}`;
|
|
19
|
+
} else {
|
|
20
|
+
privateEnv[key] = JSON.stringify(fullEnv[key]);
|
|
21
|
+
}
|
|
18
22
|
}
|
|
19
|
-
return true;
|
|
20
|
-
});
|
|
21
|
-
if (privateKeys.length === 0) {
|
|
22
|
-
return null;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return [key, JSON.stringify(fullEnv[key])];
|
|
29
|
-
})
|
|
30
|
-
);
|
|
24
|
+
privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : "undefined";
|
|
25
|
+
privateEnv.SSR = JSON.stringify(true);
|
|
26
|
+
privateEnv.BASE_URL = astroConfig.base ? `'${astroConfig.base}'` : "undefined";
|
|
27
|
+
return privateEnv;
|
|
31
28
|
}
|
|
32
29
|
function getReferencedPrivateKeys(source, privateEnv) {
|
|
33
30
|
const references = /* @__PURE__ */ new Set();
|
|
34
|
-
for (const key
|
|
31
|
+
for (const key in privateEnv) {
|
|
35
32
|
if (source.includes(key)) {
|
|
36
33
|
references.add(key);
|
|
37
34
|
}
|
|
@@ -40,73 +37,52 @@ function getReferencedPrivateKeys(source, privateEnv) {
|
|
|
40
37
|
}
|
|
41
38
|
function envVitePlugin({ settings }) {
|
|
42
39
|
let privateEnv;
|
|
43
|
-
let
|
|
44
|
-
let replacements;
|
|
45
|
-
let pattern;
|
|
40
|
+
let viteConfig;
|
|
46
41
|
const { config: astroConfig } = settings;
|
|
47
42
|
return {
|
|
48
43
|
name: "astro:vite-plugin-env",
|
|
49
44
|
enforce: "pre",
|
|
50
45
|
configResolved(resolvedConfig) {
|
|
51
|
-
|
|
46
|
+
viteConfig = resolvedConfig;
|
|
52
47
|
},
|
|
53
48
|
async transform(source, id, options) {
|
|
54
|
-
|
|
55
|
-
if (!ssr) {
|
|
49
|
+
if (!(options == null ? void 0 : options.ssr) || !source.includes("import.meta.env")) {
|
|
56
50
|
return;
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : "undefined";
|
|
65
|
-
privateEnv.SSR = JSON.stringify(true);
|
|
66
|
-
privateEnv.BASE_URL = astroConfig.base ? `'${astroConfig.base}'` : void 0;
|
|
67
|
-
const entries = Object.entries(privateEnv).map(([key, value]) => [
|
|
68
|
-
`import.meta.env.${key}`,
|
|
69
|
-
value
|
|
70
|
-
]);
|
|
71
|
-
replacements = Object.fromEntries(entries);
|
|
72
|
-
replacements = Object.assign(replacements, {
|
|
73
|
-
"import.meta.env.SITE": astroConfig.site ? `'${astroConfig.site}'` : "undefined",
|
|
74
|
-
"import.meta.env.SSR": JSON.stringify(true),
|
|
75
|
-
"import.meta.env.BASE_URL": astroConfig.base ? `'${astroConfig.base}'` : void 0,
|
|
76
|
-
"import.meta.env": `({})`
|
|
77
|
-
});
|
|
78
|
-
pattern = new RegExp(
|
|
79
|
-
"(?<!(?<!\\.\\.)\\.)\\b(" + Object.keys(replacements).map((str) => {
|
|
80
|
-
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&");
|
|
81
|
-
}).join("|") + ")\\b(?!\\s*?=[^=])",
|
|
82
|
-
"g"
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (!privateEnv || !pattern)
|
|
87
|
-
return;
|
|
88
|
-
const references = getReferencedPrivateKeys(source, privateEnv);
|
|
89
|
-
if (references.size === 0)
|
|
90
|
-
return;
|
|
91
|
-
const s = new MagicString(source);
|
|
52
|
+
let s;
|
|
53
|
+
const pattern = new RegExp(
|
|
54
|
+
`(?<!(?<!\\.\\.)\\.)\\b(import\\.meta\\.env\\.(.+?)|import\\.meta\\.env)\\b(?!\\s*?=[^=])`,
|
|
55
|
+
"g"
|
|
56
|
+
);
|
|
57
|
+
let references;
|
|
92
58
|
let match;
|
|
93
59
|
while (match = pattern.exec(source)) {
|
|
94
|
-
|
|
95
|
-
const end = start + match[0].length;
|
|
96
|
-
let replacement = "" + replacements[match[1]];
|
|
60
|
+
let replacement;
|
|
97
61
|
if (match[0] === "import.meta.env") {
|
|
62
|
+
privateEnv ?? (privateEnv = getPrivateEnv(viteConfig, astroConfig));
|
|
63
|
+
references ?? (references = getReferencedPrivateKeys(source, privateEnv));
|
|
98
64
|
replacement = `(Object.assign(import.meta.env,{`;
|
|
99
65
|
for (const key of references.values()) {
|
|
100
66
|
replacement += `${key}:${privateEnv[key]},`;
|
|
101
67
|
}
|
|
102
68
|
replacement += "}))";
|
|
69
|
+
} else if (match[2]) {
|
|
70
|
+
privateEnv ?? (privateEnv = getPrivateEnv(viteConfig, astroConfig));
|
|
71
|
+
replacement = privateEnv[match[2]];
|
|
103
72
|
}
|
|
104
|
-
|
|
73
|
+
if (replacement) {
|
|
74
|
+
const start = match.index;
|
|
75
|
+
const end = start + match[0].length;
|
|
76
|
+
s ?? (s = new MagicString(source));
|
|
77
|
+
s.overwrite(start, end, replacement);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (s) {
|
|
81
|
+
return {
|
|
82
|
+
code: s.toString(),
|
|
83
|
+
map: s.generateMap()
|
|
84
|
+
};
|
|
105
85
|
}
|
|
106
|
-
return {
|
|
107
|
-
code: s.toString(),
|
|
108
|
-
map: s.generateMap()
|
|
109
|
-
};
|
|
110
86
|
}
|
|
111
87
|
};
|
|
112
88
|
}
|