astro 2.8.2 → 2.8.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.
Files changed (111) hide show
  1. package/components/Code.astro +1 -1
  2. package/dist/@types/astro.d.ts +2 -2
  3. package/dist/assets/consts.d.ts +4 -4
  4. package/dist/assets/consts.js +11 -3
  5. package/dist/assets/index.d.ts +0 -2
  6. package/dist/assets/index.js +0 -4
  7. package/dist/assets/services/service.d.ts +1 -1
  8. package/dist/assets/services/service.js +6 -3
  9. package/dist/assets/services/sharp.js +3 -0
  10. package/dist/assets/services/squoosh.js +25 -0
  11. package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +3 -3
  12. package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +3 -3
  13. package/dist/assets/services/vendor/squoosh/image-pool.js +2 -2
  14. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +3 -3
  15. package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +3 -3
  16. package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +3 -3
  17. package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +3 -3
  18. package/dist/assets/types.d.ts +1 -0
  19. package/dist/assets/utils/emitAsset.d.ts +2 -2
  20. package/dist/assets/utils/metadata.d.ts +1 -4
  21. package/dist/assets/utils/transformToPath.js +1 -1
  22. package/dist/assets/vendor/image-size/index.js +2 -2
  23. package/dist/assets/vendor/image-size/types/tiff.js +1 -1
  24. package/dist/cli/add/index.d.ts +1 -2
  25. package/dist/cli/add/index.js +7 -4
  26. package/dist/cli/check/index.d.ts +1 -1
  27. package/dist/cli/check/index.js +2 -2
  28. package/dist/cli/check/print.js +1 -1
  29. package/dist/cli/dev/index.js +1 -1
  30. package/dist/cli/index.js +8 -28
  31. package/dist/cli/info/index.d.ts +1 -2
  32. package/dist/cli/info/index.js +2 -2
  33. package/dist/cli/load-settings.js +1 -1
  34. package/dist/cli/sync/index.js +1 -1
  35. package/dist/cli/throw-and-exit.d.ts +2 -0
  36. package/dist/cli/throw-and-exit.js +21 -0
  37. package/dist/config/index.js +1 -1
  38. package/dist/content/runtime-assets.d.ts +1 -1
  39. package/dist/content/runtime-assets.js +1 -1
  40. package/dist/content/vite-plugin-content-imports.js +1 -1
  41. package/dist/core/app/index.d.ts +3 -1
  42. package/dist/core/app/index.js +33 -47
  43. package/dist/core/app/node.d.ts +1 -1
  44. package/dist/core/app/node.js +3 -3
  45. package/dist/core/build/common.js +2 -2
  46. package/dist/core/build/css-asset-name.js +2 -2
  47. package/dist/core/build/generate.d.ts +1 -1
  48. package/dist/core/build/generate.js +21 -43
  49. package/dist/core/build/index.js +9 -2
  50. package/dist/core/build/static-build.js +8 -6
  51. package/dist/core/compile/compile.js +1 -1
  52. package/dist/core/compile/style.js +1 -1
  53. package/dist/core/config/config.d.ts +1 -1
  54. package/dist/core/config/config.js +16 -22
  55. package/dist/core/config/merge.js +10 -0
  56. package/dist/core/config/schema.d.ts +1 -1
  57. package/dist/core/config/schema.js +1 -6
  58. package/dist/core/config/settings.js +1 -1
  59. package/dist/core/config/timer.js +1 -1
  60. package/dist/core/config/tsconfig.js +2 -2
  61. package/dist/core/config/vite-load.d.ts +1 -1
  62. package/dist/core/config/vite-load.js +1 -1
  63. package/dist/core/constants.js +1 -1
  64. package/dist/core/create-vite.d.ts +1 -1
  65. package/dist/core/create-vite.js +2 -2
  66. package/dist/core/dev/container.d.ts +3 -3
  67. package/dist/core/dev/container.js +1 -1
  68. package/dist/core/dev/dev.d.ts +2 -2
  69. package/dist/core/dev/dev.js +1 -1
  70. package/dist/core/errors/dev/vite.js +2 -2
  71. package/dist/core/errors/errors-data.d.ts +1 -1
  72. package/dist/core/errors/errors-data.js +2 -2
  73. package/dist/core/fs/index.js +4 -4
  74. package/dist/core/logger/node.d.ts +1 -1
  75. package/dist/core/logger/node.js +2 -2
  76. package/dist/core/messages.js +2 -2
  77. package/dist/core/module-loader/loader.d.ts +1 -1
  78. package/dist/core/module-loader/loader.js +1 -1
  79. package/dist/core/module-loader/vite.js +1 -1
  80. package/dist/core/preview/index.js +1 -1
  81. package/dist/core/preview/static-preview-server.d.ts +1 -1
  82. package/dist/core/preview/static-preview-server.js +1 -1
  83. package/dist/core/preview/vite-plugin-astro-preview.js +2 -2
  84. package/dist/core/render/core.d.ts +9 -2
  85. package/dist/core/render/core.js +34 -1
  86. package/dist/core/render/dev/environment.d.ts +2 -2
  87. package/dist/core/render/dev/environment.js +6 -7
  88. package/dist/core/render/dev/index.js +3 -29
  89. package/dist/core/render/dev/vite.js +1 -1
  90. package/dist/core/render/index.d.ts +1 -1
  91. package/dist/core/render/index.js +2 -2
  92. package/dist/core/request.d.ts +1 -1
  93. package/dist/core/routing/manifest/create.d.ts +1 -1
  94. package/dist/core/routing/manifest/create.js +22 -3
  95. package/dist/core/util.js +3 -3
  96. package/dist/integrations/index.d.ts +1 -1
  97. package/dist/vite-plugin-astro-server/base.js +1 -1
  98. package/dist/vite-plugin-astro-server/plugin.d.ts +10 -2
  99. package/dist/vite-plugin-astro-server/plugin.js +34 -9
  100. package/dist/vite-plugin-astro-server/request.d.ts +12 -3
  101. package/dist/vite-plugin-astro-server/request.js +23 -15
  102. package/dist/vite-plugin-astro-server/response.d.ts +1 -1
  103. package/dist/vite-plugin-astro-server/route.d.ts +15 -3
  104. package/dist/vite-plugin-astro-server/route.js +32 -20
  105. package/dist/vite-plugin-config-alias/index.js +1 -1
  106. package/dist/vite-plugin-env/index.js +5 -2
  107. package/dist/vite-plugin-jsx/index.js +1 -1
  108. package/dist/vite-plugin-load-fallback/index.d.ts +1 -1
  109. package/dist/vite-plugin-load-fallback/index.js +2 -2
  110. package/dist/vite-plugin-utils/index.js +1 -1
  111. package/package.json +3 -3
