astro 0.25.2 → 0.26.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 (151) hide show
  1. package/dist/@types/astro.js +0 -0
  2. package/dist/@types/serialize-javascript.d.js +0 -0
  3. package/dist/@types/shorthash.d.js +0 -0
  4. package/dist/adapter-ssg/index.js +0 -0
  5. package/dist/cli/check.js +4 -4
  6. package/dist/cli/index.js +21 -32
  7. package/dist/core/add/babel.js +0 -0
  8. package/dist/core/add/consts.js +0 -0
  9. package/dist/core/add/imports.js +0 -0
  10. package/dist/core/add/index.js +7 -14
  11. package/dist/core/add/wrapper.js +0 -0
  12. package/dist/core/app/common.js +0 -0
  13. package/dist/core/app/index.js +13 -10
  14. package/dist/core/app/node.js +0 -0
  15. package/dist/core/app/types.js +0 -0
  16. package/dist/core/build/add-rollup-input.js +0 -0
  17. package/dist/core/build/common.js +4 -5
  18. package/dist/core/build/generate.js +65 -72
  19. package/dist/core/build/index.js +59 -74
  20. package/dist/core/build/internal.js +4 -0
  21. package/dist/core/build/page-data.js +10 -9
  22. package/dist/core/build/static-build.js +46 -28
  23. package/dist/core/build/types.d.js +0 -0
  24. package/dist/core/build/util.js +0 -0
  25. package/dist/core/build/vite-plugin-hoisted-scripts.js +1 -1
  26. package/dist/core/build/vite-plugin-internals.js +0 -0
  27. package/dist/core/build/vite-plugin-pages.js +1 -0
  28. package/dist/core/build/vite-plugin-ssr.js +4 -2
  29. package/dist/core/config.js +87 -79
  30. package/dist/core/create-vite.js +12 -7
  31. package/dist/core/dev/index.js +8 -7
  32. package/dist/core/endpoint/dev/index.js +5 -10
  33. package/dist/core/endpoint/index.js +1 -3
  34. package/dist/core/errors.js +45 -0
  35. package/dist/core/logger/console.js +43 -0
  36. package/dist/core/logger/core.js +103 -0
  37. package/dist/core/logger/node.js +94 -0
  38. package/dist/core/messages.js +50 -24
  39. package/dist/core/path.js +0 -0
  40. package/dist/core/polyfill.js +0 -0
  41. package/dist/core/preview/index.js +8 -8
  42. package/dist/core/preview/util.js +3 -6
  43. package/dist/core/render/core.js +5 -6
  44. package/dist/core/render/dev/css.js +5 -6
  45. package/dist/core/render/dev/hmr.js +0 -0
  46. package/dist/core/render/dev/html.js +0 -0
  47. package/dist/core/render/dev/index.js +23 -36
  48. package/dist/core/render/paginate.js +0 -0
  49. package/dist/core/render/pretty-feed.js +103 -0
  50. package/dist/core/render/result.js +33 -15
  51. package/dist/core/render/route-cache.js +2 -2
  52. package/dist/core/render/rss.js +5 -4
  53. package/dist/core/render/script.js +0 -0
  54. package/dist/core/render/ssr-element.js +1 -1
  55. package/dist/core/render/util.js +26 -0
  56. package/dist/core/request.js +27 -0
  57. package/dist/core/routing/index.js +0 -0
  58. package/dist/core/routing/manifest/create.js +8 -6
  59. package/dist/core/routing/manifest/serialization.js +0 -0
  60. package/dist/core/routing/match.js +0 -0
  61. package/dist/core/routing/params.js +0 -0
  62. package/dist/core/routing/validation.js +1 -1
  63. package/dist/core/util.js +57 -125
  64. package/dist/integrations/index.js +9 -1
  65. package/dist/runtime/client/hmr.js +0 -0
  66. package/dist/runtime/client/idle.js +0 -0
  67. package/dist/runtime/client/load.js +0 -0
  68. package/dist/runtime/client/media.js +0 -0
  69. package/dist/runtime/client/only.js +0 -0
  70. package/dist/runtime/client/visible.js +0 -0
  71. package/dist/runtime/server/escape.js +0 -0
  72. package/dist/runtime/server/hydration.js +0 -0
  73. package/dist/runtime/server/index.js +42 -36
  74. package/dist/runtime/server/metadata.js +0 -0
  75. package/dist/runtime/server/util.js +0 -0
  76. package/dist/template/4xx.js +1 -1
  77. package/dist/template/5xx.js +0 -0
  78. package/dist/template/css.js +0 -0
  79. package/dist/types/@types/astro.d.ts +291 -233
  80. package/dist/types/cli/index.d.ts +1 -1
  81. package/dist/types/core/add/index.d.ts +1 -1
  82. package/dist/types/core/build/common.d.ts +0 -1
  83. package/dist/types/core/build/generate.d.ts +1 -1
  84. package/dist/types/core/build/index.d.ts +1 -1
  85. package/dist/types/core/build/internal.d.ts +1 -0
  86. package/dist/types/core/build/page-data.d.ts +1 -1
  87. package/dist/types/core/build/vite-plugin-pages.d.ts +1 -0
  88. package/dist/types/core/config.d.ts +125 -116
  89. package/dist/types/core/create-vite.d.ts +1 -1
  90. package/dist/types/core/dev/index.d.ts +1 -1
  91. package/dist/types/core/endpoint/index.d.ts +1 -1
  92. package/dist/types/core/errors.d.ts +23 -0
  93. package/dist/types/core/logger/console.d.ts +4 -0
  94. package/dist/types/core/{logger.d.ts → logger/core.d.ts} +7 -22
  95. package/dist/types/core/logger/node.d.ts +34 -0
  96. package/dist/types/core/messages.d.ts +4 -2
  97. package/dist/types/core/preview/index.d.ts +1 -1
  98. package/dist/types/core/preview/util.d.ts +1 -2
  99. package/dist/types/core/render/core.d.ts +2 -3
  100. package/dist/types/core/render/dev/css.d.ts +0 -2
  101. package/dist/types/core/render/dev/index.d.ts +4 -6
  102. package/dist/types/core/render/pretty-feed.d.ts +2 -0
  103. package/dist/types/core/render/result.d.ts +2 -3
  104. package/dist/types/core/render/route-cache.d.ts +1 -1
  105. package/dist/types/core/render/util.d.ts +6 -0
  106. package/dist/types/core/request.d.ts +14 -0
  107. package/dist/types/core/routing/manifest/create.d.ts +1 -1
  108. package/dist/types/core/routing/validation.d.ts +1 -1
  109. package/dist/types/core/util.d.ts +11 -7
  110. package/dist/types/integrations/index.d.ts +6 -0
  111. package/dist/types/runtime/server/index.d.ts +1 -2
  112. package/dist/types/vite-plugin-astro/hmr.d.ts +1 -1
  113. package/dist/types/vite-plugin-astro/index.d.ts +1 -1
  114. package/dist/types/vite-plugin-astro-server/index.d.ts +1 -1
  115. package/dist/types/vite-plugin-build-css/index.d.ts +2 -1
  116. package/dist/types/vite-plugin-build-html/extract-assets.d.ts +1 -1
  117. package/dist/types/vite-plugin-build-html/index.d.ts +3 -3
  118. package/dist/types/vite-plugin-config-alias/index.d.ts +1 -1
  119. package/dist/types/vite-plugin-jsx/index.d.ts +1 -1
  120. package/dist/vite-plugin-astro/compile.js +12 -14
  121. package/dist/vite-plugin-astro/hmr.js +2 -2
  122. package/dist/vite-plugin-astro/index.js +21 -8
  123. package/dist/vite-plugin-astro/query.js +0 -0
  124. package/dist/vite-plugin-astro/styles.js +1 -1
  125. package/dist/vite-plugin-astro-postprocess/index.js +31 -34
  126. package/dist/vite-plugin-astro-server/index.js +50 -22
  127. package/dist/vite-plugin-build-css/index.js +47 -4
  128. package/dist/vite-plugin-build-css/resolve.js +0 -0
  129. package/dist/vite-plugin-build-html/add-rollup-input.js +0 -0
  130. package/dist/vite-plugin-build-html/extract-assets.js +0 -0
  131. package/dist/vite-plugin-build-html/index.js +22 -23
  132. package/dist/vite-plugin-build-html/util.js +0 -0
  133. package/dist/vite-plugin-config-alias/index.js +1 -1
  134. package/dist/vite-plugin-env/index.js +1 -1
  135. package/dist/vite-plugin-integrations-container/index.js +0 -0
  136. package/dist/vite-plugin-jsx/index.js +1 -1
  137. package/dist/vite-plugin-markdown/index.js +89 -18
  138. package/dist/vite-plugin-scripts/index.js +0 -0
  139. package/env.d.ts +1 -1
  140. package/package.json +13 -9
  141. package/dist/core/build/scan-based-build.js +0 -61
  142. package/dist/core/dev/util.js +0 -44
  143. package/dist/core/logger.js +0 -174
  144. package/dist/core/render/dev/error.js +0 -34
  145. package/dist/core/render/request.js +0 -23
  146. package/dist/core/render/sitemap.js +0 -18
  147. package/dist/types/core/build/scan-based-build.d.ts +0 -18
  148. package/dist/types/core/dev/util.d.ts +0 -9
  149. package/dist/types/core/render/dev/error.d.ts +0 -7
  150. package/dist/types/core/render/request.d.ts +0 -15
  151. package/dist/types/core/render/sitemap.d.ts +0 -2
