@fulgurjs/federation 6.14.4 → 6.14.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.
- package/CHANGELOG.md +5 -0
- package/dist/cli.js +1 -1
- package/dist/dts-cache-worker.cjs +684 -0
- package/dist/index.cjs +364 -133
- package/dist/index.js +363 -133
- package/dist/runtime.js +1 -1
- package/docs/en/reference/api.md +2 -0
- package/docs/zh/reference/api.md +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// src/dts-cache-worker.ts
|
|
26
|
+
var import_node_fs2 = __toESM(require("node:fs"), 1);
|
|
27
|
+
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
28
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
29
|
+
|
|
30
|
+
// src/dts-cache.ts
|
|
31
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
32
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
33
|
+
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
34
|
+
var import_node_module = require("node:module");
|
|
35
|
+
var import_node_url = require("node:url");
|
|
36
|
+
var import_node_zlib = require("node:zlib");
|
|
37
|
+
|
|
38
|
+
// src/dts-shared.ts
|
|
39
|
+
var TYPES_SCHEMA_VERSION = 1;
|
|
40
|
+
var isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
41
|
+
function isSafeBundlePath(v) {
|
|
42
|
+
if (typeof v !== "string" || v.length === 0) return false;
|
|
43
|
+
if (v.startsWith("/") || v.startsWith("\\")) return false;
|
|
44
|
+
if (v.includes("\\")) return false;
|
|
45
|
+
if (v.split("/").includes("..")) return false;
|
|
46
|
+
if (/[\s\u0000-\u001f]/.test(v)) return false;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
function parseDtsIndex(input) {
|
|
50
|
+
const issues = [];
|
|
51
|
+
if (!isPlainObject(input)) {
|
|
52
|
+
return { issues: [{ field: "$", message: "\u7C7B\u578B\u6E05\u5355\u5FC5\u987B\u662F JSON \u5BF9\u8C61", got: typeof input }] };
|
|
53
|
+
}
|
|
54
|
+
const raw = input;
|
|
55
|
+
if (raw.schemaVersion !== TYPES_SCHEMA_VERSION) {
|
|
56
|
+
return {
|
|
57
|
+
issues: [{
|
|
58
|
+
field: "schemaVersion",
|
|
59
|
+
message: `\u4E0D\u652F\u6301\u7684\u7C7B\u578B\u534F\u8BAE\u7248\u672C\uFF08\u5F53\u524D\u6D88\u8D39\u7AEF\u652F\u6301 ${TYPES_SCHEMA_VERSION}\uFF09`,
|
|
60
|
+
got: raw.schemaVersion
|
|
61
|
+
}],
|
|
62
|
+
unsupportedVersion: typeof raw.schemaVersion === "number" ? raw.schemaVersion : void 0
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (typeof raw.revision !== "string" || !/^[0-9a-f]{8,64}$/.test(raw.revision)) {
|
|
66
|
+
issues.push({ field: "revision", message: "\u5FC5\u987B\u662F 8-64 \u4F4D\u5341\u516D\u8FDB\u5236\u5185\u5BB9\u6458\u8981", got: raw.revision });
|
|
67
|
+
}
|
|
68
|
+
if (!isPlainObject(raw.exposes) || Object.keys(raw.exposes).length === 0) {
|
|
69
|
+
issues.push({ field: "exposes", message: "\u5FC5\u987B\u662F\u975E\u7A7A\u5BF9\u8C61\uFF08\u66B4\u9732\u5165\u53E3 \u2192 \u58F0\u660E\u6587\u4EF6\u6620\u5C04\uFF09", got: typeof raw.exposes });
|
|
70
|
+
} else {
|
|
71
|
+
for (const [name, v] of Object.entries(raw.exposes)) {
|
|
72
|
+
if (!/^\.[\w./-]+$/.test(name)) {
|
|
73
|
+
issues.push({ field: `exposes["${name}"]`, message: '\u952E\u5FC5\u987B\u662F "./xxx" \u5F62\u6001\u7684 expose \u540D' });
|
|
74
|
+
}
|
|
75
|
+
if (!isPlainObject(v) || !isSafeBundlePath(v.declaration)) {
|
|
76
|
+
issues.push({ field: `exposes["${name}"].declaration`, message: "\u5FC5\u987B\u662F bundle \u5185\u5B89\u5168\u76F8\u5BF9\u8DEF\u5F84", got: v });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!isPlainObject(raw.files) || Object.keys(raw.files).length === 0) {
|
|
81
|
+
issues.push({ field: "files", message: "\u5FC5\u987B\u662F\u975E\u7A7A\u5BF9\u8C61\uFF08\u6587\u4EF6 \u2192 sha256\uFF09", got: typeof raw.files });
|
|
82
|
+
} else {
|
|
83
|
+
for (const [file, digest] of Object.entries(raw.files)) {
|
|
84
|
+
if (!isSafeBundlePath(file)) {
|
|
85
|
+
issues.push({ field: `files["${file}"]`, message: "\u4E0D\u5B89\u5168\u7684 bundle \u6587\u4EF6\u8DEF\u5F84\uFF08\u62D2\u7EDD\u8D8A\u754C\uFF09" });
|
|
86
|
+
}
|
|
87
|
+
if (typeof digest !== "string" || !/^[0-9a-f]{64}$/.test(digest)) {
|
|
88
|
+
issues.push({ field: `files["${file}"]`, message: "\u5FC5\u987B\u662F sha256 \u5341\u516D\u8FDB\u5236\u6458\u8981", got: digest });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (isPlainObject(raw.exposes)) {
|
|
92
|
+
for (const [name, v] of Object.entries(raw.exposes)) {
|
|
93
|
+
if (isPlainObject(v) && typeof v.declaration === "string" && !Object.hasOwn(raw.files, v.declaration)) {
|
|
94
|
+
issues.push({ field: `exposes["${name}"].declaration`, message: `\u58F0\u660E\u6587\u4EF6\u672A\u5728 files \u4E2D\u767B\u8BB0\uFF08${v.declaration}\uFF09` });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (raw.externals !== void 0) {
|
|
100
|
+
if (!Array.isArray(raw.externals) || raw.externals.some((e) => typeof e !== "string")) {
|
|
101
|
+
issues.push({ field: "externals", message: "\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4\uFF08\u5916\u90E8\u7C7B\u578B\u4F9D\u8D56\u5305\u540D\uFF09", got: typeof raw.externals });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (issues.length > 0) return { issues };
|
|
105
|
+
return {
|
|
106
|
+
index: {
|
|
107
|
+
schemaVersion: TYPES_SCHEMA_VERSION,
|
|
108
|
+
generator: typeof raw.generator === "string" ? raw.generator : "@fulgurjs/federation",
|
|
109
|
+
pluginVersion: typeof raw.pluginVersion === "string" ? raw.pluginVersion : "",
|
|
110
|
+
revision: raw.revision,
|
|
111
|
+
exposes: raw.exposes,
|
|
112
|
+
externals: Array.isArray(raw.externals) ? raw.externals : [],
|
|
113
|
+
files: raw.files
|
|
114
|
+
},
|
|
115
|
+
issues
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
var DTS_FILE_MAX_BYTES = 5 * 1024 * 1024;
|
|
119
|
+
var DTS_TOTAL_MAX_BYTES = 64 * 1024 * 1024;
|
|
120
|
+
var DTS_FILE_COUNT_MAX = 4e3;
|
|
121
|
+
|
|
122
|
+
// src/dts-cache.ts
|
|
123
|
+
var import_meta = {};
|
|
124
|
+
var CACHE_FORMAT = 1;
|
|
125
|
+
var PROCESS_START = Date.now() - process.uptime() * 1e3;
|
|
126
|
+
var MAX_CACHE_BYTES = DTS_TOTAL_MAX_BYTES * 2;
|
|
127
|
+
var hash = (value) => import_node_crypto.default.createHash("sha256").update(value).digest("hex");
|
|
128
|
+
var sorted = (values) => [...values].sort();
|
|
129
|
+
var temporary = (file) => import_node_path.default.basename(file).startsWith(".fulgurjs-types-tsconfig-");
|
|
130
|
+
var stamp = (file) => {
|
|
131
|
+
const data = import_node_fs.default.readFileSync(file);
|
|
132
|
+
const stat = import_node_fs.default.statSync(file);
|
|
133
|
+
return { hash: hash(data), size: stat.size, mtime: stat.mtimeMs, ctime: stat.ctimeMs, ino: stat.ino };
|
|
134
|
+
};
|
|
135
|
+
var resolve = (from, request) => {
|
|
136
|
+
try {
|
|
137
|
+
return (0, import_node_module.createRequire)(from).resolve(request);
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
function linkIdentity(file) {
|
|
143
|
+
try {
|
|
144
|
+
return import_node_fs.default.realpathSync(file);
|
|
145
|
+
} catch {
|
|
146
|
+
return `!missing:${import_node_fs.default.readlinkSync(file)}`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function ownModule() {
|
|
150
|
+
return typeof __filename === "string" ? __filename : (0, import_node_url.fileURLToPath)(import_meta.url);
|
|
151
|
+
}
|
|
152
|
+
function settings(input) {
|
|
153
|
+
const env = Object.fromEntries(Object.entries(input.execution?.env ?? process.env).filter(([name]) => /^(NODE_ENV|NODE_OPTIONS|TS_NODE_|VUE_|VOLAR_)/.test(name)).sort(([a], [b]) => a < b ? -1 : 1));
|
|
154
|
+
return hash(JSON.stringify({
|
|
155
|
+
format: CACHE_FORMAT,
|
|
156
|
+
root: import_node_path.default.resolve(input.root),
|
|
157
|
+
exposes: input.exposes,
|
|
158
|
+
pluginVersion: input.pluginVersion,
|
|
159
|
+
ownModule: ownModule(),
|
|
160
|
+
dts: input.dts,
|
|
161
|
+
node: process.version,
|
|
162
|
+
platform: process.platform,
|
|
163
|
+
arch: process.arch,
|
|
164
|
+
execArgv: input.execution?.execArgv ?? process.execArgv,
|
|
165
|
+
env
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
function typesCachePath(root) {
|
|
169
|
+
return import_node_path.default.join(root, "node_modules/.cache/fulgurjs/types", `provider-${hash(import_node_path.default.resolve(root)).slice(0, 12)}.json.gz`);
|
|
170
|
+
}
|
|
171
|
+
function captureTypesInputs(input) {
|
|
172
|
+
const root = import_node_path.default.resolve(input.root);
|
|
173
|
+
const from = import_node_path.default.join(root, "package.json");
|
|
174
|
+
const tsFile = resolve(from, "typescript");
|
|
175
|
+
if (!tsFile) return null;
|
|
176
|
+
let ts;
|
|
177
|
+
try {
|
|
178
|
+
ts = (0, import_node_module.createRequire)(from)("typescript");
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
const snapshot = { caseSensitive: ts.sys.useCaseSensitiveFileNames, directoryStats: {}, files: {}, probes: {}, fileQueries: {}, directories: [], links: {}, resolutions: [], runtimeTools: [] };
|
|
183
|
+
const queues = [];
|
|
184
|
+
const visited = /* @__PURE__ */ new Set();
|
|
185
|
+
const toolPackages = /* @__PURE__ */ new Set();
|
|
186
|
+
const toolRuntime = /* @__PURE__ */ new Set();
|
|
187
|
+
let unsupported = false;
|
|
188
|
+
const observeDirectory = (dir) => {
|
|
189
|
+
const absolute = import_node_path.default.resolve(dir);
|
|
190
|
+
if (Object.hasOwn(snapshot.directoryStats, absolute)) return;
|
|
191
|
+
try {
|
|
192
|
+
const stat = import_node_fs.default.statSync(absolute);
|
|
193
|
+
if (stat.isDirectory()) snapshot.directoryStats[absolute] = { mtime: stat.mtimeMs, ctime: stat.ctimeMs, ino: stat.ino };
|
|
194
|
+
} catch {
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const entriesCache = /* @__PURE__ */ new Map();
|
|
198
|
+
const sourceCache = /* @__PURE__ */ new Map();
|
|
199
|
+
const entries2 = (dir) => {
|
|
200
|
+
const cached = entriesCache.get(dir);
|
|
201
|
+
if (cached) return cached;
|
|
202
|
+
let rows = [];
|
|
203
|
+
observeDirectory(dir);
|
|
204
|
+
observeDirectory(import_node_path.default.dirname(dir));
|
|
205
|
+
try {
|
|
206
|
+
rows = import_node_fs.default.readdirSync(dir, { withFileTypes: true });
|
|
207
|
+
snapshot.links[dir] = import_node_fs.default.realpathSync(dir);
|
|
208
|
+
} catch (e) {
|
|
209
|
+
if (!["ENOENT", "ENOTDIR"].includes(e.code ?? "")) throw e;
|
|
210
|
+
}
|
|
211
|
+
const result = new Map(rows.flatMap((row) => [[`e:${row.name}`, row], [`f:${row.name.toLowerCase()}`, row]]));
|
|
212
|
+
entriesCache.set(dir, result);
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
const fileExists = (file) => {
|
|
216
|
+
const absolute = import_node_path.default.resolve(file);
|
|
217
|
+
const dir = import_node_path.default.dirname(absolute);
|
|
218
|
+
const name = import_node_path.default.basename(absolute);
|
|
219
|
+
const query = snapshot.fileQueries[dir] ??= /* @__PURE__ */ Object.create(null);
|
|
220
|
+
if (Object.hasOwn(query, name)) return query[name];
|
|
221
|
+
const table = entries2(dir);
|
|
222
|
+
const entry = table.get(`e:${name}`) ?? (!snapshot.caseSensitive ? table.get(`f:${name.toLowerCase()}`) : void 0);
|
|
223
|
+
let exists = entry?.isFile() ?? false;
|
|
224
|
+
if (entry && entry.name !== name) {
|
|
225
|
+
try {
|
|
226
|
+
exists = import_node_fs.default.statSync(absolute).isFile();
|
|
227
|
+
} catch {
|
|
228
|
+
exists = false;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (entry?.isSymbolicLink() && (exists || import_node_fs.default.existsSync(absolute))) {
|
|
232
|
+
snapshot.links[absolute] = linkIdentity(absolute);
|
|
233
|
+
try {
|
|
234
|
+
exists = import_node_fs.default.statSync(absolute).isFile();
|
|
235
|
+
} catch {
|
|
236
|
+
exists = false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
query[name] = exists;
|
|
240
|
+
return exists;
|
|
241
|
+
};
|
|
242
|
+
const directoryExists = (dir) => {
|
|
243
|
+
const absolute = import_node_path.default.resolve(dir);
|
|
244
|
+
const key = `d:${absolute}`;
|
|
245
|
+
if (Object.hasOwn(snapshot.probes, key)) return snapshot.probes[key];
|
|
246
|
+
observeDirectory(absolute);
|
|
247
|
+
observeDirectory(import_node_path.default.dirname(absolute));
|
|
248
|
+
const exists = ts.sys.directoryExists?.(absolute) ?? false;
|
|
249
|
+
snapshot.probes[key] = exists;
|
|
250
|
+
return exists;
|
|
251
|
+
};
|
|
252
|
+
const read = (file) => {
|
|
253
|
+
const absolute = import_node_path.default.resolve(file);
|
|
254
|
+
if (sourceCache.has(absolute)) return sourceCache.get(absolute);
|
|
255
|
+
if (!fileExists(absolute)) return void 0;
|
|
256
|
+
const before = import_node_fs.default.statSync(absolute);
|
|
257
|
+
const data = import_node_fs.default.readFileSync(absolute);
|
|
258
|
+
const after = import_node_fs.default.statSync(absolute);
|
|
259
|
+
if (before.ctimeMs !== after.ctimeMs || before.mtimeMs !== after.mtimeMs || before.size !== after.size || before.ino !== after.ino) throw new Error("\u8F93\u5165\u5728\u8BFB\u53D6\u8FC7\u7A0B\u4E2D\u53D8\u5316");
|
|
260
|
+
const real = import_node_fs.default.realpathSync(absolute);
|
|
261
|
+
snapshot.links[absolute] = real;
|
|
262
|
+
snapshot.files[absolute] = { hash: hash(data), size: after.size, mtime: after.mtimeMs, ctime: after.ctimeMs, ino: after.ino };
|
|
263
|
+
const text = data.toString("utf8");
|
|
264
|
+
sourceCache.set(absolute, text);
|
|
265
|
+
return text;
|
|
266
|
+
};
|
|
267
|
+
const requirePath = (file, request) => {
|
|
268
|
+
const resolved = resolve(file, request);
|
|
269
|
+
snapshot.resolutions.push({ from: file, request, resolved });
|
|
270
|
+
if (request.startsWith(".") || import_node_path.default.isAbsolute(request)) {
|
|
271
|
+
const base = import_node_path.default.resolve(import_node_path.default.dirname(file), request);
|
|
272
|
+
for (const candidate of [base, `${base}.js`, `${base}.json`, `${base}.node`, import_node_path.default.join(base, "package.json"), import_node_path.default.join(base, "index.js")]) fileExists(candidate);
|
|
273
|
+
} else if (resolved && import_node_path.default.isAbsolute(resolved)) {
|
|
274
|
+
const packageName = request.startsWith("@") ? request.split("/").slice(0, 2).join("/") : request.split("/")[0];
|
|
275
|
+
for (const directory of (0, import_node_module.createRequire)(file).resolve.paths(request) ?? []) {
|
|
276
|
+
const candidate = import_node_path.default.join(directory, packageName);
|
|
277
|
+
if (!directoryExists(candidate)) continue;
|
|
278
|
+
const actual = import_node_fs.default.realpathSync(candidate);
|
|
279
|
+
snapshot.links[candidate] = actual;
|
|
280
|
+
if (!(resolved === actual || resolved.startsWith(`${actual}${import_node_path.default.sep}`))) unsupported = true;
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return resolved;
|
|
285
|
+
};
|
|
286
|
+
const host = {
|
|
287
|
+
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
288
|
+
readFile: read,
|
|
289
|
+
fileExists: (file) => fileExists(file) || file.endsWith(".vue.ts") && fileExists(file.slice(0, -3)),
|
|
290
|
+
directoryExists,
|
|
291
|
+
realpath: (file) => {
|
|
292
|
+
const resolved = ts.sys.realpath?.(file) ?? file;
|
|
293
|
+
try {
|
|
294
|
+
snapshot.links[file] = import_node_fs.default.realpathSync(file);
|
|
295
|
+
} catch {
|
|
296
|
+
}
|
|
297
|
+
return resolved;
|
|
298
|
+
},
|
|
299
|
+
readDirectory: (dir, extensions, excludes, includes, depth) => {
|
|
300
|
+
observeDirectory(dir);
|
|
301
|
+
const result = sorted(ts.sys.readDirectory(dir, extensions, excludes, includes, depth).filter((file) => !temporary(file)));
|
|
302
|
+
snapshot.directories.push({ kind: "files", root: dir, extensions, excludes, includes, depth, result });
|
|
303
|
+
return result;
|
|
304
|
+
},
|
|
305
|
+
getDirectories: (dir) => {
|
|
306
|
+
observeDirectory(dir);
|
|
307
|
+
const result = sorted(ts.sys.getDirectories(dir));
|
|
308
|
+
snapshot.directories.push({ kind: "dirs", root: dir, result });
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
const add = (file) => {
|
|
313
|
+
if (fileExists(file) && !temporary(file)) queues.push(import_node_path.default.resolve(file));
|
|
314
|
+
};
|
|
315
|
+
const packageRoot = (file) => {
|
|
316
|
+
for (let dir = import_node_path.default.dirname(file); ; dir = import_node_path.default.dirname(dir)) {
|
|
317
|
+
if (fileExists(import_node_path.default.join(dir, "package.json"))) return dir;
|
|
318
|
+
if (import_node_path.default.dirname(dir) === dir) return null;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
const walkCode = (dir, recurse, tools, inspect) => {
|
|
322
|
+
observeDirectory(dir);
|
|
323
|
+
const entries3 = import_node_fs.default.readdirSync(dir, { withFileTypes: true }).filter((e) => !["node_modules", ".git", ".svn", ".cache"].includes(e.name) && (e.isDirectory() ? recurse : /\.(?:[cm]?js|[cm]?tsx?|json|vue|node|wasm)$/.test(e.name)));
|
|
324
|
+
snapshot.directories.push({ kind: "entries", root: dir, recurse, result: sorted(entries3.map((e) => e.name)) });
|
|
325
|
+
for (const entry of entries3) {
|
|
326
|
+
const file = import_node_path.default.join(dir, entry.name);
|
|
327
|
+
if (entry.isDirectory()) {
|
|
328
|
+
if (recurse) walkCode(file, true, tools, inspect);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (!/\.(?:[cm]?js|[cm]?tsx?|json|vue|node|wasm)$/.test(entry.name)) continue;
|
|
332
|
+
const text = read(file);
|
|
333
|
+
if (tools && !/\.d\.[cm]?ts$/.test(entry.name)) toolRuntime.add(file);
|
|
334
|
+
if (text !== void 0 && /\.[cm]?js$/.test(file)) inspect?.(file, text);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const tool = (file) => {
|
|
338
|
+
if (!import_node_path.default.isAbsolute(file)) return;
|
|
339
|
+
const directory = packageRoot(file);
|
|
340
|
+
if (!directory || toolPackages.has(directory)) return;
|
|
341
|
+
toolPackages.add(directory);
|
|
342
|
+
walkCode(directory, true, true, (source, text) => {
|
|
343
|
+
for (const imported of ts.preProcessFile(text, true, true).importedFiles) {
|
|
344
|
+
const dependency = requirePath(source, imported.fileName);
|
|
345
|
+
if (dependency) tool(dependency);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
const json = JSON.parse(read(import_node_path.default.join(directory, "package.json")) ?? "{}");
|
|
349
|
+
for (const name of Object.keys({ ...json.dependencies, ...json.peerDependencies })) {
|
|
350
|
+
const dependency = requirePath(import_node_path.default.join(directory, "package.json"), `${name}/package.json`) ?? requirePath(import_node_path.default.join(directory, "package.json"), name);
|
|
351
|
+
if (dependency) tool(dependency);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
try {
|
|
355
|
+
requirePath(from, "typescript");
|
|
356
|
+
tool(tsFile);
|
|
357
|
+
for (const request of ["typescript/lib/tsc.js", "vue-tsc/package.json", "vue/compiler-sfc"]) {
|
|
358
|
+
const file = requirePath(from, request);
|
|
359
|
+
if (file) tool(file);
|
|
360
|
+
}
|
|
361
|
+
const ownFile = ownModule();
|
|
362
|
+
const ownDirectory = import_node_path.default.dirname(ownFile);
|
|
363
|
+
walkCode(ownDirectory, ownFile.endsWith(".ts"), true);
|
|
364
|
+
for (let dir = root; ; dir = import_node_path.default.dirname(dir)) {
|
|
365
|
+
for (const name of ["package.json", "package-lock.json", "pnpm-lock.yaml", "pnpm-workspace.yaml", "yarn.lock", "bun.lock", "bun.lockb"]) read(import_node_path.default.join(dir, name));
|
|
366
|
+
if (import_node_path.default.dirname(dir) === dir) break;
|
|
367
|
+
}
|
|
368
|
+
const config = ts.findConfigFile(root, fileExists, "tsconfig.json");
|
|
369
|
+
let options = {
|
|
370
|
+
target: ts.ScriptTarget.ES2022,
|
|
371
|
+
module: ts.ModuleKind.ESNext,
|
|
372
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler ?? ts.ModuleResolutionKind.NodeJs,
|
|
373
|
+
allowJs: true,
|
|
374
|
+
skipLibCheck: true
|
|
375
|
+
};
|
|
376
|
+
if (config) {
|
|
377
|
+
const raw = ts.readConfigFile(config, read);
|
|
378
|
+
if (raw.error) return null;
|
|
379
|
+
const parsed = ts.parseJsonConfigFileContent(
|
|
380
|
+
raw.config,
|
|
381
|
+
host,
|
|
382
|
+
import_node_path.default.dirname(config),
|
|
383
|
+
void 0,
|
|
384
|
+
void 0,
|
|
385
|
+
void 0,
|
|
386
|
+
[{ extension: ".vue", isMixedContent: true, scriptKind: ts.ScriptKind.Deferred }]
|
|
387
|
+
);
|
|
388
|
+
if (parsed.errors.some((d) => d.category === ts.DiagnosticCategory.Error)) return null;
|
|
389
|
+
options = parsed.options;
|
|
390
|
+
for (const file of parsed.fileNames) add(file);
|
|
391
|
+
}
|
|
392
|
+
const resolutionCache = ts.createModuleResolutionCache(root, (file) => ts.sys.useCaseSensitiveFileNames ? file : file.toLowerCase(), options);
|
|
393
|
+
const module2 = (name, containing) => {
|
|
394
|
+
for (const mode of [ts.ModuleKind.ESNext, ts.ModuleKind.CommonJS]) {
|
|
395
|
+
const result = ts.resolveModuleName(name, containing, options, host, resolutionCache, void 0, mode).resolvedModule;
|
|
396
|
+
if (result) {
|
|
397
|
+
let file = result.resolvedFileName;
|
|
398
|
+
if (file.endsWith(".vue.ts") && fileExists(file.slice(0, -3))) file = file.slice(0, -3);
|
|
399
|
+
add(file);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
const bases = [];
|
|
403
|
+
if (name.startsWith(".")) bases.push(import_node_path.default.resolve(import_node_path.default.dirname(containing), name));
|
|
404
|
+
const base = options.baseUrl ?? (typeof options.pathsBasePath === "string" ? options.pathsBasePath : root);
|
|
405
|
+
for (const [pattern, targets] of Object.entries(options.paths ?? {})) {
|
|
406
|
+
const star = pattern.indexOf("*");
|
|
407
|
+
const match = star < 0 ? name === pattern : name.startsWith(pattern.slice(0, star)) && name.endsWith(pattern.slice(star + 1));
|
|
408
|
+
if (match) for (const target of targets) bases.push(import_node_path.default.resolve(base, target.replace("*", star < 0 ? "" : name.slice(star, name.length - (pattern.length - star - 1)))));
|
|
409
|
+
}
|
|
410
|
+
if (import_node_path.default.isAbsolute(name)) bases.push(name);
|
|
411
|
+
if (options.baseUrl) bases.push(import_node_path.default.resolve(options.baseUrl, name));
|
|
412
|
+
for (const target of bases) for (const candidate of [target, `${target}.vue`, `${target}.ts`, `${target}.tsx`, import_node_path.default.join(target, "index.vue"), import_node_path.default.join(target, "index.ts")]) add(candidate);
|
|
413
|
+
};
|
|
414
|
+
const typeReference = (name, containing) => {
|
|
415
|
+
for (const mode of [ts.ModuleKind.ESNext, ts.ModuleKind.CommonJS]) {
|
|
416
|
+
const resolved = ts.resolveTypeReferenceDirective(name, containing, options, host, void 0, void 0, mode).resolvedTypeReferenceDirective;
|
|
417
|
+
if (resolved?.resolvedFileName) add(resolved.resolvedFileName);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
for (const entry of input.exposes) {
|
|
421
|
+
const file = import_node_path.default.resolve(root, entry.import.replace(/^\.?\//, ""));
|
|
422
|
+
if (fileExists(file)) add(file);
|
|
423
|
+
else module2(entry.import, from);
|
|
424
|
+
}
|
|
425
|
+
for (const name of ts.getAutomaticTypeDirectiveNames(options, host)) typeReference(name, config ?? from);
|
|
426
|
+
if (options.lib) for (const lib of options.lib) add(import_node_path.default.join(import_node_path.default.dirname(ts.getDefaultLibFilePath(options)), lib));
|
|
427
|
+
else if (!options.noLib) add(ts.getDefaultLibFilePath(options));
|
|
428
|
+
while (queues.length) {
|
|
429
|
+
const file = queues.pop();
|
|
430
|
+
if (visited.has(file)) continue;
|
|
431
|
+
visited.add(file);
|
|
432
|
+
let text = read(file);
|
|
433
|
+
if (text === void 0) continue;
|
|
434
|
+
if (file.endsWith(".vue")) {
|
|
435
|
+
const parser = (0, import_node_module.createRequire)(from)("vue/compiler-sfc");
|
|
436
|
+
const { descriptor } = parser.parse(text);
|
|
437
|
+
if (descriptor.template?.src || descriptor.template?.lang && descriptor.template.lang !== "html" || descriptor.styles.some((s) => s.module && s.src)) unsupported = true;
|
|
438
|
+
for (const script of [descriptor.script, descriptor.scriptSetup]) if (script?.src) module2(script.src, file);
|
|
439
|
+
text = [descriptor.script?.content, descriptor.scriptSetup?.content].filter(Boolean).join("\n");
|
|
440
|
+
}
|
|
441
|
+
if (!/\.(?:[cm]?[jt]sx?|vue)$/.test(file)) continue;
|
|
442
|
+
const info = ts.preProcessFile(text, true, true);
|
|
443
|
+
for (const imported of info.importedFiles) module2(imported.fileName, file);
|
|
444
|
+
if (text.includes("/**") && text.includes("import")) {
|
|
445
|
+
const source = ts.createSourceFile(
|
|
446
|
+
file,
|
|
447
|
+
text,
|
|
448
|
+
ts.ScriptTarget.Latest,
|
|
449
|
+
true,
|
|
450
|
+
/\.[jt]sx$/.test(file) ? ts.ScriptKind.TSX : /\.[cm]?js$/.test(file) ? ts.ScriptKind.JS : ts.ScriptKind.TS
|
|
451
|
+
);
|
|
452
|
+
const visit = (node) => {
|
|
453
|
+
if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) module2(node.argument.literal.text, file);
|
|
454
|
+
if (node.kind === ts.SyntaxKind.JSDocImportTag) {
|
|
455
|
+
const specifier = node.moduleSpecifier;
|
|
456
|
+
if (ts.isStringLiteral(specifier)) module2(specifier.text, file);
|
|
457
|
+
}
|
|
458
|
+
ts.forEachChild(node, visit);
|
|
459
|
+
for (const doc of node.jsDoc ?? []) visit(doc);
|
|
460
|
+
};
|
|
461
|
+
visit(source);
|
|
462
|
+
}
|
|
463
|
+
for (const ref of info.referencedFiles) add(import_node_path.default.resolve(import_node_path.default.dirname(file), ref.fileName));
|
|
464
|
+
for (const ref of info.typeReferenceDirectives) typeReference(ref.fileName, file);
|
|
465
|
+
for (const ref of info.libReferenceDirectives ?? []) {
|
|
466
|
+
add(import_node_path.default.join(import_node_path.default.dirname(ts.getDefaultLibFilePath(options)), `lib.${ref.fileName.toLowerCase()}.d.ts`));
|
|
467
|
+
module2(`@typescript/lib-${ref.fileName.toLowerCase().replace(".", "/")}`, from);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
for (const file of Object.keys(snapshot.files)) if (file.endsWith(".json")) {
|
|
471
|
+
const configText = ts.parseConfigFileTextToJson(file, import_node_fs.default.readFileSync(file, "utf8")).config;
|
|
472
|
+
if (configText?.vueCompilerOptions?.plugins?.length || configText?.vueCompilerOptions?.hooks?.length) unsupported = true;
|
|
473
|
+
}
|
|
474
|
+
snapshot.runtimeTools = [...toolRuntime];
|
|
475
|
+
return unsupported ? null : snapshot;
|
|
476
|
+
} catch {
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function validateTypesInputs(snapshot, root, stable = false) {
|
|
481
|
+
try {
|
|
482
|
+
const checked = /* @__PURE__ */ new Map();
|
|
483
|
+
const checkedDirectories = /* @__PURE__ */ new Map();
|
|
484
|
+
for (const dir of Object.keys(snapshot.directoryStats ?? {})) {
|
|
485
|
+
const stat = import_node_fs.default.statSync(dir);
|
|
486
|
+
const now = { mtime: stat.mtimeMs, ctime: stat.ctimeMs, ino: stat.ino };
|
|
487
|
+
checkedDirectories.set(dir, now);
|
|
488
|
+
}
|
|
489
|
+
for (const [file, before] of Object.entries(snapshot.files)) {
|
|
490
|
+
const prior = import_node_fs.default.statSync(file);
|
|
491
|
+
const now = stamp(file);
|
|
492
|
+
if (prior.ctimeMs !== now.ctime || prior.mtimeMs !== now.mtime || prior.ino !== now.ino || prior.size !== now.size || now.hash !== before.hash || stable && (now.ctime !== before.ctime || now.mtime !== before.mtime || now.ino !== before.ino)) return `\u8F93\u5165\u6587\u4EF6\u53D8\u5316\uFF1A${import_node_path.default.relative(root, file)}`;
|
|
493
|
+
checked.set(file, now);
|
|
494
|
+
}
|
|
495
|
+
for (const [probe, expected] of Object.entries(snapshot.probes)) {
|
|
496
|
+
const file = probe.slice(2);
|
|
497
|
+
let found = false;
|
|
498
|
+
try {
|
|
499
|
+
const stat = import_node_fs.default.statSync(file);
|
|
500
|
+
found = probe.startsWith("f:") ? stat.isFile() : stat.isDirectory();
|
|
501
|
+
} catch {
|
|
502
|
+
}
|
|
503
|
+
if (found !== expected) return `\u8F93\u5165\u6210\u5458\u53D8\u5316\uFF1A${import_node_path.default.relative(root, file)}`;
|
|
504
|
+
}
|
|
505
|
+
for (const [dir, queries] of Object.entries(snapshot.fileQueries)) {
|
|
506
|
+
let rows = [];
|
|
507
|
+
try {
|
|
508
|
+
rows = import_node_fs.default.readdirSync(dir, { withFileTypes: true });
|
|
509
|
+
} catch (e) {
|
|
510
|
+
if (!["ENOENT", "ENOTDIR"].includes(e.code ?? "")) return "\u8F93\u5165\u76EE\u5F55\u4E0D\u53EF\u8BFB\u53D6";
|
|
511
|
+
}
|
|
512
|
+
const entries2 = new Map(rows.flatMap((row) => [[`e:${row.name}`, row], [`f:${row.name.toLowerCase()}`, row]]));
|
|
513
|
+
for (const [name, expected] of Object.entries(queries)) {
|
|
514
|
+
const row = entries2.get(`e:${name}`) ?? (!snapshot.caseSensitive ? entries2.get(`f:${name.toLowerCase()}`) : void 0);
|
|
515
|
+
let actual = row?.isFile() ?? false;
|
|
516
|
+
if (row && row.name !== name) {
|
|
517
|
+
try {
|
|
518
|
+
actual = import_node_fs.default.statSync(import_node_path.default.join(dir, name)).isFile();
|
|
519
|
+
} catch {
|
|
520
|
+
actual = false;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
if (row?.isSymbolicLink()) {
|
|
524
|
+
try {
|
|
525
|
+
actual = import_node_fs.default.statSync(import_node_path.default.join(dir, name)).isFile();
|
|
526
|
+
} catch {
|
|
527
|
+
actual = false;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (actual !== expected) return `\u4F9D\u8D56\u89E3\u6790\u5019\u9009\u53D8\u5316\uFF1A${import_node_path.default.relative(root, import_node_path.default.join(dir, name))}`;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
for (const [file, expected] of Object.entries(snapshot.links)) if (linkIdentity(file) !== expected) return "\u4F9D\u8D56\u94FE\u63A5\u76EE\u6807\u53D8\u5316";
|
|
534
|
+
for (const query of snapshot.resolutions) if (resolve(query.from, query.request) !== query.resolved) return "\u5DE5\u5177\u4F9D\u8D56\u89E3\u6790\u53D8\u5316";
|
|
535
|
+
const tsPath = resolve(import_node_path.default.join(root, "package.json"), "typescript");
|
|
536
|
+
if (!tsPath) return "TypeScript\u5DE5\u5177\u4E0D\u53EF\u7528";
|
|
537
|
+
const ts = (0, import_node_module.createRequire)(import_node_path.default.join(root, "package.json"))("typescript");
|
|
538
|
+
for (const query of snapshot.directories) {
|
|
539
|
+
const result = query.kind === "files" ? ts.sys.readDirectory(query.root, query.extensions, query.excludes, query.includes, query.depth).filter((file) => !temporary(file)) : query.kind === "dirs" ? ts.sys.getDirectories(query.root) : import_node_fs.default.readdirSync(query.root, { withFileTypes: true }).filter((entry) => !["node_modules", ".git", ".svn", ".cache"].includes(entry.name) && (entry.isDirectory() ? query.recurse : /\.(?:[cm]?js|[cm]?tsx?|json|vue|node|wasm)$/.test(entry.name))).map((entry) => entry.name);
|
|
540
|
+
if (JSON.stringify(sorted(result)) !== JSON.stringify(query.result)) return `\u8F93\u5165\u76EE\u5F55\u6210\u5458\u53D8\u5316\uFF1A${import_node_path.default.relative(root, query.root)}`;
|
|
541
|
+
}
|
|
542
|
+
for (const [dir, before] of checkedDirectories) {
|
|
543
|
+
const stat = import_node_fs.default.statSync(dir);
|
|
544
|
+
if (stat.mtimeMs !== before.mtime || stat.ctimeMs !== before.ctime || stat.ino !== before.ino) {
|
|
545
|
+
for (const [name, expected] of Object.entries(snapshot.fileQueries[dir] ?? {})) {
|
|
546
|
+
let actual = false;
|
|
547
|
+
try {
|
|
548
|
+
actual = import_node_fs.default.statSync(import_node_path.default.join(dir, name)).isFile();
|
|
549
|
+
} catch {
|
|
550
|
+
}
|
|
551
|
+
if (actual !== expected) return `\u6821\u9A8C\u671F\u95F4\u89E3\u6790\u5019\u9009\u53D8\u5316\uFF1A${import_node_path.default.relative(root, import_node_path.default.join(dir, name))}`;
|
|
552
|
+
}
|
|
553
|
+
if (snapshot.directories.some((query) => query.root === dir)) return `\u6821\u9A8C\u671F\u95F4\u8F93\u5165\u76EE\u5F55\u53D8\u5316\uFF1A${import_node_path.default.relative(root, dir)}`;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
for (const [file, before] of checked) {
|
|
557
|
+
const now = import_node_fs.default.statSync(file);
|
|
558
|
+
if (now.ctimeMs !== before.ctime || now.mtimeMs !== before.mtime || now.ino !== before.ino || now.size !== before.size) return `\u6821\u9A8C\u671F\u95F4\u8F93\u5165\u53D8\u5316\uFF1A${import_node_path.default.relative(root, file)}`;
|
|
559
|
+
}
|
|
560
|
+
return null;
|
|
561
|
+
} catch {
|
|
562
|
+
return "\u8F93\u5165\u4E0D\u53EF\u8BFB\u53D6\u6216\u5FEB\u7167\u65E0\u6548";
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function runtimeIsStable(snapshot) {
|
|
566
|
+
return snapshot.runtimeTools.every((file) => (snapshot.files[file]?.ctime ?? Infinity) <= PROCESS_START);
|
|
567
|
+
}
|
|
568
|
+
function readTypesCache(input, verifyInputs = true) {
|
|
569
|
+
try {
|
|
570
|
+
const file = typesCachePath(input.root);
|
|
571
|
+
if (import_node_fs.default.statSync(file).size > MAX_CACHE_BYTES) return null;
|
|
572
|
+
const envelope = JSON.parse((0, import_node_zlib.gunzipSync)(import_node_fs.default.readFileSync(file), { maxOutputLength: MAX_CACHE_BYTES }).toString("utf8"));
|
|
573
|
+
const p = envelope.payload;
|
|
574
|
+
if (envelope.digest !== hash(JSON.stringify(p)) || p.format !== CACHE_FORMAT || p.key !== settings(input)) return null;
|
|
575
|
+
const rawIndex = JSON.parse(p.files["index.json"]);
|
|
576
|
+
const { revision, ...indexBody } = rawIndex;
|
|
577
|
+
if (revision !== hash(JSON.stringify(indexBody)).slice(0, 16)) return null;
|
|
578
|
+
const parsed = parseDtsIndex(rawIndex);
|
|
579
|
+
const index = parsed.index;
|
|
580
|
+
if (!index || index.pluginVersion !== input.pluginVersion || index.generator !== "@fulgurjs/federation" || !["typescript", "vue-tsc"].includes(p.tool) || Object.keys(index.files).length > DTS_FILE_COUNT_MAX) return null;
|
|
581
|
+
if (Object.keys(p.files).length !== Object.keys(index.files).length + 1) return null;
|
|
582
|
+
if (JSON.stringify(sorted(Object.keys(index.exposes))) !== JSON.stringify(sorted(input.exposes.map((e) => e.name)))) return null;
|
|
583
|
+
let bytes = 0;
|
|
584
|
+
for (const [name, digest] of Object.entries(index.files)) {
|
|
585
|
+
const text = p.files[name];
|
|
586
|
+
if (typeof text !== "string" || Buffer.byteLength(text) > DTS_FILE_MAX_BYTES || hash(text) !== digest) return null;
|
|
587
|
+
bytes += Buffer.byteLength(text);
|
|
588
|
+
}
|
|
589
|
+
if (bytes > DTS_TOTAL_MAX_BYTES || !runtimeIsStable(p.snapshot) || verifyInputs && validateTypesInputs(p.snapshot, input.root)) return null;
|
|
590
|
+
return { snapshot: p.snapshot, result: { ok: true, index, files: new Map(Object.entries(p.files)), tool: p.tool, fileCount: Object.keys(index.files).length, notices: [] } };
|
|
591
|
+
} catch {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function writeTypesCache(input, snapshot, result, temporaryId) {
|
|
596
|
+
if (!runtimeIsStable(snapshot)) return;
|
|
597
|
+
const file = typesCachePath(input.root);
|
|
598
|
+
import_node_fs.default.mkdirSync(import_node_path.default.dirname(file), { recursive: true });
|
|
599
|
+
const payload = { format: CACHE_FORMAT, key: settings(input), snapshot, files: Object.fromEntries(result.files), tool: result.tool };
|
|
600
|
+
const text = JSON.stringify({ digest: hash(JSON.stringify(payload)), payload });
|
|
601
|
+
if (Buffer.byteLength(text) > MAX_CACHE_BYTES) return;
|
|
602
|
+
if (temporaryId && !/^[0-9a-f-]{36}$/i.test(temporaryId)) throw new Error("\u65E0\u6548\u7684\u7F13\u5B58\u4E34\u65F6\u6807\u8BC6");
|
|
603
|
+
const temporaryFile = `${file}.${process.pid}.${temporaryId ?? import_node_crypto.default.randomUUID()}.tmp`;
|
|
604
|
+
try {
|
|
605
|
+
import_node_fs.default.writeFileSync(temporaryFile, (0, import_node_zlib.gzipSync)(text));
|
|
606
|
+
import_node_fs.default.renameSync(temporaryFile, file);
|
|
607
|
+
} finally {
|
|
608
|
+
import_node_fs.default.rmSync(temporaryFile, { force: true });
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/dts-cache-worker.ts
|
|
613
|
+
var entries = /* @__PURE__ */ new Map();
|
|
614
|
+
function observe(input) {
|
|
615
|
+
const entry = { snapshot: void 0, dirty: false, watchers: [] };
|
|
616
|
+
for (const directory of [input.root, import_node_path2.default.join(input.root, "node_modules")]) {
|
|
617
|
+
try {
|
|
618
|
+
entry.watchers.push(import_node_fs2.default.watch(directory, { persistent: false }, (_event, filename) => {
|
|
619
|
+
if (!filename) {
|
|
620
|
+
entry.dirty = true;
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
const name = filename.toString();
|
|
624
|
+
const base = import_node_path2.default.basename(name);
|
|
625
|
+
if (base.startsWith(".fulgurjs-types-") || [".cache", ".vite", ".vite-temp", ".git", ".svn", "node_modules"].includes(base) || /\.timestamp-\d+.*\.[cm]?js$/.test(base) || /\.(?:log|md|png|jpe?g|svg|tmp)$/.test(base)) return;
|
|
626
|
+
entry.dirty = true;
|
|
627
|
+
}));
|
|
628
|
+
} catch {
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return entry;
|
|
632
|
+
}
|
|
633
|
+
function close(entry) {
|
|
634
|
+
for (const watcher of entry.watchers) watcher.close();
|
|
635
|
+
}
|
|
636
|
+
function externalInputs(input, snapshot) {
|
|
637
|
+
const outside = (file) => {
|
|
638
|
+
const relative = import_node_path2.default.relative(input.root, file);
|
|
639
|
+
return (relative === ".." || relative.startsWith(`..${import_node_path2.default.sep}`) || import_node_path2.default.isAbsolute(relative)) && !file.split(import_node_path2.default.sep).includes("node_modules");
|
|
640
|
+
};
|
|
641
|
+
const files = new Set(Object.keys(snapshot.files).filter(outside));
|
|
642
|
+
for (const [directory, queries] of Object.entries(snapshot.fileQueries)) {
|
|
643
|
+
if (!outside(directory)) continue;
|
|
644
|
+
for (const name of Object.keys(queries)) if (/\.(?:[cm]?[jt]sx?|vue|json|ya?ml|lock)$/.test(name)) files.add(import_node_path2.default.join(directory, name));
|
|
645
|
+
}
|
|
646
|
+
return [...files];
|
|
647
|
+
}
|
|
648
|
+
import_node_worker_threads.parentPort?.on("message", (message) => {
|
|
649
|
+
const { id, operation, input } = message;
|
|
650
|
+
try {
|
|
651
|
+
let value;
|
|
652
|
+
if (operation === "read" || operation === "capture") {
|
|
653
|
+
const observed = observe(input);
|
|
654
|
+
const cached = operation === "read" ? readTypesCache(input, false) : null;
|
|
655
|
+
const snapshot = cached?.snapshot ?? (operation === "capture" ? captureTypesInputs(input) : null);
|
|
656
|
+
if (!snapshot) {
|
|
657
|
+
close(observed);
|
|
658
|
+
value = null;
|
|
659
|
+
} else {
|
|
660
|
+
observed.snapshot = snapshot;
|
|
661
|
+
entries.set(id, observed);
|
|
662
|
+
value = { token: id, externalInputs: externalInputs(input, snapshot), ...cached ? { result: cached.result } : {} };
|
|
663
|
+
}
|
|
664
|
+
} else {
|
|
665
|
+
const entry = entries.get(message.token);
|
|
666
|
+
if (!entry) throw new Error("\u7C7B\u578B\u7F13\u5B58\u540E\u53F0\u5FEB\u7167\u5DF2\u91CA\u653E");
|
|
667
|
+
if (operation === "validate") value = entry.dirty ? "\u8F93\u5165\u4E8B\u4EF6\u5DF2\u53D8\u5316" : validateTypesInputs(entry.snapshot, input.root, message.stable);
|
|
668
|
+
else if (operation === "write") {
|
|
669
|
+
if (entry.dirty) value = false;
|
|
670
|
+
else {
|
|
671
|
+
writeTypesCache(input, entry.snapshot, message.result, message.temporaryId);
|
|
672
|
+
value = true;
|
|
673
|
+
}
|
|
674
|
+
} else if (operation === "release") {
|
|
675
|
+
close(entry);
|
|
676
|
+
entries.delete(message.token);
|
|
677
|
+
value = true;
|
|
678
|
+
} else throw new Error("\u672A\u77E5\u7684\u7C7B\u578B\u7F13\u5B58\u540E\u53F0\u64CD\u4F5C");
|
|
679
|
+
}
|
|
680
|
+
import_node_worker_threads.parentPort?.postMessage({ id, ok: true, value });
|
|
681
|
+
} catch (error) {
|
|
682
|
+
import_node_worker_threads.parentPort?.postMessage({ id, ok: false, error: error.message });
|
|
683
|
+
}
|
|
684
|
+
});
|