astro 0.25.3 → 0.26.1

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 (111) hide show
  1. package/astro.js +12 -4
  2. package/dist/cli/check.js +4 -4
  3. package/dist/cli/index.js +21 -32
  4. package/dist/core/add/index.js +36 -20
  5. package/dist/core/app/index.js +17 -11
  6. package/dist/core/build/common.js +4 -5
  7. package/dist/core/build/generate.js +69 -73
  8. package/dist/core/build/index.js +90 -77
  9. package/dist/core/build/page-data.js +10 -9
  10. package/dist/core/build/static-build.js +41 -24
  11. package/dist/core/build/vite-plugin-hoisted-scripts.js +1 -1
  12. package/dist/core/build/vite-plugin-ssr.js +5 -2
  13. package/dist/core/config.js +89 -79
  14. package/dist/core/create-vite.js +17 -8
  15. package/dist/core/dev/index.js +22 -9
  16. package/dist/core/endpoint/dev/index.js +5 -10
  17. package/dist/core/endpoint/index.js +1 -3
  18. package/dist/core/errors.js +45 -0
  19. package/dist/core/logger/console.js +43 -0
  20. package/dist/core/logger/core.js +103 -0
  21. package/dist/core/logger/node.js +94 -0
  22. package/dist/core/messages.js +79 -28
  23. package/dist/core/preview/index.js +15 -9
  24. package/dist/core/preview/util.js +3 -6
  25. package/dist/core/render/core.js +21 -6
  26. package/dist/core/render/dev/css.js +5 -6
  27. package/dist/core/render/dev/index.js +43 -38
  28. package/dist/core/render/paginate.js +3 -1
  29. package/dist/core/render/pretty-feed.js +103 -0
  30. package/dist/core/render/result.js +33 -15
  31. package/dist/core/render/route-cache.js +12 -3
  32. package/dist/core/render/rss.js +5 -4
  33. package/dist/core/render/ssr-element.js +1 -1
  34. package/dist/core/render/util.js +35 -0
  35. package/dist/core/request.js +33 -0
  36. package/dist/core/routing/manifest/create.js +8 -6
  37. package/dist/core/routing/validation.js +1 -1
  38. package/dist/core/util.js +57 -125
  39. package/dist/integrations/index.js +38 -6
  40. package/dist/runtime/server/index.js +51 -41
  41. package/dist/template/4xx.js +8 -2
  42. package/dist/template/5xx.js +8 -1
  43. package/dist/types/@types/astro.d.ts +290 -232
  44. package/dist/types/cli/index.d.ts +1 -1
  45. package/dist/types/core/add/index.d.ts +1 -1
  46. package/dist/types/core/build/common.d.ts +0 -1
  47. package/dist/types/core/build/generate.d.ts +1 -1
  48. package/dist/types/core/build/index.d.ts +1 -1
  49. package/dist/types/core/build/page-data.d.ts +1 -1
  50. package/dist/types/core/config.d.ts +125 -116
  51. package/dist/types/core/create-vite.d.ts +1 -1
  52. package/dist/types/core/dev/index.d.ts +1 -1
  53. package/dist/types/core/endpoint/index.d.ts +1 -1
  54. package/dist/types/core/errors.d.ts +23 -0
  55. package/dist/types/core/logger/console.d.ts +4 -0
  56. package/dist/types/core/{logger.d.ts → logger/core.d.ts} +7 -22
  57. package/dist/types/core/logger/node.d.ts +34 -0
  58. package/dist/types/core/messages.d.ts +5 -3
  59. package/dist/types/core/preview/index.d.ts +1 -1
  60. package/dist/types/core/preview/util.d.ts +1 -2
  61. package/dist/types/core/render/core.d.ts +2 -3
  62. package/dist/types/core/render/dev/css.d.ts +0 -2
  63. package/dist/types/core/render/dev/index.d.ts +5 -7
  64. package/dist/types/core/render/pretty-feed.d.ts +2 -0
  65. package/dist/types/core/render/result.d.ts +2 -3
  66. package/dist/types/core/render/route-cache.d.ts +2 -2
  67. package/dist/types/core/render/util.d.ts +6 -0
  68. package/dist/types/core/request.d.ts +14 -0
  69. package/dist/types/core/routing/manifest/create.d.ts +1 -1
  70. package/dist/types/core/routing/validation.d.ts +1 -1
  71. package/dist/types/core/util.d.ts +11 -7
  72. package/dist/types/integrations/index.d.ts +11 -5
  73. package/dist/types/runtime/server/index.d.ts +1 -2
  74. package/dist/types/template/4xx.d.ts +1 -1
  75. package/dist/types/template/5xx.d.ts +1 -1
  76. package/dist/types/vite-plugin-astro/hmr.d.ts +1 -1
  77. package/dist/types/vite-plugin-astro/index.d.ts +1 -1
  78. package/dist/types/vite-plugin-astro/styles.d.ts +1 -1
  79. package/dist/types/vite-plugin-astro-server/index.d.ts +1 -1
  80. package/dist/types/vite-plugin-build-html/extract-assets.d.ts +1 -1
  81. package/dist/types/vite-plugin-build-html/index.d.ts +3 -3
  82. package/dist/types/vite-plugin-config-alias/index.d.ts +1 -1
  83. package/dist/types/vite-plugin-env/index.d.ts +1 -1
  84. package/dist/types/vite-plugin-integrations-container/index.d.ts +1 -1
  85. package/dist/types/vite-plugin-jsx/index.d.ts +1 -1
  86. package/dist/vite-plugin-astro/compile.js +12 -14
  87. package/dist/vite-plugin-astro/hmr.js +2 -2
  88. package/dist/vite-plugin-astro/index.js +41 -13
  89. package/dist/vite-plugin-astro/styles.js +8 -2
  90. package/dist/vite-plugin-astro-postprocess/index.js +35 -34
  91. package/dist/vite-plugin-astro-server/index.js +66 -25
  92. package/dist/vite-plugin-build-css/index.js +6 -2
  93. package/dist/vite-plugin-build-html/index.js +43 -23
  94. package/dist/vite-plugin-config-alias/index.js +4 -2
  95. package/dist/vite-plugin-env/index.js +8 -3
  96. package/dist/vite-plugin-integrations-container/index.js +3 -1
  97. package/dist/vite-plugin-jsx/index.js +22 -4
  98. package/dist/vite-plugin-markdown/index.js +93 -18
  99. package/env.d.ts +1 -1
  100. package/package.json +13 -9
  101. package/dist/core/build/scan-based-build.js +0 -62
  102. package/dist/core/dev/util.js +0 -44
  103. package/dist/core/logger.js +0 -174
  104. package/dist/core/render/dev/error.js +0 -34
  105. package/dist/core/render/request.js +0 -23
  106. package/dist/core/render/sitemap.js +0 -18
  107. package/dist/types/core/build/scan-based-build.d.ts +0 -18
  108. package/dist/types/core/dev/util.d.ts +0 -9
  109. package/dist/types/core/render/dev/error.d.ts +0 -7
  110. package/dist/types/core/render/request.d.ts +0 -15
  111. 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,36 @@ 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