@@ -26,6 +26,7 @@ import load from "@proload/core";
26
26
  import loadTypeScript from "@proload/plugin-tsm";
27
27
  import postcssrc from "postcss-load-config";
28
28
  import { arraify, isObject } from "./util.js";
29
+ import { appendForwardSlash, trimSlashes } from "./path.js";
29
30
  load.use([loadTypeScript]);
30
31
  async function resolvePostcssConfig(inlineOptions, root) {
31
32
  if (isObject(inlineOptions)) {
@@ -49,50 +50,66 @@ async function resolvePostcssConfig(inlineOptions, root) {
49
50
  };
50
51
  }
51
52
  }
53
+ const LEGACY_ASTRO_CONFIG_KEYS = /* @__PURE__ */ new Set([
54
+ "projectRoot",
55
+ "src",
56
+ "pages",
57
+ "public",
58
+ "dist",
59
+ "styleOptions",
60
+ "markdownOptions",
61
+ "buildOptions",
62
+ "devOptions",
63
+ "experimentalIntegrations"
64
+ ]);
52
65
  const AstroConfigSchema = z.object({
53
- projectRoot: z.string().optional().default(".").transform((val) => new URL(val)),
54
- src: z.string().optional().default("./src").transform((val) => new URL(val)),
55
- pages: z.string().optional().default("./src/pages").transform((val) => new URL(val)),
56
- public: z.string().optional().default("./public").transform((val) => new URL(val)),
57
- dist: z.string().optional().default("./dist").transform((val) => new URL(val)),
58
- integrations: z.preprocess((val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val, z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default([])),
59
66
  adapter: z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) }).optional(),
