astro 1.0.6 → 1.0.9

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 (58) hide show
  1. package/astro-jsx.d.ts +2 -2
  2. package/dist/core/add/index.js +10 -7
  3. package/dist/core/build/generate.js +3 -6
  4. package/dist/core/build/graph.js +10 -6
  5. package/dist/core/build/index.js +5 -4
  6. package/dist/core/build/internal.js +29 -3
  7. package/dist/core/build/page-data.js +2 -2
  8. package/dist/core/build/static-build.js +13 -24
  9. package/dist/core/build/vite-plugin-analyzer.js +2 -2
  10. package/dist/core/build/vite-plugin-css.js +59 -12
  11. package/dist/core/build/vite-plugin-ssr.js +3 -3
  12. package/dist/core/config.js +1 -1
  13. package/dist/core/create-vite.js +1 -1
  14. package/dist/core/dev/index.js +6 -6
  15. package/dist/core/errors.js +1 -1
  16. package/dist/core/messages.js +4 -5
  17. package/dist/core/render/result.js +18 -7
  18. package/dist/core/util.js +1 -1
  19. package/dist/integrations/index.js +99 -35
  20. package/dist/jsx/babel.js +14 -0
  21. package/dist/runtime/client/idle.js +1 -0
  22. package/dist/runtime/client/idle.prebuilt.js +1 -1
  23. package/dist/runtime/client/load.js +1 -0
  24. package/dist/runtime/client/load.prebuilt.js +1 -1
  25. package/dist/runtime/client/media.js +1 -0
  26. package/dist/runtime/client/media.prebuilt.js +1 -1
  27. package/dist/runtime/client/only.js +1 -0
  28. package/dist/runtime/client/only.prebuilt.js +1 -1
  29. package/dist/runtime/client/visible.js +1 -0
  30. package/dist/runtime/client/visible.prebuilt.js +1 -1
  31. package/dist/runtime/server/astro-global.js +1 -1
  32. package/dist/runtime/server/astro-island.js +14 -5
  33. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  34. package/dist/types/@types/astro.d.ts +17 -2
  35. package/dist/types/core/build/graph.d.ts +3 -2
  36. package/dist/types/core/build/internal.d.ts +9 -0
  37. package/dist/types/core/build/types.d.ts +3 -1
  38. package/dist/types/integrations/index.d.ts +19 -9
  39. package/dist/types/runtime/client/idle.prebuilt.d.ts +1 -1
  40. package/dist/types/runtime/client/load.prebuilt.d.ts +1 -1
  41. package/dist/types/runtime/client/media.prebuilt.d.ts +1 -1
  42. package/dist/types/runtime/client/only.prebuilt.d.ts +1 -1
  43. package/dist/types/runtime/client/visible.prebuilt.d.ts +1 -1
  44. package/dist/types/runtime/server/astro-island.d.ts +1 -1
  45. package/dist/types/runtime/server/astro-island.prebuilt.d.ts +1 -1
  46. package/dist/types/vite-plugin-astro/compile.d.ts +5 -3
  47. package/dist/types/vite-plugin-astro/hmr.d.ts +1 -10
  48. package/dist/types/vite-plugin-astro/styles.d.ts +12 -10
  49. package/dist/types/vite-plugin-integrations-container/index.d.ts +3 -1
  50. package/dist/vite-plugin-astro/compile.js +18 -30
  51. package/dist/vite-plugin-astro/hmr.js +4 -24
  52. package/dist/vite-plugin-astro/index.js +14 -14
  53. package/dist/vite-plugin-astro/styles.js +23 -18
  54. package/dist/vite-plugin-astro-server/index.js +2 -1
  55. package/dist/vite-plugin-integrations-container/index.js +3 -2
  56. package/dist/vite-plugin-jsx/index.js +91 -99
  57. package/dist/vite-plugin-markdown-legacy/index.js +8 -4
  58. package/package.json +4 -4
