@happyvertical/smrt-core 0.55.24 → 0.56.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/agents/collection-reads.md +6 -3
- package/agents/generators.md +53 -0
- package/agents/object-runtime.md +3 -0
- package/agents/recipes.md +7 -4
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +3 -1
- package/dist/collection.d.ts +4 -0
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +19 -9
- package/dist/collection.js.map +1 -1
- package/dist/consumer-plugin/hosted-sti-collections.d.ts.map +1 -1
- package/dist/consumer-plugin/hosted-sti-collections.js +4 -2
- package/dist/consumer-plugin/hosted-sti-collections.js.map +1 -1
- package/dist/cookbook/engine/commands.d.ts.map +1 -1
- package/dist/cookbook/engine/commands.js +12 -0
- package/dist/cookbook/engine/commands.js.map +1 -1
- package/dist/cookbook/engine/defaults.d.ts.map +1 -1
- package/dist/cookbook/engine/defaults.js +8 -0
- package/dist/cookbook/engine/defaults.js.map +1 -1
- package/dist/cookbook/engine/document.d.ts +4 -0
- package/dist/cookbook/engine/document.d.ts.map +1 -1
- package/dist/cookbook/engine/document.js +11 -3
- package/dist/cookbook/engine/document.js.map +1 -1
- package/dist/cookbook/engine/engine.d.ts.map +1 -1
- package/dist/cookbook/engine/engine.js +3 -1
- package/dist/cookbook/engine/engine.js.map +1 -1
- package/dist/cookbook/engine/schemas.d.ts.map +1 -1
- package/dist/cookbook/engine/schemas.js +8 -0
- package/dist/cookbook/engine/schemas.js.map +1 -1
- package/dist/cookbook/engine/types.d.ts +5 -1
- package/dist/cookbook/engine/types.d.ts.map +1 -1
- package/dist/cookbook/engine/types.js.map +1 -1
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -1
- package/dist/decorators/index.js.map +1 -1
- package/dist/generators/index.d.ts +1 -0
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +2 -1
- package/dist/generators/mcp-runtime-template.d.ts +3 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -1
- package/dist/generators/mcp-runtime-template.js +30 -4
- package/dist/generators/mcp-runtime-template.js.map +1 -1
- package/dist/generators/mcp.d.ts +5 -0
- package/dist/generators/mcp.d.ts.map +1 -1
- package/dist/generators/mcp.js +82 -9
- package/dist/generators/mcp.js.map +1 -1
- package/dist/generators/preflight-route.d.ts.map +1 -1
- package/dist/generators/preflight-route.js +3 -1
- package/dist/generators/preflight-route.js.map +1 -1
- package/dist/generators/rest.d.ts.map +1 -1
- package/dist/generators/rest.js +5 -0
- package/dist/generators/rest.js.map +1 -1
- package/dist/generators/swagger.d.ts.map +1 -1
- package/dist/generators/swagger.js +3 -1
- package/dist/generators/swagger.js.map +1 -1
- package/dist/generators.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/manifest/browser-capability.generated.js +34 -5
- package/dist/manifest/browser-capability.generated.js.map +1 -1
- package/dist/manifest/index.js +1 -1
- package/dist/manifest/static-manifest.d.ts.map +1 -1
- package/dist/manifest/static-manifest.js +9 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +1 -1
- package/dist/manifest/store.js.map +1 -1
- package/dist/manifest.json +9 -1
- package/dist/mcp-serializer.d.ts +38 -0
- package/dist/mcp-serializer.d.ts.map +1 -0
- package/dist/mcp-serializer.js +60 -0
- package/dist/mcp-serializer.js.map +1 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js +34 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/index.js.map +1 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/errors.js +343 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/errors.js.map +1 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/get-format.js +109 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/get-format.js.map +1 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/package-json-reader.js +102 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/package-json-reader.js.map +1 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/resolve.js +673 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/resolve.js.map +1 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/utils.js +32 -0
- package/dist/node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/utils.js.map +1 -0
- package/dist/object.d.ts +2 -0
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +51 -0
- package/dist/object.js.map +1 -1
- package/dist/operation-permission.d.ts +10 -0
- package/dist/operation-permission.d.ts.map +1 -0
- package/dist/operation-permission.js +36 -0
- package/dist/operation-permission.js.map +1 -0
- package/dist/registry/class-registration.d.ts.map +1 -1
- package/dist/registry/class-registration.js +12 -0
- package/dist/registry/class-registration.js.map +1 -1
- package/dist/registry/types.d.ts +18 -3
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.d.ts.map +1 -1
- package/dist/scanner/manifest-generator.js +47 -0
- package/dist/scanner/manifest-generator.js.map +1 -1
- package/dist/scanner/types.d.ts +5 -0
- package/dist/scanner/types.d.ts.map +1 -1
- package/dist/scanner/types.js.map +1 -1
- package/dist/smrt-knowledge.json +18 -11
- package/dist/utils/import-project-vite.js +1 -1
- package/dist/utils/import-workspace-module.js +1 -1
- package/dist/vite-plugin/api-client-entries.d.ts.map +1 -1
- package/dist/vite-plugin/api-client-entries.js +1 -0
- package/dist/vite-plugin/api-client-entries.js.map +1 -1
- package/dist/vite-plugin/dev-plane-route.js +1 -1
- package/dist/vite-plugin/import-build-aware.js +1 -1
- package/dist/vite-plugin/index.js +1 -1
- package/dist/vite-plugin/resources-route.js +1 -1
- package/dist/vite-plugin/sveltekit-generator.d.ts +0 -4
- package/dist/vite-plugin/sveltekit-generator.d.ts.map +1 -1
- package/dist/vite-plugin/sveltekit-generator.js +37 -25
- package/dist/vite-plugin/sveltekit-generator.js.map +1 -1
- package/package.json +16 -10
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
import { codes } from "./errors.js";
|
|
2
|
+
import { getPackageScopeConfig, read } from "./package-json-reader.js";
|
|
3
|
+
import { defaultGetFormatWithoutErrors } from "./get-format.js";
|
|
4
|
+
import { getConditionsSet } from "./utils.js";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
|
+
import assert from "node:assert";
|
|
8
|
+
import { realpathSync, statSync } from "node:fs";
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
import { builtinModules } from "node:module";
|
|
11
|
+
//#region ../../node_modules/.pnpm/import-meta-resolve@4.2.0/node_modules/import-meta-resolve/lib/resolve.js
|
|
12
|
+
/**
|
|
13
|
+
* @import {Stats} from 'node:fs'
|
|
14
|
+
* @import {ErrnoException} from './errors.js'
|
|
15
|
+
* @import {PackageConfig} from './package-json-reader.js'
|
|
16
|
+
*/
|
|
17
|
+
var RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace];
|
|
18
|
+
var { ERR_NETWORK_IMPORT_DISALLOWED, ERR_INVALID_MODULE_SPECIFIER, ERR_INVALID_PACKAGE_CONFIG, ERR_INVALID_PACKAGE_TARGET, ERR_MODULE_NOT_FOUND, ERR_PACKAGE_IMPORT_NOT_DEFINED, ERR_PACKAGE_PATH_NOT_EXPORTED, ERR_UNSUPPORTED_DIR_IMPORT, ERR_UNSUPPORTED_RESOLVE_REQUEST } = codes;
|
|
19
|
+
var own = {}.hasOwnProperty;
|
|
20
|
+
var invalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))?(\\|\/|$)/i;
|
|
21
|
+
var deprecatedInvalidSegmentRegEx = /(^|\\|\/)((\.|%2e)(\.|%2e)?|(n|%6e|%4e)(o|%6f|%4f)(d|%64|%44)(e|%65|%45)(_|%5f)(m|%6d|%4d)(o|%6f|%4f)(d|%64|%44)(u|%75|%55)(l|%6c|%4c)(e|%65|%45)(s|%73|%53))(\\|\/|$)/i;
|
|
22
|
+
var invalidPackageNameRegEx = /^\.|%|\\/;
|
|
23
|
+
var patternRegEx = /\*/g;
|
|
24
|
+
var encodedSeparatorRegEx = /%2f|%5c/i;
|
|
25
|
+
/** @type {Set<string>} */
|
|
26
|
+
var emittedPackageWarnings = /* @__PURE__ */ new Set();
|
|
27
|
+
var doubleSlashRegEx = /[/\\]{2}/;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param {string} target
|
|
31
|
+
* @param {string} request
|
|
32
|
+
* @param {string} match
|
|
33
|
+
* @param {URL} packageJsonUrl
|
|
34
|
+
* @param {boolean} internal
|
|
35
|
+
* @param {URL} base
|
|
36
|
+
* @param {boolean} isTarget
|
|
37
|
+
*/
|
|
38
|
+
function emitInvalidSegmentDeprecation(target, request, match, packageJsonUrl, internal, base, isTarget) {
|
|
39
|
+
if (process.noDeprecation) return;
|
|
40
|
+
const pjsonPath = fileURLToPath(packageJsonUrl);
|
|
41
|
+
const double = doubleSlashRegEx.exec(isTarget ? target : request) !== null;
|
|
42
|
+
process.emitWarning(`Use of deprecated ${double ? "double slash" : "leading or trailing slash matching"} resolving "${target}" for module request "${request}" ${request === match ? "" : `matched to "${match}" `}in the "${internal ? "imports" : "exports"}" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}.`, "DeprecationWarning", "DEP0166");
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @param {URL} url
|
|
46
|
+
* @param {URL} packageJsonUrl
|
|
47
|
+
* @param {URL} base
|
|
48
|
+
* @param {string} [main]
|
|
49
|
+
* @returns {void}
|
|
50
|
+
*/
|
|
51
|
+
function emitLegacyIndexDeprecation(url, packageJsonUrl, base, main) {
|
|
52
|
+
if (process.noDeprecation) return;
|
|
53
|
+
if (defaultGetFormatWithoutErrors(url, { parentURL: base.href }) !== "module") return;
|
|
54
|
+
const urlPath = fileURLToPath(url.href);
|
|
55
|
+
const packagePath = fileURLToPath(new URL(".", packageJsonUrl));
|
|
56
|
+
const basePath = fileURLToPath(base);
|
|
57
|
+
if (!main) process.emitWarning(`No "main" or "exports" field defined in the package.json for ${packagePath} resolving the main entry point "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\nDefault "index" lookups for the main are deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
|
|
58
|
+
else if (path.resolve(packagePath, main) !== urlPath) process.emitWarning(`Package ${packagePath} has a "main" field set to "${main}", excluding the full filename and extension to the resolved file at "${urlPath.slice(packagePath.length)}", imported from ${basePath}.\n Automatic extension resolution of the "main" field is deprecated for ES modules.`, "DeprecationWarning", "DEP0151");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} path
|
|
62
|
+
* @returns {Stats | undefined}
|
|
63
|
+
*/
|
|
64
|
+
function tryStatSync(path) {
|
|
65
|
+
try {
|
|
66
|
+
return statSync(path);
|
|
67
|
+
} catch {}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Legacy CommonJS main resolution:
|
|
71
|
+
* 1. let M = pkg_url + (json main field)
|
|
72
|
+
* 2. TRY(M, M.js, M.json, M.node)
|
|
73
|
+
* 3. TRY(M/index.js, M/index.json, M/index.node)
|
|
74
|
+
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
|
|
75
|
+
* 5. NOT_FOUND
|
|
76
|
+
*
|
|
77
|
+
* @param {URL} url
|
|
78
|
+
* @returns {boolean}
|
|
79
|
+
*/
|
|
80
|
+
function fileExists(url) {
|
|
81
|
+
const stats = statSync(url, { throwIfNoEntry: false });
|
|
82
|
+
const isFile = stats ? stats.isFile() : void 0;
|
|
83
|
+
return isFile === null || isFile === void 0 ? false : isFile;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @param {URL} packageJsonUrl
|
|
87
|
+
* @param {PackageConfig} packageConfig
|
|
88
|
+
* @param {URL} base
|
|
89
|
+
* @returns {URL}
|
|
90
|
+
*/
|
|
91
|
+
function legacyMainResolve(packageJsonUrl, packageConfig, base) {
|
|
92
|
+
/** @type {URL | undefined} */
|
|
93
|
+
let guess;
|
|
94
|
+
if (packageConfig.main !== void 0) {
|
|
95
|
+
guess = new URL(packageConfig.main, packageJsonUrl);
|
|
96
|
+
if (fileExists(guess)) return guess;
|
|
97
|
+
const tries = [
|
|
98
|
+
`./${packageConfig.main}.js`,
|
|
99
|
+
`./${packageConfig.main}.json`,
|
|
100
|
+
`./${packageConfig.main}.node`,
|
|
101
|
+
`./${packageConfig.main}/index.js`,
|
|
102
|
+
`./${packageConfig.main}/index.json`,
|
|
103
|
+
`./${packageConfig.main}/index.node`
|
|
104
|
+
];
|
|
105
|
+
let i = -1;
|
|
106
|
+
while (++i < tries.length) {
|
|
107
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
108
|
+
if (fileExists(guess)) break;
|
|
109
|
+
guess = void 0;
|
|
110
|
+
}
|
|
111
|
+
if (guess) {
|
|
112
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
113
|
+
return guess;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const tries = [
|
|
117
|
+
"./index.js",
|
|
118
|
+
"./index.json",
|
|
119
|
+
"./index.node"
|
|
120
|
+
];
|
|
121
|
+
let i = -1;
|
|
122
|
+
while (++i < tries.length) {
|
|
123
|
+
guess = new URL(tries[i], packageJsonUrl);
|
|
124
|
+
if (fileExists(guess)) break;
|
|
125
|
+
guess = void 0;
|
|
126
|
+
}
|
|
127
|
+
if (guess) {
|
|
128
|
+
emitLegacyIndexDeprecation(guess, packageJsonUrl, base, packageConfig.main);
|
|
129
|
+
return guess;
|
|
130
|
+
}
|
|
131
|
+
throw new ERR_MODULE_NOT_FOUND(fileURLToPath(new URL(".", packageJsonUrl)), fileURLToPath(base));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @param {URL} resolved
|
|
135
|
+
* @param {URL} base
|
|
136
|
+
* @param {boolean} [preserveSymlinks]
|
|
137
|
+
* @returns {URL}
|
|
138
|
+
*/
|
|
139
|
+
function finalizeResolution(resolved, base, preserveSymlinks) {
|
|
140
|
+
if (encodedSeparatorRegEx.exec(resolved.pathname) !== null) throw new ERR_INVALID_MODULE_SPECIFIER(resolved.pathname, "must not include encoded \"/\" or \"\\\" characters", fileURLToPath(base));
|
|
141
|
+
/** @type {string} */
|
|
142
|
+
let filePath;
|
|
143
|
+
try {
|
|
144
|
+
filePath = fileURLToPath(resolved);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
const cause = error;
|
|
147
|
+
Object.defineProperty(cause, "input", { value: String(resolved) });
|
|
148
|
+
Object.defineProperty(cause, "module", { value: String(base) });
|
|
149
|
+
throw cause;
|
|
150
|
+
}
|
|
151
|
+
const stats = tryStatSync(filePath.endsWith("/") ? filePath.slice(-1) : filePath);
|
|
152
|
+
if (stats && stats.isDirectory()) {
|
|
153
|
+
const error = new ERR_UNSUPPORTED_DIR_IMPORT(filePath, fileURLToPath(base));
|
|
154
|
+
error.url = String(resolved);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
if (!stats || !stats.isFile()) {
|
|
158
|
+
const error = new ERR_MODULE_NOT_FOUND(filePath || resolved.pathname, base && fileURLToPath(base), true);
|
|
159
|
+
error.url = String(resolved);
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
if (!preserveSymlinks) {
|
|
163
|
+
const real = realpathSync(filePath);
|
|
164
|
+
const { search, hash } = resolved;
|
|
165
|
+
resolved = pathToFileURL(real + (filePath.endsWith(path.sep) ? "/" : ""));
|
|
166
|
+
resolved.search = search;
|
|
167
|
+
resolved.hash = hash;
|
|
168
|
+
}
|
|
169
|
+
return resolved;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @param {string} specifier
|
|
173
|
+
* @param {URL | undefined} packageJsonUrl
|
|
174
|
+
* @param {URL} base
|
|
175
|
+
* @returns {Error}
|
|
176
|
+
*/
|
|
177
|
+
function importNotDefined(specifier, packageJsonUrl, base) {
|
|
178
|
+
return new ERR_PACKAGE_IMPORT_NOT_DEFINED(specifier, packageJsonUrl && fileURLToPath(new URL(".", packageJsonUrl)), fileURLToPath(base));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @param {string} subpath
|
|
182
|
+
* @param {URL} packageJsonUrl
|
|
183
|
+
* @param {URL} base
|
|
184
|
+
* @returns {Error}
|
|
185
|
+
*/
|
|
186
|
+
function exportsNotFound(subpath, packageJsonUrl, base) {
|
|
187
|
+
return new ERR_PACKAGE_PATH_NOT_EXPORTED(fileURLToPath(new URL(".", packageJsonUrl)), subpath, base && fileURLToPath(base));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @param {string} request
|
|
191
|
+
* @param {string} match
|
|
192
|
+
* @param {URL} packageJsonUrl
|
|
193
|
+
* @param {boolean} internal
|
|
194
|
+
* @param {URL} [base]
|
|
195
|
+
* @returns {never}
|
|
196
|
+
*/
|
|
197
|
+
function throwInvalidSubpath(request, match, packageJsonUrl, internal, base) {
|
|
198
|
+
throw new ERR_INVALID_MODULE_SPECIFIER(request, `request is not a valid match in pattern "${match}" for the "${internal ? "imports" : "exports"}" resolution of ${fileURLToPath(packageJsonUrl)}`, base && fileURLToPath(base));
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* @param {string} subpath
|
|
202
|
+
* @param {unknown} target
|
|
203
|
+
* @param {URL} packageJsonUrl
|
|
204
|
+
* @param {boolean} internal
|
|
205
|
+
* @param {URL} [base]
|
|
206
|
+
* @returns {Error}
|
|
207
|
+
*/
|
|
208
|
+
function invalidPackageTarget(subpath, target, packageJsonUrl, internal, base) {
|
|
209
|
+
target = typeof target === "object" && target !== null ? JSON.stringify(target, null, "") : `${target}`;
|
|
210
|
+
return new ERR_INVALID_PACKAGE_TARGET(fileURLToPath(new URL(".", packageJsonUrl)), subpath, target, internal, base && fileURLToPath(base));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* @param {string} target
|
|
214
|
+
* @param {string} subpath
|
|
215
|
+
* @param {string} match
|
|
216
|
+
* @param {URL} packageJsonUrl
|
|
217
|
+
* @param {URL} base
|
|
218
|
+
* @param {boolean} pattern
|
|
219
|
+
* @param {boolean} internal
|
|
220
|
+
* @param {boolean} isPathMap
|
|
221
|
+
* @param {Set<string> | undefined} conditions
|
|
222
|
+
* @returns {URL}
|
|
223
|
+
*/
|
|
224
|
+
function resolvePackageTargetString(target, subpath, match, packageJsonUrl, base, pattern, internal, isPathMap, conditions) {
|
|
225
|
+
if (subpath !== "" && !pattern && target[target.length - 1] !== "/") throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
226
|
+
if (!target.startsWith("./")) {
|
|
227
|
+
if (internal && !target.startsWith("../") && !target.startsWith("/")) {
|
|
228
|
+
let isURL = false;
|
|
229
|
+
try {
|
|
230
|
+
new URL(target);
|
|
231
|
+
isURL = true;
|
|
232
|
+
} catch {}
|
|
233
|
+
if (!isURL) return packageResolve(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target + subpath, packageJsonUrl, conditions);
|
|
234
|
+
}
|
|
235
|
+
throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
236
|
+
}
|
|
237
|
+
if (invalidSegmentRegEx.exec(target.slice(2)) !== null) if (deprecatedInvalidSegmentRegEx.exec(target.slice(2)) === null) {
|
|
238
|
+
if (!isPathMap) {
|
|
239
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
240
|
+
emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, true);
|
|
241
|
+
}
|
|
242
|
+
} else throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
243
|
+
const resolved = new URL(target, packageJsonUrl);
|
|
244
|
+
const resolvedPath = resolved.pathname;
|
|
245
|
+
const packagePath = new URL(".", packageJsonUrl).pathname;
|
|
246
|
+
if (!resolvedPath.startsWith(packagePath)) throw invalidPackageTarget(match, target, packageJsonUrl, internal, base);
|
|
247
|
+
if (subpath === "") return resolved;
|
|
248
|
+
if (invalidSegmentRegEx.exec(subpath) !== null) {
|
|
249
|
+
const request = pattern ? match.replace("*", () => subpath) : match + subpath;
|
|
250
|
+
if (deprecatedInvalidSegmentRegEx.exec(subpath) === null) {
|
|
251
|
+
if (!isPathMap) emitInvalidSegmentDeprecation(pattern ? RegExpPrototypeSymbolReplace.call(patternRegEx, target, () => subpath) : target, request, match, packageJsonUrl, internal, base, false);
|
|
252
|
+
} else throwInvalidSubpath(request, match, packageJsonUrl, internal, base);
|
|
253
|
+
}
|
|
254
|
+
if (pattern) return new URL(RegExpPrototypeSymbolReplace.call(patternRegEx, resolved.href, () => subpath));
|
|
255
|
+
return new URL(subpath, resolved);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @param {string} key
|
|
259
|
+
* @returns {boolean}
|
|
260
|
+
*/
|
|
261
|
+
function isArrayIndex(key) {
|
|
262
|
+
const keyNumber = Number(key);
|
|
263
|
+
if (`${keyNumber}` !== key) return false;
|
|
264
|
+
return keyNumber >= 0 && keyNumber < 4294967295;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* @param {URL} packageJsonUrl
|
|
268
|
+
* @param {unknown} target
|
|
269
|
+
* @param {string} subpath
|
|
270
|
+
* @param {string} packageSubpath
|
|
271
|
+
* @param {URL} base
|
|
272
|
+
* @param {boolean} pattern
|
|
273
|
+
* @param {boolean} internal
|
|
274
|
+
* @param {boolean} isPathMap
|
|
275
|
+
* @param {Set<string> | undefined} conditions
|
|
276
|
+
* @returns {URL | null}
|
|
277
|
+
*/
|
|
278
|
+
function resolvePackageTarget(packageJsonUrl, target, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions) {
|
|
279
|
+
if (typeof target === "string") return resolvePackageTargetString(target, subpath, packageSubpath, packageJsonUrl, base, pattern, internal, isPathMap, conditions);
|
|
280
|
+
if (Array.isArray(target)) {
|
|
281
|
+
/** @type {Array<unknown>} */
|
|
282
|
+
const targetList = target;
|
|
283
|
+
if (targetList.length === 0) return null;
|
|
284
|
+
/** @type {ErrnoException | null | undefined} */
|
|
285
|
+
let lastException;
|
|
286
|
+
let i = -1;
|
|
287
|
+
while (++i < targetList.length) {
|
|
288
|
+
const targetItem = targetList[i];
|
|
289
|
+
/** @type {URL | null} */
|
|
290
|
+
let resolveResult;
|
|
291
|
+
try {
|
|
292
|
+
resolveResult = resolvePackageTarget(packageJsonUrl, targetItem, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
const exception = error;
|
|
295
|
+
lastException = exception;
|
|
296
|
+
if (exception.code === "ERR_INVALID_PACKAGE_TARGET") continue;
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
if (resolveResult === void 0) continue;
|
|
300
|
+
if (resolveResult === null) {
|
|
301
|
+
lastException = null;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
return resolveResult;
|
|
305
|
+
}
|
|
306
|
+
if (lastException === void 0 || lastException === null) return null;
|
|
307
|
+
throw lastException;
|
|
308
|
+
}
|
|
309
|
+
if (typeof target === "object" && target !== null) {
|
|
310
|
+
const keys = Object.getOwnPropertyNames(target);
|
|
311
|
+
let i = -1;
|
|
312
|
+
while (++i < keys.length) {
|
|
313
|
+
const key = keys[i];
|
|
314
|
+
if (isArrayIndex(key)) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), base, "\"exports\" cannot contain numeric property keys.");
|
|
315
|
+
}
|
|
316
|
+
i = -1;
|
|
317
|
+
while (++i < keys.length) {
|
|
318
|
+
const key = keys[i];
|
|
319
|
+
if (key === "default" || conditions && conditions.has(key)) {
|
|
320
|
+
const conditionalTarget = target[key];
|
|
321
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, conditionalTarget, subpath, packageSubpath, base, pattern, internal, isPathMap, conditions);
|
|
322
|
+
if (resolveResult === void 0) continue;
|
|
323
|
+
return resolveResult;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
if (target === null) return null;
|
|
329
|
+
throw invalidPackageTarget(packageSubpath, target, packageJsonUrl, internal, base);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* @param {unknown} exports
|
|
333
|
+
* @param {URL} packageJsonUrl
|
|
334
|
+
* @param {URL} base
|
|
335
|
+
* @returns {boolean}
|
|
336
|
+
*/
|
|
337
|
+
function isConditionalExportsMainSugar(exports, packageJsonUrl, base) {
|
|
338
|
+
if (typeof exports === "string" || Array.isArray(exports)) return true;
|
|
339
|
+
if (typeof exports !== "object" || exports === null) return false;
|
|
340
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
341
|
+
let isConditionalSugar = false;
|
|
342
|
+
let i = 0;
|
|
343
|
+
let keyIndex = -1;
|
|
344
|
+
while (++keyIndex < keys.length) {
|
|
345
|
+
const key = keys[keyIndex];
|
|
346
|
+
const currentIsConditionalSugar = key === "" || key[0] !== ".";
|
|
347
|
+
if (i++ === 0) isConditionalSugar = currentIsConditionalSugar;
|
|
348
|
+
else if (isConditionalSugar !== currentIsConditionalSugar) throw new ERR_INVALID_PACKAGE_CONFIG(fileURLToPath(packageJsonUrl), base, "\"exports\" cannot contain some keys starting with '.' and some not. The exports object must either be an object of package subpath keys or an object of main entry condition name keys only.");
|
|
349
|
+
}
|
|
350
|
+
return isConditionalSugar;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* @param {string} match
|
|
354
|
+
* @param {URL} pjsonUrl
|
|
355
|
+
* @param {URL} base
|
|
356
|
+
*/
|
|
357
|
+
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
|
|
358
|
+
if (process.noDeprecation) return;
|
|
359
|
+
const pjsonPath = fileURLToPath(pjsonUrl);
|
|
360
|
+
if (emittedPackageWarnings.has(pjsonPath + "|" + match)) return;
|
|
361
|
+
emittedPackageWarnings.add(pjsonPath + "|" + match);
|
|
362
|
+
process.emitWarning(`Use of deprecated trailing slash pattern mapping "${match}" in the "exports" field module resolution of the package at ${pjsonPath}${base ? ` imported from ${fileURLToPath(base)}` : ""}. Mapping specifiers ending in "/" is no longer supported.`, "DeprecationWarning", "DEP0155");
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* @param {URL} packageJsonUrl
|
|
366
|
+
* @param {string} packageSubpath
|
|
367
|
+
* @param {Record<string, unknown>} packageConfig
|
|
368
|
+
* @param {URL} base
|
|
369
|
+
* @param {Set<string> | undefined} conditions
|
|
370
|
+
* @returns {URL}
|
|
371
|
+
*/
|
|
372
|
+
function packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions) {
|
|
373
|
+
let exports = packageConfig.exports;
|
|
374
|
+
if (isConditionalExportsMainSugar(exports, packageJsonUrl, base)) exports = { ".": exports };
|
|
375
|
+
if (own.call(exports, packageSubpath) && !packageSubpath.includes("*") && !packageSubpath.endsWith("/")) {
|
|
376
|
+
const target = exports[packageSubpath];
|
|
377
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, target, "", packageSubpath, base, false, false, false, conditions);
|
|
378
|
+
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
379
|
+
return resolveResult;
|
|
380
|
+
}
|
|
381
|
+
let bestMatch = "";
|
|
382
|
+
let bestMatchSubpath = "";
|
|
383
|
+
const keys = Object.getOwnPropertyNames(exports);
|
|
384
|
+
let i = -1;
|
|
385
|
+
while (++i < keys.length) {
|
|
386
|
+
const key = keys[i];
|
|
387
|
+
const patternIndex = key.indexOf("*");
|
|
388
|
+
if (patternIndex !== -1 && packageSubpath.startsWith(key.slice(0, patternIndex))) {
|
|
389
|
+
if (packageSubpath.endsWith("/")) emitTrailingSlashPatternDeprecation(packageSubpath, packageJsonUrl, base);
|
|
390
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
391
|
+
if (packageSubpath.length >= key.length && packageSubpath.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
392
|
+
bestMatch = key;
|
|
393
|
+
bestMatchSubpath = packageSubpath.slice(patternIndex, packageSubpath.length - patternTrailer.length);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (bestMatch) {
|
|
398
|
+
const target = exports[bestMatch];
|
|
399
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, false, packageSubpath.endsWith("/"), conditions);
|
|
400
|
+
if (resolveResult === null || resolveResult === void 0) throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
401
|
+
return resolveResult;
|
|
402
|
+
}
|
|
403
|
+
throw exportsNotFound(packageSubpath, packageJsonUrl, base);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* @param {string} a
|
|
407
|
+
* @param {string} b
|
|
408
|
+
*/
|
|
409
|
+
function patternKeyCompare(a, b) {
|
|
410
|
+
const aPatternIndex = a.indexOf("*");
|
|
411
|
+
const bPatternIndex = b.indexOf("*");
|
|
412
|
+
const baseLengthA = aPatternIndex === -1 ? a.length : aPatternIndex + 1;
|
|
413
|
+
const baseLengthB = bPatternIndex === -1 ? b.length : bPatternIndex + 1;
|
|
414
|
+
if (baseLengthA > baseLengthB) return -1;
|
|
415
|
+
if (baseLengthB > baseLengthA) return 1;
|
|
416
|
+
if (aPatternIndex === -1) return 1;
|
|
417
|
+
if (bPatternIndex === -1) return -1;
|
|
418
|
+
if (a.length > b.length) return -1;
|
|
419
|
+
if (b.length > a.length) return 1;
|
|
420
|
+
return 0;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* @param {string} name
|
|
424
|
+
* @param {URL} base
|
|
425
|
+
* @param {Set<string>} [conditions]
|
|
426
|
+
* @returns {URL}
|
|
427
|
+
*/
|
|
428
|
+
function packageImportsResolve(name, base, conditions) {
|
|
429
|
+
if (name === "#" || name.startsWith("#/") || name.endsWith("/")) throw new ERR_INVALID_MODULE_SPECIFIER(name, "is not a valid internal imports specifier name", fileURLToPath(base));
|
|
430
|
+
/** @type {URL | undefined} */
|
|
431
|
+
let packageJsonUrl;
|
|
432
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
433
|
+
if (packageConfig.exists) {
|
|
434
|
+
packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
435
|
+
const imports = packageConfig.imports;
|
|
436
|
+
if (imports) if (own.call(imports, name) && !name.includes("*")) {
|
|
437
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, imports[name], "", name, base, false, true, false, conditions);
|
|
438
|
+
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
439
|
+
} else {
|
|
440
|
+
let bestMatch = "";
|
|
441
|
+
let bestMatchSubpath = "";
|
|
442
|
+
const keys = Object.getOwnPropertyNames(imports);
|
|
443
|
+
let i = -1;
|
|
444
|
+
while (++i < keys.length) {
|
|
445
|
+
const key = keys[i];
|
|
446
|
+
const patternIndex = key.indexOf("*");
|
|
447
|
+
if (patternIndex !== -1 && name.startsWith(key.slice(0, -1))) {
|
|
448
|
+
const patternTrailer = key.slice(patternIndex + 1);
|
|
449
|
+
if (name.length >= key.length && name.endsWith(patternTrailer) && patternKeyCompare(bestMatch, key) === 1 && key.lastIndexOf("*") === patternIndex) {
|
|
450
|
+
bestMatch = key;
|
|
451
|
+
bestMatchSubpath = name.slice(patternIndex, name.length - patternTrailer.length);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (bestMatch) {
|
|
456
|
+
const target = imports[bestMatch];
|
|
457
|
+
const resolveResult = resolvePackageTarget(packageJsonUrl, target, bestMatchSubpath, bestMatch, base, true, true, false, conditions);
|
|
458
|
+
if (resolveResult !== null && resolveResult !== void 0) return resolveResult;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
throw importNotDefined(name, packageJsonUrl, base);
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* @param {string} specifier
|
|
466
|
+
* @param {URL} base
|
|
467
|
+
*/
|
|
468
|
+
function parsePackageName(specifier, base) {
|
|
469
|
+
let separatorIndex = specifier.indexOf("/");
|
|
470
|
+
let validPackageName = true;
|
|
471
|
+
let isScoped = false;
|
|
472
|
+
if (specifier[0] === "@") {
|
|
473
|
+
isScoped = true;
|
|
474
|
+
if (separatorIndex === -1 || specifier.length === 0) validPackageName = false;
|
|
475
|
+
else separatorIndex = specifier.indexOf("/", separatorIndex + 1);
|
|
476
|
+
}
|
|
477
|
+
const packageName = separatorIndex === -1 ? specifier : specifier.slice(0, separatorIndex);
|
|
478
|
+
if (invalidPackageNameRegEx.exec(packageName) !== null) validPackageName = false;
|
|
479
|
+
if (!validPackageName) throw new ERR_INVALID_MODULE_SPECIFIER(specifier, "is not a valid package name", fileURLToPath(base));
|
|
480
|
+
return {
|
|
481
|
+
packageName,
|
|
482
|
+
packageSubpath: "." + (separatorIndex === -1 ? "" : specifier.slice(separatorIndex)),
|
|
483
|
+
isScoped
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* @param {string} specifier
|
|
488
|
+
* @param {URL} base
|
|
489
|
+
* @param {Set<string> | undefined} conditions
|
|
490
|
+
* @returns {URL}
|
|
491
|
+
*/
|
|
492
|
+
function packageResolve(specifier, base, conditions) {
|
|
493
|
+
if (builtinModules.includes(specifier)) return new URL("node:" + specifier);
|
|
494
|
+
const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
|
|
495
|
+
const packageConfig = getPackageScopeConfig(base);
|
|
496
|
+
/* c8 ignore next 16 */
|
|
497
|
+
if (packageConfig.exists) {
|
|
498
|
+
const packageJsonUrl = pathToFileURL(packageConfig.pjsonPath);
|
|
499
|
+
if (packageConfig.name === packageName && packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
|
|
500
|
+
}
|
|
501
|
+
let packageJsonUrl = new URL("./node_modules/" + packageName + "/package.json", base);
|
|
502
|
+
let packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
503
|
+
/** @type {string} */
|
|
504
|
+
let lastPath;
|
|
505
|
+
do {
|
|
506
|
+
const stat = tryStatSync(packageJsonPath.slice(0, -13));
|
|
507
|
+
if (!stat || !stat.isDirectory()) {
|
|
508
|
+
lastPath = packageJsonPath;
|
|
509
|
+
packageJsonUrl = new URL((isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json", packageJsonUrl);
|
|
510
|
+
packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
const packageConfig = read(packageJsonPath, {
|
|
514
|
+
base,
|
|
515
|
+
specifier
|
|
516
|
+
});
|
|
517
|
+
if (packageConfig.exports !== void 0 && packageConfig.exports !== null) return packageExportsResolve(packageJsonUrl, packageSubpath, packageConfig, base, conditions);
|
|
518
|
+
if (packageSubpath === ".") return legacyMainResolve(packageJsonUrl, packageConfig, base);
|
|
519
|
+
return new URL(packageSubpath, packageJsonUrl);
|
|
520
|
+
} while (packageJsonPath.length !== lastPath.length);
|
|
521
|
+
throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), false);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* @param {string} specifier
|
|
525
|
+
* @returns {boolean}
|
|
526
|
+
*/
|
|
527
|
+
function isRelativeSpecifier(specifier) {
|
|
528
|
+
if (specifier[0] === ".") {
|
|
529
|
+
if (specifier.length === 1 || specifier[1] === "/") return true;
|
|
530
|
+
if (specifier[1] === "." && (specifier.length === 2 || specifier[2] === "/")) return true;
|
|
531
|
+
}
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* @param {string} specifier
|
|
536
|
+
* @returns {boolean}
|
|
537
|
+
*/
|
|
538
|
+
function shouldBeTreatedAsRelativeOrAbsolutePath(specifier) {
|
|
539
|
+
if (specifier === "") return false;
|
|
540
|
+
if (specifier[0] === "/") return true;
|
|
541
|
+
return isRelativeSpecifier(specifier);
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* The “Resolver Algorithm Specification” as detailed in the Node docs (which is
|
|
545
|
+
* sync and slightly lower-level than `resolve`).
|
|
546
|
+
*
|
|
547
|
+
* @param {string} specifier
|
|
548
|
+
* `/example.js`, `./example.js`, `../example.js`, `some-package`, `fs`, etc.
|
|
549
|
+
* @param {URL} base
|
|
550
|
+
* Full URL (to a file) that `specifier` is resolved relative from.
|
|
551
|
+
* @param {Set<string>} [conditions]
|
|
552
|
+
* Conditions.
|
|
553
|
+
* @param {boolean} [preserveSymlinks]
|
|
554
|
+
* Keep symlinks instead of resolving them.
|
|
555
|
+
* @returns {URL}
|
|
556
|
+
* A URL object to the found thing.
|
|
557
|
+
*/
|
|
558
|
+
function moduleResolve(specifier, base, conditions, preserveSymlinks) {
|
|
559
|
+
if (conditions === void 0) conditions = getConditionsSet();
|
|
560
|
+
const protocol = base.protocol;
|
|
561
|
+
const isRemote = protocol === "data:" || protocol === "http:" || protocol === "https:";
|
|
562
|
+
/** @type {URL | undefined} */
|
|
563
|
+
let resolved;
|
|
564
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) try {
|
|
565
|
+
resolved = new URL(specifier, base);
|
|
566
|
+
} catch (error_) {
|
|
567
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
568
|
+
error.cause = error_;
|
|
569
|
+
throw error;
|
|
570
|
+
}
|
|
571
|
+
else if (protocol === "file:" && specifier[0] === "#") resolved = packageImportsResolve(specifier, base, conditions);
|
|
572
|
+
else try {
|
|
573
|
+
resolved = new URL(specifier);
|
|
574
|
+
} catch (error_) {
|
|
575
|
+
if (isRemote && !builtinModules.includes(specifier)) {
|
|
576
|
+
const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST(specifier, base);
|
|
577
|
+
error.cause = error_;
|
|
578
|
+
throw error;
|
|
579
|
+
}
|
|
580
|
+
resolved = packageResolve(specifier, base, conditions);
|
|
581
|
+
}
|
|
582
|
+
assert.ok(resolved !== void 0, "expected to be defined");
|
|
583
|
+
if (resolved.protocol !== "file:") return resolved;
|
|
584
|
+
return finalizeResolution(resolved, base, preserveSymlinks);
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* @param {string} specifier
|
|
588
|
+
* @param {URL | undefined} parsed
|
|
589
|
+
* @param {URL | undefined} parsedParentURL
|
|
590
|
+
*/
|
|
591
|
+
function checkIfDisallowedImport(specifier, parsed, parsedParentURL) {
|
|
592
|
+
if (parsedParentURL) {
|
|
593
|
+
const parentProtocol = parsedParentURL.protocol;
|
|
594
|
+
if (parentProtocol === "http:" || parentProtocol === "https:") {
|
|
595
|
+
if (shouldBeTreatedAsRelativeOrAbsolutePath(specifier)) {
|
|
596
|
+
const parsedProtocol = parsed?.protocol;
|
|
597
|
+
if (parsedProtocol && parsedProtocol !== "https:" && parsedProtocol !== "http:") throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, "remote imports cannot import from a local location.");
|
|
598
|
+
return { url: parsed?.href || "" };
|
|
599
|
+
}
|
|
600
|
+
if (builtinModules.includes(specifier)) throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, "remote imports cannot import from a local location.");
|
|
601
|
+
throw new ERR_NETWORK_IMPORT_DISALLOWED(specifier, parsedParentURL, "only relative and absolute specifiers are supported.");
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Checks if a value has the shape of a WHATWG URL object.
|
|
607
|
+
*
|
|
608
|
+
* Using a symbol or instanceof would not be able to recognize URL objects
|
|
609
|
+
* coming from other implementations (e.g. in Electron), so instead we are
|
|
610
|
+
* checking some well known properties for a lack of a better test.
|
|
611
|
+
*
|
|
612
|
+
* We use `href` and `protocol` as they are the only properties that are
|
|
613
|
+
* easy to retrieve and calculate due to the lazy nature of the getters.
|
|
614
|
+
*
|
|
615
|
+
* @template {unknown} Value
|
|
616
|
+
* @param {Value} self
|
|
617
|
+
* @returns {Value is URL}
|
|
618
|
+
*/
|
|
619
|
+
function isURL(self) {
|
|
620
|
+
return Boolean(self && typeof self === "object" && "href" in self && typeof self.href === "string" && "protocol" in self && typeof self.protocol === "string" && self.href && self.protocol);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Validate user-input in `context` supplied by a custom loader.
|
|
624
|
+
*
|
|
625
|
+
* @param {unknown} parentURL
|
|
626
|
+
* @returns {asserts parentURL is URL | string | undefined}
|
|
627
|
+
*/
|
|
628
|
+
function throwIfInvalidParentURL(parentURL) {
|
|
629
|
+
if (parentURL === void 0) return;
|
|
630
|
+
if (typeof parentURL !== "string" && !isURL(parentURL)) throw new codes.ERR_INVALID_ARG_TYPE("parentURL", ["string", "URL"], parentURL);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* @param {string} specifier
|
|
634
|
+
* @param {{parentURL?: string, conditions?: Array<string>}} context
|
|
635
|
+
* @returns {{url: string, format?: string | null}}
|
|
636
|
+
*/
|
|
637
|
+
function defaultResolve(specifier, context = {}) {
|
|
638
|
+
const { parentURL } = context;
|
|
639
|
+
assert.ok(parentURL !== void 0, "expected `parentURL` to be defined");
|
|
640
|
+
throwIfInvalidParentURL(parentURL);
|
|
641
|
+
/** @type {URL | undefined} */
|
|
642
|
+
let parsedParentURL;
|
|
643
|
+
if (parentURL) try {
|
|
644
|
+
parsedParentURL = new URL(parentURL);
|
|
645
|
+
} catch {}
|
|
646
|
+
/** @type {URL | undefined} */
|
|
647
|
+
let parsed;
|
|
648
|
+
/** @type {string | undefined} */
|
|
649
|
+
let protocol;
|
|
650
|
+
try {
|
|
651
|
+
parsed = shouldBeTreatedAsRelativeOrAbsolutePath(specifier) ? new URL(specifier, parsedParentURL) : new URL(specifier);
|
|
652
|
+
protocol = parsed.protocol;
|
|
653
|
+
if (protocol === "data:") return {
|
|
654
|
+
url: parsed.href,
|
|
655
|
+
format: null
|
|
656
|
+
};
|
|
657
|
+
} catch {}
|
|
658
|
+
const maybeReturn = checkIfDisallowedImport(specifier, parsed, parsedParentURL);
|
|
659
|
+
if (maybeReturn) return maybeReturn;
|
|
660
|
+
if (protocol === void 0 && parsed) protocol = parsed.protocol;
|
|
661
|
+
if (protocol === "node:") return { url: specifier };
|
|
662
|
+
if (parsed && parsed.protocol === "node:") return { url: specifier };
|
|
663
|
+
const conditions = getConditionsSet(context.conditions);
|
|
664
|
+
const url = moduleResolve(specifier, new URL(parentURL), conditions, false);
|
|
665
|
+
return {
|
|
666
|
+
url: url.href,
|
|
667
|
+
format: defaultGetFormatWithoutErrors(url, { parentURL })
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
//#endregion
|
|
671
|
+
export { defaultResolve, moduleResolve };
|
|
672
|
+
|
|
673
|
+
//# sourceMappingURL=resolve.js.map
|