60
- styleOptions: z.object({
67
+ root: z.string().optional().default(".").transform((val) => new URL(val)),
68
+ srcDir: z.string().optional().default("./src").transform((val) => new URL(val)),
69
+ publicDir: z.string().optional().default("./public").transform((val) => new URL(val)),
70
+ outDir: z.string().optional().default("./dist").transform((val) => new URL(val)),
71
+ site: z.string().url().optional().transform((val) => val ? appendForwardSlash(val) : val).refine((val) => !val || new URL(val).pathname.length <= 1, {
72
+ message: '"site" must be a valid URL origin (ex: "https://example.com") but cannot contain a URL path (ex: "https://example.com/blog"). Use "base" to configure your deployed URL path'
73
+ }),
74
+ base: z.string().optional().default("./").transform((val) => val ? appendForwardSlash(trimSlashes(val)) : val),
75
+ trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default("ignore"),
76
+ build: z.object({
77
+ format: z.union([z.literal("file"), z.literal("directory")]).optional().default("directory")
78
+ }).optional().default({}),
79
+ server: z.preprocess((val) => typeof val === "function" ? val({ command: "error" }) : val, z.object({
80
+ host: z.union([z.string(), z.boolean()]).optional().default(false),
81
+ port: z.number().optional().default(3e3)
82
+ }).optional().default({})),
83
+ integrations: z.preprocess((val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val, z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default([])),
84
+ style: z.object({
61
85
  postcss: z.object({
62
86
  options: z.any(),
63
87
  plugins: z.array(z.any())
64
88
  }).optional().default({ options: {}, plugins: [] })
65
89
  }).optional().default({}),
66
- markdownOptions: z.object({
67
- render: z.any().optional().default(["@astrojs/markdown-remark", {}])
68
- }).strict().optional().default({}),
69
- buildOptions: z.object({
70
- site: z.string().optional().transform((val) => val ? addTrailingSlash(val) : val),
71
- sitemapFilter: z.function().optional(),
72
- sitemap: z.boolean().optional().default(true),
73
- pageUrlFormat: z.union([z.literal("file"), z.literal("directory")]).optional().default("directory"),
74
- legacyBuild: z.boolean().optional().default(false),
75
- experimentalStaticBuild: z.boolean().optional().default(true),
76
- experimentalSsr: z.boolean().optional().default(false),
77
- drafts: z.boolean().optional().default(false)
78
- }).optional().default({}),
79
- devOptions: z.object({
80
- host: z.union([z.string(), z.boolean()]).optional().default(false),
81
- hostname: z.string().optional().default("localhost"),
82
- port: z.number().optional().default(3e3),
83
- trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default("ignore")
84
- }).optional().default({}),
85
- experimentalIntegrations: z.boolean().optional().default(false),
86
- vite: z.any().optional().default({})
90
+ markdown: z.object({
91
+ drafts: z.boolean().optional().default(false),
92
+ mode: z.union([z.literal("md"), z.literal("mdx")]).optional().default("md"),
93
+ syntaxHighlight: z.union([z.literal("shiki"), z.literal("prism"), z.literal(false)]).optional().default("shiki"),
94
+ shikiConfig: z.any().optional().default({}),
95
+ remarkPlugins: z.array(z.any()).optional().default([]),
96
+ rehypePlugins: z.array(z.any()).optional().default([])
97
+ }).passthrough().optional().default({}),
98
+ vite: z.any().optional().default({}),
99
+ experimental: z.object({
100
+ ssr: z.boolean().optional().default(false),
101
+ integrations: z.boolean().optional().default(false)
102
+ }).optional().default({})
87
103
  });
88
- async function validateConfig(userConfig, root) {
104
+ async function validateConfig(userConfig, root, cmd) {
105
+ var _a;
89
106
  const fileProtocolRoot = pathToFileURL(root + path.sep);
90
107
  if (userConfig.hasOwnProperty("renderers")) {
91
108
  console.error('Astro "renderers" are now "integrations"!');
92
109
  console.error("Update your configuration and install new dependencies:");
93
110
  try {
94
111
  const rendererKeywords = userConfig.renderers.map((r) => r.replace("@astrojs/renderer-", ""));
95
- const rendererImports = rendererKeywords.map((r) => ` import ${r} from '@astrojs/${r}';`).join("\n");
112
+ const rendererImports = rendererKeywords.map((r) => ` import ${r} from '@astrojs/${r === "solid" ? "solid-js" : r}';`).join("\n");
96
113
  const rendererIntegrations = rendererKeywords.map((r) => ` ${r}(),`).join("\n");
97
114
  console.error("");
98
115
  console.error(colors.dim(" // astro.config.js"));
@@ -113,13 +130,27 @@ async function validateConfig(userConfig, root) {
113
130
  }
114
131
  process.exit(1);
115
132
  }
133
+ let oldConfig = false;
134
+ for (const key of Object.keys(userConfig)) {
135
+ if (LEGACY_ASTRO_CONFIG_KEYS.has(key)) {
136
+ oldConfig = true;
137
+ break;
138
+ }
139
+ }
140
+ if (oldConfig) {
141
+ throw new Error(`Legacy configuration detected. Please update your configuration to the new format!
142
+ See https://astro.build/config for more information.`);
143
+ }
116
144
  const AstroConfigRelativeSchema = AstroConfigSchema.extend({
117
- projectRoot: z.string().default(".").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
118
- src: z.string().default("./src").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
119
- pages: z.string().default("./src/pages").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
120
- public: z.string().default("./public").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
121
- dist: z.string().default("./dist").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
122
- styleOptions: z.object({
145
+ root: z.string().default(".").transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
146
+ srcDir: z.string().default("./src").transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
147
+ publicDir: z.string().default("./public").transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
148
+ outDir: z.string().default("./dist").transform((val) => new URL(appendForwardSlash(val), fileProtocolRoot)),
149
+ server: z.preprocess((val) => typeof val === "function" ? val({ command: cmd === "dev" ? "dev" : "preview" }) : val, z.object({
150
+ host: z.union([z.string(), z.boolean()]).optional().default(false),
151
+ port: z.number().optional().default(3e3)
152
+ }).optional().default({})),
153
+ style: z.object({
123
154
  postcss: z.preprocess((val) => resolvePostcssConfig(val, fileProtocolRoot), z.object({
124
155
  options: z.any(),
125
156
  plugins: z.array(z.any())
@@ -129,7 +160,7 @@ async function validateConfig(userConfig, root) {
129
160
  const result = __spreadProps(__spreadValues({}, await AstroConfigRelativeSchema.parseAsync(userConfig)), {
130
161
  _ctx: { scripts: [], renderers: [], adapter: void 0 }
131
162
  });
132
- if (!result.experimentalIntegrations && !result.integrations.every((int) => int.name.startsWith("@astrojs/"))) {
163
+ if (!((_a = result.experimental) == null ? void 0 : _a.integrations) && !result.integrations.every((int) => int.name.startsWith("@astrojs/"))) {
133
164
  throw new Error([
134
165
  `Astro integrations are still experimental.`,
135
166
  ``,
@@ -141,52 +172,34 @@ async function validateConfig(userConfig, root) {
141
172
  }
142
173
  return result;
143
174
  }
144
- function addTrailingSlash(str) {
145
- return str.replace(/\/*$/, "/");
146
- }
147
175
  function resolveFlags(flags) {
148
- if (flags.experimentalStaticBuild) {
149
- console.warn(`Passing --experimental-static-build is no longer necessary and is now the default. The flag will be removed in a future version of Astro.`);
150
- }
151
176
  return {
152
- projectRoot: typeof flags.projectRoot === "string" ? flags.projectRoot : void 0,
177
+ root: typeof flags.root === "string" ? flags.root : void 0,
153
178
  site: typeof flags.site === "string" ? flags.site : void 0,
154
- sitemap: typeof flags.sitemap === "boolean" ? flags.sitemap : void 0,
155
179
  port: typeof flags.port === "number" ? flags.port : void 0,
156
180
  config: typeof flags.config === "string" ? flags.config : void 0,
157
- hostname: typeof flags.hostname === "string" ? flags.hostname : void 0,
158
181
  host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
159
- legacyBuild: typeof flags.legacyBuild === "boolean" ? flags.legacyBuild : false,
160
182
  experimentalSsr: typeof flags.experimentalSsr === "boolean" ? flags.experimentalSsr : false,
161
183
  experimentalIntegrations: typeof flags.experimentalIntegrations === "boolean" ? flags.experimentalIntegrations : false,
162
184
  drafts: typeof flags.drafts === "boolean" ? flags.drafts : false
163
185
  };
164
186
  }
165
- function mergeCLIFlags(astroConfig, flags) {
166
- astroConfig.buildOptions = astroConfig.buildOptions || {};
167
- astroConfig.devOptions = astroConfig.devOptions || {};
168
- if (typeof flags.sitemap === "boolean")
169
- astroConfig.buildOptions.sitemap = flags.sitemap;
187
+ function mergeCLIFlags(astroConfig, flags, cmd) {
188
+ astroConfig.server = astroConfig.server || {};
189
+ astroConfig.experimental = astroConfig.experimental || {};
190
+ astroConfig.markdown = astroConfig.markdown || {};
170
191
  if (typeof flags.site === "string")
171
- astroConfig.buildOptions.site = flags.site;
172
- if (typeof flags.port === "number")
173
- astroConfig.devOptions.port = flags.port;
174
- if (typeof flags.host === "string" || typeof flags.host === "boolean")
175
- astroConfig.devOptions.host = flags.host;
176
- if (typeof flags.hostname === "string")
177
- astroConfig.devOptions.hostname = flags.hostname;
178
- if (typeof flags.legacyBuild === "boolean")
179
- astroConfig.buildOptions.legacyBuild = flags.legacyBuild;
180
- if (typeof flags.experimentalSsr === "boolean") {
181
- astroConfig.buildOptions.experimentalSsr = flags.experimentalSsr;
182
- if (flags.experimentalSsr) {
183
- astroConfig.buildOptions.legacyBuild = false;
184
- }
185
- }
192
+ astroConfig.site = flags.site;
193
+ if (typeof flags.experimentalSsr === "boolean")
194
+ astroConfig.experimental.ssr = flags.experimentalSsr;
186
195
  if (typeof flags.experimentalIntegrations === "boolean")
187
- astroConfig.experimentalIntegrations = flags.experimentalIntegrations;
196
+ astroConfig.experimental.integrations = flags.experimentalIntegrations;
188
197
  if (typeof flags.drafts === "boolean")
189
- astroConfig.buildOptions.drafts = flags.drafts;
198
+ astroConfig.markdown.drafts = flags.drafts;
199
+ if (typeof flags.port === "number")
200
+ astroConfig.server.port = flags.port;
201
+ if (typeof flags.host === "string" || typeof flags.host === "boolean")
202
+ astroConfig.server.host = flags.host;
190
203
  return astroConfig;
191
204
  }
192
205
  async function resolveConfigURL(configOptions) {
@@ -215,18 +228,13 @@ async function loadConfig(configOptions) {
215
228
  if (config) {
216
229
  userConfig = config.value;
217
230
  }
218
- return resolveConfig(userConfig, root, flags);
231
+ return resolveConfig(userConfig, root, flags, configOptions.cmd);
219
232
  }
220
- async function resolveConfig(userConfig, root, flags = {}) {
221
- const mergedConfig = mergeCLIFlags(userConfig, flags);
222
- const validatedConfig = await validateConfig(mergedConfig, root);
233
+ async function resolveConfig(userConfig, root, flags = {}, cmd) {
234
+ const mergedConfig = mergeCLIFlags(userConfig, flags, cmd);
235
+ const validatedConfig = await validateConfig(mergedConfig, root, cmd);
223
236
  return validatedConfig;
224
237
  }
225
- function formatConfigError(err) {
226
- const errorList = err.issues.map((issue) => ` ! ${colors.bold(issue.path.join("."))} ${colors.red(issue.message + ".")}`);
227
- return `${colors.red("[config]")} Astro found issue(s) with your configuration:
228
- ${errorList.join("\n")}`;
229
- }
230
238
  function mergeConfigRecursively(defaults, overrides, rootPath) {
231
239
  const merged = __spreadValues({}, defaults);
232
240
  for (const key in overrides) {
@@ -260,7 +268,7 @@ function mergeConfig(defaults, overrides, isRoot = true) {
260
268
  }
261
269
  export {
262
270
  AstroConfigSchema,
263
- formatConfigError,
271
+ LEGACY_ASTRO_CONFIG_KEYS,
264
272
  loadConfig,
265
273
  mergeConfig,
266
274
  resolveConfig,
@@ -29,7 +29,7 @@ const ALWAYS_NOEXTERNAL = /* @__PURE__ */ new Set([
29
29
  async function createVite(commandConfig, { astroConfig, logging, mode }) {
30
30
  const astroPackages = await getAstroPackages(astroConfig);
31
31
  const commonConfig = {
32
- cacheDir: fileURLToPath(new URL("./node_modules/.vite/", astroConfig.projectRoot)),
32
+ cacheDir: fileURLToPath(new URL("./node_modules/.vite/", astroConfig.root)),
33
33
  clearScreen: false,
34
34
  logLevel: "warn",
35
35
  optimizeDeps: {
@@ -46,8 +46,8 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
46
46
  astroPostprocessVitePlugin({ config: astroConfig }),
47
47
  astroIntegrationsContainerPlugin({ config: astroConfig })
48
48
  ],
49
- publicDir: fileURLToPath(astroConfig.public),
50
- root: fileURLToPath(astroConfig.projectRoot),
49
+ publicDir: fileURLToPath(astroConfig.publicDir),
50
+ root: fileURLToPath(astroConfig.root),
51
51
  envPrefix: "PUBLIC_",
52
52
  server: {
53
53
  force: true,
@@ -55,7 +55,12 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
55
55
  proxy: {}
56
56
  },
57
57
  css: {
58
- postcss: astroConfig.styleOptions.postcss || {}
58
+ postcss: astroConfig.style.postcss || {}
59
+ },
60
+ resolve: {
61
+ alias: {
62
+ randombytes: "randombytes/browser"
63
+ }
59
64
  },
60
65
  ssr: {
61
66
  external: [...ALWAYS_EXTERNAL],
@@ -67,8 +72,8 @@ async function createVite(commandConfig, { astroConfig, logging, mode }) {
67
72
  result = vite.mergeConfig(result, commandConfig);
68
73
  return result;
69
74
  }
70
- async function getAstroPackages({ projectRoot }) {
71
- const pkgUrl = new URL("./package.json", projectRoot);
75
+ async function getAstroPackages({ root }) {
76
+ const pkgUrl = new URL("./package.json", root);
72
77
  const pkgPath = fileURLToPath(pkgUrl);
73
78
  if (!fs.existsSync(pkgPath))
74
79
  return [];
@@ -79,7 +84,7 @@ async function getAstroPackages({ projectRoot }) {
79
84
  return false;
80
85
  if (/^astro\-/.test(dep))
81
86
  return true;
82
- const depPkgUrl = new URL(`./node_modules/${dep}/package.json`, projectRoot);
87
+ const depPkgUrl = new URL(`./node_modules/${dep}/package.json`, root);
83
88
  const depPkgPath = fileURLToPath(depPkgUrl);
84
89
  if (!fs.existsSync(depPkgPath))
85
90
  return false;
@@ -2,28 +2,29 @@ import { performance } from "perf_hooks";
2
2
  import * as vite from "vite";
3
3
  import { runHookConfigDone, runHookConfigSetup, runHookServerDone, runHookServerSetup, runHookServerStart } from "../../integrations/index.js";
4
4
  import { createVite } from "../create-vite.js";
5
- import { defaultLogOptions, info, warn, warnIfUsingExperimentalSSR } from "../logger.js";
5
+ import { info, warn, warnIfUsingExperimentalSSR } from "../logger/core.js";
6
+ import { nodeLogOptions } from "../logger/node.js";
6
7
  import * as msg from "../messages.js";
7
8
  import { apply as applyPolyfill } from "../polyfill.js";
8
- import { getResolvedHostForVite } from "./util.js";
9
- async function dev(config, options = { logging: defaultLogOptions }) {
9
+ async function dev(config, options = { logging: nodeLogOptions }) {
10
10
  var _a;
11
11
  const devStart = performance.now();
12
12
  applyPolyfill();
13
13
  config = await runHookConfigSetup({ config, command: "dev" });
14
+ const { host, port } = config.server;
14
15
  const viteConfig = await createVite({
15
16
  mode: "development",
16
- server: { host: getResolvedHostForVite(config) }
17
+ server: { host }
17
18
  }, { astroConfig: config, logging: options.logging, mode: "dev" });
18
19
  await runHookConfigDone({ config });
19
20
  warnIfUsingExperimentalSSR(options.logging, config);
20
21
  const viteServer = await vite.createServer(viteConfig);
21
22
  runHookServerSetup({ config, server: viteServer });
22
- await viteServer.listen(config.devOptions.port);
23
+ await viteServer.listen(port);
23
24
  const devServerAddressInfo = viteServer.httpServer.address();
24
- const site = config.buildOptions.site ? new URL(config.buildOptions.site) : void 0;
25
+ const site = config.site ? new URL(config.base, config.site) : void 0;
25
26
  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";
27
+ const currentVersion = "0.26.0";
27
28
  if (currentVersion.includes("-")) {
28
29
  warn(options.logging, null, msg.prerelease({ currentVersion }));
29
30
  }
@@ -18,18 +18,13 @@ var __spreadValues = (a, b) => {
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { preload } from "../../render/dev/index.js";
21
- import { errorHandler } from "../../render/dev/error.js";
21
+ import { isBuildingToSSR } from "../../util.js";
22
22
  import { call as callEndpoint } from "../index.js";
23
23
  async function call(ssrOpts) {
24
- try {
25
- const [, mod] = await preload(ssrOpts);
26
- return await callEndpoint(mod, __spreadProps(__spreadValues({}, ssrOpts), {
27
- ssr: ssrOpts.astroConfig.buildOptions.experimentalSsr
28
- }));
29
- } catch (e) {
30
- await errorHandler(e, { viteServer: ssrOpts.viteServer, filePath: ssrOpts.filePath });
31
- throw e;
32
- }
24
+ const [, mod] = await preload(ssrOpts);
25
+ return await callEndpoint(mod, __spreadProps(__spreadValues({}, ssrOpts), {
26
+ ssr: isBuildingToSSR(ssrOpts.astroConfig)
27
+ }));
33
28
  }
34
29
  export {
35
30
  call
@@ -19,15 +19,13 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { renderEndpoint } from "../../runtime/server/index.js";
21
21
  import { getParamsAndProps, GetParamsAndPropsError } from "../render/core.js";
22
- import { createRequest } from "../render/request.js";
23
22
  async function call(mod, opts) {
24
23
  const paramsAndPropsResp = await getParamsAndProps(__spreadProps(__spreadValues({}, opts), { mod }));
25
24
  if (paramsAndPropsResp === GetParamsAndPropsError.NoMatchingStaticPath) {
26
25
  throw new Error(`[getStaticPath] route pattern matched, but no matching static path found. (${opts.pathname})`);
27
26
  }
28
27
  const [params] = paramsAndPropsResp;
29
- const request = createRequest(opts.method, opts.pathname, opts.headers, opts.origin, opts.site, opts.ssr);
30
- const response = await renderEndpoint(mod, request, params);
28
+ const response = await renderEndpoint(mod, opts.request, params);
31
29
  if (response instanceof Response) {
32
30
  return {
33
31
  type: "response",
@@ -0,0 +1,45 @@
1
+ import eol from "eol";
2
+ import fs from "fs";
3
+ import { codeFrame, createSafeError } from "./util.js";
4
+ function cleanErrorStack(stack) {
5
+ return stack.split(/\n/g).filter((l) => /^\s*at/.test(l)).join("\n");
6
+ }
7
+ function fixViteErrorMessage(_err, server) {
8
+ const err = createSafeError(_err);
9
+ server.ssrFixStacktrace(err);
10
+ if (err.message === "import.meta.glob() can only accept string literals.") {
11
+ err.message = "Astro.glob() and import.meta.glob() can only accept string literals.";
12
+ }
13
+ return err;
14
+ }
15
+ function collectErrorMetadata(e) {
16
+ if (e.stack) {
17
+ e.stack = eol.lf(e.stack);
18
+ }
19
+ if (Array.isArray(e.errors)) {
20
+ const { location, pluginName, text } = e.errors[0];
21
+ const err = e;
22
+ if (location) {
23
+ err.loc = { file: location.file, line: location.line, column: location.column };
24
+ err.id = err.id || (location == null ? void 0 : location.file);
25
+ }
26
+ const possibleFilePath = err.pluginCode || err.id || (location == null ? void 0 : location.file);
27
+ if (possibleFilePath && !err.frame) {
28
+ try {
29
+ const fileContents = fs.readFileSync(possibleFilePath, "utf8");
30
+ err.frame = codeFrame(fileContents, err.loc);
31
+ } catch {
32
+ }
33
+ }
34
+ if (pluginName) {
35
+ err.plugin = pluginName;
36
+ }
37
+ return err;
38
+ }
39
+ return e;
40
+ }
41
+ export {
42
+ cleanErrorStack,
43
+ collectErrorMetadata,
44
+ fixViteErrorMessage
45
+ };
@@ -0,0 +1,43 @@
1
+ import { bold, cyan, dim, red, yellow, reset } from "kleur/colors";
2
+ import { format as utilFormat } from "util";
3
+ import { levels, dateTimeFormat } from "./core.js";
4
+ let lastMessage;
5
+ let lastMessageCount = 1;
6
+ const consoleLogDestination = {
7
+ write(event) {
8
+ let dest = console.error;
9
+ if (levels[event.level] < levels["error"]) {
10
+ dest = console.log;
11
+ }
12
+ function getPrefix() {
13
+ let prefix = "";
14
+ let type = event.type;
15
+ if (type) {
16
+ prefix += dim(dateTimeFormat.format(new Date()) + " ");
17
+ if (event.level === "info") {
18
+ type = bold(cyan(`[${type}]`));
19
+ } else if (event.level === "warn") {
20
+ type = bold(yellow(`[${type}]`));
21
+ } else if (event.level === "error") {
22
+ type = bold(red(`[${type}]`));
23
+ }
24
+ prefix += `${type} `;
25
+ }
26
+ return reset(prefix);
27
+ }
28
+ let message = utilFormat(...event.args);
29
+ if (message === lastMessage) {
30
+ lastMessageCount++;
31
+ message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
32
+ } else {
33
+ lastMessage = message;
34
+ lastMessageCount = 1;
35
+ }
36
+ const outMessage = getPrefix() + message;
37
+ dest(outMessage);
38
+ return true;
39
+ }
40
+ };
41
+ export {
42
+ consoleLogDestination
43
+ };
@@ -0,0 +1,103 @@
1
+ import { bold, dim } from "kleur/colors";
2
+ import stringWidth from "string-width";
3
+ function getLoggerLocale() {
4
+ const defaultLocale = "en-US";
5
+ if (process.env.LANG) {
6
+ const extractedLocale = process.env.LANG.split(".")[0].replace(/_/g, "-");
7
+ if (extractedLocale.length < 2)
8
+ return defaultLocale;
9
+ else
10
+ return extractedLocale.substring(0, 5);
11
+ } else
12
+ return defaultLocale;
13
+ }
14
+ const dateTimeFormat = new Intl.DateTimeFormat(getLoggerLocale(), {
15
+ hour: "2-digit",
16
+ minute: "2-digit",
17
+ second: "2-digit"
18
+ });
19
+ const levels = {
20
+ debug: 20,
21
+ info: 30,
22
+ warn: 40,
23
+ error: 50,
24
+ silent: 90
25
+ };
26
+ function log(opts, level, type, ...args) {
27
+ const logLevel = opts.level;
28
+ const dest = opts.dest;
29
+ const event = {
30
+ type,
31
+ level,
32
+ args,
33
+ message: ""
34
+ };
35
+ if (levels[logLevel] > levels[level]) {
36
+ return;
37
+ }
38
+ dest.write(event);
39
+ }
40
+ function info(opts, type, ...messages) {
41
+ return log(opts, "info", type, ...messages);
42
+ }
43
+ function warn(opts, type, ...messages) {
44
+ return log(opts, "warn", type, ...messages);
45
+ }
46
+ function error(opts, type, ...messages) {
47
+ return log(opts, "error", type, ...messages);
48
+ }
49
+ function table(opts, columns) {
50
+ return function logTable(logFn, ...input) {
51
+ const messages = columns.map((len, i) => padStr(input[i].toString(), len));
52
+ logFn(opts, null, ...messages);
53
+ };
54
+ }
55
+ function debug(...args) {
56
+ if ("_astroGlobalDebug" in globalThis) {
57
+ globalThis._astroGlobalDebug(...args);
58
+ }
59
+ }
60
+ function padStr(str, len) {
61
+ const strLen = stringWidth(str);
62
+ if (strLen > len) {
63
+ return str.substring(0, len - 3) + "...";
64
+ }
65
+ const spaces = Array.from({ length: len - strLen }, () => " ").join("");
66
+ return str + spaces;
67
+ }
68
+ let defaultLogLevel;
69
+ if (typeof process !== "undefined") {
70
+ if (process.argv.includes("--verbose")) {
71
+ defaultLogLevel = "debug";
72
+ } else if (process.argv.includes("--silent")) {
73
+ defaultLogLevel = "silent";
74
+ } else {
75
+ defaultLogLevel = "info";
76
+ }
77
+ } else {
78
+ defaultLogLevel = "info";
79
+ }
80
+ function timerMessage(message, startTime = Date.now()) {
81
+ let timeDiff = Date.now() - startTime;
82
+ let timeDisplay = timeDiff < 750 ? `${Math.round(timeDiff)}ms` : `${(timeDiff / 1e3).toFixed(1)}s`;
83
+ return `${message} ${dim(timeDisplay)}`;
84
+ }
85
+ function warnIfUsingExperimentalSSR(opts, config) {
86
+ var _a;
87
+ if ((_a = config._ctx.adapter) == null ? void 0 : _a.serverEntrypoint) {
88
+ warn(opts, "warning", bold(`Warning:`), ` SSR support is still experimental and subject to API changes. If using in production pin your dependencies to prevent accidental breakage.`);
89
+ }
90
+ }
91
+ export {
92
+ dateTimeFormat,
93
+ debug,
94
+ defaultLogLevel,
95
+ error,
96
+ info,
97
+ levels,
98
+ log,
99
+ table,
100
+ timerMessage,
101
+ warn,
102
+ warnIfUsingExperimentalSSR
103
+ };
@@ -0,0 +1,94 @@
1
+ import { bold, cyan, dim, red, yellow, reset } from "kleur/colors";
2
+ import stringWidth from "string-width";
3
+ import debugPackage from "debug";
4
+ import { format as utilFormat } from "util";
5
+ import * as readline from "readline";
6
+ import { Writable } from "stream";
7
+ import { info, warn, error, dateTimeFormat } from "./core.js";
8
+ let lastMessage;
9
+ let lastMessageCount = 1;
10
+ const nodeLogDestination = new Writable({
11
+ objectMode: true,
12
+ write(event, _, callback) {
13
+ let dest = process.stderr;
14
+ if (levels[event.level] < levels["error"]) {
15
+ dest = process.stdout;
16
+ }
17
+ function getPrefix() {
18
+ let prefix = "";
19
+ let type = event.type;
20
+ if (type) {
21
+ prefix += dim(dateTimeFormat.format(new Date()) + " ");
22
+ if (event.level === "info") {
23
+ type = bold(cyan(`[${type}]`));
24
+ } else if (event.level === "warn") {
25
+ type = bold(yellow(`[${type}]`));
26
+ } else if (event.level === "error") {
27
+ type = bold(red(`[${type}]`));
28
+ }
29
+ prefix += `${type} `;
30
+ }
31
+ return reset(prefix);
32
+ }
33
+ let message = utilFormat(...event.args);
34
+ if (message === lastMessage) {
35
+ lastMessageCount++;
36
+ if (levels[event.level] < levels["error"]) {
37
+ let lines = 1;
38
+ let len = stringWidth(`${getPrefix()}${message}`);
39
+ let cols = dest.columns;
40
+ if (len > cols) {
41
+ lines = Math.ceil(len / cols);
42
+ }
43
+ for (let i = 0; i < lines; i++) {
44
+ readline.clearLine(dest, 0);
45
+ readline.cursorTo(dest, 0);
46
+ readline.moveCursor(dest, 0, -1);
47
+ }
48
+ }
49
+ message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
50
+ } else {
51
+ lastMessage = message;
52
+ lastMessageCount = 1;
53
+ }
54
+ dest.write(getPrefix());
55
+ dest.write(message);
56
+ dest.write("\n");
57
+ callback();
58
+ }
59
+ });
60
+ const nodeLogOptions = {
61
+ dest: nodeLogDestination,
62
+ level: "info"
63
+ };
64
+ const levels = {
65
+ debug: 20,
66
+ info: 30,
67
+ warn: 40,
68
+ error: 50,
69
+ silent: 90
70
+ };
71
+ const debuggers = {};
72
+ function debug(type, ...messages) {
73
+ const namespace = `astro:${type}`;
74
+ debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
75
+ return debuggers[namespace](...messages);
76
+ }
77
+ globalThis._astroGlobalDebug = debug;
78
+ const logger = {
79
+ info: info.bind(null, nodeLogOptions),
80
+ warn: warn.bind(null, nodeLogOptions),
81
+ error: error.bind(null, nodeLogOptions)
82
+ };
83
+ function enableVerboseLogging() {
84
+ debug("cli", '--verbose flag enabled! Enabling: DEBUG="*,-babel"');
85
+ debug("cli", 'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".');
86
+ }
87
+ export {
88
+ debug,
89
+ enableVerboseLogging,
90
+ levels,
91
+ logger,
92
+ nodeLogDestination,
93
+ nodeLogOptions
94
+ };