package/astro-jsx.d.ts CHANGED
@@ -548,7 +548,7 @@ declare namespace astroHTML.JSX {
548
548
  | 'strict-origin-when-cross-origin'
549
549
  | 'unsafe-url';
550
550
 
551
- type HTMLAttributeAnchorTarget = '_self' | '_blank' | '_parent' | '_top';
551
+ type HTMLAttributeAnchorTarget = '_self' | '_blank' | '_parent' | '_top' | (string & {});
552
552
 
553
553
  interface AnchorHTMLAttributes extends HTMLAttributes {
554
554
  download?: string | boolean | undefined | null;
@@ -756,7 +756,7 @@ declare namespace astroHTML.JSX {
756
756
  size?: number | string | undefined | null;
757
757
  src?: string | undefined | null;
758
758
  step?: number | string | undefined | null;
759
- type?: HTMLInputTypeAttribute | string | undefined | null;
759
+ type?: HTMLInputTypeAttribute | undefined | null;
760
760
  value?: string | string[] | number | undefined | null;
761
761
  width?: number | string | undefined | null;
762
762
  }
@@ -517,7 +517,7 @@ ${message}`
517
517
  }
518
518
  }
519
519
  async function fetchPackageJson(scope, name, tag) {
520
- const packageName = `${scope ? `@${scope}/` : ""}${name}`;
520
+ const packageName = `${scope ? `${scope}/` : ""}${name}`;
521
521
  const res = await fetch(`https://registry.npmjs.org/${packageName}/${tag}`);
522
522
  if (res.status === 404) {
523
523
  return new Error();
@@ -535,10 +535,12 @@ async function validateIntegrations(integrations) {
535
535
  throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
536
536
  }
537
537
  let { scope, name, tag } = parsed;
538
- let pkgJson = null;
539
- let pkgType = "first-party";
540
- if (!scope) {
541
- const firstPartyPkgCheck = await fetchPackageJson("astrojs", name, tag);
538
+ let pkgJson;
539
+ let pkgType;
540
+ if (scope && scope !== "@astrojs") {
541
+ pkgType = "third-party";
542
+ } else {
543
+ const firstPartyPkgCheck = await fetchPackageJson("@astrojs", name, tag);
542
544
  if (firstPartyPkgCheck instanceof Error) {
543
545
  spinner.warn(
544
546
  yellow(`${bold(integration)} is not an official Astro package. Use at your own risk!`)
@@ -559,6 +561,7 @@ async function validateIntegrations(integrations) {
559
561
  spinner.start("Resolving with third party packages...");
560
562
  pkgType = "third-party";
561
563
  } else {
564
+ pkgType = "first-party";
562
565
  pkgJson = firstPartyPkgCheck;
563
566
  }
564
567
  }
@@ -570,8 +573,8 @@ async function validateIntegrations(integrations) {
570
573
  pkgJson = thirdPartyPkgCheck;
571
574
  }
572
575
  }
573
- const resolvedScope = pkgType === "first-party" ? "astrojs" : scope;
574
- const packageName = `${resolvedScope ? `@${resolvedScope}/` : ""}${name}`;
576
+ const resolvedScope = pkgType === "first-party" ? "@astrojs" : scope;
577
+ const packageName = `${resolvedScope ? `${resolvedScope}/` : ""}${name}`;
575
578
  let dependencies = [
576
579
  [pkgJson["name"], `^${pkgJson["version"]}`]
577
580
  ];
@@ -19,7 +19,7 @@ import { createRequest } from "../request.js";
19
19
  import { matchRoute } from "../routing/match.js";
20
20
  import { getOutputFilename } from "../util.js";
21
21
  import { getOutFile, getOutFolder } from "./common.js";
22
- import { eachPageData, getPageDataByComponent } from "./internal.js";
22
+ import { eachPageData, getPageDataByComponent, sortedCSS } from "./internal.js";
23
23
  import { getTimeStat } from "./util.js";
24
24
  const MAX_CONCURRENT_RENDERS = 1;
25
25
  function* throttle(max, inPaths) {
@@ -79,7 +79,7 @@ async function generatePage(opts, internals, pageData, ssrEntry, builtPaths) {
79
79
  let timeStart = performance.now();
80
80
  const renderers = ssrEntry.renderers;
81
81
  const pageInfo = getPageDataByComponent(internals, pageData.route.component);
82
- const linkIds = Array.from((pageInfo == null ? void 0 : pageInfo.css) ?? []);
82
+ const linkIds = sortedCSS(pageData);
83
83
  const scripts = (pageInfo == null ? void 0 : pageInfo.hoistedScript) ?? null;
84
84
  const pageModule = ssrEntry.pageMap.get(pageData.component);
85
85
  if (!pageModule) {
@@ -141,9 +141,6 @@ async function getPathsForRoute(pageData, mod, opts, builtPaths) {
141
141
  });
142
142
  opts.routeCache.set(route, result);
143
143
  paths = result.staticPaths.map((staticPath) => staticPath.params && route.generate(staticPath.params)).filter((staticPath) => {
144
- if (!staticPath) {
145
- return false;
146
- }
147
144
  if (!builtPaths.has(removeTrailingForwardSlash(staticPath))) {
148
145
  return true;
149
146
  }
@@ -168,7 +165,7 @@ async function generatePath(pathname, opts, gopts) {
168
165
  }
169
166
  debug("build", `Generating: ${pathname}`);
170
167
  const site = astroConfig.base !== "/" ? joinPaths(((_a = astroConfig.site) == null ? void 0 : _a.toString()) || "http://localhost/", astroConfig.base) : astroConfig.site;
171
- const links = createLinkStylesheetElementSet(linkIds.reverse(), site);
168
+ const links = createLinkStylesheetElementSet(linkIds, site);
172
169
  const scripts = createModuleScriptsSet(hoistedScripts ? [hoistedScripts] : [], site);
173
170
  if (astroConfig._ctx.scripts.some((script) => script.stage === "page")) {
174
171
  const hashedFilePath = internals.entrySpecifierToBundleMap.get(PAGE_SCRIPT_ID);
@@ -1,26 +1,30 @@
1
1
  import { resolvedPagesVirtualModuleId } from "../app/index.js";
2
- function* walkParentInfos(id, ctx, seen = /* @__PURE__ */ new Set()) {
2
+ function* walkParentInfos(id, ctx, depth = 0, seen = /* @__PURE__ */ new Set()) {
3
3
  seen.add(id);
4
4
  const info = ctx.getModuleInfo(id);
5
5
  if (info) {
6
- yield info;
6
+ yield [info, depth];
7
7
  }
8
8
  const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
9
9
  for (const imp of importers) {
10
10
  if (seen.has(imp)) {
11
11
  continue;
12
12
  }
13
- yield* walkParentInfos(imp, ctx, seen);
13
+ yield* walkParentInfos(imp, ctx, ++depth, seen);
14
14
  }
15
15
  }
16
+ function moduleIsTopLevelPage(info) {
17
+ return info.importers[0] === resolvedPagesVirtualModuleId;
18
+ }
16
19
  function* getTopLevelPages(id, ctx) {
17
- for (const info of walkParentInfos(id, ctx)) {
18
- if ((info == null ? void 0 : info.importers[0]) === resolvedPagesVirtualModuleId) {
19
- yield info;
20
+ for (const res of walkParentInfos(id, ctx)) {
21
+ if (moduleIsTopLevelPage(res[0])) {
22
+ yield res;
20
23
  }
21
24
  }
22
25
  }
23
26
  export {
24
27
  getTopLevelPages,
28
+ moduleIsTopLevelPage,
25
29
  walkParentInfos
26
30
  };
@@ -38,7 +38,7 @@ class AstroBuilder {
38
38
  debug("build", "Initial setup...");
39
39
  const { logging } = this;
40
40
  this.timer.init = performance.now();
41
- this.config = await runHookConfigSetup({ config: this.config, command: "build" });
41
+ this.config = await runHookConfigSetup({ config: this.config, command: "build", logging });
42
42
  this.manifest = createRouteManifest({ config: this.config }, this.logging);
43
43
  const viteConfig = await createVite(
44
44
  {
@@ -51,7 +51,7 @@ class AstroBuilder {
51
51
  },
52
52
  { astroConfig: this.config, logging, mode: "build" }
53
53
  );
54
- await runHookConfigDone({ config: this.config });
54
+ await runHookConfigDone({ config: this.config, logging });
55
55
  return { viteConfig };
56
56
  }
57
57
  async build({ viteConfig }) {
@@ -60,7 +60,7 @@ class AstroBuilder {
60
60
  server: new URL("./server/", this.config.outDir),
61
61
  serverEntry: "entry.mjs"
62
62
  };
63
- await runHookBuildStart({ config: this.config, buildConfig });
63
+ await runHookBuildStart({ config: this.config, buildConfig, logging: this.logging });
64
64
  info(this.logging, "build", `output target: ${colors.green(this.config.output)}`);
65
65
  if (this.config._ctx.adapter) {
66
66
  info(this.logging, "build", `deploy adapter: ${colors.green(this.config._ctx.adapter.name)}`);
@@ -106,7 +106,8 @@ class AstroBuilder {
106
106
  config: this.config,
107
107
  buildConfig,
108
108
  pages: pageNames,
109
- routes: Object.values(allPages).map((pd) => pd.route)
109
+ routes: Object.values(allPages).map((pd) => pd.route),
110
+ logging: this.logging
110
111
  });
111
112
  if (this.logging.level && levels[this.logging.level] <= levels["info"]) {
112
113
  await this.printStats({
@@ -2,9 +2,6 @@ import { prependForwardSlash } from "../path.js";
2
2
  import { viteID } from "../util.js";
3
3
  function createBuildInternals() {
4
4
  const pureCSSChunks = /* @__PURE__ */ new Set();
5
- const chunkToReferenceIdMap = /* @__PURE__ */ new Map();
6
- const astroStyleMap = /* @__PURE__ */ new Map();
7
- const astroPageStyleMap = /* @__PURE__ */ new Map();
8
5
  const hoistedScriptIdToHoistedMap = /* @__PURE__ */ new Map();
9
6
  const hoistedScriptIdToPagesMap = /* @__PURE__ */ new Map();
10
7
  return {
@@ -76,6 +73,32 @@ function hasPageDataByViteID(internals, viteid) {
76
73
  function* eachPageData(internals) {
77
74
  yield* internals.pagesByComponent.values();
78
75
  }
76
+ function sortedCSS(pageData) {
77
+ return Array.from(pageData.css).sort((a, b) => {
78
+ let depthA = a[1].depth, depthB = b[1].depth;
79
+ if (depthA === -1) {
80
+ return -1;
81
+ } else if (depthB === -1) {
82
+ return 1;
83
+ } else {
84
+ return depthA > depthB ? -1 : 1;
85
+ }
86
+ }).map(([id]) => id);
87
+ }
88
+ function isHoistedScript(internals, id) {
89
+ return internals.hoistedScriptIdToPagesMap.has(id);
90
+ }
91
+ function* getPageDatasByHoistedScriptId(internals, id) {
92
+ const set = internals.hoistedScriptIdToPagesMap.get(id);
93
+ if (set) {
94
+ for (const pageId of set) {
95
+ const pageData = getPageDataByComponent(internals, pageId.slice(1));
96
+ if (pageData) {
97
+ yield pageData;
98
+ }
99
+ }
100
+ }
101
+ }
79
102
  export {
80
103
  createBuildInternals,
81
104
  eachPageData,
@@ -83,7 +106,10 @@ export {
83
106
  getPageDataByViteID,
84
107
  getPageDatasByChunk,
85
108
  getPageDatasByClientOnlyID,
109
+ getPageDatasByHoistedScriptId,
86
110
  hasPageDataByViteID,
111
+ isHoistedScript,
112
+ sortedCSS,
87
113
  trackClientOnlyPageDatas,
88
114
  trackPageData
89
115
  };
@@ -27,7 +27,7 @@ async function collectPagesData(opts) {
27
27
  component: route.component,
28
28
  route,
29
29
  moduleSpecifier: "",
30
- css: /* @__PURE__ */ new Set(),
30
+ css: /* @__PURE__ */ new Map(),
31
31
  hoistedScript: void 0
32
32
  };
33
33
  clearInterval(routeCollectionLogTimeout);
@@ -46,7 +46,7 @@ async function collectPagesData(opts) {
46
46
  component: route.component,
47
47
  route,
48
48
  moduleSpecifier: "",
49
- css: /* @__PURE__ */ new Set(),
49
+ css: /* @__PURE__ */ new Map(),
50
50
  hoistedScript: void 0
51
51
  };
52
52
  }
@@ -78,30 +78,27 @@ ${bgMagenta(black(" finalizing server assets "))}
78
78
  }
79
79
  }
80
80
  async function ssrBuild(opts, internals, input) {
81
- var _a, _b, _c, _d;
81
+ var _a, _b, _c;
82
82
  const { astroConfig, viteConfig } = opts;
83
83
  const ssr = astroConfig.output === "server";
84
84
  const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
85
85
  const viteBuildConfig = {
86
+ ...viteConfig,
86
87
  logLevel: opts.viteConfig.logLevel ?? "error",
87
88
  mode: "production",
88
- css: viteConfig.css,
89
- optimizeDeps: {
90
- include: [...((_a = viteConfig.optimizeDeps) == null ? void 0 : _a.include) ?? []],
91
- exclude: [...((_b = viteConfig.optimizeDeps) == null ? void 0 : _b.exclude) ?? []]
92
- },
93
89
  build: {
94
90
  ...viteConfig.build,
95
91
  emptyOutDir: false,
96
92
  manifest: false,
97
93
  outDir: fileURLToPath(out),
98
94
  rollupOptions: {
95
+ ...(_a = viteConfig.build) == null ? void 0 : _a.rollupOptions,
99
96
  input: [],
100
97
  output: {
101
98
  format: "esm",
102
99
  chunkFileNames: "chunks/[name].[hash].mjs",
103
100
  assetFileNames: "assets/[name].[hash][extname]",
104
- ...(_d = (_c = viteConfig.build) == null ? void 0 : _c.rollupOptions) == null ? void 0 : _d.output,
101
+ ...(_c = (_b = viteConfig.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.output,
105
102
  entryFileNames: opts.buildConfig.serverEntry
106
103
  }
107
104
  },
@@ -125,23 +122,20 @@ async function ssrBuild(opts, internals, input) {
125
122
  vitePluginAnalyzer(internals)
126
123
  ],
127
124
  publicDir: ssr ? false : viteConfig.publicDir,
128
- root: viteConfig.root,
129
125
  envPrefix: "PUBLIC_",
130
- server: viteConfig.server,
131
- base: astroConfig.base,
132
- ssr: viteConfig.ssr,
133
- resolve: viteConfig.resolve
126
+ base: astroConfig.base
134
127
  };
135
128
  await runHookBuildSetup({
136
129
  config: astroConfig,
137
130
  pages: internals.pagesByComponent,
138
131
  vite: viteBuildConfig,
139
- target: "server"
132
+ target: "server",
133
+ logging: opts.logging
140
134
  });
141
135
  return await vite.build(viteBuildConfig);
142
136
  }
143
137
  async function clientBuild(opts, internals, input) {
144
- var _a, _b, _c, _d;
138
+ var _a, _b, _c;
145
139
  const { astroConfig, viteConfig } = opts;
146
140
  const timer = performance.now();
147
141
  const ssr = astroConfig.output === "server";
@@ -155,26 +149,23 @@ async function clientBuild(opts, internals, input) {
155
149
  info(opts.logging, null, `
156
150
  ${bgGreen(black(" building client "))}`);
157
151
  const viteBuildConfig = {
152
+ ...viteConfig,
158
153
  logLevel: "info",
159
154
  mode: "production",
160
- css: viteConfig.css,
161
- optimizeDeps: {
162
- include: [...((_a = viteConfig.optimizeDeps) == null ? void 0 : _a.include) ?? []],
163
- exclude: [...((_b = viteConfig.optimizeDeps) == null ? void 0 : _b.exclude) ?? []]
164
- },
165
155
  build: {
166
156
  ...viteConfig.build,
167
157
  emptyOutDir: false,
168
158
  minify: "esbuild",
169
159
  outDir: fileURLToPath(out),
170
160
  rollupOptions: {
161
+ ...(_a = viteConfig.build) == null ? void 0 : _a.rollupOptions,
171
162
  input: Array.from(input),
172
163
  output: {
173
164
  format: "esm",
174
165
  entryFileNames: "[name].[hash].js",
175
166
  chunkFileNames: "chunks/[name].[hash].js",
176
167
  assetFileNames: "assets/[name].[hash][extname]",
177
- ...(_d = (_c = viteConfig.build) == null ? void 0 : _c.rollupOptions) == null ? void 0 : _d.output
168
+ ...(_c = (_b = viteConfig.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.output
178
169
  },
179
170
  preserveEntrySignatures: "exports-only"
180
171
  },
@@ -191,17 +182,15 @@ ${bgGreen(black(" building client "))}`);
191
182
  }),
192
183
  ...viteConfig.plugins || []
193
184
  ],
194
- publicDir: viteConfig.publicDir,
195
- root: viteConfig.root,
196
185
  envPrefix: "PUBLIC_",
197
- server: viteConfig.server,
198
186
  base: astroConfig.base
199
187
  };
200
188
  await runHookBuildSetup({
201
189
  config: astroConfig,
202
190
  pages: internals.pagesByComponent,
203
191
  vite: viteBuildConfig,
204
- target: "client"
192
+ target: "client",
193
+ logging: opts.logging
205
194
  });
206
195
  const buildResult = await vite.build(viteBuildConfig);
207
196
  info(opts.logging, null, dim(`Completed in ${getTimeStat(timer, performance.now())}.
@@ -15,7 +15,7 @@ function vitePluginAnalyzer(internals) {
15
15
  hoistedScripts.add(hid);
16
16
  }
17
17
  if (hoistedScripts.size) {
18
- for (const pageInfo of getTopLevelPages(from, this)) {
18
+ for (const [pageInfo] of getTopLevelPages(from, this)) {
19
19
  const pageId = pageInfo.id;
20
20
  for (const hid of hoistedScripts) {
21
21
  if (pageScripts.has(pageId)) {
@@ -77,7 +77,7 @@ function vitePluginAnalyzer(internals) {
77
77
  internals.discoveredClientOnlyComponents.add(cid);
78
78
  clientOnlys.push(cid);
79
79
  }
80
- for (const pageInfo of getTopLevelPages(id, this)) {
80
+ for (const [pageInfo] of getTopLevelPages(id, this)) {
81
81
  const pageData = getPageDataByViteID(internals, pageInfo.id);
82
82
  if (!pageData)
83
83
  continue;
@@ -3,12 +3,19 @@ import esbuild from "esbuild";
3
3
  import npath from "path";
4
4
  import { isCSSRequest } from "../render/util.js";
5
5
  import { relativeToSrcDir } from "../util.js";
6
- import { getTopLevelPages, walkParentInfos } from "./graph.js";
7
- import { getPageDataByViteID, getPageDatasByClientOnlyID } from "./internal.js";
6
+ import { getTopLevelPages, moduleIsTopLevelPage, walkParentInfos } from "./graph.js";
7
+ import {
8
+ eachPageData,
9
+ getPageDataByViteID,
10
+ getPageDatasByClientOnlyID,
11
+ getPageDatasByHoistedScriptId,
12
+ isHoistedScript
13
+ } from "./internal.js";
8
14
  const MAX_NAME_LENGTH = 70;
9
15
  function rollupPluginAstroBuildCSS(options) {
10
16
  const { internals, buildOptions } = options;
11
17
  const { astroConfig } = buildOptions;
18
+ let resolvedConfig;
12
19
  function nameifyPage(id) {
13
20
  let rel = relativeToSrcDir(astroConfig, id);
14
21
  if (rel.startsWith("pages/")) {
@@ -20,19 +27,19 @@ function rollupPluginAstroBuildCSS(options) {
20
27
  return named;
21
28
  }
22
29
  function createNameForParentPages(id, ctx) {
23
- const parents = Array.from(getTopLevelPages(id, ctx)).sort();
24
- const proposedName = parents.map((page) => nameifyPage(page.id)).join("-");
30
+ const parents = Array.from(getTopLevelPages(id, ctx));
31
+ const proposedName = parents.map(([page]) => nameifyPage(page.id)).sort().join("-");
25
32
  if (proposedName.length <= MAX_NAME_LENGTH) {
26
33
  return proposedName;
27
34
  }
28
35
  const hash = crypto.createHash("sha256");
29
- for (const page of parents) {
36
+ for (const [page] of parents) {
30
37
  hash.update(page.id, "utf-8");
31
38
  }
32
39
  return hash.digest("hex").slice(0, 8);
33
40
  }
34
41
  function* getParentClientOnlys(id, ctx) {
35
- for (const info of walkParentInfos(id, ctx)) {
42
+ for (const [info] of walkParentInfos(id, ctx)) {
36
43
  yield* getPageDatasByClientOnlyID(internals, info.id);
37
44
  }
38
45
  }
@@ -58,6 +65,18 @@ function rollupPluginAstroBuildCSS(options) {
58
65
  };
59
66
  },
60
67
  async generateBundle(_outputOptions, bundle) {
68
+ const appendCSSToPage = (pageData, meta, depth) => {
69
+ for (const importedCssImport of meta.importedCss) {
70
+ if (pageData == null ? void 0 : pageData.css.has(importedCssImport)) {
71
+ const cssInfo = pageData == null ? void 0 : pageData.css.get(importedCssImport);
72
+ if (depth < cssInfo.depth) {
73
+ cssInfo.depth = depth;
74
+ }
75
+ } else {
76
+ pageData == null ? void 0 : pageData.css.set(importedCssImport, { depth });
77
+ }
78
+ }
79
+ };
61
80
  for (const [_, chunk] of Object.entries(bundle)) {
62
81
  if (chunk.type === "chunk") {
63
82
  const c = chunk;
@@ -68,17 +87,26 @@ function rollupPluginAstroBuildCSS(options) {
68
87
  for (const [id] of Object.entries(c.modules)) {
69
88
  for (const pageData of getParentClientOnlys(id, this)) {
70
89
  for (const importedCssImport of meta.importedCss) {
71
- pageData.css.add(importedCssImport);
90
+ pageData.css.set(importedCssImport, { depth: -1 });
72
91
  }
73
92
  }
74
93
  }
75
94
  }
76
95
  for (const [id] of Object.entries(c.modules)) {
77
- for (const pageInfo of getTopLevelPages(id, this)) {
78
- const pageViteID = pageInfo.id;
79
- const pageData = getPageDataByViteID(internals, pageViteID);
80
- for (const importedCssImport of meta.importedCss) {
81
- pageData == null ? void 0 : pageData.css.add(importedCssImport);
96
+ for (const [pageInfo, depth] of walkParentInfos(id, this)) {
97
+ if (moduleIsTopLevelPage(pageInfo)) {
98
+ const pageViteID = pageInfo.id;
99
+ const pageData = getPageDataByViteID(internals, pageViteID);
100
+ if (pageData) {
101
+ appendCSSToPage(pageData, meta, depth);
102
+ }
103
+ } else if (options.target === "client" && isHoistedScript(internals, pageInfo.id)) {
104
+ for (const pageData of getPageDatasByHoistedScriptId(
105
+ internals,
106
+ pageInfo.id
107
+ )) {
108
+ appendCSSToPage(pageData, meta, -1);
109
+ }
82
110
  }
83
111
  }
84
112
  }
@@ -88,6 +116,25 @@ function rollupPluginAstroBuildCSS(options) {
88
116
  }
89
117
  }
90
118
  },
119
+ {
120
+ name: "astro:rollup-plugin-single-css",
121
+ enforce: "post",
122
+ configResolved(config) {
123
+ resolvedConfig = config;
124
+ },
125
+ generateBundle(_, bundle) {
126
+ if (!resolvedConfig.build.cssCodeSplit) {
127
+ const cssChunk = Object.values(bundle).find(
128
+ (chunk) => chunk.type === "asset" && chunk.name === "style.css"
129
+ );
130
+ if (cssChunk) {
131
+ for (const pageData of eachPageData(internals)) {
132
+ pageData.css.set(cssChunk.fileName, { depth: -1 });
133
+ }
134
+ }
135
+ }
136
+ }
137
+ },
91
138
  {
92
139
  name: "astro:rollup-plugin-build-css-minify",
93
140
  enforce: "post",
@@ -6,7 +6,7 @@ import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-sc
6
6
  import { pagesVirtualModuleId } from "../app/index.js";
7
7
  import { serializeRouteData } from "../routing/index.js";
8
8
  import { addRollupInput } from "./add-rollup-input.js";
9
- import { eachPageData } from "./internal.js";
9
+ import { eachPageData, sortedCSS } from "./internal.js";
10
10
  const virtualModuleId = "@astrojs-ssr-virtual-entry";
11
11
  const resolvedVirtualModuleId = "\0" + virtualModuleId;
12
12
  const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
@@ -83,7 +83,7 @@ async function injectManifest(buildOpts, internals) {
83
83
  }
84
84
  const staticFiles = internals.staticFiles;
85
85
  const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles));
86
- await runHookBuildSsr({ config: buildOpts.astroConfig, manifest });
86
+ await runHookBuildSsr({ config: buildOpts.astroConfig, manifest, logging: buildOpts.logging });
87
87
  const chunk = internals.ssrEntryChunk;
88
88
  const code = chunk.code;
89
89
  chunk.code = code.replace(replaceExp, () => {
@@ -110,7 +110,7 @@ function buildManifest(opts, internals, staticFiles) {
110
110
  }
111
111
  routes.push({
112
112
  file: "",
113
- links: Array.from(pageData.css).reverse(),
113
+ links: sortedCSS(pageData),
114
114
  scripts: [
115
115
  ...scripts,
116
116
  ...astroConfig._ctx.scripts.filter((script) => script.stage === "head-inline").map(({ stage, content }) => ({ stage, children: content }))
@@ -218,7 +218,7 @@ function resolveFlags(flags) {
218
218
  port: typeof flags.port === "number" ? flags.port : void 0,
219
219
  config: typeof flags.config === "string" ? flags.config : void 0,
220
220
  host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
221
- drafts: typeof flags.drafts === "boolean" ? flags.drafts : false
221
+ drafts: typeof flags.drafts === "boolean" ? flags.drafts : void 0
222
222
  };
223
223
  }
224
224
  function mergeCLIFlags(astroConfig, flags, cmd) {
@@ -52,7 +52,7 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
52
52
  htmlVitePlugin(),
53
53
  jsxVitePlugin({ config: astroConfig, logging }),
54
54
  astroPostprocessVitePlugin({ config: astroConfig }),
55
- astroIntegrationsContainerPlugin({ config: astroConfig }),
55
+ astroIntegrationsContainerPlugin({ config: astroConfig, logging }),
56
56
  astroScriptsPageSSRPlugin({ config: astroConfig })
57
57
  ],
58
58
  publicDir: fileURLToPath(astroConfig.publicDir),
@@ -16,7 +16,7 @@ async function dev(config, options) {
16
16
  const devStart = performance.now();
17
17
  applyPolyfill();
18
18
  await options.telemetry.record([]);
19
- config = await runHookConfigSetup({ config, command: "dev" });
19
+ config = await runHookConfigSetup({ config, command: "dev", logging: options.logging });
20
20
  const { host, port } = config.server;
21
21
  const rendererClientEntries = config._ctx.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
22
22
  const viteConfig = await createVite(
@@ -29,9 +29,9 @@ async function dev(config, options) {
29
29
  },
30
30
  { astroConfig: config, logging: options.logging, mode: "dev" }
31
31
  );
32
- await runHookConfigDone({ config });
32
+ await runHookConfigDone({ config, logging: options.logging });
33
33
  const viteServer = await vite.createServer(viteConfig);
34
- runHookServerSetup({ config, server: viteServer });
34
+ runHookServerSetup({ config, server: viteServer, logging: options.logging });
35
35
  await viteServer.listen(port);
36
36
  const devServerAddressInfo = viteServer.httpServer.address();
37
37
  const site = config.site ? new URL(config.base, config.site) : void 0;
@@ -46,14 +46,14 @@ async function dev(config, options) {
46
46
  https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
47
47
  })
48
48
  );
49
- const currentVersion = "1.0.6";
49
+ const currentVersion = "1.0.9";
50
50
  if (currentVersion.includes("-")) {
51
51
  warn(options.logging, null, msg.prerelease({ currentVersion }));
52
52
  }
53
53
  if (((_c = (_b = viteConfig.server) == null ? void 0 : _b.fs) == null ? void 0 : _c.strict) === false) {
54
54
  warn(options.logging, null, msg.fsStrictWarning());
55
55
  }
56
- await runHookServerStart({ config, address: devServerAddressInfo });
56
+ await runHookServerStart({ config, address: devServerAddressInfo, logging: options.logging });
57
57
  return {
58
58
  address: devServerAddressInfo,
59
59
  get watcher() {
@@ -61,7 +61,7 @@ async function dev(config, options) {
61
61
  },
62
62
  stop: async () => {
63
63
  await viteServer.close();
64
- await runHookServerDone({ config });
64
+ await runHookServerDone({ config, logging: options.logging });
65
65
  }
66
66
  };
67
67
  }
@@ -12,7 +12,7 @@ var AstroErrorCodes = /* @__PURE__ */ ((AstroErrorCodes2) => {
12
12
  return AstroErrorCodes2;
13
13
  })(AstroErrorCodes || {});
14
14
  function cleanErrorStack(stack) {
15
- return stack.split(/\n/g).filter((l) => /^\s*at/.test(l)).map((l) => l.replace(/\/@fs\//g, "/")).join("\n");
15
+ return stack.split(/\n/g).map((l) => l.replace(/\/@fs\//g, "/")).join("\n");
16
16
  }
17
17
  function fixViteErrorMessage(_err, server, filePath) {
18
18
  var _a, _b;
@@ -15,7 +15,6 @@ import {
15
15
  yellow
16
16
  } from "kleur/colors";
17
17
  import os from "os";
18
- import { cleanErrorStack } from "./errors.js";
19
18
  import { emoji, getLocalAddress, padMultilineString } from "./util.js";
20
19
  const PREFIX_PADDING = 6;
21
20
  function req({
@@ -47,7 +46,7 @@ function devStart({
47
46
  https,
48
47
  site
49
48
  }) {
50
- const version = "1.0.6";
49
+ const version = "1.0.9";
51
50
  const rootPath = site ? site.pathname : "/";
52
51
  const localPrefix = `${dim("\u2503")} Local `;
53
52
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -190,10 +189,10 @@ function formatErrorMessage(err, args = []) {
190
189
  args.push(red(padMultilineString(err.frame, 4)));
191
190
  }
192
191
  if (args.length === 1 && err.stack) {
193
- args.push(dim(cleanErrorStack(err.stack)));
192
+ args.push(dim(err.stack));
194
193
  } else if (err.stack) {
195
194
  args.push(` ${bold("Stacktrace:")}`);
196
- args.push(dim(cleanErrorStack(err.stack)));
195
+ args.push(dim(err.stack));
197
196
  args.push(``);
198
197
  }
199
198
  return args.join("\n");
@@ -226,7 +225,7 @@ function printHelp({
226
225
  message.push(
227
226
  linebreak(),
228
227
  ` ${bgGreen(black(` ${commandName} `))} ${green(
229
- `v${"1.0.6"}`
228
+ `v${"1.0.9"}`
230
229
  )} ${headline}`
231
230
  );
232
231
  }