astro 1.4.5 → 1.4.7

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/config.mjs CHANGED
@@ -1,43 +1 @@
1
- export function defineConfig(config) {
2
- return config;
3
- }
4
-
5
- export function getViteConfig(inlineConfig) {
6
- // Return an async Vite config getter which exposes a resolved `mode` and `command`
7
- return async ({ mode, command }) => {
8
- // Vite `command` is `serve | build`, but Astro uses `dev | build`
9
- const cmd = command === 'serve' ? 'dev' : command;
10
-
11
- // Use dynamic import to avoid pulling in deps unless used
12
- const [
13
- { mergeConfig },
14
- { nodeLogDestination },
15
- { openConfig },
16
- { createVite },
17
- { runHookConfigSetup, runHookConfigDone },
18
- ] = await Promise.all([
19
- import('vite'),
20
- import('./dist/core/logger/node.js'),
21
- import('./dist/core/config.js'),
22
- import('./dist/core/create-vite.js'),
23
- import('./dist/integrations/index.js'),
24
- ]);
25
- const logging = {
26
- dest: nodeLogDestination,
27
- level: 'info',
28
- };
29
- const { astroConfig: config } = await openConfig({
30
- cmd,
31
- logging,
32
- });
33
- await runHookConfigSetup({ config, command: cmd });
34
- const viteConfig = await createVite(
35
- {
36
- mode,
37
- },
38
- { astroConfig: config, logging: logging, mode }
39
- );
40
- await runHookConfigDone({ config });
41
- return mergeConfig(viteConfig, inlineConfig);
42
- };
43
- }
1
+ export { defineConfig, getViteConfig } from './dist/config/index.js';
@@ -384,22 +384,13 @@ export interface AstroUserConfig {
384
384
  * @name base
385
385
  * @type {string}
386
386
  * @description
387
- * The base path you're deploying to. Astro will match this pathname during development so that your development experience matches your build environment as closely as possible. In the example below, `astro dev` will start your server at `/docs`.
387
+ * The base path to deploy to. Astro will build your pages and assets using this path as the root. Currently, this has no effect during development.
388
388
  *
389
389
  * ```js
390
390
  * {
391
391
  * base: '/docs'
392
392
  * }
393
393
  * ```
394
- *
395
- * When using this option, you should mind that all of your imports will be affected. In this example, all of the imports including static resources and codes should add a prefix `/docs/`.
396
- *
397
- * For example, if you want to use a image in your Astro component, you need to change it from '/someimg.png' into '/docs/someimg.png'.
398
- *
399
- * ```astro
400
- * <!-- <img src="/someimg.png"> is not correct. -->
401
- * <img src="/docs/someimg.png">
402
- * ```
403
394
  */
404
395
  base?: string;
405
396
  /**
@@ -0,0 +1,7 @@
1
+ import type { UserConfig } from 'vite';
2
+ import type { AstroUserConfig } from '../@types/astro';
3
+ export declare function defineConfig(config: AstroUserConfig): AstroUserConfig;
4
+ export declare function getViteConfig(inlineConfig: UserConfig): ({ mode, command }: {
5
+ mode: string;
6
+ command: 'serve' | 'build';
7
+ }) => Promise<Record<string, any>>;
@@ -0,0 +1,48 @@
1
+ function defineConfig(config) {
2
+ return config;
3
+ }
4
+ function getViteConfig(inlineConfig) {
5
+ return async ({ mode, command }) => {
6
+ const cmd = command === "serve" ? "dev" : command;
7
+ const [
8
+ { mergeConfig },
9
+ { nodeLogDestination },
10
+ { openConfig, createSettings, loadTSConfig },
11
+ { createVite },
12
+ { runHookConfigSetup, runHookConfigDone }
13
+ ] = await Promise.all([
14
+ import("vite"),
15
+ import("../core/logger/node.js"),
16
+ import("../core/config/index.js"),
17
+ import("../core/create-vite.js"),
18
+ import("../integrations/index.js")
19
+ ]);
20
+ const logging = {
21
+ dest: nodeLogDestination,
22
+ level: "info"
23
+ };
24
+ const { astroConfig: config } = await openConfig({
25
+ cmd,
26
+ logging
27
+ });
28
+ const initialTsConfig = loadTSConfig(inlineConfig.root);
29
+ const settings = createSettings({
30
+ config,
31
+ tsConfig: initialTsConfig == null ? void 0 : initialTsConfig.config,
32
+ tsConfigPath: initialTsConfig == null ? void 0 : initialTsConfig.path
33
+ });
34
+ await runHookConfigSetup({ settings, command: cmd, logging });
35
+ const viteConfig = await createVite(
36
+ {
37
+ mode
38
+ },
39
+ { settings, logging, mode }
40
+ );
41
+ await runHookConfigDone({ settings, logging });
42
+ return mergeConfig(viteConfig, inlineConfig);
43
+ };
44
+ }
45
+ export {
46
+ defineConfig,
47
+ getViteConfig
48
+ };
@@ -5,8 +5,9 @@ import path from "path";
5
5
  import { fileURLToPath } from "url";
6
6
  import * as vite from "vite";
7
7
  import { createBuildInternals } from "../../core/build/internal.js";
8
+ import { emptyDir, removeDir } from "../../core/fs/index.js";
8
9
  import { prependForwardSlash } from "../../core/path.js";
9
- import { emptyDir, isModeServerWithNoAdapter, removeDir } from "../../core/util.js";
10
+ import { isModeServerWithNoAdapter } from "../../core/util.js";
10
11
  import { runHookBuildSetup } from "../../integrations/index.js";
11
12
  import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
12
13
  import { info } from "../logger/core.js";
@@ -2,7 +2,6 @@ import crypto from "crypto";
2
2
  import esbuild from "esbuild";
3
3
  import npath from "path";
4
4
  import { isCSSRequest } from "../render/util.js";
5
- import { relativeToSrcDir } from "../util.js";
6
5
  import { getTopLevelPages, moduleIsTopLevelPage, walkParentInfos } from "./graph.js";
7
6
  import {
8
7
  eachPageData,
@@ -11,32 +10,22 @@ import {
11
10
  getPageDatasByHoistedScriptId,
12
11
  isHoistedScript
13
12
  } from "./internal.js";
14
- const MAX_NAME_LENGTH = 70;
15
13
  function rollupPluginAstroBuildCSS(options) {
16
14
  const { internals, buildOptions } = options;
17
15
  const { settings } = buildOptions;
18
16
  let resolvedConfig;
19
- function nameifyPage(id) {
20
- let rel = relativeToSrcDir(settings.config, id);
21
- if (rel.startsWith("pages/")) {
22
- rel = rel.slice(6);
23
- }
24
- const ext = npath.extname(rel);
25
- const noext = rel.slice(0, rel.length - ext.length);
26
- const named = noext.replace(/\//g, "-");
27
- return named;
28
- }
29
17
  function createNameForParentPages(id, ctx) {
18
+ var _a;
30
19
  const parents = Array.from(getTopLevelPages(id, ctx));
31
- const proposedName = parents.map(([page]) => nameifyPage(page.id)).sort().join("-");
32
- if (proposedName.length <= MAX_NAME_LENGTH) {
33
- return proposedName;
34
- }
20
+ const firstParentId = (_a = parents[0]) == null ? void 0 : _a[0].id;
21
+ const firstParentName = firstParentId ? npath.parse(firstParentId).name : "index";
35
22
  const hash = crypto.createHash("sha256");
36
23
  for (const [page] of parents) {
37
24
  hash.update(page.id, "utf-8");
38
25
  }
39
- return hash.digest("hex").slice(0, 8);
26
+ const h = hash.digest("hex").slice(0, 8);
27
+ const proposedName = firstParentName + "." + h;
28
+ return proposedName;
40
29
  }
41
30
  function* getParentClientOnlys(id, ctx) {
42
31
  for (const [info] of walkParentInfos(id, ctx)) {
@@ -49,7 +49,7 @@ async function dev(settings, options) {
49
49
  isRestart
50
50
  })
51
51
  );
52
- const currentVersion = "1.4.5";
52
+ const currentVersion = "1.4.7";
53
53
  if (currentVersion.includes("-")) {
54
54
  warn(options.logging, null, msg.prerelease({ currentVersion }));
55
55
  }
@@ -0,0 +1,3 @@
1
+ /** An fs utility, similar to `rimraf` or `rm -rf` */
2
+ export declare function removeDir(_dir: URL): void;
3
+ export declare function emptyDir(_dir: URL, skip?: Set<string>): void;
@@ -0,0 +1,79 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ const isWindows = process.platform === "win32";
5
+ function removeDir(_dir) {
6
+ const dir = fileURLToPath(_dir);
7
+ fs.rmSync(dir, { recursive: true, force: true, maxRetries: 3 });
8
+ }
9
+ function emptyDir(_dir, skip) {
10
+ const dir = fileURLToPath(_dir);
11
+ if (!fs.existsSync(dir))
12
+ return void 0;
13
+ for (const file of fs.readdirSync(dir)) {
14
+ if (skip == null ? void 0 : skip.has(file)) {
15
+ continue;
16
+ }
17
+ const p = path.resolve(dir, file);
18
+ const rmOptions = { recursive: true, force: true, maxRetries: 3 };
19
+ try {
20
+ fs.rmSync(p, rmOptions);
21
+ } catch (er) {
22
+ if (er.code === "ENOENT") {
23
+ return;
24
+ }
25
+ if (er.code === "EPERM" && isWindows) {
26
+ fixWinEPERMSync(p, rmOptions, er);
27
+ }
28
+ }
29
+ }
30
+ }
31
+ /**
32
+ * https://github.com/isaacs/rimraf/blob/8c10fb8d685d5cc35708e0ffc4dac9ec5dd5b444/rimraf.js#L183
33
+ * @license ISC
34
+ * The ISC License
35
+ *
36
+ * Copyright (c) Isaac Z. Schlueter and Contributors
37
+ *
38
+ * Permission to use, copy, modify, and/or distribute this software for any
39
+ purpose with or without fee is hereby granted, provided that the above
40
+ copyright notice and this permission notice appear in all copies.
41
+ *
42
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
43
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
44
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
45
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
46
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
47
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
48
+ IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49
+ */
50
+ const fixWinEPERMSync = (p, options, er) => {
51
+ try {
52
+ fs.chmodSync(p, 438);
53
+ } catch (er2) {
54
+ if (er2.code === "ENOENT") {
55
+ return;
56
+ } else {
57
+ throw er;
58
+ }
59
+ }
60
+ let stats;
61
+ try {
62
+ stats = fs.statSync(p);
63
+ } catch (er3) {
64
+ if (er3.code === "ENOENT") {
65
+ return;
66
+ } else {
67
+ throw er;
68
+ }
69
+ }
70
+ if (stats.isDirectory()) {
71
+ fs.rmdirSync(p, options);
72
+ } else {
73
+ fs.unlinkSync(p);
74
+ }
75
+ };
76
+ export {
77
+ emptyDir,
78
+ removeDir
79
+ };
@@ -47,7 +47,7 @@ function serverStart({
47
47
  site,
48
48
  isRestart = false
49
49
  }) {
50
- const version = "1.4.5";
50
+ const version = "1.4.7";
51
51
  const rootPath = site ? site.pathname : "/";
52
52
  const localPrefix = `${dim("\u2503")} Local `;
53
53
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -250,7 +250,7 @@ function printHelp({
250
250
  message.push(
251
251
  linebreak(),
252
252
  ` ${bgGreen(black(` ${commandName} `))} ${green(
253
- `v${"1.4.5"}`
253
+ `v${"1.4.7"}`
254
254
  )} ${headline}`
255
255
  );
256
256
  }
@@ -33,9 +33,6 @@ export declare function resolveDependency(dep: string, projectRoot: URL): string
33
33
  export declare function viteID(filePath: URL): string;
34
34
  export declare const VALID_ID_PREFIX = "/@id/";
35
35
  export declare function unwrapId(id: string): string;
36
- /** An fs utility, similar to `rimraf` or `rm -rf` */
37
- export declare function removeDir(_dir: URL): void;
38
- export declare function emptyDir(_dir: URL, skip?: Set<string>): void;
39
36
  export declare function resolvePages(config: AstroConfig): URL;
40
37
  export declare function isPage(file: URL, settings: AstroSettings): boolean;
41
38
  export declare function isModeServerWithNoAdapter(settings: AstroSettings): boolean;
package/dist/core/util.js CHANGED
@@ -5,7 +5,7 @@ import resolve from "resolve";
5
5
  import slash from "slash";
6
6
  import { fileURLToPath, pathToFileURL } from "url";
7
7
  import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
8
- const ASTRO_VERSION = "1.4.5";
8
+ const ASTRO_VERSION = "1.4.7";
9
9
  function isObject(value) {
10
10
  return typeof value === "object" && value != null;
11
11
  }
@@ -93,21 +93,6 @@ const VALID_ID_PREFIX = `/@id/`;
93
93
  function unwrapId(id) {
94
94
  return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length) : id;
95
95
  }
96
- function removeDir(_dir) {
97
- const dir = fileURLToPath(_dir);
98
- fs.rmSync(dir, { recursive: true, force: true, maxRetries: 3 });
99
- }
100
- function emptyDir(_dir, skip) {
101
- const dir = fileURLToPath(_dir);
102
- if (!fs.existsSync(dir))
103
- return void 0;
104
- for (const file of fs.readdirSync(dir)) {
105
- if (skip == null ? void 0 : skip.has(file)) {
106
- continue;
107
- }
108
- fs.rmSync(path.resolve(dir, file), { recursive: true, force: true, maxRetries: 3 });
109
- }
110
- }
111
96
  function resolvePages(config) {
112
97
  return new URL("./pages", config.srcDir);
113
98
  }
@@ -197,7 +182,6 @@ export {
197
182
  codeFrame,
198
183
  createSafeError,
199
184
  emoji,
200
- emptyDir,
201
185
  getLocalAddress,
202
186
  getOutputFilename,
203
187
  isModeServerWithNoAdapter,
@@ -206,7 +190,6 @@ export {
206
190
  padMultilineString,
207
191
  parseNpmName,
208
192
  relativeToSrcDir,
209
- removeDir,
210
193
  resolveDependency,
211
194
  resolveIdToUrl,
212
195
  resolveJsToTs,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.4.5";
1
+ const ASTRO_VERSION = "1.4.7";
2
2
  function createDeprecatedFetchContentFn() {
3
3
  return () => {
4
4
  throw new Error("Deprecated: Astro.fetchContent() has been replaced with Astro.glob().");
@@ -84,7 +84,7 @@ async function generateHydrateScript(scriptOptions, metadata) {
84
84
  };
85
85
  if (attrs) {
86
86
  for (const [key, value] of Object.entries(attrs)) {
87
- island.props[key] = value;
87
+ island.props[key] = escapeHTML(value);
88
88
  }
89
89
  }
90
90
  island.props["component-url"] = await result.resolve(decodeURI(componentUrl));
@@ -14,6 +14,7 @@ async function iterableToHTMLBytes(result, iterable, onDocTypeInjection) {
14
14
  for await (const chunk of iterable) {
15
15
  if (isHTMLString(chunk)) {
16
16
  if (i === 0) {
17
+ i++;
17
18
  if (!/<!doctype html/i.test(String(chunk))) {
18
19
  parts.append("<!DOCTYPE html>\n", result);
19
20
  if (onDocTypeInjection) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
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",