astro 2.2.2 → 2.3.0

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 (50) hide show
  1. package/dist/assets/consts.d.ts +3 -2
  2. package/dist/assets/consts.js +4 -1
  3. package/dist/assets/services/service.js +3 -3
  4. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm.d.ts +3 -0
  5. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.wasm.js +4 -0
  6. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm.d.ts +3 -0
  7. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.wasm.js +4 -0
  8. package/dist/assets/services/vendor/squoosh/codecs.js +24 -25
  9. package/dist/assets/services/vendor/squoosh/emscripten-utils.d.ts +2 -2
  10. package/dist/assets/services/vendor/squoosh/emscripten-utils.js +6 -8
  11. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm.d.ts +3 -0
  12. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.wasm.js +4 -0
  13. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm.d.ts +3 -0
  14. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.wasm.js +4 -0
  15. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm.d.ts +3 -0
  16. package/dist/assets/services/vendor/squoosh/png/squoosh_oxipng_bg.wasm.js +4 -0
  17. package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm.d.ts +3 -0
  18. package/dist/assets/services/vendor/squoosh/png/squoosh_png_bg.wasm.js +4 -0
  19. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm.d.ts +3 -0
  20. package/dist/assets/services/vendor/squoosh/resize/squoosh_resize_bg.wasm.js +4 -0
  21. package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm.d.ts +3 -0
  22. package/dist/assets/services/vendor/squoosh/rotate/rotate.wasm.js +4 -0
  23. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm.d.ts +3 -0
  24. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.wasm.js +4 -0
  25. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm.d.ts +3 -0
  26. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.wasm.js +4 -0
  27. package/dist/assets/types.d.ts +1 -1
  28. package/dist/assets/vite-plugin-assets.js +0 -10
  29. package/dist/content/index.d.ts +1 -0
  30. package/dist/content/index.js +3 -0
  31. package/dist/content/runtime-assets.d.ts +1 -1
  32. package/dist/content/runtime-assets.js +1 -1
  33. package/dist/content/types-generator.js +6 -1
  34. package/dist/content/utils.d.ts +1 -1
  35. package/dist/content/utils.js +6 -2
  36. package/dist/content/vite-plugin-content-assets.js +33 -34
  37. package/dist/content/vite-plugin-content-imports.js +23 -24
  38. package/dist/core/build/generate.js +0 -4
  39. package/dist/core/build/plugins/plugin-css.js +7 -9
  40. package/dist/core/build/static-build.js +4 -1
  41. package/dist/core/constants.js +1 -1
  42. package/dist/core/dev/dev.js +1 -1
  43. package/dist/core/messages.js +2 -2
  44. package/dist/runtime/server/render/slot.js +1 -1
  45. package/dist/vite-plugin-config-alias/index.d.ts +2 -7
  46. package/dist/vite-plugin-config-alias/index.js +59 -34
  47. package/dist/vite-plugin-jsx/index.js +7 -0
  48. package/package.json +5 -5
  49. package/dist/assets/services/vendor/squoosh/copy-wasm.d.ts +0 -2
  50. package/dist/assets/services/vendor/squoosh/copy-wasm.js +0 -37
@@ -2,7 +2,7 @@ import type { VALID_INPUT_FORMATS, VALID_OUTPUT_FORMATS } from './consts.js';
2
2
  import type { ImageService } from './services/service.js';
3
3
  export type ImageQualityPreset = 'low' | 'mid' | 'high' | 'max' | (string & {});
4
4
  export type ImageQuality = ImageQualityPreset | number;
5
- export type ImageInputFormat = (typeof VALID_INPUT_FORMATS)[number] | 'svg';
5
+ export type ImageInputFormat = (typeof VALID_INPUT_FORMATS)[number];
6
6
  export type ImageOutputFormat = (typeof VALID_OUTPUT_FORMATS)[number] | (string & {});
