astro 6.0.0-alpha.1 → 6.0.0-alpha.2

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.
Files changed (77) hide show
  1. package/dist/actions/vite-plugin-actions.js +49 -35
  2. package/dist/assets/consts.d.ts +1 -0
  3. package/dist/assets/consts.js +2 -0
  4. package/dist/assets/fonts/vite-plugin-fonts.js +10 -4
  5. package/dist/assets/services/noop.js +10 -5
  6. package/dist/assets/services/service.d.ts +1 -1
  7. package/dist/assets/services/service.js +55 -51
  8. package/dist/assets/types.d.ts +2 -2
  9. package/dist/assets/utils/index.d.ts +1 -1
  10. package/dist/assets/utils/index.js +4 -4
  11. package/dist/assets/vite-plugin-assets.js +30 -15
  12. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  13. package/dist/container/vite-plugin-container.js +7 -4
  14. package/dist/content/content-layer.js +3 -3
  15. package/dist/content/types-generator.js +10 -1
  16. package/dist/content/utils.js +9 -2
  17. package/dist/content/vite-plugin-content-assets.js +59 -53
  18. package/dist/content/vite-plugin-content-imports.js +48 -36
  19. package/dist/content/vite-plugin-content-virtual-mod.js +90 -75
  20. package/dist/core/app/validate-forwarded-headers.d.ts +1 -1
  21. package/dist/core/app/validate-forwarded-headers.js +1 -1
  22. package/dist/core/build/plugins/plugin-component-entry.js +10 -4
  23. package/dist/core/build/plugins/plugin-css.js +6 -2
  24. package/dist/core/build/plugins/plugin-noop.js +10 -4
  25. package/dist/core/build/plugins/plugin-ssr.js +30 -12
  26. package/dist/core/constants.js +1 -1
  27. package/dist/core/create-vite.js +5 -5
  28. package/dist/core/dev/dev.js +1 -1
  29. package/dist/core/errors/errors-data.d.ts +5 -9
  30. package/dist/core/errors/errors-data.js +6 -6
  31. package/dist/core/messages.js +2 -2
  32. package/dist/core/middleware/vite-plugin.js +24 -18
  33. package/dist/core/server-islands/vite-plugin-server-islands.js +70 -55
  34. package/dist/core/session/vite-plugin.js +10 -4
  35. package/dist/core/viteUtils.d.ts +1 -0
  36. package/dist/core/viteUtils.js +2 -0
  37. package/dist/env/vite-plugin-env.js +52 -38
  38. package/dist/env/vite-plugin-import-meta-env.js +44 -37
  39. package/dist/i18n/vite-plugin-i18n.js +7 -4
  40. package/dist/manifest/serialized.js +10 -4
  41. package/dist/manifest/virtual-module.js +29 -17
  42. package/dist/prefetch/vite-plugin-prefetch.js +20 -9
  43. package/dist/toolbar/vite-plugin-dev-toolbar.js +13 -7
  44. package/dist/transitions/vite-plugin-transitions.js +35 -22
  45. package/dist/types/public/config.d.ts +38 -5
  46. package/dist/types/public/extendables.d.ts +2 -0
  47. package/dist/vite-plugin-adapter-config/index.js +10 -4
  48. package/dist/vite-plugin-app/index.js +6 -3
  49. package/dist/vite-plugin-app/pipeline.js +1 -1
  50. package/dist/vite-plugin-astro/index.js +211 -180
  51. package/dist/vite-plugin-astro-server/index.d.ts +1 -1
  52. package/dist/vite-plugin-astro-server/index.js +2 -6
  53. package/dist/vite-plugin-astro-server/plugin.d.ts +0 -1
  54. package/dist/vite-plugin-astro-server/plugin.js +0 -57
  55. package/dist/vite-plugin-astro-server/util.d.ts +2 -0
  56. package/dist/vite-plugin-astro-server/util.js +3 -1
  57. package/dist/vite-plugin-chromedevtools/index.d.ts +7 -0
  58. package/dist/vite-plugin-chromedevtools/index.js +47 -0
  59. package/dist/vite-plugin-config-alias/index.js +19 -12
  60. package/dist/vite-plugin-css/index.js +73 -52
  61. package/dist/vite-plugin-fileurl/index.js +6 -3
  62. package/dist/vite-plugin-html/index.d.ts +7 -4
  63. package/dist/vite-plugin-html/index.js +5 -3
  64. package/dist/vite-plugin-load-fallback/index.js +12 -5
  65. package/dist/vite-plugin-markdown/index.js +27 -8
  66. package/dist/vite-plugin-overlay/index.d.ts +2 -0
  67. package/dist/vite-plugin-overlay/index.js +21 -0
  68. package/dist/vite-plugin-pages/page.js +10 -4
  69. package/dist/vite-plugin-pages/pages.js +10 -4
  70. package/dist/vite-plugin-renderers/index.js +11 -6
  71. package/dist/vite-plugin-routes/index.js +14 -10
  72. package/dist/vite-plugin-scripts/index.js +25 -19
  73. package/dist/vite-plugin-utils/index.d.ts +1 -0
  74. package/dist/vite-plugin-utils/index.js +2 -1
  75. package/package.json +3 -3
  76. package/dist/assets/utils/remotePattern.d.ts +0 -1
  77. package/dist/assets/utils/remotePattern.js +0 -16
