astro 1.1.5 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/astro.d.ts +2 -2
- package/dist/core/add/index.js +7 -4
- package/dist/core/build/vite-plugin-analyzer.js +2 -3
- package/dist/core/build/vite-plugin-css.js +1 -0
- package/dist/{vite-plugin-astro → core/compile}/compile.d.ts +3 -8
- package/dist/{vite-plugin-astro → core/compile}/compile.js +23 -56
- package/dist/core/compile/index.d.ts +3 -0
- package/dist/core/compile/index.js +7 -0
- package/dist/core/compile/style.d.ts +5 -0
- package/dist/core/compile/style.js +31 -0
- package/dist/core/compile/types.d.ts +7 -0
- package/dist/core/compile/types.js +0 -0
- package/dist/core/create-vite.js +78 -26
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/css.js +3 -3
- package/dist/core/util.d.ts +13 -0
- package/dist/core/util.js +10 -2
- package/dist/jsx/babel.js +5 -9
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/hydration.js +3 -3
- package/dist/runtime/server/render/component.js +2 -1
- package/dist/runtime/server/render/page.js +1 -1
- package/dist/runtime/server/serialize.d.ts +2 -1
- package/dist/runtime/server/serialize.js +37 -12
- package/dist/vite-plugin-astro/hmr.d.ts +1 -1
- package/dist/vite-plugin-astro/hmr.js +1 -1
- package/dist/vite-plugin-astro/index.js +18 -26
- package/dist/vite-plugin-astro-server/index.js +1 -0
- package/dist/vite-plugin-markdown-legacy/index.js +16 -10
- package/dist/vite-style-transform/index.d.ts +2 -0
- package/dist/vite-style-transform/index.js +5 -0
- package/dist/vite-style-transform/style-transform.d.ts +10 -0
- package/dist/vite-style-transform/style-transform.js +36 -0
- package/dist/{vite-plugin-astro/styles.d.ts → vite-style-transform/transform-with-vite.d.ts} +0 -0
- package/dist/{vite-plugin-astro/styles.js → vite-style-transform/transform-with-vite.js} +0 -0
- package/package.json +7 -6
package/dist/@types/astro.d.ts
CHANGED
|
@@ -843,7 +843,7 @@ export interface MarkdownInstance<T extends Record<string, any>> {
|
|
|
843
843
|
getHeaders(): void;
|
|
844
844
|
default: AstroComponentFactory;
|
|
845
845
|
}
|
|
846
|
-
export interface MDXInstance<T
|
|
846
|
+
export interface MDXInstance<T extends Record<string, any>> extends Omit<MarkdownInstance<T>, 'rawContent' | 'compiledContent'> {
|
|
847
847
|
/** MDX does not support rawContent! If you need to read the Markdown contents to calculate values (ex. reading time), we suggest injecting frontmatter via remark plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */
|
|
848
848
|
rawContent: never;
|
|
849
849
|
/** MDX does not support compiledContent! If you need to read the HTML contents to calculate values (ex. reading time), we suggest injecting frontmatter via rehype plugins. Learn more on our docs: https://docs.astro.build/en/guides/integrations-guide/mdx/#inject-frontmatter-via-remark-or-rehype-plugins */
|
|
@@ -860,7 +860,7 @@ export interface MarkdownLayoutProps<T extends Record<string, any>> {
|
|
|
860
860
|
rawContent: MarkdownInstance<T>['rawContent'];
|
|
861
861
|
compiledContent: MarkdownInstance<T>['compiledContent'];
|
|
862
862
|
}
|
|
863
|
-
export declare type MDXLayoutProps<T
|
|
863
|
+
export declare type MDXLayoutProps<T extends Record<string, any>> = Omit<MarkdownLayoutProps<T>, 'rawContent' | 'compiledContent'>;
|
|
864
864
|
export declare type GetHydrateCallback = () => Promise<() => void | Promise<void>>;
|
|
865
865
|
/**
|
|
866
866
|
* getStaticPaths() options
|
package/dist/core/add/index.js
CHANGED
|
@@ -459,11 +459,11 @@ async function getInstallIntegrationsCommand({
|
|
|
459
459
|
).sort();
|
|
460
460
|
switch (pm.name) {
|
|
461
461
|
case "npm":
|
|
462
|
-
return { pm: "npm", command: "install", flags: [
|
|
462
|
+
return { pm: "npm", command: "install", flags: [], dependencies };
|
|
463
463
|
case "yarn":
|
|
464
|
-
return { pm: "yarn", command: "add", flags: [
|
|
464
|
+
return { pm: "yarn", command: "add", flags: [], dependencies };
|
|
465
465
|
case "pnpm":
|
|
466
|
-
return { pm: "pnpm", command: "install", flags: [
|
|
466
|
+
return { pm: "pnpm", command: "install", flags: [], dependencies };
|
|
467
467
|
default:
|
|
468
468
|
return null;
|
|
469
469
|
}
|
|
@@ -478,7 +478,10 @@ async function tryToInstallIntegrations({
|
|
|
478
478
|
if (installCommand === null) {
|
|
479
479
|
return 0 /* none */;
|
|
480
480
|
} else {
|
|
481
|
-
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}
|
|
481
|
+
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}${[
|
|
482
|
+
"",
|
|
483
|
+
...installCommand.flags
|
|
484
|
+
].join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
|
|
482
485
|
const message = `
|
|
483
486
|
${boxen(coloredOutput, {
|
|
484
487
|
margin: 0.5,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { prependForwardSlash } from "../../core/path.js";
|
|
2
|
-
import { resolveClientDevPath } from "../../core/render/dev/resolve.js";
|
|
3
2
|
import { getTopLevelPages } from "./graph.js";
|
|
4
3
|
import { getPageDataByViteID, trackClientOnlyPageDatas } from "./internal.js";
|
|
5
4
|
function vitePluginAnalyzer(internals) {
|
|
@@ -66,14 +65,14 @@ function vitePluginAnalyzer(internals) {
|
|
|
66
65
|
continue;
|
|
67
66
|
const astro = info.meta.astro;
|
|
68
67
|
for (const c of astro.hydratedComponents) {
|
|
69
|
-
const rid = c.resolvedPath ?
|
|
68
|
+
const rid = c.resolvedPath ? decodeURI(c.resolvedPath) : c.specifier;
|
|
70
69
|
internals.discoveredHydratedComponents.add(rid);
|
|
71
70
|
}
|
|
72
71
|
hoistScanner.scan.call(this, astro.scripts, id);
|
|
73
72
|
if (astro.clientOnlyComponents.length) {
|
|
74
73
|
const clientOnlys = [];
|
|
75
74
|
for (const c of astro.clientOnlyComponents) {
|
|
76
|
-
const cid = c.resolvedPath ?
|
|
75
|
+
const cid = c.resolvedPath ? decodeURI(c.resolvedPath) : c.specifier;
|
|
77
76
|
internals.discoveredClientOnlyComponents.add(cid);
|
|
78
77
|
clientOnlys.push(cid);
|
|
79
78
|
}
|
|
@@ -92,6 +92,7 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
92
92
|
if (Object.keys(c.modules).every((id) => internals.cssChunkModuleIds.has(id))) {
|
|
93
93
|
for (const importedCssImport of meta.importedCss) {
|
|
94
94
|
delete bundle[importedCssImport];
|
|
95
|
+
meta.importedCss.delete(importedCssImport);
|
|
95
96
|
}
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { TransformResult } from '@astrojs/compiler';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { AstroConfig } from '../@types/astro';
|
|
5
|
-
import type { TransformStyleWithVite } from './styles';
|
|
2
|
+
import type { AstroConfig } from '../../@types/astro';
|
|
3
|
+
import type { TransformStyle } from './types';
|
|
6
4
|
declare type CompileResult = TransformResult & {
|
|
7
5
|
cssDeps: Set<string>;
|
|
8
6
|
source: string;
|
|
@@ -12,10 +10,7 @@ export interface CompileProps {
|
|
|
12
10
|
filename: string;
|
|
13
11
|
moduleId: string;
|
|
14
12
|
source: string;
|
|
15
|
-
|
|
16
|
-
transformStyleWithVite: TransformStyleWithVite;
|
|
17
|
-
viteDevServer?: ViteDevServer;
|
|
18
|
-
pluginContext: PluginContext;
|
|
13
|
+
transformStyle: TransformStyle;
|
|
19
14
|
}
|
|
20
15
|
export declare function isCached(config: AstroConfig, filename: string): boolean;
|
|
21
16
|
export declare function getCachedSource(config: AstroConfig, filename: string): string | null;
|
|
@@ -1,35 +1,19 @@
|
|
|
1
1
|
import { transform } from "@astrojs/compiler";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { AstroErrorCodes } from "../errors.js";
|
|
3
|
+
import { prependForwardSlash } from "../path.js";
|
|
4
|
+
import { AggregateError, viteID } from "../util.js";
|
|
5
|
+
import { createStylePreprocessor } from "./style.js";
|
|
6
6
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
function getNormalizedID(filename) {
|
|
8
|
-
try {
|
|
9
|
-
const filenameURL = new URL(`file://${filename}`);
|
|
10
|
-
return fileURLToPath(filenameURL);
|
|
11
|
-
} catch (err) {
|
|
12
|
-
return filename;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
7
|
async function compile({
|
|
16
8
|
config,
|
|
17
9
|
filename,
|
|
18
10
|
moduleId,
|
|
19
11
|
source,
|
|
20
|
-
|
|
21
|
-
transformStyleWithVite,
|
|
22
|
-
viteDevServer,
|
|
23
|
-
pluginContext
|
|
12
|
+
transformStyle
|
|
24
13
|
}) {
|
|
25
14
|
var _a;
|
|
26
|
-
const normalizedID = getNormalizedID(filename);
|
|
27
15
|
let cssDeps = /* @__PURE__ */ new Set();
|
|
28
|
-
let
|
|
29
|
-
if (!pluginContext.addWatchFile) {
|
|
30
|
-
pluginContext.addWatchFile = () => {
|
|
31
|
-
};
|
|
32
|
-
}
|
|
16
|
+
let cssTransformErrors = [];
|
|
33
17
|
const transformResult = await transform(source, {
|
|
34
18
|
pathname: `/@fs${prependForwardSlash(moduleId)}`,
|
|
35
19
|
projectRoot: config.root.toString(),
|
|
@@ -37,47 +21,30 @@ async function compile({
|
|
|
37
21
|
sourcefile: filename,
|
|
38
22
|
sourcemap: "both",
|
|
39
23
|
internalURL: `/@fs${prependForwardSlash(
|
|
40
|
-
viteID(new URL("
|
|
24
|
+
viteID(new URL("../../runtime/server/index.js", import.meta.url))
|
|
41
25
|
)}`,
|
|
42
26
|
experimentalStaticExtraction: true,
|
|
43
|
-
preprocessStyle:
|
|
44
|
-
const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
|
|
45
|
-
try {
|
|
46
|
-
const result = await transformStyleWithVite.call(pluginContext, {
|
|
47
|
-
id: normalizedID,
|
|
48
|
-
source: value,
|
|
49
|
-
lang,
|
|
50
|
-
ssr,
|
|
51
|
-
viteDevServer
|
|
52
|
-
});
|
|
53
|
-
if (!result)
|
|
54
|
-
return null;
|
|
55
|
-
for (const dep of result.deps) {
|
|
56
|
-
cssDeps.add(dep);
|
|
57
|
-
}
|
|
58
|
-
let map;
|
|
59
|
-
if (result.map) {
|
|
60
|
-
if (typeof result.map === "string") {
|
|
61
|
-
map = result.map;
|
|
62
|
-
} else if (result.map.mappings) {
|
|
63
|
-
map = result.map.toString();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return { code: result.code, map };
|
|
67
|
-
} catch (err) {
|
|
68
|
-
cssTransformError = err;
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
27
|
+
preprocessStyle: createStylePreprocessor(transformStyle, cssDeps, cssTransformErrors)
|
|
72
28
|
}).catch((err) => {
|
|
73
29
|
err.code = err.code || AstroErrorCodes.UnknownCompilerError;
|
|
74
30
|
throw err;
|
|
75
31
|
}).then((result) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
32
|
+
switch (cssTransformErrors.length) {
|
|
33
|
+
case 0:
|
|
34
|
+
return result;
|
|
35
|
+
case 1: {
|
|
36
|
+
let error = cssTransformErrors[0];
|
|
37
|
+
if (!error.code) {
|
|
38
|
+
error.code = AstroErrorCodes.UnknownCompilerCSSError;
|
|
39
|
+
}
|
|
40
|
+
throw cssTransformErrors[0];
|
|
41
|
+
}
|
|
42
|
+
default: {
|
|
43
|
+
const aggregateError = new AggregateError(cssTransformErrors);
|
|
44
|
+
aggregateError.code = AstroErrorCodes.UnknownCompilerCSSError;
|
|
45
|
+
throw aggregateError;
|
|
46
|
+
}
|
|
79
47
|
}
|
|
80
|
-
return result;
|
|
81
48
|
});
|
|
82
49
|
const compileResult = Object.create(transformResult, {
|
|
83
50
|
cssDeps: {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { TransformOptions } from '@astrojs/compiler';
|
|
2
|
+
import type { TransformStyle } from './types';
|
|
3
|
+
declare type PreprocessStyle = TransformOptions['preprocessStyle'];
|
|
4
|
+
export declare function createStylePreprocessor(transformStyle: TransformStyle, cssDeps: Set<string>, errors: Error[]): PreprocessStyle;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function createStylePreprocessor(transformStyle, cssDeps, errors) {
|
|
2
|
+
const preprocessStyle = async (value, attrs) => {
|
|
3
|
+
const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
|
|
4
|
+
try {
|
|
5
|
+
const result = await transformStyle(value, lang);
|
|
6
|
+
if (!result)
|
|
7
|
+
return null;
|
|
8
|
+
for (const dep of result.deps) {
|
|
9
|
+
cssDeps.add(dep);
|
|
10
|
+
}
|
|
11
|
+
let map;
|
|
12
|
+
if (result.map) {
|
|
13
|
+
if (typeof result.map === "string") {
|
|
14
|
+
map = result.map;
|
|
15
|
+
} else if (result.map.mappings) {
|
|
16
|
+
map = result.map.toString();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return { code: result.code, map };
|
|
20
|
+
} catch (err) {
|
|
21
|
+
errors.push(err);
|
|
22
|
+
return {
|
|
23
|
+
error: err + ""
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return preprocessStyle;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
createStylePreprocessor
|
|
31
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SourceMap } from 'rollup';
|
|
2
|
+
export declare type TransformStyleResult = null | {
|
|
3
|
+
code: string;
|
|
4
|
+
map: SourceMap | null;
|
|
5
|
+
deps: Set<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare type TransformStyle = (source: string, lang: string) => TransformStyleResult | Promise<TransformStyleResult>;
|
|
File without changes
|
package/dist/core/create-vite.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import path from "path";
|
|
2
4
|
import { fileURLToPath } from "url";
|
|
3
5
|
import * as vite from "vite";
|
|
4
6
|
import astroPostprocessVitePlugin from "../vite-plugin-astro-postprocess/index.js";
|
|
@@ -116,32 +118,82 @@ function sortPlugins(pluginOptions) {
|
|
|
116
118
|
pluginOptions.splice(jsxPluginIndex, 0, mdxPlugin);
|
|
117
119
|
}
|
|
118
120
|
async function getAstroPackages({ root }) {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
121
|
+
const { astroPackages } = new DependencyWalker(root);
|
|
122
|
+
return astroPackages;
|
|
123
|
+
}
|
|
124
|
+
class DependencyWalker {
|
|
125
|
+
constructor(root) {
|
|
126
|
+
this.astroDeps = /* @__PURE__ */ new Set();
|
|
127
|
+
this.nonAstroDeps = /* @__PURE__ */ new Set();
|
|
128
|
+
const pkgUrl = new URL("./package.json", root);
|
|
129
|
+
this.require = createRequire(pkgUrl);
|
|
130
|
+
const pkgPath = fileURLToPath(pkgUrl);
|
|
131
|
+
if (!fs.existsSync(pkgPath))
|
|
132
|
+
return;
|
|
133
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
134
|
+
const deps = [
|
|
135
|
+
...Object.keys(pkg.dependencies || {}),
|
|
136
|
+
...Object.keys(pkg.devDependencies || {})
|
|
137
|
+
];
|
|
138
|
+
this.scanDependencies(deps);
|
|
139
|
+
}
|
|
140
|
+
get astroPackages() {
|
|
141
|
+
return Array.from(this.astroDeps);
|
|
142
|
+
}
|
|
143
|
+
seen(dep) {
|
|
144
|
+
return this.astroDeps.has(dep) || this.nonAstroDeps.has(dep);
|
|
145
|
+
}
|
|
146
|
+
readPkgJSON(dir) {
|
|
147
|
+
try {
|
|
148
|
+
const filePath = path.join(dir, "package.json");
|
|
149
|
+
return JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
150
|
+
} catch (e) {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
resolvePkgJSON(dep) {
|
|
154
|
+
try {
|
|
155
|
+
const pkgJson = this.require(dep + "/package.json");
|
|
156
|
+
return pkgJson;
|
|
157
|
+
} catch (e) {
|
|
158
|
+
try {
|
|
159
|
+
let dir = path.dirname(this.require.resolve(dep));
|
|
160
|
+
while (dir) {
|
|
161
|
+
const pkgJSON = this.readPkgJSON(dir);
|
|
162
|
+
if (pkgJSON && pkgJSON.name === dep)
|
|
163
|
+
return pkgJSON;
|
|
164
|
+
const parentDir = path.dirname(dir);
|
|
165
|
+
if (parentDir === dir)
|
|
166
|
+
break;
|
|
167
|
+
dir = parentDir;
|
|
168
|
+
}
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
scanDependencies(deps) {
|
|
174
|
+
const newDeps = [];
|
|
175
|
+
for (const dep of deps) {
|
|
176
|
+
if (isCommonNotAstro(dep)) {
|
|
177
|
+
this.nonAstroDeps.add(dep);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const pkgJson = this.resolvePkgJSON(dep);
|
|
181
|
+
if (!pkgJson) {
|
|
182
|
+
this.nonAstroDeps.add(dep);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const { dependencies = {}, peerDependencies = {}, keywords = [] } = pkgJson;
|
|
186
|
+
if (peerDependencies.astro || dependencies.astro || keywords.includes("astro") || keywords.includes("astro-component") || /^(@[^\/]+\/)?astro\-/.test(dep)) {
|
|
187
|
+
this.astroDeps.add(dep);
|
|
188
|
+
const unknownDependencies = Object.keys(dependencies).filter((d) => !this.seen(d));
|
|
189
|
+
newDeps.push(...unknownDependencies);
|
|
190
|
+
} else {
|
|
191
|
+
this.nonAstroDeps.add(dep);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (newDeps.length)
|
|
195
|
+
this.scanDependencies(newDeps);
|
|
196
|
+
}
|
|
145
197
|
}
|
|
146
198
|
const COMMON_DEPENDENCIES_NOT_ASTRO = [
|
|
147
199
|
"autoprefixer",
|
package/dist/core/dev/index.js
CHANGED
|
@@ -46,7 +46,7 @@ async function dev(config, options) {
|
|
|
46
46
|
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
|
|
47
47
|
})
|
|
48
48
|
);
|
|
49
|
-
const currentVersion = "1.1.
|
|
49
|
+
const currentVersion = "1.1.8";
|
|
50
50
|
if (currentVersion.includes("-")) {
|
|
51
51
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
52
52
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -46,7 +46,7 @@ function devStart({
|
|
|
46
46
|
https,
|
|
47
47
|
site
|
|
48
48
|
}) {
|
|
49
|
-
const version = "1.1.
|
|
49
|
+
const version = "1.1.8";
|
|
50
50
|
const rootPath = site ? site.pathname : "/";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -225,7 +225,7 @@ function printHelp({
|
|
|
225
225
|
message.push(
|
|
226
226
|
linebreak(),
|
|
227
227
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
228
|
-
`v${"1.1.
|
|
228
|
+
`v${"1.1.8"}`
|
|
229
229
|
)} ${headline}`
|
|
230
230
|
);
|
|
231
231
|
}
|
|
@@ -3,14 +3,14 @@ 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;
|
|
7
6
|
const importedCssUrls = /* @__PURE__ */ new Set();
|
|
8
7
|
const importedStylesMap = /* @__PURE__ */ new Map();
|
|
9
8
|
for await (const importedModule of crawlGraph(viteServer, viteID(filePath), true)) {
|
|
10
9
|
const ext = path.extname(importedModule.url).toLowerCase();
|
|
11
10
|
if (STYLE_EXTENSIONS.has(ext)) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const ssrModule = importedModule.ssrModule ?? await viteServer.ssrLoadModule(importedModule.url);
|
|
12
|
+
if (mode === "development" && typeof (ssrModule == null ? void 0 : ssrModule.default) === "string") {
|
|
13
|
+
importedStylesMap.set(importedModule.url, ssrModule.default);
|
|
14
14
|
} else {
|
|
15
15
|
importedCssUrls.add(importedModule.url);
|
|
16
16
|
}
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { ErrorPayload, ViteDevServer } from 'vite';
|
|
2
3
|
import type { AstroConfig, RouteType } from '../@types/astro';
|
|
3
4
|
export declare const ASTRO_VERSION: string;
|
|
@@ -46,3 +47,15 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
|
|
|
46
47
|
* through a script tag or a dynamic import as-is.
|
|
47
48
|
*/
|
|
48
49
|
export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
|
|
50
|
+
export declare const AggregateError: AggregateErrorConstructor | {
|
|
51
|
+
new (errors: Iterable<any>, message?: string | undefined): {
|
|
52
|
+
errors: Array<any>;
|
|
53
|
+
name: string;
|
|
54
|
+
message: string;
|
|
55
|
+
stack?: string | undefined;
|
|
56
|
+
cause?: Error | undefined;
|
|
57
|
+
};
|
|
58
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
59
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
60
|
+
stackTraceLimit: number;
|
|
61
|
+
};
|
package/dist/core/util.js
CHANGED
|
@@ -5,7 +5,7 @@ import resolve from "resolve";
|
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
8
|
-
const ASTRO_VERSION = "1.1.
|
|
8
|
+
const ASTRO_VERSION = "1.1.8";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
|
@@ -87,7 +87,7 @@ function resolveDependency(dep, projectRoot) {
|
|
|
87
87
|
return pathToFileURL(resolved).toString();
|
|
88
88
|
}
|
|
89
89
|
function viteID(filePath) {
|
|
90
|
-
return slash(fileURLToPath(filePath));
|
|
90
|
+
return slash(fileURLToPath(filePath) + filePath.search);
|
|
91
91
|
}
|
|
92
92
|
const VALID_ID_PREFIX = `/@id/`;
|
|
93
93
|
function unwrapId(id) {
|
|
@@ -170,8 +170,16 @@ async function resolveIdToUrl(viteServer, id) {
|
|
|
170
170
|
}
|
|
171
171
|
return VALID_ID_PREFIX + result.id;
|
|
172
172
|
}
|
|
173
|
+
const AggregateError = typeof globalThis.AggregateError !== "undefined" ? globalThis.AggregateError : class extends Error {
|
|
174
|
+
constructor(errors, message) {
|
|
175
|
+
super(message);
|
|
176
|
+
this.errors = [];
|
|
177
|
+
this.errors = Array.from(errors);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
173
180
|
export {
|
|
174
181
|
ASTRO_VERSION,
|
|
182
|
+
AggregateError,
|
|
175
183
|
VALID_ID_PREFIX,
|
|
176
184
|
arraify,
|
|
177
185
|
codeFrame,
|
package/dist/jsx/babel.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
2
|
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { resolveClientDevPath } from "../core/render/dev/resolve.js";
|
|
3
4
|
import { HydrationDirectiveProps } from "../runtime/server/hydration.js";
|
|
4
5
|
const ClientOnlyPlaceholder = "astro-client-only";
|
|
5
6
|
function isComponent(tagName) {
|
|
@@ -184,7 +185,8 @@ function astroJSX() {
|
|
|
184
185
|
break;
|
|
185
186
|
}
|
|
186
187
|
if (namespace.at(0) === local) {
|
|
187
|
-
|
|
188
|
+
const name = imported === "*" ? imported : tagName;
|
|
189
|
+
path.setData("import", { name, path: source });
|
|
188
190
|
break;
|
|
189
191
|
}
|
|
190
192
|
}
|
|
@@ -194,10 +196,7 @@ function astroJSX() {
|
|
|
194
196
|
let resolvedPath;
|
|
195
197
|
if (meta.path.startsWith(".")) {
|
|
196
198
|
const fileURL = pathToFileURL(state.filename);
|
|
197
|
-
resolvedPath = `/@fs${new URL(meta.path, fileURL).pathname}
|
|
198
|
-
if (resolvedPath.endsWith(".jsx")) {
|
|
199
|
-
resolvedPath = resolvedPath.slice(0, -4);
|
|
200
|
-
}
|
|
199
|
+
resolvedPath = resolveClientDevPath(`/@fs${new URL(meta.path, fileURL).pathname}`);
|
|
201
200
|
} else {
|
|
202
201
|
resolvedPath = meta.path;
|
|
203
202
|
}
|
|
@@ -273,10 +272,7 @@ function astroJSX() {
|
|
|
273
272
|
let resolvedPath;
|
|
274
273
|
if (meta.path.startsWith(".")) {
|
|
275
274
|
const fileURL = pathToFileURL(state.filename);
|
|
276
|
-
resolvedPath = `/@fs${new URL(meta.path, fileURL).pathname}
|
|
277
|
-
if (resolvedPath.endsWith(".jsx")) {
|
|
278
|
-
resolvedPath = resolvedPath.slice(0, -4);
|
|
279
|
-
}
|
|
275
|
+
resolvedPath = resolveClientDevPath(`/@fs${new URL(meta.path, fileURL).pathname}`);
|
|
280
276
|
} else {
|
|
281
277
|
resolvedPath = meta.path;
|
|
282
278
|
}
|
|
@@ -85,11 +85,11 @@ async function generateHydrateScript(scriptOptions, metadata) {
|
|
|
85
85
|
island.props[key] = value;
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
island.props["component-url"] = await result.resolve(componentUrl);
|
|
88
|
+
island.props["component-url"] = await result.resolve(decodeURI(componentUrl));
|
|
89
89
|
if (renderer.clientEntrypoint) {
|
|
90
90
|
island.props["component-export"] = componentExport.value;
|
|
91
|
-
island.props["renderer-url"] = await result.resolve(renderer.clientEntrypoint);
|
|
92
|
-
island.props["props"] = escapeHTML(serializeProps(props));
|
|
91
|
+
island.props["renderer-url"] = await result.resolve(decodeURI(renderer.clientEntrypoint));
|
|
92
|
+
island.props["props"] = escapeHTML(serializeProps(props, metadata));
|
|
93
93
|
}
|
|
94
94
|
island.props["ssr"] = "";
|
|
95
95
|
island.props["client"] = hydrate;
|
|
@@ -231,7 +231,8 @@ If you're still stuck, please open an issue on GitHub or join us at https://astr
|
|
|
231
231
|
`<!--${metadata.componentExport.value}:${metadata.componentUrl}-->
|
|
232
232
|
${html}
|
|
233
233
|
${serializeProps(
|
|
234
|
-
props
|
|
234
|
+
props,
|
|
235
|
+
metadata
|
|
235
236
|
)}`
|
|
236
237
|
);
|
|
237
238
|
const island = await generateHydrateScript(
|
|
@@ -56,7 +56,7 @@ async function renderPage(result, componentFactory, props, children, streaming)
|
|
|
56
56
|
controller.enqueue(encoder.encode("<!DOCTYPE html>\n"));
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
controller.enqueue(encoder.encode(html));
|
|
59
|
+
controller.enqueue(encoder.encode(String(html)));
|
|
60
60
|
i++;
|
|
61
61
|
}
|
|
62
62
|
controller.close();
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AstroComponentMetadata } from '../../@types/astro';
|
|
2
|
+
export declare function serializeProps(props: any, metadata: AstroComponentMetadata): string;
|
|
@@ -8,17 +8,35 @@ const PROP_TYPE = {
|
|
|
8
8
|
BigInt: 6,
|
|
9
9
|
URL: 7
|
|
10
10
|
};
|
|
11
|
-
function serializeArray(value) {
|
|
12
|
-
|
|
11
|
+
function serializeArray(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
|
12
|
+
if (parents.has(value)) {
|
|
13
|
+
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
|
14
|
+
|
|
15
|
+
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
|
16
|
+
}
|
|
17
|
+
parents.add(value);
|
|
18
|
+
const serialized = value.map((v) => {
|
|
19
|
+
return convertToSerializedForm(v, metadata, parents);
|
|
20
|
+
});
|
|
21
|
+
parents.delete(value);
|
|
22
|
+
return serialized;
|
|
13
23
|
}
|
|
14
|
-
function serializeObject(value) {
|
|
15
|
-
|
|
24
|
+
function serializeObject(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
|
25
|
+
if (parents.has(value)) {
|
|
26
|
+
throw new Error(`Cyclic reference detected while serializing props for <${metadata.displayName} client:${metadata.hydrate}>!
|
|
27
|
+
|
|
28
|
+
Cyclic references cannot be safely serialized for client-side usage. Please remove the cyclic reference.`);
|
|
29
|
+
}
|
|
30
|
+
parents.add(value);
|
|
31
|
+
const serialized = Object.fromEntries(
|
|
16
32
|
Object.entries(value).map(([k, v]) => {
|
|
17
|
-
return [k, convertToSerializedForm(v)];
|
|
33
|
+
return [k, convertToSerializedForm(v, metadata, parents)];
|
|
18
34
|
})
|
|
19
35
|
);
|
|
36
|
+
parents.delete(value);
|
|
37
|
+
return serialized;
|
|
20
38
|
}
|
|
21
|
-
function convertToSerializedForm(value) {
|
|
39
|
+
function convertToSerializedForm(value, metadata = {}, parents = /* @__PURE__ */ new WeakSet()) {
|
|
22
40
|
const tag = Object.prototype.toString.call(value);
|
|
23
41
|
switch (tag) {
|
|
24
42
|
case "[object Date]": {
|
|
@@ -28,10 +46,16 @@ function convertToSerializedForm(value) {
|
|
|
28
46
|
return [PROP_TYPE.RegExp, value.source];
|
|
29
47
|
}
|
|
30
48
|
case "[object Map]": {
|
|
31
|
-
return [
|
|
49
|
+
return [
|
|
50
|
+
PROP_TYPE.Map,
|
|
51
|
+
JSON.stringify(serializeArray(Array.from(value), metadata, parents))
|
|
52
|
+
];
|
|
32
53
|
}
|
|
33
54
|
case "[object Set]": {
|
|
34
|
-
return [
|
|
55
|
+
return [
|
|
56
|
+
PROP_TYPE.Set,
|
|
57
|
+
JSON.stringify(serializeArray(Array.from(value), metadata, parents))
|
|
58
|
+
];
|
|
35
59
|
}
|
|
36
60
|
case "[object BigInt]": {
|
|
37
61
|
return [PROP_TYPE.BigInt, value.toString()];
|
|
@@ -40,19 +64,20 @@ function convertToSerializedForm(value) {
|
|
|
40
64
|
return [PROP_TYPE.URL, value.toString()];
|
|
41
65
|
}
|
|
42
66
|
case "[object Array]": {
|
|
43
|
-
return [PROP_TYPE.JSON, JSON.stringify(serializeArray(value))];
|
|
67
|
+
return [PROP_TYPE.JSON, JSON.stringify(serializeArray(value, metadata, parents))];
|
|
44
68
|
}
|
|
45
69
|
default: {
|
|
46
70
|
if (value !== null && typeof value === "object") {
|
|
47
|
-
return [PROP_TYPE.Value, serializeObject(value)];
|
|
71
|
+
return [PROP_TYPE.Value, serializeObject(value, metadata, parents)];
|
|
48
72
|
} else {
|
|
49
73
|
return [PROP_TYPE.Value, value];
|
|
50
74
|
}
|
|
51
75
|
}
|
|
52
76
|
}
|
|
53
77
|
}
|
|
54
|
-
function serializeProps(props) {
|
|
55
|
-
|
|
78
|
+
function serializeProps(props, metadata) {
|
|
79
|
+
const serialized = JSON.stringify(serializeObject(props, metadata));
|
|
80
|
+
return serialized;
|
|
56
81
|
}
|
|
57
82
|
export {
|
|
58
83
|
serializeProps
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HmrContext, ModuleNode } from 'vite';
|
|
2
2
|
import type { AstroConfig } from '../@types/astro';
|
|
3
|
+
import { cachedCompilation } from '../core/compile/index.js';
|
|
3
4
|
import type { LogOptions } from '../core/logger/core.js';
|
|
4
|
-
import { cachedCompilation } from './compile.js';
|
|
5
5
|
export interface HandleHotUpdateOptions {
|
|
6
6
|
config: AstroConfig;
|
|
7
7
|
logging: LogOptions;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { invalidateCompilation, isCached } from "../core/compile/index.js";
|
|
2
3
|
import { info } from "../core/logger/core.js";
|
|
3
4
|
import * as msg from "../core/messages.js";
|
|
4
|
-
import { invalidateCompilation, isCached } from "./compile.js";
|
|
5
5
|
import { isAstroScript } from "./query.js";
|
|
6
6
|
const PKG_PREFIX = new URL("../../", import.meta.url);
|
|
7
7
|
const isPkgFile = (id) => {
|
|
@@ -2,12 +2,16 @@ import ancestor from "common-ancestor-path";
|
|
|
2
2
|
import esbuild from "esbuild";
|
|
3
3
|
import slash from "slash";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import {
|
|
5
|
+
import { cachedCompilation, getCachedSource } from "../core/compile/index.js";
|
|
6
|
+
import { isRelativePath, prependForwardSlash, startsWithForwardSlash } from "../core/path.js";
|
|
7
|
+
import { viteID } from "../core/util.js";
|
|
6
8
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
7
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
createTransformStyles,
|
|
11
|
+
createViteStyleTransformer
|
|
12
|
+
} from "../vite-style-transform/index.js";
|
|
8
13
|
import { handleHotUpdate } from "./hmr.js";
|
|
9
14
|
import { parseAstroRequest } from "./query.js";
|
|
10
|
-
import { createTransformStyleWithViteFn } from "./styles.js";
|
|
11
15
|
const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
|
|
12
16
|
function astro({ config, logging }) {
|
|
13
17
|
function normalizeFilename(filename) {
|
|
@@ -24,10 +28,11 @@ function astro({ config, logging }) {
|
|
|
24
28
|
return slash(fileURLToPath(url)) + url.search;
|
|
25
29
|
}
|
|
26
30
|
let resolvedConfig;
|
|
27
|
-
let
|
|
31
|
+
let styleTransformer;
|
|
28
32
|
let viteDevServer;
|
|
29
33
|
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
|
30
34
|
const isBrowserPath = (path) => path.startsWith(srcRootWeb);
|
|
35
|
+
const isFullFilePath = (path) => path.startsWith(prependForwardSlash(slash(fileURLToPath(config.root))));
|
|
31
36
|
function resolveRelativeFromAstroParent(id, parsedFrom) {
|
|
32
37
|
const filename = normalizeFilename(parsedFrom.filename);
|
|
33
38
|
const resolvedURL = new URL(id, `file://${filename}`);
|
|
@@ -42,10 +47,11 @@ function astro({ config, logging }) {
|
|
|
42
47
|
enforce: "pre",
|
|
43
48
|
configResolved(_resolvedConfig) {
|
|
44
49
|
resolvedConfig = _resolvedConfig;
|
|
45
|
-
|
|
50
|
+
styleTransformer = createViteStyleTransformer(_resolvedConfig);
|
|
46
51
|
},
|
|
47
52
|
configureServer(server) {
|
|
48
53
|
viteDevServer = server;
|
|
54
|
+
styleTransformer.viteDevServer = server;
|
|
49
55
|
},
|
|
50
56
|
async resolveId(id, from, opts) {
|
|
51
57
|
if (from) {
|
|
@@ -63,6 +69,9 @@ function astro({ config, logging }) {
|
|
|
63
69
|
if (query.type === "style" && isBrowserPath(id)) {
|
|
64
70
|
return relativeToRoot(id);
|
|
65
71
|
}
|
|
72
|
+
if (isFullFilePath(id)) {
|
|
73
|
+
return viteID(new URL("file://" + id));
|
|
74
|
+
}
|
|
66
75
|
return id;
|
|
67
76
|
}
|
|
68
77
|
},
|
|
@@ -86,10 +95,7 @@ function astro({ config, logging }) {
|
|
|
86
95
|
filename,
|
|
87
96
|
moduleId: id,
|
|
88
97
|
source,
|
|
89
|
-
|
|
90
|
-
transformStyleWithVite,
|
|
91
|
-
viteDevServer,
|
|
92
|
-
pluginContext: this
|
|
98
|
+
transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
|
|
93
99
|
};
|
|
94
100
|
switch (query.type) {
|
|
95
101
|
case "style": {
|
|
@@ -163,7 +169,7 @@ File: ${filename}`
|
|
|
163
169
|
}
|
|
164
170
|
},
|
|
165
171
|
async transform(source, id, opts) {
|
|
166
|
-
var _a
|
|
172
|
+
var _a;
|
|
167
173
|
const parsedId = parseAstroRequest(id);
|
|
168
174
|
const query = parsedId.query;
|
|
169
175
|
if (!id.endsWith(".astro") || query.astro) {
|
|
@@ -178,10 +184,7 @@ File: ${filename}`
|
|
|
178
184
|
filename,
|
|
179
185
|
moduleId: id,
|
|
180
186
|
source,
|
|
181
|
-
|
|
182
|
-
transformStyleWithVite,
|
|
183
|
-
viteDevServer,
|
|
184
|
-
pluginContext: this
|
|
187
|
+
transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
|
|
185
188
|
};
|
|
186
189
|
try {
|
|
187
190
|
const transformResult = await cachedCompilation(compileProps);
|
|
@@ -203,16 +206,8 @@ const $$url = ${JSON.stringify(
|
|
|
203
206
|
)};export { $$file as file, $$url as url };
|
|
204
207
|
`;
|
|
205
208
|
if (!resolvedConfig.isProduction) {
|
|
206
|
-
const metadata = transformResult.code.split("$$createMetadata(")[1].split("});\n")[0];
|
|
207
|
-
const pattern = /specifier:\s*'([^']*)'/g;
|
|
208
|
-
const deps = /* @__PURE__ */ new Set();
|
|
209
|
-
let match;
|
|
210
|
-
while (match = (_b = pattern.exec(metadata)) == null ? void 0 : _b[1]) {
|
|
211
|
-
deps.add(match);
|
|
212
|
-
}
|
|
213
209
|
let i = 0;
|
|
214
210
|
while (i < transformResult.scripts.length) {
|
|
215
|
-
deps.add(`${id}?astro&type=script&index=${i}&lang.ts`);
|
|
216
211
|
SUFFIX += `import "${id}?astro&type=script&index=${i}&lang.ts";`;
|
|
217
212
|
i++;
|
|
218
213
|
}
|
|
@@ -288,10 +283,7 @@ ${source}
|
|
|
288
283
|
filename: context.file,
|
|
289
284
|
moduleId: context.file,
|
|
290
285
|
source: await context.read(),
|
|
291
|
-
|
|
292
|
-
transformStyleWithVite,
|
|
293
|
-
viteDevServer,
|
|
294
|
-
pluginContext: this
|
|
286
|
+
transformStyle: createTransformStyles(styleTransformer, context.file, true, this)
|
|
295
287
|
};
|
|
296
288
|
const compile = () => cachedCompilation(compileProps);
|
|
297
289
|
return handleHotUpdate.call(this, context, {
|
|
@@ -83,6 +83,7 @@ async function handle404Response(origin, config, req, res) {
|
|
|
83
83
|
async function handle500Response(viteServer, origin, req, res, err) {
|
|
84
84
|
res.on("close", () => setTimeout(() => viteServer.ws.send(getViteErrorPayload(err)), 200));
|
|
85
85
|
if (res.headersSent) {
|
|
86
|
+
res.write(`<script type="module" src="/@vite/client"><\/script>`);
|
|
86
87
|
res.end();
|
|
87
88
|
} else {
|
|
88
89
|
writeHtmlResponse(
|
|
@@ -5,12 +5,13 @@ import fs from "fs";
|
|
|
5
5
|
import matter from "gray-matter";
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import { pagesVirtualModuleId } from "../core/app/index.js";
|
|
8
|
+
import { cachedCompilation } from "../core/compile/index.js";
|
|
8
9
|
import { collectErrorMetadata } from "../core/errors.js";
|
|
9
|
-
import { cachedCompilation } from "../vite-plugin-astro/compile.js";
|
|
10
|
-
import {
|
|
11
|
-
createTransformStyleWithViteFn
|
|
12
|
-
} from "../vite-plugin-astro/styles.js";
|
|
13
10
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
11
|
+
import {
|
|
12
|
+
createTransformStyles,
|
|
13
|
+
createViteStyleTransformer
|
|
14
|
+
} from "../vite-style-transform/index.js";
|
|
14
15
|
const MARKDOWN_IMPORT_FLAG = "?mdImport";
|
|
15
16
|
const MARKDOWN_CONTENT_FLAG = "?content";
|
|
16
17
|
function safeMatter(source, id) {
|
|
@@ -43,13 +44,16 @@ function markdown({ config, logging }) {
|
|
|
43
44
|
}
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
46
|
-
let
|
|
47
|
+
let styleTransformer;
|
|
47
48
|
let viteDevServer;
|
|
48
49
|
return {
|
|
49
50
|
name: "astro:markdown",
|
|
50
51
|
enforce: "pre",
|
|
51
52
|
configResolved(_resolvedConfig) {
|
|
52
|
-
|
|
53
|
+
styleTransformer = createViteStyleTransformer(_resolvedConfig);
|
|
54
|
+
},
|
|
55
|
+
configureServer(server) {
|
|
56
|
+
styleTransformer.viteDevServer = server;
|
|
53
57
|
},
|
|
54
58
|
async resolveId(id, importer, options) {
|
|
55
59
|
if (id.endsWith(`.md${MARKDOWN_CONTENT_FLAG}`)) {
|
|
@@ -161,10 +165,12 @@ ${astroResult}
|
|
|
161
165
|
filename,
|
|
162
166
|
moduleId: id,
|
|
163
167
|
source: astroResult,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
transformStyle: createTransformStyles(
|
|
169
|
+
styleTransformer,
|
|
170
|
+
filename,
|
|
171
|
+
Boolean(opts == null ? void 0 : opts.ssr),
|
|
172
|
+
this
|
|
173
|
+
)
|
|
168
174
|
};
|
|
169
175
|
let transformResult = await cachedCompilation(compileProps);
|
|
170
176
|
let { code: tsResult } = transformResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PluginContext } from 'rollup';
|
|
2
|
+
import type { TransformStyle } from '../core/compile/index';
|
|
3
|
+
import { TransformStyleWithVite } from './transform-with-vite.js';
|
|
4
|
+
import type * as vite from 'vite';
|
|
5
|
+
export declare type ViteStyleTransformer = {
|
|
6
|
+
viteDevServer?: vite.ViteDevServer;
|
|
7
|
+
transformStyleWithVite: TransformStyleWithVite;
|
|
8
|
+
};
|
|
9
|
+
export declare function createViteStyleTransformer(viteConfig: vite.ResolvedConfig): ViteStyleTransformer;
|
|
10
|
+
export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext: PluginContext): TransformStyle;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { fileURLToPath } from "url";
|
|
2
|
+
import { createTransformStyleWithViteFn } from "./transform-with-vite.js";
|
|
3
|
+
function createViteStyleTransformer(viteConfig) {
|
|
4
|
+
return {
|
|
5
|
+
transformStyleWithVite: createTransformStyleWithViteFn(viteConfig)
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function getNormalizedIDForPostCSS(filename) {
|
|
9
|
+
try {
|
|
10
|
+
const filenameURL = new URL(`file://${filename}`);
|
|
11
|
+
return fileURLToPath(filenameURL);
|
|
12
|
+
} catch (err) {
|
|
13
|
+
return filename;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function createTransformStyles(viteStyleTransformer, filename, ssr, pluginContext) {
|
|
17
|
+
if (!pluginContext.addWatchFile) {
|
|
18
|
+
pluginContext.addWatchFile = () => {
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const normalizedID = getNormalizedIDForPostCSS(filename);
|
|
22
|
+
return async function(styleSource, lang) {
|
|
23
|
+
const result = await viteStyleTransformer.transformStyleWithVite.call(pluginContext, {
|
|
24
|
+
id: normalizedID,
|
|
25
|
+
source: styleSource,
|
|
26
|
+
lang,
|
|
27
|
+
ssr,
|
|
28
|
+
viteDevServer: viteStyleTransformer.viteDevServer
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
createTransformStyles,
|
|
35
|
+
createViteStyleTransformer
|
|
36
|
+
};
|
package/dist/{vite-plugin-astro/styles.d.ts → vite-style-transform/transform-with-vite.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
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",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"vendor"
|
|
83
83
|
],
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@astrojs/compiler": "^0.
|
|
85
|
+
"@astrojs/compiler": "^0.24.0",
|
|
86
86
|
"@astrojs/language-server": "^0.23.0",
|
|
87
87
|
"@astrojs/markdown-remark": "^1.1.1",
|
|
88
88
|
"@astrojs/telemetry": "^1.0.0",
|
|
@@ -95,6 +95,9 @@
|
|
|
95
95
|
"@babel/types": "^7.18.4",
|
|
96
96
|
"@proload/core": "^0.3.2",
|
|
97
97
|
"@proload/plugin-tsm": "^0.2.1",
|
|
98
|
+
"@types/babel__core": "^7.1.19",
|
|
99
|
+
"@types/html-escaper": "^3.0.0",
|
|
100
|
+
"@types/yargs-parser": "^21.0.0",
|
|
98
101
|
"boxen": "^6.2.1",
|
|
99
102
|
"ci-info": "^3.3.1",
|
|
100
103
|
"common-ancestor-path": "^1.0.1",
|
|
@@ -139,7 +142,6 @@
|
|
|
139
142
|
},
|
|
140
143
|
"devDependencies": {
|
|
141
144
|
"@playwright/test": "^1.22.2",
|
|
142
|
-
"@types/babel__core": "^7.1.19",
|
|
143
145
|
"@types/babel__generator": "^7.6.4",
|
|
144
146
|
"@types/babel__traverse": "^7.17.1",
|
|
145
147
|
"@types/chai": "^4.3.1",
|
|
@@ -148,7 +150,6 @@
|
|
|
148
150
|
"@types/debug": "^4.1.7",
|
|
149
151
|
"@types/diff": "^5.0.2",
|
|
150
152
|
"@types/estree": "^0.0.51",
|
|
151
|
-
"@types/html-escaper": "^3.0.0",
|
|
152
153
|
"@types/mime": "^2.0.3",
|
|
153
154
|
"@types/mocha": "^9.1.1",
|
|
154
155
|
"@types/parse5": "^6.0.3",
|
|
@@ -158,7 +159,6 @@
|
|
|
158
159
|
"@types/rimraf": "^3.0.2",
|
|
159
160
|
"@types/send": "^0.17.1",
|
|
160
161
|
"@types/unist": "^2.0.6",
|
|
161
|
-
"@types/yargs-parser": "^21.0.0",
|
|
162
162
|
"ast-types": "^0.14.2",
|
|
163
163
|
"astro-scripts": "0.0.7",
|
|
164
164
|
"chai": "^4.3.6",
|
|
@@ -178,7 +178,8 @@
|
|
|
178
178
|
"dev": "astro-scripts dev --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.ts\"",
|
|
179
179
|
"postbuild": "astro-scripts copy \"src/**/*.astro\"",
|
|
180
180
|
"benchmark": "node test/benchmark/dev.bench.js && node test/benchmark/build.bench.js",
|
|
181
|
-
"test": "mocha --exit --timeout
|
|
181
|
+
"test:unit": "mocha --exit --timeout 2000 ./test/units/**/*.test.js",
|
|
182
|
+
"test": "pnpm run test:unit && mocha --exit --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js",
|
|
182
183
|
"test:match": "mocha --timeout 20000 -g",
|
|
183
184
|
"test:e2e": "playwright test",
|
|
184
185
|
"test:e2e:match": "playwright test -g"
|