7
7
  declare global {
8
8
  var astroAsset: {
@@ -10,7 +10,6 @@ import { appendForwardSlash, joinPaths, prependForwardSlash } from "../core/path
10
10
  import { VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
11
11
  import { isESMImportedImage } from "./internal.js";
12
12
  import { isLocalService } from "./services/service.js";
13
- import { copyWasmFiles } from "./services/vendor/squoosh/copy-wasm.js";
14
13
  import { emitESMImage } from "./utils/emitAsset.js";
15
14
  import { imageMetadata } from "./utils/metadata.js";
16
15
  import { getOrigQueryParams } from "./utils/queryParams.js";
@@ -143,15 +142,6 @@ function assets({
143
142
  }
144
143
  };
145
144
  },
146
- async buildEnd() {
147
- if (mode != "build") {
148
- return;
149
- }
150
- if (settings.config.image.service === "astro/assets/services/squoosh") {
151
- const dir = settings.config.output === "server" ? settings.config.build.server : settings.config.outDir;
152
- await copyWasmFiles(new URL("./chunks", dir));
153
- }
154
- },
155
145
  // In build, rewrite paths to ESM imported images in code to their final location
156
146
  async renderChunk(code) {
157
147
  const assetUrlRE = /__ASTRO_ASSET_IMAGE__([a-z\d]{8})__(?:_(.*?)__)?/g;
@@ -1,3 +1,4 @@
1
+ export { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from './consts.js';
1
2
  export { errorMap } from './error-map.js';
2
3
  export { attachContentServerListeners } from './server-listeners.js';
3
4
  export { createContentTypesGenerator } from './types-generator.js';
@@ -1,3 +1,4 @@
1
+ import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from "./consts.js";
1
2
  import { errorMap } from "./error-map.js";
2
3
  import { attachContentServerListeners } from "./server-listeners.js";
3
4
  import { createContentTypesGenerator } from "./types-generator.js";
@@ -6,6 +7,8 @@ import { astroContentAssetPropagationPlugin } from "./vite-plugin-content-assets
6
7
  import { astroContentImportPlugin } from "./vite-plugin-content-imports.js";
7
8
  import { astroContentVirtualModPlugin } from "./vite-plugin-content-virtual-mod.js";
8
9
  export {
10
+ CONTENT_FLAG,
11
+ PROPAGATED_ASSET_FLAG,
9
12
  astroContentAssetPropagationPlugin,
10
13
  astroContentImportPlugin,
11
14
  astroContentVirtualModPlugin,
@@ -1,4 +1,4 @@
1
1
  import type { PluginContext } from 'rollup';
2
2
  import { z } from 'zod';
3
3
  import type { AstroSettings } from '../@types/astro.js';
4
- export declare function createImage(settings: AstroSettings, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata, string>;
4
+ export declare function createImage(settings: AstroSettings, pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
@@ -17,7 +17,7 @@ function createImage(settings, pluginContext, entryFilePath) {
17
17
  message: `Image ${imagePath} does not exist. Is the path correct?`,
18
18
  fatal: true
19
19
  });
20
- return z.NEVER;
20
+ return z.never();
21
21
  }
22
22
  return metadata;
23
23
  });
@@ -80,7 +80,12 @@ async function createContentTypesGenerator({
80
80
  }
81
81
  return { shouldGenerateTypes: true };
82
82
  }
83
- const fileType = getEntryType(fileURLToPath(event.entry), contentPaths, contentEntryExts);
83
+ const fileType = getEntryType(
84
+ fileURLToPath(event.entry),
85
+ contentPaths,
86
+ contentEntryExts,
87
+ settings.config.experimental.assets
88
+ );
84
89
  if (fileType === "ignored") {
85
90
  return { shouldGenerateTypes: false };
86
91
  }
@@ -63,7 +63,7 @@ export declare function getEntryInfo(params: Pick<ContentPaths, 'contentDir'> &
63
63
  entry: URL;
64
64
  allowFilesOutsideCollection?: true;
65
65
  }): EntryInfo;
66
- export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[]): 'content' | 'config' | 'ignored' | 'unsupported';
66
+ export declare function getEntryType(entryPath: string, paths: Pick<ContentPaths, 'config' | 'contentDir'>, contentFileExts: string[], experimentalAssets: boolean): 'content' | 'config' | 'ignored' | 'unsupported';
67
67
  /**
68
68
  * Match YAML exception handling from Astro core errors
69
69
  * @see 'astro/src/core/errors.ts'
@@ -5,6 +5,7 @@ import path from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import { normalizePath } from "vite";
7
7
  import { z } from "zod";
8
+ import { VALID_INPUT_FORMATS } from "../assets/consts.js";
8
9
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
9
10
  import { CONTENT_TYPES_FILE } from "./consts.js";
10
11
  import { errorMap } from "./error-map.js";
@@ -113,10 +114,10 @@ function getEntryInfo({
113
114
  };
114
115
  return res;
115
116
  }
116
- function getEntryType(entryPath, paths, contentFileExts) {
117
+ function getEntryType(entryPath, paths, contentFileExts, experimentalAssets) {
117
118
  const { ext, base } = path.parse(entryPath);
118
119
  const fileUrl = pathToFileURL(entryPath);
119
- if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir) || isOnIgnoreList(base)) {
120
+ if (hasUnderscoreBelowContentDirectoryPath(fileUrl, paths.contentDir) || isOnIgnoreList(base) || experimentalAssets && isImageAsset(ext)) {
120
121
  return "ignored";
121
122
  } else if (contentFileExts.includes(ext)) {
122
123
  return "content";
@@ -129,6 +130,9 @@ function getEntryType(entryPath, paths, contentFileExts) {
129
130
  function isOnIgnoreList(fileName) {
130
131
  return [".DS_Store"].includes(fileName);
131
132
  }
133
+ function isImageAsset(fileExt) {
134
+ return VALID_INPUT_FORMATS.includes(fileExt.slice(1));
135
+ }
132
136
  function hasUnderscoreBelowContentDirectoryPath(fileUrl, contentDir) {
133
137
  const parts = fileUrl.pathname.replace(contentDir.pathname, "").split("/");
134
138
  for (const part of parts) {
@@ -12,9 +12,9 @@ import {
12
12
  STYLES_PLACEHOLDER
13
13
  } from "./consts.js";
14
14
  import { getContentEntryExts } from "./utils.js";
15
- function isPropagatedAsset(viteId, contentEntryExts) {
16
- const url = new URL(viteId, "file://");
17
- return url.searchParams.has(PROPAGATED_ASSET_FLAG) && contentEntryExts.some((ext) => url.pathname.endsWith(ext));
15
+ function isPropagatedAsset(viteId) {
16
+ const flags = new URLSearchParams(viteId.split("?")[1]);
17
+ return flags.has(PROPAGATED_ASSET_FLAG);
18
18
  }
19
19
  function astroContentAssetPropagationPlugin({
20
20
  mode,
@@ -24,48 +24,47 @@ function astroContentAssetPropagationPlugin({
24
24
  const contentEntryExts = getContentEntryExts(settings);
25
25
  return {
26
26
  name: "astro:content-asset-propagation",
27
- enforce: "pre",
28
27
  configureServer(server) {
29
28
  if (mode === "dev") {
30
29
  devModuleLoader = createViteLoader(server);
31
30
  }
32
31
  },
33
- load(id) {
34
- if (isPropagatedAsset(id, contentEntryExts)) {
32
+ async transform(_, id, options) {
33
+ var _a;
34
+ if (isPropagatedAsset(id)) {
35
35
  const basePath = id.split("?")[0];
36
+ let stringifiedLinks, stringifiedStyles, stringifiedScripts;
37
+ if ((options == null ? void 0 : options.ssr) && devModuleLoader) {
38
+ if (!((_a = devModuleLoader.getModuleById(basePath)) == null ? void 0 : _a.ssrModule)) {
39
+ await devModuleLoader.import(basePath);
40
+ }
41
+ const { stylesMap, urls } = await getStylesForURL(
42
+ pathToFileURL(basePath),
43
+ devModuleLoader,
44
+ "development"
45
+ );
46
+ const hoistedScripts = await getScriptsForURL(
47
+ pathToFileURL(basePath),
48
+ settings.config.root,
49
+ devModuleLoader
50
+ );
51
+ stringifiedLinks = JSON.stringify([...urls]);
52
+ stringifiedStyles = JSON.stringify([...stylesMap.values()]);
53
+ stringifiedScripts = JSON.stringify([...hoistedScripts]);
54
+ } else {
55
+ stringifiedLinks = JSON.stringify(LINKS_PLACEHOLDER);
56
+ stringifiedStyles = JSON.stringify(STYLES_PLACEHOLDER);
57
+ stringifiedScripts = JSON.stringify(SCRIPTS_PLACEHOLDER);
58
+ }
36
59
  const code = `
37
60
  export async function getMod() {
38
61
  return import(${JSON.stringify(basePath)});
39
62
  }
40
- export const collectedLinks = ${JSON.stringify(LINKS_PLACEHOLDER)};
41
- export const collectedStyles = ${JSON.stringify(STYLES_PLACEHOLDER)};
42
- export const collectedScripts = ${JSON.stringify(SCRIPTS_PLACEHOLDER)};
63
+ export const collectedLinks = ${stringifiedLinks};
64
+ export const collectedStyles = ${stringifiedStyles};
65
+ export const collectedScripts = ${stringifiedScripts};
43
66
  `;
44
- return { code };
45
- }
46
- },
47
- async transform(code, id, options) {
48
- var _a;
49
- if (!(options == null ? void 0 : options.ssr))
50
- return;
51
- if (devModuleLoader && isPropagatedAsset(id, contentEntryExts)) {
52
- const basePath = id.split("?")[0];
53
- if (!((_a = devModuleLoader.getModuleById(basePath)) == null ? void 0 : _a.ssrModule)) {
54
- await devModuleLoader.import(basePath);
55
- }
56
- const { stylesMap, urls } = await getStylesForURL(
57
- pathToFileURL(basePath),
58
- devModuleLoader,
59
- "development"
60
- );
61
- const hoistedScripts = await getScriptsForURL(
62
- pathToFileURL(basePath),
63
- settings.config.root,
64
- devModuleLoader
65
- );
66
- return {
67
- code: code.replace(JSON.stringify(LINKS_PLACEHOLDER), JSON.stringify([...urls])).replace(JSON.stringify(STYLES_PLACEHOLDER), JSON.stringify([...stylesMap.values()])).replace(JSON.stringify(SCRIPTS_PLACEHOLDER), JSON.stringify([...hoistedScripts]))
68
- };
67
+ return { code, map: { mappings: "" } };
69
68
  }
70
69
  }
71
70
  };
@@ -15,9 +15,9 @@ import {
15
15
  globalContentConfigObserver,
16
16
  NoCollectionError
17
17
  } from "./utils.js";
18
- function isContentFlagImport(viteId, contentEntryExts) {
19
- const { searchParams, pathname } = new URL(viteId, "file://");
20
- return searchParams.has(CONTENT_FLAG) && contentEntryExts.some((ext) => pathname.endsWith(ext));
18
+ function isContentFlagImport(viteId) {
19
+ const flags = new URLSearchParams(viteId.split("?")[1]);
20
+ return flags.has(CONTENT_FLAG);
21
21
  }
22
22
  function getContentRendererByViteId(viteId, settings) {
23
23
  let ext = viteId.split(".").pop();
@@ -46,32 +46,36 @@ function astroContentImportPlugin({
46
46
  const plugins = [
47
47
  {
48
48
  name: "astro:content-imports",
49
- async load(viteId) {
50
- if (isContentFlagImport(viteId, contentEntryExts)) {
51
- const { fileId } = getFileInfo(viteId, settings.config);
49
+ async transform(_, viteId) {
50
+ if (isContentFlagImport(viteId)) {
51
+ const fileId = viteId.split("?")[0];
52
52
  const { id, slug, collection, body, data, _internal } = await setContentEntryModuleCache({
53
53
  fileId,
54
54
  pluginContext: this
55
55
  });
56
56
  const code = escapeViteEnvReferences(`
57
- export const id = ${JSON.stringify(id)};
58
- export const collection = ${JSON.stringify(collection)};
59
- export const slug = ${JSON.stringify(slug)};
60
- export const body = ${JSON.stringify(body)};
61
- export const data = ${devalue.uneval(data)};
62
- export const _internal = {
63
- filePath: ${JSON.stringify(_internal.filePath)},
64
- rawData: ${JSON.stringify(_internal.rawData)},
65
- };
66
- `);
67
- return { code };
57
+ export const id = ${JSON.stringify(id)};
58
+ export const collection = ${JSON.stringify(collection)};
59
+ export const slug = ${JSON.stringify(slug)};
60
+ export const body = ${JSON.stringify(body)};
61
+ export const data = ${devalue.uneval(data)};
62
+ export const _internal = {
63
+ filePath: ${JSON.stringify(_internal.filePath)},
64
+ rawData: ${JSON.stringify(_internal.rawData)},
65
+ };`);
66
+ return { code, map: { mappings: "" } };
68
67
  }
69
68
  },
70
69
  configureServer(viteServer) {
71
70
  viteServer.watcher.on("all", async (event, entry) => {
72
- if (CHOKIDAR_MODIFIED_EVENTS.includes(event) && getEntryType(entry, contentPaths, contentEntryExts) === "config") {
71
+ if (CHOKIDAR_MODIFIED_EVENTS.includes(event) && getEntryType(
72
+ entry,
73
+ contentPaths,
74
+ contentEntryExts,
75
+ settings.config.experimental.assets
76
+ ) === "config") {
73
77
  for (const modUrl of viteServer.moduleGraph.urlToModuleMap.keys()) {
74
- if (isContentFlagImport(modUrl, contentEntryExts) || Boolean(getContentRendererByViteId(modUrl, settings))) {
78
+ if (isContentFlagImport(modUrl) || Boolean(getContentRendererByViteId(modUrl, settings))) {
75
79
  const mod = await viteServer.moduleGraph.getModuleByUrl(modUrl);
76
80
  if (mod) {
77
81
  viteServer.moduleGraph.invalidateModule(mod);
@@ -80,11 +84,6 @@ export const _internal = {
80
84
  }
81
85
  }
82
86
  });
83
- },
84
- async transform(code, id) {
85
- if (isContentFlagImport(id, contentEntryExts)) {
86
- return { code: escapeViteEnvReferences(code) };
87
- }
88
87
  }
89
88
  }
90
89
  ];
@@ -6,7 +6,6 @@ import {
6
6
  generateImage as generateImageInternal,
7
7
  getStaticImageList
8
8
  } from "../../assets/internal.js";
9
- import { deleteWasmFiles } from "../../assets/services/vendor/squoosh/copy-wasm.js";
10
9
  import { hasPrerenderedPages } from "../../core/build/internal.js";
11
10
  import {
12
11
  prependForwardSlash,
@@ -88,9 +87,6 @@ ${bgGreen(black(` generating optimized images `))}`);
88
87
  for (const imageData of getStaticImageList()) {
89
88
  await generateImage(opts, imageData[1].options, imageData[1].path);
90
89
  }
91
- if (opts.settings.config.image.service === "astro/assets/services/squoosh" && opts.settings.config.output === "static") {
92
- await deleteWasmFiles(new URL("./chunks", opts.settings.config.outDir));
93
- }
94
90
  delete globalThis.astroAsset.addStaticImage;
95
91
  }
96
92
  await runHookBuildGenerated({
@@ -34,7 +34,14 @@ function rollupPluginAstroBuildCSS(options) {
34
34
  return [
35
35
  {
36
36
  name: "astro:rollup-plugin-build-css",
37
+ transform(_, id) {
38
+ if (options.target === "client" && internals.cssChunkModuleIds.has(id)) {
39
+ return "";
40
+ }
41
+ },
37
42
  outputOptions(outputOptions) {
43
+ if (options.target === "client")
44
+ return;
38
45
  const assetFileNames = outputOptions.assetFileNames;
39
46
  const namingIncludesHash = assetFileNames == null ? void 0 : assetFileNames.toString().includes("[hash]");
40
47
  const createNameForParentPages = namingIncludesHash ? assetName.shortHashedName : assetName.createSlugger(settings);
@@ -82,15 +89,6 @@ function rollupPluginAstroBuildCSS(options) {
82
89
  internals.cssChunkModuleIds.add(id);
83
90
  }
84
91
  }
85
- if (options.target === "client") {
86
- if (Object.keys(c.modules).every((id) => internals.cssChunkModuleIds.has(id))) {
87
- for (const importedCssImport of meta.importedCss) {
88
- delete bundle[importedCssImport];
89
- meta.importedCss.delete(importedCssImport);
90
- }
91
- return;
92
- }
93
- }
94
92
  if (options.target === "client") {
95
93
  for (const id of Object.keys(c.modules)) {
96
94
  for (const pageData of getParentClientOnlys(id, this)) {
@@ -3,6 +3,7 @@ import * as eslexer from "es-module-lexer";
3
3
  import glob from "fast-glob";
4
4
  import fs from "fs";
5
5
  import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
6
+ import path from "path";
6
7
  import { fileURLToPath } from "url";
7
8
  import * as vite from "vite";
8
9
  import {
@@ -292,11 +293,13 @@ async function ssrMoveAssets(opts) {
292
293
  cwd: fileURLToPath(serverAssets)
293
294
  });
294
295
  if (files.length > 0) {
295
- await fs.promises.mkdir(clientAssets, { recursive: true });
296
296
  await Promise.all(
297
297
  files.map(async (filename) => {
298
298
  const currentUrl = new URL(filename, appendForwardSlash(serverAssets.toString()));
299
299
  const clientUrl = new URL(filename, appendForwardSlash(clientAssets.toString()));
300
+ const dir = new URL(path.parse(clientUrl.href).dir);
301
+ if (!fs.existsSync(dir))
302
+ await fs.promises.mkdir(dir, { recursive: true });
300
303
  return fs.promises.rename(currentUrl, clientUrl);
301
304
  })
302
305
  );
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.2.2";
1
+ const ASTRO_VERSION = "2.3.0";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -53,7 +53,7 @@ async function dev(settings, options) {
53
53
  isRestart: options.isRestart
54
54
  })
55
55
  );
56
- const currentVersion = "2.2.2";
56
+ const currentVersion = "2.3.0";
57
57
  if (currentVersion.includes("-")) {
58
58
  warn(options.logging, null, msg.prerelease({ currentVersion }));
59
59
  }
@@ -47,7 +47,7 @@ function serverStart({
47
47
  base,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "2.2.2";
50
+ const version = "2.3.0";
51
51
  const localPrefix = `${dim("\u2503")} Local `;
52
52
  const networkPrefix = `${dim("\u2503")} Network `;
53
53
  const emptyPrefix = " ".repeat(11);
@@ -233,7 +233,7 @@ function printHelp({
233
233
  message.push(
234
234
  linebreak(),
235
235
  ` ${bgGreen(black(` ${commandName} `))} ${green(
236
- `v${"2.2.2"}`
236
+ `v${"2.3.0"}`
237
237
  )} ${headline}`
238
238
  );
239
239
  }
@@ -17,7 +17,7 @@ async function* renderSlot(result, slotted, fallback) {
17
17
  let iterator = renderChild(typeof slotted === "function" ? slotted(result) : slotted);
18
18
  yield* iterator;
19
19
  }
20
- if (fallback) {
20
+ if (fallback && !slotted) {
21
21
  yield* renderSlot(result, fallback);
22
22
  }
23
23
  }
@@ -1,11 +1,6 @@
1
+ import { type Plugin as VitePlugin } from 'vite';
1
2
  import type { AstroSettings } from '../@types/astro';
2
- import type * as vite from 'vite';
3
- /** Result of successfully parsed tsconfig.json or jsconfig.json. */
4
- export declare interface Alias {
5
- find: RegExp;
6
- replacement: string;
7
- }
8
3
  /** Returns a Vite plugin used to alias paths from tsconfig.json and jsconfig.json. */
9
4
  export default function configAliasVitePlugin({ settings, }: {
10
5
  settings: AstroSettings;
11
- }): vite.PluginOption;
6
+ }): VitePlugin | null;
@@ -1,66 +1,91 @@
1
- import * as path from "path";
2
- const normalize = (pathname) => String(pathname).split(path.sep).join(path.posix.sep);
1
+ import path from "path";
2
+ import { normalizePath } from "vite";
3
3
  const getConfigAlias = (settings) => {
4
- const config = settings.tsConfig;
5
- const configPath = settings.tsConfigPath;
6
- if (!config || !configPath)
4
+ const { tsConfig, tsConfigPath } = settings;
5
+ if (!tsConfig || !tsConfigPath || !tsConfig.compilerOptions)
7
6
  return null;
8
- const compilerOptions = Object(config.compilerOptions);
9
- if (!compilerOptions.baseUrl)
7
+ const { baseUrl, paths } = tsConfig.compilerOptions;
8
+ if (!baseUrl || !paths)
10
9
  return null;
11
- const baseUrl = path.posix.resolve(
12
- path.posix.dirname(normalize(configPath).replace(/^\/?/, "/")),
13
- normalize(compilerOptions.baseUrl)
14
- );
10
+ const resolvedBaseUrl = path.resolve(path.dirname(tsConfigPath), baseUrl);
15
11
  const aliases = [];
16
- for (let [alias, values] of Object.entries(
17
- Object(compilerOptions.paths)
18
- )) {
19
- values = [].concat(values);
12
+ for (const [alias, values] of Object.entries(paths)) {
20
13
  const find = new RegExp(
21
14
  `^${[...alias].map(
22
15
  (segment) => segment === "*" ? "(.+)" : segment.replace(/[\\^$*+?.()|[\]{}]/, "\\$&")
23
16
  ).join("")}$`
24
17
  );
25
18
  let matchId = 0;
26
- for (let value of values) {
27
- const replacement = [...path.posix.resolve(baseUrl, value)].map((segment) => segment === "*" ? `$${++matchId}` : segment === "$" ? "$$" : segment).join("");
19
+ for (const value of values) {
20
+ const replacement = [...normalizePath(path.resolve(resolvedBaseUrl, value))].map((segment) => segment === "*" ? `$${++matchId}` : segment === "$" ? "$$" : segment).join("");
28
21
  aliases.push({ find, replacement });
29
22
  }
30
23
  }
31
24
  aliases.push({
32
- find: /^(?!\.*\/)(.+)$/,
33
- replacement: `${[...baseUrl].map((segment) => segment === "$" ? "$$" : segment).join("")}/$1`
25
+ find: /^(?!\.*\/|\w:)(.+)$/,
26
+ replacement: `${[...normalizePath(resolvedBaseUrl)].map((segment) => segment === "$" ? "$$" : segment).join("")}/$1`
34
27
  });
35
28
  return aliases;
36
29
  };
37
30
  function configAliasVitePlugin({
38
31
  settings
39
32
  }) {
40
- const { config } = settings;
41
33
  const configAlias = getConfigAlias(settings);
42
34
  if (!configAlias)
43
- return {};
44
- return {
35
+ return null;
36
+ const plugin = {
45
37
  name: "astro:tsconfig-alias",
46
38
  enforce: "pre",
47
- async resolveId(sourceId, importer, options) {
48
- const resolvedId = await this.resolve(sourceId, importer, { skipSelf: true, ...options });
49
- if (resolvedId)
50
- return resolvedId;
39
+ configResolved(config) {
40
+ patchCreateResolver(config, plugin);
41
+ },
42
+ async resolveId(id, importer, options) {
43
+ if (isVirtualId(id))
44
+ return;
51
45
  for (const alias of configAlias) {
52
- if (alias.find.test(sourceId)) {
53
- const aliasedSourceId = sourceId.replace(alias.find, alias.replacement);
54
- const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, {
55
- skipSelf: true,
56
- ...options
57
- });
58
- if (resolvedAliasedId)
59
- return resolvedAliasedId;
46
+ if (alias.find.test(id)) {
47
+ const updatedId = id.replace(alias.find, alias.replacement);
48
+ const resolved = await this.resolve(updatedId, importer, { skipSelf: true, ...options });
49
+ if (resolved)
50
+ return resolved;
60
51
  }
61
52
  }
62
53
  }
63
54
  };
55
+ return plugin;
56
+ }
57
+ function patchCreateResolver(config, prePlugin) {
58
+ const _createResolver = config.createResolver;
59
+ config.createResolver = function(...args1) {
60
+ const resolver = _createResolver.apply(config, args1);
61
+ return async function(...args2) {
62
+ const id = args2[0];
63
+ const importer = args2[1];
64
+ const ssr = args2[3];
65
+ if (importer == null ? void 0 : importer.includes("node_modules")) {
66
+ return resolver.apply(_createResolver, args2);
67
+ }
68
+ const fakePluginContext = {
69
+ resolve: (_id, _importer) => resolver(_id, _importer, false, ssr)
70
+ };
71
+ const fakeResolveIdOpts = {
72
+ assertions: {},
73
+ isEntry: false,
74
+ ssr
75
+ };
76
+ const resolved = await prePlugin.resolveId.apply(fakePluginContext, [
77
+ id,
78
+ importer,
79
+ fakeResolveIdOpts
80
+ ]);
81
+ if (resolved)
82
+ return resolved;
83
+ return resolver.apply(_createResolver, args2);
84
+ };
85
+ };
86
+ }
87
+ function isVirtualId(id) {
88
+ return id.includes("\0") || id.startsWith("virtual:") || id.startsWith("astro:");
64
89
  }
65
90
  export {
66
91
  configAliasVitePlugin as default
@@ -4,6 +4,7 @@ import {
4
4
  import babel from "@babel/core";
5
5
  import * as colors from "kleur/colors";
6
6
  import path from "path";
7
+ import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from "../content/index.js";
7
8
  import { error } from "../core/logger/core.js";
8
9
  import { removeQueryString } from "../core/path.js";
9
10
  import { detectImportSource } from "./import-source.js";
@@ -75,6 +76,9 @@ async function transformJSX({
75
76
  map: result.map
76
77
  };
77
78
  }
79
+ const SPECIAL_QUERY_REGEX = new RegExp(
80
+ `[?&](?:worker|sharedworker|raw|url|${CONTENT_FLAG}|${PROPAGATED_ASSET_FLAG})\\b`
81
+ );
78
82
  function jsx({ settings, logging }) {
79
83
  let viteConfig;
80
84
  const jsxRenderers = /* @__PURE__ */ new Map();
@@ -100,6 +104,9 @@ function jsx({ settings, logging }) {
100
104
  },
101
105
  async transform(code, id, opts) {
102
106
  const ssr = Boolean(opts == null ? void 0 : opts.ssr);
107
+ if (SPECIAL_QUERY_REGEX.test(id)) {
108
+ return null;
109
+ }
103
110
  id = removeQueryString(id);
104
111
  if (!JSX_EXTENSIONS.has(path.extname(id))) {
105
112
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
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",
@@ -95,7 +95,7 @@
95
95
  "dependencies": {
96
96
  "@astrojs/compiler": "^1.3.1",
97
97
  "@astrojs/language-server": "^0.28.3",
98
- "@astrojs/markdown-remark": "^2.1.3",
98
+ "@astrojs/markdown-remark": "^2.1.4",
99
99
  "@astrojs/telemetry": "^2.1.0",
100
100
  "@astrojs/webapi": "^2.1.0",
101
101
  "@babel/core": "^7.18.2",
@@ -145,7 +145,7 @@
145
145
  "vite": "^4.2.1",
146
146
  "vitefu": "^0.2.4",
147
147
  "yargs-parser": "^21.0.1",
148
- "zod": "^3.17.3"
148
+ "zod": "^3.20.6"
149
149
  },
150
150
  "devDependencies": {
151
151
  "@playwright/test": "^1.29.2",
@@ -170,7 +170,6 @@
170
170
  "@types/server-destroy": "^1.0.1",
171
171
  "@types/sharp": "^0.31.1",
172
172
  "@types/unist": "^2.0.6",
173
- "astro-scripts": "0.0.14",
174
173
  "chai": "^4.3.6",
175
174
  "cheerio": "^1.0.0-rc.11",
176
175
  "eol": "^0.9.1",
@@ -186,7 +185,8 @@
186
185
  "sharp": "^0.31.3",
187
186
  "srcset-parse": "^1.1.0",
188
187
  "undici": "^5.20.0",
189
- "unified": "^10.1.2"
188
+ "unified": "^10.1.2",
189
+ "astro-scripts": "0.0.14"
190
190
  },
191
191
  "peerDependencies": {
192
192
  "sharp": "^0.31.3"
@@ -1,2 +0,0 @@
1
- export declare function copyWasmFiles(dir: URL): Promise<void>;
2
- export declare function deleteWasmFiles(dir: URL): Promise<void>;