@vite-hub/workflow 0.0.1 → 0.0.2
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/README.md +56 -6
- package/dist/{cloudflare-env-BVUMOgFK.d.ts → cloudflare-env-CIjdFTv6.d.ts} +2 -1
- package/dist/{cloudflare-env-g0Rf3ClH.js → cloudflare-env-mFp2Uj6Z.js} +7 -3
- package/dist/{cloudflare-vite-DcM5YVTP.js → cloudflare-vite-B0zel2Do.js} +4 -5
- package/dist/{config-DkgsQuXz.js → config-BDqB6I4E.js} +43 -5
- package/dist/index.d.ts +43 -18
- package/dist/index.js +99 -111
- package/dist/provider-operation-CWIV4k42.js +62 -0
- package/dist/runtime/cloudflare-runner.d.ts +2 -2
- package/dist/runtime/cloudflare-runner.js +15 -14
- package/dist/runtime/cloudflare-shared.d.ts +2 -2
- package/dist/runtime/cloudflare-shared.js +2 -2
- package/dist/runtime/cloudflare-vite.d.ts +3 -3
- package/dist/runtime/cloudflare-vite.js +1 -1
- package/dist/runtime/execute.d.ts +1 -1
- package/dist/runtime/openworkflow-worker.d.ts +4 -2
- package/dist/runtime/openworkflow-worker.js +63 -6
- package/dist/runtime/openworkflow.d.ts +22 -1
- package/dist/runtime/openworkflow.js +110 -37
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/vercel-vite.d.ts +58 -3
- package/dist/runtime/vercel-vite.js +3 -2
- package/dist/{types-ThDitg7Z.d.ts → types-BUlYBZwH.d.ts} +48 -6
- package/dist/vercel-D2_J5D_Y.js +217 -0
- package/dist/vite.d.ts +2 -5
- package/dist/vite.js +1678 -144
- package/package.json +45 -48
- package/dist/module-UYEnVfxy.js +0 -1546
- package/dist/nitro.d.ts +0 -19
- package/dist/nitro.js +0 -2
- package/dist/openworkflow-amN7IkGO.d.ts +0 -24
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -14
- /package/dist/{_app-BVWpnNHo.d.ts → _app-DgwN4ulW.d.ts} +0 -0
- /package/dist/{app-BE3EYOWn.js → app-BZpq2cwC.js} +0 -0
- /package/dist/{cloudflare-CeHVSHoN.js → cloudflare-Cds1VIWa.js} +0 -0
- /package/dist/{cloudflare-shared-BIeY2kak.d.ts → cloudflare-shared-BVVgDSdq.d.ts} +0 -0
package/dist/module-UYEnVfxy.js
DELETED
|
@@ -1,1546 +0,0 @@
|
|
|
1
|
-
import { t as normalizeWorkflowOptions } from "./config-DkgsQuXz.js";
|
|
2
|
-
import { r as getCloudflareWorkflowClassName, t as createCloudflareWorkflowBindings } from "./cloudflare-CeHVSHoN.js";
|
|
3
|
-
import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
|
-
import path, { isAbsolute, join, relative, resolve } from "node:path";
|
|
5
|
-
import fs, { existsSync, lstatSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
6
|
-
import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
-
import { basename as basename$1, dirname, normalize, relative as relative$1, resolve as resolve$1 } from "pathe";
|
|
8
|
-
import assert from "node:assert";
|
|
9
|
-
import process$1 from "node:process";
|
|
10
|
-
import v8 from "node:v8";
|
|
11
|
-
import { format, inspect } from "node:util";
|
|
12
|
-
//#region ../internal/src/build/paths.ts
|
|
13
|
-
function generatedDirSegments(productName) {
|
|
14
|
-
return [".vitehub", productName];
|
|
15
|
-
}
|
|
16
|
-
function ensureGeneratedDir(rootDir, productName) {
|
|
17
|
-
return resolve$1(rootDir, ...generatedDirSegments(productName));
|
|
18
|
-
}
|
|
19
|
-
function computePackageDir(importMetaUrl) {
|
|
20
|
-
const currentFileDir = dirname(fileURLToPath(importMetaUrl));
|
|
21
|
-
return resolve$1(currentFileDir, basename$1(currentFileDir) === "internal" ? "../.." : "..");
|
|
22
|
-
}
|
|
23
|
-
function resolveRuntimeModule(packageDir, modulePath) {
|
|
24
|
-
const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
|
|
25
|
-
return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
|
|
26
|
-
}
|
|
27
|
-
function createImportPath(fromFile, targetFile) {
|
|
28
|
-
const importPath = relative$1(realpathIfExists(dirname(fromFile)), realpathIfExists(targetFile));
|
|
29
|
-
return importPath.startsWith(".") ? importPath : `./${importPath}`;
|
|
30
|
-
}
|
|
31
|
-
function realpathIfExists(path) {
|
|
32
|
-
try {
|
|
33
|
-
return realpathSync.native(path);
|
|
34
|
-
} catch {
|
|
35
|
-
return resolve$1(path);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region ../internal/src/definition-catalog.ts
|
|
40
|
-
const sourceFilePattern$1 = /\.(?:c|m)?[jt]s$/i;
|
|
41
|
-
const declarationFilePattern$1 = /\.d\.(?:c|m)?[jt]s$/i;
|
|
42
|
-
const ignoredDirs = new Set([
|
|
43
|
-
"node_modules",
|
|
44
|
-
"dist",
|
|
45
|
-
".nitro",
|
|
46
|
-
".output",
|
|
47
|
-
".nuxt",
|
|
48
|
-
".vercel",
|
|
49
|
-
".git",
|
|
50
|
-
".vitehub"
|
|
51
|
-
]);
|
|
52
|
-
function resolveDefinitionScanRoots(rootDir, scanDirs = []) {
|
|
53
|
-
return [...new Set([rootDir, ...scanDirs].filter(Boolean))];
|
|
54
|
-
}
|
|
55
|
-
function createDirectoryDefinitionSource(source, scanDirs, subdir, options = {}) {
|
|
56
|
-
return {
|
|
57
|
-
...options,
|
|
58
|
-
kind: "directory",
|
|
59
|
-
scanDirs,
|
|
60
|
-
source,
|
|
61
|
-
subdir
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function createSuffixDefinitionSource(source, roots, pattern, normalizeName, options = {}) {
|
|
65
|
-
return {
|
|
66
|
-
...options,
|
|
67
|
-
kind: "suffix",
|
|
68
|
-
normalizeName,
|
|
69
|
-
pattern,
|
|
70
|
-
roots,
|
|
71
|
-
source
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function readDirEntries$1(root) {
|
|
75
|
-
try {
|
|
76
|
-
return readdirSync(root, { withFileTypes: true });
|
|
77
|
-
} catch (error) {
|
|
78
|
-
if (error.code === "ENOENT") return [];
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function listMatchingFiles(root, predicate, options = {}) {
|
|
83
|
-
const files = [];
|
|
84
|
-
for (const entry of readDirEntries$1(root)) {
|
|
85
|
-
const absolute = resolve$1(root, entry.name);
|
|
86
|
-
if (entry.isDirectory() && !entry.isSymbolicLink()) {
|
|
87
|
-
if (entry.name.startsWith(".")) continue;
|
|
88
|
-
if (ignoredDirs.has(entry.name)) continue;
|
|
89
|
-
files.push(...listMatchingFiles(absolute, predicate, options));
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (entry.name.startsWith(".") && !options.includeHidden) continue;
|
|
93
|
-
if (entry.isFile() && predicate(entry.name)) files.push(absolute);
|
|
94
|
-
}
|
|
95
|
-
return files.sort();
|
|
96
|
-
}
|
|
97
|
-
function listSourceFiles(root, options = {}) {
|
|
98
|
-
return listMatchingFiles(root, (name) => sourceFilePattern$1.test(name) && !declarationFilePattern$1.test(name), options);
|
|
99
|
-
}
|
|
100
|
-
function normalizePathDefinitionName(rootDir, file) {
|
|
101
|
-
return relative$1(rootDir, file).replace(sourceFilePattern$1, "").replace(/\/index$/i, "");
|
|
102
|
-
}
|
|
103
|
-
function normalizeSuffixDefinitionName(rootDir, file, pattern, options = {}) {
|
|
104
|
-
const normalized = relative$1(rootDir, file).replace(pattern, "");
|
|
105
|
-
if (options.stripPrefix && normalized.startsWith(options.stripPrefix)) return normalized.slice(options.stripPrefix.length);
|
|
106
|
-
return normalized;
|
|
107
|
-
}
|
|
108
|
-
function sortDefinitions(definitions) {
|
|
109
|
-
return [...definitions.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
110
|
-
}
|
|
111
|
-
function registerDefinition(definitions, definition, sourceLabel) {
|
|
112
|
-
const existing = definitions.get(definition.name);
|
|
113
|
-
if (existing) throw new Error(`Duplicate ${sourceLabel} name "${definition.name}":\n - ${existing.handler}\n - ${definition.handler}`);
|
|
114
|
-
definitions.set(definition.name, definition);
|
|
115
|
-
}
|
|
116
|
-
function mergeDefinitions(feature, ...sources) {
|
|
117
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
118
|
-
for (const source of sources) {
|
|
119
|
-
if (!source) continue;
|
|
120
|
-
for (const definition of source) {
|
|
121
|
-
const existing = definitions.get(definition.name);
|
|
122
|
-
if (existing && existing.handler !== definition.handler) throw new Error(`Duplicate ${feature} name "${definition.name}" from multiple discovery sources:\n - ${existing.handler} (${existing.source ?? "unknown"})\n - ${definition.handler} (${definition.source ?? "unknown"})`);
|
|
123
|
-
if (!existing) definitions.set(definition.name, definition);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return sortDefinitions(definitions);
|
|
127
|
-
}
|
|
128
|
-
function createDefinition(source, file, name) {
|
|
129
|
-
if (source.createDefinition) return source.createDefinition({
|
|
130
|
-
file,
|
|
131
|
-
name
|
|
132
|
-
});
|
|
133
|
-
return {
|
|
134
|
-
handler: file,
|
|
135
|
-
name,
|
|
136
|
-
source: source.source
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function scanSuffixDefinitions(feature, source) {
|
|
140
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
141
|
-
for (const root of source.roots) for (const file of listMatchingFiles(root, (name) => source.pattern.test(name), { includeHidden: source.includeHidden })) {
|
|
142
|
-
const name = source.normalizeName(root, file);
|
|
143
|
-
if (!name) continue;
|
|
144
|
-
registerDefinition(definitions, createDefinition(source, file, name), feature);
|
|
145
|
-
}
|
|
146
|
-
return sortDefinitions(definitions);
|
|
147
|
-
}
|
|
148
|
-
function scanDirectoryDefinitions(feature, source) {
|
|
149
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
150
|
-
for (const scanDir of source.scanDirs) {
|
|
151
|
-
const directory = resolve$1(scanDir, source.subdir);
|
|
152
|
-
for (const file of listSourceFiles(directory, { includeHidden: source.includeHidden })) {
|
|
153
|
-
const name = source.normalizeName ? source.normalizeName(directory, file) : normalizePathDefinitionName(directory, file);
|
|
154
|
-
if (!name) continue;
|
|
155
|
-
registerDefinition(definitions, createDefinition(source, file, name), feature);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return sortDefinitions(definitions);
|
|
159
|
-
}
|
|
160
|
-
function discoverDefinitions(feature, sources) {
|
|
161
|
-
return mergeDefinitions(feature, ...sources.map((source) => source.kind === "suffix" ? scanSuffixDefinitions(feature, source) : scanDirectoryDefinitions(feature, source)));
|
|
162
|
-
}
|
|
163
|
-
function createImportExpression(registryFile, file) {
|
|
164
|
-
const importPath = relative$1(resolve$1(registryFile, ".."), file);
|
|
165
|
-
return `import(${JSON.stringify(importPath.startsWith(".") ? importPath : `./${importPath}`)})`;
|
|
166
|
-
}
|
|
167
|
-
function createRuntimeRegistryContents(registryFile, definitions) {
|
|
168
|
-
const needsWorkflowRuntime = definitions.some((definition) => definition.steps?.length);
|
|
169
|
-
const runtimeImport = needsWorkflowRuntime ? [`import { createWorkflowSteps } from "@vite-hub/workflow/runtime/execute"`, `import { takeInlineWorkflowDefinitionForModule } from "@vite-hub/workflow/runtime/state"`] : [];
|
|
170
|
-
const imports = definitions.map((definition) => {
|
|
171
|
-
if (!definition.steps?.length) return ` ${JSON.stringify(definition.name)}: async () => ${createImportExpression(registryFile, definition.handler)},`;
|
|
172
|
-
const workflowDirectory = /\.(?:c|m)?[jt]s$/i.test(definition.handler) ? dirname(definition.handler) : definition.handler;
|
|
173
|
-
const stepImports = definition.steps.map((step) => {
|
|
174
|
-
const stepName = relative$1(workflowDirectory, step);
|
|
175
|
-
return `{ name: ${JSON.stringify(stepName)}, run: (await ${createImportExpression(registryFile, step)}).default }`;
|
|
176
|
-
});
|
|
177
|
-
const hasIndex = /\.(?:c|m)?[jt]s$/i.test(definition.handler);
|
|
178
|
-
const indexImport = hasIndex ? `const index = await ${createImportExpression(registryFile, definition.handler)}` : "";
|
|
179
|
-
const handler = hasIndex ? `index.default?.handler ? index.default : takeInlineWorkflowDefinitionForModule(${JSON.stringify(definition.name)}, index) || { handler: index.default }` : "{ handler: async (context) => { let value = context.payload; for (const step of Object.values(context.steps || {})) value = await step(value); return value } }";
|
|
180
|
-
return [
|
|
181
|
-
` ${JSON.stringify(definition.name)}: async () => {`,
|
|
182
|
-
` const cached = registryEntryCache.get(${JSON.stringify(definition.name)})`,
|
|
183
|
-
" if (cached) return cached",
|
|
184
|
-
indexImport ? ` ${indexImport}` : "",
|
|
185
|
-
` const steps = [${stepImports.join(", ")}]`,
|
|
186
|
-
` const definition = ${handler}`,
|
|
187
|
-
" const entry = {",
|
|
188
|
-
" ...definition,",
|
|
189
|
-
" options: { ...definition.options, rootStep: false },",
|
|
190
|
-
" handler: async (context) => {",
|
|
191
|
-
" const workflowSteps = createWorkflowSteps(context, steps)",
|
|
192
|
-
" return await definition.handler({ ...context, steps: workflowSteps })",
|
|
193
|
-
" },",
|
|
194
|
-
" }",
|
|
195
|
-
` registryEntryCache.set(${JSON.stringify(definition.name)}, entry)`,
|
|
196
|
-
" return entry",
|
|
197
|
-
" },"
|
|
198
|
-
].filter(Boolean).join("\n");
|
|
199
|
-
});
|
|
200
|
-
return [
|
|
201
|
-
...runtimeImport,
|
|
202
|
-
runtimeImport.length ? "" : "",
|
|
203
|
-
...needsWorkflowRuntime ? ["const registryEntryCache = new Map()", ""] : [],
|
|
204
|
-
"const registry = {",
|
|
205
|
-
...imports,
|
|
206
|
-
"}",
|
|
207
|
-
"",
|
|
208
|
-
"export default registry",
|
|
209
|
-
""
|
|
210
|
-
].join("\n");
|
|
211
|
-
}
|
|
212
|
-
function createGeneratedDefinitionPath(rootDir, options) {
|
|
213
|
-
const segments = options.segments ?? generatedDirSegments(options.productName);
|
|
214
|
-
return resolve$1(...options.buildDir ? [
|
|
215
|
-
rootDir,
|
|
216
|
-
options.buildDir,
|
|
217
|
-
...segments,
|
|
218
|
-
options.fileName
|
|
219
|
-
] : [
|
|
220
|
-
rootDir,
|
|
221
|
-
...segments,
|
|
222
|
-
options.fileName
|
|
223
|
-
]);
|
|
224
|
-
}
|
|
225
|
-
function createNitroRuntimeFilePath(rootDir, options) {
|
|
226
|
-
return createGeneratedDefinitionPath(rootDir, options);
|
|
227
|
-
}
|
|
228
|
-
async function writeRuntimeRegistryFiles(options) {
|
|
229
|
-
await Promise.all([writeFileIfChanged(options.registryFile, createRuntimeRegistryContents(options.registryFile, options.definitions)), writeFileIfChanged(options.pluginFile, options.createPluginContents(options.pluginFile, options.registryFile))]);
|
|
230
|
-
return {
|
|
231
|
-
definitions: options.definitions,
|
|
232
|
-
pluginFile: options.pluginFile,
|
|
233
|
-
registryFile: options.registryFile
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
function applyNitroRuntimeAliases(nitro, aliases) {
|
|
237
|
-
nitro.options.alias ||= {};
|
|
238
|
-
Object.assign(nitro.options.alias, aliases);
|
|
239
|
-
}
|
|
240
|
-
function hookNitroRuntimeRegistryRefresh(nitro, refresh, onRefresh = () => {}) {
|
|
241
|
-
for (const hookName of ["build:before", "dev:reload"]) nitro.hooks.hook(hookName, async () => {
|
|
242
|
-
await onRefresh(await refresh(), hookName);
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
async function writeFileIfChanged(file, contents) {
|
|
246
|
-
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
247
|
-
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
248
|
-
await writeFile(file, contents, "utf8");
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
//#region ../../node_modules/.pnpm/exsolve@1.0.8/node_modules/exsolve/dist/index.mjs
|
|
252
|
-
const nodeBuiltins = [
|
|
253
|
-
"_http_agent",
|
|
254
|
-
"_http_client",
|
|
255
|
-
"_http_common",
|
|
256
|
-
"_http_incoming",
|
|
257
|
-
"_http_outgoing",
|
|
258
|
-
"_http_server",
|
|
259
|
-
"_stream_duplex",
|
|
260
|
-
"_stream_passthrough",
|
|
261
|
-
"_stream_readable",
|
|
262
|
-
"_stream_transform",
|
|
263
|
-
"_stream_wrap",
|
|
264
|
-
"_stream_writable",
|
|
265
|
-
"_tls_common",
|
|
266
|
-
"_tls_wrap",
|
|
267
|
-
"assert",
|
|
268
|
-
"assert/strict",
|
|
269
|
-
"async_hooks",
|
|
270
|
-
"buffer",
|
|
271
|
-
"child_process",
|
|
272
|
-
"cluster",
|
|
273
|
-
"console",
|
|
274
|
-
"constants",
|
|
275
|
-
"crypto",
|
|
276
|
-
"dgram",
|
|
277
|
-
"diagnostics_channel",
|
|
278
|
-
"dns",
|
|
279
|
-
"dns/promises",
|
|
280
|
-
"domain",
|
|
281
|
-
"events",
|
|
282
|
-
"fs",
|
|
283
|
-
"fs/promises",
|
|
284
|
-
"http",
|
|
285
|
-
"http2",
|
|
286
|
-
"https",
|
|
287
|
-
"inspector",
|
|
288
|
-
"inspector/promises",
|
|
289
|
-
"module",
|
|
290
|
-
"net",
|
|
291
|
-
"os",
|
|
292
|
-
"path",
|
|
293
|
-
"path/posix",
|
|
294
|
-
"path/win32",
|
|
295
|
-
"perf_hooks",
|
|
296
|
-
"process",
|
|
297
|
-
"punycode",
|
|
298
|
-
"querystring",
|
|
299
|
-
"readline",
|
|
300
|
-
"readline/promises",
|
|
301
|
-
"repl",
|
|
302
|
-
"stream",
|
|
303
|
-
"stream/consumers",
|
|
304
|
-
"stream/promises",
|
|
305
|
-
"stream/web",
|
|
306
|
-
"string_decoder",
|
|
307
|
-
"sys",
|
|
308
|
-
"timers",
|
|
309
|
-
"timers/promises",
|
|
310
|
-
"tls",
|
|
311
|
-
"trace_events",
|
|
312
|
-
"tty",
|
|
313
|
-
"url",
|
|
314
|
-
"util",
|
|
315
|
-
"util/types",
|
|
316
|
-
"v8",
|
|
317
|
-
"vm",
|
|
318
|
-
"wasi",
|
|
319
|
-
"worker_threads",
|
|
320
|
-
"zlib"
|
|
321
|
-
];
|
|
322
|
-
const own$1 = {}.hasOwnProperty;
|
|
323
|
-
const classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
324
|
-
const kTypes = new Set([
|
|
325
|
-
"string",
|
|
326
|
-
"function",
|
|
327
|
-
"number",
|
|
328
|
-
"object",
|
|
329
|
-
"Function",
|
|
330
|
-
"Object",
|
|
331
|
-
"boolean",
|
|
332
|
-
"bigint",
|
|
333
|
-
"symbol"
|
|
334
|
-
]);
|
|
335
|
-
const messages = /* @__PURE__ */ new Map();
|
|
336
|
-
const nodeInternalPrefix = "__node_internal_";
|
|
337
|
-
let userStackTraceLimit;
|
|
338
|
-
/**
|
|
339
|
-
* Create a list string in the form like 'A and B' or 'A, B, ..., and Z'.
|
|
340
|
-
* We cannot use Intl.ListFormat because it's not available in
|
|
341
|
-
* --without-intl builds.
|
|
342
|
-
*
|
|
343
|
-
* @param {Array<string>} array
|
|
344
|
-
* An array of strings.
|
|
345
|
-
* @param {string} [type]
|
|
346
|
-
* The list type to be inserted before the last element.
|
|
347
|
-
* @returns {string}
|
|
348
|
-
*/
|
|
349
|
-
function formatList(array, type = "and") {
|
|
350
|
-
return array.length < 3 ? array.join(` ${type} `) : `${array.slice(0, -1).join(", ")}, ${type} ${array.at(-1)}`;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Utility function for registering the error codes.
|
|
354
|
-
*/
|
|
355
|
-
function createError(sym, value, constructor) {
|
|
356
|
-
messages.set(sym, value);
|
|
357
|
-
return makeNodeErrorWithCode(constructor, sym);
|
|
358
|
-
}
|
|
359
|
-
function makeNodeErrorWithCode(Base, key) {
|
|
360
|
-
return function NodeError(...parameters) {
|
|
361
|
-
const limit = Error.stackTraceLimit;
|
|
362
|
-
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
|
|
363
|
-
const error = new Base();
|
|
364
|
-
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = limit;
|
|
365
|
-
const message = getMessage(key, parameters, error);
|
|
366
|
-
Object.defineProperties(error, {
|
|
367
|
-
message: {
|
|
368
|
-
value: message,
|
|
369
|
-
enumerable: false,
|
|
370
|
-
writable: true,
|
|
371
|
-
configurable: true
|
|
372
|
-
},
|
|
373
|
-
toString: {
|
|
374
|
-
value() {
|
|
375
|
-
return `${this.name} [${key}]: ${this.message}`;
|
|
376
|
-
},
|
|
377
|
-
enumerable: false,
|
|
378
|
-
writable: true,
|
|
379
|
-
configurable: true
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
captureLargerStackTrace(error);
|
|
383
|
-
error.code = key;
|
|
384
|
-
return error;
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
function isErrorStackTraceLimitWritable() {
|
|
388
|
-
try {
|
|
389
|
-
if (v8.startupSnapshot.isBuildingSnapshot()) return false;
|
|
390
|
-
} catch {}
|
|
391
|
-
const desc = Object.getOwnPropertyDescriptor(Error, "stackTraceLimit");
|
|
392
|
-
if (desc === void 0) return Object.isExtensible(Error);
|
|
393
|
-
return own$1.call(desc, "writable") && desc.writable !== void 0 ? desc.writable : desc.set !== void 0;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* This function removes unnecessary frames from Node.js core errors.
|
|
397
|
-
*/
|
|
398
|
-
function hideStackFrames(wrappedFunction) {
|
|
399
|
-
const hidden = nodeInternalPrefix + wrappedFunction.name;
|
|
400
|
-
Object.defineProperty(wrappedFunction, "name", { value: hidden });
|
|
401
|
-
return wrappedFunction;
|
|
402
|
-
}
|
|
403
|
-
const captureLargerStackTrace = hideStackFrames(function(error) {
|
|
404
|
-
const stackTraceLimitIsWritable = isErrorStackTraceLimitWritable();
|
|
405
|
-
if (stackTraceLimitIsWritable) {
|
|
406
|
-
userStackTraceLimit = Error.stackTraceLimit;
|
|
407
|
-
Error.stackTraceLimit = Number.POSITIVE_INFINITY;
|
|
408
|
-
}
|
|
409
|
-
Error.captureStackTrace(error);
|
|
410
|
-
if (stackTraceLimitIsWritable) Error.stackTraceLimit = userStackTraceLimit;
|
|
411
|
-
return error;
|
|
412
|
-
});
|
|
413
|
-
function getMessage(key, parameters, self) {
|
|
414
|
-
const message = messages.get(key);
|
|
415
|
-
assert.ok(message !== void 0, "expected `message` to be found");
|
|
416
|
-
if (typeof message === "function") {
|
|
417
|
-
assert.ok(message.length <= parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${message.length}).`);
|
|
418
|
-
return Reflect.apply(message, self, parameters);
|
|
419
|
-
}
|
|
420
|
-
const regex = /%[dfijoOs]/g;
|
|
421
|
-
let expectedLength = 0;
|
|
422
|
-
while (regex.exec(message) !== null) expectedLength++;
|
|
423
|
-
assert.ok(expectedLength === parameters.length, `Code: ${key}; The provided arguments length (${parameters.length}) does not match the required ones (${expectedLength}).`);
|
|
424
|
-
if (parameters.length === 0) return message;
|
|
425
|
-
parameters.unshift(message);
|
|
426
|
-
return Reflect.apply(format, null, parameters);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Determine the specific type of a value for type-mismatch errors.
|
|
430
|
-
*/
|
|
431
|
-
function determineSpecificType(value) {
|
|
432
|
-
if (value === null || value === void 0) return String(value);
|
|
433
|
-
if (typeof value === "function" && value.name) return `function ${value.name}`;
|
|
434
|
-
if (typeof value === "object") {
|
|
435
|
-
if (value.constructor && value.constructor.name) return `an instance of ${value.constructor.name}`;
|
|
436
|
-
return `${inspect(value, { depth: -1 })}`;
|
|
437
|
-
}
|
|
438
|
-
let inspected = inspect(value, { colors: false });
|
|
439
|
-
if (inspected.length > 28) inspected = `${inspected.slice(0, 25)}...`;
|
|
440
|
-
return `type ${typeof value} (${inspected})`;
|
|
441
|
-
}
|
|
442
|
-
createError("ERR_INVALID_ARG_TYPE", (name, expected, actual) => {
|
|
443
|
-
assert.ok(typeof name === "string", "'name' must be a string");
|
|
444
|
-
if (!Array.isArray(expected)) expected = [expected];
|
|
445
|
-
let message = "The ";
|
|
446
|
-
if (name.endsWith(" argument")) message += `${name} `;
|
|
447
|
-
else {
|
|
448
|
-
const type = name.includes(".") ? "property" : "argument";
|
|
449
|
-
message += `"${name}" ${type} `;
|
|
450
|
-
}
|
|
451
|
-
message += "must be ";
|
|
452
|
-
const types = [];
|
|
453
|
-
const instances = [];
|
|
454
|
-
const other = [];
|
|
455
|
-
for (const value of expected) {
|
|
456
|
-
assert.ok(typeof value === "string", "All expected entries have to be of type string");
|
|
457
|
-
if (kTypes.has(value)) types.push(value.toLowerCase());
|
|
458
|
-
else if (classRegExp.exec(value) === null) {
|
|
459
|
-
assert.ok(value !== "object", "The value \"object\" should be written as \"Object\"");
|
|
460
|
-
other.push(value);
|
|
461
|
-
} else instances.push(value);
|
|
462
|
-
}
|
|
463
|
-
if (instances.length > 0) {
|
|
464
|
-
const pos = types.indexOf("object");
|
|
465
|
-
if (pos !== -1) {
|
|
466
|
-
types.slice(pos, 1);
|
|
467
|
-
instances.push("Object");
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
if (types.length > 0) {
|
|
471
|
-
message += `${types.length > 1 ? "one of type" : "of type"} ${formatList(types, "or")}`;
|
|
472
|
-
if (instances.length > 0 || other.length > 0) message += " or ";
|
|
473
|
-
}
|
|
474
|
-
if (instances.length > 0) {
|
|
475
|
-
message += `an instance of ${formatList(instances, "or")}`;
|
|
476
|
-
if (other.length > 0) message += " or ";
|
|
477
|
-
}
|
|
478
|
-
if (other.length > 0) if (other.length > 1) message += `one of ${formatList(other, "or")}`;
|
|
479
|
-
else {
|
|
480
|
-
if (other[0]?.toLowerCase() !== other[0]) message += "an ";
|
|
481
|
-
message += `${other[0]}`;
|
|
482
|
-
}
|
|
483
|
-
message += `. Received ${determineSpecificType(actual)}`;
|
|
484
|
-
return message;
|
|
485
|
-
}, TypeError);
|
|
486
|
-
const ERR_INVALID_MODULE_SPECIFIER = createError(
|
|
487
|
-
"ERR_INVALID_MODULE_SPECIFIER",
|
|
488
|
-
/**
|
|
489
|
-
* @param {string} request
|
|
490
|
-
* @param {string} reason
|
|
491
|
-
* @param {string} [base]
|
|
492
|
-
*/
|
|
493
|
-
(request, reason, base) => {
|
|
494
|
-
return `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ""}`;
|
|
495
|
-
},
|
|
496
|
-
TypeError
|
|
497
|
-
);
|
|
498
|
-
const ERR_INVALID_PACKAGE_CONFIG = createError("ERR_INVALID_PACKAGE_CONFIG", (path$1, base, message) => {
|
|
499
|
-
return `Invalid package config ${path$1}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
500
|
-
}, Error);
|
|
501
|
-
const ERR_INVALID_PACKAGE_TARGET = createError("ERR_INVALID_PACKAGE_TARGET", (packagePath, key, target, isImport = false, base) => {
|
|
502
|
-
const relatedError = typeof target === "string" && !isImport && target.length > 0 && !target.startsWith("./");
|
|
503
|
-
if (key === ".") {
|
|
504
|
-
assert.ok(isImport === false);
|
|
505
|
-
return `Invalid "exports" main target ${JSON.stringify(target)} defined in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? "; targets must start with \"./\"" : ""}`;
|
|
506
|
-
}
|
|
507
|
-
return `Invalid "${isImport ? "imports" : "exports"}" target ${JSON.stringify(target)} defined for '${key}' in the package config ${packagePath}package.json${base ? ` imported from ${base}` : ""}${relatedError ? "; targets must start with \"./\"" : ""}`;
|
|
508
|
-
}, Error);
|
|
509
|
-
const ERR_MODULE_NOT_FOUND = createError("ERR_MODULE_NOT_FOUND", (path$1, base, exactUrl = false) => {
|
|
510
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${path$1}' imported from ${base}`;
|
|
511
|
-
}, Error);
|
|
512
|
-
createError("ERR_NETWORK_IMPORT_DISALLOWED", "import of '%s' by %s is not supported: %s", Error);
|
|
513
|
-
const ERR_PACKAGE_IMPORT_NOT_DEFINED = createError("ERR_PACKAGE_IMPORT_NOT_DEFINED", (specifier, packagePath, base) => {
|
|
514
|
-
return `Package import specifier "${specifier}" is not defined${packagePath ? ` in package ${packagePath || ""}package.json` : ""} imported from ${base}`;
|
|
515
|
-
}, TypeError);
|
|
516
|
-
const ERR_PACKAGE_PATH_NOT_EXPORTED = createError(
|
|
517
|
-
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
518
|
-
/**
|
|
519
|
-
* @param {string} packagePath
|
|
520
|
-
* @param {string} subpath
|
|
521
|
-
* @param {string} [base]
|
|
522
|
-
*/
|
|
523
|
-
(packagePath, subpath, base) => {
|
|
524
|
-
if (subpath === ".") return `No "exports" main defined in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
525
|
-
return `Package subpath '${subpath}' is not defined by "exports" in ${packagePath}package.json${base ? ` imported from ${base}` : ""}`;
|
|
526
|
-
},
|
|
527
|
-
Error
|
|
528
|
-
);
|
|
529
|
-
const ERR_UNSUPPORTED_DIR_IMPORT = createError("ERR_UNSUPPORTED_DIR_IMPORT", "Directory import '%s' is not supported resolving ES modules imported from %s", Error);
|
|
530
|
-
const ERR_UNSUPPORTED_RESOLVE_REQUEST = createError("ERR_UNSUPPORTED_RESOLVE_REQUEST", "Failed to resolve module specifier \"%s\" from \"%s\": Invalid relative URL or base scheme is not hierarchical.", TypeError);
|
|
531
|
-
const ERR_UNKNOWN_FILE_EXTENSION = createError("ERR_UNKNOWN_FILE_EXTENSION", (extension, path$1) => {
|
|
532
|
-
return `Unknown file extension "${extension}" for ${path$1}`;
|
|
533
|
-
}, TypeError);
|
|
534
|
-
createError("ERR_INVALID_ARG_VALUE", (name, value, reason = "is invalid") => {
|
|
535
|
-
let inspected = inspect(value);
|
|
536
|
-
if (inspected.length > 128) inspected = `${inspected.slice(0, 128)}...`;
|
|
537
|
-
return `The ${name.includes(".") ? "property" : "argument"} '${name}' ${reason}. Received ${inspected}`;
|
|
538
|
-
}, TypeError);
|
|
539
|
-
const hasOwnProperty$1 = {}.hasOwnProperty;
|
|
540
|
-
const cache = /* @__PURE__ */ new Map();
|
|
541
|
-
function read(jsonPath, { base, specifier }) {
|
|
542
|
-
const existing = cache.get(jsonPath);
|
|
543
|
-
if (existing) return existing;
|
|
544
|
-
let string;
|
|
545
|
-
try {
|
|
546
|
-
string = fs.readFileSync(path.toNamespacedPath(jsonPath), "utf8");
|
|
547
|
-
} catch (error) {
|
|
548
|
-
const exception = error;
|
|
549
|
-
if (exception.code !== "ENOENT") throw exception;
|
|
550
|
-
}
|
|
551
|
-
const result = {
|
|
552
|
-
exists: false,
|
|
553
|
-
pjsonPath: jsonPath,
|
|
554
|
-
main: void 0,
|
|
555
|
-
name: void 0,
|
|
556
|
-
type: "none",
|
|
557
|
-
exports: void 0,
|
|
558
|
-
imports: void 0
|
|
559
|
-
};
|
|
560
|
-
if (string !== void 0) {
|
|
561
|
-
let parsed;
|
|
562
|
-
try {
|
|
563
|
-
parsed = JSON.parse(string);
|
|
564
|
-
} catch (error_) {
|
|
565
|
-
const error = new ERR_INVALID_PACKAGE_CONFIG(jsonPath, (base ? `"${specifier}" from ` : "") + fileURLToPath(base || specifier), error_.message);
|
|
566
|
-
error.cause = error_;
|
|
567
|
-
throw error;
|
|
568
|
-
}
|
|
569
|
-
result.exists = true;
|
|
570
|
-
if (hasOwnProperty$1.call(parsed, "name") && typeof parsed.name === "string") result.name = parsed.name;
|
|
571
|
-
if (hasOwnProperty$1.call(parsed, "main") && typeof parsed.main === "string") result.main = parsed.main;
|
|
572
|
-
if (hasOwnProperty$1.call(parsed, "exports")) result.exports = parsed.exports;
|
|
573
|
-
if (hasOwnProperty$1.call(parsed, "imports")) result.imports = parsed.imports;
|
|
574
|
-
if (hasOwnProperty$1.call(parsed, "type") && (parsed.type === "commonjs" || parsed.type === "module")) result.type = parsed.type;
|
|
575
|
-
}
|
|
576
|
-
cache.set(jsonPath, result);
|
|
577
|
-
return result;
|
|
578
|
-
}
|
|
579
|
-
function getPackageScopeConfig(resolved) {
|
|
580
|
-
let packageJSONUrl = new URL("package.json", resolved);
|
|
581
|
-
while (true) {
|
|
582
|
-
if (packageJSONUrl.pathname.endsWith("node_modules/package.json")) break;
|
|
583
|
-
const packageConfig = read(fileURLToPath(packageJSONUrl), { specifier: resolved });
|
|
584
|
-
if (packageConfig.exists) return packageConfig;
|
|
585
|
-
const lastPackageJSONUrl = packageJSONUrl;
|
|
586
|
-
packageJSONUrl = new URL("../package.json", packageJSONUrl);
|
|
587
|
-
if (packageJSONUrl.pathname === lastPackageJSONUrl.pathname) break;
|
|
588
|
-
}
|
|
589
|
-
return {
|
|
590
|
-
pjsonPath: fileURLToPath(packageJSONUrl),
|
|
591
|
-
exists: false,
|
|
592
|
-
type: "none"
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
const hasOwnProperty = {}.hasOwnProperty;
|
|
596
|
-
const extensionFormatMap = {
|
|
597
|
-
__proto__: null,
|
|
598
|
-
".json": "json",
|
|
599
|
-
".cjs": "commonjs",
|
|
600
|
-
".cts": "commonjs",
|
|
601
|
-
".js": "module",
|
|
602
|
-
".ts": "module",
|
|
603
|
-
".mts": "module",
|
|
604
|
-
".mjs": "module"
|
|
605
|
-
};
|
|
606
|
-
const protocolHandlers = {
|
|
607
|
-
__proto__: null,
|
|
608
|
-
"data:": getDataProtocolModuleFormat,
|
|
609
|
-
"file:": getFileProtocolModuleFormat,
|
|
610
|
-
"node:": () => "builtin"
|
|
611
|
-
};
|
|
612
|
-
function mimeToFormat(mime) {
|
|
613
|
-
if (mime && /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i.test(mime)) return "module";
|
|
614
|
-
if (mime === "application/json") return "json";
|
|
615
|
-
return null;
|
|
616
|
-
}
|
|
617
|
-
function getDataProtocolModuleFormat(parsed) {
|
|
618
|
-
const { 1: mime } = /^([^/]+\/[^;,]+)[^,]*?(;base64)?,/.exec(parsed.pathname) || [
|
|
619
|
-
null,
|
|
620
|
-
null,
|
|
621
|
-
null
|
|
622
|
-
];
|
|
623
|
-
return mimeToFormat(mime);
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Returns the file extension from a URL.
|
|
627
|
-
*
|
|
628
|
-
* Should give similar result to
|
|
629
|
-
* `require('node:path').extname(require('node:url').fileURLToPath(url))`
|
|
630
|
-
* when used with a `file:` URL.
|
|
631
|
-
*
|
|
632
|
-
*/
|
|
633
|
-
function extname(url) {
|
|
634
|
-
const pathname = url.pathname;
|
|
635
|
-
let index = pathname.length;
|
|
636
|
-
while (index--) {
|
|
637
|
-
const code = pathname.codePointAt(index);
|
|
638
|
-
if (code === 47) return "";
|
|
639
|
-
if (code === 46) return pathname.codePointAt(index - 1) === 47 ? "" : pathname.slice(index);
|
|
640
|
-
}
|
|
641
|
-
return "";
|
|
642
|
-
}
|
|
643
|
-
function getFileProtocolModuleFormat(url, _context, ignoreErrors) {
|
|
644
|
-
const ext = extname(url);
|
|
645
|
-
if (ext === ".js") {
|
|
646
|
-
const { type: packageType } = getPackageScopeConfig(url);
|
|
647
|
-
if (packageType !== "none") return packageType;
|
|
648
|
-
return "commonjs";
|
|
649
|
-
}
|
|
650
|
-
if (ext === "") {
|
|
651
|
-
const { type: packageType } = getPackageScopeConfig(url);
|
|
652
|
-
if (packageType === "none" || packageType === "commonjs") return "commonjs";
|
|
653
|
-
return "module";
|
|
654
|
-
}
|
|
655
|
-
const format$1 = extensionFormatMap[ext];
|
|
656
|
-
if (format$1) return format$1;
|
|
657
|
-
if (ignoreErrors) return;
|
|
658
|
-
throw new ERR_UNKNOWN_FILE_EXTENSION(ext, fileURLToPath(url));
|
|
659
|
-
}
|
|
660
|
-
function defaultGetFormatWithoutErrors(url, context) {
|
|
661
|
-
const protocol = url.protocol;
|
|
662
|
-
if (!hasOwnProperty.call(protocolHandlers, protocol)) return null;
|
|
663
|
-
return protocolHandlers[protocol](url, context, true) || null;
|
|
664
|
-
}
|
|
665
|
-
const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
666
|
-
const own = {}.hasOwnProperty;
|
|
667
|
-
const invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
668
|
-
const deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
669
|
-
const invalidPackageNameRegEx = /^\.|%|\\/;
|
|
670
|
-
const patternRegEx = /\*/g;
|
|
671
|
-
const encodedSeparatorRegEx = /%2f|%5c/i;
|
|
672
|
-
const emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
673
|
-
const doubleSlashRegEx = /[/\\]{2}/;
|
|
674
|
-
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
675
|
-
if (process$1.noDeprecation) return;
|
|
676
|
-
const pjsonPath = fileURLToPath(packageJsonUrl);
|
|
677
|
-
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
678
|
-
process$1.emitWarning(`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}.`, "DeprecationWarning", "DEP0166");
|
|
679
|
-
}
|
|
680
|
-
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
681
|
-
if (process$1.noDeprecation) return;
|
|
682
|
-
if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module") return;
|
|
683
|
-
const urlPath = fileURLToPath(url.href);
|
|
684
|
-
const packagePath = fileURLToPath(new URL$1(".", packageJsonUrl));
|
|
685
|
-
const basePath = fileURLToPath(base);
|
|
686
|
-
if (!main) process$1.emitWarning(`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
|
|
687
|
-
else if (path.resolve(packagePath, main) !== urlPath) process$1.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
|
|
688
|
-
}
|
|
689
|
-
function tryStatSync(path$1) {
|
|
690
|
-
try {
|
|
691
|
-
return statSync(path$1);
|
|
692
|
-
} catch {}
|
|
693
|
-
}
|
|
694
|
-
/**
|
|
695
|
-
* Legacy CommonJS main resolution:
|
|
696
|
-
* 1. let M = pkg_url + (json main field)
|
|
697
|
-
* 2. TRY(M, M.js, M.json, M.node)
|
|
698
|
-
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
699
|
-
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
700
|
-
* 5. NOT_FOUND
|
|
701
|
-
*/
|
|
702
|
-
function fileExists(url) {
|
|
703
|
-
const stats = statSync(url, { throwIfNoEntry: false });
|
|
704
|
-
const isFile = stats ? stats.isFile() : void 0;
|
|
705
|
-
return isFile === null || isFile === void 0 ? false : isFile;
|
|
706
|
-
}
|
|
707
|
-
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
708
|
-
let guess;
|
|
709
|
-
if (packageConfig.main !== void 0) {
|
|
710
|
-
guess = new URL$1(packageConfig.main, packageJsonUrl);
|
|
711
|
-
if (fileExists(guess)) return guess;
|
|
712
|
-
const tries$1 = [
|
|
713
|
-
`./${packageConfig.main}.js`,
|
|
714
|
-
`./${packageConfig.main}.json`,
|
|
715
|
-
`./${packageConfig.main}.node`,
|
|
716
|
-
`./${packageConfig.main}/index.js`,
|
|
717
|
-
`./${packageConfig.main}/index.json`,
|
|
718
|
-
`./${packageConfig.main}/index.node`
|
|
719
|
-
];
|
|
720
|
-
let i$1 = -1;
|
|
721
|
-
while (++i$1 < tries$1.length) {
|
|
722
|
-
guess = new URL$1(tries$1[i$1], packageJsonUrl);
|
|
723
|
-
if (fileExists(guess)) break;
|
|
724
|
-
guess = void 0;
|
|
725
|
-
}
|
|
726
|
-
if (guess) {
|
|
727
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
728
|
-
return guess;
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
const tries = [
|
|
732
|
-
"./index.js",
|
|
733
|
-
"./index.json",
|
|
734
|
-
"./index.node"
|
|
735
|
-
];
|
|
736
|
-
let i = -1;
|
|
737
|
-
while (++i < tries.length) {
|
|
738
|
-
guess = new URL$1(tries[i], packageJsonUrl);
|
|
739
|
-
if (fileExists(guess)) break;
|
|
740
|
-
guess = void 0;
|
|
741
|
-
}
|
|
742
|
-
if (guess) {
|
|
743
|
-
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
744
|
-
return guess;
|
|
745
|
-
}
|
|
746
|
-
throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL$1(".", packageJsonUrl)), fileURLToPath(base));
|
|
747
|
-
}
|
|
748
|
-
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
749
|
-
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, String.raw`must not include encoded "/" or "\" characters`, fileURLToPath(base));
|
|
750
|
-
let filePath;
|
|
751
|
-
try {
|
|
752
|
-
filePath = fileURLToPath(resolved);
|
|
753
|
-
} catch (error) {
|
|
754
|
-
Object.defineProperty(error, "input", { value: String(resolved) });
|
|
755
|
-
Object.defineProperty(error, "module", { value: String(base) });
|
|
756
|
-
throw error;
|
|
757
|
-
}
|
|
758
|
-
const stats = tryStatSync(filePath.endsWith("/") ? filePath.slice(-1) : filePath);
|
|
759
|
-
if (stats && stats.isDirectory()) {
|
|
760
|
-
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath(base));
|
|
761
|
-
error.url = String(resolved);
|
|
762
|
-
throw error;
|
|
763
|
-
}
|
|
764
|
-
if (!stats || !stats.isFile()) {
|
|
765
|
-
const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && fileURLToPath(base), true);
|
|
766
|
-
error.url = String(resolved);
|
|
767
|
-
throw error;
|
|
768
|
-
}
|
|
769
|
-
if (!preserveSymlinks) {
|
|
770
|
-
const real = realpathSync(filePath);
|
|
771
|
-
const { search, hash } = resolved;
|
|
772
|
-
resolved = pathToFileURL(real + (filePath.endsWith(path.sep) ? "/" : ""));
|
|
773
|
-
resolved.search = search;
|
|
774
|
-
resolved.hash = hash;
|
|
775
|
-
}
|
|
776
|
-
return resolved;
|
|
777
|
-
}
|
|
778
|
-
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
779
|
-
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && fileURLToPath(new URL$1(".", packageJsonUrl)), fileURLToPath(base));
|
|
780
|
-
}
|
|
781
|
-
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
782
|
-
return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL$1(".", packageJsonUrl)), subpath, base && fileURLToPath(base));
|
|
783
|
-
}
|
|
784
|
-
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
785
|
-
throw new ERR_INVALID_MODULE_SPECIFIER(request, `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJsonUrl)}`, base && fileURLToPath(base));
|
|
786
|
-
}
|
|
787
|
-
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
788
|
-
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
789
|
-
return new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL$1(".", packageJsonUrl)), subpath, target, internal, base && fileURLToPath(base));
|
|
790
|
-
}
|
|
791
|
-
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
792
|
-
if (subpath !== "" && !pattern && target.at(-1) !== "/") throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
793
|
-
if (!target.startsWith("./")) {
|
|
794
|
-
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
795
|
-
let isURL = false;
|
|
796
|
-
try {
|
|
797
|
-
new URL$1(target);
|
|
798
|
-
isURL = true;
|
|
799
|
-
} catch {}
|
|
800
|
-
if (!isURL) return packageResolve(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath, packageJsonUrl, conditions);
|
|
801
|
-
}
|
|
802
|
-
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
803
|
-
}
|
|
804
|
-
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
805
|
-
if (!isPathMap) {
|
|
806
|
-
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
807
|
-
emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, true);
|
|
808
|
-
}
|
|
809
|
-
} else throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
810
|
-
const resolved = new URL$1(target, packageJsonUrl);
|
|
811
|
-
const resolvedPath = resolved.pathname;
|
|
812
|
-
const packagePath = new URL$1(".", packageJsonUrl).pathname;
|
|
813
|
-
if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
814
|
-
if (subpath === "") return resolved;
|
|
815
|
-
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
816
|
-
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
817
|
-
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
818
|
-
if (!isPathMap) emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, false);
|
|
819
|
-
} else throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
820
|
-
}
|
|
821
|
-
if (pattern) return new URL$1(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
|
|
822
|
-
return new URL$1(subpath, resolved);
|
|
823
|
-
}
|
|
824
|
-
function isArrayIndex(key) {
|
|
825
|
-
const keyNumber = Number(key);
|
|
826
|
-
if (`${keyNumber}` !== key) return false;
|
|
827
|
-
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
828
|
-
}
|
|
829
|
-
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
830
|
-
if (typeof target === "string") return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
|
|
831
|
-
if (Array.isArray(target)) {
|
|
832
|
-
const targetList = target;
|
|
833
|
-
if (targetList.length === 0) return null;
|
|
834
|
-
let lastException;
|
|
835
|
-
let i = -1;
|
|
836
|
-
while (++i < targetList.length) {
|
|
837
|
-
const targetItem = targetList[i];
|
|
838
|
-
let resolveResult;
|
|
839
|
-
try {
|
|
840
|
-
resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
841
|
-
} catch (error) {
|
|
842
|
-
const exception = error;
|
|
843
|
-
lastException = exception;
|
|
844
|
-
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
845
|
-
throw error;
|
|
846
|
-
}
|
|
847
|
-
if (resolveResult === void 0) continue;
|
|
848
|
-
if (resolveResult === null) {
|
|
849
|
-
lastException = null;
|
|
850
|
-
continue;
|
|
851
|
-
}
|
|
852
|
-
return resolveResult;
|
|
853
|
-
}
|
|
854
|
-
if (lastException === void 0 || lastException === null) return null;
|
|
855
|
-
throw lastException;
|
|
856
|
-
}
|
|
857
|
-
if (typeof target === "object" && target !== null) {
|
|
858
|
-
const keys = Object.getOwnPropertyNames(target);
|
|
859
|
-
let i = -1;
|
|
860
|
-
while (++i < keys.length) {
|
|
861
|
-
const key = keys[i];
|
|
862
|
-
if (isArrayIndex(key)) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), fileURLToPath(base), "\"exports\" cannot contain numeric property keys.");
|
|
863
|
-
}
|
|
864
|
-
i = -1;
|
|
865
|
-
while (++i < keys.length) {
|
|
866
|
-
const key = keys[i];
|
|
867
|
-
if (key === "default" || conditions && conditions.has(key)) {
|
|
868
|
-
const conditionalTarget = target[key];
|
|
869
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
870
|
-
if (resolveResult === void 0) continue;
|
|
871
|
-
return resolveResult;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
return null;
|
|
875
|
-
}
|
|
876
|
-
if (target === null) return null;
|
|
877
|
-
throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
|
|
878
|
-
}
|
|
879
|
-
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
880
|
-
if (typeof exports === "string" || Array.isArray(exports)) return true;
|
|
881
|
-
if (typeof exports !== "object" || exports === null) return false;
|
|
882
|
-
const keys = Object.getOwnPropertyNames(exports);
|
|
883
|
-
let isConditionalSugar = false;
|
|
884
|
-
let i = 0;
|
|
885
|
-
let keyIndex = -1;
|
|
886
|
-
while (++keyIndex < keys.length) {
|
|
887
|
-
const key = keys[keyIndex];
|
|
888
|
-
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
889
|
-
if (i++ === 0) isConditionalSugar = currentIsConditionalSugar;
|
|
890
|
-
else if (isConditionalSugar !== currentIsConditionalSugar) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), fileURLToPath(base), "\"exports\" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.");
|
|
891
|
-
}
|
|
892
|
-
return isConditionalSugar;
|
|
893
|
-
}
|
|
894
|
-
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
895
|
-
if (process$1.noDeprecation) return;
|
|
896
|
-
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
897
|
-
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
898
|
-
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
899
|
-
process$1.emitWarning(`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`, "DeprecationWarning", "DEP0155");
|
|
900
|
-
}
|
|
901
|
-
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
902
|
-
let exports = packageConfig.exports;
|
|
903
|
-
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) exports = { ".": exports };
|
|
904
|
-
if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
905
|
-
const target = exports[packageSubpath];
|
|
906
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, target, "", packageSubpath, base, false, false, false, conditions);
|
|
907
|
-
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
908
|
-
return resolveResult;
|
|
909
|
-
}
|
|
910
|
-
let bestMatch = "";
|
|
911
|
-
let bestMatchSubpath = "";
|
|
912
|
-
const keys = Object.getOwnPropertyNames(exports);
|
|
913
|
-
let i = -1;
|
|
914
|
-
while (++i < keys.length) {
|
|
915
|
-
const key = keys[i];
|
|
916
|
-
const patternIndex = key.indexOf("*");
|
|
917
|
-
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
918
|
-
if (packageSubpath.endsWith("/")) emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
|
|
919
|
-
const patternTrailer = key.slice(patternIndex + 1);
|
|
920
|
-
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
921
|
-
bestMatch = key;
|
|
922
|
-
bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
if (bestMatch) {
|
|
927
|
-
const target = exports[bestMatch];
|
|
928
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith("/"), conditions);
|
|
929
|
-
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
930
|
-
return resolveResult;
|
|
931
|
-
}
|
|
932
|
-
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
933
|
-
}
|
|
934
|
-
function patternKeyCompare(a, b) {
|
|
935
|
-
const aPatternIndex = a.indexOf("*");
|
|
936
|
-
const bPatternIndex = b.indexOf("*");
|
|
937
|
-
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
938
|
-
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
939
|
-
if (baseLengthA > baseLengthB) return -1;
|
|
940
|
-
if (baseLengthB > baseLengthA) return 1;
|
|
941
|
-
if (aPatternIndex === -1) return 1;
|
|
942
|
-
if (bPatternIndex === -1) return -1;
|
|
943
|
-
if (a.length > b.length) return -1;
|
|
944
|
-
if (b.length > a.length) return 1;
|
|
945
|
-
return 0;
|
|
946
|
-
}
|
|
947
|
-
function packageImportsResolve(name, base, conditions) {
|
|
948
|
-
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) throw new ERR_INVALID_MODULE_SPECIFIER(name, "is not a valid internal imports specifier name", fileURLToPath(base));
|
|
949
|
-
let packageJsonUrl;
|
|
950
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
951
|
-
if (packageConfig.exists) {
|
|
952
|
-
packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
953
|
-
const imports = packageConfig.imports;
|
|
954
|
-
if (imports) if (own.call(imports, name) && !name.includes("*")) {
|
|
955
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], "", name, base, false, true, false, conditions);
|
|
956
|
-
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
957
|
-
} else {
|
|
958
|
-
let bestMatch = "";
|
|
959
|
-
let bestMatchSubpath = "";
|
|
960
|
-
const keys = Object.getOwnPropertyNames(imports);
|
|
961
|
-
let i = -1;
|
|
962
|
-
while (++i < keys.length) {
|
|
963
|
-
const key = keys[i];
|
|
964
|
-
const patternIndex = key.indexOf("*");
|
|
965
|
-
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
966
|
-
const patternTrailer = key.slice(patternIndex + 1);
|
|
967
|
-
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
968
|
-
bestMatch = key;
|
|
969
|
-
bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
if (bestMatch) {
|
|
974
|
-
const target = imports[bestMatch];
|
|
975
|
-
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
|
|
976
|
-
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
throw importNotDefined(name, packageJsonUrl, base);
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* @param {string} specifier
|
|
984
|
-
* @param {URL} base
|
|
985
|
-
*/
|
|
986
|
-
function parsePackageName(specifier, base) {
|
|
987
|
-
let separatorIndex = specifier.indexOf("/");
|
|
988
|
-
let validPackageName = true;
|
|
989
|
-
let isScoped = false;
|
|
990
|
-
if (specifier[0] === "@") {
|
|
991
|
-
isScoped = true;
|
|
992
|
-
if (separatorIndex === -1 || specifier.length === 0) validPackageName = false;
|
|
993
|
-
else separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
994
|
-
}
|
|
995
|
-
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
996
|
-
if (invalidPackageNameRegEx.exec(packageName) !== null) validPackageName = false;
|
|
997
|
-
if (!validPackageName) throw new ERR_INVALID_MODULE_SPECIFIER(specifier, "is not a valid package name", fileURLToPath(base));
|
|
998
|
-
return {
|
|
999
|
-
packageName,
|
|
1000
|
-
packageSubpath: "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex)),
|
|
1001
|
-
isScoped
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
|
-
function packageResolve(specifier, base, conditions) {
|
|
1005
|
-
if (nodeBuiltins.includes(specifier)) return new URL$1("node:" + specifier);
|
|
1006
|
-
const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
|
|
1007
|
-
const packageConfig = getPackageScopeConfig(base);
|
|
1008
|
-
if (packageConfig.exists && packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(pathToFileURL(packageConfig.pjsonPath), packageSubpath, packageConfig, base, conditions);
|
|
1009
|
-
let packageJsonUrl = new URL$1("./node_modules/" + packageName + "/package.json", base);
|
|
1010
|
-
let packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
1011
|
-
let lastPath;
|
|
1012
|
-
do {
|
|
1013
|
-
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
1014
|
-
if (!stat || !stat.isDirectory()) {
|
|
1015
|
-
lastPath = packageJsonPath;
|
|
1016
|
-
packageJsonUrl = new URL$1((isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json", packageJsonUrl);
|
|
1017
|
-
packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
1018
|
-
continue;
|
|
1019
|
-
}
|
|
1020
|
-
const packageConfig$1 = read(packageJsonPath, {
|
|
1021
|
-
base,
|
|
1022
|
-
specifier
|
|
1023
|
-
});
|
|
1024
|
-
if (packageConfig$1.exports !== void 0 && packageConfig$1.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig$1, base, conditions);
|
|
1025
|
-
if (packageSubpath === ".") return legacyMainResolve(packageJsonUrl, packageConfig$1, base);
|
|
1026
|
-
return new URL$1(packageSubpath, packageJsonUrl);
|
|
1027
|
-
} while (packageJsonPath.length !== lastPath.length);
|
|
1028
|
-
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), false);
|
|
1029
|
-
}
|
|
1030
|
-
function isRelativeSpecifier(specifier) {
|
|
1031
|
-
if (specifier[0] === ".") {
|
|
1032
|
-
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
1033
|
-
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) return true;
|
|
1034
|
-
}
|
|
1035
|
-
return false;
|
|
1036
|
-
}
|
|
1037
|
-
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
1038
|
-
if (specifier === "") return false;
|
|
1039
|
-
if (specifier[0] === "/") return true;
|
|
1040
|
-
return isRelativeSpecifier(specifier);
|
|
1041
|
-
}
|
|
1042
|
-
/**
|
|
1043
|
-
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
1044
|
-
* sync and slightly lower-level than `resolve`).
|
|
1045
|
-
*
|
|
1046
|
-
* @param {string} specifier
|
|
1047
|
-
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
|
|
1048
|
-
* @param {URL} base
|
|
1049
|
-
* Full URL (to a file) that `specifier` is resolved relative from.
|
|
1050
|
-
* @param {Set<string>} [conditions]
|
|
1051
|
-
* Conditions.
|
|
1052
|
-
* @param {boolean} [preserveSymlinks]
|
|
1053
|
-
* Keep symlinks instead of resolving them.
|
|
1054
|
-
* @returns {URL}
|
|
1055
|
-
* A URL object to the found thing.
|
|
1056
|
-
*/
|
|
1057
|
-
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
1058
|
-
const protocol = base.protocol;
|
|
1059
|
-
const isData = protocol === "data:";
|
|
1060
|
-
let resolved;
|
|
1061
|
-
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) try {
|
|
1062
|
-
resolved = new URL$1(specifier, base);
|
|
1063
|
-
} catch (error_) {
|
|
1064
|
-
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1065
|
-
error.cause = error_;
|
|
1066
|
-
throw error;
|
|
1067
|
-
}
|
|
1068
|
-
else if (protocol === "file:" && specifier[0] === "#") resolved = packageImportsResolve(specifier, base, conditions);
|
|
1069
|
-
else try {
|
|
1070
|
-
resolved = new URL$1(specifier);
|
|
1071
|
-
} catch (error_) {
|
|
1072
|
-
if (isData && !nodeBuiltins.includes(specifier)) {
|
|
1073
|
-
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
1074
|
-
error.cause = error_;
|
|
1075
|
-
throw error;
|
|
1076
|
-
}
|
|
1077
|
-
resolved = packageResolve(specifier, base, conditions);
|
|
1078
|
-
}
|
|
1079
|
-
assert.ok(resolved !== void 0, "expected to be defined");
|
|
1080
|
-
if (resolved.protocol !== "file:") return resolved;
|
|
1081
|
-
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
1082
|
-
}
|
|
1083
|
-
const DEFAULT_CONDITIONS_SET = /* @__PURE__ */ new Set(["node", "import"]);
|
|
1084
|
-
const isWindows = process.platform === "win32";
|
|
1085
|
-
const globalCache = globalThis["__EXSOLVE_CACHE__"] ||= /* @__PURE__ */ new Map();
|
|
1086
|
-
/**
|
|
1087
|
-
* Synchronously resolves a module url based on the options provided.
|
|
1088
|
-
*
|
|
1089
|
-
* @param {string} input - The identifier or path of the module to resolve.
|
|
1090
|
-
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
|
|
1091
|
-
* @returns {string} The resolved URL as a string.
|
|
1092
|
-
*/
|
|
1093
|
-
function resolveModuleURL(input, options) {
|
|
1094
|
-
const parsedInput = _parseInput(input);
|
|
1095
|
-
if ("external" in parsedInput) return parsedInput.external;
|
|
1096
|
-
const specifier = parsedInput.specifier;
|
|
1097
|
-
let url = parsedInput.url;
|
|
1098
|
-
let absolutePath = parsedInput.absolutePath;
|
|
1099
|
-
let cacheKey;
|
|
1100
|
-
let cacheObj;
|
|
1101
|
-
if (options?.cache !== false) {
|
|
1102
|
-
cacheKey = _cacheKey(absolutePath || specifier, options);
|
|
1103
|
-
cacheObj = options?.cache && typeof options?.cache === "object" ? options.cache : globalCache;
|
|
1104
|
-
}
|
|
1105
|
-
if (cacheObj) {
|
|
1106
|
-
const cached = cacheObj.get(cacheKey);
|
|
1107
|
-
if (typeof cached === "string") return cached;
|
|
1108
|
-
if (cached instanceof Error) {
|
|
1109
|
-
if (options?.try) return;
|
|
1110
|
-
throw cached;
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
if (absolutePath) try {
|
|
1114
|
-
const stat = lstatSync(absolutePath);
|
|
1115
|
-
if (stat.isSymbolicLink()) {
|
|
1116
|
-
absolutePath = realpathSync(absolutePath);
|
|
1117
|
-
url = pathToFileURL(absolutePath);
|
|
1118
|
-
}
|
|
1119
|
-
if (stat.isFile()) {
|
|
1120
|
-
if (cacheObj) cacheObj.set(cacheKey, url.href);
|
|
1121
|
-
return url.href;
|
|
1122
|
-
}
|
|
1123
|
-
} catch (error) {
|
|
1124
|
-
if (error?.code !== "ENOENT") {
|
|
1125
|
-
if (cacheObj) cacheObj.set(cacheKey, error);
|
|
1126
|
-
throw error;
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
const conditionsSet = options?.conditions ? new Set(options.conditions) : DEFAULT_CONDITIONS_SET;
|
|
1130
|
-
const target = specifier || url.href;
|
|
1131
|
-
const bases = _normalizeBases(options?.from);
|
|
1132
|
-
const suffixes = options?.suffixes || [""];
|
|
1133
|
-
const extensions = options?.extensions ? ["", ...options.extensions] : [""];
|
|
1134
|
-
let resolved;
|
|
1135
|
-
for (const base of bases) {
|
|
1136
|
-
for (const suffix of suffixes) {
|
|
1137
|
-
let name = _join(target, suffix);
|
|
1138
|
-
if (name === ".") name += "/.";
|
|
1139
|
-
for (const extension of extensions) {
|
|
1140
|
-
resolved = _tryModuleResolve(name + extension, base, conditionsSet);
|
|
1141
|
-
if (resolved) break;
|
|
1142
|
-
}
|
|
1143
|
-
if (resolved) break;
|
|
1144
|
-
}
|
|
1145
|
-
if (resolved) break;
|
|
1146
|
-
}
|
|
1147
|
-
if (!resolved) {
|
|
1148
|
-
const error = /* @__PURE__ */ new Error(`Cannot resolve module "${input}" (from: ${bases.map((u) => _fmtPath(u)).join(", ")})`);
|
|
1149
|
-
error.code = "ERR_MODULE_NOT_FOUND";
|
|
1150
|
-
if (cacheObj) cacheObj.set(cacheKey, error);
|
|
1151
|
-
if (options?.try) return;
|
|
1152
|
-
throw error;
|
|
1153
|
-
}
|
|
1154
|
-
if (cacheObj) cacheObj.set(cacheKey, resolved.href);
|
|
1155
|
-
return resolved.href;
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Synchronously resolves a module then converts it to a file path
|
|
1159
|
-
*
|
|
1160
|
-
* (throws error if reolved path is not file:// scheme)
|
|
1161
|
-
*
|
|
1162
|
-
* @param {string} id - The identifier or path of the module to resolve.
|
|
1163
|
-
* @param {ResolveOptions} [options] - Options to resolve the module. See {@link ResolveOptions}.
|
|
1164
|
-
* @returns {string} The resolved URL as a string.
|
|
1165
|
-
*/
|
|
1166
|
-
function resolveModulePath(id, options) {
|
|
1167
|
-
const resolved = resolveModuleURL(id, options);
|
|
1168
|
-
if (!resolved) return;
|
|
1169
|
-
if (!resolved.startsWith("file://") && options?.try) return;
|
|
1170
|
-
const absolutePath = fileURLToPath(resolved);
|
|
1171
|
-
return isWindows ? _normalizeWinPath(absolutePath) : absolutePath;
|
|
1172
|
-
}
|
|
1173
|
-
function _tryModuleResolve(specifier, base, conditions) {
|
|
1174
|
-
try {
|
|
1175
|
-
return moduleResolve(specifier, base, conditions);
|
|
1176
|
-
} catch {}
|
|
1177
|
-
}
|
|
1178
|
-
function _normalizeBases(inputs) {
|
|
1179
|
-
const urls = (Array.isArray(inputs) ? inputs : [inputs]).flatMap((input) => _normalizeBase(input));
|
|
1180
|
-
if (urls.length === 0) return [pathToFileURL("./")];
|
|
1181
|
-
return urls;
|
|
1182
|
-
}
|
|
1183
|
-
function _normalizeBase(input) {
|
|
1184
|
-
if (!input) return [];
|
|
1185
|
-
if (_isURL(input)) return [input];
|
|
1186
|
-
if (typeof input !== "string") return [];
|
|
1187
|
-
if (/^(?:node|data|http|https|file):/.test(input)) return new URL(input);
|
|
1188
|
-
try {
|
|
1189
|
-
if (input.endsWith("/") || statSync(input).isDirectory()) return pathToFileURL(input + "/");
|
|
1190
|
-
return pathToFileURL(input);
|
|
1191
|
-
} catch {
|
|
1192
|
-
return [pathToFileURL(input + "/"), pathToFileURL(input)];
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
function _fmtPath(input) {
|
|
1196
|
-
try {
|
|
1197
|
-
return fileURLToPath(input);
|
|
1198
|
-
} catch {
|
|
1199
|
-
return input;
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
function _cacheKey(id, opts) {
|
|
1203
|
-
return JSON.stringify([
|
|
1204
|
-
id,
|
|
1205
|
-
(opts?.conditions || ["node", "import"]).sort(),
|
|
1206
|
-
opts?.extensions,
|
|
1207
|
-
opts?.from,
|
|
1208
|
-
opts?.suffixes
|
|
1209
|
-
]);
|
|
1210
|
-
}
|
|
1211
|
-
function _join(a, b) {
|
|
1212
|
-
if (!a || !b || b === "/") return a;
|
|
1213
|
-
return (a.endsWith("/") ? a : a + "/") + (b.startsWith("/") ? b.slice(1) : b);
|
|
1214
|
-
}
|
|
1215
|
-
function _normalizeWinPath(path$1) {
|
|
1216
|
-
return path$1.replace(/\\/g, "/").replace(/^[a-z]:\//, (r) => r.toUpperCase());
|
|
1217
|
-
}
|
|
1218
|
-
function _isURL(input) {
|
|
1219
|
-
return input instanceof URL || input?.constructor?.name === "URL";
|
|
1220
|
-
}
|
|
1221
|
-
function _parseInput(input) {
|
|
1222
|
-
if (typeof input === "string") {
|
|
1223
|
-
if (input.startsWith("file:")) {
|
|
1224
|
-
const url = new URL(input);
|
|
1225
|
-
return {
|
|
1226
|
-
url,
|
|
1227
|
-
absolutePath: fileURLToPath(url)
|
|
1228
|
-
};
|
|
1229
|
-
}
|
|
1230
|
-
if (isAbsolute(input)) return {
|
|
1231
|
-
url: pathToFileURL(input),
|
|
1232
|
-
absolutePath: input
|
|
1233
|
-
};
|
|
1234
|
-
if (/^(?:node|data|http|https):/.test(input)) return { external: input };
|
|
1235
|
-
if (nodeBuiltins.includes(input) && !input.includes(":")) return { external: `node:${input}` };
|
|
1236
|
-
return { specifier: input };
|
|
1237
|
-
}
|
|
1238
|
-
if (_isURL(input)) {
|
|
1239
|
-
if (input.protocol === "file:") return {
|
|
1240
|
-
url: input,
|
|
1241
|
-
absolutePath: fileURLToPath(input)
|
|
1242
|
-
};
|
|
1243
|
-
return { external: input.href };
|
|
1244
|
-
}
|
|
1245
|
-
throw new TypeError("id must be a `string` or `URL`");
|
|
1246
|
-
}
|
|
1247
|
-
//#endregion
|
|
1248
|
-
//#region ../internal/src/nitro.ts
|
|
1249
|
-
function resolveRuntimeEntry$1(srcRelative, packageSubpath, importMetaUrl) {
|
|
1250
|
-
return resolveModulePath(srcRelative, {
|
|
1251
|
-
extensions: [".ts", ".mts"],
|
|
1252
|
-
from: importMetaUrl,
|
|
1253
|
-
try: true
|
|
1254
|
-
}) ?? resolveModulePath(packageSubpath, {
|
|
1255
|
-
extensions: [".js", ".mjs"],
|
|
1256
|
-
from: importMetaUrl
|
|
1257
|
-
});
|
|
1258
|
-
}
|
|
1259
|
-
function isPromiseLike(value) {
|
|
1260
|
-
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
1261
|
-
}
|
|
1262
|
-
async function hasNamedVitePlugin(plugin, name) {
|
|
1263
|
-
if (isPromiseLike(plugin)) return hasNamedVitePlugin(await plugin, name);
|
|
1264
|
-
if (Array.isArray(plugin)) {
|
|
1265
|
-
for (const entry of plugin) if (await hasNamedVitePlugin(entry, name)) return true;
|
|
1266
|
-
return false;
|
|
1267
|
-
}
|
|
1268
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === name;
|
|
1269
|
-
}
|
|
1270
|
-
async function assertNoVitePlugin(vite, vitePluginName, integrationName) {
|
|
1271
|
-
if (await hasNamedVitePlugin(vite?.plugins, vitePluginName)) throw new Error(`[vitehub] Do not configure ${vitePluginName} when using ${integrationName}.`);
|
|
1272
|
-
}
|
|
1273
|
-
async function assertNoVitePluginInNitro(nitro, vitePluginName, integrationName) {
|
|
1274
|
-
await assertNoVitePlugin(nitro.options.vite, vitePluginName, integrationName);
|
|
1275
|
-
}
|
|
1276
|
-
function mergeNitroImportsPreset(current, preset) {
|
|
1277
|
-
if (current === false) return current;
|
|
1278
|
-
const existing = current || {};
|
|
1279
|
-
const presets = Array.isArray(existing.presets) ? [...existing.presets] : [];
|
|
1280
|
-
const found = presets.find((entry) => entry?.from === preset.from);
|
|
1281
|
-
if (found && Array.isArray(found.imports)) {
|
|
1282
|
-
const seen = new Set(found.imports);
|
|
1283
|
-
found.imports.push(...preset.imports.filter((name) => !seen.has(name)));
|
|
1284
|
-
} else if (!found) presets.push({
|
|
1285
|
-
from: preset.from,
|
|
1286
|
-
imports: [...preset.imports]
|
|
1287
|
-
});
|
|
1288
|
-
return {
|
|
1289
|
-
...existing,
|
|
1290
|
-
presets
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
//#endregion
|
|
1294
|
-
//#region src/discovery.ts
|
|
1295
|
-
const workflowSuffixPattern = /\.workflow\.(?:c|m)?[jt]s$/i;
|
|
1296
|
-
const sourceFilePattern = /\.(?:c|m)?[jt]s$/i;
|
|
1297
|
-
const declarationFilePattern = /\.d\.(?:c|m)?[jt]s$/i;
|
|
1298
|
-
const stepFilePattern = /^\d+[.-].*\.(?:c|m)?[jt]s$/i;
|
|
1299
|
-
function normalizeSuffixWorkflowName(rootDir, file) {
|
|
1300
|
-
return normalizeSuffixDefinitionName(rootDir, file, workflowSuffixPattern, { stripPrefix: "src/" });
|
|
1301
|
-
}
|
|
1302
|
-
function readDirEntries(root) {
|
|
1303
|
-
try {
|
|
1304
|
-
return readdirSync(root, { withFileTypes: true });
|
|
1305
|
-
} catch (error) {
|
|
1306
|
-
if (error.code === "ENOENT") return [];
|
|
1307
|
-
throw error;
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
function isSourceFile(file) {
|
|
1311
|
-
return sourceFilePattern.test(file) && !declarationFilePattern.test(file);
|
|
1312
|
-
}
|
|
1313
|
-
function isWorkflowFolder(directory) {
|
|
1314
|
-
return readDirEntries(directory).some((entry) => entry.isFile() && (entry.name.toLowerCase().startsWith("index.") || stepFilePattern.test(entry.name)) && isSourceFile(entry.name));
|
|
1315
|
-
}
|
|
1316
|
-
function findWorkflowFolders(workflowsDir) {
|
|
1317
|
-
const folders = [];
|
|
1318
|
-
for (const entry of readDirEntries(workflowsDir)) {
|
|
1319
|
-
if (!entry.isDirectory() || entry.isSymbolicLink() || entry.name.startsWith(".")) continue;
|
|
1320
|
-
const directory = resolve$1(workflowsDir, entry.name);
|
|
1321
|
-
if (isWorkflowFolder(directory)) {
|
|
1322
|
-
folders.push(directory);
|
|
1323
|
-
continue;
|
|
1324
|
-
}
|
|
1325
|
-
folders.push(...findWorkflowFolders(directory));
|
|
1326
|
-
}
|
|
1327
|
-
return folders.sort();
|
|
1328
|
-
}
|
|
1329
|
-
function discoverWorkflowFolders(scanDirs, source) {
|
|
1330
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
1331
|
-
for (const scanDir of scanDirs) {
|
|
1332
|
-
const workflowsDir = resolve$1(scanDir, "workflows");
|
|
1333
|
-
for (const directory of findWorkflowFolders(workflowsDir)) {
|
|
1334
|
-
const files = readDirEntries(directory).filter((entry) => entry.isFile() && isSourceFile(entry.name)).map((entry) => resolve$1(directory, entry.name)).sort();
|
|
1335
|
-
const index = files.find((file) => /\/index\.(?:c|m)?[jt]s$/i.test(normalize(file)));
|
|
1336
|
-
const steps = files.filter((file) => stepFilePattern.test(file.split("/").pop()));
|
|
1337
|
-
if (!index && steps.length === 0) continue;
|
|
1338
|
-
const relativeName = normalize(relative(workflowsDir, directory));
|
|
1339
|
-
registerDefinition(definitions, {
|
|
1340
|
-
handler: index || directory,
|
|
1341
|
-
name: relativeName,
|
|
1342
|
-
source,
|
|
1343
|
-
steps
|
|
1344
|
-
}, "workflow");
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
return sortDefinitions(definitions);
|
|
1348
|
-
}
|
|
1349
|
-
function discoverFlatServerWorkflowDefinitions(scanDirs, source) {
|
|
1350
|
-
return discoverDefinitions("workflow", [createDirectoryDefinitionSource("nitro-server-workflows", scanDirs, "workflows", {
|
|
1351
|
-
normalizeName(directory, file) {
|
|
1352
|
-
const normalizedFile = normalize(file);
|
|
1353
|
-
const parent = normalize(resolve$1(file, ".."));
|
|
1354
|
-
if (parent !== normalize(directory) && statSync(parent).isDirectory() && isWorkflowFolder(parent)) return;
|
|
1355
|
-
const fileName = normalizedFile.split("/").pop();
|
|
1356
|
-
if (fileName.toLowerCase().startsWith("index.") || stepFilePattern.test(fileName)) return;
|
|
1357
|
-
return normalizePathDefinitionName(directory, file);
|
|
1358
|
-
},
|
|
1359
|
-
createDefinition: ({ file, name }) => ({
|
|
1360
|
-
handler: file,
|
|
1361
|
-
name,
|
|
1362
|
-
source
|
|
1363
|
-
})
|
|
1364
|
-
})]);
|
|
1365
|
-
}
|
|
1366
|
-
function discoverWorkflowDefinitions(options) {
|
|
1367
|
-
if (options.mode === "nitro-server-workflows") return mergeDefinitions("workflow", discoverFlatServerWorkflowDefinitions(options.scanDirs, "nitro-server-workflows"), discoverWorkflowFolders(options.scanDirs, "nitro-server-workflows"));
|
|
1368
|
-
const roots = resolveDefinitionScanRoots(options.rootDir, options.scanDirs);
|
|
1369
|
-
const serverScanDirs = roots.map((root) => resolve$1(root, "server"));
|
|
1370
|
-
const folderDefinitions = discoverWorkflowFolders(serverScanDirs, "nitro-server-workflows");
|
|
1371
|
-
return mergeDefinitions("workflow", discoverDefinitions("workflow", [createSuffixDefinitionSource("vite-suffix", roots, workflowSuffixPattern, normalizeSuffixWorkflowName, { createDefinition: ({ file, name }) => ({
|
|
1372
|
-
handler: file,
|
|
1373
|
-
name,
|
|
1374
|
-
source: "vite-suffix"
|
|
1375
|
-
}) })]), discoverFlatServerWorkflowDefinitions(serverScanDirs, "nitro-server-workflows"), folderDefinitions);
|
|
1376
|
-
}
|
|
1377
|
-
//#endregion
|
|
1378
|
-
//#region src/nitro/module.ts
|
|
1379
|
-
const WORKFLOW_NITRO_IMPORTS_PRESET = {
|
|
1380
|
-
from: "@vite-hub/workflow",
|
|
1381
|
-
imports: ["defineWorkflow", "getWorkflowRun"]
|
|
1382
|
-
};
|
|
1383
|
-
const WORKFLOW_VITE_PLUGIN_NAME = "@vite-hub/workflow/vite";
|
|
1384
|
-
function resolveRuntimeEntry(srcRelative, packageSubpath) {
|
|
1385
|
-
return resolveRuntimeEntry$1(srcRelative, packageSubpath, import.meta.url);
|
|
1386
|
-
}
|
|
1387
|
-
function createNitroWorkflowRegistryPath(rootDir, buildDir) {
|
|
1388
|
-
return createNitroRuntimeFilePath(rootDir, {
|
|
1389
|
-
buildDir,
|
|
1390
|
-
fileName: "nitro-registry.mjs",
|
|
1391
|
-
segments: ["vitehub", "workflow"]
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
function createNitroWorkflowPluginPath(rootDir, buildDir) {
|
|
1395
|
-
return createNitroRuntimeFilePath(rootDir, {
|
|
1396
|
-
buildDir,
|
|
1397
|
-
fileName: "nitro-plugin.ts",
|
|
1398
|
-
segments: ["vitehub", "workflow"]
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
|
-
function resolveNitroWorkflowScanDirs(rootDir, scanDirs) {
|
|
1402
|
-
return scanDirs?.length ? scanDirs : [resolve(rootDir, "server")];
|
|
1403
|
-
}
|
|
1404
|
-
function createNitroWorkflowPluginContents(file, registryFile) {
|
|
1405
|
-
return [
|
|
1406
|
-
"import { definePlugin as defineNitroPlugin } from \"nitro\"",
|
|
1407
|
-
"import { useRuntimeConfig } from \"nitro/runtime-config\"",
|
|
1408
|
-
"",
|
|
1409
|
-
"import { runCloudflareWorkflow } from \"@vite-hub/workflow/runtime/cloudflare-runner\"",
|
|
1410
|
-
"import { startOpenWorkflowWorker } from \"@vite-hub/workflow/runtime/openworkflow-worker\"",
|
|
1411
|
-
"import { enterWorkflowRuntimeEvent, setWorkflowRuntimeConfig, setWorkflowRuntimeRegistry } from \"@vite-hub/workflow/runtime/state\"",
|
|
1412
|
-
"",
|
|
1413
|
-
`import workflowRegistry from ${JSON.stringify(createImportPath(file, registryFile))}`,
|
|
1414
|
-
"",
|
|
1415
|
-
"function applyWorkflowRuntimeEnv(runtimeConfig, env) {",
|
|
1416
|
-
" globalThis.__vitehubApplyRuntimeEnvToRuntimeConfig?.(runtimeConfig, { env: env || {} })",
|
|
1417
|
-
"}",
|
|
1418
|
-
"",
|
|
1419
|
-
"export async function runNitroWorkflowDefinition(name, env, event, step) {",
|
|
1420
|
-
" const runtimeConfig = useRuntimeConfig()",
|
|
1421
|
-
" applyWorkflowRuntimeEnv(runtimeConfig, env)",
|
|
1422
|
-
" return await runCloudflareWorkflow({ config: runtimeConfig.workflow, env: env || {}, event, name, registry: workflowRegistry, step })",
|
|
1423
|
-
"}",
|
|
1424
|
-
"",
|
|
1425
|
-
"globalThis.__vitehubRunNitroWorkflowDefinition = runNitroWorkflowDefinition",
|
|
1426
|
-
"",
|
|
1427
|
-
"function shouldStartOpenWorkflowWorker(workflowConfig) {",
|
|
1428
|
-
" return workflowConfig?.provider === \"openworkflow\" && hasOpenWorkflowPostgresConfig(workflowConfig) && globalThis.process?.env?.OPENWORKFLOW_WORKER !== \"false\"",
|
|
1429
|
-
"}",
|
|
1430
|
-
"",
|
|
1431
|
-
"function hasOpenWorkflowPostgresConfig(workflowConfig) {",
|
|
1432
|
-
" return Boolean(workflowConfig?.postgres?.url || globalThis.process?.env?.OPENWORKFLOW_POSTGRES_URL || globalThis.process?.env?.DATABASE_URL)",
|
|
1433
|
-
"}",
|
|
1434
|
-
"",
|
|
1435
|
-
"const workflowNitroPlugin = defineNitroPlugin(async (nitroApp) => {",
|
|
1436
|
-
" const runtimeConfig = useRuntimeConfig()",
|
|
1437
|
-
" setWorkflowRuntimeConfig(runtimeConfig.workflow)",
|
|
1438
|
-
" setWorkflowRuntimeRegistry(workflowRegistry)",
|
|
1439
|
-
"",
|
|
1440
|
-
" nitroApp.hooks.hook(\"request\", (event) => {",
|
|
1441
|
-
" enterWorkflowRuntimeEvent(event)",
|
|
1442
|
-
" })",
|
|
1443
|
-
"",
|
|
1444
|
-
" if (!shouldStartOpenWorkflowWorker(runtimeConfig.workflow)) {",
|
|
1445
|
-
" return",
|
|
1446
|
-
" }",
|
|
1447
|
-
"",
|
|
1448
|
-
" const worker = await startOpenWorkflowWorker({",
|
|
1449
|
-
" config: runtimeConfig.workflow,",
|
|
1450
|
-
" concurrency: Number(globalThis.process?.env?.OPENWORKFLOW_WORKER_CONCURRENCY || runtimeConfig.workflow.worker?.concurrency || 10),",
|
|
1451
|
-
" registry: workflowRegistry,",
|
|
1452
|
-
" signals: false,",
|
|
1453
|
-
" })",
|
|
1454
|
-
"",
|
|
1455
|
-
" let stopped = false",
|
|
1456
|
-
" nitroApp.hooks.hook(\"close\", async () => {",
|
|
1457
|
-
" if (stopped) {",
|
|
1458
|
-
" return",
|
|
1459
|
-
" }",
|
|
1460
|
-
" stopped = true",
|
|
1461
|
-
" await worker.stop()",
|
|
1462
|
-
" })",
|
|
1463
|
-
"})",
|
|
1464
|
-
"",
|
|
1465
|
-
"export default workflowNitroPlugin",
|
|
1466
|
-
""
|
|
1467
|
-
].join("\n");
|
|
1468
|
-
}
|
|
1469
|
-
function createCloudflareWorkflowClassExports(definitions) {
|
|
1470
|
-
if (!definitions.length) return "";
|
|
1471
|
-
return [
|
|
1472
|
-
"",
|
|
1473
|
-
"import { WorkflowEntrypoint as ViteHubWorkflowEntrypoint } from \"cloudflare:workers\"",
|
|
1474
|
-
"",
|
|
1475
|
-
...definitions.map((definition) => {
|
|
1476
|
-
return [
|
|
1477
|
-
`export class ${getCloudflareWorkflowClassName(definition.name)} extends ViteHubWorkflowEntrypoint {`,
|
|
1478
|
-
" async run(event, step) {",
|
|
1479
|
-
` return await globalThis.__vitehubRunNitroWorkflowDefinition(${JSON.stringify(definition.name)}, this.env || {}, event, step)`,
|
|
1480
|
-
" }",
|
|
1481
|
-
"}",
|
|
1482
|
-
""
|
|
1483
|
-
].join("\n");
|
|
1484
|
-
})
|
|
1485
|
-
].flat().join("\n");
|
|
1486
|
-
}
|
|
1487
|
-
async function writeNitroWorkflowRuntimeFiles(nitro) {
|
|
1488
|
-
const registryFile = createNitroWorkflowRegistryPath(nitro.options.rootDir, nitro.options.buildDir);
|
|
1489
|
-
const pluginFile = createNitroWorkflowPluginPath(nitro.options.rootDir, nitro.options.buildDir);
|
|
1490
|
-
const definitions = discoverWorkflowDefinitions({
|
|
1491
|
-
mode: "nitro-server-workflows",
|
|
1492
|
-
scanDirs: resolveNitroWorkflowScanDirs(nitro.options.rootDir, nitro.options.scanDirs)
|
|
1493
|
-
});
|
|
1494
|
-
const providerDefinitions = definitions;
|
|
1495
|
-
return {
|
|
1496
|
-
...await writeRuntimeRegistryFiles({
|
|
1497
|
-
createPluginContents: createNitroWorkflowPluginContents,
|
|
1498
|
-
definitions,
|
|
1499
|
-
pluginFile,
|
|
1500
|
-
registryFile
|
|
1501
|
-
}),
|
|
1502
|
-
providerDefinitions
|
|
1503
|
-
};
|
|
1504
|
-
}
|
|
1505
|
-
const workflowNitroModule = {
|
|
1506
|
-
name: "@vite-hub/workflow",
|
|
1507
|
-
async setup(nitro) {
|
|
1508
|
-
await assertNoVitePluginInNitro(nitro, WORKFLOW_VITE_PLUGIN_NAME, "@vite-hub/workflow/nitro");
|
|
1509
|
-
const resolved = normalizeWorkflowOptions(nitro.options.workflow, { hosting: nitro.options.preset });
|
|
1510
|
-
const runtimeConfig = nitro.options.runtimeConfig ||= {};
|
|
1511
|
-
if (nitro.options.preset) runtimeConfig.hosting ||= nitro.options.preset;
|
|
1512
|
-
runtimeConfig.workflow = resolved || false;
|
|
1513
|
-
nitro.options.alias ||= {};
|
|
1514
|
-
nitro.options.alias["@vite-hub/workflow"] = resolveRuntimeEntry("../index", "@vite-hub/workflow");
|
|
1515
|
-
nitro.options.alias["@vite-hub/workflow/runtime/state"] = resolveRuntimeEntry("../runtime/state", "@vite-hub/workflow/runtime/state");
|
|
1516
|
-
nitro.options.alias["@vite-hub/workflow/runtime/execute"] = resolveRuntimeEntry("../runtime/execute", "@vite-hub/workflow/runtime/execute");
|
|
1517
|
-
nitro.options.alias["@vite-hub/workflow/runtime/cloudflare-runner"] = resolveRuntimeEntry("../runtime/cloudflare-runner", "@vite-hub/workflow/runtime/cloudflare-runner");
|
|
1518
|
-
nitro.options.alias["@vite-hub/workflow/runtime/openworkflow"] = resolveRuntimeEntry("../runtime/openworkflow", "@vite-hub/workflow/runtime/openworkflow");
|
|
1519
|
-
nitro.options.alias["@vite-hub/workflow/runtime/openworkflow-worker"] = resolveRuntimeEntry("../runtime/openworkflow-worker", "@vite-hub/workflow/runtime/openworkflow-worker");
|
|
1520
|
-
let runtimeFiles = await writeNitroWorkflowRuntimeFiles(nitro);
|
|
1521
|
-
applyNitroRuntimeAliases(nitro, { "#vitehub/workflow/registry": runtimeFiles.registryFile });
|
|
1522
|
-
if (!(nitro.options._config?.imports === false)) nitro.options.imports = mergeNitroImportsPreset(nitro.options.imports === false ? {} : nitro.options.imports, WORKFLOW_NITRO_IMPORTS_PRESET);
|
|
1523
|
-
nitro.options.plugins ||= [];
|
|
1524
|
-
if (!nitro.options.plugins.includes(runtimeFiles.pluginFile)) nitro.options.plugins.push(runtimeFiles.pluginFile);
|
|
1525
|
-
if (!resolved) return;
|
|
1526
|
-
const workflows = resolved.provider === "cloudflare" ? createCloudflareWorkflowBindings(runtimeFiles.providerDefinitions, resolved) : void 0;
|
|
1527
|
-
if (workflows && nitro.options.preset?.includes("cloudflare")) {
|
|
1528
|
-
nitro.options.cloudflare ||= {};
|
|
1529
|
-
nitro.options.cloudflare.wrangler ||= {};
|
|
1530
|
-
nitro.options.cloudflare.wrangler.workflows ||= [];
|
|
1531
|
-
for (const workflow of workflows) if (!nitro.options.cloudflare.wrangler.workflows.some((existing) => existing.binding === workflow.binding)) nitro.options.cloudflare.wrangler.workflows.push(workflow);
|
|
1532
|
-
}
|
|
1533
|
-
hookNitroRuntimeRegistryRefresh(nitro, () => writeNitroWorkflowRuntimeFiles(nitro), (nextRuntimeFiles) => {
|
|
1534
|
-
runtimeFiles = nextRuntimeFiles;
|
|
1535
|
-
applyNitroRuntimeAliases(nitro, { "#vitehub/workflow/registry": runtimeFiles.registryFile });
|
|
1536
|
-
});
|
|
1537
|
-
nitro.hooks.hook("compiled", async (currentNitro) => {
|
|
1538
|
-
if (resolved.provider !== "cloudflare" || !currentNitro.options.preset?.includes("cloudflare")) return;
|
|
1539
|
-
const classExports = createCloudflareWorkflowClassExports(runtimeFiles.providerDefinitions);
|
|
1540
|
-
if (!classExports) return;
|
|
1541
|
-
await appendFile(join(currentNitro.options.output.serverDir, "index.mjs"), classExports, "utf8");
|
|
1542
|
-
});
|
|
1543
|
-
}
|
|
1544
|
-
};
|
|
1545
|
-
//#endregion
|
|
1546
|
-
export { createImportPath as a, computePackageDir as i, discoverWorkflowDefinitions as n, ensureGeneratedDir as o, createRuntimeRegistryContents as r, resolveRuntimeModule as s, workflowNitroModule as t };
|