@vite-hub/kv 0.4.1 → 0.5.1
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 +7 -3
- package/dist/{batch--v0ri69O.js → batch-D-ib5_0P.js} +0 -1
- package/dist/{cli-DpPhz_Ek.d.ts → cli-BvVInMht.d.ts} +1 -6
- package/dist/cli.d.ts +2 -4
- package/dist/cli.js +24 -14
- package/dist/{cloudflare-env-lOtHHsgP.js → cloudflare-env-Bm6huR35.js} +4 -4
- package/dist/{cloudflare-env-lookup-Bs0VDpU5.js → cloudflare-env-lookup-Dgq5n1Aq.js} +1 -2
- package/dist/{cloudflare-kv-C3NO4C21.js → cloudflare-kv-K2MzfP6D.js} +12 -16
- package/dist/{cloudflare-kv-local-C2sbIrFy.js → cloudflare-kv-local-lov9LLhU.js} +5 -10
- package/dist/{config-LfpUj9hs.js → config-B8FRGmX_.js} +53 -22
- package/dist/{create-storage-BORQm2a8.js → create-storage-BMvkkYdM.js} +9 -15
- package/dist/{cursor-history-DRHh5bO5.js → cursor-history-C6oG12QO.js} +9 -6
- package/dist/{deno-kv-D_VtffFv.js → deno-kv-MnqlNH1e.js} +45 -10
- package/dist/{dev-peer-CHafxbtj.js → dev-peer-D0vOxmrD.js} +1 -2
- package/dist/driver-bLMl-wMO.d.ts +43 -0
- package/dist/durability.d.ts +1 -3
- package/dist/durability.js +1 -2
- package/dist/{error-diagnostics-C54QQEhN.js → error-diagnostics-DUIp6FhO.js} +7 -4
- package/dist/{errors-DzD6YNEH.js → errors-IaVOqzAs.js} +42 -8
- package/dist/errors.d.ts +8 -5
- package/dist/errors.js +1 -2
- package/dist/fs-lite-DhXLUL-H.js +1 -0
- package/dist/{fs-lite-BaklCLuV.js → fs-lite-fvNdBEr9.js} +3 -5
- package/dist/index.d.ts +1 -3
- package/dist/index.js +34 -66
- package/dist/{inspect-BIKQsqX4.js → inspect-BWMcVWD8.js} +2 -4
- package/dist/{invariant-DolT9EEx.js → invariant-Dj2R1eMr.js} +1 -2
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{operation-definition-nmRu_O3V.d.ts → operation-definition-CqZkx1Rm.d.ts} +8 -6
- package/dist/{operations-D2iI9oN4.js → operations-CGAX5ASA.js} +53 -28
- package/dist/{operations-CtrWLmPK.js → operations-FgS_sJ3M.js} +27 -45
- package/dist/operations.d.ts +2 -8
- package/dist/operations.js +8 -12
- package/dist/out-By90R-Bo.js +22706 -0
- package/dist/{redis-shared-5ogRd3-Y.js → redis-shared-DO7Ib1Sz.js} +2 -3
- package/dist/request-log-DllKQXj7.js +104 -0
- package/dist/results-emgN7uDS.js +4 -0
- package/dist/rolldown-runtime-DegdyBIC.js +25 -0
- package/dist/runtime/cloudflare-kv.d.ts +1 -3
- package/dist/runtime/cloudflare-kv.js +1 -2
- package/dist/runtime/cloudflare-request-env.d.ts +1 -3
- package/dist/runtime/cloudflare-request-env.js +2 -3
- package/dist/runtime/database.d.ts +2 -0
- package/dist/{database-oJdy0ZVX.js → runtime/database.js} +69 -39
- package/dist/runtime/nitro-plugin.d.ts +1 -2
- package/dist/runtime/nitro-plugin.js +11 -8
- package/dist/runtime/redis-driver.d.ts +3 -5
- package/dist/runtime/redis-driver.js +6 -10
- package/dist/runtime/unstorage-driver.d.ts +2 -4
- package/dist/runtime/unstorage-driver.js +2 -3
- package/dist/runtime/upstash-driver.d.ts +3 -5
- package/dist/runtime/upstash-driver.js +6 -11
- package/dist/{types-Bj3EQoRg.d.ts → types-BUb0FcjM.d.ts} +0 -2
- package/dist/{types-Dv-OSXZC.d.ts → types-C397WKyf.d.ts} +4 -20
- package/dist/{upstash-B-vaUYqO.js → upstash-DQVo1zbz.js} +3 -4
- package/dist/{utils2-FozcTsmb.js → utils2-By8eee1x.js} +1 -2
- package/dist/vite.d.ts +8 -19
- package/dist/vite.js +2676 -104
- package/package.json +15 -10
- package/dist/driver-R4Z5Z5fl.d.ts +0 -15
- package/dist/fs-lite-BAgpmNAF.js +0 -2
- package/dist/results-p7nPCnaJ.js +0 -6
package/dist/vite.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import { n as
|
|
8
|
-
import {
|
|
1
|
+
import { r as __toESM } from "./rolldown-runtime-DegdyBIC.js";
|
|
2
|
+
import { n as invariantError, t as invariant } from "./invariant-Dj2R1eMr.js";
|
|
3
|
+
import { a as resolve$1, i as relative$1, n as relativeDefinitionFile, r as dirname$1 } from "./inspect-BWMcVWD8.js";
|
|
4
|
+
import { t as addViteHubDevPeerDevHandler } from "./dev-peer-D0vOxmrD.js";
|
|
5
|
+
import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
|
|
6
|
+
import { C as resolveViteHubProjectRoot, N as writeViteHubDevServerFile, P as internalErrorDiagnostics, S as markViteConfigPlugin, b as hasNitroConfigContext, j as removeViteHubDevServerFile, k as readViteHubDevServerFile, p as operationRpcPath, r as collectOperationContributions, v as VITEHUB_PROJECT_ROOT, w as shouldSkipViteProviderBuild, x as isServerEnvironment, y as createNoExternalAddition } from "./operations-CGAX5ASA.js";
|
|
7
|
+
import { a as upstashUrlEnvNames, i as upstashTokenEnvNames, n as kvRedisEnvHint, o as resolveHostPreset, r as normalizeKVOptions } from "./config-B8FRGmX_.js";
|
|
8
|
+
import { n as kvErrorDiagnostics } from "./error-diagnostics-DUIp6FhO.js";
|
|
9
|
+
import { n as resolveUpstashRuntimeValues } from "./upstash-DQVo1zbz.js";
|
|
9
10
|
import { createRequire, isBuiltin } from "node:module";
|
|
10
|
-
import { copyFile, cp, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
11
|
+
import { access, copyFile, cp, mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
11
12
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
12
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
13
14
|
import { formatDiagnostic } from "nostics";
|
|
14
15
|
import { tmpdir } from "node:os";
|
|
15
16
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
17
|
import { createHash } from "node:crypto";
|
|
17
|
-
|
|
18
|
+
// ../internal/src/build/paths.ts
|
|
18
19
|
function resolveRuntimeModule(packageDir, modulePath) {
|
|
19
20
|
const distFile = resolve$1(packageDir, "dist", `${modulePath}.js`);
|
|
20
21
|
return existsSync(distFile) ? distFile : resolve$1(packageDir, "src", `${modulePath}.ts`);
|
|
@@ -41,16 +42,22 @@ function findPackageDir(file) {
|
|
|
41
42
|
function ownModule(importMetaUrl, modulePath) {
|
|
42
43
|
return resolveRuntimeModule(findPackageDir(fileURLToPath(importMetaUrl)), modulePath);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
//#region ../internal/src/definition-catalog.ts
|
|
45
|
+
// ../internal/src/definition-catalog.ts
|
|
46
46
|
/** `writeFileIfChangedSync` for async callers. */
|
|
47
47
|
async function writeFileIfChanged(file, contents) {
|
|
48
48
|
if (await readFile(file, "utf8").catch(() => void 0) === contents) return;
|
|
49
49
|
await mkdir(resolve$1(file, ".."), { recursive: true });
|
|
50
50
|
await writeFile(file, contents, "utf8");
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
Object.freeze({ vitehubAuthAccess: "handler" });
|
|
53
|
+
/**
|
|
54
|
+
* The route meta of a generated handler that checks access on every request, even when the app adds no rule: a required
|
|
55
|
+
* `authorize` policy, an explicit `access` rule, a required access token, or a signature. Auth access routes still apply
|
|
56
|
+
* to it, so an app rule stays in force. `checksOwnAccess(event)` of `vite-hub/auth` reads it, so app middleware can skip
|
|
57
|
+
* the route. A route that can run without a check, such as a browser error sink, an optional `authorize`, or a webhook
|
|
58
|
+
* with `secret: false`, must not use it.
|
|
59
|
+
*/
|
|
60
|
+
const ownAccessRouteMeta = Object.freeze({ vitehubOwnAccess: true });
|
|
54
61
|
function cloneArray(value) {
|
|
55
62
|
return Array.isArray(value) ? [...value] : [];
|
|
56
63
|
}
|
|
@@ -78,8 +85,7 @@ function createNitroServerKit(value = {}) {
|
|
|
78
85
|
}
|
|
79
86
|
};
|
|
80
87
|
}
|
|
81
|
-
|
|
82
|
-
//#region ../internal/src/contributions.ts
|
|
88
|
+
// ../internal/src/contributions.ts
|
|
83
89
|
function isThenable(value) {
|
|
84
90
|
return typeof value.then === "function";
|
|
85
91
|
}
|
|
@@ -106,8 +112,7 @@ async function flattenPluginOptions(plugins) {
|
|
|
106
112
|
await flattenPlugins(plugins ?? [], flattened, /* @__PURE__ */ new Set());
|
|
107
113
|
return flattened;
|
|
108
114
|
}
|
|
109
|
-
|
|
110
|
-
//#region ../internal/src/operations-vite.ts
|
|
115
|
+
// ../internal/src/operations-vite.ts
|
|
111
116
|
const owners$1 = /* @__PURE__ */ new Set([
|
|
112
117
|
"@vite-hub/kv/vite",
|
|
113
118
|
"@vite-hub/blob/vite",
|
|
@@ -166,6 +171,7 @@ async function installStandaloneOperationRpc(config, command, module) {
|
|
|
166
171
|
const kit = createNitroServerKit(Reflect.get(config, "nitro"));
|
|
167
172
|
kit.addHandler({
|
|
168
173
|
handler,
|
|
174
|
+
meta: { ...ownAccessRouteMeta },
|
|
169
175
|
route: operationRpcPath
|
|
170
176
|
});
|
|
171
177
|
const devHandlers = kit.config.devHandlers;
|
|
@@ -174,14 +180,12 @@ async function installStandaloneOperationRpc(config, command, module) {
|
|
|
174
180
|
kit.config.devHandlers = signed;
|
|
175
181
|
Reflect.set(config, "nitro", kit.config);
|
|
176
182
|
}
|
|
177
|
-
|
|
178
|
-
//#region ../internal/src/durability.ts
|
|
183
|
+
// ../internal/src/durability.ts
|
|
179
184
|
/** The `durability` module next to the Vite plugin module at `importMetaUrl`, in source and in `dist`. */
|
|
180
185
|
function durabilityModuleFile(importMetaUrl) {
|
|
181
186
|
return fileURLToPath(new URL(importMetaUrl.endsWith(".ts") ? "./durability.ts" : "./durability.js", importMetaUrl));
|
|
182
187
|
}
|
|
183
|
-
|
|
184
|
-
//#region src/vite-config.ts
|
|
188
|
+
// src/vite-config.ts
|
|
185
189
|
const KV_VITE_PLUGIN_NAME = "@vite-hub/kv/vite";
|
|
186
190
|
const KV_VIRTUAL_CONFIG_ID = "#vitehub/kv/config";
|
|
187
191
|
function resolveKVViteConfig(kv, input = {}) {
|
|
@@ -199,8 +203,7 @@ function resolveKVViteConfig(kv, input = {}) {
|
|
|
199
203
|
}) ?? false
|
|
200
204
|
};
|
|
201
205
|
}
|
|
202
|
-
|
|
203
|
-
//#region ../internal/src/build/client-output.ts
|
|
206
|
+
// ../internal/src/build/client-output.ts
|
|
204
207
|
function hasStaticIndex(clientDir) {
|
|
205
208
|
return existsSync(resolve$1(clientDir, "index.html"));
|
|
206
209
|
}
|
|
@@ -237,8 +240,7 @@ async function copyClientOutput(clientDir, targetDir, excludedDirs = []) {
|
|
|
237
240
|
filter
|
|
238
241
|
});
|
|
239
242
|
}
|
|
240
|
-
|
|
241
|
-
//#region ../internal/src/build/provider-output-config.ts
|
|
243
|
+
// ../internal/src/build/provider-output-config.ts
|
|
242
244
|
function isProviderJsonArray(value, ancestors) {
|
|
243
245
|
if (Object.getPrototypeOf(value) !== Array.prototype || ancestors.has(value)) return false;
|
|
244
246
|
if (Reflect.ownKeys(value).length !== value.length + 1) return false;
|
|
@@ -376,13 +378,11 @@ async function cleanProviderOutputConfig(file, ownership) {
|
|
|
376
378
|
if (!changed) return;
|
|
377
379
|
await persistProviderJsonRecord(file, next, true);
|
|
378
380
|
}
|
|
379
|
-
|
|
380
|
-
//#region ../internal/src/build/user-entry.ts
|
|
381
|
+
// ../internal/src/build/user-entry.ts
|
|
381
382
|
function toSafeAppName(rootDir) {
|
|
382
383
|
return basename(rootDir).replace(/[^a-z0-9-]+/gi, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").toLowerCase();
|
|
383
384
|
}
|
|
384
|
-
|
|
385
|
-
//#region ../internal/src/build/cloudflare.ts
|
|
385
|
+
// ../internal/src/build/cloudflare.ts
|
|
386
386
|
function createDefaultCloudflareOutputRoot(rootDir) {
|
|
387
387
|
return resolve(rootDir, "dist", toSafeAppName(rootDir));
|
|
388
388
|
}
|
|
@@ -399,8 +399,7 @@ async function writeCloudflareWranglerConfig(options) {
|
|
|
399
399
|
removeIfEmpty: true
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
|
-
|
|
403
|
-
//#region ../internal/src/build/bundle-options.ts
|
|
402
|
+
// ../internal/src/build/bundle-options.ts
|
|
404
403
|
const encodedAliasPrefixMarker = "\0vitehub-prefix:";
|
|
405
404
|
const encodedAliasExactMarker = "\0vitehub-exact:";
|
|
406
405
|
/** Select the runtime constants from one resolved Vite configuration. */
|
|
@@ -412,8 +411,7 @@ function resolveViteHubBundleDefines(config) {
|
|
|
412
411
|
}
|
|
413
412
|
return defines;
|
|
414
413
|
}
|
|
415
|
-
|
|
416
|
-
//#region ../internal/src/build/ast-walk.ts
|
|
414
|
+
// ../internal/src/build/ast-walk.ts
|
|
417
415
|
/** The oxc parser grammar for a file, from its extension. Defaults to TypeScript. */
|
|
418
416
|
function moduleLanguage(file) {
|
|
419
417
|
if (/\.(?:c|m)?tsx$/i.test(file)) return "tsx";
|
|
@@ -436,8 +434,7 @@ function walk(node, visit, parent) {
|
|
|
436
434
|
} else if (isNode(child)) walk(child, visit, node);
|
|
437
435
|
}
|
|
438
436
|
}
|
|
439
|
-
|
|
440
|
-
//#region ../internal/src/build/rolldown.ts
|
|
437
|
+
// ../internal/src/build/rolldown.ts
|
|
441
438
|
const viteRawPrefix = "\0vitehub-vite-raw:";
|
|
442
439
|
const markdownTemplatePrefix = "\0vitehub-markdown-template:";
|
|
443
440
|
const markdownTemplateFileSuffix = ".template.md";
|
|
@@ -930,6 +927,24 @@ function createExternalMatcher(patterns) {
|
|
|
930
927
|
});
|
|
931
928
|
return (id) => matchers.some((matches) => matches(id));
|
|
932
929
|
}
|
|
930
|
+
/** Returns the modules of the chunks that no chunk loaded from the entry chunk imports. */
|
|
931
|
+
function findUnusedChunkModules(chunks) {
|
|
932
|
+
const used = new Set(chunks.filter((chunk) => chunk.isEntry));
|
|
933
|
+
for (const chunk of used) for (const other of chunks) if (!used.has(other) && chunk.code.includes(other.fileName)) used.add(other);
|
|
934
|
+
return new Set(chunks.filter((chunk) => !used.has(chunk)).flatMap((chunk) => chunk.moduleIds));
|
|
935
|
+
}
|
|
936
|
+
function createEmptyModulesPlugin(ids) {
|
|
937
|
+
return {
|
|
938
|
+
name: "vitehub-empty-unused-chunks",
|
|
939
|
+
load(id) {
|
|
940
|
+
if (ids.has(id)) return {
|
|
941
|
+
code: "",
|
|
942
|
+
moduleSideEffects: false,
|
|
943
|
+
moduleType: "js"
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
}
|
|
933
948
|
async function bundleEsmEntry(entryFile, outfile, options = {}) {
|
|
934
949
|
const { rolldown } = await importRolldown();
|
|
935
950
|
options.signal?.throwIfAborted();
|
|
@@ -960,7 +975,7 @@ async function bundleEsmEntry(entryFile, outfile, options = {}) {
|
|
|
960
975
|
" globalThis.__dirname = globalThis.process.getBuiltinModule(\"node:path\").dirname(globalThis.__filename);",
|
|
961
976
|
"}"
|
|
962
977
|
] : []].filter(Boolean).join("\n");
|
|
963
|
-
const
|
|
978
|
+
const build = (extraPlugins = [], shimMissingExports = false) => rolldown({
|
|
964
979
|
cwd: workingDir,
|
|
965
980
|
external: isExternal ? (id) => isExternal(id) : void 0,
|
|
966
981
|
input: entryFile,
|
|
@@ -969,41 +984,2311 @@ async function bundleEsmEntry(entryFile, outfile, options = {}) {
|
|
|
969
984
|
},
|
|
970
985
|
moduleTypes: platform === "node" ? { ".wasm": "binary" } : void 0,
|
|
971
986
|
platform,
|
|
972
|
-
plugins,
|
|
987
|
+
plugins: [...extraPlugins, ...plugins],
|
|
973
988
|
resolve: {
|
|
974
989
|
conditionNames: options.conditions ?? (platform === "node" ? ["node"] : void 0),
|
|
975
990
|
extensions: options.extensions,
|
|
976
991
|
mainFields: options.mainFields ?? (platform === "neutral" ? ["module", "main"] : void 0),
|
|
977
992
|
symlinks: !options.preserveSymlinks
|
|
978
993
|
},
|
|
994
|
+
shimMissingExports,
|
|
979
995
|
transform: {
|
|
980
996
|
define: options.define,
|
|
981
997
|
target: "es2022"
|
|
982
998
|
},
|
|
983
999
|
tsconfig: options.tsconfig ?? true
|
|
984
1000
|
});
|
|
1001
|
+
const generate = async (bundle, codeSplitting) => (await bundle.generate({
|
|
1002
|
+
banner: banner || void 0,
|
|
1003
|
+
chunkFileNames: codeSplitting ? "chunk-[hash].js" : void 0,
|
|
1004
|
+
codeSplitting,
|
|
1005
|
+
format,
|
|
1006
|
+
keepNames: options.keepNames ?? Boolean(options.minifySyntax || options.minifyIdentifiers),
|
|
1007
|
+
minify,
|
|
1008
|
+
polyfillRequire: !(format === "esm" && platform === "node"),
|
|
1009
|
+
sourcemap: false
|
|
1010
|
+
})).output;
|
|
1011
|
+
let bundle = await build();
|
|
985
1012
|
let output;
|
|
986
1013
|
try {
|
|
987
|
-
output =
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1014
|
+
output = await generate(bundle, true);
|
|
1015
|
+
const chunks = output.filter((file) => file.type === "chunk");
|
|
1016
|
+
if (chunks.length > 1 || chunks.some((chunk) => chunk.dynamicImports.includes(chunk.fileName))) {
|
|
1017
|
+
options.signal?.throwIfAborted();
|
|
1018
|
+
const unusedModules = findUnusedChunkModules(chunks);
|
|
1019
|
+
if (unusedModules.size) {
|
|
1020
|
+
await bundle.close();
|
|
1021
|
+
bundle = await build([createEmptyModulesPlugin(unusedModules)], true);
|
|
1022
|
+
}
|
|
1023
|
+
output = await generate(bundle, false);
|
|
1024
|
+
}
|
|
996
1025
|
} finally {
|
|
997
1026
|
await bundle.close();
|
|
998
1027
|
}
|
|
999
1028
|
options.signal?.throwIfAborted();
|
|
1000
|
-
const chunk = output.find((file) => file.type === "chunk");
|
|
1029
|
+
const chunk = output.find((file) => file.type === "chunk" && file.isEntry);
|
|
1001
1030
|
await mkdir(dirname(outfile), { recursive: true });
|
|
1002
1031
|
await writeFile(outfile, chunk.code, { signal: options.signal });
|
|
1003
1032
|
options.signal?.throwIfAborted();
|
|
1004
1033
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1034
|
+
// ../../node_modules/.pnpm/balanced-match@4.0.4/node_modules/balanced-match/dist/esm/index.js
|
|
1035
|
+
const balanced = (a, b, str) => {
|
|
1036
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
1037
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
1038
|
+
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
1039
|
+
return r && {
|
|
1040
|
+
start: r[0],
|
|
1041
|
+
end: r[1],
|
|
1042
|
+
pre: str.slice(0, r[0]),
|
|
1043
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
1044
|
+
post: str.slice(r[1] + mb.length)
|
|
1045
|
+
};
|
|
1046
|
+
};
|
|
1047
|
+
const maybeMatch = (reg, str) => {
|
|
1048
|
+
const m = str.match(reg);
|
|
1049
|
+
return m ? m[0] : null;
|
|
1050
|
+
};
|
|
1051
|
+
const range = (a, b, str) => {
|
|
1052
|
+
let begs, beg, left, right = void 0, result;
|
|
1053
|
+
let ai = str.indexOf(a);
|
|
1054
|
+
let bi = str.indexOf(b, ai + 1);
|
|
1055
|
+
let i = ai;
|
|
1056
|
+
if (ai >= 0 && bi > 0) {
|
|
1057
|
+
if (a === b) return [ai, bi];
|
|
1058
|
+
begs = [];
|
|
1059
|
+
left = str.length;
|
|
1060
|
+
while (i >= 0 && !result) {
|
|
1061
|
+
if (i === ai) {
|
|
1062
|
+
begs.push(i);
|
|
1063
|
+
ai = str.indexOf(a, i + 1);
|
|
1064
|
+
} else if (begs.length === 1) {
|
|
1065
|
+
const r = begs.pop();
|
|
1066
|
+
if (r !== void 0) result = [r, bi];
|
|
1067
|
+
} else {
|
|
1068
|
+
beg = begs.pop();
|
|
1069
|
+
if (beg !== void 0 && beg < left) {
|
|
1070
|
+
left = beg;
|
|
1071
|
+
right = bi;
|
|
1072
|
+
}
|
|
1073
|
+
bi = str.indexOf(b, i + 1);
|
|
1074
|
+
}
|
|
1075
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
1076
|
+
}
|
|
1077
|
+
if (begs.length && right !== void 0) result = [left, right];
|
|
1078
|
+
}
|
|
1079
|
+
return result;
|
|
1080
|
+
};
|
|
1081
|
+
// ../../node_modules/.pnpm/brace-expansion@5.0.12/node_modules/brace-expansion/dist/esm/index.js
|
|
1082
|
+
const escSlash = "\0SLASH" + Math.random() + "\0";
|
|
1083
|
+
const escOpen = "\0OPEN" + Math.random() + "\0";
|
|
1084
|
+
const escClose = "\0CLOSE" + Math.random() + "\0";
|
|
1085
|
+
const escComma = "\0COMMA" + Math.random() + "\0";
|
|
1086
|
+
const escPeriod = "\0PERIOD" + Math.random() + "\0";
|
|
1087
|
+
const escSlashPattern = new RegExp(escSlash, "g");
|
|
1088
|
+
const escOpenPattern = new RegExp(escOpen, "g");
|
|
1089
|
+
const escClosePattern = new RegExp(escClose, "g");
|
|
1090
|
+
const escCommaPattern = new RegExp(escComma, "g");
|
|
1091
|
+
const escPeriodPattern = new RegExp(escPeriod, "g");
|
|
1092
|
+
const slashPattern = /\\\\/g;
|
|
1093
|
+
const openPattern = /\\{/g;
|
|
1094
|
+
const closePattern = /\\}/g;
|
|
1095
|
+
const commaPattern = /\\,/g;
|
|
1096
|
+
const periodPattern = /\\\./g;
|
|
1097
|
+
const EXPANSION_MAX = 1e5;
|
|
1098
|
+
const EXPANSION_MAX_LENGTH = 4e6;
|
|
1099
|
+
const EXPANSION_MAX_DEPTH = 1e3;
|
|
1100
|
+
const EXPANSION_MAX_REWRITES = 1e3;
|
|
1101
|
+
function numeric(str) {
|
|
1102
|
+
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
1103
|
+
}
|
|
1104
|
+
function escapeBraces(str) {
|
|
1105
|
+
return str.replace(slashPattern, escSlash).replace(openPattern, escOpen).replace(closePattern, escClose).replace(commaPattern, escComma).replace(periodPattern, escPeriod);
|
|
1106
|
+
}
|
|
1107
|
+
function unescapeBraces(str) {
|
|
1108
|
+
return str.replace(escSlashPattern, "\\").replace(escOpenPattern, "{").replace(escClosePattern, "}").replace(escCommaPattern, ",").replace(escPeriodPattern, ".");
|
|
1109
|
+
}
|
|
1110
|
+
function pushAll(target, items) {
|
|
1111
|
+
for (let i = 0; i < items.length; i++) target.push(items[i]);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Basically just str.split(","), but handling cases
|
|
1115
|
+
* where we have nested braced sections, which should be
|
|
1116
|
+
* treated as individual members, like {a,{b,c},d}
|
|
1117
|
+
*/
|
|
1118
|
+
function parseCommaParts(str) {
|
|
1119
|
+
const parts = [];
|
|
1120
|
+
let carry = "";
|
|
1121
|
+
for (;;) {
|
|
1122
|
+
const m = balanced("{", "}", str);
|
|
1123
|
+
if (!m) {
|
|
1124
|
+
const tail = str.split(",");
|
|
1125
|
+
tail[0] = carry + tail[0];
|
|
1126
|
+
pushAll(parts, tail);
|
|
1127
|
+
return parts;
|
|
1128
|
+
}
|
|
1129
|
+
const { pre, body, post } = m;
|
|
1130
|
+
const p = pre.split(",");
|
|
1131
|
+
p[0] = carry + p[0];
|
|
1132
|
+
p[p.length - 1] += "{" + body + "}";
|
|
1133
|
+
if (!post.length) {
|
|
1134
|
+
pushAll(parts, p);
|
|
1135
|
+
return parts;
|
|
1136
|
+
}
|
|
1137
|
+
carry = p.pop();
|
|
1138
|
+
pushAll(parts, p);
|
|
1139
|
+
str = post;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
function expand(str, options = {}) {
|
|
1143
|
+
if (!str) return [];
|
|
1144
|
+
const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH, maxDepth = EXPANSION_MAX_DEPTH, maxRewrites = EXPANSION_MAX_REWRITES } = options;
|
|
1145
|
+
if (str.slice(0, 2) === "{}") str = "\\{\\}" + str.slice(2);
|
|
1146
|
+
return expand_(escapeBraces(str), max, maxLength, maxDepth, 0, maxRewrites, true).map(unescapeBraces);
|
|
1147
|
+
}
|
|
1148
|
+
function embrace(str) {
|
|
1149
|
+
return "{" + str + "}";
|
|
1150
|
+
}
|
|
1151
|
+
function isPadded(el) {
|
|
1152
|
+
return /^-?0\d/.test(el);
|
|
1153
|
+
}
|
|
1154
|
+
function lte(i, y) {
|
|
1155
|
+
return i <= y;
|
|
1156
|
+
}
|
|
1157
|
+
function gte(i, y) {
|
|
1158
|
+
return i >= y;
|
|
1159
|
+
}
|
|
1160
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties) {
|
|
1161
|
+
const out = [];
|
|
1162
|
+
let length = 0;
|
|
1163
|
+
for (let a = 0; a < acc.length; a++) for (let v = 0; v < values.length; v++) {
|
|
1164
|
+
if (out.length >= max) return out;
|
|
1165
|
+
const expansion = acc[a] + pre + values[v];
|
|
1166
|
+
if (dropEmpties && !expansion) continue;
|
|
1167
|
+
if (length + expansion.length > maxLength) return out;
|
|
1168
|
+
out.push(expansion);
|
|
1169
|
+
length += expansion.length;
|
|
1170
|
+
}
|
|
1171
|
+
return out;
|
|
1172
|
+
}
|
|
1173
|
+
function expandSequence(body, isAlphaSequence, max, maxLength) {
|
|
1174
|
+
const n = body.split(/\.\./);
|
|
1175
|
+
const N = [];
|
|
1176
|
+
/* c8 ignore start */
|
|
1177
|
+
if (n[0] === void 0 || n[1] === void 0) return N;
|
|
1178
|
+
/* c8 ignore stop */
|
|
1179
|
+
const x = numeric(n[0]);
|
|
1180
|
+
const y = numeric(n[1]);
|
|
1181
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
1182
|
+
let incr = n.length === 3 && n[2] !== void 0 ? Math.max(Math.abs(numeric(n[2])), 1) : 1;
|
|
1183
|
+
let test = lte;
|
|
1184
|
+
if (y < x) {
|
|
1185
|
+
incr *= -1;
|
|
1186
|
+
test = gte;
|
|
1187
|
+
}
|
|
1188
|
+
const pad = n.some(isPadded);
|
|
1189
|
+
let length = 0;
|
|
1190
|
+
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
1191
|
+
let c;
|
|
1192
|
+
if (isAlphaSequence) {
|
|
1193
|
+
c = String.fromCharCode(i);
|
|
1194
|
+
if (c === "\\") c = "";
|
|
1195
|
+
} else {
|
|
1196
|
+
c = String(i);
|
|
1197
|
+
if (pad) {
|
|
1198
|
+
const need = width - c.length;
|
|
1199
|
+
if (need > 0) {
|
|
1200
|
+
const z = new Array(need + 1).join("0");
|
|
1201
|
+
if (i < 0) c = "-" + z + c.slice(1);
|
|
1202
|
+
else c = z + c;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (length + c.length > maxLength) break;
|
|
1207
|
+
N.push(c);
|
|
1208
|
+
length += c.length;
|
|
1209
|
+
}
|
|
1210
|
+
return N;
|
|
1211
|
+
}
|
|
1212
|
+
function expand_(str, max, maxLength, maxDepth, depth, maxRewrites, isTop) {
|
|
1213
|
+
if (depth > maxDepth) return [str];
|
|
1214
|
+
let acc = [""];
|
|
1215
|
+
let rewrites = 0;
|
|
1216
|
+
let dropEmpties = false;
|
|
1217
|
+
let firstGroup = true;
|
|
1218
|
+
for (;;) {
|
|
1219
|
+
const m = balanced("{", "}", str);
|
|
1220
|
+
if (!m) return combine(acc, str, [""], max, maxLength, dropEmpties);
|
|
1221
|
+
const pre = m.pre;
|
|
1222
|
+
if (/\$$/.test(pre)) {
|
|
1223
|
+
acc = combine(acc, pre + "{" + m.body + "}", [""], max, maxLength, dropEmpties && !m.post.length);
|
|
1224
|
+
firstGroup = false;
|
|
1225
|
+
if (!m.post.length) break;
|
|
1226
|
+
str = m.post;
|
|
1227
|
+
continue;
|
|
1228
|
+
}
|
|
1229
|
+
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
1230
|
+
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
1231
|
+
const isSequence = isNumericSequence || isAlphaSequence;
|
|
1232
|
+
const isOptions = m.body.indexOf(",") >= 0;
|
|
1233
|
+
if (!isSequence && !isOptions) {
|
|
1234
|
+
if (rewrites < maxRewrites && m.post.match(/,(?!,).*\}/)) {
|
|
1235
|
+
rewrites++;
|
|
1236
|
+
str = m.pre + "{" + m.body + escClose + m.post;
|
|
1237
|
+
isTop = true;
|
|
1238
|
+
continue;
|
|
1239
|
+
}
|
|
1240
|
+
return combine(acc, pre + "{" + m.body + "}" + m.post, [""], max, maxLength, dropEmpties);
|
|
1241
|
+
}
|
|
1242
|
+
if (firstGroup) {
|
|
1243
|
+
dropEmpties = isTop && !isSequence;
|
|
1244
|
+
firstGroup = false;
|
|
1245
|
+
}
|
|
1246
|
+
let values;
|
|
1247
|
+
if (isSequence) values = expandSequence(m.body, isAlphaSequence, max, maxLength);
|
|
1248
|
+
else {
|
|
1249
|
+
let n = parseCommaParts(m.body);
|
|
1250
|
+
if (n.length === 1 && n[0] !== void 0) {
|
|
1251
|
+
n = expand_(n[0], max, maxLength, maxDepth, depth + 1, maxRewrites, false).map(embrace);
|
|
1252
|
+
/* c8 ignore start */
|
|
1253
|
+
if (n.length === 1) {
|
|
1254
|
+
acc = combine(acc, pre + n[0], [""], max, maxLength, dropEmpties && !m.post.length);
|
|
1255
|
+
if (!m.post.length) break;
|
|
1256
|
+
str = m.post;
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
let dropsEmpties = dropEmpties && !m.post.length && !pre;
|
|
1261
|
+
for (let d = 0; dropsEmpties && d < acc.length; d++) if (acc[d]) dropsEmpties = false;
|
|
1262
|
+
values = [];
|
|
1263
|
+
let valuesLength = 0;
|
|
1264
|
+
outer: for (let j = 0; j < n.length; j++) {
|
|
1265
|
+
const expanded = expand_(n[j], max, maxLength, maxDepth, depth + 1, maxRewrites, false);
|
|
1266
|
+
for (let k = 0; k < expanded.length; k++) {
|
|
1267
|
+
const v = expanded[k];
|
|
1268
|
+
if (dropsEmpties && !v) continue;
|
|
1269
|
+
if (values.length >= max || valuesLength + v.length > maxLength) break outer;
|
|
1270
|
+
values.push(v);
|
|
1271
|
+
valuesLength += v.length;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
|
|
1276
|
+
if (!m.post.length) break;
|
|
1277
|
+
str = m.post;
|
|
1278
|
+
}
|
|
1279
|
+
return acc;
|
|
1280
|
+
}
|
|
1281
|
+
// ../../node_modules/.pnpm/@isaacs+nonrecursive-glob-match@1.1.0/node_modules/@isaacs/nonrecursive-glob-match/dist/esm/numeric-range.js
|
|
1282
|
+
const digit = (a, b) => a === b ? {
|
|
1283
|
+
t: "lit",
|
|
1284
|
+
ch: String(a)
|
|
1285
|
+
} : {
|
|
1286
|
+
t: "class",
|
|
1287
|
+
re: new RegExp(`^[${a}-${b}]$`)
|
|
1288
|
+
};
|
|
1289
|
+
const prefix = (d, alts) => alts.map((s) => [digit(d, d), ...s]);
|
|
1290
|
+
const fixed = (a, b) => {
|
|
1291
|
+
if (!a) return [[]];
|
|
1292
|
+
let lo = +a[0];
|
|
1293
|
+
let hi = +b[0];
|
|
1294
|
+
const ra = a.slice(1);
|
|
1295
|
+
const rb = b.slice(1);
|
|
1296
|
+
if (lo === hi) return prefix(lo, fixed(ra, rb));
|
|
1297
|
+
const zeros = "0".repeat(ra.length);
|
|
1298
|
+
const nines = "9".repeat(ra.length);
|
|
1299
|
+
const out = [];
|
|
1300
|
+
if (ra !== zeros) out.push(...prefix(lo++, fixed(ra, nines)));
|
|
1301
|
+
const last = rb === nines ? [] : prefix(hi--, fixed(zeros, rb));
|
|
1302
|
+
if (lo <= hi) out.push([digit(lo, hi), ...Array.from(ra, () => digit(0, 9))]);
|
|
1303
|
+
out.push(...last);
|
|
1304
|
+
return out;
|
|
1305
|
+
};
|
|
1306
|
+
const nonneg = (a, b, width) => {
|
|
1307
|
+
if (width) return fixed(String(a).padStart(width, "0"), String(b).padStart(width, "0"));
|
|
1308
|
+
const out = [];
|
|
1309
|
+
for (let len = String(a).length; len <= String(b).length; len++) {
|
|
1310
|
+
const lo = Math.max(a, len === 1 ? 0 : 10 ** (len - 1));
|
|
1311
|
+
const hi = Math.min(b, 10 ** len - 1);
|
|
1312
|
+
out.push(...fixed(String(lo), String(hi)));
|
|
1313
|
+
}
|
|
1314
|
+
return out;
|
|
1315
|
+
};
|
|
1316
|
+
/**
|
|
1317
|
+
* The strings that the bash brace expansion `{lo..hi}` makes, as
|
|
1318
|
+
* the alternatives of an `@(...)` extglob. Each one is a sequence of
|
|
1319
|
+
* digits and digit classes, so there are only a few of them, even for
|
|
1320
|
+
* a large range.
|
|
1321
|
+
*
|
|
1322
|
+
* If either end has a leading zero, such as `{01..10}`, each number
|
|
1323
|
+
* has leading zeros to make it as long as the longer end, counting a
|
|
1324
|
+
* `-` sign. So `{-05..3}` makes `-05` to `-01`, then `000` to `003`.
|
|
1325
|
+
*
|
|
1326
|
+
* Returns undefined if either end is not a safe integer.
|
|
1327
|
+
*/
|
|
1328
|
+
const numericRange = (loStr, hiStr) => {
|
|
1329
|
+
let lo = Number(loStr);
|
|
1330
|
+
let hi = Number(hiStr);
|
|
1331
|
+
if (!Number.isSafeInteger(lo) || !Number.isSafeInteger(hi)) return;
|
|
1332
|
+
if (lo > hi) [lo, hi] = [hi, lo];
|
|
1333
|
+
const width = /^-?0\d/.test(loStr) || /^-?0\d/.test(hiStr) ? Math.max(loStr.length, hiStr.length) : 0;
|
|
1334
|
+
const out = [];
|
|
1335
|
+
if (lo < 0) {
|
|
1336
|
+
const neg = nonneg(Math.max(-hi, 1), -lo, width && width - 1);
|
|
1337
|
+
out.push(...neg.map((s) => [{
|
|
1338
|
+
t: "lit",
|
|
1339
|
+
ch: "-"
|
|
1340
|
+
}, ...s]));
|
|
1341
|
+
}
|
|
1342
|
+
if (hi >= 0) out.push(...nonneg(Math.max(lo, 0), hi, width));
|
|
1343
|
+
return out;
|
|
1344
|
+
};
|
|
1345
|
+
// ../../node_modules/.pnpm/@isaacs+nonrecursive-glob-match@1.1.0/node_modules/@isaacs/nonrecursive-glob-match/dist/esm/parse-class.js
|
|
1346
|
+
const posixClasses = {
|
|
1347
|
+
"[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}"],
|
|
1348
|
+
"[:alpha:]": ["\\p{L}\\p{Nl}"],
|
|
1349
|
+
"[:ascii:]": ["\\x00-\\x7f"],
|
|
1350
|
+
"[:blank:]": ["\\p{Zs}\\t"],
|
|
1351
|
+
"[:cntrl:]": ["\\p{Cc}"],
|
|
1352
|
+
"[:digit:]": ["\\p{Nd}"],
|
|
1353
|
+
"[:graph:]": ["\\p{Z}\\p{C}", true],
|
|
1354
|
+
"[:lower:]": ["\\p{Ll}"],
|
|
1355
|
+
"[:print:]": ["\\p{C}", true],
|
|
1356
|
+
"[:punct:]": ["\\p{P}\\p{S}"],
|
|
1357
|
+
"[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f"],
|
|
1358
|
+
"[:upper:]": ["\\p{Lu}"],
|
|
1359
|
+
"[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}"],
|
|
1360
|
+
"[:xdigit:]": ["A-Fa-f0-9"]
|
|
1361
|
+
};
|
|
1362
|
+
const braceEscape = (s) => s.replace(/[[\]\\-]/g, "\\$&");
|
|
1363
|
+
const noMatch = /$./;
|
|
1364
|
+
const parseClass = (glob, position, nocase = false, form) => {
|
|
1365
|
+
const norm = (c) => {
|
|
1366
|
+
const n = form ? c.normalize(form) : c;
|
|
1367
|
+
return [...n].length === 1 ? n : c;
|
|
1368
|
+
};
|
|
1369
|
+
const pos = position;
|
|
1370
|
+
/* c8 ignore start */
|
|
1371
|
+
if (glob.charAt(pos) !== "[") throw new Error("not in a brace expression");
|
|
1372
|
+
/* c8 ignore stop */
|
|
1373
|
+
const ranges = [];
|
|
1374
|
+
const negs = [];
|
|
1375
|
+
let i = pos + 1;
|
|
1376
|
+
let sawStart = false;
|
|
1377
|
+
let escaping = false;
|
|
1378
|
+
let negate = false;
|
|
1379
|
+
let endPos = pos;
|
|
1380
|
+
let rangeStart = "";
|
|
1381
|
+
WHILE: while (i < glob.length) {
|
|
1382
|
+
const c = String.fromCodePoint(glob.codePointAt(i));
|
|
1383
|
+
if ((c === "!" || c === "^") && i === pos + 1) {
|
|
1384
|
+
negate = true;
|
|
1385
|
+
i++;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
if (c === "]" && sawStart && !escaping) {
|
|
1389
|
+
endPos = i + 1;
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
sawStart = true;
|
|
1393
|
+
if (c === "\\") {
|
|
1394
|
+
if (!escaping) {
|
|
1395
|
+
escaping = true;
|
|
1396
|
+
i++;
|
|
1397
|
+
continue;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
if (c === "[" && !escaping) {
|
|
1401
|
+
for (const [cls, [unip, neg]] of Object.entries(posixClasses)) if (glob.startsWith(cls, i)) {
|
|
1402
|
+
if (rangeStart) return [noMatch, glob.length - pos];
|
|
1403
|
+
i += cls.length;
|
|
1404
|
+
if (neg) negs.push(unip);
|
|
1405
|
+
else ranges.push(unip);
|
|
1406
|
+
continue WHILE;
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
escaping = false;
|
|
1410
|
+
const n = norm(c);
|
|
1411
|
+
if (rangeStart) {
|
|
1412
|
+
if (n.codePointAt(0) > rangeStart.codePointAt(0)) ranges.push(braceEscape(rangeStart) + "-" + braceEscape(n));
|
|
1413
|
+
else if (n === rangeStart) ranges.push(braceEscape(n));
|
|
1414
|
+
rangeStart = "";
|
|
1415
|
+
i += c.length;
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
if (glob.startsWith("-]", i + c.length)) {
|
|
1419
|
+
ranges.push(braceEscape(n + "-"));
|
|
1420
|
+
i += c.length + 1;
|
|
1421
|
+
continue;
|
|
1422
|
+
}
|
|
1423
|
+
if (glob.startsWith("-", i + c.length)) {
|
|
1424
|
+
rangeStart = n;
|
|
1425
|
+
i += c.length + 1;
|
|
1426
|
+
continue;
|
|
1427
|
+
}
|
|
1428
|
+
ranges.push(braceEscape(n));
|
|
1429
|
+
i += c.length;
|
|
1430
|
+
}
|
|
1431
|
+
if (endPos < i) return [noMatch, 0];
|
|
1432
|
+
if (!ranges.length && !negs.length) return [noMatch, glob.length - pos];
|
|
1433
|
+
const sranges = "[" + (negate ? "^" : "") + ranges.join("") + "]";
|
|
1434
|
+
const snegs = "[" + (negate ? "" : "^") + negs.join("") + "]";
|
|
1435
|
+
const comb = "^" + (ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs);
|
|
1436
|
+
return [new RegExp(comb, nocase ? "iu" : "u"), endPos - pos];
|
|
1437
|
+
};
|
|
1438
|
+
// ../../node_modules/.pnpm/@isaacs+nonrecursive-glob-match@1.1.0/node_modules/@isaacs/nonrecursive-glob-match/dist/esm/index.js
|
|
1439
|
+
const MATCH = {
|
|
1440
|
+
t: "match",
|
|
1441
|
+
id: 0
|
|
1442
|
+
};
|
|
1443
|
+
const extTypes = "!?+*@";
|
|
1444
|
+
const lit = (ch) => ({
|
|
1445
|
+
t: "lit",
|
|
1446
|
+
ch
|
|
1447
|
+
});
|
|
1448
|
+
const reEscape = (s) => s.replace(/[\\^$.*+?()[\]{}|/]/g, "\\$&");
|
|
1449
|
+
const newFoldRe = (s) => new RegExp(`^${reEscape(s)}$`, "iu");
|
|
1450
|
+
const foldCache = /* @__PURE__ */ new Map();
|
|
1451
|
+
const foldRe = (ch) => {
|
|
1452
|
+
let re = foldCache.get(ch);
|
|
1453
|
+
if (!re) {
|
|
1454
|
+
re = newFoldRe(ch);
|
|
1455
|
+
if (foldCache.size >= 1e3) foldCache.clear();
|
|
1456
|
+
foldCache.set(ch, re);
|
|
1457
|
+
}
|
|
1458
|
+
return re;
|
|
1459
|
+
};
|
|
1460
|
+
const litMatch = (l, c) => {
|
|
1461
|
+
if (c === l.ch) return true;
|
|
1462
|
+
if (!l.re) return false;
|
|
1463
|
+
const code = c.charCodeAt(0);
|
|
1464
|
+
if (code >= 128) return l.re.test(c);
|
|
1465
|
+
const ascii = l.ascii ??= /* @__PURE__ */ new Uint8Array(128);
|
|
1466
|
+
ascii[code] ||= l.re.test(c) ? 1 : 2;
|
|
1467
|
+
return ascii[code] === 1;
|
|
1468
|
+
};
|
|
1469
|
+
const tokenize = (p, nocase, noext, form, mark) => {
|
|
1470
|
+
const toks = [];
|
|
1471
|
+
for (let i = 0; i < p.length;) {
|
|
1472
|
+
const c = String.fromCodePoint(p.codePointAt(i));
|
|
1473
|
+
if (mark) {
|
|
1474
|
+
const m = c === "\\" && p.startsWith(mark, i + 1) ? 1 : 0;
|
|
1475
|
+
if (m || c === mark) {
|
|
1476
|
+
const start = i + m + mark.length;
|
|
1477
|
+
const end = p.indexOf(mark, start);
|
|
1478
|
+
const r = /^(-?\d+)\.\.(-?\d+)$/.exec(p.slice(start, end));
|
|
1479
|
+
const alts = end !== -1 && r && numericRange(r[1], r[2]);
|
|
1480
|
+
if (alts) {
|
|
1481
|
+
toks.push({
|
|
1482
|
+
t: "ext",
|
|
1483
|
+
type: "@",
|
|
1484
|
+
alts
|
|
1485
|
+
});
|
|
1486
|
+
i = end + mark.length;
|
|
1487
|
+
continue;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (c === "\\") {
|
|
1492
|
+
const e = p.codePointAt(i + 1);
|
|
1493
|
+
const ch = e === void 0 ? c : String.fromCodePoint(e);
|
|
1494
|
+
toks.push(lit(ch));
|
|
1495
|
+
i += 1 + ch.length;
|
|
1496
|
+
continue;
|
|
1497
|
+
}
|
|
1498
|
+
if (c === "[") {
|
|
1499
|
+
const [re, consumed] = parseClass(p, i, nocase, form);
|
|
1500
|
+
if (consumed) {
|
|
1501
|
+
toks.push({
|
|
1502
|
+
t: "class",
|
|
1503
|
+
re
|
|
1504
|
+
});
|
|
1505
|
+
i += consumed;
|
|
1506
|
+
continue;
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
if (!noext && extTypes.includes(c) && p[i + 1] === "(") {
|
|
1510
|
+
toks.push({
|
|
1511
|
+
t: "open",
|
|
1512
|
+
type: c
|
|
1513
|
+
});
|
|
1514
|
+
i += 2;
|
|
1515
|
+
continue;
|
|
1516
|
+
}
|
|
1517
|
+
toks.push(!noext && c === "|" ? { t: "bar" } : !noext && c === ")" ? { t: "close" } : c === "*" ? { t: "star" } : c === "?" ? { t: "any" } : lit(c));
|
|
1518
|
+
i += c.length;
|
|
1519
|
+
}
|
|
1520
|
+
return toks;
|
|
1521
|
+
};
|
|
1522
|
+
const pair = (toks) => {
|
|
1523
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
1524
|
+
const stack = [];
|
|
1525
|
+
toks.forEach((tok, i) => {
|
|
1526
|
+
if (tok.t === "open") stack.push(i);
|
|
1527
|
+
else if (tok.t === "close" && stack.length) pairs.set(stack.pop(), i);
|
|
1528
|
+
});
|
|
1529
|
+
return pairs;
|
|
1530
|
+
};
|
|
1531
|
+
const build = (toks, pairs, start, end, top) => {
|
|
1532
|
+
let seq = [];
|
|
1533
|
+
const alts = [seq];
|
|
1534
|
+
for (let i = start; i < end; i++) {
|
|
1535
|
+
const tok = toks[i];
|
|
1536
|
+
const close = pairs.get(i);
|
|
1537
|
+
if (tok.t === "open" && close !== void 0) {
|
|
1538
|
+
const sub = build(toks, pairs, i + 1, close, false);
|
|
1539
|
+
seq.push({
|
|
1540
|
+
t: "ext",
|
|
1541
|
+
type: tok.type,
|
|
1542
|
+
alts: sub
|
|
1543
|
+
});
|
|
1544
|
+
i = close;
|
|
1545
|
+
} else if (tok.t === "bar" && !top) alts.push(seq = []);
|
|
1546
|
+
else if (tok.t === "open") seq.push(lit(tok.type), lit("("));
|
|
1547
|
+
else if (tok.t === "bar") seq.push(lit("|"));
|
|
1548
|
+
else if (tok.t === "close") seq.push(lit(")"));
|
|
1549
|
+
else seq.push(tok);
|
|
1550
|
+
}
|
|
1551
|
+
return alts;
|
|
1552
|
+
};
|
|
1553
|
+
const normalize = (items, form) => {
|
|
1554
|
+
const out = [];
|
|
1555
|
+
let run = "";
|
|
1556
|
+
const flush = () => {
|
|
1557
|
+
for (const ch of run.normalize(form)) out.push(lit(ch));
|
|
1558
|
+
run = "";
|
|
1559
|
+
};
|
|
1560
|
+
for (const it of items) {
|
|
1561
|
+
if (it.t === "lit") {
|
|
1562
|
+
run += it.ch;
|
|
1563
|
+
continue;
|
|
1564
|
+
}
|
|
1565
|
+
flush();
|
|
1566
|
+
out.push(it.t === "ext" ? {
|
|
1567
|
+
...it,
|
|
1568
|
+
alts: it.alts.map((a) => normalize(a, form))
|
|
1569
|
+
} : it);
|
|
1570
|
+
}
|
|
1571
|
+
flush();
|
|
1572
|
+
return out;
|
|
1573
|
+
};
|
|
1574
|
+
const compile = (items, nocase) => {
|
|
1575
|
+
let id = 1;
|
|
1576
|
+
const split = (out) => ({
|
|
1577
|
+
t: "split",
|
|
1578
|
+
id: id++,
|
|
1579
|
+
out
|
|
1580
|
+
});
|
|
1581
|
+
const seq = (items, next) => items.reduceRight((next, it) => item(it, next), next);
|
|
1582
|
+
const item = (it, next) => {
|
|
1583
|
+
switch (it.t) {
|
|
1584
|
+
case "lit":
|
|
1585
|
+
const re = nocase ? foldRe(it.ch) : void 0;
|
|
1586
|
+
return {
|
|
1587
|
+
t: "lit",
|
|
1588
|
+
id: id++,
|
|
1589
|
+
ch: it.ch,
|
|
1590
|
+
re,
|
|
1591
|
+
next
|
|
1592
|
+
};
|
|
1593
|
+
case "any":
|
|
1594
|
+
case "star": return {
|
|
1595
|
+
t: it.t,
|
|
1596
|
+
id: id++,
|
|
1597
|
+
next
|
|
1598
|
+
};
|
|
1599
|
+
case "class": return {
|
|
1600
|
+
t: "class",
|
|
1601
|
+
id: id++,
|
|
1602
|
+
re: it.re,
|
|
1603
|
+
next
|
|
1604
|
+
};
|
|
1605
|
+
}
|
|
1606
|
+
const alts = (next) => it.alts.map((a) => seq(a, next));
|
|
1607
|
+
switch (it.type) {
|
|
1608
|
+
case "@": return split(alts(next));
|
|
1609
|
+
case "?": return split([next, ...alts(next)]);
|
|
1610
|
+
case "!": return {
|
|
1611
|
+
t: "neg",
|
|
1612
|
+
id: id++,
|
|
1613
|
+
sub: split(alts(MATCH)),
|
|
1614
|
+
next
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
const after = split([]);
|
|
1618
|
+
const entry = split(alts(after));
|
|
1619
|
+
after.out.push(next, entry);
|
|
1620
|
+
return it.type === "*" ? after : entry;
|
|
1621
|
+
};
|
|
1622
|
+
return [seq(items, MATCH), id];
|
|
1623
|
+
};
|
|
1624
|
+
const show = (start) => {
|
|
1625
|
+
const lines = [];
|
|
1626
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1627
|
+
const ref = (n) => n.t === "match" ? "match" : String(n.id);
|
|
1628
|
+
const walk = (n, indent) => {
|
|
1629
|
+
if (n.t === "match" || seen.has(n)) return;
|
|
1630
|
+
seen.add(n);
|
|
1631
|
+
const line = (desc) => lines.push(`${indent}${n.id}: ${desc}`);
|
|
1632
|
+
switch (n.t) {
|
|
1633
|
+
case "split":
|
|
1634
|
+
line(`split -> ${n.out.map(ref).join(", ")}`);
|
|
1635
|
+
for (const o of n.out) walk(o, indent);
|
|
1636
|
+
return;
|
|
1637
|
+
case "neg":
|
|
1638
|
+
line(`!(${ref(n.sub)}) -> ${ref(n.next)}`);
|
|
1639
|
+
walk(n.sub, indent + " ");
|
|
1640
|
+
return walk(n.next, indent);
|
|
1641
|
+
case "lit":
|
|
1642
|
+
line(`${JSON.stringify(n.ch)} -> ${ref(n.next)}`);
|
|
1643
|
+
break;
|
|
1644
|
+
case "class":
|
|
1645
|
+
line(`${n.re} -> ${ref(n.next)}`);
|
|
1646
|
+
break;
|
|
1647
|
+
default: line(`${n.t === "any" ? "?" : "*"} -> ${ref(n.next)}`);
|
|
1648
|
+
}
|
|
1649
|
+
walk(n.next, indent);
|
|
1650
|
+
};
|
|
1651
|
+
walk(start, "");
|
|
1652
|
+
return [`start -> ${ref(start)}`, ...lines].join("\n");
|
|
1653
|
+
};
|
|
1654
|
+
var State = class {
|
|
1655
|
+
gen;
|
|
1656
|
+
threads = [];
|
|
1657
|
+
match = false;
|
|
1658
|
+
runs = [];
|
|
1659
|
+
ids = [];
|
|
1660
|
+
constructor(gen) {
|
|
1661
|
+
this.gen = gen;
|
|
1662
|
+
}
|
|
1663
|
+
get dead() {
|
|
1664
|
+
return !this.threads.length && !this.match && !this.runs.length;
|
|
1665
|
+
}
|
|
1666
|
+
};
|
|
1667
|
+
const sameState = (a, b) => {
|
|
1668
|
+
if (a.ids.length !== b.ids.length) return false;
|
|
1669
|
+
if (a.runs.length !== b.runs.length) return false;
|
|
1670
|
+
if (a.ids.some((id, i) => id !== b.ids[i])) return false;
|
|
1671
|
+
return a.runs.every((r) => b.runs.some((o) => o.neg === r.neg && sameState(o.state, r.state)));
|
|
1672
|
+
};
|
|
1673
|
+
const marks = (size) => ({
|
|
1674
|
+
has: new Float64Array(size),
|
|
1675
|
+
seen: new Float64Array(size),
|
|
1676
|
+
gen: 0
|
|
1677
|
+
});
|
|
1678
|
+
var Sim = class {
|
|
1679
|
+
dots;
|
|
1680
|
+
dotStart;
|
|
1681
|
+
#marks;
|
|
1682
|
+
constructor(dots, dotStart, marks) {
|
|
1683
|
+
this.dots = dots;
|
|
1684
|
+
this.dotStart = dotStart;
|
|
1685
|
+
this.#marks = marks;
|
|
1686
|
+
}
|
|
1687
|
+
state() {
|
|
1688
|
+
return new State(++this.#marks.gen);
|
|
1689
|
+
}
|
|
1690
|
+
done(state) {
|
|
1691
|
+
state.ids = state.threads.map((n) => n.id).sort((a, b) => a - b);
|
|
1692
|
+
if (state.match) state.ids.unshift(MATCH.id);
|
|
1693
|
+
return state;
|
|
1694
|
+
}
|
|
1695
|
+
#visit(state, node) {
|
|
1696
|
+
const { seen } = this.#marks;
|
|
1697
|
+
if (seen[node.id] === state.gen) return false;
|
|
1698
|
+
seen[node.id] = state.gen;
|
|
1699
|
+
return true;
|
|
1700
|
+
}
|
|
1701
|
+
#addThread(state, node) {
|
|
1702
|
+
const { has } = this.#marks;
|
|
1703
|
+
if (has[node.id] === state.gen) return false;
|
|
1704
|
+
has[node.id] = state.gen;
|
|
1705
|
+
state.threads.push(node);
|
|
1706
|
+
return true;
|
|
1707
|
+
}
|
|
1708
|
+
restricted(i, top) {
|
|
1709
|
+
return top && (this.dots || this.dotStart && i === 0);
|
|
1710
|
+
}
|
|
1711
|
+
add(state, node, i, top) {
|
|
1712
|
+
switch (node.t) {
|
|
1713
|
+
case "split":
|
|
1714
|
+
if (!this.#visit(state, node)) return;
|
|
1715
|
+
for (const o of node.out) this.add(state, o, i, top);
|
|
1716
|
+
return;
|
|
1717
|
+
case "neg":
|
|
1718
|
+
if (!this.#visit(state, node)) return;
|
|
1719
|
+
const sub = this.state();
|
|
1720
|
+
this.add(sub, node.sub, i, false);
|
|
1721
|
+
this.done(sub);
|
|
1722
|
+
return this.addRun(state, {
|
|
1723
|
+
t: "run",
|
|
1724
|
+
neg: node,
|
|
1725
|
+
state: sub
|
|
1726
|
+
}, i, top);
|
|
1727
|
+
case "star":
|
|
1728
|
+
if (this.restricted(i, top)) return;
|
|
1729
|
+
if (this.#addThread(state, node)) this.add(state, node.next, i, top);
|
|
1730
|
+
return;
|
|
1731
|
+
case "match":
|
|
1732
|
+
state.match = true;
|
|
1733
|
+
return;
|
|
1734
|
+
default: this.#addThread(state, node);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
addRun(state, run, i, top) {
|
|
1738
|
+
for (const r of state.runs) if (r.neg === run.neg && sameState(r.state, run.state)) return;
|
|
1739
|
+
state.runs.push(run);
|
|
1740
|
+
if (!run.state.match) this.add(state, run.neg.next, i, top);
|
|
1741
|
+
}
|
|
1742
|
+
step(state, c, i, top) {
|
|
1743
|
+
const next = this.state();
|
|
1744
|
+
for (const th of state.threads) switch (th.t) {
|
|
1745
|
+
case "lit":
|
|
1746
|
+
if (litMatch(th, c)) this.add(next, th.next, i + 1, top);
|
|
1747
|
+
break;
|
|
1748
|
+
case "any":
|
|
1749
|
+
if (!this.restricted(i, top)) this.add(next, th.next, i + 1, top);
|
|
1750
|
+
break;
|
|
1751
|
+
case "class":
|
|
1752
|
+
if (!this.restricted(i, top) && th.re.test(c)) this.add(next, th.next, i + 1, top);
|
|
1753
|
+
break;
|
|
1754
|
+
case "star": if (!this.restricted(i, top)) this.add(next, th, i + 1, top);
|
|
1755
|
+
}
|
|
1756
|
+
if (!this.restricted(i, top)) for (const run of state.runs) {
|
|
1757
|
+
if (run.state.dead) {
|
|
1758
|
+
this.addRun(next, run, i + 1, top);
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
const sub = this.step(run.state, c, i, false);
|
|
1762
|
+
this.addRun(next, {
|
|
1763
|
+
t: "run",
|
|
1764
|
+
neg: run.neg,
|
|
1765
|
+
state: sub
|
|
1766
|
+
}, i + 1, top);
|
|
1767
|
+
}
|
|
1768
|
+
return this.done(next);
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
const stateKey = (state) => {
|
|
1772
|
+
const ids = state.ids.join();
|
|
1773
|
+
if (!state.runs.length) return ids;
|
|
1774
|
+
return `${ids}|${state.runs.map((r) => `${r.neg.id}(${stateKey(r.state)})`).sort().join("|")}`;
|
|
1775
|
+
};
|
|
1776
|
+
const DFA_BUDGET = 1 << 18;
|
|
1777
|
+
var Dfa = class {
|
|
1778
|
+
#start;
|
|
1779
|
+
#states = /* @__PURE__ */ new Map();
|
|
1780
|
+
#size = 0;
|
|
1781
|
+
#plain;
|
|
1782
|
+
#dotStart;
|
|
1783
|
+
#sim;
|
|
1784
|
+
#dotSim;
|
|
1785
|
+
constructor(start, marks) {
|
|
1786
|
+
this.#start = start;
|
|
1787
|
+
this.#sim = new Sim(false, false, marks);
|
|
1788
|
+
this.#dotSim = new Sim(false, true, marks);
|
|
1789
|
+
}
|
|
1790
|
+
#make(state) {
|
|
1791
|
+
return {
|
|
1792
|
+
state,
|
|
1793
|
+
match: state.match,
|
|
1794
|
+
dead: state.dead,
|
|
1795
|
+
next: /* @__PURE__ */ new Map()
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
#intern(state) {
|
|
1799
|
+
const key = stateKey(state);
|
|
1800
|
+
const found = this.#states.get(key);
|
|
1801
|
+
if (found) return found;
|
|
1802
|
+
if (this.#size > DFA_BUDGET) this.#clear();
|
|
1803
|
+
const d = this.#make(state);
|
|
1804
|
+
this.#states.set(key, d);
|
|
1805
|
+
this.#size += key.length + 1;
|
|
1806
|
+
return d;
|
|
1807
|
+
}
|
|
1808
|
+
#clear() {
|
|
1809
|
+
this.#states.clear();
|
|
1810
|
+
this.#size = 0;
|
|
1811
|
+
this.#plain = void 0;
|
|
1812
|
+
this.#dotStart = void 0;
|
|
1813
|
+
}
|
|
1814
|
+
start(dotStart) {
|
|
1815
|
+
if (dotStart) {
|
|
1816
|
+
if (this.#dotStart) return this.#dotStart;
|
|
1817
|
+
const state = this.#dotSim.state();
|
|
1818
|
+
this.#dotSim.add(state, this.#start, 0, true);
|
|
1819
|
+
return this.#dotStart = this.#make(this.#dotSim.done(state));
|
|
1820
|
+
}
|
|
1821
|
+
if (this.#plain) return this.#plain;
|
|
1822
|
+
const state = this.#sim.state();
|
|
1823
|
+
this.#sim.add(state, this.#start, 0, true);
|
|
1824
|
+
return this.#plain = this.#intern(this.#sim.done(state));
|
|
1825
|
+
}
|
|
1826
|
+
next(d, c) {
|
|
1827
|
+
const code = c.charCodeAt(0);
|
|
1828
|
+
const found = code < 128 ? void 0 : d.next.get(c);
|
|
1829
|
+
if (found) return found;
|
|
1830
|
+
const n = d === this.#dotStart ? this.#intern(this.#dotSim.step(d.state, c, 0, true)) : this.#intern(this.#sim.step(d.state, c, 1, true));
|
|
1831
|
+
if (code < 128) {
|
|
1832
|
+
if (!d.ascii) {
|
|
1833
|
+
d.ascii = new Array(128);
|
|
1834
|
+
this.#size += 128;
|
|
1835
|
+
}
|
|
1836
|
+
d.ascii[code] = n;
|
|
1837
|
+
} else d.next.set(c, n);
|
|
1838
|
+
this.#size++;
|
|
1839
|
+
return n;
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
const linear = (start) => {
|
|
1843
|
+
const nodes = [];
|
|
1844
|
+
for (let n = start; n.t !== "match"; n = n.next) {
|
|
1845
|
+
if (n.t === "split" || n.t === "neg") return void 0;
|
|
1846
|
+
nodes.push(n);
|
|
1847
|
+
}
|
|
1848
|
+
return nodes;
|
|
1849
|
+
};
|
|
1850
|
+
const testLinear = (nodes, chars, start, end) => {
|
|
1851
|
+
let ni = 0;
|
|
1852
|
+
let ci = start;
|
|
1853
|
+
let starNi = -1;
|
|
1854
|
+
let starCi = 0;
|
|
1855
|
+
while (ci < end) {
|
|
1856
|
+
const n = nodes[ni];
|
|
1857
|
+
if (n?.t === "star") {
|
|
1858
|
+
starNi = ni++;
|
|
1859
|
+
starCi = ci;
|
|
1860
|
+
continue;
|
|
1861
|
+
}
|
|
1862
|
+
const c = chars[ci];
|
|
1863
|
+
if (n && (n.t === "any" || n.t === "lit" && litMatch(n, c) || n.t === "class" && n.re.test(c))) {
|
|
1864
|
+
ni++;
|
|
1865
|
+
ci++;
|
|
1866
|
+
continue;
|
|
1867
|
+
}
|
|
1868
|
+
if (starNi === -1) return false;
|
|
1869
|
+
ni = starNi + 1;
|
|
1870
|
+
ci = ++starCi;
|
|
1871
|
+
}
|
|
1872
|
+
while (nodes[ni]?.t === "star") ni++;
|
|
1873
|
+
return ni === nodes.length;
|
|
1874
|
+
};
|
|
1875
|
+
const lengths = (items) => {
|
|
1876
|
+
let min = 0;
|
|
1877
|
+
let max = 0;
|
|
1878
|
+
for (const it of items) {
|
|
1879
|
+
const [lo, hi] = itemLengths(it);
|
|
1880
|
+
min += lo;
|
|
1881
|
+
max += hi;
|
|
1882
|
+
}
|
|
1883
|
+
return [min, max];
|
|
1884
|
+
};
|
|
1885
|
+
const itemLengths = (it) => {
|
|
1886
|
+
if (it.t === "star") return [0, Infinity];
|
|
1887
|
+
if (it.t !== "ext") return [1, 1];
|
|
1888
|
+
if (it.type === "!") return [0, Infinity];
|
|
1889
|
+
const alts = it.alts.map(lengths);
|
|
1890
|
+
const min = Math.min(...alts.map((a) => a[0]));
|
|
1891
|
+
const max = Math.max(...alts.map((a) => a[1]));
|
|
1892
|
+
const loop = max === 0 ? 0 : Infinity;
|
|
1893
|
+
return it.type === "@" ? [min, max] : it.type === "?" ? [0, max] : it.type === "*" ? [0, loop] : [min, loop];
|
|
1894
|
+
};
|
|
1895
|
+
const hasAffix = (lits, chars, start) => {
|
|
1896
|
+
for (let j = 0; j < lits.length; j++) if (!litMatch(lits[j], chars[start + j])) return false;
|
|
1897
|
+
return true;
|
|
1898
|
+
};
|
|
1899
|
+
const slashOrSurrogate = /[/\ud800-\udfff]/;
|
|
1900
|
+
const surrogate = /[\ud800-\udfff]/;
|
|
1901
|
+
const codePoints = (s) => surrogate.test(s) ? [...s] : s;
|
|
1902
|
+
const noSlash = (s) => {
|
|
1903
|
+
if (s.includes("/")) throw new Error("can only match a single path portion, got: " + s);
|
|
1904
|
+
};
|
|
1905
|
+
var Matcher = class {
|
|
1906
|
+
pattern;
|
|
1907
|
+
options;
|
|
1908
|
+
#start;
|
|
1909
|
+
#size;
|
|
1910
|
+
#marks;
|
|
1911
|
+
#dotsSim;
|
|
1912
|
+
#literal;
|
|
1913
|
+
#literalFold = false;
|
|
1914
|
+
#literalRe;
|
|
1915
|
+
#linear;
|
|
1916
|
+
#wild = false;
|
|
1917
|
+
#min = 0;
|
|
1918
|
+
#max = Infinity;
|
|
1919
|
+
#prefix = [];
|
|
1920
|
+
#suffix = [];
|
|
1921
|
+
#prefixStr;
|
|
1922
|
+
#suffixStr;
|
|
1923
|
+
#affix = false;
|
|
1924
|
+
#dfa;
|
|
1925
|
+
#form;
|
|
1926
|
+
constructor(pattern, options = {}) {
|
|
1927
|
+
if (pattern.includes("/")) throw new Error("can only match a single path portion, got pattern: " + pattern);
|
|
1928
|
+
this.pattern = pattern;
|
|
1929
|
+
this.options = options;
|
|
1930
|
+
const { nocase = false, noext = false, normalize: n } = options;
|
|
1931
|
+
this.#form = n === true ? "NFC" : n || void 0;
|
|
1932
|
+
const literal = /^[?*+@]\(\)$/.test(pattern);
|
|
1933
|
+
const toks = tokenize(pattern, nocase, noext || literal, this.#form, options.rangeMark);
|
|
1934
|
+
let [items] = build(toks, pair(toks), 0, toks.length, true);
|
|
1935
|
+
if (this.#form) items = normalize(items, this.#form);
|
|
1936
|
+
const [start, size] = compile(items, nocase);
|
|
1937
|
+
this.#start = start;
|
|
1938
|
+
this.#size = size;
|
|
1939
|
+
if (items.every((it) => it.t === "lit")) {
|
|
1940
|
+
this.#literal = items.map((it) => it.ch).join("");
|
|
1941
|
+
this.#literalFold = nocase;
|
|
1942
|
+
} else {
|
|
1943
|
+
const lit = (it) => it.t !== "lit" ? void 0 : nocase ? {
|
|
1944
|
+
ch: it.ch,
|
|
1945
|
+
re: foldRe(it.ch)
|
|
1946
|
+
} : { ch: it.ch };
|
|
1947
|
+
for (const it of items) {
|
|
1948
|
+
const l = lit(it);
|
|
1949
|
+
if (!l) break;
|
|
1950
|
+
this.#prefix.push(l);
|
|
1951
|
+
}
|
|
1952
|
+
for (let j = items.length - 1; j >= 0; j--) {
|
|
1953
|
+
const l = lit(items[j]);
|
|
1954
|
+
if (!l) break;
|
|
1955
|
+
this.#suffix.unshift(l);
|
|
1956
|
+
}
|
|
1957
|
+
this.#affix = !!(this.#prefix.length || this.#suffix.length);
|
|
1958
|
+
if (!nocase) {
|
|
1959
|
+
this.#prefixStr = this.#prefix.map((l) => l.ch).join("");
|
|
1960
|
+
this.#suffixStr = this.#suffix.map((l) => l.ch).join("");
|
|
1961
|
+
}
|
|
1962
|
+
this.#linear = linear(this.#start)?.slice(this.#prefix.length, -this.#suffix.length || void 0);
|
|
1963
|
+
this.#wild = !!this.#linear?.every((n) => n.t === "star" || n.t === "any");
|
|
1964
|
+
const [min, max] = lengths(items);
|
|
1965
|
+
this.#min = min;
|
|
1966
|
+
this.#max = max;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
test(s) {
|
|
1970
|
+
if (this.#form) {
|
|
1971
|
+
noSlash(s);
|
|
1972
|
+
return this.#test(s.normalize(this.#form));
|
|
1973
|
+
}
|
|
1974
|
+
if (slashOrSurrogate.test(s)) {
|
|
1975
|
+
noSlash(s);
|
|
1976
|
+
return this.#test(s, [...s]);
|
|
1977
|
+
}
|
|
1978
|
+
return this.#test(s, s);
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* The same as {@link Matcher#test}, but the string is not checked
|
|
1982
|
+
* for `/` chars, so the result for a string that has one is not
|
|
1983
|
+
* defined. Only use it for a string that is known to be one path
|
|
1984
|
+
* portion, such as a part of a path that was split on `/`. It can
|
|
1985
|
+
* be faster, because some patterns do not need to look at each char
|
|
1986
|
+
* of the string.
|
|
1987
|
+
*/
|
|
1988
|
+
testUnchecked(s) {
|
|
1989
|
+
return this.#test(this.#form ? s.normalize(this.#form) : s);
|
|
1990
|
+
}
|
|
1991
|
+
#test(s, chars) {
|
|
1992
|
+
if (this.#literal !== void 0) return this.#literalFold ? (this.#literalRe ??= newFoldRe(this.#literal)).test(s) : s === this.#literal;
|
|
1993
|
+
const min = this.#min;
|
|
1994
|
+
const max = this.#max;
|
|
1995
|
+
if (chars === void 0) {
|
|
1996
|
+
const most = s.length;
|
|
1997
|
+
const least = most + 1 >> 1;
|
|
1998
|
+
if (most < min || least > max) return false;
|
|
1999
|
+
if (least < min || most > max) chars = codePoints(s);
|
|
2000
|
+
}
|
|
2001
|
+
if (chars !== void 0 && (chars.length < min || chars.length > max)) return false;
|
|
2002
|
+
const prefix = this.#prefix.length;
|
|
2003
|
+
if (this.#affix) {
|
|
2004
|
+
if (this.#prefixStr !== void 0 && this.#suffixStr !== void 0) {
|
|
2005
|
+
if (!s.startsWith(this.#prefixStr) || !s.endsWith(this.#suffixStr)) return false;
|
|
2006
|
+
} else {
|
|
2007
|
+
chars ??= codePoints(s);
|
|
2008
|
+
const end = chars.length - this.#suffix.length;
|
|
2009
|
+
if (!hasAffix(this.#prefix, chars, 0) || !hasAffix(this.#suffix, chars, end)) return false;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
const dotStart = !this.options.dot && s.startsWith(".");
|
|
2013
|
+
if (this.#linear) {
|
|
2014
|
+
if (s === "." || s === "..") return false;
|
|
2015
|
+
if (dotStart && !prefix) return false;
|
|
2016
|
+
if (this.#wild) return true;
|
|
2017
|
+
chars ??= codePoints(s);
|
|
2018
|
+
const end = chars.length - this.#suffix.length;
|
|
2019
|
+
return testLinear(this.#linear, chars, prefix, end);
|
|
2020
|
+
}
|
|
2021
|
+
chars ??= codePoints(s);
|
|
2022
|
+
if (s === "." || s === "..") {
|
|
2023
|
+
this.#marks ??= marks(this.#size);
|
|
2024
|
+
const sim = this.#dotsSim ??= new Sim(true, false, this.#marks);
|
|
2025
|
+
const start = sim.state();
|
|
2026
|
+
sim.add(start, this.#start, 0, true);
|
|
2027
|
+
let state = sim.done(start);
|
|
2028
|
+
for (let i = 0; i < chars.length; i++) state = sim.step(state, chars[i], i, true);
|
|
2029
|
+
return state.match;
|
|
2030
|
+
}
|
|
2031
|
+
this.#marks ??= marks(this.#size);
|
|
2032
|
+
const dfa = this.#dfa ??= new Dfa(this.#start, this.#marks);
|
|
2033
|
+
let d = dfa.start(dotStart);
|
|
2034
|
+
const str = chars === s;
|
|
2035
|
+
for (let i = 0; i < chars.length; i++) {
|
|
2036
|
+
if (d.dead) return false;
|
|
2037
|
+
const code = str ? s.charCodeAt(i) : chars[i].charCodeAt(0);
|
|
2038
|
+
d = d.ascii?.[code] ?? dfa.next(d, chars[i]);
|
|
2039
|
+
}
|
|
2040
|
+
return d.match;
|
|
2041
|
+
}
|
|
2042
|
+
/** a readable listing of the state machine */
|
|
2043
|
+
toString() {
|
|
2044
|
+
return show(this.#start);
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/assert-valid-pattern.js
|
|
2048
|
+
const MAX_PATTERN_LENGTH = 65536;
|
|
2049
|
+
const assertValidPattern = (pattern) => {
|
|
2050
|
+
if (typeof pattern !== "string") throw new TypeError("invalid pattern");
|
|
2051
|
+
if (pattern.length > MAX_PATTERN_LENGTH) throw new TypeError("pattern is too long");
|
|
2052
|
+
};
|
|
2053
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/escape.js
|
|
2054
|
+
/**
|
|
2055
|
+
* Escape all magic characters in a glob pattern.
|
|
2056
|
+
*
|
|
2057
|
+
* If the {@link MinimatchOptions.windowsPathsNoEscape}
|
|
2058
|
+
* option is used, then characters are escaped by wrapping in `[]`, because
|
|
2059
|
+
* a magic character wrapped in a character class can only be satisfied by
|
|
2060
|
+
* that exact character. In this mode, `\` is _not_ escaped, because it is
|
|
2061
|
+
* not interpreted as a magic character, but instead as a path separator.
|
|
2062
|
+
*
|
|
2063
|
+
* If the {@link MinimatchOptions.magicalBraces} option is used,
|
|
2064
|
+
* then braces (`{` and `}`) will be escaped.
|
|
2065
|
+
*
|
|
2066
|
+
* A leading `#` or `!` is escaped as well, so that the result is never a
|
|
2067
|
+
* comment or a negated pattern. In `windowsPathsNoEscape` mode, a leading
|
|
2068
|
+
* `!` is written as `@(!)`, because `[!` starts a negated class.
|
|
2069
|
+
*/
|
|
2070
|
+
const escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {}) => {
|
|
2071
|
+
const e = magicalBraces ? windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&") : windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&");
|
|
2072
|
+
const c = e.charAt(0);
|
|
2073
|
+
if (c === "#") return (windowsPathsNoEscape ? "[#]" : "\\#") + e.slice(1);
|
|
2074
|
+
if (c === "!") return (windowsPathsNoEscape ? "@(!)" : "\\!") + e.slice(1);
|
|
2075
|
+
return e;
|
|
2076
|
+
};
|
|
2077
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/unescape.js
|
|
2078
|
+
/**
|
|
2079
|
+
* Un-escape a string that has been escaped with {@link escape}.
|
|
2080
|
+
*
|
|
2081
|
+
* If the {@link MinimatchOptions.windowsPathsNoEscape} option is used, then
|
|
2082
|
+
* square-bracket escapes are removed, but not backslash escapes.
|
|
2083
|
+
*
|
|
2084
|
+
* For example, it will turn the string `'[*]'` into `*`, but it will not
|
|
2085
|
+
* turn `'\\*'` into `'*'`, because `\` is a path separator in
|
|
2086
|
+
* `windowsPathsNoEscape` mode.
|
|
2087
|
+
*
|
|
2088
|
+
* When `windowsPathsNoEscape` is not set, then both square-bracket escapes and
|
|
2089
|
+
* backslash escapes are removed.
|
|
2090
|
+
*
|
|
2091
|
+
* Slashes (and backslashes in `windowsPathsNoEscape` mode) cannot be escaped
|
|
2092
|
+
* or unescaped.
|
|
2093
|
+
*
|
|
2094
|
+
* When `magicalBraces` is not set, escapes of braces (`{` and `}`) will not be
|
|
2095
|
+
* unescaped.
|
|
2096
|
+
*/
|
|
2097
|
+
const unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {}) => {
|
|
2098
|
+
if (windowsPathsNoEscape && s.startsWith("@(!)")) return "!" + unescape(s.slice(4), {
|
|
2099
|
+
windowsPathsNoEscape,
|
|
2100
|
+
magicalBraces
|
|
2101
|
+
});
|
|
2102
|
+
if (magicalBraces) return windowsPathsNoEscape ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1");
|
|
2103
|
+
return windowsPathsNoEscape ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
|
|
2104
|
+
};
|
|
2105
|
+
// ../../node_modules/.pnpm/minimatch@11.0.9/node_modules/minimatch/dist/esm/index.js
|
|
2106
|
+
const DEFAULT_BRACE_EXPAND_MAX = 1e5;
|
|
2107
|
+
const DEFAULT_GLOB_STAR_RECURSION_MAX = 200;
|
|
2108
|
+
const AWE_KEY = "allowWindowsEscape";
|
|
2109
|
+
const minimatch = (p, pattern, options) => {
|
|
2110
|
+
assertValidPattern(pattern);
|
|
2111
|
+
if (!options?.nocomment && pattern.charAt(0) === "#") return false;
|
|
2112
|
+
return cachedMinimatch(pattern, options).match(p);
|
|
2113
|
+
};
|
|
2114
|
+
let cache = /* @__PURE__ */ new Map();
|
|
2115
|
+
let oldCache = /* @__PURE__ */ new Map();
|
|
2116
|
+
let cacheSize = 0;
|
|
2117
|
+
let cacheTotalWeight = 0;
|
|
2118
|
+
const cacheMax = 256;
|
|
2119
|
+
const cacheMaxWeight = 32768;
|
|
2120
|
+
const cacheMaxEntryWeight = 4096;
|
|
2121
|
+
const cacheWeight = (mm) => {
|
|
2122
|
+
let w = mm.pattern.length;
|
|
2123
|
+
for (const s of mm.globSet) {
|
|
2124
|
+
w += s.length + 1;
|
|
2125
|
+
if (w > cacheMaxEntryWeight) break;
|
|
2126
|
+
}
|
|
2127
|
+
return w;
|
|
2128
|
+
};
|
|
2129
|
+
const tri = (v) => v === void 0 ? 0 : v ? 2 : 1;
|
|
2130
|
+
const booleanWeights = new Map(Object.keys({
|
|
2131
|
+
nobrace: 0,
|
|
2132
|
+
nocomment: 0,
|
|
2133
|
+
nonegate: 0,
|
|
2134
|
+
noglobstar: 0,
|
|
2135
|
+
noext: 0,
|
|
2136
|
+
nonull: 0,
|
|
2137
|
+
partial: 0,
|
|
2138
|
+
dot: 0,
|
|
2139
|
+
nocase: 0,
|
|
2140
|
+
nocaseMagicOnly: 0,
|
|
2141
|
+
magicalBraces: 0,
|
|
2142
|
+
matchBase: 0,
|
|
2143
|
+
flipNegate: 0,
|
|
2144
|
+
preserveMultipleSlashes: 0,
|
|
2145
|
+
windowsNoMagicRoot: 0
|
|
2146
|
+
}).map((k, i) => [k, 24 * 3 ** i]));
|
|
2147
|
+
const optionsKey = (o) => {
|
|
2148
|
+
let n = 0;
|
|
2149
|
+
let wpe = false;
|
|
2150
|
+
for (const k in o) {
|
|
2151
|
+
const v = o[k];
|
|
2152
|
+
switch (k) {
|
|
2153
|
+
case "windowsPathsNoEscape":
|
|
2154
|
+
if (v) wpe = true;
|
|
2155
|
+
break;
|
|
2156
|
+
case AWE_KEY:
|
|
2157
|
+
if (v === false) wpe = true;
|
|
2158
|
+
break;
|
|
2159
|
+
case "platform": {
|
|
2160
|
+
const p = v || defaultPlatform;
|
|
2161
|
+
if (p === defaultPlatform) break;
|
|
2162
|
+
if (p === "darwin") n += 3;
|
|
2163
|
+
else if (p === "win32") n += 6;
|
|
2164
|
+
else if (p === "linux") n += 9;
|
|
2165
|
+
else return JSON.stringify(o);
|
|
2166
|
+
break;
|
|
2167
|
+
}
|
|
2168
|
+
case "optimizationLevel":
|
|
2169
|
+
if (v === void 0) break;
|
|
2170
|
+
n += v >= 2 ? 1 : v >= 1 ? 0 : 2;
|
|
2171
|
+
break;
|
|
2172
|
+
case "braceExpandMax":
|
|
2173
|
+
if (v !== void 0 && v !== DEFAULT_BRACE_EXPAND_MAX) return JSON.stringify(o);
|
|
2174
|
+
break;
|
|
2175
|
+
case "maxGlobstarRecursion":
|
|
2176
|
+
if (v !== void 0 && v !== DEFAULT_GLOB_STAR_RECURSION_MAX) return JSON.stringify(o);
|
|
2177
|
+
break;
|
|
2178
|
+
case "normalize":
|
|
2179
|
+
if (v !== void 0) return JSON.stringify(o);
|
|
2180
|
+
break;
|
|
2181
|
+
default: n += (booleanWeights.get(k) ?? 0) * tri(v);
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
return wpe ? n + 12 : n;
|
|
2185
|
+
};
|
|
2186
|
+
const copyOptions = (o) => {
|
|
2187
|
+
const copy = {};
|
|
2188
|
+
for (const k in o) copy[k] = o[k];
|
|
2189
|
+
return copy;
|
|
2190
|
+
};
|
|
2191
|
+
const cachedMinimatch = (pattern, options) => {
|
|
2192
|
+
const key = options ? optionsKey(options) : 0;
|
|
2193
|
+
let mm = cache.get(key)?.get(pattern);
|
|
2194
|
+
if (mm) return mm;
|
|
2195
|
+
mm = oldCache.get(key)?.get(pattern) ?? new Minimatch(pattern, copyOptions(options));
|
|
2196
|
+
const weight = cacheWeight(mm);
|
|
2197
|
+
if (weight > cacheMaxEntryWeight) return mm;
|
|
2198
|
+
if (cacheSize >= cacheMax || cacheTotalWeight + weight > cacheMaxWeight) {
|
|
2199
|
+
oldCache = cache;
|
|
2200
|
+
cache = /* @__PURE__ */ new Map();
|
|
2201
|
+
cacheSize = 0;
|
|
2202
|
+
cacheTotalWeight = 0;
|
|
2203
|
+
}
|
|
2204
|
+
let byPattern = cache.get(key);
|
|
2205
|
+
if (!byPattern) cache.set(key, byPattern = /* @__PURE__ */ new Map());
|
|
2206
|
+
byPattern.set(pattern, mm);
|
|
2207
|
+
cacheSize++;
|
|
2208
|
+
cacheTotalWeight += weight;
|
|
2209
|
+
return mm;
|
|
2210
|
+
};
|
|
2211
|
+
/* c8 ignore start */
|
|
2212
|
+
const defaultPlatform = typeof process === "object" && process ? process.env?.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
2213
|
+
const path = {
|
|
2214
|
+
win32: { sep: "\\" },
|
|
2215
|
+
posix: { sep: "/" }
|
|
2216
|
+
};
|
|
2217
|
+
minimatch.sep = defaultPlatform === "win32" ? path.win32.sep : path.posix.sep;
|
|
2218
|
+
const GLOBSTAR = Symbol("globstar **");
|
|
2219
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
2220
|
+
const filter = (pattern, options) => {
|
|
2221
|
+
let mm;
|
|
2222
|
+
return (p) => (mm ??= cachedMinimatch(pattern, options)).match(p);
|
|
2223
|
+
};
|
|
2224
|
+
minimatch.filter = filter;
|
|
2225
|
+
const ext = (a, b = {}) => Object.assign({}, a, b);
|
|
2226
|
+
const defaults = (def) => {
|
|
2227
|
+
if (!def || typeof def !== "object" || !Object.keys(def).length) return minimatch;
|
|
2228
|
+
const orig = minimatch;
|
|
2229
|
+
const m = (p, pattern, options = {}) => orig(p, pattern, ext(def, options));
|
|
2230
|
+
return Object.assign(m, {
|
|
2231
|
+
Minimatch: class Minimatch extends orig.Minimatch {
|
|
2232
|
+
constructor(pattern, options = {}) {
|
|
2233
|
+
super(pattern, ext(def, options));
|
|
2234
|
+
}
|
|
2235
|
+
static defaults(options) {
|
|
2236
|
+
return orig.defaults(ext(def, options)).Minimatch;
|
|
2237
|
+
}
|
|
2238
|
+
},
|
|
2239
|
+
unescape: (s, options = {}) => orig.unescape(s, ext(def, options)),
|
|
2240
|
+
escape: (s, options = {}) => orig.escape(s, ext(def, options)),
|
|
2241
|
+
filter: (pattern, options = {}) => orig.filter(pattern, ext(def, options)),
|
|
2242
|
+
defaults: (options) => orig.defaults(ext(def, options)),
|
|
2243
|
+
braceExpand: (pattern, options = {}) => orig.braceExpand(pattern, ext(def, options)),
|
|
2244
|
+
match: (list, pattern, options = {}) => orig.match(list, pattern, ext(def, options)),
|
|
2245
|
+
sep: orig.sep,
|
|
2246
|
+
GLOBSTAR
|
|
2247
|
+
});
|
|
2248
|
+
};
|
|
2249
|
+
minimatch.defaults = defaults;
|
|
2250
|
+
const braceExpand = (pattern, options = {}) => {
|
|
2251
|
+
assertValidPattern(pattern);
|
|
2252
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) return [pattern];
|
|
2253
|
+
let p = pattern.replace(/\\\\/g, "\\\\\\\\");
|
|
2254
|
+
if (options.windowsPathsNoEscape || options[AWE_KEY] === false) p = p.replace(/\[([{}])\]/g, "[\\$1]");
|
|
2255
|
+
return expand(p, { max: options.braceExpandMax });
|
|
2256
|
+
};
|
|
2257
|
+
minimatch.braceExpand = braceExpand;
|
|
2258
|
+
const RANGE_MIN = 100;
|
|
2259
|
+
const rangeRe = /(?<![\\$])\{(-?\d+)\.\.(-?\d+)\}/g;
|
|
2260
|
+
const inRepeatOrNegExt = (portion, mark) => {
|
|
2261
|
+
const stack = [];
|
|
2262
|
+
for (let i = 0; i < portion.length; i++) {
|
|
2263
|
+
const c = portion.charAt(i);
|
|
2264
|
+
if (c === "\\") i++;
|
|
2265
|
+
else if (c === mark) {
|
|
2266
|
+
if (stack.some((t) => t !== "@" && t !== "?")) return true;
|
|
2267
|
+
} else if (portion.charAt(i + 1) === "(" && "!?+*@".includes(c)) {
|
|
2268
|
+
stack.push(c);
|
|
2269
|
+
i++;
|
|
2270
|
+
} else if (c === ")") stack.pop();
|
|
2271
|
+
}
|
|
2272
|
+
return false;
|
|
2273
|
+
};
|
|
2274
|
+
const match = (list, pattern, options = {}) => {
|
|
2275
|
+
const mm = new Minimatch(pattern, options);
|
|
2276
|
+
list = list.filter((f) => mm.match(f));
|
|
2277
|
+
if (mm.options.nonull && !list.length) list.push(pattern);
|
|
2278
|
+
return list;
|
|
2279
|
+
};
|
|
2280
|
+
minimatch.match = match;
|
|
2281
|
+
const globMagic = /[?*]|[+@!]\(.*?\)|\[|\]/;
|
|
2282
|
+
const classEnd = (pattern, start) => {
|
|
2283
|
+
let i = start + 1;
|
|
2284
|
+
if (pattern.charAt(i) === "!" || pattern.charAt(i) === "^") i++;
|
|
2285
|
+
let sawStart = false;
|
|
2286
|
+
for (; i < pattern.length; i++) {
|
|
2287
|
+
const c = pattern.charAt(i);
|
|
2288
|
+
if (c === "]" && sawStart) return i;
|
|
2289
|
+
sawStart = true;
|
|
2290
|
+
if (c === "\\") i++;
|
|
2291
|
+
}
|
|
2292
|
+
return -1;
|
|
2293
|
+
};
|
|
2294
|
+
const literal = (pattern, noext) => {
|
|
2295
|
+
if (!noext && (pattern === "+()" || pattern === "@()")) return pattern;
|
|
2296
|
+
let lit = "";
|
|
2297
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
2298
|
+
const c = pattern.charAt(i);
|
|
2299
|
+
if (c === "\\") lit += pattern.charAt(++i) || c;
|
|
2300
|
+
else if (c === "*" || c === "?") return;
|
|
2301
|
+
else if (c === "[") {
|
|
2302
|
+
const close = classEnd(pattern, i);
|
|
2303
|
+
if (close === -1) {
|
|
2304
|
+
lit += c;
|
|
2305
|
+
continue;
|
|
2306
|
+
}
|
|
2307
|
+
let body = pattern.slice(i + 1, close);
|
|
2308
|
+
if (body.startsWith("\\")) body = body.slice(1);
|
|
2309
|
+
if ([...body].length !== 1 || "!^".includes(pattern.charAt(i + 1))) return;
|
|
2310
|
+
lit += body;
|
|
2311
|
+
i = close;
|
|
2312
|
+
} else if (!noext && "+@!".includes(c) && pattern.charAt(i + 1) === "(" && pattern.includes(")", i + 2)) return;
|
|
2313
|
+
else lit += c;
|
|
2314
|
+
}
|
|
2315
|
+
return lit;
|
|
2316
|
+
};
|
|
2317
|
+
const MAX_EXTGLOBS = 256;
|
|
2318
|
+
const extglobCount = (pattern) => {
|
|
2319
|
+
let n = 0;
|
|
2320
|
+
for (let i = 0; i < pattern.length - 1; i++) {
|
|
2321
|
+
const c = pattern.charAt(i);
|
|
2322
|
+
if (c === "\\") i++;
|
|
2323
|
+
else if ("+@!?*".includes(c) && pattern.charAt(i + 1) === "(") {
|
|
2324
|
+
n++;
|
|
2325
|
+
i++;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
return n;
|
|
2329
|
+
};
|
|
2330
|
+
const assertValidExtglobs = (pattern) => {
|
|
2331
|
+
if (extglobCount(pattern) > MAX_EXTGLOBS) throw new TypeError("pattern has too many extglobs");
|
|
2332
|
+
};
|
|
2333
|
+
const extSafe = (pattern) => {
|
|
2334
|
+
if (/^[?*+@]\(\)$/.test(pattern) || pattern.includes("[:")) return false;
|
|
2335
|
+
let depth = 0;
|
|
2336
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
2337
|
+
const c = pattern.charAt(i);
|
|
2338
|
+
if (c === "\\") {
|
|
2339
|
+
if (++i === pattern.length) return false;
|
|
2340
|
+
} else if (c === "[") {
|
|
2341
|
+
const close = classEnd(pattern, i);
|
|
2342
|
+
if (close !== -1) i = close;
|
|
2343
|
+
} else if ("+@!?*".includes(c) && pattern.charAt(i + 1) === "(") {
|
|
2344
|
+
depth++;
|
|
2345
|
+
i++;
|
|
2346
|
+
} else if (c === ")") {
|
|
2347
|
+
if (!depth--) return false;
|
|
2348
|
+
} else if (c === "|" && !depth) return false;
|
|
2349
|
+
}
|
|
2350
|
+
return !depth;
|
|
2351
|
+
};
|
|
2352
|
+
let lastSplit;
|
|
2353
|
+
let lastChecked;
|
|
2354
|
+
const portionMatch = (p, f) => typeof p === "string" ? f === p : f !== "" && p.testUnchecked(f);
|
|
2355
|
+
const endIndex = (p, last, lastStart, prev, prevStart) => portionMatch(p, last) ? lastStart : prev !== void 0 && portionMatch(p, prev) ? prevStart : -1;
|
|
2356
|
+
const isDots = (p) => p === "." || p === "..";
|
|
2357
|
+
const isDrive = (p) => typeof p === "string" && /^[a-z]:$/i.test(p);
|
|
2358
|
+
const isLongUNC = (p) => typeof p === "string" && /^unc$/i.test(p);
|
|
2359
|
+
const uncHost = (p) => {
|
|
2360
|
+
if (p[0] !== "" || p[1] !== "") return -1;
|
|
2361
|
+
const h = p[2] !== "?" ? 2 : isLongUNC(p[3]) ? 4 : -1;
|
|
2362
|
+
const host = p[h];
|
|
2363
|
+
const share = p[h + 1];
|
|
2364
|
+
return h !== -1 && host !== void 0 && host !== "" && host !== GLOBSTAR && share !== void 0 && share !== "" && share !== GLOBSTAR ? h : -1;
|
|
2365
|
+
};
|
|
2366
|
+
const walkable = (p, dot) => !isDots(p) && (dot || !p.startsWith("."));
|
|
2367
|
+
const dotPortion = (f, start, end, dot, sep) => {
|
|
2368
|
+
for (let k = start; k < end;) {
|
|
2369
|
+
if (f.charCodeAt(k) === 46) {
|
|
2370
|
+
if (!dot) return true;
|
|
2371
|
+
const n = f.charCodeAt(k + 1) === 46 ? k + 2 : k + 1;
|
|
2372
|
+
if (n >= end || isSep(f.charCodeAt(n), sep)) return true;
|
|
2373
|
+
}
|
|
2374
|
+
const s = nextSep(f, k, sep);
|
|
2375
|
+
if (s === -1) return false;
|
|
2376
|
+
k = s + 1;
|
|
2377
|
+
while (k < end && isSep(f.charCodeAt(k), sep)) k++;
|
|
2378
|
+
}
|
|
2379
|
+
return false;
|
|
2380
|
+
};
|
|
2381
|
+
const isSep = (c, sep) => sep === "/" ? c === 47 : sep === "\\" ? c === 92 : c === 47 || c === 92;
|
|
2382
|
+
const nextSep = (f, from, sep) => {
|
|
2383
|
+
if (sep !== "both") return f.indexOf(sep, from);
|
|
2384
|
+
const s = f.indexOf("/", from);
|
|
2385
|
+
const b = f.indexOf("\\", from);
|
|
2386
|
+
return s === -1 ? b : b === -1 ? s : Math.min(s, b);
|
|
2387
|
+
};
|
|
2388
|
+
const lastSep = (f, from, sep) => sep !== "both" ? f.lastIndexOf(sep, from) : Math.max(f.lastIndexOf("/", from), f.lastIndexOf("\\", from));
|
|
2389
|
+
const PENDING = {};
|
|
2390
|
+
var Minimatch = class {
|
|
2391
|
+
options;
|
|
2392
|
+
set;
|
|
2393
|
+
pattern;
|
|
2394
|
+
windowsPathsNoEscape;
|
|
2395
|
+
nonegate;
|
|
2396
|
+
negate;
|
|
2397
|
+
comment;
|
|
2398
|
+
empty;
|
|
2399
|
+
preserveMultipleSlashes;
|
|
2400
|
+
partial;
|
|
2401
|
+
globSet;
|
|
2402
|
+
globParts;
|
|
2403
|
+
nocase;
|
|
2404
|
+
isWindows;
|
|
2405
|
+
platform;
|
|
2406
|
+
windowsNoMagicRoot;
|
|
2407
|
+
maxGlobstarRecursion;
|
|
2408
|
+
#endCheck;
|
|
2409
|
+
#literalCheck;
|
|
2410
|
+
#level2;
|
|
2411
|
+
#form;
|
|
2412
|
+
#literals = [];
|
|
2413
|
+
#shapes = [];
|
|
2414
|
+
#endRows = [];
|
|
2415
|
+
#matchers = /* @__PURE__ */ new Map();
|
|
2416
|
+
#pending = false;
|
|
2417
|
+
#rangeMark;
|
|
2418
|
+
#globstarParts = /* @__PURE__ */ new WeakMap();
|
|
2419
|
+
constructor(pattern, options = {}) {
|
|
2420
|
+
assertValidPattern(pattern);
|
|
2421
|
+
options = options || {};
|
|
2422
|
+
this.options = options;
|
|
2423
|
+
this.maxGlobstarRecursion = options.maxGlobstarRecursion ?? DEFAULT_GLOB_STAR_RECURSION_MAX;
|
|
2424
|
+
this.pattern = pattern;
|
|
2425
|
+
this.platform = options.platform || defaultPlatform;
|
|
2426
|
+
this.isWindows = this.platform === "win32";
|
|
2427
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape || options[AWE_KEY] === false;
|
|
2428
|
+
if (this.windowsPathsNoEscape) this.pattern = this.pattern.replace(/\\/g, "/");
|
|
2429
|
+
this.preserveMultipleSlashes = !!options.preserveMultipleSlashes;
|
|
2430
|
+
this.negate = false;
|
|
2431
|
+
this.nonegate = !!options.nonegate;
|
|
2432
|
+
this.comment = false;
|
|
2433
|
+
this.empty = false;
|
|
2434
|
+
this.partial = !!options.partial;
|
|
2435
|
+
this.nocase = !!this.options.nocase;
|
|
2436
|
+
this.windowsNoMagicRoot = options.windowsNoMagicRoot !== void 0 ? options.windowsNoMagicRoot : !!(this.isWindows && this.nocase);
|
|
2437
|
+
this.globSet = [];
|
|
2438
|
+
this.globParts = [];
|
|
2439
|
+
this.set = [];
|
|
2440
|
+
this.#endCheck = !this.preserveMultipleSlashes;
|
|
2441
|
+
this.#level2 = (options.optimizationLevel ?? 1) >= 2;
|
|
2442
|
+
const n = options.normalize;
|
|
2443
|
+
this.#form = n === true ? "NFC" : n || void 0;
|
|
2444
|
+
this.make();
|
|
2445
|
+
const drives = this.set.map((row) => this.#rootIndex(row));
|
|
2446
|
+
this.#endRows = this.set.map((row, r) => this.#endCheck && row.length - 1 > drives[r]);
|
|
2447
|
+
this.#literals = this.set.map((row, r) => {
|
|
2448
|
+
const end = this.#endRows[r] ? row.length - 1 : row.length;
|
|
2449
|
+
const lits = row.slice(drives[r] + 1, end).filter((p) => typeof p === "string" && !!p);
|
|
2450
|
+
return [...new Set(lits)];
|
|
2451
|
+
});
|
|
2452
|
+
this.#literalCheck = this.#literals.some((l) => l.length);
|
|
2453
|
+
this.#shapes = this.set.map((row, r) => {
|
|
2454
|
+
const [p0, p1, p2] = row;
|
|
2455
|
+
if (this.#endRows[r] && row.length === 2) {
|
|
2456
|
+
if (p0 === GLOBSTAR && p1 !== GLOBSTAR) return "tail";
|
|
2457
|
+
}
|
|
2458
|
+
if (this.#endRows[r] && options.matchBase && row.length === 1 && p0 !== GLOBSTAR && p0 !== "") return "base";
|
|
2459
|
+
if (!this.#endCheck || drives[r] !== -1) return void 0;
|
|
2460
|
+
if (row.length === 3 && p0 === GLOBSTAR && p2 === GLOBSTAR && p1 !== GLOBSTAR && p1 !== "" && this.maxGlobstarRecursion > 0) return "mid";
|
|
2461
|
+
if (row.length === 2 && p1 === GLOBSTAR && p0 !== GLOBSTAR && p0 !== "") return "head";
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
#norm(p) {
|
|
2465
|
+
return this.#form ? p.normalize(this.#form) : p;
|
|
2466
|
+
}
|
|
2467
|
+
#rootIndex(row) {
|
|
2468
|
+
if (!this.isWindows) return -1;
|
|
2469
|
+
if (isDrive(row[0])) return 0;
|
|
2470
|
+
if (row[0] === "" && row[1] === "" && row[2] === "?" && isDrive(row[3])) return 3;
|
|
2471
|
+
const h = uncHost(row);
|
|
2472
|
+
return h === -1 ? -1 : h + 1;
|
|
2473
|
+
}
|
|
2474
|
+
hasMagic() {
|
|
2475
|
+
if (this.options.magicalBraces && this.set.length > 1) return true;
|
|
2476
|
+
for (const pattern of this.set) for (const part of pattern) if (typeof part !== "string") return true;
|
|
2477
|
+
return false;
|
|
2478
|
+
}
|
|
2479
|
+
make() {
|
|
2480
|
+
const pattern = this.pattern;
|
|
2481
|
+
const options = this.options;
|
|
2482
|
+
if (!options.nocomment && pattern.charAt(0) === "#") {
|
|
2483
|
+
this.comment = true;
|
|
2484
|
+
return;
|
|
2485
|
+
}
|
|
2486
|
+
if (!pattern) {
|
|
2487
|
+
this.empty = true;
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
this.parseNegate();
|
|
2491
|
+
this.globSet = [...new Set(this.#expandBraces())];
|
|
2492
|
+
const rawGlobParts = this.globSet.map((s) => this.#slashSplit(s));
|
|
2493
|
+
this.globParts = this.preprocess(rawGlobParts);
|
|
2494
|
+
this.#pending = true;
|
|
2495
|
+
let set = this.globParts.map((s, _, __) => {
|
|
2496
|
+
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
2497
|
+
const n = s[2] === "?" && isLongUNC(s[3]) ? 6 : 4;
|
|
2498
|
+
const isUNC = s[0] === "" && s[1] === "" && (s[2] === "?" || !globMagic.test(s[2])) && s.slice(3, n).every((p) => !globMagic.test(p));
|
|
2499
|
+
const isDrive = /^[a-z]:/i.test(s[0]);
|
|
2500
|
+
if (isUNC) return [...s.slice(0, n).map((p) => this.#norm(p)), ...s.slice(n).map((ss) => this.parse(ss))];
|
|
2501
|
+
else if (isDrive) return [this.#norm(s[0]), ...s.slice(1).map((ss) => this.parse(ss))];
|
|
2502
|
+
}
|
|
2503
|
+
return s.map((ss) => this.parse(ss));
|
|
2504
|
+
});
|
|
2505
|
+
this.set = set.filter((s) => s.indexOf(false) === -1);
|
|
2506
|
+
if (this.isWindows) for (let i = 0; i < this.set.length; i++) {
|
|
2507
|
+
const p = this.set[i];
|
|
2508
|
+
if (p[0] === "" && p[1] === "" && this.globParts[i][2] === "?" && (isDrive(p[3]) || isLongUNC(this.globParts[i][3]))) {
|
|
2509
|
+
if (isLongUNC(this.globParts[i][3])) p[3] = "UNC";
|
|
2510
|
+
p[2] = "?";
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
if (!options.noext) this.mergeRows();
|
|
2514
|
+
this.#pending = false;
|
|
2515
|
+
this.set.forEach((row, i) => {
|
|
2516
|
+
for (let k = 0; k < row.length; k++) if (row[k] === PENDING) row[k] = this.parse(this.globParts[i][k]);
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
mergeRows() {
|
|
2520
|
+
let merged = true;
|
|
2521
|
+
while (merged) {
|
|
2522
|
+
merged = false;
|
|
2523
|
+
if (this.set.length < 2) return;
|
|
2524
|
+
let keys = this.#mergeKeys();
|
|
2525
|
+
const len = Math.max(0, ...this.set.map((r) => r.length));
|
|
2526
|
+
for (let k = 0; k < len; k++) {
|
|
2527
|
+
const groups = /* @__PURE__ */ new Map();
|
|
2528
|
+
const R = this.set.length + 1;
|
|
2529
|
+
this.set.forEach((row, i) => {
|
|
2530
|
+
if (!(row[k] instanceof Matcher || row[k] === PENDING) || !extSafe(this.globParts[i][k])) return;
|
|
2531
|
+
const { pre, suf } = keys[i];
|
|
2532
|
+
const key = pre[k] * R + suf[k + 1];
|
|
2533
|
+
const g = groups.get(key);
|
|
2534
|
+
if (g) g.push(i);
|
|
2535
|
+
else groups.set(key, [i]);
|
|
2536
|
+
});
|
|
2537
|
+
const drop = /* @__PURE__ */ new Set();
|
|
2538
|
+
for (const g of groups.values()) {
|
|
2539
|
+
if (g.length < 2) continue;
|
|
2540
|
+
const [first, ...rest] = g;
|
|
2541
|
+
const glob = `@(${g.map((i) => this.globParts[i][k]).join("|")})`;
|
|
2542
|
+
if (extglobCount(glob) > MAX_EXTGLOBS) continue;
|
|
2543
|
+
this.globParts[first][k] = glob;
|
|
2544
|
+
this.set[first][k] = this.parse(glob);
|
|
2545
|
+
for (const i of rest) drop.add(i);
|
|
2546
|
+
}
|
|
2547
|
+
if (drop.size) {
|
|
2548
|
+
merged = true;
|
|
2549
|
+
this.set = this.set.filter((_, i) => !drop.has(i));
|
|
2550
|
+
this.globParts = this.globParts.filter((_, i) => !drop.has(i));
|
|
2551
|
+
if (this.set.length < 2) return;
|
|
2552
|
+
keys = this.#mergeKeys();
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
#mergeKeys() {
|
|
2558
|
+
const partIds = /* @__PURE__ */ new Map();
|
|
2559
|
+
const ids = this.globParts.map((parts) => parts.map((s) => {
|
|
2560
|
+
let id = partIds.get(s);
|
|
2561
|
+
if (id === void 0) partIds.set(s, id = partIds.size);
|
|
2562
|
+
return id;
|
|
2563
|
+
}));
|
|
2564
|
+
const P = partIds.size;
|
|
2565
|
+
const len = Math.max(0, ...ids.map((r) => r.length));
|
|
2566
|
+
const keys = ids.map((r) => ({
|
|
2567
|
+
pre: [0],
|
|
2568
|
+
suf: new Array(r.length + 1).fill(0)
|
|
2569
|
+
}));
|
|
2570
|
+
for (let k = 0; k < len; k++) {
|
|
2571
|
+
const m = /* @__PURE__ */ new Map();
|
|
2572
|
+
ids.forEach((r, i) => {
|
|
2573
|
+
if (k >= r.length) return;
|
|
2574
|
+
const { pre } = keys[i];
|
|
2575
|
+
const key = pre[k] * P + r[k];
|
|
2576
|
+
let id = m.get(key);
|
|
2577
|
+
if (id === void 0) m.set(key, id = m.size + 1);
|
|
2578
|
+
pre.push(id);
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
for (let k = len - 1; k >= 0; k--) {
|
|
2582
|
+
const m = /* @__PURE__ */ new Map();
|
|
2583
|
+
ids.forEach((r, i) => {
|
|
2584
|
+
if (k >= r.length) return;
|
|
2585
|
+
const { suf } = keys[i];
|
|
2586
|
+
const key = suf[k + 1] * P + r[k];
|
|
2587
|
+
let id = m.get(key);
|
|
2588
|
+
if (id === void 0) m.set(key, id = m.size + 1);
|
|
2589
|
+
suf[k] = id;
|
|
2590
|
+
});
|
|
2591
|
+
}
|
|
2592
|
+
return keys;
|
|
2593
|
+
}
|
|
2594
|
+
preprocess(globParts) {
|
|
2595
|
+
if (this.options.noglobstar) {
|
|
2596
|
+
for (const partset of globParts) for (let j = 0; j < partset.length; j++) if (partset[j] === "**") partset[j] = "*";
|
|
2597
|
+
}
|
|
2598
|
+
const { optimizationLevel = 1 } = this.options;
|
|
2599
|
+
if (optimizationLevel >= 2) {
|
|
2600
|
+
globParts = this.firstPhasePreProcess(globParts);
|
|
2601
|
+
globParts = this.secondPhasePreProcess(globParts);
|
|
2602
|
+
} else if (optimizationLevel >= 1) globParts = this.levelOneOptimize(globParts);
|
|
2603
|
+
else globParts = this.adjascentGlobstarOptimize(globParts);
|
|
2604
|
+
return globParts;
|
|
2605
|
+
}
|
|
2606
|
+
adjascentGlobstarOptimize(globParts) {
|
|
2607
|
+
return globParts.map((parts) => {
|
|
2608
|
+
let gs = -1;
|
|
2609
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
2610
|
+
let i = gs;
|
|
2611
|
+
while (parts[i + 1] === "**") i++;
|
|
2612
|
+
if (i !== gs) parts.splice(gs, i - gs);
|
|
2613
|
+
}
|
|
2614
|
+
return parts;
|
|
2615
|
+
});
|
|
2616
|
+
}
|
|
2617
|
+
levelOneOptimize(globParts) {
|
|
2618
|
+
return globParts.map((parts) => {
|
|
2619
|
+
const root = this.#rootIndex(parts) + 1;
|
|
2620
|
+
parts = parts.reduce((set, part) => {
|
|
2621
|
+
const prev = set[set.length - 1];
|
|
2622
|
+
if (part === "**" && prev === "**") return set;
|
|
2623
|
+
if (part === "..") {
|
|
2624
|
+
if (set.length > root && prev && prev !== ".." && prev !== "." && prev !== "**") {
|
|
2625
|
+
set.pop();
|
|
2626
|
+
return set;
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
set.push(part);
|
|
2630
|
+
return set;
|
|
2631
|
+
}, []);
|
|
2632
|
+
return parts.length === 0 ? [""] : parts;
|
|
2633
|
+
});
|
|
2634
|
+
}
|
|
2635
|
+
#canMatch(f) {
|
|
2636
|
+
const sep = !this.isWindows || !f.includes("\\") ? "/" : f.includes("/") ? "both" : "\\";
|
|
2637
|
+
let ends = this.#endCheck ? 0 : -1;
|
|
2638
|
+
let last = "";
|
|
2639
|
+
let lastStart = 0;
|
|
2640
|
+
let prev;
|
|
2641
|
+
let prevStart = 0;
|
|
2642
|
+
const dot = !!this.options.dot;
|
|
2643
|
+
ROWS: for (let r = 0; r < this.set.length; r++) {
|
|
2644
|
+
const row = this.set[r];
|
|
2645
|
+
const p = row[row.length - 1];
|
|
2646
|
+
let end = ends !== -1 && this.#endRows[r] && p !== GLOBSTAR;
|
|
2647
|
+
if (end && ends === 0) {
|
|
2648
|
+
const i = lastSep(f, f.length, sep);
|
|
2649
|
+
lastStart = i + 1;
|
|
2650
|
+
last = f.slice(lastStart);
|
|
2651
|
+
if (last === "" && i >= 0) {
|
|
2652
|
+
let j = i;
|
|
2653
|
+
while (j > 0 && isSep(f.charCodeAt(j - 1), sep)) j--;
|
|
2654
|
+
prevStart = j === 0 ? 0 : lastSep(f, j - 1, sep) + 1;
|
|
2655
|
+
prev = f.slice(prevStart, j);
|
|
2656
|
+
}
|
|
2657
|
+
const resolves = this.#level2 && (isDots(last) || last === "" && prev !== void 0 && isDots(prev));
|
|
2658
|
+
ends = resolves ? -1 : 1;
|
|
2659
|
+
end = !resolves;
|
|
2660
|
+
}
|
|
2661
|
+
let tailStart = -1;
|
|
2662
|
+
if (end && typeof p === "string") {
|
|
2663
|
+
tailStart = endIndex(p, last, lastStart, prev, prevStart);
|
|
2664
|
+
if (tailStart === -1) continue;
|
|
2665
|
+
}
|
|
2666
|
+
if (this.#literalCheck) {
|
|
2667
|
+
for (const l of this.#literals[r]) if (!f.includes(l)) continue ROWS;
|
|
2668
|
+
}
|
|
2669
|
+
if (end && typeof p === "object") {
|
|
2670
|
+
tailStart = endIndex(p, last, lastStart, prev, prevStart);
|
|
2671
|
+
if (tailStart === -1) continue;
|
|
2672
|
+
}
|
|
2673
|
+
const shape = this.#shapes[r];
|
|
2674
|
+
if (shape === "base" && end) return "yes";
|
|
2675
|
+
if (shape === "tail" && end) {
|
|
2676
|
+
if (this.#level2 && dotPortion(f, 0, tailStart, true, sep)) return "maybe";
|
|
2677
|
+
if (!dotPortion(f, 0, tailStart, dot, sep)) return "yes";
|
|
2678
|
+
continue;
|
|
2679
|
+
}
|
|
2680
|
+
if (shape === "mid" || shape === "head") {
|
|
2681
|
+
const m = this.#walk(f, row, shape === "head", dot, sep);
|
|
2682
|
+
if (m !== "no") return m;
|
|
2683
|
+
continue;
|
|
2684
|
+
}
|
|
2685
|
+
return "maybe";
|
|
2686
|
+
}
|
|
2687
|
+
return "no";
|
|
2688
|
+
}
|
|
2689
|
+
#matchShape(file, row, shape) {
|
|
2690
|
+
const dot = !!this.options.dot;
|
|
2691
|
+
const n = file.length;
|
|
2692
|
+
if (shape === "head") {
|
|
2693
|
+
if (n < 2 || !portionMatch(row[0], file[0])) return false;
|
|
2694
|
+
for (let i = 1; i < n; i++) if (!walkable(file[i], dot)) return false;
|
|
2695
|
+
return true;
|
|
2696
|
+
}
|
|
2697
|
+
const x = row[1];
|
|
2698
|
+
if (shape === "tail") {
|
|
2699
|
+
let t = n - 1;
|
|
2700
|
+
if (!portionMatch(x, file[t])) {
|
|
2701
|
+
if (file[t] !== "" || n === 1 || !portionMatch(x, file[--t])) return false;
|
|
2702
|
+
}
|
|
2703
|
+
for (let i = 0; i < t; i++) if (!walkable(file[i], dot)) return false;
|
|
2704
|
+
return true;
|
|
2705
|
+
}
|
|
2706
|
+
for (let k = 0; k < n; k++) {
|
|
2707
|
+
if (portionMatch(x, file[k]) && k + 1 < n) {
|
|
2708
|
+
let i = k + 1;
|
|
2709
|
+
while (i < n && walkable(file[i], dot)) i++;
|
|
2710
|
+
if (i === n) return true;
|
|
2711
|
+
}
|
|
2712
|
+
if (!walkable(file[k], dot)) return false;
|
|
2713
|
+
}
|
|
2714
|
+
return false;
|
|
2715
|
+
}
|
|
2716
|
+
#walk(f, row, head, dot, sep) {
|
|
2717
|
+
if (this.#level2 && dotPortion(f, 0, f.length, true, sep)) return "maybe";
|
|
2718
|
+
const x = row[head ? 0 : 1];
|
|
2719
|
+
let s = 0;
|
|
2720
|
+
for (let e = nextSep(f, s, sep); e !== -1; e = nextSep(f, s, sep)) {
|
|
2721
|
+
let next = e + 1;
|
|
2722
|
+
while (next < f.length && isSep(f.charCodeAt(next), sep)) next++;
|
|
2723
|
+
if ((typeof x === "string" ? e - s === x.length && f.startsWith(x, s) : e > s && x.testUnchecked(f.slice(s, e))) && !dotPortion(f, next, f.length, dot, sep)) return "yes";
|
|
2724
|
+
if (head || dotPortion(f, s, next, dot, sep)) return "no";
|
|
2725
|
+
s = next;
|
|
2726
|
+
}
|
|
2727
|
+
return "no";
|
|
2728
|
+
}
|
|
2729
|
+
#cachedSplit(f) {
|
|
2730
|
+
const last = lastSplit;
|
|
2731
|
+
return last?.f === f && last.isWindows === this.isWindows && last.preserveMultipleSlashes === this.preserveMultipleSlashes && last.normalize === this.#form ? last : void 0;
|
|
2732
|
+
}
|
|
2733
|
+
#split(f) {
|
|
2734
|
+
const { isWindows, preserveMultipleSlashes } = this;
|
|
2735
|
+
let parts = this.#slashSplit(isWindows ? f.split("\\").join("/") : f);
|
|
2736
|
+
const normalize = this.#form;
|
|
2737
|
+
if (normalize) parts = parts.map((p) => p.normalize(normalize));
|
|
2738
|
+
lastSplit = {
|
|
2739
|
+
f,
|
|
2740
|
+
isWindows,
|
|
2741
|
+
preserveMultipleSlashes,
|
|
2742
|
+
normalize,
|
|
2743
|
+
parts
|
|
2744
|
+
};
|
|
2745
|
+
return lastSplit;
|
|
2746
|
+
}
|
|
2747
|
+
#levelTwoFileOptimize(file) {
|
|
2748
|
+
const parts = [...file];
|
|
2749
|
+
let didSomething = false;
|
|
2750
|
+
do {
|
|
2751
|
+
didSomething = false;
|
|
2752
|
+
if (!this.preserveMultipleSlashes) {
|
|
2753
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
2754
|
+
const p = parts[i];
|
|
2755
|
+
if (i === 1 && p === "" && parts[0] === "") continue;
|
|
2756
|
+
if (p === "." || p === "") {
|
|
2757
|
+
didSomething = true;
|
|
2758
|
+
parts.splice(i, 1);
|
|
2759
|
+
i--;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
2763
|
+
didSomething = true;
|
|
2764
|
+
parts.pop();
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
const root = this.#rootIndex(parts) + 1;
|
|
2768
|
+
let dd = root;
|
|
2769
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
2770
|
+
const p = parts[dd - 1];
|
|
2771
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
2772
|
+
didSomething = true;
|
|
2773
|
+
parts.splice(dd - 1, 2);
|
|
2774
|
+
dd = Math.max(dd - 2, root);
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
} while (didSomething);
|
|
2778
|
+
return parts.length === 0 ? [""] : parts;
|
|
2779
|
+
}
|
|
2780
|
+
firstPhasePreProcess(globParts) {
|
|
2781
|
+
const { braceExpandMax = DEFAULT_BRACE_EXPAND_MAX } = this.options;
|
|
2782
|
+
let splitCells = 0;
|
|
2783
|
+
const maxSplitCells = 1e6;
|
|
2784
|
+
let didSomething = false;
|
|
2785
|
+
do {
|
|
2786
|
+
didSomething = false;
|
|
2787
|
+
for (let parts of globParts) {
|
|
2788
|
+
let gs = -1;
|
|
2789
|
+
while (-1 !== (gs = parts.indexOf("**", gs + 1))) {
|
|
2790
|
+
let gss = gs;
|
|
2791
|
+
while (parts[gss + 1] === "**") gss++;
|
|
2792
|
+
if (gss > gs) parts.splice(gs + 1, gss - gs);
|
|
2793
|
+
let next = parts[gs + 1];
|
|
2794
|
+
const p = parts[gs + 2];
|
|
2795
|
+
const p2 = parts[gs + 3];
|
|
2796
|
+
if (next !== "..") continue;
|
|
2797
|
+
if (!p || p === "." || p === ".." || !p2 || p2 === "." || p2 === "..") continue;
|
|
2798
|
+
const addedCells = parts.length - 1;
|
|
2799
|
+
if (globParts.length >= braceExpandMax || splitCells + addedCells > maxSplitCells) throw new RangeError(`optimizationLevel 2: too many patterns from '**/..'`);
|
|
2800
|
+
didSomething = true;
|
|
2801
|
+
parts.splice(gs, 1);
|
|
2802
|
+
const other = parts.slice(0);
|
|
2803
|
+
other[gs] = "**";
|
|
2804
|
+
splitCells += addedCells;
|
|
2805
|
+
globParts.push(other);
|
|
2806
|
+
gs--;
|
|
2807
|
+
}
|
|
2808
|
+
if (!this.preserveMultipleSlashes) {
|
|
2809
|
+
for (let i = 1; i < parts.length - 1; i++) {
|
|
2810
|
+
const p = parts[i];
|
|
2811
|
+
if (i === 1 && p === "" && parts[0] === "") continue;
|
|
2812
|
+
if (p === "." || p === "") {
|
|
2813
|
+
didSomething = true;
|
|
2814
|
+
parts.splice(i, 1);
|
|
2815
|
+
i--;
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
if (parts[0] === "." && parts.length === 2 && (parts[1] === "." || parts[1] === "")) {
|
|
2819
|
+
didSomething = true;
|
|
2820
|
+
parts.pop();
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
const root = this.#rootIndex(parts) + 1;
|
|
2824
|
+
let dd = root;
|
|
2825
|
+
while (-1 !== (dd = parts.indexOf("..", dd + 1))) {
|
|
2826
|
+
const p = parts[dd - 1];
|
|
2827
|
+
if (p && p !== "." && p !== ".." && p !== "**") {
|
|
2828
|
+
didSomething = true;
|
|
2829
|
+
const splin = dd === 1 && parts[dd + 1] === "**" ? ["."] : [];
|
|
2830
|
+
parts.splice(dd - 1, 2, ...splin);
|
|
2831
|
+
if (parts.length === 0) parts.push("");
|
|
2832
|
+
dd = Math.max(dd - 2, root);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
} while (didSomething);
|
|
2837
|
+
return globParts;
|
|
2838
|
+
}
|
|
2839
|
+
secondPhasePreProcess(globParts) {
|
|
2840
|
+
const keys = /* @__PURE__ */ new Set();
|
|
2841
|
+
const rows = globParts.filter((parts) => {
|
|
2842
|
+
const key = parts.join("/");
|
|
2843
|
+
if (keys.has(key)) return false;
|
|
2844
|
+
keys.add(key);
|
|
2845
|
+
return true;
|
|
2846
|
+
});
|
|
2847
|
+
const stars = /* @__PURE__ */ new Map();
|
|
2848
|
+
for (const parts of rows) {
|
|
2849
|
+
const s = [];
|
|
2850
|
+
for (let i = 0; i < parts.length; i++) if (parts[i] === "*") s.push(i);
|
|
2851
|
+
if (s.length) stars.set(s.join(","), s);
|
|
2852
|
+
}
|
|
2853
|
+
if (!stars.size || rows.length * stars.size > 1e5) return rows;
|
|
2854
|
+
const { dot } = this.options;
|
|
2855
|
+
return rows.filter((parts) => {
|
|
2856
|
+
for (const s of stars.values()) {
|
|
2857
|
+
if (s[s.length - 1] >= parts.length) continue;
|
|
2858
|
+
const c = [...parts];
|
|
2859
|
+
let ok = true;
|
|
2860
|
+
let changed = false;
|
|
2861
|
+
for (const i of s) {
|
|
2862
|
+
const p = parts[i];
|
|
2863
|
+
if (p === "*") continue;
|
|
2864
|
+
if (!p || p === "**" || !dot && p.startsWith(".")) {
|
|
2865
|
+
ok = false;
|
|
2866
|
+
break;
|
|
2867
|
+
}
|
|
2868
|
+
c[i] = "*";
|
|
2869
|
+
changed = true;
|
|
2870
|
+
}
|
|
2871
|
+
if (ok && changed && keys.has(c.join("/"))) return false;
|
|
2872
|
+
}
|
|
2873
|
+
return true;
|
|
2874
|
+
});
|
|
2875
|
+
}
|
|
2876
|
+
parseNegate() {
|
|
2877
|
+
if (this.nonegate) return;
|
|
2878
|
+
const pattern = this.pattern;
|
|
2879
|
+
let negate = false;
|
|
2880
|
+
let negateOffset = 0;
|
|
2881
|
+
for (let i = 0; i < pattern.length && pattern.charAt(i) === "!"; i++) {
|
|
2882
|
+
negate = !negate;
|
|
2883
|
+
negateOffset++;
|
|
2884
|
+
}
|
|
2885
|
+
if (negateOffset) this.pattern = pattern.slice(negateOffset);
|
|
2886
|
+
this.negate = negate;
|
|
2887
|
+
}
|
|
2888
|
+
#matchRow(file, resolved, pattern, partial) {
|
|
2889
|
+
let fileStartIndex = 0;
|
|
2890
|
+
let patternStartIndex = 0;
|
|
2891
|
+
const fh = this.isWindows ? uncHost(resolved) : -1;
|
|
2892
|
+
const ph = fh === -1 ? -1 : uncHost(pattern);
|
|
2893
|
+
if (ph !== -1) {
|
|
2894
|
+
const host = pattern[ph];
|
|
2895
|
+
const share = pattern[ph + 1];
|
|
2896
|
+
if (typeof host !== "string" || typeof share !== "string") {
|
|
2897
|
+
fileStartIndex = fh;
|
|
2898
|
+
patternStartIndex = ph;
|
|
2899
|
+
} else if (resolved[fh].toLowerCase() === host.toLowerCase() && resolved[fh + 1].toLowerCase() === share.toLowerCase()) {
|
|
2900
|
+
fileStartIndex = fh + 2;
|
|
2901
|
+
patternStartIndex = ph + 2;
|
|
2902
|
+
}
|
|
2903
|
+
} else if (this.isWindows) {
|
|
2904
|
+
const fileDrive = typeof file[0] === "string" && /^[a-z]:$/i.test(file[0]);
|
|
2905
|
+
const fileUNC = !fileDrive && file[0] === "" && file[1] === "" && file[2] === "?" && /^[a-z]:$/i.test(file[3]);
|
|
2906
|
+
const patternDrive = typeof pattern[0] === "string" && /^[a-z]:$/i.test(pattern[0]);
|
|
2907
|
+
const patternUNC = !patternDrive && pattern[0] === "" && pattern[1] === "" && pattern[2] === "?" && typeof pattern[3] === "string" && /^[a-z]:$/i.test(pattern[3]);
|
|
2908
|
+
const fdi = fileUNC ? 3 : fileDrive ? 0 : void 0;
|
|
2909
|
+
const pdi = patternUNC ? 3 : patternDrive ? 0 : void 0;
|
|
2910
|
+
if (typeof fdi === "number" && typeof pdi === "number") {
|
|
2911
|
+
const [fd, pd] = [file[fdi], pattern[pdi]];
|
|
2912
|
+
if (fd.toLowerCase() === pd.toLowerCase()) {
|
|
2913
|
+
patternStartIndex = pdi + 1;
|
|
2914
|
+
fileStartIndex = fdi + 1;
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
file = resolved;
|
|
2919
|
+
if (pattern.includes(GLOBSTAR)) return this.#matchGlobstar(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
2920
|
+
return this.#matchOne(file, pattern, partial, fileStartIndex, patternStartIndex);
|
|
2921
|
+
}
|
|
2922
|
+
#matchGlobstar(file, pattern, partial, fileIndex, patternIndex) {
|
|
2923
|
+
const { head, body, tail, segments } = this.#getGlobstarParts(pattern, partial, patternIndex);
|
|
2924
|
+
if (head.length) {
|
|
2925
|
+
const headEnd = fileIndex + head.length;
|
|
2926
|
+
if (!this.#matchOne(file, head, partial, fileIndex, 0, headEnd)) return false;
|
|
2927
|
+
fileIndex += head.length;
|
|
2928
|
+
patternIndex += head.length;
|
|
2929
|
+
}
|
|
2930
|
+
let fileTailMatch = 0;
|
|
2931
|
+
if (tail.length) {
|
|
2932
|
+
if (tail.length + fileIndex > file.length) return false;
|
|
2933
|
+
let tailStart = file.length - tail.length;
|
|
2934
|
+
if (this.#matchOne(file, tail, partial, tailStart, 0)) fileTailMatch = tail.length;
|
|
2935
|
+
else {
|
|
2936
|
+
if (file[file.length - 1] !== "" || fileIndex + tail.length === file.length) return false;
|
|
2937
|
+
tailStart--;
|
|
2938
|
+
if (!this.#matchOne(file, tail, partial, tailStart, 0)) return false;
|
|
2939
|
+
fileTailMatch = tail.length + 1;
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
if (!body.length) {
|
|
2943
|
+
let sawSome = !!fileTailMatch;
|
|
2944
|
+
for (let i = fileIndex; i < file.length - fileTailMatch; i++) {
|
|
2945
|
+
const f = String(file[i]);
|
|
2946
|
+
sawSome = true;
|
|
2947
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) return false;
|
|
2948
|
+
}
|
|
2949
|
+
return partial || sawSome;
|
|
2950
|
+
}
|
|
2951
|
+
return !!this.#matchGlobStarBodySections(file, segments, file.length - fileTailMatch, fileIndex, 0, partial, 0, !!fileTailMatch, /* @__PURE__ */ new Set());
|
|
2952
|
+
}
|
|
2953
|
+
#getGlobstarParts(pattern, partial, patternIndex) {
|
|
2954
|
+
let byStart = this.#globstarParts.get(pattern);
|
|
2955
|
+
if (!byStart) {
|
|
2956
|
+
byStart = [];
|
|
2957
|
+
this.#globstarParts.set(pattern, byStart);
|
|
2958
|
+
}
|
|
2959
|
+
const key = patternIndex * 2 + (partial ? 1 : 0);
|
|
2960
|
+
const found = byStart[key];
|
|
2961
|
+
if (found) return found;
|
|
2962
|
+
const firstgs = pattern.indexOf(GLOBSTAR, patternIndex);
|
|
2963
|
+
const lastgs = pattern.lastIndexOf(GLOBSTAR);
|
|
2964
|
+
const head = pattern.slice(patternIndex, firstgs);
|
|
2965
|
+
const body = pattern.slice(firstgs + 1, partial ? void 0 : lastgs);
|
|
2966
|
+
const tail = partial ? [] : pattern.slice(lastgs + 1);
|
|
2967
|
+
const segments = [[[], 0]];
|
|
2968
|
+
let current = segments[0];
|
|
2969
|
+
let nonGsParts = 0;
|
|
2970
|
+
const nonGsPartsSums = [0];
|
|
2971
|
+
for (const b of body) if (b === GLOBSTAR) {
|
|
2972
|
+
nonGsPartsSums.push(nonGsParts);
|
|
2973
|
+
current = [[], 0];
|
|
2974
|
+
segments.push(current);
|
|
2975
|
+
} else {
|
|
2976
|
+
current[0].push(b);
|
|
2977
|
+
nonGsParts++;
|
|
2978
|
+
}
|
|
2979
|
+
segments.forEach((b, i) => {
|
|
2980
|
+
b[1] = nonGsParts - nonGsPartsSums[i];
|
|
2981
|
+
});
|
|
2982
|
+
const parts = {
|
|
2983
|
+
head,
|
|
2984
|
+
body,
|
|
2985
|
+
tail,
|
|
2986
|
+
segments
|
|
2987
|
+
};
|
|
2988
|
+
byStart[key] = parts;
|
|
2989
|
+
return parts;
|
|
2990
|
+
}
|
|
2991
|
+
#matchGlobStarBodySections(file, bodySegments, fileLength, fileIndex, bodyIndex, partial, globStarDepth, sawTail, tried) {
|
|
2992
|
+
const bs = bodySegments[bodyIndex];
|
|
2993
|
+
if (!bs) {
|
|
2994
|
+
if (partial) return fileIndex >= fileLength || fileIndex === fileLength - 1 && file[fileIndex] === "";
|
|
2995
|
+
for (let i = fileIndex; i < fileLength; i++) {
|
|
2996
|
+
sawTail = true;
|
|
2997
|
+
const f = file[i];
|
|
2998
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) return false;
|
|
2999
|
+
}
|
|
3000
|
+
return sawTail;
|
|
3001
|
+
}
|
|
3002
|
+
const [body, need] = bs;
|
|
3003
|
+
const after = partial ? fileLength : fileLength - need;
|
|
3004
|
+
while (fileIndex <= after) {
|
|
3005
|
+
const key = bodyIndex * (file.length + 1) + fileIndex;
|
|
3006
|
+
if (tried.has(key)) return false;
|
|
3007
|
+
tried.add(key);
|
|
3008
|
+
if (this.#matchOne(file, body, partial, fileIndex, 0, fileIndex + body.length) && globStarDepth < this.maxGlobstarRecursion) {
|
|
3009
|
+
const sub = this.#matchGlobStarBodySections(file, bodySegments, fileLength, fileIndex + body.length, bodyIndex + 1, partial, globStarDepth + 1, sawTail, tried);
|
|
3010
|
+
if (sub !== false) return sub;
|
|
3011
|
+
}
|
|
3012
|
+
if (fileIndex === after) break;
|
|
3013
|
+
const f = file[fileIndex];
|
|
3014
|
+
if (f === "." || f === ".." || !this.options.dot && f.startsWith(".")) return false;
|
|
3015
|
+
fileIndex++;
|
|
3016
|
+
}
|
|
3017
|
+
return partial || null;
|
|
3018
|
+
}
|
|
3019
|
+
#matchOne(file, pattern, partial, fileIndex, patternIndex, fileEnd = file.length) {
|
|
3020
|
+
let fi;
|
|
3021
|
+
let pi;
|
|
3022
|
+
let pl;
|
|
3023
|
+
let fl;
|
|
3024
|
+
for (fi = fileIndex, pi = patternIndex, fl = Math.min(fileEnd, file.length), pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
|
|
3025
|
+
let p = pattern[pi];
|
|
3026
|
+
let f = file[fi];
|
|
3027
|
+
/* c8 ignore start */
|
|
3028
|
+
if (p === false || p === GLOBSTAR) return false;
|
|
3029
|
+
/* c8 ignore stop */
|
|
3030
|
+
if (!portionMatch(p, f)) return false;
|
|
3031
|
+
}
|
|
3032
|
+
if (fi === fl && pi === pl) return true;
|
|
3033
|
+
else if (fi === fl) return partial;
|
|
3034
|
+
else if (pi === pl) return fi === fl - 1 && file[fi] === "";
|
|
3035
|
+
else throw new Error("wtf?");
|
|
3036
|
+
/* c8 ignore stop */
|
|
3037
|
+
}
|
|
3038
|
+
braceExpand() {
|
|
3039
|
+
return braceExpand(this.pattern, this.options);
|
|
3040
|
+
}
|
|
3041
|
+
#expandBraces() {
|
|
3042
|
+
const { pattern } = this;
|
|
3043
|
+
if (this.options.nobrace) return this.braceExpand();
|
|
3044
|
+
let code = 57344;
|
|
3045
|
+
while (pattern.includes(String.fromCharCode(code))) if (++code > 63743) return this.braceExpand();
|
|
3046
|
+
const mark = String.fromCharCode(code);
|
|
3047
|
+
let found = false;
|
|
3048
|
+
const marked = pattern.replace(rangeRe, (m, lo, hi) => {
|
|
3049
|
+
const a = Number(lo);
|
|
3050
|
+
const b = Number(hi);
|
|
3051
|
+
if (!Number.isSafeInteger(a) || !Number.isSafeInteger(b) || Math.abs(a - b) + 1 < RANGE_MIN) return m;
|
|
3052
|
+
found = true;
|
|
3053
|
+
return `${mark}${lo}..${hi}${mark}`;
|
|
3054
|
+
});
|
|
3055
|
+
if (!found) return this.braceExpand();
|
|
3056
|
+
const set = braceExpand(marked, this.options);
|
|
3057
|
+
for (const p of set) for (const portion of p.split("/")) {
|
|
3058
|
+
const c = portion.indexOf("[");
|
|
3059
|
+
if (c !== -1 && c < portion.lastIndexOf(mark)) return this.braceExpand();
|
|
3060
|
+
if (!this.options.noext && inRepeatOrNegExt(portion, mark)) return this.braceExpand();
|
|
3061
|
+
}
|
|
3062
|
+
this.#rangeMark = mark;
|
|
3063
|
+
return set;
|
|
3064
|
+
}
|
|
3065
|
+
parse(pattern) {
|
|
3066
|
+
assertValidPattern(pattern);
|
|
3067
|
+
const options = this.options;
|
|
3068
|
+
if (pattern === "**") return GLOBSTAR;
|
|
3069
|
+
if (pattern === "") return "";
|
|
3070
|
+
const { nocase, nocaseMagicOnly, noext = false, dot, normalize } = options;
|
|
3071
|
+
const rangeMark = this.#rangeMark;
|
|
3072
|
+
const lit = rangeMark && pattern.includes(rangeMark) ? void 0 : literal(pattern, noext);
|
|
3073
|
+
if (lit !== void 0 && !(nocase && !nocaseMagicOnly && pattern.toUpperCase() !== pattern.toLowerCase())) return this.#norm(lit);
|
|
3074
|
+
if (this.#pending) return PENDING;
|
|
3075
|
+
let m = this.#matchers.get(pattern);
|
|
3076
|
+
if (!m) {
|
|
3077
|
+
if (!noext) assertValidExtglobs(pattern);
|
|
3078
|
+
m = new Matcher(pattern, {
|
|
3079
|
+
nocase,
|
|
3080
|
+
noext,
|
|
3081
|
+
dot,
|
|
3082
|
+
normalize,
|
|
3083
|
+
...rangeMark && { rangeMark }
|
|
3084
|
+
});
|
|
3085
|
+
this.#matchers.set(pattern, m);
|
|
3086
|
+
}
|
|
3087
|
+
return m;
|
|
3088
|
+
}
|
|
3089
|
+
#slashSplit(p) {
|
|
3090
|
+
if (this.preserveMultipleSlashes) return p.split("/");
|
|
3091
|
+
else if (this.isWindows && /^\/\/[^/]+/.test(p)) return ["", ...p.split(/\/+/)];
|
|
3092
|
+
else return p.split(/\/+/);
|
|
3093
|
+
}
|
|
3094
|
+
match(f, partial = this.partial) {
|
|
3095
|
+
if (this.comment) return false;
|
|
3096
|
+
if (this.empty) return f === "";
|
|
3097
|
+
if (f === "/" && partial) return true;
|
|
3098
|
+
const options = this.options;
|
|
3099
|
+
let split = this.#cachedSplit(f);
|
|
3100
|
+
if (!split) {
|
|
3101
|
+
if (!partial && !this.#form && (this.#endCheck || this.#literalCheck) && lastChecked !== f) {
|
|
3102
|
+
lastChecked = f;
|
|
3103
|
+
const can = this.#canMatch(f);
|
|
3104
|
+
if (can === "no") return options.flipNegate ? false : this.negate;
|
|
3105
|
+
if (can === "yes") return options.flipNegate ? true : !this.negate;
|
|
3106
|
+
}
|
|
3107
|
+
split = this.#split(f);
|
|
3108
|
+
}
|
|
3109
|
+
const ff = split.parts;
|
|
3110
|
+
const resolved = this.#level2 ? split.resolved ??= this.#levelTwoFileOptimize(ff) : ff;
|
|
3111
|
+
const set = this.set;
|
|
3112
|
+
let filename = ff[ff.length - 1];
|
|
3113
|
+
if (!filename) for (let i = ff.length - 2; !filename && i >= 0; i--) filename = ff[i];
|
|
3114
|
+
for (let r = 0; r < set.length; r++) {
|
|
3115
|
+
const pattern = set[r];
|
|
3116
|
+
const shape = partial ? void 0 : this.#shapes[r];
|
|
3117
|
+
if (shape === "base" ? portionMatch(pattern[0], filename) : shape ? this.#matchShape(resolved, pattern, shape) : options.matchBase && pattern.length === 1 ? this.#matchRow([filename], [filename], pattern, partial) : this.#matchRow(ff, resolved, pattern, partial)) {
|
|
3118
|
+
if (options.flipNegate) return true;
|
|
3119
|
+
return !this.negate;
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
if (options.flipNegate) return false;
|
|
3123
|
+
return this.negate;
|
|
3124
|
+
}
|
|
3125
|
+
static defaults(def) {
|
|
3126
|
+
return minimatch.defaults(def).Minimatch;
|
|
3127
|
+
}
|
|
3128
|
+
};
|
|
3129
|
+
/* c8 ignore stop */
|
|
3130
|
+
minimatch.Minimatch = Minimatch;
|
|
3131
|
+
minimatch.escape = escape;
|
|
3132
|
+
minimatch.unescape = unescape;
|
|
3133
|
+
// ../internal/src/build/runtime-package-files.ts
|
|
3134
|
+
const alwaysPublishedFile = /^(?:package\.json|(?:readme|copying|licen[cs]e)(?:\..*[^~$])?)$/i;
|
|
3135
|
+
const rootExcluded = /* @__PURE__ */ new Set([
|
|
3136
|
+
"package-lock.json",
|
|
3137
|
+
"yarn.lock",
|
|
3138
|
+
"pnpm-lock.yaml",
|
|
3139
|
+
"bun.lockb",
|
|
3140
|
+
".lock-wscript",
|
|
3141
|
+
"build/config.gypi"
|
|
3142
|
+
]);
|
|
3143
|
+
const excludedEntry = /^(?:node_modules|\.git|\.hg|\.svn|CVS|\.npmrc|\.npmignore|\.gitignore|\.DS_Store|npm-debug\.log|\._.*|.*\.orig|\..*\.swp)$/i;
|
|
3144
|
+
function hasNodeModulesSegment$1(path) {
|
|
3145
|
+
return path.split(/[\\/]/).includes("node_modules");
|
|
3146
|
+
}
|
|
3147
|
+
function isNestedPath(path) {
|
|
3148
|
+
return Boolean(path) && path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
3149
|
+
}
|
|
3150
|
+
/** Runs a filesystem read, and returns `undefined` when the path is gone. */
|
|
3151
|
+
async function unlessGone(read) {
|
|
3152
|
+
try {
|
|
3153
|
+
return await read();
|
|
3154
|
+
} catch (error) {
|
|
3155
|
+
const { code } = error;
|
|
3156
|
+
if (code === "ENOENT" || code === "ENOTDIR") return void 0;
|
|
3157
|
+
throw error;
|
|
3158
|
+
}
|
|
3159
|
+
}
|
|
3160
|
+
function readIfPresent(read) {
|
|
3161
|
+
try {
|
|
3162
|
+
return read();
|
|
3163
|
+
} catch (error) {
|
|
3164
|
+
if (error.code === "ENOENT") return void 0;
|
|
3165
|
+
throw error;
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
function packageRule(entry) {
|
|
3169
|
+
const include = !entry.startsWith("!");
|
|
3170
|
+
const matcher = new Minimatch((include ? entry : entry.slice(1)).replace(/^\.\//, "/").replace(/\/$/, "") || "**", {
|
|
3171
|
+
dot: true,
|
|
3172
|
+
matchBase: true,
|
|
3173
|
+
nocase: true,
|
|
3174
|
+
nocomment: true,
|
|
3175
|
+
nonegate: true
|
|
3176
|
+
});
|
|
3177
|
+
return {
|
|
3178
|
+
include,
|
|
3179
|
+
matches: (path, partial = false) => matcher.match(path, partial) || matcher.match(`/${path}`, partial)
|
|
3180
|
+
};
|
|
3181
|
+
}
|
|
3182
|
+
/** Files selected for a linked package's publish list; `undefined` keeps the whole package. */
|
|
3183
|
+
function publishedPackagePaths(packageDir) {
|
|
3184
|
+
let manifest;
|
|
3185
|
+
const contents = readIfPresent(() => readFileSync(join(packageDir, "package.json"), "utf8"));
|
|
3186
|
+
if (contents === void 0) return void 0;
|
|
3187
|
+
try {
|
|
3188
|
+
manifest = JSON.parse(contents);
|
|
3189
|
+
} catch {
|
|
3190
|
+
return;
|
|
3191
|
+
}
|
|
3192
|
+
if (!manifest || typeof manifest !== "object" || !("files" in manifest) || !Array.isArray(manifest.files)) return void 0;
|
|
3193
|
+
const rules = [];
|
|
3194
|
+
const required = /* @__PURE__ */ new Set();
|
|
3195
|
+
const requiredAncestors = /* @__PURE__ */ new Set();
|
|
3196
|
+
const requirePath = (entry) => {
|
|
3197
|
+
const path = relative(packageDir, join(packageDir, entry));
|
|
3198
|
+
if (!isNestedPath(path)) return;
|
|
3199
|
+
required.add(path);
|
|
3200
|
+
for (let parent = dirname(path); parent !== "."; parent = dirname(parent)) requiredAncestors.add(parent);
|
|
3201
|
+
};
|
|
3202
|
+
for (const entry of manifest.files) {
|
|
3203
|
+
if (typeof entry !== "string" || !entry) continue;
|
|
3204
|
+
const candidate = join(packageDir, entry);
|
|
3205
|
+
if (!entry.startsWith("!") && isNestedPath(relative(packageDir, candidate)) && readIfPresent(() => lstatSync(candidate))?.isFile()) requirePath(entry);
|
|
3206
|
+
else rules.push(packageRule(entry.endsWith("/*") ? `${entry}*` : entry));
|
|
3207
|
+
}
|
|
3208
|
+
if ("main" in manifest && typeof manifest.main === "string") requirePath(manifest.main);
|
|
3209
|
+
if ("browser" in manifest && typeof manifest.browser === "string") requirePath(manifest.browser);
|
|
3210
|
+
if ("bin" in manifest) {
|
|
3211
|
+
const bin = manifest.bin;
|
|
3212
|
+
if (typeof bin === "string") requirePath(bin);
|
|
3213
|
+
else if (bin && typeof bin === "object") {
|
|
3214
|
+
for (const file of Object.values(bin)) if (typeof file === "string") requirePath(file);
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
const files = /* @__PURE__ */ new Set();
|
|
3218
|
+
const entries = /* @__PURE__ */ new Set([""]);
|
|
3219
|
+
const visit = (directory, ancestors, inheritedIgnores) => {
|
|
3220
|
+
const children = readIfPresent(() => readdirSync(join(packageDir, directory)));
|
|
3221
|
+
if (!children) return;
|
|
3222
|
+
let ignores = inheritedIgnores;
|
|
3223
|
+
if (directory) {
|
|
3224
|
+
const ignore = readIfPresent(() => readFileSync(join(packageDir, directory, ".npmignore"), "utf8")) ?? readIfPresent(() => readFileSync(join(packageDir, directory, ".gitignore"), "utf8"));
|
|
3225
|
+
if (ignore) {
|
|
3226
|
+
const localRules = ignore.split(/\r?\n/).map((line) => line.trim()).filter((line) => line && !line.startsWith("#")).map(packageRule);
|
|
3227
|
+
ignores = [...ignores, (paths, included) => {
|
|
3228
|
+
for (const rule of localRules) if (paths.slice(ancestors.length).some((path) => rule.matches(path.slice(directory.length + 1)))) included = !rule.include;
|
|
3229
|
+
return included;
|
|
3230
|
+
}];
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
for (const child of children) {
|
|
3234
|
+
const path = join(directory, child);
|
|
3235
|
+
const portablePath = path.replaceAll(sep, "/");
|
|
3236
|
+
if (excludedEntry.test(child) || rootExcluded.has(portablePath) || child.includes("*")) continue;
|
|
3237
|
+
const prefixes = [...ancestors, portablePath];
|
|
3238
|
+
let included = false;
|
|
3239
|
+
for (const rule of rules) if (prefixes.some((prefix) => rule.matches(prefix))) included = rule.include;
|
|
3240
|
+
const includeFile = included && ignores.every((ignore) => ignore(prefixes, true)) || required.has(path) || !directory && alwaysPublishedFile.test(child);
|
|
3241
|
+
const includeDirectory = included || requiredAncestors.has(path) || rules.some((rule) => rule.include && rule.matches(portablePath, true));
|
|
3242
|
+
if (!includeFile && !includeDirectory) continue;
|
|
3243
|
+
const info = readIfPresent(() => lstatSync(join(packageDir, path)));
|
|
3244
|
+
if (info?.isDirectory() && includeDirectory) visit(path, prefixes, ignores);
|
|
3245
|
+
else if (info?.isFile() && includeFile) {
|
|
3246
|
+
files.add(path);
|
|
3247
|
+
for (let entry = path; entry !== "." && !entries.has(entry); entry = dirname(entry)) entries.add(entry);
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
3251
|
+
visit("", [], []);
|
|
3252
|
+
return {
|
|
3253
|
+
files,
|
|
3254
|
+
entries
|
|
3255
|
+
};
|
|
3256
|
+
}
|
|
3257
|
+
/** Copies a file or folder and follows links. `node_modules` folders and paths that disappear during the copy are skipped. */
|
|
3258
|
+
async function copyTree(source, target) {
|
|
3259
|
+
const info = await unlessGone(() => stat(source));
|
|
3260
|
+
if (!info) return;
|
|
3261
|
+
if (!info.isDirectory()) {
|
|
3262
|
+
await unlessGone(() => copyFile(source, target));
|
|
3263
|
+
return;
|
|
3264
|
+
}
|
|
3265
|
+
const entries = await unlessGone(() => readdir(source));
|
|
3266
|
+
if (!entries) return;
|
|
3267
|
+
await mkdir(target, { recursive: true });
|
|
3268
|
+
for (const entry of entries) if (entry !== "node_modules") await copyTree(join(source, entry), join(target, entry));
|
|
3269
|
+
}
|
|
3270
|
+
/**
|
|
3271
|
+
* Copies one runtime package into deployment output, without its `node_modules`.
|
|
3272
|
+
*
|
|
3273
|
+
* An installed package only holds its published files. A linked workspace package, such as a `link:` or `workspace:`
|
|
3274
|
+
* dependency, is a whole source folder with tests and fixtures, so only the files that `npm publish` would ship are
|
|
3275
|
+
* copied. A path that disappears during the copy, such as a temporary test folder that another process removes, is
|
|
3276
|
+
* skipped instead of failing the build.
|
|
3277
|
+
*/
|
|
3278
|
+
async function copyRuntimePackageFiles(packageDir, targetDir) {
|
|
3279
|
+
const paths = hasNodeModulesSegment$1(packageDir) ? void 0 : publishedPackagePaths(packageDir);
|
|
3280
|
+
if (!paths) {
|
|
3281
|
+
await copyTree(packageDir, targetDir);
|
|
3282
|
+
return;
|
|
3283
|
+
}
|
|
3284
|
+
await mkdir(targetDir, { recursive: true });
|
|
3285
|
+
for (const path of paths.files) {
|
|
3286
|
+
const target = join(targetDir, path);
|
|
3287
|
+
await mkdir(dirname(target), { recursive: true });
|
|
3288
|
+
await unlessGone(() => copyFile(join(packageDir, path), target));
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
// ../internal/src/build/provider-output-sources.ts
|
|
1007
3292
|
/** Removes retained provider output after readers release it, tolerating transient filesystem contention. */
|
|
1008
3293
|
async function removeProviderOutputArtifactDir(path) {
|
|
1009
3294
|
await rm(path, {
|
|
@@ -1013,8 +3298,10 @@ async function removeProviderOutputArtifactDir(path) {
|
|
|
1013
3298
|
retryDelay: 50
|
|
1014
3299
|
});
|
|
1015
3300
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
3301
|
+
// ../internal/src/build/vercel-config.ts
|
|
3302
|
+
function createDefaultVercelOutputRoot(rootDir) {
|
|
3303
|
+
return resolve(rootDir, ".vercel", "output");
|
|
3304
|
+
}
|
|
1018
3305
|
function createVercelConfigJson() {
|
|
1019
3306
|
return {
|
|
1020
3307
|
routes: [{ handle: "filesystem" }, {
|
|
@@ -1034,8 +3321,309 @@ function createNodeFunctionConfig(extra = {}) {
|
|
|
1034
3321
|
...extra
|
|
1035
3322
|
};
|
|
1036
3323
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
3324
|
+
// ../internal/src/build/runtime-package-resolution.ts
|
|
3325
|
+
/** Locates package metadata through exports, an entry's ancestors, or the project's dependency roots. */
|
|
3326
|
+
function createRuntimePackageResolver(readPackageName) {
|
|
3327
|
+
return async (name, resolver, fromDir) => {
|
|
3328
|
+
try {
|
|
3329
|
+
return resolver.resolve(`${name}/package.json`);
|
|
3330
|
+
} catch (error) {
|
|
3331
|
+
if (!isPackageResolutionMiss(error)) throw error;
|
|
3332
|
+
}
|
|
3333
|
+
try {
|
|
3334
|
+
let current = dirname(resolver.resolve(name));
|
|
3335
|
+
while (current !== dirname(current)) {
|
|
3336
|
+
const candidate = join(current, "package.json");
|
|
3337
|
+
try {
|
|
3338
|
+
await access(candidate);
|
|
3339
|
+
if (readPackageName(await readFile(candidate, "utf8"), candidate) === name) return candidate;
|
|
3340
|
+
} catch (error) {
|
|
3341
|
+
if (error.code !== "ENOENT") throw error;
|
|
3342
|
+
}
|
|
3343
|
+
current = dirname(current);
|
|
3344
|
+
}
|
|
3345
|
+
} catch (error) {
|
|
3346
|
+
if (!isPackageResolutionMiss(error)) throw error;
|
|
3347
|
+
}
|
|
3348
|
+
let current = fromDir;
|
|
3349
|
+
while (current !== dirname(current)) {
|
|
3350
|
+
const candidate = join(current, "node_modules", ...name.split("/"), "package.json");
|
|
3351
|
+
try {
|
|
3352
|
+
await access(candidate);
|
|
3353
|
+
return candidate;
|
|
3354
|
+
} catch (error) {
|
|
3355
|
+
if (error.code !== "ENOENT") throw error;
|
|
3356
|
+
}
|
|
3357
|
+
current = dirname(current);
|
|
3358
|
+
}
|
|
3359
|
+
};
|
|
3360
|
+
}
|
|
3361
|
+
function isPackageResolutionMiss(error) {
|
|
3362
|
+
const code = error?.code;
|
|
3363
|
+
return code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
3364
|
+
}
|
|
3365
|
+
// ../internal/src/build/runtime-package-directory.ts
|
|
3366
|
+
/** Update a staged copy, then publish it with rollback on failure or cancellation. */
|
|
3367
|
+
async function updateRuntimePackageDirectory(options) {
|
|
3368
|
+
const stagingRoot = await mkdtemp(join(dirname(options.directory), ".vitehub-runtime-packages-"));
|
|
3369
|
+
const stagedDirectory = join(stagingRoot, "node_modules");
|
|
3370
|
+
const previousDirectory = join(stagingRoot, "previous-node_modules");
|
|
3371
|
+
let movedPreviousOutput = false;
|
|
3372
|
+
let installedReplacement = false;
|
|
3373
|
+
let cleanupStagingRoot = true;
|
|
3374
|
+
try {
|
|
3375
|
+
try {
|
|
3376
|
+
await cp(options.directory, stagedDirectory, { recursive: true });
|
|
3377
|
+
} catch (error) {
|
|
3378
|
+
if (error.code !== "ENOENT") throw error;
|
|
3379
|
+
}
|
|
3380
|
+
await mkdir(stagedDirectory, { recursive: true });
|
|
3381
|
+
await options.update(stagedDirectory);
|
|
3382
|
+
options.signal?.throwIfAborted();
|
|
3383
|
+
try {
|
|
3384
|
+
await rename(options.directory, previousDirectory);
|
|
3385
|
+
movedPreviousOutput = true;
|
|
3386
|
+
cleanupStagingRoot = false;
|
|
3387
|
+
} catch (error) {
|
|
3388
|
+
if (error.code !== "ENOENT") throw error;
|
|
3389
|
+
}
|
|
3390
|
+
try {
|
|
3391
|
+
options.signal?.throwIfAborted();
|
|
3392
|
+
await rename(stagedDirectory, options.directory);
|
|
3393
|
+
installedReplacement = true;
|
|
3394
|
+
options.signal?.throwIfAborted();
|
|
3395
|
+
cleanupStagingRoot = true;
|
|
3396
|
+
} catch (error) {
|
|
3397
|
+
if (installedReplacement) await rm(options.directory, {
|
|
3398
|
+
force: true,
|
|
3399
|
+
recursive: true
|
|
3400
|
+
});
|
|
3401
|
+
if (movedPreviousOutput) await rename(previousDirectory, options.directory);
|
|
3402
|
+
cleanupStagingRoot = true;
|
|
3403
|
+
throw error;
|
|
3404
|
+
}
|
|
3405
|
+
} finally {
|
|
3406
|
+
if (cleanupStagingRoot) await rm(stagingRoot, {
|
|
3407
|
+
force: true,
|
|
3408
|
+
recursive: true
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
// ../internal/src/build/vercel-runtime-packages.ts
|
|
3413
|
+
const runtimeExportConditions = /* @__PURE__ */ new Set([
|
|
3414
|
+
"default",
|
|
3415
|
+
"import",
|
|
3416
|
+
"module",
|
|
3417
|
+
"node",
|
|
3418
|
+
"node-addons",
|
|
3419
|
+
"require"
|
|
3420
|
+
]);
|
|
3421
|
+
const resolvePackageJson = createRuntimePackageResolver((source, path) => parsePackageJson(JSON.parse(source), path).name);
|
|
3422
|
+
let nodeFileTracePromise;
|
|
3423
|
+
/** Collects the runtime packages that features add to Vercel functions, then traces and copies them once per function. */
|
|
3424
|
+
function createVercelFunctionRuntimePackagesPass(beforeWrite) {
|
|
3425
|
+
const requests = [];
|
|
3426
|
+
return {
|
|
3427
|
+
add(request) {
|
|
3428
|
+
requests.push(request);
|
|
3429
|
+
},
|
|
3430
|
+
async copy(signal) {
|
|
3431
|
+
const functions = /* @__PURE__ */ new Map();
|
|
3432
|
+
for (const request of requests.splice(0)) {
|
|
3433
|
+
const outputRoot = request.outputRoot ?? createDefaultVercelOutputRoot(request.rootDir);
|
|
3434
|
+
const serverDir = resolve(outputRoot, "functions", request.serverFunctionName ?? "__server.func");
|
|
3435
|
+
const entry = functions.get(serverDir) ?? {
|
|
3436
|
+
requests: [],
|
|
3437
|
+
rootDir: request.rootDir
|
|
3438
|
+
};
|
|
3439
|
+
entry.requests.push(request);
|
|
3440
|
+
functions.set(serverDir, entry);
|
|
3441
|
+
}
|
|
3442
|
+
for (const [serverDir, entry] of functions) await copyFunctionRuntimePackages(serverDir, entry.rootDir, entry.requests, signal, beforeWrite);
|
|
3443
|
+
}
|
|
3444
|
+
};
|
|
3445
|
+
}
|
|
3446
|
+
async function copyFunctionRuntimePackages(serverDir, rootDir, requests, signal, beforeWrite) {
|
|
3447
|
+
try {
|
|
3448
|
+
await access(serverDir);
|
|
3449
|
+
} catch (error) {
|
|
3450
|
+
if (error.code === "ENOENT") return;
|
|
3451
|
+
throw error;
|
|
3452
|
+
}
|
|
3453
|
+
const groups = [];
|
|
3454
|
+
for (const request of requests) {
|
|
3455
|
+
const requested = Array.isArray(request.packages) ? request.packages : await request.packages();
|
|
3456
|
+
if (requested.length) groups.push(requested.map((runtimePackage) => ({
|
|
3457
|
+
...runtimePackage,
|
|
3458
|
+
resolveFrom: runtimePackage.resolveFrom ?? join(request.rootDir, "package.json")
|
|
3459
|
+
})));
|
|
3460
|
+
}
|
|
3461
|
+
if (!groups.length) return;
|
|
3462
|
+
const directory = resolve(serverDir, "node_modules");
|
|
3463
|
+
await beforeWrite?.(directory);
|
|
3464
|
+
await updateRuntimePackageDirectory({
|
|
3465
|
+
directory,
|
|
3466
|
+
signal,
|
|
3467
|
+
update: (outputNodeModules) => copyNodeRuntimePackageGroups(outputNodeModules, rootDir, groups)
|
|
3468
|
+
});
|
|
3469
|
+
}
|
|
3470
|
+
async function copyNodeRuntimePackageGroups(outputNodeModules, rootDir, groups) {
|
|
3471
|
+
const selected = /* @__PURE__ */ new Map();
|
|
3472
|
+
const requested = /* @__PURE__ */ new Map();
|
|
3473
|
+
for (const packages of groups) {
|
|
3474
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3475
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
3476
|
+
for (const runtimePackage of packages) {
|
|
3477
|
+
const resolveFrom = runtimePackage.resolveFrom ?? join(rootDir, "package.json");
|
|
3478
|
+
const resolver = createRequire(resolveFrom);
|
|
3479
|
+
const packageJsonPath = await selectRuntimePackage(runtimePackage.name, resolver, dirname(resolveFrom), selected, visited, expanded, runtimePackage);
|
|
3480
|
+
if (!packageJsonPath) continue;
|
|
3481
|
+
const previous = requested.get(runtimePackage.name);
|
|
3482
|
+
if (previous && previous !== packageJsonPath) throw internalErrorDiagnostics.INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT({
|
|
3483
|
+
first: dirname(previous),
|
|
3484
|
+
name: runtimePackage.name,
|
|
3485
|
+
second: dirname(packageJsonPath)
|
|
3486
|
+
});
|
|
3487
|
+
requested.set(runtimePackage.name, packageJsonPath);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
for (const [name, { packageJson, packageJsonPath, resolver }] of selected) {
|
|
3491
|
+
const packageDir = dirname(packageJsonPath);
|
|
3492
|
+
const targetDir = join(outputNodeModules, ...name.split("/"));
|
|
3493
|
+
await rm(targetDir, {
|
|
3494
|
+
force: true,
|
|
3495
|
+
recursive: true
|
|
3496
|
+
});
|
|
3497
|
+
if (!await copyTracedPackageFiles(name, resolver, packageDir, packageJsonPath, packageJson, targetDir)) await copyRuntimePackageFiles(packageDir, targetDir);
|
|
3498
|
+
}
|
|
3499
|
+
}
|
|
3500
|
+
async function selectRuntimePackage(name, resolver, fromDir, selected, visited, expanded, options = { name }) {
|
|
3501
|
+
const packageJsonPath = await resolvePackageJson(name, resolver, fromDir);
|
|
3502
|
+
if (!packageJsonPath) {
|
|
3503
|
+
if (options.optional) return void 0;
|
|
3504
|
+
throw internalErrorDiagnostics.INTERNAL_B0046({ message: `Could not resolve package.json for ${name}.` });
|
|
3505
|
+
}
|
|
3506
|
+
const resolvedPackageJsonPath = await realpath(packageJsonPath);
|
|
3507
|
+
const packageDir = dirname(resolvedPackageJsonPath);
|
|
3508
|
+
const packageJson = parsePackageJson(JSON.parse(await readFile(resolvedPackageJsonPath, "utf8")), resolvedPackageJsonPath);
|
|
3509
|
+
const packageKey = `${name}\0${resolvedPackageJsonPath}`;
|
|
3510
|
+
if (!visited.has(packageKey)) {
|
|
3511
|
+
visited.add(packageKey);
|
|
3512
|
+
selected.set(name, {
|
|
3513
|
+
packageJson,
|
|
3514
|
+
packageJsonPath: resolvedPackageJsonPath,
|
|
3515
|
+
resolver
|
|
3516
|
+
});
|
|
3517
|
+
}
|
|
3518
|
+
const expansionKey = `${packageKey}\0${options.includePeerDependencies ? "peers" : "dependencies"}`;
|
|
3519
|
+
if (expanded.has(expansionKey)) return resolvedPackageJsonPath;
|
|
3520
|
+
expanded.add(expansionKey);
|
|
3521
|
+
const packageRequire = createRequire(resolvedPackageJsonPath);
|
|
3522
|
+
const dependencyNames = new Set(Object.keys(packageJson.dependencies || {}));
|
|
3523
|
+
const optionalDependencyNames = new Set(Object.keys(packageJson.optionalDependencies || {}));
|
|
3524
|
+
for (const dependencyName of optionalDependencyNames) dependencyNames.add(dependencyName);
|
|
3525
|
+
const requiredPeerDependencyNames = /* @__PURE__ */ new Set();
|
|
3526
|
+
if (options.includePeerDependencies) {
|
|
3527
|
+
for (const dependencyName of Object.keys(packageJson.peerDependencies || {})) if (!packageJson.peerDependenciesMeta?.[dependencyName]?.optional) {
|
|
3528
|
+
dependencyNames.add(dependencyName);
|
|
3529
|
+
requiredPeerDependencyNames.add(dependencyName);
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
for (const dependencyName of dependencyNames) await selectRuntimePackage(dependencyName, packageRequire, packageDir, selected, visited, expanded, {
|
|
3533
|
+
includePeerDependencies: options.includePeerDependencies,
|
|
3534
|
+
name: dependencyName,
|
|
3535
|
+
optional: optionalDependencyNames.has(dependencyName) && !requiredPeerDependencyNames.has(dependencyName)
|
|
3536
|
+
});
|
|
3537
|
+
return resolvedPackageJsonPath;
|
|
3538
|
+
}
|
|
3539
|
+
async function copyTracedPackageFiles(name, resolver, packageDir, packageJsonPath, packageJson, targetDir) {
|
|
3540
|
+
const entries = await resolvePackageTraceEntries(name, resolver, packageDir, packageJson);
|
|
3541
|
+
if (!entries) return false;
|
|
3542
|
+
const { fileList } = await (await loadNodeFileTrace())([...entries], {
|
|
3543
|
+
base: packageDir,
|
|
3544
|
+
conditions: ["node"],
|
|
3545
|
+
exportsOnly: true,
|
|
3546
|
+
processCwd: packageDir
|
|
3547
|
+
});
|
|
3548
|
+
fileList.add(relative(packageDir, packageJsonPath));
|
|
3549
|
+
for (const file of fileList) {
|
|
3550
|
+
const source = resolve(packageDir, file);
|
|
3551
|
+
if (!isInsideDirectory(packageDir, source) || hasNodeModulesSegment(file)) continue;
|
|
3552
|
+
if (!(await stat(source)).isFile()) continue;
|
|
3553
|
+
const target = resolve(targetDir, file);
|
|
3554
|
+
await mkdir(dirname(target), { recursive: true });
|
|
3555
|
+
await copyFile(source, target);
|
|
3556
|
+
}
|
|
3557
|
+
return true;
|
|
3558
|
+
}
|
|
3559
|
+
async function loadNodeFileTrace() {
|
|
3560
|
+
nodeFileTracePromise ??= import("./out-By90R-Bo.js").then((m) => /* @__PURE__ */ __toESM(m.default, 1)).then(({ nodeFileTrace }) => nodeFileTrace);
|
|
3561
|
+
return nodeFileTracePromise;
|
|
3562
|
+
}
|
|
3563
|
+
async function resolvePackageTraceEntries(name, resolver, packageDir, packageJson) {
|
|
3564
|
+
const entryCandidates = /* @__PURE__ */ new Set();
|
|
3565
|
+
if (packageJson.exports) {
|
|
3566
|
+
const exportedTargets = collectRuntimeExportTargets(packageJson.exports);
|
|
3567
|
+
if (!exportedTargets) return void 0;
|
|
3568
|
+
for (const target of exportedTargets) entryCandidates.add(resolve(packageDir, target));
|
|
3569
|
+
} else {
|
|
3570
|
+
try {
|
|
3571
|
+
entryCandidates.add(resolver.resolve(name));
|
|
3572
|
+
} catch (error) {
|
|
3573
|
+
if (!isPackageResolutionMiss(error)) throw error;
|
|
3574
|
+
}
|
|
3575
|
+
if (packageJson.main) entryCandidates.add(resolve(packageDir, packageJson.main));
|
|
3576
|
+
if (packageJson.module) entryCandidates.add(resolve(packageDir, packageJson.module));
|
|
3577
|
+
entryCandidates.add(resolve(packageDir, "index.js"));
|
|
3578
|
+
}
|
|
3579
|
+
const entries = [];
|
|
3580
|
+
for (const candidate of entryCandidates) try {
|
|
3581
|
+
const candidateStat = await stat(candidate);
|
|
3582
|
+
if (candidateStat.isFile()) entries.push(candidate);
|
|
3583
|
+
else if (candidateStat.isDirectory()) return void 0;
|
|
3584
|
+
} catch (error) {
|
|
3585
|
+
if (error.code !== "ENOENT") throw error;
|
|
3586
|
+
}
|
|
3587
|
+
return entries.length ? entries : void 0;
|
|
3588
|
+
}
|
|
3589
|
+
function collectRuntimeExportTargets(exportsValue, condition) {
|
|
3590
|
+
if (typeof exportsValue === "string") {
|
|
3591
|
+
if (condition === "types") return /* @__PURE__ */ new Set();
|
|
3592
|
+
if (exportsValue.includes("*")) return void 0;
|
|
3593
|
+
return exportsValue.startsWith("./") ? /* @__PURE__ */ new Set([exportsValue]) : /* @__PURE__ */ new Set();
|
|
3594
|
+
}
|
|
3595
|
+
if (Array.isArray(exportsValue)) {
|
|
3596
|
+
const targets = /* @__PURE__ */ new Set();
|
|
3597
|
+
for (const entry of exportsValue) {
|
|
3598
|
+
const entryTargets = collectRuntimeExportTargets(entry, condition);
|
|
3599
|
+
if (!entryTargets) return void 0;
|
|
3600
|
+
for (const target of entryTargets) targets.add(target);
|
|
3601
|
+
}
|
|
3602
|
+
return targets;
|
|
3603
|
+
}
|
|
3604
|
+
if (typeof exportsValue !== "object" || exportsValue === null) return /* @__PURE__ */ new Set();
|
|
3605
|
+
const targets = /* @__PURE__ */ new Set();
|
|
3606
|
+
for (const [key, value] of Object.entries(exportsValue)) {
|
|
3607
|
+
if (key === "types") continue;
|
|
3608
|
+
if (!key.startsWith(".") && !runtimeExportConditions.has(key)) continue;
|
|
3609
|
+
const entryTargets = collectRuntimeExportTargets(value, key);
|
|
3610
|
+
if (!entryTargets) return void 0;
|
|
3611
|
+
for (const target of entryTargets) targets.add(target);
|
|
3612
|
+
}
|
|
3613
|
+
return targets;
|
|
3614
|
+
}
|
|
3615
|
+
function hasNodeModulesSegment(path) {
|
|
3616
|
+
return path.split(/[\\/]/).includes("node_modules");
|
|
3617
|
+
}
|
|
3618
|
+
function isInsideDirectory(parent, child) {
|
|
3619
|
+
const childRelativePath = relative(parent, child);
|
|
3620
|
+
return childRelativePath === "" || !childRelativePath.startsWith(`..${sep}`) && childRelativePath !== ".." && !isAbsolute(childRelativePath);
|
|
3621
|
+
}
|
|
3622
|
+
function parsePackageJson(value, path) {
|
|
3623
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw internalErrorDiagnostics.INTERNAL_B0047({ message: `Expected ${path} to contain a JSON object.` });
|
|
3624
|
+
return value;
|
|
3625
|
+
}
|
|
3626
|
+
// ../internal/src/build/provider-output-catalog.ts
|
|
1039
3627
|
var ProviderOutputCatalog = class {
|
|
1040
3628
|
bundleDefines = {};
|
|
1041
3629
|
#appliedCloudflareContributions = /* @__PURE__ */ new Map();
|
|
@@ -1263,8 +3851,7 @@ function useProviderOutputCatalog(config) {
|
|
|
1263
3851
|
providerOutputCatalogs.set(config, catalog);
|
|
1264
3852
|
return catalog;
|
|
1265
3853
|
}
|
|
1266
|
-
|
|
1267
|
-
//#region ../internal/src/build/deployment-output.ts
|
|
3854
|
+
// ../internal/src/build/deployment-output.ts
|
|
1268
3855
|
const providerDeploymentOutputRegistry = globalThis;
|
|
1269
3856
|
const providerDeploymentOutputWrites = providerDeploymentOutputRegistry.__vitehubProviderDeploymentOutputWrites ??= /* @__PURE__ */ new Map();
|
|
1270
3857
|
const providerDeploymentOutputFinalizations = providerDeploymentOutputRegistry.__vitehubProviderDeploymentOutputFinalizations ??= /* @__PURE__ */ new WeakMap();
|
|
@@ -1355,9 +3942,6 @@ async function writeProviderOutputOwnershipFiles(outputRoot, ownership, files) {
|
|
|
1355
3942
|
await writeFile(file, `${JSON.stringify(values, null, 2)}\n`, "utf8");
|
|
1356
3943
|
}));
|
|
1357
3944
|
}
|
|
1358
|
-
function createDefaultVercelOutputRoot(rootDir) {
|
|
1359
|
-
return resolve(rootDir, ".vercel", "output");
|
|
1360
|
-
}
|
|
1361
3945
|
function createDefaultNetlifyOutputRoot(rootDir) {
|
|
1362
3946
|
return resolve(rootDir, ".netlify", "v1");
|
|
1363
3947
|
}
|
|
@@ -2198,9 +4782,11 @@ async function finalizeProviderDeploymentOutputs(catalog, options = {}) {
|
|
|
2198
4782
|
const write = withProviderDeploymentOutputRootLock(rootDir, async () => {
|
|
2199
4783
|
await withProviderDeploymentOutputRootTransaction(rootDir, async (transaction) => {
|
|
2200
4784
|
try {
|
|
4785
|
+
const vercelRuntimePackages = createVercelFunctionRuntimePackagesPass((nodeModules) => transaction.snapshot([nodeModules]));
|
|
2201
4786
|
for (const contribution of rootContributions) {
|
|
2202
4787
|
throwIfProviderOutputAborted(controller.signal);
|
|
2203
4788
|
await contribution.write({
|
|
4789
|
+
addVercelRuntimePackages: (request) => vercelRuntimePackages.add(request),
|
|
2204
4790
|
readCloudflareState: async (options) => await readCloudflareProviderDeploymentOutputState(rootDir, options),
|
|
2205
4791
|
signal: controller.signal,
|
|
2206
4792
|
write: async (writeOptions) => {
|
|
@@ -2216,6 +4802,8 @@ async function finalizeProviderDeploymentOutputs(catalog, options = {}) {
|
|
|
2216
4802
|
});
|
|
2217
4803
|
throwIfProviderOutputAborted(controller.signal);
|
|
2218
4804
|
}
|
|
4805
|
+
await vercelRuntimePackages.copy(controller.signal);
|
|
4806
|
+
throwIfProviderOutputAborted(controller.signal);
|
|
2219
4807
|
ready();
|
|
2220
4808
|
const rollback = await rootDecision;
|
|
2221
4809
|
if (rollback !== void 0) throw rollback;
|
|
@@ -2275,8 +4863,7 @@ async function finalizeProviderDeploymentOutputs(catalog, options = {}) {
|
|
|
2275
4863
|
if (providerDeploymentOutputFinalizations.get(catalog) === active) providerDeploymentOutputFinalizations.delete(catalog);
|
|
2276
4864
|
}
|
|
2277
4865
|
}
|
|
2278
|
-
|
|
2279
|
-
//#region ../internal/src/hints.ts
|
|
4866
|
+
// ../internal/src/hints.ts
|
|
2280
4867
|
/**
|
|
2281
4868
|
* The file that lists the hints of the last build or dev server, relative to the project root. A hint is a warning
|
|
2282
4869
|
* about something that works now and fails later, such as counts that stay in one server's memory. Agents and CI read
|
|
@@ -2354,8 +4941,7 @@ function startViteHubHints(config, owner = config) {
|
|
|
2354
4941
|
started.add(owner);
|
|
2355
4942
|
write(startRun(config));
|
|
2356
4943
|
}
|
|
2357
|
-
|
|
2358
|
-
//#region ../internal/src/provision-state.ts
|
|
4944
|
+
// ../internal/src/provision-state.ts
|
|
2359
4945
|
const PROVISION_STATE_FILE = ".vitehub/provision.json";
|
|
2360
4946
|
function getProvisionStatePath(rootDir) {
|
|
2361
4947
|
return resolve$1(rootDir, PROVISION_STATE_FILE);
|
|
@@ -2406,8 +4992,7 @@ function setOwn(target, key, value) {
|
|
|
2406
4992
|
writable: true
|
|
2407
4993
|
});
|
|
2408
4994
|
}
|
|
2409
|
-
|
|
2410
|
-
//#region ../internal/src/vite-stage.ts
|
|
4995
|
+
// ../internal/src/vite-stage.ts
|
|
2411
4996
|
/**
|
|
2412
4997
|
* Vite's `loadEnv(mode, envDir, "")`: every `.env` value of the mode and the whole shell. With `DEBUG=vite:env`, Vite
|
|
2413
4998
|
* logs that result to stderr, secrets included. loadEnv is synchronous, so this drops only the writes of this call.
|
|
@@ -2444,8 +5029,7 @@ function configureCloudflareKV(target, config, provisionState = {}) {
|
|
|
2444
5029
|
});
|
|
2445
5030
|
}
|
|
2446
5031
|
}
|
|
2447
|
-
|
|
2448
|
-
//#region src/inspect.ts
|
|
5032
|
+
// src/inspect.ts
|
|
2449
5033
|
function describeDevelopment(store) {
|
|
2450
5034
|
switch (store.driver) {
|
|
2451
5035
|
case "upstash": return "Remote. `vite dev` uses the real Upstash database, so writes change real data.";
|
|
@@ -2475,21 +5059,24 @@ function inspectKVStores(build, dev, file) {
|
|
|
2475
5059
|
};
|
|
2476
5060
|
});
|
|
2477
5061
|
}
|
|
2478
|
-
function cloudflareStores(options, env) {
|
|
5062
|
+
function cloudflareStores(options, env, hosting) {
|
|
2479
5063
|
const stores = /* @__PURE__ */ new Map();
|
|
2480
|
-
const kv = resolveKVViteConfig(options, {
|
|
5064
|
+
const kv = resolveKVViteConfig(options, {
|
|
5065
|
+
env,
|
|
5066
|
+
hosting
|
|
5067
|
+
}).kv;
|
|
2481
5068
|
if (!kv) return stores;
|
|
2482
5069
|
for (const [name, store] of Object.entries(kv.stores || { default: kv.store })) if (store.driver === "cloudflare") stores.set(name, store);
|
|
2483
5070
|
return stores;
|
|
2484
5071
|
}
|
|
2485
5072
|
/** Lists the Workers KV namespaces that KV Stores bind, with where each id comes from. Reads local config and Provision State only. */
|
|
2486
|
-
function inspectKVResources(options, provisionRoot, env = process.env) {
|
|
2487
|
-
const stores = cloudflareStores(options, env);
|
|
5073
|
+
function inspectKVResources(options, provisionRoot, env = process.env, hosting) {
|
|
5074
|
+
const stores = cloudflareStores(options, env, hosting);
|
|
2488
5075
|
if (!stores.size) return [];
|
|
2489
5076
|
const configured = cloudflareStores(options, {
|
|
2490
5077
|
...env,
|
|
2491
5078
|
KV_NAMESPACE_ID: void 0
|
|
2492
|
-
});
|
|
5079
|
+
}, hosting);
|
|
2493
5080
|
const provisionState = readProvisionStateSync(provisionRoot);
|
|
2494
5081
|
return [...stores].map(([storeName, store]) => {
|
|
2495
5082
|
const configuredId = configured.get(storeName)?.namespaceId;
|
|
@@ -2510,8 +5097,7 @@ function inspectKVResources(options, provisionRoot, env = process.env) {
|
|
|
2510
5097
|
};
|
|
2511
5098
|
});
|
|
2512
5099
|
}
|
|
2513
|
-
|
|
2514
|
-
//#region ../internal/src/host-credentials.ts
|
|
5100
|
+
// ../internal/src/host-credentials.ts
|
|
2515
5101
|
/** Reads host credentials from environment variables only. Returns undefined when the token is not set. */
|
|
2516
5102
|
function readHostCredentialsFromEnv(host, env) {
|
|
2517
5103
|
switch (host) {
|
|
@@ -2545,8 +5131,7 @@ function trimmed(value) {
|
|
|
2545
5131
|
const result = value?.trim();
|
|
2546
5132
|
return result ? result : void 0;
|
|
2547
5133
|
}
|
|
2548
|
-
|
|
2549
|
-
//#region ../internal/src/provider-failure.ts
|
|
5134
|
+
// ../internal/src/provider-failure.ts
|
|
2550
5135
|
const cloudflareCodes = {
|
|
2551
5136
|
d1: {},
|
|
2552
5137
|
kv: { 10014: "conflict" },
|
|
@@ -2648,8 +5233,7 @@ function readProviderErrorCodes(body) {
|
|
|
2648
5233
|
const errors = Reflect.get(body, "errors");
|
|
2649
5234
|
return [error && typeof error === "object" ? Reflect.get(error, "code") : void 0, ...Array.isArray(errors) ? errors.map((entry) => entry && typeof entry === "object" ? Reflect.get(entry, "code") : void 0) : []].filter((code) => typeof code === "number" && Number.isFinite(code) || typeof code === "string" && /^[\w.-]{1,128}$/.test(code));
|
|
2650
5235
|
}
|
|
2651
|
-
|
|
2652
|
-
//#region ../internal/src/provision.ts
|
|
5236
|
+
// ../internal/src/provision.ts
|
|
2653
5237
|
/**
|
|
2654
5238
|
* Whether a value from Provision State can appear in a copyable shell command as is.
|
|
2655
5239
|
* The file is editable, so a hint shows a command only for plain names and ids.
|
|
@@ -2771,8 +5355,7 @@ async function listCloudflarePages(request, path, options) {
|
|
|
2771
5355
|
} else if (options.perPage === void 0 || pageItems.length < options.perPage) return items;
|
|
2772
5356
|
}
|
|
2773
5357
|
}
|
|
2774
|
-
|
|
2775
|
-
//#region src/provision.ts
|
|
5358
|
+
// src/provision.ts
|
|
2776
5359
|
const CLOUDFLARE_KV_NAMESPACE_LIST_PER_PAGE = 100;
|
|
2777
5360
|
function parseNamespaces(value) {
|
|
2778
5361
|
if (!Array.isArray(value)) throw kvErrorDiagnostics.KV_PROVISION_FAILED({ problem: "Cloudflare returned an invalid KV namespace list." });
|
|
@@ -2871,8 +5454,7 @@ function createKVCloudflareProvisionStep(resolveOptions) {
|
|
|
2871
5454
|
}
|
|
2872
5455
|
};
|
|
2873
5456
|
}
|
|
2874
|
-
|
|
2875
|
-
//#region src/deployment-env.ts
|
|
5457
|
+
// src/deployment-env.ts
|
|
2876
5458
|
const owners = ["kv"];
|
|
2877
5459
|
const maskedRuntimeValue = "********";
|
|
2878
5460
|
function entry(names) {
|
|
@@ -2897,8 +5479,7 @@ function kvDeploymentEnv(config) {
|
|
|
2897
5479
|
if (!config) return [];
|
|
2898
5480
|
return Object.values(config.stores ?? { default: config.store }).flatMap(storeEntries);
|
|
2899
5481
|
}
|
|
2900
|
-
|
|
2901
|
-
//#region src/vite.ts
|
|
5482
|
+
// src/vite.ts
|
|
2902
5483
|
const operationsModule = ownModule(import.meta.url, "operations");
|
|
2903
5484
|
const RESOLVED_KV_VIRTUAL_CONFIG_ID = `\0${KV_VIRTUAL_CONFIG_ID}`;
|
|
2904
5485
|
const RESOLVED_KV_RUNTIME_ID = `\0#vitehub/kv/runtime`;
|
|
@@ -2938,7 +5519,6 @@ function hubKVOptionalPeerResolver() {
|
|
|
2938
5519
|
function kvStores(kv) {
|
|
2939
5520
|
return kv ? Object.values(kv.stores || { default: kv.store }) : [];
|
|
2940
5521
|
}
|
|
2941
|
-
/** Redis is selected explicitly at build time. */
|
|
2942
5522
|
function hasRedisStore(kv) {
|
|
2943
5523
|
return kvStores(kv).some((store) => store.driver === "redis");
|
|
2944
5524
|
}
|
|
@@ -2971,27 +5551,20 @@ function hasCloudflareKVStore(kv) {
|
|
|
2971
5551
|
if (!kv) return false;
|
|
2972
5552
|
return Object.values(kv.stores || { default: kv.store }).some((store) => store.driver === "cloudflare");
|
|
2973
5553
|
}
|
|
2974
|
-
/**
|
|
2975
|
-
* Registers the KV Nitro plugin for Redis connections and inferred-store boot notices. It prints the driver of each inferred store at boot, and
|
|
2976
|
-
* disposes the stores when the server closes. Without it, the open connection keeps a Node process alive after a stop
|
|
2977
|
-
* signal.
|
|
2978
|
-
*/
|
|
2979
5554
|
function configureNitroPlugin(nitro, kv) {
|
|
2980
5555
|
const plugins = (nitro.plugins ?? []).filter((plugin) => plugin !== KV_NITRO_PLUGIN);
|
|
2981
5556
|
if (hasRedisStore(kv) || kvStores(kv).some((store) => "inferred" in store && store.inferred)) plugins.push(KV_NITRO_PLUGIN);
|
|
2982
5557
|
if (plugins.length || nitro.plugins) nitro.plugins = plugins;
|
|
2983
5558
|
}
|
|
2984
|
-
/** The Nitro storage mount of a store: `kv` for the default store, `kv-<name>` for a named store. */
|
|
2985
5559
|
function kvStorageMountName(store) {
|
|
2986
5560
|
const segment = store.replace(/[%:/\\?]/g, (character) => encodeURIComponent(character)) || "%";
|
|
2987
5561
|
return store === "default" ? "kv" : `kv-${segment}`;
|
|
2988
5562
|
}
|
|
2989
|
-
/**
|
|
2990
|
-
* Mounts each KV store in Nitro storage, so `useStorage("kv")` and modules that take a mount name use the store.
|
|
2991
|
-
* A mount that the app set in `kv` or the deprecated `storage` option wins.
|
|
2992
|
-
*/
|
|
2993
5563
|
function configureNitroStorage(nitro, kv) {
|
|
2994
5564
|
if (!kv) return;
|
|
5565
|
+
const deps = nitro.deps ??= {};
|
|
5566
|
+
const paths = deps.paths ??= {};
|
|
5567
|
+
paths.unstorage ??= import.meta.resolve("unstorage");
|
|
2995
5568
|
const names = Object.keys({
|
|
2996
5569
|
default: kv.store,
|
|
2997
5570
|
...kv.stores
|
|
@@ -3008,7 +5581,6 @@ function configureNitroStorage(nitro, kv) {
|
|
|
3008
5581
|
}
|
|
3009
5582
|
if (Object.keys(mounts).length || nitro.kv) nitro.kv = mounts;
|
|
3010
5583
|
}
|
|
3011
|
-
/** Registers the middleware that installs the request's Cloudflare env, or removes it when no store uses a binding. */
|
|
3012
5584
|
function configureNitroCloudflareRequestEnv(nitro, kv) {
|
|
3013
5585
|
const handlers = Array.isArray(nitro.handlers) ? nitro.handlers.filter((handler) => !(isRecord(handler) && handler.handler === KV_CLOUDFLARE_REQUEST_ENV_MIDDLEWARE)) : [];
|
|
3014
5586
|
if (hasCloudflareKVStore(kv)) handlers.unshift({
|
|
@@ -3020,7 +5592,6 @@ function configureNitroCloudflareRequestEnv(nitro, kv) {
|
|
|
3020
5592
|
function hasUpstashStore(kv) {
|
|
3021
5593
|
return kvStores(kv).some((store) => store.driver === "upstash");
|
|
3022
5594
|
}
|
|
3023
|
-
/** The import of a provider driver from the KV runtime. A build without a store on that provider keeps it external. */
|
|
3024
5595
|
function isKVOptionalDriverImport(driver, id, importer) {
|
|
3025
5596
|
if (id !== driver || !importer) return false;
|
|
3026
5597
|
const normalizedImporter = importer.replace(/\\/g, "/").split("?", 1)[0];
|
|
@@ -3039,7 +5610,7 @@ function createCloudflareKVWranglerConfig(kv, provisionState) {
|
|
|
3039
5610
|
function serializeCloudflareRuntime(config) {
|
|
3040
5611
|
return [
|
|
3041
5612
|
`import { createCloudflareKVStorage } from ${JSON.stringify(CLOUDFLARE_KV_RUNTIME_IMPORT_ID)};`,
|
|
3042
|
-
`import { kvClearOptionsError, kvInvalidLimitError, kvKeyLimitCodes, kvListLimitInvalid, kvResult, kvStoreNotFoundError, kvStoreWithMode, kvUnsupportedOperationError,
|
|
5613
|
+
`import { kvClearOptionsError, kvInvalidLimitError, kvKeyLimitCodes, kvListLimitInvalid, kvResult, kvSetCodes, kvSetTTL, kvStoreNotFoundError, kvStoreWithMode, kvUnsupportedOperationError, listKVKeys } from ${JSON.stringify(KV_ERRORS_IMPORT_ID)};`,
|
|
3043
5614
|
"",
|
|
3044
5615
|
`const kvConfig = ${JSON.stringify(config, null, 2)}`,
|
|
3045
5616
|
"const storages = new Map();",
|
|
@@ -3087,8 +5658,8 @@ function serializeCloudflareRuntime(config) {
|
|
|
3087
5658
|
" async increment() { return unsupported(\"increment\", name); },",
|
|
3088
5659
|
" lock() { return { async acquire() { return unsupported(\"lock\", name); }, async run() { return unsupported(\"lock\", name); } }; },",
|
|
3089
5660
|
" async list(options = {}) { if (kvListLimitInvalid(options)) return [kvInvalidLimitError(), undefined]; return kvResult(\"list\", name, () => listKVKeys(page => resolveStorage(name).listKeys(page), options), [\"KV_INVALID_CURSOR\"]); },",
|
|
3090
|
-
" async set(key, value, options) { return kvResult(\"set\", name, async () => {
|
|
3091
|
-
" async setMany(entries, options) { return kvResult(\"setMany\", name, async () => {
|
|
5661
|
+
" async set(key, value, options) { return kvResult(\"set\", name, async () => { const storage = resolveStorage(name); const ttl = kvSetTTL(\"set\", options); await storage.setItem(key, value, ttl === undefined ? undefined : { ttl }); }, kvSetCodes); },",
|
|
5662
|
+
" async setMany(entries, options) { return kvResult(\"setMany\", name, async () => { const storage = resolveStorage(name); const ttl = kvSetTTL(\"setMany\", options); await storage.setMany(entries, ttl === undefined ? undefined : { ttl }); }, kvSetCodes); },",
|
|
3092
5663
|
" async setIfAbsent() { return unsupported(\"setIfAbsent\", name); },",
|
|
3093
5664
|
" store(storeName, options) { return kvStoreWithMode(createKVStorage(storeName), options); },",
|
|
3094
5665
|
" };",
|
|
@@ -3151,7 +5722,7 @@ function configureNitroCloudflareKV(config, options, input, ownedNamespaces, pro
|
|
|
3151
5722
|
const kv = resolveKVViteConfig(options, input).kv;
|
|
3152
5723
|
configureNitroCloudflareRequestEnv(target, kv);
|
|
3153
5724
|
configureNitroPlugin(target, kv);
|
|
3154
|
-
configureNitroStorage(target, kv);
|
|
5725
|
+
if (Reflect.get(config, "__vitehubNitroConfigContext") === true) configureNitroStorage(target, kv);
|
|
3155
5726
|
if (kv) {
|
|
3156
5727
|
const existingNamespaces = new Set(target.cloudflare?.wrangler?.kv_namespaces);
|
|
3157
5728
|
configureCloudflareKV(target, kv, provisionState);
|
|
@@ -3209,6 +5780,7 @@ function hubKV(options, input = {}) {
|
|
|
3209
5780
|
setup(nitro) {
|
|
3210
5781
|
nitroOptions = nitro.options;
|
|
3211
5782
|
if (runtimeConfig) reconcileNitroCloudflareKV(nitroOptions, runtimeConfig.kv, ownedNitroNamespaces, readProvisionStateSync(projectRoot));
|
|
5783
|
+
else configureNitroStorage(nitroOptions, resolveKVViteConfig(options, resolutionInput()).kv);
|
|
3212
5784
|
nitro.hooks?.hook("prerender:config", (config) => {
|
|
3213
5785
|
const prerender = resolveKVViteConfig(options, {
|
|
3214
5786
|
hosting: input.hosting,
|
|
@@ -3264,7 +5836,7 @@ function hubKV(options, input = {}) {
|
|
|
3264
5836
|
label: "KV stores",
|
|
3265
5837
|
list: () => inspectKVStores(build, dev, file)
|
|
3266
5838
|
}],
|
|
3267
|
-
resources: () => inspectKVResources(options, projectRoot)
|
|
5839
|
+
resources: () => inspectKVResources(options, projectRoot, process.env, input.hosting)
|
|
3268
5840
|
};
|
|
3269
5841
|
},
|
|
3270
5842
|
operations: [{
|
|
@@ -3286,6 +5858,7 @@ function hubKV(options, input = {}) {
|
|
|
3286
5858
|
config: {
|
|
3287
5859
|
order: "pre",
|
|
3288
5860
|
async handler(config, env) {
|
|
5861
|
+
if (env) markViteConfigPlugin(env, KV_VITE_PLUGIN_NAME);
|
|
3289
5862
|
command = env?.command ?? "build";
|
|
3290
5863
|
mode = env?.mode ?? config.mode ?? (command === "serve" ? "development" : "production");
|
|
3291
5864
|
runtimeConfig = void 0;
|
|
@@ -3422,5 +5995,4 @@ function hubKV(options, input = {}) {
|
|
|
3422
5995
|
}
|
|
3423
5996
|
};
|
|
3424
5997
|
}
|
|
3425
|
-
//#endregion
|
|
3426
5998
|
export { KV_VIRTUAL_CONFIG_ID, KV_VITE_PLUGIN_NAME, hubKV, hubKVOptionalPeerResolver, kvStorageDriver, resolveKVViteConfig };
|