astro 2.1.3 → 2.1.5

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 (154) hide show
  1. package/dist/@types/astro.d.ts +15 -0
  2. package/dist/@types/typed-emitter.d.ts +1 -2
  3. package/dist/assets/consts.js +8 -0
  4. package/dist/assets/image-endpoint.js +1 -1
  5. package/dist/assets/internal.d.ts +2 -1
  6. package/dist/assets/internal.js +10 -5
  7. package/dist/assets/services/service.d.ts +10 -1
  8. package/dist/assets/services/service.js +35 -29
  9. package/dist/assets/services/sharp.d.ts +1 -1
  10. package/dist/assets/services/sharp.js +5 -4
  11. package/dist/assets/services/squoosh.d.ts +1 -1
  12. package/dist/assets/services/squoosh.js +7 -4
  13. package/dist/assets/services/vendor/squoosh/codecs.js +2 -0
  14. package/dist/assets/services/vendor/squoosh/image-pool.js +2 -0
  15. package/dist/assets/services/vendor/squoosh/impl.js +2 -0
  16. package/dist/assets/utils/metadata.js +2 -5
  17. package/dist/assets/vendor/image-size/detector.d.ts +3 -0
  18. package/dist/assets/vendor/image-size/detector.js +28 -0
  19. package/dist/assets/vendor/image-size/index.d.ts +11 -0
  20. package/dist/assets/vendor/image-size/index.js +93 -0
  21. package/dist/assets/vendor/image-size/readUInt.d.ts +4 -0
  22. package/dist/assets/vendor/image-size/readUInt.js +9 -0
  23. package/dist/assets/vendor/image-size/types/bmp.d.ts +2 -0
  24. package/dist/assets/vendor/image-size/types/bmp.js +14 -0
  25. package/dist/assets/vendor/image-size/types/cur.d.ts +2 -0
  26. package/dist/assets/vendor/image-size/types/cur.js +16 -0
  27. package/dist/assets/vendor/image-size/types/dds.d.ts +2 -0
  28. package/dist/assets/vendor/image-size/types/dds.js +14 -0
  29. package/dist/assets/vendor/image-size/types/gif.d.ts +2 -0
  30. package/dist/assets/vendor/image-size/types/gif.js +16 -0
  31. package/dist/assets/vendor/image-size/types/icns.d.ts +2 -0
  32. package/dist/assets/vendor/image-size/types/icns.js +87 -0
  33. package/dist/assets/vendor/image-size/types/ico.d.ts +2 -0
  34. package/dist/assets/vendor/image-size/types/ico.js +42 -0
  35. package/dist/assets/vendor/image-size/types/interface.d.ts +14 -0
  36. package/dist/assets/vendor/image-size/types/interface.js +0 -0
  37. package/dist/assets/vendor/image-size/types/j2c.d.ts +2 -0
  38. package/dist/assets/vendor/image-size/types/j2c.js +14 -0
  39. package/dist/assets/vendor/image-size/types/jp2.d.ts +2 -0
  40. package/dist/assets/vendor/image-size/types/jp2.js +56 -0
  41. package/dist/assets/vendor/image-size/types/jpg.d.ts +2 -0
  42. package/dist/assets/vendor/image-size/types/jpg.js +95 -0
  43. package/dist/assets/vendor/image-size/types/ktx.d.ts +2 -0
  44. package/dist/assets/vendor/image-size/types/ktx.js +15 -0
  45. package/dist/assets/vendor/image-size/types/png.d.ts +2 -0
  46. package/dist/assets/vendor/image-size/types/png.js +33 -0
  47. package/dist/assets/vendor/image-size/types/pnm.d.ts +2 -0
  48. package/dist/assets/vendor/image-size/types/pnm.js +72 -0
  49. package/dist/assets/vendor/image-size/types/psd.d.ts +2 -0
  50. package/dist/assets/vendor/image-size/types/psd.js +14 -0
  51. package/dist/assets/vendor/image-size/types/svg.d.ts +2 -0
  52. package/dist/assets/vendor/image-size/types/svg.js +91 -0
  53. package/dist/assets/vendor/image-size/types/tiff.d.ts +2 -0
  54. package/dist/assets/vendor/image-size/types/tiff.js +81 -0
  55. package/dist/assets/vendor/image-size/types/webp.d.ts +2 -0
  56. package/dist/assets/vendor/image-size/types/webp.js +51 -0
  57. package/dist/assets/vendor/image-size/types.d.ts +19 -0
  58. package/dist/assets/vendor/image-size/types.js +37 -0
  59. package/dist/assets/vendor/queue/queue.d.ts +39 -0
  60. package/dist/assets/vendor/queue/queue.js +187 -0
  61. package/dist/assets/vite-plugin-assets.js +4 -0
  62. package/dist/cli/check/index.js +43 -2
  63. package/dist/cli/check/print.d.ts +1 -1
  64. package/dist/content/error-map.js +4 -1
  65. package/dist/content/server-listeners.d.ts +1 -1
  66. package/dist/content/types-generator.d.ts +3 -3
  67. package/dist/content/types-generator.js +3 -0
  68. package/dist/content/utils.d.ts +2 -2
  69. package/dist/content/utils.js +2 -0
  70. package/dist/content/vite-plugin-content-assets.d.ts +1 -1
  71. package/dist/content/vite-plugin-content-imports.d.ts +1 -1
  72. package/dist/content/vite-plugin-content-imports.js +163 -77
  73. package/dist/content/vite-plugin-content-virtual-mod.js +4 -1
  74. package/dist/core/add/index.d.ts +1 -1
  75. package/dist/core/add/index.js +11 -9
  76. package/dist/core/app/index.js +4 -1
  77. package/dist/core/app/node.d.ts +1 -1
  78. package/dist/core/build/generate.d.ts +1 -1
  79. package/dist/core/build/generate.js +5 -1
  80. package/dist/core/build/index.js +4 -0
  81. package/dist/core/build/plugin.js +1 -0
  82. package/dist/core/build/plugins/plugin-css.d.ts +1 -1
  83. package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
  84. package/dist/core/build/static-build.d.ts +1 -1
  85. package/dist/core/build/static-build.js +4 -1
  86. package/dist/core/compile/cache.d.ts +1 -1
  87. package/dist/core/compile/style.d.ts +1 -1
  88. package/dist/core/config/schema.d.ts +36 -36
  89. package/dist/core/config/schema.js +9 -1
  90. package/dist/core/config/timer.js +9 -0
  91. package/dist/core/config/tsconfig.js +4 -0
  92. package/dist/core/config/vite-load.js +3 -0
  93. package/dist/core/constants.js +1 -1
  94. package/dist/core/cookies/cookies.js +35 -1
  95. package/dist/core/create-vite.js +30 -3
  96. package/dist/core/dev/container.js +1 -0
  97. package/dist/core/dev/dev.d.ts +1 -1
  98. package/dist/core/dev/dev.js +2 -1
  99. package/dist/core/endpoint/index.d.ts +1 -1
  100. package/dist/core/endpoint/index.js +1 -0
  101. package/dist/core/errors/dev/utils.d.ts +1 -1
  102. package/dist/core/errors/dev/utils.js +2 -1
  103. package/dist/core/errors/dev/vite.d.ts +1 -1
  104. package/dist/core/errors/dev/vite.js +5 -0
  105. package/dist/core/errors/errors-data.js +486 -3
  106. package/dist/core/errors/errors.js +2 -0
  107. package/dist/core/errors/overlay.js +16 -5
  108. package/dist/core/errors/utils.d.ts +1 -1
  109. package/dist/core/logger/console.js +1 -1
  110. package/dist/core/logger/node.js +1 -1
  111. package/dist/core/messages.d.ts +1 -1
  112. package/dist/core/messages.js +2 -2
  113. package/dist/core/module-loader/loader.d.ts +3 -3
  114. package/dist/core/render/dev/css.js +2 -1
  115. package/dist/core/render/dev/environment.js +1 -0
  116. package/dist/core/render/dev/index.js +1 -0
  117. package/dist/core/render/dev/resolve.js +1 -6
  118. package/dist/core/render/dev/vite.js +13 -1
  119. package/dist/core/render/index.d.ts +1 -1
  120. package/dist/core/render/result.d.ts +1 -1
  121. package/dist/core/render/result.js +4 -0
  122. package/dist/core/render/route-cache.d.ts +1 -1
  123. package/dist/core/render/route-cache.js +1 -0
  124. package/dist/core/routing/manifest/create.js +4 -1
  125. package/dist/core/sync/index.d.ts +1 -1
  126. package/dist/core/sync/index.js +1 -1
  127. package/dist/events/error.d.ts +1 -1
  128. package/dist/integrations/index.d.ts +1 -1
  129. package/dist/jsx/renderer.js +1 -0
  130. package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
  131. package/dist/runtime/client/visible.prebuilt.js +1 -1
  132. package/dist/runtime/server/hydration.js +1 -0
  133. package/dist/runtime/server/render/scope.js +5 -0
  134. package/dist/runtime/server/scripts.js +2 -2
  135. package/dist/vite-plugin-astro/compile.d.ts +2 -2
  136. package/dist/vite-plugin-astro/compile.js +1 -0
  137. package/dist/vite-plugin-astro/index.js +7 -1
  138. package/dist/vite-plugin-astro-server/base.d.ts +1 -1
  139. package/dist/vite-plugin-astro-server/common.d.ts +1 -1
  140. package/dist/vite-plugin-astro-server/response.js +2 -2
  141. package/dist/vite-plugin-config-alias/index.d.ts +2 -7
  142. package/dist/vite-plugin-config-alias/index.js +32 -41
  143. package/dist/vite-plugin-env/index.js +1 -0
  144. package/dist/vite-plugin-inject-env-ts/index.d.ts +2 -2
  145. package/dist/vite-plugin-inject-env-ts/index.js +2 -0
  146. package/dist/vite-plugin-jsx/index.d.ts +1 -1
  147. package/dist/vite-plugin-jsx/index.js +7 -1
  148. package/dist/vite-plugin-jsx/tag.js +7 -0
  149. package/dist/vite-plugin-markdown/index.js +27 -58
  150. package/dist/vite-plugin-scanner/index.d.ts +1 -1
  151. package/dist/vite-plugin-scripts/page-ssr.d.ts +1 -1
  152. package/package.json +5 -6
  153. package/src/content/template/types.d.ts +12 -1
  154. package/tsconfigs/base.json +4 -1
