astro 0.25.2 → 0.25.3

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/cli/index.js CHANGED
@@ -37,7 +37,7 @@ function printAstroHelp() {
37
37
  });
38
38
  }
39
39
  async function printVersion() {
40
- const version = "0.25.2";
40
+ const version = "0.25.3";
41
41
  console.log();
42
42
  console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
43
43
  }
@@ -41,6 +41,9 @@ function getPageDataByViteID(internals, viteid) {
41
41
  }
42
42
  return void 0;
43
43
  }
44
+ function hasPageDataByViteID(internals, viteid) {
45
+ return internals.pagesByViteID.has(viteid);
46
+ }
44
47
  function* eachPageData(internals) {
45
48
  yield* internals.pagesByComponent.values();
46
49
  }
@@ -50,5 +53,6 @@ export {
50
53
  getPageDataByComponent,
51
54
  getPageDataByViteID,
52
55
  getPageDatasByChunk,
56
+ hasPageDataByViteID,
53
57
  trackPageData
54
58
  };
@@ -45,7 +45,8 @@ async function build(opts) {
45
45
  viteServer
46
46
  }),
47
47
  rollupPluginAstroBuildCSS({
48
- internals
48
+ internals,
49
+ legacy: true
49
50
  }),
50
51
  ...viteConfig.plugins || []
51
52
  ],
@@ -110,8 +110,7 @@ async function ssrBuild(opts, internals, input) {
110
110
  format: "esm",
111
111
  entryFileNames: opts.buildConfig.serverEntry,
112
112
  chunkFileNames: "chunks/chunk.[hash].mjs",
113
- assetFileNames: "assets/asset.[hash][extname]",
114
- inlineDynamicImports: true
113
+ assetFileNames: "assets/asset.[hash][extname]"
115
114
  }
116
115
  },
117
116
  target: "esnext",
@@ -123,7 +122,8 @@ async function ssrBuild(opts, internals, input) {
123
122
  vitePluginInternals(input, internals),
124
123
  vitePluginPages(opts, internals),
125
124
  rollupPluginAstroBuildCSS({
126
- internals
125
+ internals,
126
+ legacy: false
127
127
  }),
128
128
  ...viteConfig.plugins || [],
129
129
  isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter)
@@ -170,7 +170,8 @@ ${bgGreen(black(" building resources "))}
170
170
  vitePluginInternals(input, internals),
171
171
  vitePluginHoistedScripts(astroConfig, internals),
172
172
  rollupPluginAstroBuildCSS({
173
- internals
173
+ internals,
174
+ legacy: false
174
175
  }),
175
176
  ...viteConfig.plugins || []
176
177
  ],