@@ -3,7 +3,7 @@ import type * as shiki from 'shiki';
3
3
  import { renderToHtml } from 'shiki';
4
4
  import { getHighlighter } from './Shiki.js';
5
5
 
6
- export interface Props {
6
+ interface Props {
7
7
  /** The code to highlight. Required. */
8
8
  code: string;
9
9
  /**
@@ -3,8 +3,8 @@
3
3
  /// <reference types="node" />
4
4
  import type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
5
5
  import type * as babel from '@babel/core';
6
- import type { OutgoingHttpHeaders } from 'http';
7
- import type { AddressInfo } from 'net';
6
+ import type { OutgoingHttpHeaders } from 'node:http';
7
+ import type { AddressInfo } from 'node:net';
8
8
  import type * as rollup from 'rollup';
9
9
  import type { TsConfigJson } from 'tsconfig-resolver';
10
10
  import type * as vite from 'vite';
@@ -2,8 +2,8 @@ export declare const VIRTUAL_MODULE_ID = "astro:assets";
2
2
  export declare const VIRTUAL_SERVICE_ID = "virtual:image-service";
3
3
  export declare const VALID_INPUT_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif", "svg"];
4
4
  /**
5
- * Valid formats for optimizations in our base services.
6
- * Certain formats can be imported (namely SVGs) but not processed, so they are excluded from this list.
5
+ * Valid formats that our base services support.
6
+ * Certain formats can be imported (namely SVGs) but will not be processed.
7
7
  */
8
- export declare const VALID_OPTIMIZABLE_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif"];
9
- export declare const VALID_OUTPUT_FORMATS: readonly ["avif", "png", "webp", "jpeg", "jpg"];
8
+ export declare const VALID_SUPPORTED_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif", "svg"];
9
+ export declare const VALID_OUTPUT_FORMATS: readonly ["avif", "png", "webp", "jpeg", "jpg", "svg"];
@@ -17,12 +17,20 @@ const VALID_INPUT_FORMATS = [
17
17
  "gif",
18
18
  "svg"
19
19
  ];
20
- const VALID_OPTIMIZABLE_FORMATS = ["jpeg", "jpg", "png", "tiff", "webp", "gif"];
21
- const VALID_OUTPUT_FORMATS = ["avif", "png", "webp", "jpeg", "jpg"];
20
+ const VALID_SUPPORTED_FORMATS = [
21
+ "jpeg",
22
+ "jpg",
23
+ "png",
24
+ "tiff",
25
+ "webp",
26
+ "gif",
27
+ "svg"
28
+ ];
29
+ const VALID_OUTPUT_FORMATS = ["avif", "png", "webp", "jpeg", "jpg", "svg"];
22
30
  export {
23
31
  VALID_INPUT_FORMATS,
24
- VALID_OPTIMIZABLE_FORMATS,
25
32
  VALID_OUTPUT_FORMATS,
33
+ VALID_SUPPORTED_FORMATS,
26
34
  VIRTUAL_MODULE_ID,
27
35
  VIRTUAL_SERVICE_ID
28
36
  };
@@ -1,5 +1,3 @@
1
1
  export { getConfiguredImageService, getImage } from './internal.js';
2
2
  export { baseService, isLocalService } from './services/service.js';
3
3
  export { type LocalImageProps, type RemoteImageProps } from './types.js';
4
- export { emitESMImage } from './utils/emitAsset.js';
5
- export { imageMetadata } from './utils/metadata.js';
@@ -1,13 +1,9 @@
1
1
  import { getConfiguredImageService, getImage } from "./internal.js";
2
2
  import { baseService, isLocalService } from "./services/service.js";
3
3
  import {} from "./types.js";
4
- import { emitESMImage } from "./utils/emitAsset.js";
5
- import { imageMetadata } from "./utils/metadata.js";
6
4
  export {
7
5
  baseService,
8
- emitESMImage,
9
6
  getConfiguredImageService,
10
7
  getImage,
11
- imageMetadata,
12
8
  isLocalService
13
9
  };
@@ -31,7 +31,7 @@ interface SharedServiceProps {
31
31
  validateOptions?: (options: ImageTransform, serviceConfig: Record<string, any>) => ImageTransform;
32
32
  }
33
33
  export type ExternalImageService = SharedServiceProps;
34
- type LocalImageTransform = {
34
+ export type LocalImageTransform = {
35
35
  src: string;
36
36
  [key: string]: any;
37
37
  };
@@ -1,6 +1,6 @@
1
1
  import { AstroError, AstroErrorData } from "../../core/errors/index.js";
2
2
  import { joinPaths } from "../../core/path.js";
3
- import { VALID_OPTIMIZABLE_FORMATS } from "../consts.js";
3
+ import { VALID_SUPPORTED_FORMATS } from "../consts.js";
4
4
  import { isESMImportedImage } from "../internal.js";
5
5
  function isLocalService(service) {
6
6
  if (!service) {
@@ -45,16 +45,19 @@ const baseService = {
45
45
  });
46
46
  }
47
47
  } else {
48
- if (!VALID_OPTIMIZABLE_FORMATS.includes(options.src.format)) {
48
+ if (!VALID_SUPPORTED_FORMATS.includes(options.src.format)) {
49
49
  throw new AstroError({
50
50
  ...AstroErrorData.UnsupportedImageFormat,
51
51
  message: AstroErrorData.UnsupportedImageFormat.message(
52
52
  options.src.format,
53
53
  options.src.src,
54
- VALID_OPTIMIZABLE_FORMATS
54
+ VALID_SUPPORTED_FORMATS
55
55
  )
56
56
  });
57
57
  }
58
+ if (options.src.format === "svg") {
59
+ options.format = "svg";
60
+ }
58
61
  }
59
62
  if (!options.format) {
60
63
  options.format = "webp";
@@ -27,7 +27,10 @@ const sharpService = {
27
27
  if (!sharp)
28
28
  sharp = await loadSharp();
29
29
  const transform = transformOptions;
30
+ if (transform.format === "svg")
31
+ return { data: inputBuffer, format: "svg" };
30
32
  let result = sharp(inputBuffer, { failOnError: false, pages: -1 });
33
+ result.rotate();
31
34
  if (transform.height && !transform.width) {
32
35
  result.resize({ height: transform.height });
33
36
  } else if (transform.width) {
@@ -1,3 +1,4 @@
1
+ import { imageMetadata } from "../utils/metadata.js";
1
2
  import {
2
3
  baseService,
3
4
  parseQuality
@@ -17,6 +18,24 @@ const qualityTable = {
17
18
  webp: baseQuality
18
19
  // Squoosh's PNG encoder does not support a quality setting, so we can skip that here
19
20
  };
21
+ async function getRotationForEXIF(transform, inputBuffer) {
22
+ const filePath = transform.src.slice("/@fs".length);
23
+ const filePathURL = new URL("." + filePath, "file:");
24
+ const meta = await imageMetadata(filePathURL, inputBuffer);
25
+ if (!meta)
26
+ return void 0;
27
+ switch (meta.orientation) {
28
+ case 3:
29
+ case 4:
30
+ return { type: "rotate", numRotations: 2 };
31
+ case 5:
32
+ case 6:
33
+ return { type: "rotate", numRotations: 1 };
34
+ case 7:
35
+ case 8:
36
+ return { type: "rotate", numRotations: 3 };
37
+ }
38
+ }
20
39
  const service = {
21
40
  validateOptions: baseService.validateOptions,
22
41
  getURL: baseService.getURL,
@@ -25,7 +44,13 @@ const service = {
25
44
  async transform(inputBuffer, transformOptions) {
26
45
  const transform = transformOptions;
27
46
  let format = transform.format;
47
+ if (format === "svg")
48
+ return { data: inputBuffer, format: "svg" };
28
49
  const operations = [];
50
+ const rotation = await getRotationForEXIF(transform, inputBuffer);
51
+ if (rotation) {
52
+ operations.push(rotation);
53
+ }
29
54
  if (transform.height && !transform.width) {
30
55
  operations.push({
31
56
  type: "resize",
@@ -37,15 +37,15 @@ var Module = function() {
37
37
  var nodePath;
38
38
  if (ENVIRONMENT_IS_NODE) {
39
39
  if (ENVIRONMENT_IS_WORKER) {
40
- scriptDirectory = require2("path").dirname(scriptDirectory) + "/";
40
+ scriptDirectory = require2("node:path").dirname(scriptDirectory) + "/";
41
41
  } else {
42
42
  scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
43
43
  }
44
44
  read_ = function shell_read(filename, binary) {
45
45
  if (!nodeFS)
46
- nodeFS = require2("fs");
46
+ nodeFS = require2("node:fs");
47
47
  if (!nodePath)
48
- nodePath = require2("path");
48
+ nodePath = require2("node:path");
49
49
  filename = nodePath["normalize"](filename);
50
50
  return nodeFS["readFileSync"](filename, binary ? null : "utf8");
51
51
  };
@@ -37,15 +37,15 @@ var Module = function() {
37
37
  var nodePath;
38
38
  if (ENVIRONMENT_IS_NODE) {
39
39
  if (ENVIRONMENT_IS_WORKER) {
40
- scriptDirectory = require2("path").dirname(scriptDirectory) + "/";
40
+ scriptDirectory = require2("node:path").dirname(scriptDirectory) + "/";
41
41
  } else {
42
42
  scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
43
43
  }
44
44
  read_ = function shell_read(filename, binary) {
45
45
  if (!nodeFS)
46
- nodeFS = require2("fs");
46
+ nodeFS = require2("node:fs");
47
47
  if (!nodePath)
48
- nodePath = require2("path");
48
+ nodePath = require2("node:path");
49
49
  filename = nodePath["normalize"](filename);
50
50
  return nodeFS["readFileSync"](filename, binary ? null : "utf8");
51
51
  };
@@ -1,6 +1,6 @@
1
+ import { cpus } from "node:os";
2
+ import { fileURLToPath } from "node:url";
1
3
  import { isMainThread } from "node:worker_threads";
2
- import { cpus } from "os";
3
- import { fileURLToPath } from "url";
4
4
  import { getModuleURL } from "./emscripten-utils.js";
5
5
  import * as impl from "./impl.js";
6
6
  import execOnce from "./utils/execOnce.js";
@@ -37,15 +37,15 @@ var Module = function() {
37
37
  var nodePath;
38
38
  if (ENVIRONMENT_IS_NODE) {
39
39
  if (ENVIRONMENT_IS_WORKER) {
40
- scriptDirectory = require2("path").dirname(scriptDirectory) + "/";
40
+ scriptDirectory = require2("node:path").dirname(scriptDirectory) + "/";
41
41
  } else {
42
42
  scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
43
43
  }
44
44
  read_ = function shell_read(filename, binary) {
45
45
  if (!nodeFS)
46
- nodeFS = require2("fs");
46
+ nodeFS = require2("node:fs");
47
47
  if (!nodePath)
48
- nodePath = require2("path");
48
+ nodePath = require2("node:path");
49
49
  filename = nodePath["normalize"](filename);
50
50
  return nodeFS["readFileSync"](filename, binary ? null : "utf8");
51
51
  };
@@ -37,15 +37,15 @@ var Module = function() {
37
37
  var nodePath;
38
38
  if (ENVIRONMENT_IS_NODE) {
39
39
  if (ENVIRONMENT_IS_WORKER) {
40
- scriptDirectory = require2("path").dirname(scriptDirectory) + "/";
40
+ scriptDirectory = require2("node:path").dirname(scriptDirectory) + "/";
41
41
  } else {
42
42
  scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
43
43
  }
44
44
  read_ = function shell_read(filename, binary) {
45
45
  if (!nodeFS)
46
- nodeFS = require2("fs");
46
+ nodeFS = require2("node:fs");
47
47
  if (!nodePath)
48
- nodePath = require2("path");
48
+ nodePath = require2("node:path");
49
49
  filename = nodePath["normalize"](filename);
50
50
  return nodeFS["readFileSync"](filename, binary ? null : "utf8");
51
51
  };
@@ -37,15 +37,15 @@ var Module = function() {
37
37
  var nodePath;
38
38
  if (ENVIRONMENT_IS_NODE) {
39
39
  if (ENVIRONMENT_IS_WORKER) {
40
- scriptDirectory = require2("path").dirname(scriptDirectory) + "/";
40
+ scriptDirectory = require2("node:path").dirname(scriptDirectory) + "/";
41
41
  } else {
42
42
  scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
43
43
  }
44
44
  read_ = function shell_read(filename, binary) {
45
45
  if (!nodeFS)
46
- nodeFS = require2("fs");
46
+ nodeFS = require2("node:fs");
47
47
  if (!nodePath)
48
- nodePath = require2("path");
48
+ nodePath = require2("node:path");
49
49
  filename = nodePath["normalize"](filename);
50
50
  return nodeFS["readFileSync"](filename, binary ? null : "utf8");
51
51
  };
@@ -37,15 +37,15 @@ var Module = function() {
37
37
  var nodePath;
38
38
  if (ENVIRONMENT_IS_NODE) {
39
39
  if (ENVIRONMENT_IS_WORKER) {
40
- scriptDirectory = require2("path").dirname(scriptDirectory) + "/";
40
+ scriptDirectory = require2("node:path").dirname(scriptDirectory) + "/";
41
41
  } else {
42
42
  scriptDirectory = dirname(getModuleURL(import.meta.url)) + "/";
43
43
  }
44
44
  read_ = function shell_read(filename, binary) {
45
45
  if (!nodeFS)
46
- nodeFS = require2("fs");
46
+ nodeFS = require2("node:fs");
47
47
  if (!nodePath)
48
- nodePath = require2("path");
48
+ nodePath = require2("node:path");
49
49
  filename = nodePath["normalize"](filename);
50
50
  return nodeFS["readFileSync"](filename, binary ? null : "utf8");
51
51
  };
@@ -22,6 +22,7 @@ export interface ImageMetadata {
22
22
  width: number;
23
23
  height: number;
24
24
  format: ImageInputFormat;
25
+ orientation?: number;
25
26
  }
26
27
  /**
27
28
  * Options accepted by the image transformation service.
@@ -1,2 +1,2 @@
1
- import { type Metadata } from './metadata.js';
2
- export declare function emitESMImage(id: string | undefined, watchMode: boolean, fileEmitter: any): Promise<Metadata | undefined>;
1
+ import type { ImageMetadata } from '../types.js';
2
+ export declare function emitESMImage(id: string | undefined, watchMode: boolean, fileEmitter: any): Promise<ImageMetadata | undefined>;
@@ -1,6 +1,3 @@
1
1
  /// <reference types="node" />
2
2
  import type { ImageMetadata } from '../types.js';
3
- export interface Metadata extends ImageMetadata {
4
- orientation?: number;
5
- }
6
- export declare function imageMetadata(src: URL | string, data?: Buffer): Promise<Metadata | undefined>;
3
+ export declare function imageMetadata(src: URL | string, data?: Buffer): Promise<ImageMetadata | undefined>;
@@ -1,4 +1,4 @@
1
- import { basename, extname } from "path";
1
+ import { basename, extname } from "node:path";
2
2
  import { removeQueryString } from "../../core/path.js";
3
3
  import { shorthash } from "../../runtime/server/shorthash.js";
4
4
  import { isESMImportedImage } from "../internal.js";
@@ -1,5 +1,5 @@
1
- import * as fs from "fs";
2
- import * as path from "path";
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
3
  import Queue from "../queue/queue.js";
4
4
  import { detector } from "./detector.js";
5
5
  import { typeHandlers } from "./types.js";
@@ -1,4 +1,4 @@
1
- import * as fs from "fs";
1
+ import * as fs from "node:fs";
2
2
  import { readUInt } from "../readUInt.js";
3
3
  function readIFD(buffer, filepath, isBigEndian) {
4
4
  const ifdOffset = readUInt(buffer, 32, 4, isBigEndian);
@@ -3,7 +3,6 @@ import { type LogOptions } from '../../core/logger/core.js';
3
3
  interface AddOptions {
4
4
  logging: LogOptions;
5
5
  flags: yargs.Arguments;
6
- cwd?: string;
7
6
  }
8
7
  interface IntegrationInfo {
9
8
  id: string;
@@ -11,6 +10,6 @@ interface IntegrationInfo {
11
10
  dependencies: [name: string, version: string][];
12
11
  type: 'integration' | 'adapter';
13
12
  }
14
- export declare function add(names: string[], { cwd, flags, logging }: AddOptions): Promise<void>;
13
+ export declare function add(names: string[], { flags, logging }: AddOptions): Promise<void>;
15
14
  export declare function validateIntegrations(integrations: string[]): Promise<IntegrationInfo[]>;
16
15
  export {};
@@ -1,13 +1,13 @@
1
1
  import boxen from "boxen";
2
2
  import { diffWords } from "diff";
3
3
  import { execa } from "execa";
4
- import fsMod, { existsSync, promises as fs } from "fs";
5
4
  import { bold, cyan, dim, green, magenta, red, yellow } from "kleur/colors";
5
+ import fsMod, { existsSync, promises as fs } from "node:fs";
6
+ import path from "node:path";
7
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
8
  import ora from "ora";
7
- import path from "path";
8
9
  import preferredPM from "preferred-pm";
9
10
  import prompts from "prompts";
10
- import { fileURLToPath, pathToFileURL } from "url";
11
11
  import { loadTSConfig, resolveConfigPath } from "../../core/config/index.js";
12
12
  import {
13
13
  defaultTSConfig,
@@ -20,6 +20,7 @@ import { printHelp } from "../../core/messages.js";
20
20
  import { appendForwardSlash } from "../../core/path.js";
21
21
  import { apply as applyPolyfill } from "../../core/polyfill.js";
22
22
  import { parseNpmName } from "../../core/util.js";
23
+ import { eventCliSession, telemetry } from "../../events/index.js";
23
24
  import { generate, parse, t, visit } from "./babel.js";
24
25
  import { ensureImport } from "./imports.js";
25
26
  import { wrapDefaultExport } from "./wrapper.js";
@@ -65,8 +66,9 @@ async function getRegistry() {
65
66
  return "https://registry.npmjs.org";
66
67
  }
67
68
  }
68
- async function add(names, { cwd, flags, logging }) {
69
+ async function add(names, { flags, logging }) {
69
70
  var _a;
71
+ telemetry.record(eventCliSession("add"));
70
72
  applyPolyfill();
71
73
  if (flags.help || names.length === 0) {
72
74
  printHelp({
@@ -106,6 +108,7 @@ async function add(names, { cwd, flags, logging }) {
106
108
  });
107
109
  return;
108
110
  }
111
+ const cwd = flags.root;
109
112
  const integrationNames = names.map((name) => ALIASES.has(name) ? ALIASES.get(name) : name);
110
113
  const integrations = await validateIntegrations(integrationNames);
111
114
  let installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logging });
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { AstroCheck } from '@astrojs/language-server';
3
- import fs from 'fs';
3
+ import fs from 'node:fs';
4
4
  import type { Arguments as Flags } from 'yargs-parser';
5
5
  import type { AstroSettings } from '../../@types/astro';
6
6
  import type { LogOptions } from '../../core/logger/core.js';
@@ -3,12 +3,12 @@ import {
3
3
  DiagnosticSeverity
4
4
  } from "@astrojs/language-server";
5
5
  import glob from "fast-glob";
6
- import fs from "fs";
7
6
  import { bold, dim, red, yellow } from "kleur/colors";
8
7
  import { createRequire } from "module";
8
+ import fs from "node:fs";
9
9
  import { join } from "node:path";
10
+ import { fileURLToPath, pathToFileURL } from "node:url";
10
11
  import ora from "ora";
11
- import { fileURLToPath, pathToFileURL } from "url";
12
12
  import { debug, info } from "../../core/logger/core.js";
13
13
  import { printHelp } from "../../core/messages.js";
14
14
  import { loadSettings } from "../load-settings.js";
@@ -11,8 +11,8 @@ import {
11
11
  white,
12
12
  yellow
13
13
  } from "kleur/colors";
14
+ import { fileURLToPath } from "node:url";
14
15
  import stringWidth from "string-width";
15
- import { fileURLToPath } from "url";
16
16
  function printDiagnostic(filePath, text, diag) {
17
17
  let result = [];
18
18
  const realStartLine = diag.range.start.line + 1;
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import fs from "node:fs";
2
2
  import { resolveConfigPath, resolveFlags } from "../../core/config/index.js";
3
3
  import devServer from "../../core/dev/index.js";
4
4
  import { info } from "../../core/logger/core.js";
package/dist/cli/index.js CHANGED
@@ -1,14 +1,8 @@
1
1
  import * as colors from "kleur/colors";
2
2
  import yargs from "yargs-parser";
3
3
  import { ASTRO_VERSION } from "../core/constants.js";
4
- import { collectErrorMetadata } from "../core/errors/dev/index.js";
5
- import { createSafeError } from "../core/errors/index.js";
6
- import { debug } from "../core/logger/core.js";
7
- import { enableVerboseLogging, nodeLogDestination } from "../core/logger/node.js";
8
- import { formatErrorMessage, printHelp } from "../core/messages.js";
9
- import * as event from "../events/index.js";
10
- import { eventError, telemetry } from "../events/index.js";
11
- function printAstroHelp() {
4
+ async function printAstroHelp() {
5
+ const { printHelp } = await import("../core/messages.js");
12
6
  printHelp({
13
7
  commandName: "astro",
14
8
  usage: "[command] [...flags]",
@@ -64,21 +58,19 @@ function resolveCommand(flags) {
64
58
  }
65
59
  async function runCommand(cmd, flags) {
66
60
  var _a;
67
- const root = flags.root;
68
61
  switch (cmd) {
69
62
  case "help":
70
- printAstroHelp();
63
+ await printAstroHelp();
71
64
  return;
72
65
  case "version":
73
66
  printVersion();
74
67
  return;
75
68
  case "info": {
76
69
  const { printInfo } = await import("./info/index.js");
77
- await printInfo({ cwd: root, flags });
70
+ await printInfo({ flags });
78
71
  return;
79
72
  }
80
73
  case "docs": {
81
- telemetry.record(event.eventCliSession(cmd));
82
74
  const { docs } = await import("./docs/index.js");
83
75
  await docs({ flags });
84
76
  return;
@@ -90,6 +82,7 @@ async function runCommand(cmd, flags) {
90
82
  return;
91
83
  }
92
84
  }
85
+ const { enableVerboseLogging, nodeLogDestination } = await import("../core/logger/node.js");
93
86
  const logging = {
94
87
  dest: nodeLogDestination,
95
88
  level: "info"
@@ -105,10 +98,9 @@ async function runCommand(cmd, flags) {
105
98
  }
106
99
  switch (cmd) {
107
100
  case "add": {
108
- telemetry.record(event.eventCliSession(cmd));
109
101
  const { add } = await import("./add/index.js");
110
102
  const packages = flags._.slice(3);
111
- await add(packages, { cwd: root, flags, logging });
103
+ await add(packages, { flags, logging });
112
104
  return;
113
105
  }
114
106
  case "dev": {
@@ -142,7 +134,7 @@ async function runCommand(cmd, flags) {
142
134
  return await new Promise(() => {
143
135
  });
144
136
  } else {
145
- let checkResult = await checkServer.check();
137
+ const checkResult = await checkServer.check();
146
138
  return process.exit(checkResult);
147
139
  }
148
140
  }
@@ -162,22 +154,10 @@ async function cli(args) {
162
154
  try {
163
155
  await runCommand(cmd, flags);
164
156
  } catch (err) {
157
+ const { throwAndExit } = await import("./throw-and-exit.js");
165
158
  await throwAndExit(cmd, err);
166
159
  }
167
160
  }
168
- async function throwAndExit(cmd, err) {
169
- let telemetryPromise;
170
- let errorMessage;
171
- function exitWithErrorMessage() {
172
- console.error(errorMessage);
173
- process.exit(1);
174
- }
175
- const errorWithMetadata = collectErrorMetadata(createSafeError(err));
176
- telemetryPromise = telemetry.record(eventError({ cmd, err: errorWithMetadata, isFatal: true }));
177
- errorMessage = formatErrorMessage(errorWithMetadata);
178
- setTimeout(exitWithErrorMessage, 400);
179
- await telemetryPromise.catch((err2) => debug("telemetry", `record() error: ${err2.message}`)).then(exitWithErrorMessage);
180
- }
181
161
  export {
182
162
  cli
183
163
  };
@@ -1,7 +1,6 @@
1
1
  import type yargs from 'yargs-parser';
2
2
  interface InfoOptions {
3
- cwd?: string;
4
3
  flags: yargs.Arguments;
5
4
  }
6
- export declare function printInfo({ cwd, flags }: InfoOptions): Promise<void>;
5
+ export declare function printInfo({ flags }: InfoOptions): Promise<void>;
7
6
  export {};
@@ -3,7 +3,7 @@ import { arch, platform } from "node:os";
3
3
  import whichPm from "which-pm";
4
4
  import { openConfig } from "../../core/config/index.js";
5
5
  import { ASTRO_VERSION } from "../../core/constants.js";
6
- async function printInfo({ cwd, flags }) {
6
+ async function printInfo({ flags }) {
7
7
  var _a;
8
8
  const packageManager = await whichPm(process.cwd());
9
9
  let adapter = "Couldn't determine.";
@@ -15,7 +15,7 @@ async function printInfo({ cwd, flags }) {
15
15
  }
16
16
  try {
17
17
  const { userConfig } = await openConfig({
18
- cwd,
18
+ cwd: flags.root,
19
19
  flags,
20
20
  cmd: "info"
21
21
  });
@@ -1,5 +1,5 @@
1
- import fs from "fs";
2
1
  import * as colors from "kleur/colors";
2
+ import fs from "node:fs";
3
3
  import { ZodError } from "zod";
4
4
  import { createSettings, openConfig, resolveConfigPath } from "../core/config/index.js";
5
5
  import { collectErrorMetadata } from "../core/errors/dev/index.js";
@@ -1,4 +1,4 @@
1
- import fs from "fs";
1
+ import fs from "node:fs";
2
2
  import { syncCli } from "../../core/sync/index.js";
3
3
  import { loadSettings } from "../load-settings.js";
4
4
  async function sync({ flags, logging }) {
@@ -0,0 +1,2 @@
1
+ /** Display error and exit */
2
+ export declare function throwAndExit(cmd: string, err: unknown): Promise<void>;
@@ -0,0 +1,21 @@
1
+ import { collectErrorMetadata } from "../core/errors/dev/index.js";
2
+ import { createSafeError } from "../core/errors/index.js";
3
+ import { debug } from "../core/logger/core.js";
4
+ import { formatErrorMessage } from "../core/messages.js";
5
+ import { eventError, telemetry } from "../events/index.js";
6
+ async function throwAndExit(cmd, err) {
7
+ let telemetryPromise;
8
+ let errorMessage;
9
+ function exitWithErrorMessage() {
10
+ console.error(errorMessage);
11
+ process.exit(1);
12
+ }
13
+ const errorWithMetadata = collectErrorMetadata(createSafeError(err));
14
+ telemetryPromise = telemetry.record(eventError({ cmd, err: errorWithMetadata, isFatal: true }));
15
+ errorMessage = formatErrorMessage(errorWithMetadata);
16
+ setTimeout(exitWithErrorMessage, 400);
17
+ await telemetryPromise.catch((err2) => debug("telemetry", `record() error: ${err2.message}`)).then(exitWithErrorMessage);
18
+ }
19
+ export {
20
+ throwAndExit
21
+ };
@@ -13,7 +13,7 @@ function getViteConfig(inlineConfig) {
13
13
  { runHookConfigSetup, runHookConfigDone },
14
14
  { astroContentListenPlugin }
15
15
  ] = await Promise.all([
16
- import("fs"),
16
+ import("node:fs"),
17
17
  import("vite"),
18
18
  import("../core/logger/node.js"),
19
19
  import("../core/config/index.js"),
@@ -1,3 +1,3 @@
1
1
  import type { PluginContext } from 'rollup';
2
2
  import { z } from 'zod';
3
- export declare function createImage(pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/utils/metadata.js").Metadata | z.ZodNever, string>;
3
+ export declare function createImage(pluginContext: PluginContext, entryFilePath: string): () => z.ZodEffects<z.ZodString, import("../assets/types.js").ImageMetadata | z.ZodNever, string>;