astro 1.0.0-beta.1 → 1.0.0-beta.4

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
@@ -7,6 +7,7 @@ import add from "../core/add/index.js";
7
7
  import devServer from "../core/dev/index.js";
8
8
  import preview from "../core/preview/index.js";
9
9
  import { check } from "./check.js";
10
+ import { openInBrowser } from "./open.js";
10
11
  import { loadConfig } from "../core/config.js";
11
12
  import { printHelp, formatErrorMessage, formatConfigErrorMessage } from "../core/messages.js";
12
13
  import { createSafeError } from "../core/util.js";
@@ -16,6 +17,7 @@ function printAstroHelp() {
16
17
  headline: "Futuristic web development tool.",
17
18
  commands: [
18
19
  ["add", "Add an integration to your configuration."],
20
+ ["docs", "Launch Astro's Doc site directly from the terminal. "],
19
21
  ["dev", "Run Astro in development mode."],
20
22
  ["build", "Build a pre-compiled production-ready site."],
21
23
  ["preview", "Preview your build locally before deploying."],
@@ -36,7 +38,7 @@ function printAstroHelp() {
36
38
  });
37
39
  }
38
40
  async function printVersion() {
39
- const version = "1.0.0-beta.1";
41
+ const version = "1.0.0-beta.4";
40
42
  console.log();
41
43
  console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
42
44
  }
@@ -48,7 +50,7 @@ function resolveCommand(flags) {
48
50
  return "version";
49
51
  else if (flags.help)
50
52
  return "help";
51
- const supportedCommands = /* @__PURE__ */ new Set(["dev", "build", "preview", "check"]);
53
+ const supportedCommands = /* @__PURE__ */ new Set(["dev", "build", "preview", "check", "docs"]);
52
54
  if (supportedCommands.has(cmd)) {
53
55
  return cmd;
54
56
  }
@@ -113,7 +115,15 @@ async function cli(args) {
113
115
  }
114
116
  case "preview": {
115
117
  try {
116
- return await preview(config, { logging });
118
+ const server = await preview(config, { logging });
119
+ return await server.closed();
120
+ } catch (err) {
121
+ return throwAndExit(err);
122
+ }
123
+ }
124
+ case "docs": {
125
+ try {
126
+ return await openInBrowser("https://docs.astro.build/");
117
127
  } catch (err) {
118
128
  return throwAndExit(err);
119
129
  }
@@ -0,0 +1,26 @@
1
+ import { execa } from "execa";
2
+ const getPlatformSpecificCommand = () => {
3
+ const isGitPod = Boolean(process.env.GITPOD_REPO_ROOT);
4
+ const platform = isGitPod ? "gitpod" : process.platform;
5
+ switch (platform) {
6
+ case "android":
7
+ case "linux":
8
+ return ["xdg-open"];
9
+ case "darwin":
10
+ return ["open"];
11
+ case "win32":
12
+ return ["cmd", ["/c", "start"]];
13
+ case "gitpod":
14
+ return ["/ide/bin/remote-cli/gitpod-code", ["--openExternal"]];
15
+ default:
16
+ throw new Error(`It looks like your platform ("${platform}") isn't supported!
17
+ To view Astro's docs, please visit https://docs.astro.build`);
18
+ }
19
+ };
20
+ async function openInBrowser(url) {
21
+ const [command, args = []] = getPlatformSpecificCommand();
22
+ return execa(command, [...args, encodeURI(url)]);
23
+ }
24
+ export {
25
+ openInBrowser
26
+ };
@@ -128,7 +128,7 @@ renderPage_fn = async function(request, routeData, mod) {
128
128
  });
129
129
  };
130
130
  _callEndpoint = new WeakSet();
