astro 1.0.0-beta.26 → 1.0.0-beta.27

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
@@ -11,7 +11,7 @@ import preview from "../core/preview/index.js";
11
11
  import { check } from "./check.js";
12
12
  import { openInBrowser } from "./open.js";
13
13
  import * as telemetryHandler from "./telemetry.js";
14
- import { loadConfig } from "../core/config.js";
14
+ import { openConfig } from "../core/config.js";
15
15
  import { printHelp, formatErrorMessage, formatConfigErrorMessage } from "../core/messages.js";
16
16
  import { createSafeError } from "../core/util.js";
17
17
  function printAstroHelp() {
@@ -40,7 +40,7 @@ function printAstroHelp() {
40
40
  });
41
41
  }
42
42
  async function printVersion() {
43
- const version = "1.0.0-beta.26";
43
+ const version = "1.0.0-beta.27";
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.26" });
86
+ const telemetry = new AstroTelemetry({ version: "1.0.0-beta.27" });
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.26",
100
+ astroVersion: "1.0.0-beta.27",
101
101
  cliCommand: "add"
102
102
  }));
103
103
  return await add(packages, { cwd: root, flags, logging, telemetry });
@@ -107,9 +107,9 @@ async function cli(args) {
107
107
  }
108
108
  case "dev": {
109
109
  try {
110
- const config = await loadConfig({ cwd: root, flags, cmd });
111
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.26", cliCommand: "dev" }, config));
112
- await devServer(config, { logging, telemetry });
110
+ const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
111
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.27", cliCommand: "dev" }, userConfig, flags));
112
+ await devServer(astroConfig, { logging, telemetry });
113
113
  return await new Promise(() => {
114
114
  });
115
115
  } catch (err) {
@@ -118,24 +118,24 @@ async function cli(args) {
118
118
  }
119
119
  case "build": {
120
120
  try {
121
- const config = await loadConfig({ cwd: root, flags, cmd });
122
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.26", cliCommand: "build" }, config));
123
- return await build(config, { logging, telemetry });
121
+ const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
122
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.27", cliCommand: "build" }, userConfig, flags));
123
+ return await build(astroConfig, { logging, telemetry });
124
124
  } catch (err) {
125
125
  return throwAndExit(err);
126
126
  }
127
127
  }
128
128
  case "check": {
129
- const config = await loadConfig({ cwd: root, flags, cmd });
130
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.26", cliCommand: "check" }, config));
131
- const ret = await check(config);
129
+ const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
130
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.27", cliCommand: "check" }, userConfig, flags));
131
+ const ret = await check(astroConfig);
132
132
  return process.exit(ret);
133
133
  }
134
134
  case "preview": {
135
135
  try {
136
- const config = await loadConfig({ cwd: root, flags, cmd });
137
- telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.26", cliCommand: "preview" }, config));
138
- const server = await preview(config, { logging, telemetry });
136
+ const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
137
+ telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.27", cliCommand: "preview" }, userConfig, flags));
138
+ const server = await preview(astroConfig, { logging, telemetry });
139
139
  return await server.closed();
140
140
  } catch (err) {
141
141
  return throwAndExit(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.26",
147
+ astroVersion: "1.0.0-beta.27",
148
148
  cliCommand: "docs"
149
149
  }));
150
150
  return await openInBrowser("https://docs.astro.build/");
@@ -133,7 +133,7 @@ async function ssrBuild(opts, internals, input) {
133
133
  root: viteConfig.root,
134
134
  envPrefix: "PUBLIC_",
135
135
  server: viteConfig.server,
136
- base: astroConfig.site ? new URL(astroConfig.site).pathname : "/",
136
+ base: astroConfig.base,
137
137
  ssr: viteConfig.ssr,
138
138
  resolve: viteConfig.resolve
139
139
  };
@@ -27,7 +27,7 @@ import load, { resolve, ProloadError } from "@proload/core";
27
27
  import loadTypeScript from "@proload/plugin-tsm";
28
28
  import postcssrc from "postcss-load-config";
29
29
  import { arraify, isObject } from "./util.js";
30
- import { appendForwardSlash, trimSlashes } from "./path.js";
30
+ import { appendForwardSlash, prependForwardSlash, trimSlashes } from "./path.js";
31
31
  load.use([loadTypeScript]);
32
32
  async function resolvePostcssConfig(inlineOptions, root) {
33
33
  if (isObject(inlineOptions)) {
@@ -72,7 +72,7 @@ const AstroConfigSchema = z.object({
72
72
  site: z.string().url().optional().transform((val) => val ? appendForwardSlash(val) : val).refine((val) => !val || new URL(val).pathname.length <= 1, {
73
73
  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'
74
74
  }),
75
- base: z.string().optional().default("/").transform((val) => appendForwardSlash(trimSlashes(val))),
75
+ base: z.string().optional().default("/").transform((val) => prependForwardSlash(appendForwardSlash(trimSlashes(val)))),
76
76
  trailingSlash: z.union([z.literal("always"), z.literal("never"), z.literal("ignore")]).optional().default("ignore"),
77
77
  build: z.object({
78
78
  format: z.union([z.literal("file"), z.literal("directory")]).optional().default("directory")
@@ -237,6 +237,39 @@ async function resolveConfigURL(configOptions) {
237
237
  return pathToFileURL(configPath);
238
238
  }
239
239
  }
240
+ async function openConfig(configOptions) {
241
+ const root = configOptions.cwd ? path.resolve(configOptions.cwd) : process.cwd();
242
+ const flags = resolveFlags(configOptions.flags || {});
243
+ let userConfig = {};
244
+ let userConfigPath;
245
+ if (flags == null ? void 0 : flags.config) {
246
+ userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
247
+ userConfigPath = fileURLToPath(new URL(userConfigPath, appendForwardSlash(pathToFileURL(root).toString())));
248
+ }
249
+ let config;
250
+ try {
251
+ config = await load("astro", {
252
+ mustExist: !!userConfigPath,
253
+ cwd: root,
254
+ filePath: userConfigPath
255
+ });
256
+ } catch (err) {
257
+ if (err instanceof ProloadError && flags.config) {
258
+ throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
259
+ }
260
+ throw err;
261
+ }
262
+ if (config) {
263
+ userConfig = config.value;
264
+ }
265
+ const astroConfig = await resolveConfig(userConfig, root, flags, configOptions.cmd);
266
+ return {
267
+ astroConfig,
268
+ userConfig,
269
+ flags,
270
+ root
271
+ };
272
+ }
240
273
  async function loadConfig(configOptions) {
241
274
  const root = configOptions.cwd ? path.resolve(configOptions.cwd) : process.cwd();
242
275
  const flags = resolveFlags(configOptions.flags || {});
@@ -305,6 +338,7 @@ export {
305
338
  LEGACY_ASTRO_CONFIG_KEYS,
306
339
  loadConfig,
307
340
  mergeConfig,
341
+ openConfig,
308
342
  resolveConfig,
309
343
  resolveConfigURL,
310
344
  validateConfig
@@ -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.26";
39
+ const currentVersion = "1.0.0-beta.27";
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.26";
50
+ const version = "1.0.0-beta.27";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -199,7 +199,7 @@ function printHelp({
199
199
  };
200
200
  let message = [];
201
201
  if (headline) {
202
- message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.26"}`)} ${headline}`);
202
+ message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.27"}`)} ${headline}`);
203
203
  }
204
204
  if (usage) {
205
205
  message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
@@ -243,7 +243,18 @@ interface LoadConfigOptions {
243
243
  * instead of the resolved config
244
244
  */
245
245
  export declare function resolveConfigURL(configOptions: Pick<LoadConfigOptions, 'cwd' | 'flags'>): Promise<URL | undefined>;
246
- /** Attempt to load an `astro.config.mjs` file */
246
+ interface OpenConfigResult {
247
+ userConfig: AstroUserConfig;
248
+ astroConfig: AstroConfig;
249
+ flags: CLIFlags;
250
+ root: string;
251
+ }
252
+ /** Load a configuration file, returning both the userConfig and astroConfig */
253
+ export declare function openConfig(configOptions: LoadConfigOptions): Promise<OpenConfigResult>;
254
+ /**
255
+ * Attempt to load an `astro.config.mjs` file
256
+ * @deprecated
257
+ */
247
258
  export declare function loadConfig(configOptions: LoadConfigOptions): Promise<AstroConfig>;
248
259
  /** Attempt to resolve an Astro configuration object. Normalize, validate, and return. */
249
260
  export declare function resolveConfig(userConfig: AstroUserConfig, root: string, flags: CLIFlags | undefined, cmd: string): Promise<AstroConfig>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.0.0-beta.26",
3
+ "version": "1.0.0-beta.27",
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",
@@ -70,7 +70,7 @@
70
70
  "@astrojs/language-server": "^0.13.4",
71
71
  "@astrojs/markdown-remark": "^0.9.4",
72
72
  "@astrojs/prism": "0.4.1",
73
- "@astrojs/telemetry": "^0.1.1",
73
+ "@astrojs/telemetry": "^0.1.2",
74
74
  "@astrojs/webapi": "^0.11.1",
75
75
  "@babel/core": "^7.17.9",
76
76
  "@babel/generator": "^7.17.9",