astro 1.0.0-beta.34 → 1.0.0-beta.35

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
@@ -40,7 +40,7 @@ function printAstroHelp() {
40
40
  });
41
41
  }
42
42
  async function printVersion() {
43
- const version = "1.0.0-beta.34";
43
+ const version = "1.0.0-beta.35";
44
44
  console.log();
45
45
  console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
46
46
  }
@@ -83,7 +83,7 @@ async function cli(args) {
83
83
  } else if (flags.silent) {
84
84
  logging.level = "silent";
85
85
  }
86
- const telemetry = new AstroTelemetry({ version: "1.0.0-beta.34" });
86
+ const telemetry = new AstroTelemetry({ version: "1.0.0-beta.35" });
87
87
  if (cmd === "telemetry") {
88
88
  try {
89
89
  const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
@@ -97,7 +97,7 @@ async function cli(args) {
97
97
  try {
98
98
  const packages = flags._.slice(3);
99
99
  telemetry.record(event.eventCliSession({
100
- astroVersion: "1.0.0-beta.34",
100
+ astroVersion: "1.0.0-beta.35",
101
101
  cliCommand: "add"
102
102
  }));
103
103
  return await add(packages, { cwd: root, flags, logging, telemetry });
@@ -108,7 +108,7 @@ async function cli(args) {
108
108
  case "dev": {
109
109
  try {
110
110
  const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
111
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.34", cliCommand: "dev" }, userConfig, flags));
111
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.35", cliCommand: "dev" }, userConfig, flags));
112
112
  await devServer(astroConfig, { logging, telemetry });
113
113
  return await new Promise(() => {
114
114
  });
@@ -119,7 +119,7 @@ async function cli(args) {
119
119
  case "build": {
120
120
  try {
121
121
  const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
122
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.34", cliCommand: "build" }, userConfig, flags));
122
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.35", cliCommand: "build" }, userConfig, flags));
123
123
  return await build(astroConfig, { logging, telemetry });
124
124
  } catch (err) {
125
125
  return throwAndExit(err);
@@ -127,14 +127,14 @@ async function cli(args) {
127
127
  }
128
128
  case "check": {
129
129
  const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
130
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.34", cliCommand: "check" }, userConfig, flags));
130
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.35", cliCommand: "check" }, userConfig, flags));
131
131
  const ret = await check(astroConfig);
132
132
  return process.exit(ret);
133
133
  }
134
134
  case "preview": {
135
135
  try {
136
136
  const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
137
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.34", cliCommand: "preview" }, userConfig, flags));
137
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.35", cliCommand: "preview" }, userConfig, flags));
138
138
  const server = await preview(astroConfig, { logging, telemetry });
139
139
  return await server.closed();
140
140
  } catch (err) {
@@ -144,7 +144,7 @@ async function cli(args) {
144
144
  case "docs": {
145
145
  try {
146
146
  await telemetry.record(event.eventCliSession({
147
- astroVersion: "1.0.0-beta.34",
147
+ astroVersion: "1.0.0-beta.35",
148
148
  cliCommand: "docs"
149
149
  }));
150
150
  return await openInBrowser("https://docs.astro.build/");
@@ -159,6 +159,7 @@ async function generatePath(pathname, opts, gopts) {
159
159
  }
160
160
  const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type);
161
161
  const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
162
+ pageData.route.distURL = outFile;
162
163
  await fs.promises.mkdir(outFolder, { recursive: true });
163
164
  await fs.promises.writeFile(outFile, body, "utf-8");
164
165
  }
@@ -42,15 +42,14 @@ function* getPageDatasByChunk(internals, chunk) {
42
42
  }
43
43
  }
44
44
  }
45
- function* getPageDatasByClientOnlyChunk(internals, chunk) {
45
+ function* getPageDatasByClientOnlyID(internals, viteid) {
46
46
  const pagesByClientOnly = internals.pagesByClientOnly;
47
47
  if (pagesByClientOnly.size) {
48
- for (const [modulePath] of Object.entries(chunk.modules)) {
49
- const pathname = `/@fs${prependForwardSlash(modulePath)}`;
50
- if (pagesByClientOnly.has(pathname)) {
51
- for (const pageData of pagesByClientOnly.get(pathname)) {
52
- yield pageData;
53
- }
48
+ const pathname = `/@fs${prependForwardSlash(viteid)}`;
49
+ const pageBuildDatas = pagesByClientOnly.get(pathname);
50
+ if (pageBuildDatas) {
51
+ for (const pageData of pageBuildDatas) {
52
+ yield pageData;
54
53
  }
55
54
  }
56
55
  }
@@ -79,7 +78,7 @@ export {
79
78
  getPageDataByComponent,
80
79
  getPageDataByViteID,
81
80
  getPageDatasByChunk,
82
- getPageDatasByClientOnlyChunk,
81
+ getPageDatasByClientOnlyID,
83
82
  hasPageDataByViteID,
84
83
  trackClientOnlyPageDatas,
85
84
  trackPageData
@@ -36,7 +36,7 @@ async function dev(config, options) {
36
36
  site,
37
37
  https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
38
38
  }));
39
- const currentVersion = "1.0.0-beta.34";
39
+ const currentVersion = "1.0.0-beta.35";
40
40
  if (currentVersion.includes("-")) {
41
41
  warn(options.logging, null, msg.prerelease({ currentVersion }));
42
42
  }
@@ -47,7 +47,7 @@ function devStart({
47
47
  https,
48
48
  site
49
49
  }) {
50
- const version = "1.0.0-beta.34";
50
+ const version = "1.0.0-beta.35";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -203,7 +203,7 @@ function printHelp({
203
203
  };
204
204
  let message = [];
205
205
  if (headline) {
206
- message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.34"}`)} ${headline}`);
206
+ message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.35"}`)} ${headline}`);
207
207
  }
208
208
  if (usage) {
209
209
  message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
@@ -1,4 +1,4 @@
1
- async function onLoad(astroId, options, getHydrateCallback) {
1
+ async function onOnly(astroId, options, getHydrateCallback) {
2
2
  const roots = document.querySelectorAll(`astro-root[uid="${astroId}"]`);
3
3
  if (roots.length === 0) {
4
4
  throw new Error(`Unable to find the root for the component ${options.name}`);
@@ -20,5 +20,5 @@ async function onLoad(astroId, options, getHydrateCallback) {
20
20
  }
21
21
  }
22
22
  export {
23
- onLoad as default
23
+ onOnly as default
24
24
  };
@@ -876,6 +876,7 @@ export interface RouteData {
876
876
  generate: (data?: any) => string;
877
877
  params: string[];
878
878
  pathname?: string;
879
+ distURL?: URL;
879
880
  pattern: RegExp;
880
881
  segments: RoutePart[][];
881
882
  type: RouteType;
@@ -29,7 +29,7 @@ export declare function trackPageData(internals: BuildInternals, component: stri
29
29
  */
30
30
  export declare function trackClientOnlyPageDatas(internals: BuildInternals, pageData: PageBuildData, clientOnlys: string[]): void;
31
31
  export declare function getPageDatasByChunk(internals: BuildInternals, chunk: RenderedChunk): Generator<PageBuildData, void, unknown>;
32
- export declare function getPageDatasByClientOnlyChunk(internals: BuildInternals, chunk: RenderedChunk): Generator<PageBuildData, void, unknown>;
32
+ export declare function getPageDatasByClientOnlyID(internals: BuildInternals, viteid: ViteID): Generator<PageBuildData, void, unknown>;
33
33
  export declare function getPageDataByComponent(internals: BuildInternals, component: string): PageBuildData | undefined;
34
34
  export declare function getPageDataByViteID(internals: BuildInternals, viteid: ViteID): PageBuildData | undefined;
35
35
  export declare function hasPageDataByViteID(internals: BuildInternals, viteid: ViteID): boolean;
@@ -1,6 +1,6 @@
1
1
  import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro';
2
2
  /**
3
- * Hydrate this component as soon as the main thread is free
3
+ * Hydrate this component as soon as the main thread is free!
4
4
  * (or after a short delay, if `requestIdleCallback`) isn't supported
5
5
  */
6
6
  export default function onIdle(astroId: string, options: HydrateOptions, getHydrateCallback: GetHydrateCallback): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro';
2
2
  /**
3
- * Hydrate this component immediately
3
+ * Hydrate this component immediately!
4
4
  */
5
5
  export default function onLoad(astroId: string, options: HydrateOptions, getHydrateCallback: GetHydrateCallback): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro';
2
2
  /**
3
- * Hydrate this component when a matching media query is found
3
+ * Hydrate this component when a matching media query is found!
4
4
  */
5
5
  export default function onMedia(astroId: string, options: HydrateOptions, getHydrateCallback: GetHydrateCallback): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro';
2
2
  /**
3
- * Hydrate this component immediately
3
+ * Hydrate this component only on the client
4
4
  */
5
- export default function onLoad(astroId: string, options: HydrateOptions, getHydrateCallback: GetHydrateCallback): Promise<void>;
5
+ export default function onOnly(astroId: string, options: HydrateOptions, getHydrateCallback: GetHydrateCallback): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import type { GetHydrateCallback, HydrateOptions } from '../../@types/astro';
2
2
  /**
3
- * Hydrate this component when one of it's children becomes visible.
3
+ * Hydrate this component when one of it's children becomes visible!
4
4
  * We target the children because `astro-root` is set to `display: contents`
5
5
  * which doesn't work with IntersectionObserver
6
6
  */
@@ -1,154 +1,126 @@
1
- import * as path from "path";
2
- import esbuild from "esbuild";
3
1
  import { isCSSRequest } from "../core/render/util.js";
4
- import {
5
- getPageDatasByChunk,
6
- getPageDataByViteID,
7
- hasPageDataByViteID,
8
- getPageDatasByClientOnlyChunk
9
- } from "../core/build/internal.js";
10
- const PLUGIN_NAME = "@astrojs/rollup-plugin-build-css";
11
- const ASTRO_STYLE_PREFIX = "@astro-inline-style";
12
- const ASTRO_PAGE_STYLE_PREFIX = "@astro-page-all-styles";
13
- function isStyleVirtualModule(id) {
14
- return id.startsWith(ASTRO_STYLE_PREFIX);
15
- }
16
- function isPageStyleVirtualModule(id) {
17
- return id.startsWith(ASTRO_PAGE_STYLE_PREFIX);
18
- }
19
- function isRawOrUrlModule(id) {
20
- return id.match(/(\?|\&)([^=]+)(raw|url)/gm);
21
- }
2
+ import { getPageDataByViteID, getPageDatasByClientOnlyID } from "../core/build/internal.js";
3
+ import { resolvedPagesVirtualModuleId } from "../core/app/index.js";
4
+ import crypto from "crypto";
22
5
  function rollupPluginAstroBuildCSS(options) {
23
6
  const { internals } = options;
24
- const styleSourceMap = /* @__PURE__ */ new Map();
25
- function* walkStyles(ctx, id, seen = /* @__PURE__ */ new Set()) {
7
+ function* walkParentInfos(id, ctx, seen = /* @__PURE__ */ new Set()) {
26
8
  seen.add(id);
27
- if (styleSourceMap.has(id)) {
28
- yield [id, styleSourceMap.get(id)];
29
- }
30
9
  const info = ctx.getModuleInfo(id);
31
10
  if (info) {
32
- for (const importedId of [...info.importedIds, ...info.dynamicallyImportedIds]) {
33
- if (!seen.has(importedId) && !isRawOrUrlModule(importedId)) {
34
- yield* walkStyles(ctx, importedId, seen);
35
- }
11
+ yield info;
12
+ }
13
+ const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
14
+ for (const imp of importers) {
15
+ if (seen.has(imp)) {
16
+ continue;
36
17
  }
18
+ yield* walkParentInfos(imp, ctx, seen);
37
19
  }
38
20
  }
39
- async function addStyles() {
40
- var _a;
41
- for (const id of this.getModuleIds()) {
42
- if (hasPageDataByViteID(internals, id)) {
43
- let pageStyles = "";
44
- for (const [_styleId, styles] of walkStyles(this, id)) {
45
- pageStyles += styles;
46
- }
47
- if (!pageStyles)
48
- continue;
49
- const { code: minifiedCSS } = await esbuild.transform(pageStyles, {
50
- loader: "css",
51
- minify: true
52
- });
53
- const referenceId = this.emitFile({
54
- name: "entry.css",
55
- type: "asset",
56
- source: minifiedCSS
57
- });
58
- const fileName = this.getFileName(referenceId);
59
- (_a = getPageDataByViteID(internals, id)) == null ? void 0 : _a.css.add(fileName);
21
+ function* getTopLevelPages(id, ctx) {
22
+ for (const info of walkParentInfos(id, ctx)) {
23
+ const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
24
+ if (importers.length <= 2 && importers[0] === resolvedPagesVirtualModuleId) {
25
+ yield info.id;
60
26
  }
61
27
  }
62
28
  }
29
+ function createHashOfPageParents(id, ctx) {
30
+ const parents = Array.from(getTopLevelPages(id, ctx)).sort();
31
+ const hash = crypto.createHash("sha256");
32
+ for (const page of parents) {
33
+ hash.update(page, "utf-8");
34
+ }
35
+ return hash.digest("hex").slice(0, 8);
36
+ }
37
+ function* getParentClientOnlys(id, ctx) {
38
+ for (const info of walkParentInfos(id, ctx)) {
39
+ yield* getPageDatasByClientOnlyID(internals, info.id);
40
+ }
41
+ }
63
42
  return {
64
- name: PLUGIN_NAME,
43
+ name: "@astrojs/rollup-plugin-build-css",
65
44
  configResolved(resolvedConfig) {
66
45
  const plugins = resolvedConfig.plugins;
67
46
  const viteCSSPostIndex = resolvedConfig.plugins.findIndex((p) => p.name === "vite:css-post");
68
47
  if (viteCSSPostIndex !== -1) {
69
48
  const viteCSSPost = plugins[viteCSSPostIndex];
70
- delete viteCSSPost.renderChunk;
71
- delete viteCSSPost.generateBundle;
72
- const ourIndex = plugins.findIndex((p) => p.name === PLUGIN_NAME);
49
+ const renderChunk = viteCSSPost.renderChunk;
50
+ if (renderChunk) {
51
+ viteCSSPost.renderChunk = async function(...args) {
52
+ const minifyOption = resolvedConfig.build.minify;
53
+ if (minifyOption === false) {
54
+ resolvedConfig.build.minify = "esbuild";
55
+ }
56
+ const result = await renderChunk.apply(this, args);
57
+ if (typeof result === "string") {
58
+ return {
59
+ code: result
60
+ };
61
+ }
62
+ resolvedConfig.build.minify = minifyOption;
63
+ return result || null;
64
+ };
65
+ }
66
+ const ourIndex = plugins.findIndex((p) => p.name === "@astrojs/rollup-plugin-build-css");
73
67
  const ourPlugin = plugins[ourIndex];
74
68
  plugins.splice(ourIndex, 1);
75
69
  plugins.splice(viteCSSPostIndex - 1, 0, ourPlugin);
76
70
  }
77
71
  },
78
- async resolveId(id) {
79
- if (isPageStyleVirtualModule(id)) {
80
- return id;
81
- }
82
- if (isStyleVirtualModule(id)) {
83
- return id;
84
- }
85
- return void 0;
86
- },
87
- async transform(value, id) {
88
- if (isStyleVirtualModule(id)) {
89
- styleSourceMap.set(id, value);
90
- }
91
- if (isCSSRequest(id)) {
92
- styleSourceMap.set(id, value);
93
- }
94
- return null;
95
- },
96
- async renderChunk(_code, chunk) {
97
- if (options.target === "server")
98
- return null;
99
- let chunkCSS = "";
100
- let isPureCSS = true;
101
- for (const [id] of Object.entries(chunk.modules)) {
102
- if (!isCSSRequest(id) && !isPageStyleVirtualModule(id)) {
103
- isPureCSS = false;
104
- }
105
- if (styleSourceMap.has(id)) {
106
- chunkCSS += styleSourceMap.get(id);
107
- }
108
- }
109
- if (!chunkCSS)
110
- return null;
111
- if (isPureCSS) {
112
- internals.pureCSSChunks.add(chunk);
113
- }
114
- const { code: minifiedCSS } = await esbuild.transform(chunkCSS, {
115
- loader: "css",
116
- minify: true
117
- });
118
- const referenceId = this.emitFile({
119
- name: chunk.name + ".css",
120
- type: "asset",
121
- source: minifiedCSS
122
- });
123
- if (chunk.type === "chunk") {
124
- const fileName = this.getFileName(referenceId);
125
- for (const pageData of getPageDatasByChunk(internals, chunk)) {
126
- pageData.css.add(fileName);
72
+ outputOptions(outputOptions) {
73
+ const manualChunks = outputOptions.manualChunks || Function.prototype;
74
+ outputOptions.manualChunks = function(id, ...args) {
75
+ if (typeof manualChunks == "object") {
76
+ if (id in manualChunks) {
77
+ return manualChunks[id];
78
+ }
79
+ } else if (typeof manualChunks === "function") {
80
+ const outid = manualChunks.call(this, id, ...args);
81
+ if (outid) {
82
+ return outid;
83
+ }
127
84
  }
128
- for (const pageData of getPageDatasByClientOnlyChunk(internals, chunk)) {
129
- pageData.css.add(fileName);
85
+ if (isCSSRequest(id)) {
86
+ return createHashOfPageParents(id, args[0]);
130
87
  }
131
- }
132
- return null;
88
+ };
133
89
  },
134
- async generateBundle(opts, bundle) {
135
- const hasPureCSSChunks = internals.pureCSSChunks.size;
136
- const pureChunkFilenames = new Set([...internals.pureCSSChunks].map((chunk) => chunk.fileName));
137
- const emptyChunkFiles = [...pureChunkFilenames].map((file) => path.basename(file)).join("|").replace(/\./g, "\\.");
138
- const emptyChunkRE = new RegExp(opts.format === "es" ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";
139
- ?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);
140
- ?`, "g");
141
- await addStyles.call(this);
142
- for (const [chunkId, chunk] of Object.entries(bundle)) {
90
+ async generateBundle(_outputOptions, bundle) {
91
+ for (const [_, chunk] of Object.entries(bundle)) {
143
92
  if (chunk.type === "chunk") {
144
- if (hasPureCSSChunks) {
145
- if (internals.pureCSSChunks.has(chunk) && !chunk.exports.length) {
146
- delete bundle[chunkId];
147
- } else {
148
- chunk.code = chunk.code.replace(emptyChunkRE, (m) => `/* empty css ${"".padEnd(m.length - 15)}*/`);
93
+ const c = chunk;
94
+ if ("viteMetadata" in chunk) {
95
+ const meta = chunk["viteMetadata"];
96
+ if (meta.importedCss.size) {
97
+ if (options.target === "client") {
98
+ for (const [id] of Object.entries(c.modules)) {
99
+ for (const pageData of getParentClientOnlys(id, this)) {
100
+ for (const importedCssImport of meta.importedCss) {
101
+ pageData.css.add(importedCssImport);
102
+ }
103
+ }
104
+ }
105
+ }
106
+ for (const [id] of Object.entries(c.modules)) {
107
+ for (const pageViteID of getTopLevelPages(id, this)) {
108
+ const pageData = getPageDataByViteID(internals, pageViteID);
109
+ for (const importedCssImport of meta.importedCss) {
110
+ pageData == null ? void 0 : pageData.css.add(importedCssImport);
111
+ }
112
+ }
113
+ }
149
114
  }
150
115
  }
151
116
  }
117
+ if (chunk.type === "chunk") {
118
+ const exp = new RegExp(`(\\bimport\\s*)[']([^']*(?:[a-z]+.[0-9a-z]+.m?js))['](;
119
+ ?)`, "g");
120
+ chunk.code = chunk.code.replace(exp, (_match, begin, chunkPath, end) => {
121
+ return begin + '"' + chunkPath + '"' + end;
122
+ });
123
+ }
152
124
  }
153
125
  }
154
126
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.0.0-beta.34",
3
+ "version": "1.0.0-beta.35",
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",
@@ -66,7 +66,7 @@
66
66
  "vendor"
67
67
  ],
68
68
  "dependencies": {
69
- "@astrojs/compiler": "^0.15.0",
69
+ "@astrojs/compiler": "^0.15.1",
70
70
  "@astrojs/language-server": "^0.13.4",
71
71
  "@astrojs/markdown-remark": "^0.10.1",
72
72
  "@astrojs/prism": "0.4.1",