astro 2.1.3 → 2.1.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/@types/typed-emitter.d.ts +1 -2
- package/dist/assets/consts.js +8 -0
- package/dist/assets/image-endpoint.js +1 -1
- package/dist/assets/internal.d.ts +2 -1
- package/dist/assets/internal.js +10 -5
- package/dist/assets/services/service.d.ts +10 -1
- package/dist/assets/services/service.js +35 -29
- package/dist/assets/services/sharp.d.ts +1 -1
- package/dist/assets/services/sharp.js +5 -4
- package/dist/assets/services/squoosh.d.ts +1 -1
- package/dist/assets/services/squoosh.js +7 -4
- package/dist/assets/services/vendor/squoosh/codecs.js +2 -0
- package/dist/assets/services/vendor/squoosh/image-pool.js +2 -0
- package/dist/assets/services/vendor/squoosh/impl.js +2 -0
- package/dist/assets/utils/metadata.js +2 -5
- package/dist/assets/vendor/image-size/detector.d.ts +3 -0
- package/dist/assets/vendor/image-size/detector.js +28 -0
- package/dist/assets/vendor/image-size/index.d.ts +11 -0
- package/dist/assets/vendor/image-size/index.js +93 -0
- package/dist/assets/vendor/image-size/readUInt.d.ts +4 -0
- package/dist/assets/vendor/image-size/readUInt.js +9 -0
- package/dist/assets/vendor/image-size/types/bmp.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/bmp.js +14 -0
- package/dist/assets/vendor/image-size/types/cur.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/cur.js +16 -0
- package/dist/assets/vendor/image-size/types/dds.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/dds.js +14 -0
- package/dist/assets/vendor/image-size/types/gif.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/gif.js +16 -0
- package/dist/assets/vendor/image-size/types/icns.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/icns.js +87 -0
- package/dist/assets/vendor/image-size/types/ico.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/ico.js +42 -0
- package/dist/assets/vendor/image-size/types/interface.d.ts +14 -0
- package/dist/assets/vendor/image-size/types/interface.js +0 -0
- package/dist/assets/vendor/image-size/types/j2c.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/j2c.js +14 -0
- package/dist/assets/vendor/image-size/types/jp2.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/jp2.js +56 -0
- package/dist/assets/vendor/image-size/types/jpg.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/jpg.js +95 -0
- package/dist/assets/vendor/image-size/types/ktx.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/ktx.js +15 -0
- package/dist/assets/vendor/image-size/types/png.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/png.js +33 -0
- package/dist/assets/vendor/image-size/types/pnm.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/pnm.js +72 -0
- package/dist/assets/vendor/image-size/types/psd.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/psd.js +14 -0
- package/dist/assets/vendor/image-size/types/svg.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/svg.js +91 -0
- package/dist/assets/vendor/image-size/types/tiff.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/tiff.js +81 -0
- package/dist/assets/vendor/image-size/types/webp.d.ts +2 -0
- package/dist/assets/vendor/image-size/types/webp.js +51 -0
- package/dist/assets/vendor/image-size/types.d.ts +19 -0
- package/dist/assets/vendor/image-size/types.js +37 -0
- package/dist/assets/vendor/queue/queue.d.ts +39 -0
- package/dist/assets/vendor/queue/queue.js +187 -0
- package/dist/assets/vite-plugin-assets.js +4 -0
- package/dist/cli/check/index.js +43 -2
- package/dist/cli/check/print.d.ts +1 -1
- package/dist/content/error-map.js +4 -1
- package/dist/content/server-listeners.d.ts +1 -1
- package/dist/content/types-generator.d.ts +3 -3
- package/dist/content/types-generator.js +3 -0
- package/dist/content/utils.d.ts +2 -2
- package/dist/content/utils.js +2 -0
- package/dist/content/vite-plugin-content-assets.d.ts +1 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +4 -1
- package/dist/core/add/index.d.ts +1 -1
- package/dist/core/add/index.js +11 -9
- package/dist/core/app/index.js +4 -1
- package/dist/core/app/node.d.ts +1 -1
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +5 -1
- package/dist/core/build/index.js +4 -0
- package/dist/core/build/plugin.js +1 -0
- package/dist/core/build/plugins/plugin-css.d.ts +1 -1
- package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
- package/dist/core/build/static-build.d.ts +1 -1
- package/dist/core/build/static-build.js +4 -1
- package/dist/core/compile/cache.d.ts +1 -1
- package/dist/core/compile/style.d.ts +1 -1
- package/dist/core/config/schema.d.ts +36 -36
- package/dist/core/config/schema.js +9 -1
- package/dist/core/config/timer.js +9 -0
- package/dist/core/config/tsconfig.js +4 -0
- package/dist/core/config/vite-load.js +3 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +35 -1
- package/dist/core/create-vite.js +30 -3
- package/dist/core/dev/container.js +1 -0
- package/dist/core/dev/dev.d.ts +1 -1
- package/dist/core/dev/dev.js +2 -1
- package/dist/core/endpoint/index.d.ts +1 -1
- package/dist/core/endpoint/index.js +1 -0
- package/dist/core/errors/dev/utils.d.ts +1 -1
- package/dist/core/errors/dev/utils.js +2 -1
- package/dist/core/errors/dev/vite.d.ts +1 -1
- package/dist/core/errors/dev/vite.js +1 -0
- package/dist/core/errors/errors-data.js +486 -3
- package/dist/core/errors/errors.js +2 -0
- package/dist/core/errors/overlay.js +16 -5
- package/dist/core/errors/utils.d.ts +1 -1
- package/dist/core/logger/console.js +1 -1
- package/dist/core/logger/node.js +1 -1
- package/dist/core/messages.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/module-loader/loader.d.ts +3 -3
- package/dist/core/render/dev/css.js +2 -1
- package/dist/core/render/dev/environment.js +1 -0
- package/dist/core/render/dev/index.js +1 -0
- package/dist/core/render/dev/resolve.js +1 -6
- package/dist/core/render/dev/vite.js +13 -1
- package/dist/core/render/index.d.ts +1 -1
- package/dist/core/render/result.d.ts +1 -1
- package/dist/core/render/result.js +4 -0
- package/dist/core/render/route-cache.d.ts +1 -1
- package/dist/core/render/route-cache.js +1 -0
- package/dist/core/routing/manifest/create.js +4 -1
- package/dist/core/sync/index.d.ts +1 -1
- package/dist/core/sync/index.js +1 -1
- package/dist/events/error.d.ts +1 -1
- package/dist/integrations/index.d.ts +1 -1
- package/dist/jsx/renderer.js +1 -0
- package/dist/runtime/client/visible.prebuilt.d.ts +1 -1
- package/dist/runtime/client/visible.prebuilt.js +1 -1
- package/dist/runtime/server/hydration.js +1 -0
- package/dist/runtime/server/render/scope.js +5 -0
- package/dist/runtime/server/scripts.js +2 -2
- package/dist/vite-plugin-astro/compile.d.ts +2 -2
- package/dist/vite-plugin-astro/compile.js +1 -0
- package/dist/vite-plugin-astro/index.js +7 -1
- package/dist/vite-plugin-astro-server/base.d.ts +1 -1
- package/dist/vite-plugin-astro-server/common.d.ts +1 -1
- package/dist/vite-plugin-astro-server/response.js +2 -2
- package/dist/vite-plugin-config-alias/index.d.ts +2 -7
- package/dist/vite-plugin-config-alias/index.js +32 -41
- package/dist/vite-plugin-env/index.js +1 -0
- package/dist/vite-plugin-inject-env-ts/index.d.ts +2 -2
- package/dist/vite-plugin-inject-env-ts/index.js +2 -0
- package/dist/vite-plugin-jsx/index.d.ts +1 -1
- package/dist/vite-plugin-jsx/index.js +7 -1
- package/dist/vite-plugin-jsx/tag.js +7 -0
- package/dist/vite-plugin-markdown/index.js +12 -4
- package/dist/vite-plugin-scanner/index.d.ts +1 -1
- package/dist/vite-plugin-scripts/page-ssr.d.ts +1 -1
- package/package.json +5 -6
- package/src/content/template/types.d.ts +12 -1
- package/tsconfigs/base.json +4 -1
|
@@ -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",
|
package/dist/cli/check/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
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: [
|
|
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 ?
|
|
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) {
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -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 = {
|
package/dist/content/utils.js
CHANGED
|
@@ -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, }: {
|
|
@@ -17,7 +17,10 @@ function astroContentVirtualModPlugin({
|
|
|
17
17
|
);
|
|
18
18
|
const contentEntryExts = getContentEntryExts(settings);
|
|
19
19
|
const assetsDir = settings.config.experimental.assets ? contentPaths.assetsDir.toString() : "undefined";
|
|
20
|
-
const extGlob = contentEntryExts.length === 1 ?
|
|
20
|
+
const extGlob = contentEntryExts.length === 1 ? (
|
|
21
|
+
// Wrapping {...} breaks when there is only one extension
|
|
22
|
+
contentEntryExts[0]
|
|
23
|
+
) : `{${contentEntryExts.join(",")}}`;
|
|
21
24
|
const entryGlob = `${relContentDir}**/*${extGlob}`;
|
|
22
25
|
const virtualModContents = fsMod.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("@@ENTRY_GLOB_PATH@@", entryGlob).replace("@@RENDER_ENTRY_GLOB_PATH@@", entryGlob);
|
|
23
26
|
const virtualAssetsModContents = fsMod.readFileSync(contentPaths.virtualAssetsModTemplate, "utf-8").replace("@@ASSETS_DIR@@", assetsDir);
|
package/dist/core/add/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AstroTelemetry } from '@astrojs/telemetry';
|
|
2
2
|
import type yargs from 'yargs-parser';
|
|
3
|
-
import { LogOptions } from '../logger/core.js';
|
|
3
|
+
import { type LogOptions } from '../logger/core.js';
|
|
4
4
|
export interface AddOptions {
|
|
5
5
|
logging: LogOptions;
|
|
6
6
|
flags: yargs.Arguments;
|
package/dist/core/add/index.js
CHANGED
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
};
|
|
47
47
|
`;
|
|
48
48
|
const LIT_NPMRC_STUB = `# Lit libraries are required to be hoisted due to dependency issues.
|
|
49
|
-
public-hoist-pattern[]=*lit*
|
|
49
|
+
public-hoist-pattern[]=*lit*
|
|
50
50
|
`;
|
|
51
51
|
const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
|
|
52
52
|
netlify: "@astrojs/netlify/functions",
|
|
@@ -102,7 +102,7 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
102
102
|
const root = pathToFileURL(cwd ? path.resolve(cwd) : process.cwd());
|
|
103
103
|
root.href = appendForwardSlash(root.href);
|
|
104
104
|
switch (installResult) {
|
|
105
|
-
case
|
|
105
|
+
case 1 /* updated */: {
|
|
106
106
|
if (integrations.find((integration) => integration.id === "tailwind")) {
|
|
107
107
|
await setupIntegrationConfig({
|
|
108
108
|
root,
|
|
@@ -142,7 +142,7 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
142
142
|
}
|
|
143
143
|
break;
|
|
144
144
|
}
|
|
145
|
-
case
|
|
145
|
+
case 2 /* cancelled */: {
|
|
146
146
|
info(
|
|
147
147
|
logging,
|
|
148
148
|
null,
|
|
@@ -153,7 +153,7 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
153
153
|
);
|
|
154
154
|
break;
|
|
155
155
|
}
|
|
156
|
-
case
|
|
156
|
+
case 3 /* failure */: {
|
|
157
157
|
throw createPrettyError(new Error(`Unable to install dependencies`));
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -227,11 +227,11 @@ async function add(names, { cwd, flags, logging, telemetry }) {
|
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
switch (configResult) {
|
|
230
|
-
case
|
|
230
|
+
case 2 /* cancelled */: {
|
|
231
231
|
info(logging, null, msg.cancelled(`Your configuration has ${bold("NOT")} been updated.`));
|
|
232
232
|
break;
|
|
233
233
|
}
|
|
234
|
-
case
|
|
234
|
+
case 0 /* none */: {
|
|
235
235
|
const pkgURL = new URL("./package.json", configURL);
|
|
236
236
|
if (existsSync(fileURLToPath(pkgURL))) {
|
|
237
237
|
const { dependencies = {}, devDependencies = {} } = await fs.readFile(fileURLToPath(pkgURL)).then((res) => JSON.parse(res.toString()));
|
|
@@ -261,10 +261,10 @@ ${list}`
|
|
|
261
261
|
}
|
|
262
262
|
const updateTSConfigResult = await updateTSConfig(cwd, logging, integrations, flags);
|
|
263
263
|
switch (updateTSConfigResult) {
|
|
264
|
-
case
|
|
264
|
+
case 0 /* none */: {
|
|
265
265
|
break;
|
|
266
266
|
}
|
|
267
|
-
case
|
|
267
|
+
case 2 /* cancelled */: {
|
|
268
268
|
info(
|
|
269
269
|
logging,
|
|
270
270
|
null,
|
|
@@ -272,7 +272,7 @@ ${list}`
|
|
|
272
272
|
);
|
|
273
273
|
break;
|
|
274
274
|
}
|
|
275
|
-
case
|
|
275
|
+
case 3 /* failure */: {
|
|
276
276
|
throw new Error(
|
|
277
277
|
`Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.`
|
|
278
278
|
);
|
|
@@ -315,6 +315,7 @@ async function addIntegration(ast, integration) {
|
|
|
315
315
|
)
|
|
316
316
|
);
|
|
317
317
|
visit(ast, {
|
|
318
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
318
319
|
ExportDefaultDeclaration(path2) {
|
|
319
320
|
if (!t.isCallExpression(path2.node.declaration))
|
|
320
321
|
return;
|
|
@@ -359,6 +360,7 @@ async function setAdapter(ast, adapter, exportName) {
|
|
|
359
360
|
t.importDeclaration([t.importDefaultSpecifier(adapterId)], t.stringLiteral(exportName))
|
|
360
361
|
);
|
|
361
362
|
visit(ast, {
|
|
363
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
362
364
|
ExportDefaultDeclaration(path2) {
|
|
363
365
|
if (!t.isCallExpression(path2.node.declaration))
|
|
364
366
|
return;
|
package/dist/core/app/index.js
CHANGED
|
@@ -83,7 +83,10 @@ class App {
|
|
|
83
83
|
return void 0;
|
|
84
84
|
return routeData;
|
|
85
85
|
} else if (matchNotFound) {
|
|
86
|
-
|
|
86
|
+
const notFoundRouteData = matchRoute("/404", this.#manifestData);
|
|
87
|
+
if (notFoundRouteData == null ? void 0 : notFoundRouteData.prerender)
|
|
88
|
+
return void 0;
|
|
89
|
+
return notFoundRouteData;
|
|
87
90
|
} else {
|
|
88
91
|
return void 0;
|
|
89
92
|
}
|
package/dist/core/app/node.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { RouteData } from '../../@types/astro';
|
|
3
3
|
import type { SSRManifest } from './types';
|
|
4
4
|
import type { IncomingMessage } from 'http';
|
|
5
|
-
import { App, MatchOptions } from './index.js';
|
|
5
|
+
import { App, type MatchOptions } from './index.js';
|
|
6
6
|
export declare class NodeApp extends App {
|
|
7
7
|
match(req: IncomingMessage | Request, opts?: MatchOptions): RouteData | undefined;
|
|
8
8
|
render(req: IncomingMessage | Request, routeData?: RouteData): Promise<Response>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OutputAsset, OutputChunk } from 'rollup';
|
|
2
2
|
import type { AstroSettings } from '../../@types/astro';
|
|
3
|
-
import { BuildInternals } from '../../core/build/internal.js';
|
|
3
|
+
import { type BuildInternals } from '../../core/build/internal.js';
|
|
4
4
|
import type { StaticBuildOptions } from './types';
|
|
5
5
|
export declare function rootRelativeFacadeId(facadeId: string, settings: AstroSettings): string;
|
|
6
6
|
export declare function chunkIsPage(settings: AstroSettings, output: OutputAsset | OutputChunk, internals: BuildInternals): boolean;
|
|
@@ -34,7 +34,11 @@ import {
|
|
|
34
34
|
import { getTimeStat } from "./util.js";
|
|
35
35
|
function shouldSkipDraft(pageModule, settings) {
|
|
36
36
|
var _a;
|
|
37
|
-
return
|
|
37
|
+
return (
|
|
38
|
+
// Drafts are disabled
|
|
39
|
+
!settings.config.markdown.drafts && // This is a draft post
|
|
40
|
+
"frontmatter" in pageModule && ((_a = pageModule.frontmatter) == null ? void 0 : _a.draft) === true
|
|
41
|
+
);
|
|
38
42
|
}
|
|
39
43
|
function rootRelativeFacadeId(facadeId, settings) {
|
|
40
44
|
return facadeId.slice(fileURLToPath(settings.config.root).length);
|