+ }
202
+ if (typeof flags.host === "string" || typeof flags.host === "boolean") {
203
+ astroConfig.server.host = flags.host;
204
+ }
190
205
  return astroConfig;
191
206
  }
192
207
  async function resolveConfigURL(configOptions) {
@@ -215,18 +230,13 @@ async function loadConfig(configOptions) {
215
230
  if (config) {
216
231
  userConfig = config.value;
217
232
  }
218
- return resolveConfig(userConfig, root, flags);
233
+ return resolveConfig(userConfig, root, flags, configOptions.cmd);
219
234
  }
220
- async function resolveConfig(userConfig, root, flags = {}) {
221
- const mergedConfig = mergeCLIFlags(userConfig, flags);
222
- const validatedConfig = await validateConfig(mergedConfig, root);
235
+ async function resolveConfig(userConfig, root, flags = {}, cmd) {
236
+ const mergedConfig = mergeCLIFlags(userConfig, flags, cmd);
237
+ const validatedConfig = await validateConfig(mergedConfig, root, cmd);
223
238
  return validatedConfig;
224
239
  }
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
240
  function mergeConfigRecursively(defaults, overrides, rootPath) {
231
241
  const merged = __spreadValues({}, defaults);
232
242
  for (const key in overrides) {
@@ -260,7 +270,7 @@ function mergeConfig(defaults, overrides, isRoot = true) {
260
270
  }
261
271
  export {
262
272
  AstroConfigSchema,
263
- formatConfigError,
273
+ LEGACY_ASTRO_CONFIG_KEYS,
264
274
  loadConfig,
265
275
  mergeConfig,
266
276
  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,11 +84,15 @@ 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;
86
- const { dependencies = {}, peerDependencies = {}, keywords = [] } = JSON.parse(fs.readFileSync(depPkgPath, "utf-8"));
91
+ const {
92
+ dependencies = {},
93
+ peerDependencies = {},
94
+ keywords = []
95
+ } = JSON.parse(fs.readFileSync(depPkgPath, "utf-8"));
87
96
  if (peerDependencies.astro || dependencies.astro)
88
97
  return true;
89
98
  if (keywords.includes("astro") || keywords.includes("astro-component"))
@@ -1,29 +1,42 @@
1
1
  import { performance } from "perf_hooks";
2
2
  import * as vite from "vite";
3
- import { runHookConfigDone, runHookConfigSetup, runHookServerDone, runHookServerSetup, runHookServerStart } from "../../integrations/index.js";
3
+ import {
4
+ runHookConfigDone,
5
+ runHookConfigSetup,
6
+ runHookServerDone,
7
+ runHookServerSetup,
8
+ runHookServerStart
9
+ } from "../../integrations/index.js";
4
10
  import { createVite } from "../create-vite.js";
5
- import { defaultLogOptions, info, warn, warnIfUsingExperimentalSSR } from "../logger.js";
11
+ import { info, warn, warnIfUsingExperimentalSSR } from "../logger/core.js";
12
+ import { nodeLogOptions } from "../logger/node.js";
6
13
  import * as msg from "../messages.js";
7
14
  import { apply as applyPolyfill } from "../polyfill.js";
8
- import { getResolvedHostForVite } from "./util.js";
9
- async function dev(config, options = { logging: defaultLogOptions }) {
15
+ async function dev(config, options = { logging: nodeLogOptions }) {
10
16
  var _a;
11
17
  const devStart = performance.now();
12
18
  applyPolyfill();
13
19
  config = await runHookConfigSetup({ config, command: "dev" });
20
+ const { host, port } = config.server;
14
21
  const viteConfig = await createVite({
15
22
  mode: "development",
16
- server: { host: getResolvedHostForVite(config) }
23
+ server: { host }
17
24
  }, { astroConfig: config, logging: options.logging, mode: "dev" });
18
25
  await runHookConfigDone({ config });
19
26
  warnIfUsingExperimentalSSR(options.logging, config);
20
27
  const viteServer = await vite.createServer(viteConfig);
21
28
  runHookServerSetup({ config, server: viteServer });
22
- await viteServer.listen(config.devOptions.port);
29
+ await viteServer.listen(port);
23
30
  const devServerAddressInfo = viteServer.httpServer.address();
24
- const site = config.buildOptions.site ? new URL(config.buildOptions.site) : void 0;
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.3";
31
+ const site = config.site ? new URL(config.base, config.site) : void 0;
32
+ info(options.logging, null, msg.devStart({
33
+ startupTime: performance.now() - devStart,
34
+ config,
35
+ devServerAddressInfo,
36
+ site,
37
+ https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
38
+ }));
39
+ const currentVersion = "0.26.1";
27
40
  if (currentVersion.includes("-")) {
28
41
  warn(options.logging, null, msg.prerelease({ currentVersion }));
29
42
  }
@@ -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
+ };