@@ -45,6 +45,7 @@ export const renderers = [${rendererItems}];`;
45
45
  };
46
46
  }
47
47
  export {
48
+ resolvedVirtualModuleId,
48
49
  virtualModuleId,
49
50
  vitePluginPages
50
51
  };
@@ -23,7 +23,7 @@ async function dev(config, options = { logging: defaultLogOptions }) {
23
23
  const devServerAddressInfo = viteServer.httpServer.address();
24
24
  const site = config.buildOptions.site ? new URL(config.buildOptions.site) : void 0;
25
25
  info(options.logging, null, msg.devStart({ startupTime: performance.now() - devStart, config, devServerAddressInfo, site, https: !!((_a = viteConfig.server) == null ? void 0 : _a.https) }));
26
- const currentVersion = "0.25.2";
26
+ const currentVersion = "0.25.3";
27
27
  if (currentVersion.includes("-")) {
28
28
  warn(options.logging, null, msg.prerelease({ currentVersion }));
29
29
  }
@@ -28,7 +28,7 @@ function devStart({
28
28
  https,
29
29
  site
30
30
  }) {
31
- const version = "0.25.2";
31
+ const version = "0.25.3";
32
32
  const rootPath = site ? site.pathname : "/";
33
33
  const localPrefix = `${dim("\u2503")} Local `;
34
34
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -121,7 +121,7 @@ function printHelp({
121
121
  };
122
122
  let message = [];
123
123
  if (headline) {
124
- message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"0.25.2"}`)} ${headline}`);
124
+ message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"0.25.3"}`)} ${headline}`);
125
125
  }
126
126
  if (usage) {
127
127
  message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
@@ -37,4 +37,5 @@ export declare function trackPageData(internals: BuildInternals, component: stri
37
37
  export declare function getPageDatasByChunk(internals: BuildInternals, chunk: RenderedChunk): Generator<PageBuildData, void, unknown>;
38
38
  export declare function getPageDataByComponent(internals: BuildInternals, component: string): PageBuildData | undefined;
39
39
  export declare function getPageDataByViteID(internals: BuildInternals, viteid: ViteID): PageBuildData | undefined;
40
+ export declare function hasPageDataByViteID(internals: BuildInternals, viteid: ViteID): boolean;
40
41
  export declare function eachPageData(internals: BuildInternals): Generator<PageBuildData, void, undefined>;
@@ -2,4 +2,5 @@ import type { Plugin as VitePlugin } from 'vite';
2
2
  import type { BuildInternals } from './internal.js';
3
3
  import type { StaticBuildOptions } from './types';
4
4
  export declare const virtualModuleId = "@astrojs-pages-virtual-entry";
5
+ export declare const resolvedVirtualModuleId: string;
5
6
  export declare function vitePluginPages(opts: StaticBuildOptions, internals: BuildInternals): VitePlugin;
@@ -1,10 +1,11 @@
1
- import type { BuildInternals } from '../core/build/internal';
1
+ import { BuildInternals } from '../core/build/internal';
2
2
  import { Plugin as VitePlugin } from 'vite';
3
3
  export declare function getAstroPageStyleId(pathname: string): string;
4
4
  export declare function getAstroStyleId(pathname: string): string;
5
5
  export declare function getAstroStylePathFromId(id: string): string;
6
6
  interface PluginOptions {
7
7
  internals: BuildInternals;
8
+ legacy: boolean;
8
9
  }
9
10
  export declare function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin;
10
11
  export {};
@@ -1,7 +1,7 @@
1
1
  import * as path from "path";
2
2
  import esbuild from "esbuild";
3
3
  import { isCSSRequest } from "../core/render/dev/css.js";
4
- import { getPageDatasByChunk } from "../core/build/internal.js";
4
+ import { getPageDatasByChunk, getPageDataByViteID, hasPageDataByViteID } from "../core/build/internal.js";
5
5
  const PLUGIN_NAME = "@astrojs/rollup-plugin-build-css";
6
6
  const ASTRO_STYLE_PREFIX = "@astro-inline-style";
7
7
  const ASTRO_PAGE_STYLE_PREFIX = "@astro-page-all-styles";
@@ -30,8 +30,46 @@ function isPageStyleVirtualModule(id) {
30
30
  return id.startsWith(ASTRO_PAGE_STYLE_PREFIX);
31
31
  }
32
32
  function rollupPluginAstroBuildCSS(options) {
33
- const { internals } = options;
33
+ const { internals, legacy } = options;
34
34
  const styleSourceMap = /* @__PURE__ */ new Map();
35
+ function* walkStyles(ctx, id, seen = /* @__PURE__ */ new Set()) {
36
+ seen.add(id);
37
+ if (styleSourceMap.has(id)) {
38
+ yield [id, styleSourceMap.get(id)];
39
+ }
40
+ const info = ctx.getModuleInfo(id);
41
+ if (info) {
42
+ for (const importedId of info.importedIds) {
43
+ if (!seen.has(importedId)) {
44
+ yield* walkStyles(ctx, importedId, seen);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ async function addStyles() {
50
+ var _a;
51
+ for (const id of this.getModuleIds()) {
52
+ if (hasPageDataByViteID(internals, id)) {
53
+ let pageStyles = "";
54
+ for (const [_styleId, styles] of walkStyles(this, id)) {
55
+ pageStyles += styles;
56
+ }
57
+ if (!pageStyles)
58
+ continue;
59
+ const { code: minifiedCSS } = await esbuild.transform(pageStyles, {
60
+ loader: "css",
61
+ minify: true
62
+ });
63
+ const referenceId = this.emitFile({
64
+ name: "entry.css",
65
+ type: "asset",
66
+ source: minifiedCSS
67
+ });
68
+ const fileName = this.getFileName(referenceId);
69
+ (_a = getPageDataByViteID(internals, id)) == null ? void 0 : _a.css.add(fileName);
70
+ }
71
+ }
72
+ }
35
73
  return {
36
74
  name: PLUGIN_NAME,
37
75
  configResolved(resolvedConfig) {
@@ -75,6 +113,8 @@ function rollupPluginAstroBuildCSS(options) {
75
113
  return null;
76
114
  },
77
115
  async renderChunk(_code, chunk) {
116
+ if (!legacy)
117
+ return null;
78
118
  let chunkCSS = "";
79
119
  let isPureCSS = true;
80
120
  for (const [id] of Object.entries(chunk.modules)) {
@@ -108,13 +148,16 @@ function rollupPluginAstroBuildCSS(options) {
108
148
  }
109
149
  return null;
110
150
  },
111
- generateBundle(opts, bundle) {
151
+ async generateBundle(opts, bundle) {
112
152
  const hasPureCSSChunks = internals.pureCSSChunks.size;
113
153
  const pureChunkFilenames = new Set([...internals.pureCSSChunks].map((chunk) => chunk.fileName));
114
154
  const emptyChunkFiles = [...pureChunkFilenames].map((file) => path.basename(file)).join("|").replace(/\./g, "\\.");
115
155
  const emptyChunkRE = new RegExp(opts.format === "es" ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";
116
156
  ?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);
117
157
  ?`, "g");
158
+ if (!legacy) {
159
+ await addStyles.call(this);
160
+ }
118
161
  for (const [chunkId, chunk] of Object.entries(bundle)) {
119
162
  if (chunk.type === "chunk") {
120
163
  for (const { css: cssSet } of getPageDatasByChunk(internals, chunk)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "0.25.2",
3
+ "version": "0.25.3",
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",