@@ -0,0 +1,51 @@
1
+ function calculateExtended(buffer) {
2
+ return {
3
+ height: 1 + buffer.readUIntLE(7, 3),
4
+ width: 1 + buffer.readUIntLE(4, 3)
5
+ };
6
+ }
7
+ function calculateLossless(buffer) {
8
+ return {
9
+ height: 1 + ((buffer[4] & 15) << 10 | buffer[3] << 2 | (buffer[2] & 192) >> 6),
10
+ width: 1 + ((buffer[2] & 63) << 8 | buffer[1])
11
+ };
12
+ }
13
+ function calculateLossy(buffer) {
14
+ return {
15
+ height: buffer.readInt16LE(8) & 16383,
16
+ width: buffer.readInt16LE(6) & 16383
17
+ };
18
+ }
19
+ const WEBP = {
20
+ validate(buffer) {
21
+ const riffHeader = "RIFF" === buffer.toString("ascii", 0, 4);
22
+ const webpHeader = "WEBP" === buffer.toString("ascii", 8, 12);
23
+ const vp8Header = "VP8" === buffer.toString("ascii", 12, 15);
24
+ return riffHeader && webpHeader && vp8Header;
25
+ },
26
+ calculate(buffer) {
27
+ const chunkHeader = buffer.toString("ascii", 12, 16);
28
+ buffer = buffer.slice(20, 30);
29
+ if (chunkHeader === "VP8X") {
30
+ const extendedHeader = buffer[0];
31
+ const validStart = (extendedHeader & 192) === 0;
32
+ const validEnd = (extendedHeader & 1) === 0;
33
+ if (validStart && validEnd) {
34
+ return calculateExtended(buffer);
35
+ } else {
36
+ throw new TypeError("Invalid WebP");
37
+ }
38
+ }
39
+ if (chunkHeader === "VP8 " && buffer[0] !== 47) {
40
+ return calculateLossy(buffer);
41
+ }
42
+ const signature = buffer.toString("hex", 3, 6);
43
+ if (chunkHeader === "VP8L" && signature !== "9d012a") {
44
+ return calculateLossless(buffer);
45
+ }
46
+ throw new TypeError("Invalid WebP");
47
+ }
48
+ };
49
+ export {
50
+ WEBP
51
+ };
@@ -0,0 +1,19 @@
1
+ export declare const typeHandlers: {
2
+ bmp: import("./types/interface.js").IImage;
3
+ cur: import("./types/interface.js").IImage;
4
+ dds: import("./types/interface.js").IImage;
5
+ gif: import("./types/interface.js").IImage;
6
+ icns: import("./types/interface.js").IImage;
7
+ ico: import("./types/interface.js").IImage;
8
+ j2c: import("./types/interface.js").IImage;
9
+ jp2: import("./types/interface.js").IImage;
10
+ jpg: import("./types/interface.js").IImage;
11
+ ktx: import("./types/interface.js").IImage;
12
+ png: import("./types/interface.js").IImage;
13
+ pnm: import("./types/interface.js").IImage;
14
+ psd: import("./types/interface.js").IImage;
15
+ svg: import("./types/interface.js").IImage;
16
+ tiff: import("./types/interface.js").IImage;
17
+ webp: import("./types/interface.js").IImage;
18
+ };
19
+ export type imageType = keyof typeof typeHandlers;
@@ -0,0 +1,37 @@
1
+ import { BMP } from "./types/bmp.js";
2
+ import { CUR } from "./types/cur.js";
3
+ import { DDS } from "./types/dds.js";
4
+ import { GIF } from "./types/gif.js";
5
+ import { ICNS } from "./types/icns.js";
6
+ import { ICO } from "./types/ico.js";
7
+ import { J2C } from "./types/j2c.js";
8
+ import { JP2 } from "./types/jp2.js";
9
+ import { JPG } from "./types/jpg.js";
10
+ import { KTX } from "./types/ktx.js";
11
+ import { PNG } from "./types/png.js";
12
+ import { PNM } from "./types/pnm.js";
13
+ import { PSD } from "./types/psd.js";
14
+ import { SVG } from "./types/svg.js";
15
+ import { TIFF } from "./types/tiff.js";
16
+ import { WEBP } from "./types/webp.js";
17
+ const typeHandlers = {
18
+ bmp: BMP,
19
+ cur: CUR,
20
+ dds: DDS,
21
+ gif: GIF,
22
+ icns: ICNS,
23
+ ico: ICO,
24
+ j2c: J2C,
25
+ jp2: JP2,
26
+ jpg: JPG,
27
+ ktx: KTX,
28
+ png: PNG,
29
+ pnm: PNM,
30
+ psd: PSD,
31
+ svg: SVG,
32
+ tiff: TIFF,
33
+ webp: WEBP
34
+ };
35
+ export {
36
+ typeHandlers
37
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Since CustomEvent is only supported in nodejs since version 19,
3
+ * you have to create your own class instead of using CustomEvent
4
+ * @see https://github.com/nodejs/node/issues/40678
5
+ * */
6
+ export class QueueEvent extends Event {
7
+ constructor(name: any, detail: any);
8
+ detail: any;
9
+ }
10
+ export default class Queue extends EventTarget {
11
+ constructor(options?: {});
12
+ concurrency: any;
13
+ timeout: any;
14
+ autostart: any;
15
+ results: any;
16
+ pending: number;
17
+ session: number;
18
+ running: boolean;
19
+ jobs: any[];
20
+ timers: any[];
21
+ _errorHandler(evt: any): void;
22
+ pop(): any;
23
+ shift(): any;
24
+ indexOf(searchElement: any, fromIndex: any): number;
25
+ lastIndexOf(searchElement: any, fromIndex: any): number;
26
+ slice(start: any, end: any): Queue;
27
+ reverse(): Queue;
28
+ push(...workers: any[]): number;
29
+ unshift(...workers: any[]): number;
30
+ splice(start: any, deleteCount: any, ...workers: any[]): Queue;
31
+ get length(): number;
32
+ start(callback: any): any;
33
+ stop(): void;
34
+ end(error: any): void;
35
+ clearTimers(): void;
36
+ _addCallbackToEndEvent(cb: any): void;
37
+ _createPromiseToEndEvent(): Promise<any>;
38
+ done(error: any): void;
39
+ }
@@ -0,0 +1,187 @@
1
+ const has = Object.prototype.hasOwnProperty;
2
+ class QueueEvent extends Event {
3
+ constructor(name, detail) {
4
+ super(name);
5
+ this.detail = detail;
6
+ }
7
+ }
8
+ class Queue extends EventTarget {
9
+ constructor(options = {}) {
10
+ super();
11
+ const { concurrency = Infinity, timeout = 0, autostart = false, results = null } = options;
12
+ this.concurrency = concurrency;
13
+ this.timeout = timeout;
14
+ this.autostart = autostart;
15
+ this.results = results;
16
+ this.pending = 0;
17
+ this.session = 0;
18
+ this.running = false;
19
+ this.jobs = [];
20
+ this.timers = [];
21
+ this.addEventListener("error", this._errorHandler);
22
+ }
23
+ _errorHandler(evt) {
24
+ this.end(evt.detail.error);
25
+ }
26
+ pop() {
27
+ return this.jobs.pop();
28
+ }
29
+ shift() {
30
+ return this.jobs.shift();
31
+ }
32
+ indexOf(searchElement, fromIndex) {
33
+ return this.jobs.indexOf(searchElement, fromIndex);
34
+ }
35
+ lastIndexOf(searchElement, fromIndex) {
36
+ if (fromIndex !== void 0) {
37
+ return this.jobs.lastIndexOf(searchElement, fromIndex);
38
+ }
39
+ return this.jobs.lastIndexOf(searchElement);
40
+ }
41
+ slice(start, end) {
42
+ this.jobs = this.jobs.slice(start, end);
43
+ return this;
44
+ }
45
+ reverse() {
46
+ this.jobs.reverse();
47
+ return this;
48
+ }
49
+ push(...workers) {
50
+ const methodResult = this.jobs.push(...workers);
51
+ if (this.autostart) {
52
+ this.start();
53
+ }
54
+ return methodResult;
55
+ }
56
+ unshift(...workers) {
57
+ const methodResult = this.jobs.unshift(...workers);
58
+ if (this.autostart) {
59
+ this.start();
60
+ }
61
+ return methodResult;
62
+ }
63
+ splice(start, deleteCount, ...workers) {
64
+ this.jobs.splice(start, deleteCount, ...workers);
65
+ if (this.autostart) {
66
+ this.start();
67
+ }
68
+ return this;
69
+ }
70
+ get length() {
71
+ return this.pending + this.jobs.length;
72
+ }
73
+ start(callback) {
74
+ let awaiter;
75
+ if (callback) {
76
+ this._addCallbackToEndEvent(callback);
77
+ } else {
78
+ awaiter = this._createPromiseToEndEvent();
79
+ }
80
+ this.running = true;
81
+ if (this.pending >= this.concurrency) {
82
+ return;
83
+ }
84
+ if (this.jobs.length === 0) {
85
+ if (this.pending === 0) {
86
+ this.done();
87
+ }
88
+ return;
89
+ }
90
+ const job = this.jobs.shift();
91
+ const session = this.session;
92
+ const timeout = job !== void 0 && has.call(job, "timeout") ? job.timeout : this.timeout;
93
+ let once = true;
94
+ let timeoutId = null;
95
+ let didTimeout = false;
96
+ let resultIndex = null;
97
+ const next = (error, ...result) => {
98
+ if (once && this.session === session) {
99
+ once = false;
100
+ this.pending--;
101
+ if (timeoutId !== null) {
102
+ this.timers = this.timers.filter((tID) => tID !== timeoutId);
103
+ clearTimeout(timeoutId);
104
+ }
105
+ if (error) {
106
+ this.dispatchEvent(new QueueEvent("error", { error, job }));
107
+ } else if (!didTimeout) {
108
+ if (resultIndex !== null && this.results !== null) {
109
+ this.results[resultIndex] = [...result];
110
+ }
111
+ this.dispatchEvent(new QueueEvent("success", { result: [...result], job }));
112
+ }
113
+ if (this.session === session) {
114
+ if (this.pending === 0 && this.jobs.length === 0) {
115
+ this.done();
116
+ } else if (this.running) {
117
+ this.start();
118
+ }
119
+ }
120
+ }
121
+ };
122
+ if (timeout) {
123
+ timeoutId = setTimeout(() => {
124
+ didTimeout = true;
125
+ this.dispatchEvent(new QueueEvent("timeout", { next, job }));
126
+ next();
127
+ }, timeout);
128
+ this.timers.push(timeoutId);
129
+ }
130
+ if (this.results != null) {
131
+ resultIndex = this.results.length;
132
+ this.results[resultIndex] = null;
133
+ }
134
+ this.pending++;
135
+ this.dispatchEvent(new QueueEvent("start", { job }));
136
+ const promise = job(next);
137
+ if (promise !== void 0 && typeof promise.then === "function") {
138
+ promise.then(function(result) {
139
+ return next(void 0, result);
140
+ }).catch(function(err) {
141
+ return next(err || true);
142
+ });
143
+ }
144
+ if (this.running && this.jobs.length > 0) {
145
+ return this.start();
146
+ }
147
+ return awaiter;
148
+ }
149
+ stop() {
150
+ this.running = false;
151
+ }
152
+ end(error) {
153
+ this.clearTimers();
154
+ this.jobs.length = 0;
155
+ this.pending = 0;
156
+ this.done(error);
157
+ }
158
+ clearTimers() {
159
+ this.timers.forEach((timer) => {
160
+ clearTimeout(timer);
161
+ });
162
+ this.timers = [];
163
+ }
164
+ _addCallbackToEndEvent(cb) {
165
+ const onend = (evt) => {
166
+ this.removeEventListener("end", onend);
167
+ cb(evt.detail.error, this.results);
168
+ };
169
+ this.addEventListener("end", onend);
170
+ }
171
+ _createPromiseToEndEvent() {
172
+ return new Promise((resolve) => {
173
+ this._addCallbackToEndEvent((error, results) => {
174
+ resolve({ error, results });
175
+ });
176
+ });
177
+ }
178
+ done(error) {
179
+ this.session++;
180
+ this.running = false;
181
+ this.dispatchEvent(new QueueEvent("end", { error }));
182
+ }
183
+ }
184
+ export {
185
+ QueueEvent,
186
+ Queue as default
187
+ };
@@ -43,6 +43,7 @@ function assets({
43
43
  );
44
44
  }
45
45
  return [
46
+ // Expose the components and different utilities from `astro:assets` and handle serving images from `/_image` in dev
46
47
  {
47
48
  name: "astro:assets",
48
49
  config() {
@@ -73,6 +74,7 @@ function assets({
73
74
  `;
74
75
  }
75
76
  },
77
+ // Handle serving images during development
76
78
  configureServer(server) {
77
79
  server.middlewares.use(async (req, res, next) => {
78
80
  var _a2;
@@ -150,6 +152,7 @@ function assets({
150
152
  const dir = settings.config.output === "server" ? settings.config.build.server : settings.config.outDir;
151
153
  await copyWasmFiles(new URL("./chunks", dir));
152
154
  },
155
+ // In build, rewrite paths to ESM imported images in code to their final location
153
156
  async renderChunk(code) {
154
157
  const assetUrlRE = /__ASTRO_ASSET_IMAGE__([a-z\d]{8})__(?:_(.*?)__)?/g;
155
158
  let match;
@@ -171,6 +174,7 @@ function assets({
171
174
  }
172
175
  }
173
176
  },
177
+ // Return a more advanced shape for images imported in ESM
174
178
  {
175
179
  name: "astro:assets:esm",
176
180
  enforce: "pre",
@@ -1,4 +1,7 @@
1
- import { AstroCheck, DiagnosticSeverity } from "@astrojs/language-server";
1
+ import {
2
+ AstroCheck,
3
+ DiagnosticSeverity
4
+ } from "@astrojs/language-server";
2
5
  import glob from "fast-glob";
3
6
  import * as fs from "fs";
4
7
  import { bold, dim, red, yellow } from "kleur/colors";
@@ -22,7 +25,10 @@ async function check(settings, { logging, flags }) {
22
25
  commandName: "astro check",
23
26
  usage: "[...flags]",
24
27
  tables: {
25
- Flags: [["--help (-h)", "See all available flags."]]
28
+ Flags: [
29
+ ["--watch", "Watch Astro files for changes and re-run checks."],
30
+ ["--help (-h)", "See all available flags."]
31
+ ]
26
32
  },
27
33
  description: `Runs diagnostics against your project and reports errors to the console.`
28
34
  });
@@ -78,18 +84,30 @@ class AstroChecker {
78
84
  this.#fs = fileSystem;
79
85
  this.#filesCount = 0;
80
86
  }
87
+ /**
88
+ * Check all `.astro` files once and then finishes the operation.
89
+ */
81
90
  async check() {
82
91
  return await this.#checkAllFiles(true);
83
92
  }
93
+ /**
94
+ * Check all `.astro` files and then start watching for changes.
95
+ */
84
96
  async watch() {
85
97
  await this.#checkAllFiles(true);
86
98
  await this.#watch();
87
99
  return 2 /* Listen */;
88
100
  }
101
+ /**
102
+ * Stops the watch. It terminates the inner server.
103
+ */
89
104
  async stop() {
90
105
  var _a;
91
106
  await ((_a = this.#watcher) == null ? void 0 : _a.close());
92
107
  }
108
+ /**
109
+ * Whether the checker should run in watch mode
110
+ */
93
111
  get isWatchMode() {
94
112
  return this.#shouldWatch;
95
113
  }
@@ -100,6 +118,14 @@ class AstroChecker {
100
118
  this.#diagnosticsChecker
101
119
  );
102
120
  }
121
+ /**
122
+ * Lint all `.astro` files, and report the result in console. Operations executed, in order:
123
+ * 1. Compile content collections.
124
+ * 2. Optionally, traverse the file system for `.astro` files and saves their paths.
125
+ * 3. Get diagnostics for said files and print the result in console.
126
+ *
127
+ * @param openDocuments Whether the operation should open all `.astro` files
128
+ */
103
129
  async #checkAllFiles(openDocuments) {
104
130
  const processExit = await this.#syncCli(this.#settings, {
105
131
  logging: this.#logging,
@@ -123,6 +149,9 @@ class AstroChecker {
123
149
  clearTimeout(this.#updateDiagnostics);
124
150
  this.#updateDiagnostics = setTimeout(async () => await this.#checkAllFiles(false), 500);
125
151
  }
152
+ /**
153
+ * This function is responsible to attach events to the server watcher
154
+ */
126
155
  async #watch() {
127
156
  const { default: chokidar } = await import("chokidar");
128
157
  this.#watcher = chokidar.watch(
@@ -147,6 +176,10 @@ class AstroChecker {
147
176
  this.#checkForDiagnostics();
148
177
  });
149
178
  }
179
+ /**
180
+ * Add a document to the diagnostics checker
181
+ * @param filePath Path to the file
182
+ */
150
183
  #addDocument(filePath) {
151
184
  const text = fs.readFileSync(filePath, "utf-8");
152
185
  this.#diagnosticsChecker.upsertDocument({
@@ -154,6 +187,11 @@ class AstroChecker {
154
187
  text
155
188
  });
156
189
  }
190
+ /**
191
+ * Logs the result of the various diagnostics
192
+ *
193
+ * @param result Result emitted by AstroChecker.#breakDownDiagnostics
194
+ */
157
195
  #logDiagnosticsSeverity(result) {
158
196
  info(
159
197
  this.#logging,
@@ -168,6 +206,9 @@ class AstroChecker {
168
206
  ${dim("-")} `)
169
207
  );
170
208
  }
209
+ /**
210
+ * It loops through all diagnostics and break down diagnostics that are errors, warnings or hints.
211
+ */
171
212
  #breakDownDiagnostics(diagnostics) {
172
213
  let result = {
173
214
  errors: 0,
@@ -1,2 +1,2 @@
1
- import { Diagnostic } from '@astrojs/language-server';
1
+ import { type Diagnostic } from '@astrojs/language-server';
2
2
  export declare function printDiagnostic(filePath: string, text: string, diag: Diagnostic): string;
@@ -25,7 +25,10 @@ const errorMap = (baseError, ctx) => {
25
25
  return {
26
26
  message: messages.concat(
27
27
  [...typeOrLiteralErrByPath.entries()].filter(([, error]) => error.expected.length === baseError.unionErrors.length).map(
28
- ([key, error]) => key === baseErrorPath ? `> ${getTypeOrLiteralMsg(error)}` : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
28
+ ([key, error]) => key === baseErrorPath ? (
29
+ // Avoid printing the key again if it's a base error
30
+ `> ${getTypeOrLiteralMsg(error)}`
31
+ ) : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
29
32
  )
30
33
  ).join("\n")
31
34
  };
@@ -2,7 +2,7 @@
2
2
  import type fsMod from 'node:fs';
3
3
  import type { ViteDevServer } from 'vite';
4
4
  import type { AstroSettings } from '../@types/astro.js';
5
- import { LogOptions } from '../core/logger/core.js';
5
+ import { type LogOptions } from '../core/logger/core.js';
6
6
  interface ContentServerListenerParams {
7
7
  fs: typeof fsMod;
8
8
  logging: LogOptions;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import type fsMod from 'node:fs';
3
- import { ViteDevServer } from 'vite';
3
+ import { type ViteDevServer } from 'vite';
4
4
  import type { AstroSettings } from '../@types/astro.js';
5
- import { LogOptions } from '../core/logger/core.js';
6
- import { ContentObservable } from './utils.js';
5
+ import { type LogOptions } from '../core/logger/core.js';
6
+ import { type ContentObservable } from './utils.js';
7
7
  type ChokidarEvent = 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
8
8
  type RawContentEvent = {
9
9
  name: ChokidarEvent;
@@ -48,6 +48,7 @@ async function createContentTypesGenerator({
48
48
  }
49
49
  });
50
50
  const entries = globResult.map((e) => new URL(e, contentPaths.contentDir)).filter(
51
+ // Config loading handled first. Avoid running twice.
51
52
  (e) => !e.href.startsWith(contentPaths.config.url.href)
52
53
  );
53
54
  for (const entry of entries) {
@@ -107,6 +108,7 @@ async function createContentTypesGenerator({
107
108
  const entryInfo2 = getEntryInfo({
108
109
  entry: event.entry,
109
110
  contentDir: contentPaths.contentDir,
111
+ // Skip invalid file check. We already know it’s invalid.
110
112
  allowFilesOutsideCollection: true
111
113
  });
112
114
  return {
@@ -174,6 +176,7 @@ async function createContentTypesGenerator({
174
176
  debounceTimeout = setTimeout(
175
177
  async () => runEvents(opts),
176
178
  50
179
+ /* debounce to batch chokidar events */
177
180
  );
178
181
  }
179
182
  async function runEvents(opts) {
@@ -2,7 +2,7 @@
2
2
  import matter from 'gray-matter';
3
3
  import fsMod from 'node:fs';
4
4
  import type { EmitFile } from 'rollup';
5
- import { ViteDevServer } from 'vite';
5
+ import { type ViteDevServer } from 'vite';
6
6
  import { z } from 'zod';
7
7
  import type { AstroConfig, AstroSettings } from '../@types/astro.js';
8
8
  export declare const collectionConfigParser: z.ZodObject<{
@@ -36,7 +36,7 @@ export declare const contentConfigParser: z.ZodObject<{
36
36
  export type CollectionConfig = z.infer<typeof collectionConfigParser>;
37
37
  export type ContentConfig = z.infer<typeof contentConfigParser>;
38
38
  type EntryInternal = {
39
- rawData: string;
39
+ rawData: string | undefined;
40
40
  filePath: string;
41
41
  };
42
42
  export type EntryInfo = {
@@ -151,6 +151,8 @@ function hasUnderscoreBelowContentDirectoryPath(fileUrl, contentDir) {
151
151
  return false;
152
152
  }
153
153
  function getFrontmatterErrorLine(rawFrontmatter, frontmatterKey) {
154
+ if (!rawFrontmatter)
155
+ return 0;
154
156
  const indexOfFrontmatterKey = rawFrontmatter.indexOf(`
155
157
  ${frontmatterKey}`);
156
158
  if (indexOfFrontmatterKey === -1)
@@ -1,6 +1,6 @@
1
1
  import type { Plugin } from 'vite';
2
2
  import type { AstroSettings } from '../@types/astro.js';
3
- import { BuildInternals } from '../core/build/internal.js';
3
+ import { type BuildInternals } from '../core/build/internal.js';
4
4
  import type { AstroBuildPlugin } from '../core/build/plugin.js';
5
5
  import type { StaticBuildOptions } from '../core/build/types';
6
6
  export declare function astroContentAssetPropagationPlugin({ mode, settings, }: {
@@ -5,4 +5,4 @@ import type { AstroSettings } from '../@types/astro.js';
5
5
  export declare function astroContentImportPlugin({ fs, settings, }: {
6
6
  fs: typeof fsMod;
7
7
  settings: AstroSettings;
8
- }): Plugin;
8
+ }): Plugin[];