131
- callEndpoint_fn = async function(request, _routeData, mod) {
131
+ callEndpoint_fn = async function(request, routeData, mod) {
132
132
  const url = new URL(request.url);
133
133
  const handler = mod;
134
134
  const result = await callEndpoint(handler, {
@@ -136,6 +136,7 @@ callEndpoint_fn = async function(request, _routeData, mod) {
136
136
  origin: url.origin,
137
137
  pathname: url.pathname,
138
138
  request,
139
+ route: routeData,
139
140
  routeCache: __privateGet(this, _routeCache),
140
141
  ssr: true
141
142
  });
@@ -122,6 +122,7 @@ class AstroBuilder {
122
122
  await viteServer.close();
123
123
  await runHookBuildDone({
124
124
  config: this.config,
125
+ buildConfig,
125
126
  pages: pageNames,
126
127
  routes: Object.values(allPages).map((pd) => pd.route)
127
128
  });
@@ -22,7 +22,7 @@ import path from "path";
22
22
  import { pathToFileURL, fileURLToPath } from "url";
23
23
  import { mergeConfig as mergeViteConfig } from "vite";
24
24
  import { z } from "zod";
25
- import load from "@proload/core";
25
+ import load, { ProloadError } 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";
@@ -89,7 +89,7 @@ const AstroConfigSchema = z.object({
89
89
  }).optional().default({}),
90
90
  markdown: z.object({
91
91
  drafts: z.boolean().optional().default(false),
92
- mode: z.union([z.literal("md"), z.literal("mdx")]).optional().default("md"),
92
+ mode: z.union([z.literal("md"), z.literal("mdx")]).optional().default("mdx"),
93
93
  syntaxHighlight: z.union([z.literal("shiki"), z.literal("prism"), z.literal(false)]).optional().default("shiki"),
94
94
  shikiConfig: z.any().optional().default({}),
95
95
  remarkPlugins: z.array(z.any()).optional().default([]),
@@ -224,9 +224,21 @@ async function loadConfig(configOptions) {
224
224
  let userConfigPath;
225
225
  if (flags == null ? void 0 : flags.config) {
226
226
  userConfigPath = /^\.*\//.test(flags.config) ? flags.config : `./${flags.config}`;
227
- userConfigPath = fileURLToPath(new URL(userConfigPath, pathToFileURL(root)));
227
+ userConfigPath = fileURLToPath(new URL(userConfigPath, appendForwardSlash(pathToFileURL(root).toString())));
228
+ }
229
+ let config;
230
+ try {
231
+ config = await load("astro", {
232
+ mustExist: !!userConfigPath,
233
+ cwd: root,
234
+ filePath: userConfigPath
235
+ });
236
+ } catch (err) {
237
+ if (err instanceof ProloadError && flags.config) {
238
+ throw new Error(`Unable to resolve --config "${flags.config}"! Does the file exist?`);
239
+ }
240
+ throw err;
228
241
  }
229
- const config = await load("astro", { mustExist: false, cwd: root, filePath: userConfigPath });
230
242
  if (config) {
231
243
  userConfig = config.value;
232
244
  }
@@ -36,7 +36,7 @@ async function dev(config, options = { logging: nodeLogOptions }) {
36
36
  site,
37
37
  https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
38
38
  }));
39
- const currentVersion = "1.0.0-beta.1";
39
+ const currentVersion = "1.0.0-beta.4";
40
40
  if (currentVersion.includes("-")) {
41
41
  warn(options.logging, null, msg.prerelease({ currentVersion }));
42
42
  }
@@ -45,7 +45,7 @@ function devStart({
45
45
  https,
46
46
  site
47
47
  }) {
48
- const version = "1.0.0-beta.1";
48
+ const version = "1.0.0-beta.4";
49
49
  const rootPath = site ? site.pathname : "/";
50
50
  const localPrefix = `${dim("\u2503")} Local `;
51
51
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -170,7 +170,7 @@ function printHelp({
170
170
  };
171
171
  let message = [];
172
172
  if (headline) {
173
- message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.1"}`)} ${headline}`);
173
+ message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.4"}`)} ${headline}`);
174
174
  }
175
175
  if (usage) {
176
176
  message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
@@ -88,9 +88,16 @@ async function preview(config, { logging }) {
88
88
  });
89
89
  }
90
90
  await startServer(startServerTime);
91
+ function closed() {
92
+ return new Promise((resolve, reject) => {
93
+ httpServer.addListener("close", resolve);
94
+ httpServer.addListener("error", reject);
95
+ });
96
+ }
91
97
  return {
92
98
  host,
93
99
  port,
100
+ closed,
94
101
  server: httpServer,
95
102
  stop: async () => {
96
103
  await new Promise((resolve, reject) => {
@@ -189,6 +189,7 @@ function createRouteManifest({ config, cwd }, logging) {
189
189
  routes.push({
190
190
  type: item.isPage ? "page" : "endpoint",
191
191
  pattern,
192
+ segments,
192
193
  params,
193
194
  component,
194
195
  generate,
@@ -1,11 +1,12 @@
1
- function createRouteData(pattern, params, component, pathname, type) {
1
+ function createRouteData(pattern, params, component, pathname, type, segments) {
2
2
  return {
3
3
  type,
4
4
  pattern,
5
5
  params,
6
6
  component,
7
7
  generate: () => "",
8
- pathname: pathname || void 0
8
+ pathname: pathname || void 0,
9
+ segments
9
10
  };
10
11
  }
11
12
  function serializeRouteData(routeData) {
@@ -14,9 +15,9 @@ function serializeRouteData(routeData) {
14
15
  return outRouteData;
15
16
  }
16
17
  function deserializeRouteData(rawRouteData) {
17
- const { component, params, pathname, type } = rawRouteData;
18
+ const { component, params, pathname, type, segments } = rawRouteData;
18
19
  const pattern = new RegExp(rawRouteData.pattern);
19
- return createRouteData(pattern, params, component, pathname, type);
20
+ return createRouteData(pattern, params, component, pathname, type, segments);
20
21
  }
21
22
  export {
22
23
  deserializeRouteData,
@@ -16,6 +16,7 @@ var __spreadValues = (a, b) => {
16
16
  };
17
17
  import { mergeConfig } from "../core/config.js";
18
18
  import ssgAdapter from "../adapter-ssg/index.js";
19
+ import { isBuildingToSSR } from "../core/util.js";
19
20
  async function runHookConfigSetup({
20
21
  config: _config,
21
22
  command
@@ -120,14 +121,16 @@ async function runHookBuildSetup({
120
121
  }
121
122
  async function runHookBuildDone({
122
123
  config,
124
+ buildConfig,
123
125
  pages,
124
126
  routes
125
127
  }) {
128
+ const dir = isBuildingToSSR(config) ? buildConfig.client : config.outDir;
126
129
  for (const integration of config.integrations) {
127
130
  if (integration.hooks["astro:build:done"]) {
128
131
  await integration.hooks["astro:build:done"]({
129
132
  pages: pages.map((p) => ({ pathname: p })),
130
- dir: config.outDir,
133
+ dir,
131
134
  routes
132
135
  });
133
136
  }
@@ -724,12 +724,18 @@ export interface AstroIntegration {
724
724
  };
725
725
  }
726
726
  export declare type RouteType = 'page' | 'endpoint';
727
+ export interface RoutePart {
728
+ content: string;
729
+ dynamic: boolean;
730
+ spread: boolean;
731
+ }
727
732
  export interface RouteData {
728
733
  component: string;
729
734
  generate: (data?: any) => string;
730
735
  params: string[];
731
736
  pathname?: string;
732
737
  pattern: RegExp;
738
+ segments: RoutePart[][];
733
739
  type: RouteType;
734
740
  }
735
741
  export declare type SerializedRouteData = Omit<RouteData, 'generate' | 'pattern'> & {
@@ -0,0 +1,2 @@
1
+ import type { ExecaChildProcess } from 'execa';
2
+ export declare function openInBrowser(url: string): Promise<ExecaChildProcess>;
@@ -9,6 +9,7 @@ export interface PreviewServer {
9
9
  host?: string;
10
10
  port: number;
11
11
  server: http.Server;
12
+ closed(): Promise<void>;
12
13
  stop(): Promise<void>;
13
14
  }
14
15
  /** The primary dev action */
@@ -30,8 +30,9 @@ export declare function runHookBuildSetup({ config, vite, target, }: {
30
30
  vite: ViteConfigWithSSR;
31
31
  target: 'server' | 'client';
32
32
  }): Promise<void>;
33
- export declare function runHookBuildDone({ config, pages, routes, }: {
33
+ export declare function runHookBuildDone({ config, buildConfig, pages, routes, }: {
34
34
  config: AstroConfig;
35
+ buildConfig: BuildConfig;
35
36
  pages: string[];
36
37
  routes: RouteData[];
37
38
  }): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.4",
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",