@@ -2,7 +2,6 @@ import { extname } from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { isRunnableDevEnvironment } from "vite";
4
4
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
5
- import { createViteLoader } from "../core/module-loader/vite.js";
6
5
  import { wrapId } from "../core/util.js";
7
6
  import { isBuildableCSSRequest } from "../vite-plugin-astro-server/util.js";
8
7
  import { crawlGraph } from "../vite-plugin-astro-server/vite.js";
@@ -20,72 +19,78 @@ import { isAstroServerEnvironment } from "../environments.js";
20
19
  function astroContentAssetPropagationPlugin({
21
20
  settings
22
21
  }) {
23
- let devModuleLoader;
22
+ let environment = void 0;
24
23
  return {
25
24
  name: "astro:content-asset-propagation",
26
25
  enforce: "pre",
27
- async resolveId(id, importer, opts) {
28
- if (hasContentFlag(id, CONTENT_IMAGE_FLAG)) {
29
- const [base, query] = id.split("?");
30
- const params = new URLSearchParams(query);
31
- const importerParam = params.get("importer");
32
- const importerPath = importerParam ? fileURLToPath(new URL(importerParam, settings.config.root)) : importer;
33
- const resolved = await this.resolve(base, importerPath, { skipSelf: true, ...opts });
34
- if (!resolved) {
35
- throw new AstroError({
36
- ...AstroErrorData.ImageNotFound,
37
- message: AstroErrorData.ImageNotFound.message(base)
38
- });
39
- }
40
- return resolved;
41
- }
42
- if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
43
- const base = id.split("?")[0];
44
- for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
45
- if (handlePropagation && extensions.includes(extname(base))) {
46
- return this.resolve(`${base}?${PROPAGATED_ASSET_FLAG}`, importer, {
47
- skipSelf: true,
48
- ...opts
26
+ resolveId: {
27
+ filter: {
28
+ id: new RegExp(`(?:\\?|&)(?:${CONTENT_IMAGE_FLAG}|${CONTENT_RENDER_FLAG})(?:&|=|$)`)
29
+ },
30
+ async handler(id, importer, opts) {
31
+ if (hasContentFlag(id, CONTENT_IMAGE_FLAG)) {
32
+ const [base, query] = id.split("?");
33
+ const params = new URLSearchParams(query);
34
+ const importerParam = params.get("importer");
35
+ const importerPath = importerParam ? fileURLToPath(new URL(importerParam, settings.config.root)) : importer;
36
+ const resolved = await this.resolve(base, importerPath, { skipSelf: true, ...opts });
37
+ if (!resolved) {
38
+ throw new AstroError({
39
+ ...AstroErrorData.ImageNotFound,
40
+ message: AstroErrorData.ImageNotFound.message(base)
49
41
  });
50
42
  }
43
+ return resolved;
44
+ }
45
+ if (hasContentFlag(id, CONTENT_RENDER_FLAG)) {
46
+ const base = id.split("?")[0];
47
+ for (const { extensions, handlePropagation = true } of settings.contentEntryTypes) {
48
+ if (handlePropagation && extensions.includes(extname(base))) {
49
+ return this.resolve(`${base}?${PROPAGATED_ASSET_FLAG}`, importer, {
50
+ skipSelf: true,
51
+ ...opts
52
+ });
53
+ }
54
+ }
55
+ return this.resolve(base, importer, { skipSelf: true, ...opts });
51
56
  }
52
- return this.resolve(base, importer, { skipSelf: true, ...opts });
53
57
  }
54
58
  },
55
59
  configureServer(server) {
56
60
  if (!isRunnableDevEnvironment(server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr])) {
57
61
  return;
58
62
  }
59
- devModuleLoader = createViteLoader(
60
- server,
61
- server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr]
62
- );
63
+ environment = server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
63
64
  },
64
- async transform(_, id) {
65
- if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
66
- const basePath = id.split("?")[0];
67
- let stringifiedLinks, stringifiedStyles;
68
- if (isAstroServerEnvironment(this.environment) && devModuleLoader) {
69
- if (!devModuleLoader.getModuleById(basePath)?.ssrModule) {
70
- await devModuleLoader.import(basePath);
71
- }
72
- const {
73
- styles,
74
- urls,
75
- crawledFiles: styleCrawledFiles
76
- } = await getStylesForURL(basePath, devModuleLoader.getSSREnvironment());
77
- for (const file of styleCrawledFiles) {
78
- if (!file.includes("node_modules")) {
79
- this.addWatchFile(file);
65
+ transform: {
66
+ filter: {
67
+ id: new RegExp(`(?:\\?|&)${PROPAGATED_ASSET_FLAG}(?:&|=|$)`)
68
+ },
69
+ async handler(_, id) {
70
+ if (hasContentFlag(id, PROPAGATED_ASSET_FLAG)) {
71
+ const basePath = id.split("?")[0];
72
+ let stringifiedLinks, stringifiedStyles;
73
+ if (isAstroServerEnvironment(this.environment) && environment) {
74
+ if (!environment.moduleGraph.getModuleById(basePath)?.ssrModule) {
75
+ await environment.runner.import(basePath);
76
+ }
77
+ const {
78
+ styles,
79
+ urls,
80
+ crawledFiles: styleCrawledFiles
81
+ } = await getStylesForURL(basePath, environment);
82
+ for (const file of styleCrawledFiles) {
83
+ if (!file.includes("node_modules")) {
84
+ this.addWatchFile(file);
85
+ }
80
86
  }
87
+ stringifiedLinks = JSON.stringify([...urls]);
88
+ stringifiedStyles = JSON.stringify(styles.map((s) => s.content));
89
+ } else {
90
+ stringifiedLinks = JSON.stringify(LINKS_PLACEHOLDER);
91
+ stringifiedStyles = JSON.stringify(STYLES_PLACEHOLDER);
81
92
  }
82
- stringifiedLinks = JSON.stringify([...urls]);
83
- stringifiedStyles = JSON.stringify(styles.map((s) => s.content));
84
- } else {
85
- stringifiedLinks = JSON.stringify(LINKS_PLACEHOLDER);
86
- stringifiedStyles = JSON.stringify(STYLES_PLACEHOLDER);
87
- }
88
- const code = `
93
+ const code = `
89
94
  async function getMod() {
90
95
  return import(${JSON.stringify(basePath)});
91
96
  }
@@ -94,7 +99,8 @@ function astroContentAssetPropagationPlugin({
94
99
  const defaultMod = { __astroPropagation: true, getMod, collectedLinks, collectedStyles, collectedScripts: [] };
95
100
  export default defaultMod;
96
101
  `;
97
- return { code, map: { mappings: "" } };
102
+ return { code, map: { mappings: "" } };
103
+ }
98
104
  }
99
105
  }
100
106
  };
@@ -57,23 +57,27 @@ function astroContentImportPlugin({
57
57
  async buildStart() {
58
58
  symlinks = await getSymlinkedContentCollections({ contentDir, logger, fs });
59
59
  },
60
- async transform(_, viteId) {
61
- if (hasContentFlag(viteId, DATA_FLAG)) {
62
- const fileId = reverseSymlink({
63
- entry: viteId.split("?")[0] ?? viteId,
64
- contentDir,
65
- symlinks
66
- });
67
- const { id, data, collection, _internal } = await getDataEntryModule({
68
- fileId,
69
- entryConfigByExt: dataEntryConfigByExt,
70
- contentDir,
71
- config: settings.config,
72
- fs,
73
- pluginContext: this,
74
- shouldEmitFile
75
- });
76
- const code = `
60
+ transform: {
61
+ filter: {
62
+ id: new RegExp(`(?:\\?|&)(?:${DATA_FLAG}|${CONTENT_FLAG})(?:&|=|$)`)
63
+ },
64
+ async handler(_, viteId) {
65
+ if (hasContentFlag(viteId, DATA_FLAG)) {
66
+ const fileId = reverseSymlink({
67
+ entry: viteId.split("?")[0] ?? viteId,
68
+ contentDir,
69
+ symlinks
70
+ });
71
+ const { id, data, collection, _internal } = await getDataEntryModule({
72
+ fileId,
73
+ entryConfigByExt: dataEntryConfigByExt,
74
+ contentDir,
75
+ config: settings.config,
76
+ fs,
77
+ pluginContext: this,
78
+ shouldEmitFile
79
+ });
80
+ const code = `
77
81
  export const id = ${JSON.stringify(id)};
78
82
  export const collection = ${JSON.stringify(collection)};
79
83
  export const data = ${stringifyEntryData(data, settings.buildOutput === "server")};
@@ -83,19 +87,19 @@ export const _internal = {
83
87
  rawData: ${JSON.stringify(_internal.rawData)},
84
88
  };
85
89
  `;
86
- return code;
87
- } else if (hasContentFlag(viteId, CONTENT_FLAG)) {
88
- const fileId = reverseSymlink({ entry: viteId.split("?")[0], contentDir, symlinks });
89
- const { id, slug, collection, body, data, _internal } = await getContentEntryModule({
90
- fileId,
91
- entryConfigByExt: contentEntryConfigByExt,
92
- contentDir,
93
- config: settings.config,
94
- fs,
95
- pluginContext: this,
96
- shouldEmitFile
97
- });
98
- const code = `
90
+ return code;
91
+ } else if (hasContentFlag(viteId, CONTENT_FLAG)) {
92
+ const fileId = reverseSymlink({ entry: viteId.split("?")[0], contentDir, symlinks });
93
+ const { id, slug, collection, body, data, _internal } = await getContentEntryModule({
94
+ fileId,
95
+ entryConfigByExt: contentEntryConfigByExt,
96
+ contentDir,
97
+ config: settings.config,
98
+ fs,
99
+ pluginContext: this,
100
+ shouldEmitFile
101
+ });
102
+ const code = `
99
103
  export const id = ${JSON.stringify(id)};
100
104
  export const collection = ${JSON.stringify(collection)};
101
105
  export const slug = ${JSON.stringify(slug)};
@@ -106,7 +110,8 @@ export const _internal = {
106
110
  filePath: ${JSON.stringify(_internal.filePath)},
107
111
  rawData: ${JSON.stringify(_internal.rawData)},
108
112
  };`;
109
- return { code, map: { mappings: "" } };
113
+ return { code, map: { mappings: "" } };
114
+ }
110
115
  }
111
116
  },
112
117
  configureServer(viteServer) {
@@ -143,11 +148,18 @@ export const _internal = {
143
148
  if (settings.contentEntryTypes.some((t) => t.getRenderModule)) {
144
149
  plugins.push({
145
150
  name: "astro:content-render-imports",
146
- async transform(contents, viteId) {
147
- const contentRenderer = getContentRendererByViteId(viteId, settings);
148
- if (!contentRenderer) return;
149
- const fileId = viteId.split("?")[0];
150
- return contentRenderer.bind(this)({ viteId, contents, fileUrl: pathToFileURL(fileId) });
151
+ transform: {
152
+ filter: {
153
+ id: {
154
+ include: settings.contentEntryTypes.filter((t) => t.getRenderModule).map((t) => new RegExp(`\\.(${t.extensions.map((e) => e.slice(1)).join("|")})$`))
155
+ }
156
+ },
157
+ async handler(contents, viteId) {
158
+ const contentRenderer = getContentRendererByViteId(viteId, settings);
159
+ if (!contentRenderer) return;
160
+ const fileId = viteId.split("?")[0];
161
+ return contentRenderer.bind(this)({ viteId, contents, fileUrl: pathToFileURL(fileId) });
162
+ }
151
163
  }
152
164
  });
153
165
  }
@@ -1,15 +1,17 @@
1
- import { dataToEsm } from "@rollup/pluginutils";
2
1
  import nodeFs from "node:fs";
3
2
  import { fileURLToPath } from "node:url";
3
+ import { dataToEsm } from "@rollup/pluginutils";
4
4
  import { normalizePath } from "vite";
5
5
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
6
6
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
7
7
  import { rootRelativePath } from "../core/viteUtils.js";
8
+ import { isAstroClientEnvironment } from "../environments.js";
8
9
  import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
9
10
  import {
10
11
  ASSET_IMPORTS_FILE,
11
12
  ASSET_IMPORTS_RESOLVED_STUB_ID,
12
13
  ASSET_IMPORTS_VIRTUAL_ID,
14
+ CONTENT_MODULE_FLAG,
13
15
  CONTENT_RENDER_FLAG,
14
16
  DATA_STORE_VIRTUAL_ID,
15
17
  MODULES_IMPORTS_FILE,
@@ -21,7 +23,6 @@ import {
21
23
  } from "./consts.js";
22
24
  import { getDataStoreFile } from "./content-layer.js";
23
25
  import { getContentPaths, isDeferredModule } from "./utils.js";
24
- import { isAstroClientEnvironment } from "../environments.js";
25
26
  function invalidateDataStore(viteServer) {
26
27
  const environment = viteServer.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
27
28
  const module = environment.moduleGraph.getModuleById(RESOLVED_DATA_STORE_VIRTUAL_ID);
@@ -56,91 +57,105 @@ function astroContentVirtualModPlugin({
56
57
  invalidateDataStore(devServer);
57
58
  }
58
59
  },
59
- async resolveId(id, importer) {
60
- if (id === VIRTUAL_MODULE_ID) {
61
- if (liveConfig && importer && liveConfig === normalizePath(importer)) {
62
- return this.resolve("astro/virtual-modules/live-config", importer, {
63
- skipSelf: true
64
- });
60
+ resolveId: {
61
+ filter: {
62
+ id: new RegExp(
63
+ `^(${VIRTUAL_MODULE_ID}|${DATA_STORE_VIRTUAL_ID}|${MODULES_MJS_ID}|${ASSET_IMPORTS_VIRTUAL_ID})$|(?:\\?|&)${CONTENT_MODULE_FLAG}(?:&|=|$)`
64
+ )
65
+ },
66
+ async handler(id, importer) {
67
+ if (id === VIRTUAL_MODULE_ID) {
68
+ if (liveConfig && importer && liveConfig === normalizePath(importer)) {
69
+ return this.resolve("astro/virtual-modules/live-config", importer, {
70
+ skipSelf: true
71
+ });
72
+ }
73
+ return RESOLVED_VIRTUAL_MODULE_ID;
65
74
  }
66
- return RESOLVED_VIRTUAL_MODULE_ID;
67
- }
68
- if (id === DATA_STORE_VIRTUAL_ID) {
69
- return RESOLVED_DATA_STORE_VIRTUAL_ID;
70
- }
71
- if (isDeferredModule(id)) {
72
- const [, query] = id.split("?");
73
- const params = new URLSearchParams(query);
74
- const fileName = params.get("fileName");
75
- let importPath = void 0;
76
- if (fileName && URL.canParse(fileName, settings.config.root.toString())) {
77
- importPath = fileURLToPath(new URL(fileName, settings.config.root));
75
+ if (id === DATA_STORE_VIRTUAL_ID) {
76
+ return RESOLVED_DATA_STORE_VIRTUAL_ID;
78
77
  }
79
- if (importPath) {
80
- return await this.resolve(`${importPath}?${CONTENT_RENDER_FLAG}`);
78
+ if (isDeferredModule(id)) {
79
+ const [, query] = id.split("?");
80
+ const params = new URLSearchParams(query);
81
+ const fileName = params.get("fileName");
82
+ let importPath = void 0;
83
+ if (fileName && URL.canParse(fileName, settings.config.root.toString())) {
84
+ importPath = fileURLToPath(new URL(fileName, settings.config.root));
85
+ }
86
+ if (importPath) {
87
+ return await this.resolve(`${importPath}?${CONTENT_RENDER_FLAG}`);
88
+ }
81
89
  }
82
- }
83
- if (id === MODULES_MJS_ID) {
84
- const modules = new URL(MODULES_IMPORTS_FILE, settings.dotAstroDir);
85
- if (fs.existsSync(modules)) {
86
- return fileURLToPath(modules);
90
+ if (id === MODULES_MJS_ID) {
91
+ const modules = new URL(MODULES_IMPORTS_FILE, settings.dotAstroDir);
92
+ if (fs.existsSync(modules)) {
93
+ return fileURLToPath(modules);
94
+ }
95
+ return MODULES_MJS_VIRTUAL_ID;
87
96
  }
88
- return MODULES_MJS_VIRTUAL_ID;
89
- }
90
- if (id === ASSET_IMPORTS_VIRTUAL_ID) {
91
- const assetImportsFile = new URL(ASSET_IMPORTS_FILE, settings.dotAstroDir);
92
- if (fs.existsSync(assetImportsFile)) {
93
- return fileURLToPath(assetImportsFile);
97
+ if (id === ASSET_IMPORTS_VIRTUAL_ID) {
98
+ const assetImportsFile = new URL(ASSET_IMPORTS_FILE, settings.dotAstroDir);
99
+ if (fs.existsSync(assetImportsFile)) {
100
+ return fileURLToPath(assetImportsFile);
101
+ }
102
+ return ASSET_IMPORTS_RESOLVED_STUB_ID;
94
103
  }
95
- return ASSET_IMPORTS_RESOLVED_STUB_ID;
96
104
  }
97
105
  },
98
- async load(id) {
99
- if (id === RESOLVED_VIRTUAL_MODULE_ID) {
100
- const isClient = isAstroClientEnvironment(this.environment);
101
- const code = await generateContentEntryFile({
102
- settings,
103
- fs,
104
- isClient
105
- });
106
- const astro = createDefaultAstroMetadata();
107
- astro.propagation = "in-tree";
108
- return {
109
- code,
110
- meta: {
111
- astro
106
+ load: {
107
+ filter: {
108
+ id: new RegExp(
109
+ `^(${RESOLVED_VIRTUAL_MODULE_ID}|${RESOLVED_DATA_STORE_VIRTUAL_ID}|${ASSET_IMPORTS_RESOLVED_STUB_ID}|${MODULES_MJS_VIRTUAL_ID})$`
110
+ )
111
+ },
112
+ async handler(id) {
113
+ if (id === RESOLVED_VIRTUAL_MODULE_ID) {
114
+ const isClient = isAstroClientEnvironment(this.environment);
115
+ const code = await generateContentEntryFile({
116
+ settings,
117
+ fs,
118
+ isClient
119
+ });
120
+ const astro = createDefaultAstroMetadata();
121
+ astro.propagation = "in-tree";
122
+ return {
123
+ code,
124
+ meta: {
125
+ astro
126
+ }
127
+ };
128
+ }
129
+ if (id === RESOLVED_DATA_STORE_VIRTUAL_ID) {
130
+ if (!fs.existsSync(dataStoreFile)) {
131
+ return { code: "export default new Map()" };
132
+ }
133
+ const jsonData = await fs.promises.readFile(dataStoreFile, "utf-8");
134
+ try {
135
+ const parsed = JSON.parse(jsonData);
136
+ return {
137
+ code: dataToEsm(parsed, {
138
+ compact: true
139
+ }),
140
+ map: { mappings: "" }
141
+ };
142
+ } catch (err) {
143
+ const message = "Could not parse JSON file";
144
+ this.error({ message, id, cause: err });
112
145
  }
113
- };
114
- }
115
- if (id === RESOLVED_DATA_STORE_VIRTUAL_ID) {
116
- if (!fs.existsSync(dataStoreFile)) {
117
- return { code: "export default new Map()" };
118
146
  }
119
- const jsonData = await fs.promises.readFile(dataStoreFile, "utf-8");
120
- try {
121
- const parsed = JSON.parse(jsonData);
147
+ if (id === ASSET_IMPORTS_RESOLVED_STUB_ID) {
148
+ const assetImportsFile = new URL(ASSET_IMPORTS_FILE, settings.dotAstroDir);
122
149
  return {
123
- code: dataToEsm(parsed, {
124
- compact: true
125
- }),
126
- map: { mappings: "" }
150
+ code: fs.existsSync(assetImportsFile) ? fs.readFileSync(assetImportsFile, "utf-8") : "export default new Map()"
151
+ };
152
+ }
153
+ if (id === MODULES_MJS_VIRTUAL_ID) {
154
+ const modules = new URL(MODULES_IMPORTS_FILE, settings.dotAstroDir);
155
+ return {
156
+ code: fs.existsSync(modules) ? fs.readFileSync(modules, "utf-8") : "export default new Map()"
127
157
  };
128
- } catch (err) {
129
- const message = "Could not parse JSON file";
130
- this.error({ message, id, cause: err });
131
158
  }
132
- }
133
- if (id === ASSET_IMPORTS_RESOLVED_STUB_ID) {
134
- const assetImportsFile = new URL(ASSET_IMPORTS_FILE, settings.dotAstroDir);
135
- return {
136
- code: fs.existsSync(assetImportsFile) ? fs.readFileSync(assetImportsFile, "utf-8") : "export default new Map()"
137
- };
138
- }
139
- if (id === MODULES_MJS_VIRTUAL_ID) {
140
- const modules = new URL(MODULES_IMPORTS_FILE, settings.dotAstroDir);
141
- return {
142
- code: fs.existsSync(modules) ? fs.readFileSync(modules, "utf-8") : "export default new Map()"
143
- };
144
159
  }
145
160
  },
146
161
  configureServer(server) {
@@ -1,4 +1,4 @@
1
- import { type RemotePattern } from '../../assets/utils/remotePattern.js';
1
+ import { type RemotePattern } from '@astrojs/internal-helpers/remote';
2
2
  /**
3
3
  * Validate a hostname by rejecting any with path separators.
4
4
  * Prevents path injection attacks. Invalid hostnames return undefined.
@@ -1,4 +1,4 @@
1
- import { matchPattern } from "../../assets/utils/remotePattern.js";
1
+ import { matchPattern } from "@astrojs/internal-helpers/remote";
2
2
  function sanitizeHost(hostname) {
3
3
  if (!hostname) return void 0;
4
4
  if (/[/\\]/.test(hostname)) return void 0;
@@ -38,13 +38,19 @@ function pluginComponentEntry(internals) {
38
38
  });
39
39
  }
40
40
  },
41
- async resolveId(id) {
42
- if (id.startsWith(astroEntryPrefix)) {
41
+ resolveId: {
42
+ filter: {
43
+ id: new RegExp(`^${astroEntryPrefix}`)
44
+ },
45
+ handler(id) {
43
46
  return id;
44
47
  }
45
48
  },
46
- async load(id) {
47
- if (id.startsWith(astroEntryPrefix)) {
49
+ load: {
50
+ filter: {
51
+ id: new RegExp(`^${astroEntryPrefix}`)
52
+ },
53
+ async handler(id) {
48
54
  const componentId = id.slice(astroEntryPrefix.length);
49
55
  const exportNames = componentToExportNames.get(componentId);
50
56
  if (exportNames) {
@@ -8,6 +8,7 @@ import {
8
8
  import { getPageDataByViteID, getPageDatasByClientOnlyID } from "../internal.js";
9
9
  import { shouldInlineAsset } from "./util.js";
10
10
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../../constants.js";
11
+ import { CSS_LANGS_RE } from "../../viteUtils.js";
11
12
  function pluginCSS(options, internals) {
12
13
  return rollupPluginAstroBuildCSS({
13
14
  buildOptions: options,
@@ -26,8 +27,11 @@ function rollupPluginAstroBuildCSS(options) {
26
27
  applyToEnvironment(environment) {
27
28
  return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.client || environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr || environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender;
28
29
  },
29
- transform(_code, id) {
30
- if (isCSSRequest(id)) {
30
+ transform: {
31
+ filter: {
32
+ id: CSS_LANGS_RE
33
+ },
34
+ handler(_code, id) {
31
35
  if (this.environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender) {
32
36
  if (cssModulesInBundles.has(id)) {
33
37
  return {
@@ -3,13 +3,19 @@ const RESOLVED_NOOP_MODULE_ID = "\0" + NOOP_MODULE_ID;
3
3
  function pluginNoop() {
4
4
  return {
5
5
  name: "plugin-noop",
6
- resolveId(id) {
7
- if (id === NOOP_MODULE_ID) {
6
+ resolveId: {
7
+ filter: {
8
+ id: new RegExp(`^${NOOP_MODULE_ID}$`)
9
+ },
10
+ handler() {
8
11
  return RESOLVED_NOOP_MODULE_ID;
9
12
  }
10
13
  },
11
- load(id) {
12
- if (id === RESOLVED_NOOP_MODULE_ID) {
14
+ load: {
15
+ filter: {
16
+ id: new RegExp(`^${RESOLVED_NOOP_MODULE_ID}$`)
17
+ },
18
+ handler() {
13
19
  return "export const noop = {};";
14
20
  }
15
21
  },
@@ -12,13 +12,19 @@ function vitePluginAdapter(adapter) {
12
12
  applyToEnvironment(environment) {
13
13
  return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr;
14
14
  },
15
- resolveId(id) {
16
- if (id === ADAPTER_VIRTUAL_MODULE_ID) {
15
+ resolveId: {
16
+ filter: {
17
+ id: new RegExp(`^${ADAPTER_VIRTUAL_MODULE_ID}$`)
18
+ },
19
+ handler() {
17
20
  return RESOLVED_ADAPTER_VIRTUAL_MODULE_ID;
18
21
  }
19
22
  },
20
- async load(id) {
21
- if (id === RESOLVED_ADAPTER_VIRTUAL_MODULE_ID) {
23
+ load: {
24
+ filter: {
25
+ id: new RegExp(`^${RESOLVED_ADAPTER_VIRTUAL_MODULE_ID}$`)
26
+ },
27
+ async handler() {
22
28
  const adapterEntrypointStr = JSON.stringify(adapter.serverEntrypoint);
23
29
  return {
24
30
  code: `export * from ${adapterEntrypointStr};
@@ -36,13 +42,19 @@ function vitePluginAdapterConfig(adapter) {
36
42
  applyToEnvironment(environment) {
37
43
  return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr;
38
44
  },
39
- resolveId(id) {
40
- if (id === ADAPTER_CONFIG_VIRTUAL_MODULE_ID) {
45
+ resolveId: {
46
+ filter: {
47
+ id: new RegExp(`^${ADAPTER_CONFIG_VIRTUAL_MODULE_ID}$`)
48
+ },
49
+ handler() {
41
50
  return RESOLVED_ADAPTER_CONFIG_VIRTUAL_MODULE_ID;
42
51
  }
43
52
  },
44
- load(id) {
45
- if (id === RESOLVED_ADAPTER_CONFIG_VIRTUAL_MODULE_ID) {
53
+ load: {
54
+ filter: {
55
+ id: new RegExp(`^${RESOLVED_ADAPTER_CONFIG_VIRTUAL_MODULE_ID}$`)
56
+ },
57
+ handler() {
46
58
  return {
47
59
  code: `export const args = ${adapter.args ? JSON.stringify(adapter.args, null, 2) : "undefined"};
48
60
  export const exports = ${adapter.exports ? JSON.stringify(adapter.exports) : "undefined"};
@@ -60,13 +72,19 @@ function vitePluginSSR(internals, adapter) {
60
72
  applyToEnvironment(environment) {
61
73
  return environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr;
62
74
  },
63
- resolveId(id) {
64
- if (id === SSR_VIRTUAL_MODULE_ID) {
75
+ resolveId: {
76
+ filter: {
77
+ id: new RegExp(`^${SSR_VIRTUAL_MODULE_ID}$`)
78
+ },
79
+ handler() {
65
80
  return RESOLVED_SSR_VIRTUAL_MODULE_ID;
66
81
  }
67
82
  },
68
- load(id) {
69
- if (id === RESOLVED_SSR_VIRTUAL_MODULE_ID) {
83
+ load: {
84
+ filter: {
85
+ id: new RegExp(`^${RESOLVED_SSR_VIRTUAL_MODULE_ID}$`)
86
+ },
87
+ handler() {
70
88
  const exports = [];
71
89
  if (adapter.exports) {
72
90
  exports.push(
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "6.0.0-alpha.1";
1
+ const ASTRO_VERSION = "6.0.0-alpha.2";
2
2
  const ASTRO_GENERATOR = `Astro v${ASTRO_VERSION}`;
3
3
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
4
4
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
@@ -23,10 +23,7 @@ import astroTransitions from "../transitions/vite-plugin-transitions.js";
23
23
  import { vitePluginAdapterConfig } from "../vite-plugin-adapter-config/index.js";
24
24
  import { vitePluginApp } from "../vite-plugin-app/index.js";
25
25
  import astroVitePlugin from "../vite-plugin-astro/index.js";
26
- import {
27
- vitePluginAstroServer,
28
- vitePluginAstroServerClient
29
- } from "../vite-plugin-astro-server/index.js";
26
+ import { vitePluginAstroServer } from "../vite-plugin-astro-server/index.js";
30
27
  import configAliasVitePlugin from "../vite-plugin-config-alias/index.js";
31
28
  import { astroDevCssPlugin } from "../vite-plugin-css/index.js";
32
29
  import vitePluginFileURL from "../vite-plugin-fileurl/index.js";
@@ -49,6 +46,8 @@ import { vitePluginSessionDriver } from "./session/vite-plugin.js";
49
46
  import { isObject } from "./util.js";
50
47
  import { vitePluginEnvironment } from "../vite-plugin-environment/index.js";
51
48
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "./constants.js";
49
+ import { vitePluginChromedevtools } from "../vite-plugin-chromedevtools/index.js";
50
+ import { vitePluginAstroServerClient } from "../vite-plugin-overlay/index.js";
52
51
  async function createVite(commandConfig, { settings, logger, mode, command, fs = nodeFs, sync, routesList }) {
53
52
  const astroPkgsConfig = await crawlFrameworkPkgs({
54
53
  root: fileURLToPath(settings.config.root),
@@ -128,7 +127,8 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
128
127
  vitePluginServerIslands({ settings, logger }),
129
128
  vitePluginSessionDriver({ settings }),
130
129
  astroContainer(),
131
- astroHmrReloadPlugin()
130
+ astroHmrReloadPlugin(),
131
+ vitePluginChromedevtools({ settings })
132
132
  ],
133
133
  publicDir: fileURLToPath(settings.config.publicDir),
134
134
  root: fileURLToPath(settings.config.root),