@typespec/compiler 0.61.0-dev.9 → 0.62.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/manifest.js +2 -2
- package/dist/src/config/config-interpolation.d.ts.map +1 -1
- package/dist/src/config/config-interpolation.js +39 -11
- package/dist/src/config/config-interpolation.js.map +1 -1
- package/dist/src/config/config-to-options.d.ts +1 -0
- package/dist/src/config/config-to-options.d.ts.map +1 -1
- package/dist/src/config/config-to-options.js +45 -2
- package/dist/src/config/config-to-options.js.map +1 -1
- package/dist/src/core/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +7 -1
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +4 -34
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/actions/compile/args.d.ts +2 -0
- package/dist/src/core/cli/actions/compile/args.d.ts.map +1 -1
- package/dist/src/core/cli/actions/compile/args.js.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.d.ts +1 -4
- package/dist/src/core/cli/actions/compile/compile.d.ts.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.js +26 -13
- package/dist/src/core/cli/actions/compile/compile.js.map +1 -1
- package/dist/src/core/diagnostic-creator.d.ts.map +1 -1
- package/dist/src/core/diagnostic-creator.js +5 -1
- package/dist/src/core/diagnostic-creator.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -1
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +1 -1
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/js-marshaller.d.ts.map +1 -1
- package/dist/src/core/js-marshaller.js +16 -1
- package/dist/src/core/js-marshaller.js.map +1 -1
- package/dist/src/core/logger/console-sink.js +1 -1
- package/dist/src/core/logger/console-sink.js.map +1 -1
- package/dist/src/core/messages.d.ts +27 -12
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +9 -2
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +16 -36
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/projector.d.ts.map +1 -1
- package/dist/src/core/projector.js +3 -0
- package/dist/src/core/projector.js.map +1 -1
- package/dist/src/core/semantic-walker.d.ts.map +1 -1
- package/dist/src/core/semantic-walker.js +9 -0
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/source-loader.d.ts +4 -2
- package/dist/src/core/source-loader.d.ts.map +1 -1
- package/dist/src/core/source-loader.js +26 -12
- package/dist/src/core/source-loader.js.map +1 -1
- package/dist/src/core/types.d.ts +30 -4
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/init/scaffold.d.ts.map +1 -1
- package/dist/src/init/scaffold.js.map +1 -1
- package/dist/src/lib/examples.d.ts.map +1 -1
- package/dist/src/lib/examples.js +6 -4
- package/dist/src/lib/examples.js.map +1 -1
- package/dist/src/module-resolver/esm/resolve-package-exports.d.ts +9 -0
- package/dist/src/module-resolver/esm/resolve-package-exports.d.ts.map +1 -0
- package/dist/src/module-resolver/esm/resolve-package-exports.js +58 -0
- package/dist/src/module-resolver/esm/resolve-package-exports.js.map +1 -0
- package/dist/src/module-resolver/esm/resolve-package-imports-exports.d.ts +11 -0
- package/dist/src/module-resolver/esm/resolve-package-imports-exports.d.ts.map +1 -0
- package/dist/src/module-resolver/esm/resolve-package-imports-exports.js +72 -0
- package/dist/src/module-resolver/esm/resolve-package-imports-exports.js.map +1 -0
- package/dist/src/module-resolver/esm/resolve-package-target.d.ts +10 -0
- package/dist/src/module-resolver/esm/resolve-package-target.d.ts.map +1 -0
- package/dist/src/module-resolver/esm/resolve-package-target.js +133 -0
- package/dist/src/module-resolver/esm/resolve-package-target.js.map +1 -0
- package/dist/src/module-resolver/esm/utils.d.ts +35 -0
- package/dist/src/module-resolver/esm/utils.d.ts.map +1 -0
- package/dist/src/module-resolver/esm/utils.js +40 -0
- package/dist/src/module-resolver/esm/utils.js.map +1 -0
- package/dist/src/{core → module-resolver}/module-resolver.d.ts +16 -25
- package/dist/src/module-resolver/module-resolver.d.ts.map +1 -0
- package/dist/src/module-resolver/module-resolver.js +272 -0
- package/dist/src/module-resolver/module-resolver.js.map +1 -0
- package/dist/src/module-resolver/utils.d.ts +6 -0
- package/dist/src/module-resolver/utils.d.ts.map +1 -0
- package/dist/src/module-resolver/utils.js +16 -0
- package/dist/src/module-resolver/utils.js.map +1 -0
- package/dist/src/runner.js +1 -1
- package/dist/src/runner.js.map +1 -1
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/testing/test-host.js +1 -1
- package/dist/src/testing/test-host.js.map +1 -1
- package/dist/src/types/package-json.d.ts +40 -0
- package/dist/src/types/package-json.d.ts.map +1 -0
- package/dist/src/types/package-json.js +2 -0
- package/dist/src/types/package-json.js.map +1 -0
- package/package.json +5 -5
- package/templates/__snapshots__/emitter-ts/.gitignore +9 -0
- package/templates/__snapshots__/emitter-ts/eslint.config.js +1 -1
- package/templates/__snapshots__/library-ts/.gitignore +9 -0
- package/templates/__snapshots__/library-ts/eslint.config.js +1 -1
- package/templates/scaffolding.json +4 -4
- package/dist/src/core/module-resolver.d.ts.map +0 -1
- package/dist/src/core/module-resolver.js +0 -169
- package/dist/src/core/module-resolver.js.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { resolvePackageTarget } from "./resolve-package-target.js";
|
|
2
|
+
import { InvalidModuleSpecifierError } from "./utils.js";
|
|
3
|
+
/** Implementation of PACKAGE_IMPORTS_EXPORTS_RESOLVE https://github.com/nodejs/node/blob/main/doc/api/esm.md */
|
|
4
|
+
export async function resolvePackageImportsExports(context, { matchKey, matchObj, isImports }) {
|
|
5
|
+
// If matchKey is a key of matchObj and does not contain "*", then
|
|
6
|
+
if (!matchKey.includes("*") && matchKey in matchObj) {
|
|
7
|
+
// Let target be the value of matchObj[matchKey].
|
|
8
|
+
const target = matchObj[matchKey];
|
|
9
|
+
// Return the result of PACKAGE_TARGET_RESOLVE(packageURL, target, null, isImports, conditions).
|
|
10
|
+
const resolved = await resolvePackageTarget(context, { target, patternMatch: "", isImports });
|
|
11
|
+
return resolved;
|
|
12
|
+
}
|
|
13
|
+
// Let expansionKeys be the list of keys of matchObj containing only a single "*"
|
|
14
|
+
const expansionKeys = Object.keys(matchObj)
|
|
15
|
+
// Assert: ends with "/" or contains only a single "*".
|
|
16
|
+
.filter((k) => k.endsWith("/") || k.includes("*"))
|
|
17
|
+
// sorted by the sorting function PATTERN_KEY_COMPARE which orders in descending order of specificity.
|
|
18
|
+
.sort(nodePatternKeyCompare);
|
|
19
|
+
// For each key expansionKey in expansionKeys, do
|
|
20
|
+
for (const expansionKey of expansionKeys) {
|
|
21
|
+
const indexOfAsterisk = expansionKey.indexOf("*");
|
|
22
|
+
// Let patternBase be the substring of expansionKey up to but excluding the first "*" character.
|
|
23
|
+
const patternBase = indexOfAsterisk === -1 ? expansionKey : expansionKey.substring(0, indexOfAsterisk);
|
|
24
|
+
// If matchKey starts with but is not equal to patternBase, then
|
|
25
|
+
if (matchKey.startsWith(patternBase) && matchKey !== patternBase) {
|
|
26
|
+
// Let patternTrailer be the substring of expansionKey from the index after the first "*" character.
|
|
27
|
+
const patternTrailer = indexOfAsterisk !== -1 ? expansionKey.substring(indexOfAsterisk + 1) : "";
|
|
28
|
+
// If patternTrailer has zero length,
|
|
29
|
+
if (patternTrailer.length === 0 ||
|
|
30
|
+
// or if matchKey ends with patternTrailer and the length of matchKey is greater than or equal to the length of expansionKey, then
|
|
31
|
+
(matchKey.endsWith(patternTrailer) && matchKey.length >= expansionKey.length)) {
|
|
32
|
+
// Let target be the value of matchObj[expansionKey].
|
|
33
|
+
const target = matchObj[expansionKey];
|
|
34
|
+
// Let patternMatch be the substring of matchKey starting at the index of the length of patternBase up to the length
|
|
35
|
+
// of matchKey minus the length of patternTrailer.
|
|
36
|
+
const patternMatch = matchKey.substring(patternBase.length, matchKey.length - patternTrailer.length);
|
|
37
|
+
// Return the result of PACKAGE_TARGET_RESOLVE
|
|
38
|
+
const resolved = await resolvePackageTarget(context, {
|
|
39
|
+
target,
|
|
40
|
+
patternMatch,
|
|
41
|
+
isImports,
|
|
42
|
+
});
|
|
43
|
+
return resolved;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new InvalidModuleSpecifierError(context, isImports);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Implementation of Node's `PATTERN_KEY_COMPARE` function
|
|
51
|
+
*/
|
|
52
|
+
function nodePatternKeyCompare(keyA, keyB) {
|
|
53
|
+
// Let baseLengthA be the index of "*" in keyA plus one, if keyA contains "*", or the length of keyA otherwise.
|
|
54
|
+
const baseLengthA = keyA.includes("*") ? keyA.indexOf("*") + 1 : keyA.length;
|
|
55
|
+
// Let baseLengthB be the index of "*" in keyB plus one, if keyB contains "*", or the length of keyB otherwise.
|
|
56
|
+
const baseLengthB = keyB.includes("*") ? keyB.indexOf("*") + 1 : keyB.length;
|
|
57
|
+
// if baseLengthA is greater, return -1, if lower 1
|
|
58
|
+
const rval = baseLengthB - baseLengthA;
|
|
59
|
+
if (rval !== 0)
|
|
60
|
+
return rval;
|
|
61
|
+
// If keyA does not contain "*", return 1.
|
|
62
|
+
if (!keyA.includes("*"))
|
|
63
|
+
return 1;
|
|
64
|
+
// If keyB does not contain "*", return -1.
|
|
65
|
+
if (!keyB.includes("*"))
|
|
66
|
+
return -1;
|
|
67
|
+
// If the length of keyA is greater than the length of keyB, return -1.
|
|
68
|
+
// If the length of keyB is greater than the length of keyA, return 1.
|
|
69
|
+
// Else Return 0.
|
|
70
|
+
return keyB.length - keyA.length;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=resolve-package-imports-exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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AAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAE7E,mDAAmD;IACnD,MAAM,IAAI,GAAG,WAAW,GAAG,WAAW,CAAC;IACvC,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5B,0CAA0C;IAC1C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC;IAClC,2CAA2C;IAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC;IAEnC,uEAAuE;IACvE,sEAAsE;IACtE,iBAAiB;IACjB,OAAO,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Exports } from "../../types/package-json.js";
|
|
2
|
+
import { EsmResolutionContext } from "./utils.js";
|
|
3
|
+
export interface ResolvePackageTargetOptions {
|
|
4
|
+
readonly target: Exports;
|
|
5
|
+
readonly patternMatch?: string;
|
|
6
|
+
readonly isImports?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** Implementation of PACKAGE_TARGET_RESOLVE https://github.com/nodejs/node/blob/main/doc/api/esm.md */
|
|
9
|
+
export declare function resolvePackageTarget(context: EsmResolutionContext, { target, patternMatch, isImports }: ResolvePackageTargetOptions): Promise<null | undefined | string>;
|
|
10
|
+
//# sourceMappingURL=resolve-package-target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-package-target.d.ts","sourceRoot":"","sources":["../../../../src/module-resolver/esm/resolve-package-target.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EACL,oBAAoB,EAIrB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,uGAAuG;AACvG,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,oBAAoB,EAC7B,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,EAAE,2BAA2B,GAC/D,OAAO,CAAC,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,CAgIpC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { resolvePath } from "../../core/path-utils.js";
|
|
2
|
+
import { InvalidModuleSpecifierError, InvalidPackageTargetError, isUrl, } from "./utils.js";
|
|
3
|
+
/** Implementation of PACKAGE_TARGET_RESOLVE https://github.com/nodejs/node/blob/main/doc/api/esm.md */
|
|
4
|
+
export async function resolvePackageTarget(context, { target, patternMatch, isImports }) {
|
|
5
|
+
const { packageUrl } = context;
|
|
6
|
+
const packageUrlWithTrailingSlash = packageUrl.endsWith("/") ? packageUrl : `${packageUrl}/`;
|
|
7
|
+
// 1. If target is a String, then
|
|
8
|
+
if (typeof target === "string") {
|
|
9
|
+
// 1.i If target does not start with "./", then
|
|
10
|
+
if (!target.startsWith("./")) {
|
|
11
|
+
// 1.i.a If isImports is false, or if target starts with "../" or "/", or if target is a valid URL, then
|
|
12
|
+
if (!isImports || target.startsWith("../") || target.startsWith("/") || isUrl(target)) {
|
|
13
|
+
// 1.i.a.a Throw an Invalid Package Target error.
|
|
14
|
+
throw new InvalidPackageTargetError(context, `Invalid mapping: "${target}".`);
|
|
15
|
+
}
|
|
16
|
+
// 1.i.b If patternMatch is a String, then
|
|
17
|
+
if (typeof patternMatch === "string") {
|
|
18
|
+
// 1.i.b.a Return PACKAGE_RESOLVE(target with every instance of "*" replaced by patternMatch, packageURL + "/")
|
|
19
|
+
return await context.resolveId(target.replace(/\*/g, patternMatch), packageUrlWithTrailingSlash);
|
|
20
|
+
}
|
|
21
|
+
// 1.i.c Return PACKAGE_RESOLVE(target, packageURL + "/").
|
|
22
|
+
return await context.resolveId(target, packageUrlWithTrailingSlash);
|
|
23
|
+
}
|
|
24
|
+
// 1.ii If target split on "/" or "\"
|
|
25
|
+
checkInvalidSegment(context, target);
|
|
26
|
+
// 1.iii Let resolvedTarget be the URL resolution of the concatenation of packageURL and target.
|
|
27
|
+
const resolvedTarget = resolvePath(packageUrlWithTrailingSlash, target);
|
|
28
|
+
// 1.iv Assert: resolvedTarget is contained in packageURL.
|
|
29
|
+
if (!resolvedTarget.startsWith(packageUrl)) {
|
|
30
|
+
throw new InvalidPackageTargetError(context, `Resolved to ${resolvedTarget} which is outside package ${packageUrl}`);
|
|
31
|
+
}
|
|
32
|
+
// 1.v If patternMatch is null, then
|
|
33
|
+
if (!patternMatch) {
|
|
34
|
+
// Return resolvedTarget.
|
|
35
|
+
return resolvedTarget;
|
|
36
|
+
}
|
|
37
|
+
// 1.vi If patternMatch split on "/" or "\" contains invalid segments
|
|
38
|
+
if (includesInvalidSegments(patternMatch.split(/\/|\\/), context.moduleDirs)) {
|
|
39
|
+
// throw an Invalid Module Specifier error.
|
|
40
|
+
throw new InvalidModuleSpecifierError(context);
|
|
41
|
+
}
|
|
42
|
+
// 1.vii Return the URL resolution of resolvedTarget with every instance of "*" replaced with patternMatch.
|
|
43
|
+
return resolvedTarget.replace(/\*/g, patternMatch);
|
|
44
|
+
}
|
|
45
|
+
// 3. Otherwise, if target is an Array, then
|
|
46
|
+
if (Array.isArray(target)) {
|
|
47
|
+
// 3.i If _target.length is zero, return null.
|
|
48
|
+
if (target.length === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
let lastError = null;
|
|
52
|
+
// 3.ii For each item in target, do
|
|
53
|
+
for (const item of target) {
|
|
54
|
+
// Let resolved be the result of PACKAGE_TARGET_RESOLVE of the item
|
|
55
|
+
// continuing the loop on any Invalid Package Target error.
|
|
56
|
+
try {
|
|
57
|
+
const resolved = await resolvePackageTarget(context, {
|
|
58
|
+
target: item,
|
|
59
|
+
patternMatch,
|
|
60
|
+
isImports,
|
|
61
|
+
});
|
|
62
|
+
// If resolved is undefined, continue the loop.
|
|
63
|
+
// Else Return resolved.
|
|
64
|
+
if (resolved !== undefined) {
|
|
65
|
+
return resolved;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (!(error instanceof InvalidPackageTargetError)) {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
lastError = error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Return or throw the last fallback resolution null return or error
|
|
78
|
+
if (lastError) {
|
|
79
|
+
throw lastError;
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
// 2. Otherwise, if target is a non-null Object, then
|
|
84
|
+
if (target && typeof target === "object") {
|
|
85
|
+
// 2.ii For each property of target
|
|
86
|
+
for (const [key, value] of Object.entries(target)) {
|
|
87
|
+
// 2.ii.a If key equals "default" or conditions contains an entry for the key, then
|
|
88
|
+
if ((key === "default" && !context.ignoreDefaultCondition) ||
|
|
89
|
+
context.conditions.includes(key)) {
|
|
90
|
+
// Let targetValue be the value of the property in target.
|
|
91
|
+
// Let resolved be the result of PACKAGE_TARGET_RESOLVE of the targetValue
|
|
92
|
+
const resolved = await resolvePackageTarget(context, {
|
|
93
|
+
target: value,
|
|
94
|
+
patternMatch,
|
|
95
|
+
isImports,
|
|
96
|
+
});
|
|
97
|
+
// If resolved is equal to undefined, continue the loop.
|
|
98
|
+
// Return resolved.
|
|
99
|
+
if (resolved !== undefined) {
|
|
100
|
+
return resolved;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Return undefined.
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
// Otherwise, if target is null, return null.
|
|
108
|
+
if (target === null) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
// Otherwise throw an Invalid Package Target error.
|
|
112
|
+
throw new InvalidPackageTargetError(context, `Invalid exports field.`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check for invalid path segments
|
|
116
|
+
*/
|
|
117
|
+
function includesInvalidSegments(pathSegments, moduleDirs) {
|
|
118
|
+
const invalidSegments = ["", ".", "..", ...moduleDirs];
|
|
119
|
+
// contains any "", ".", "..", or "node_modules" segments, including percent encoded variants
|
|
120
|
+
return pathSegments.some((v) => invalidSegments.includes(v) || invalidSegments.includes(decodeURI(v)));
|
|
121
|
+
}
|
|
122
|
+
function checkInvalidSegment(context, target) {
|
|
123
|
+
const pathSegments = target.split(/\/|\\/);
|
|
124
|
+
// after the first "." segment
|
|
125
|
+
const firstDot = pathSegments.indexOf(".");
|
|
126
|
+
firstDot !== -1 && pathSegments.slice(firstDot);
|
|
127
|
+
if (firstDot !== -1 &&
|
|
128
|
+
firstDot < pathSegments.length - 1 &&
|
|
129
|
+
includesInvalidSegments(pathSegments.slice(firstDot + 1), context.moduleDirs)) {
|
|
130
|
+
throw new InvalidPackageTargetError(context, `Invalid mapping: "${target}".`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=resolve-package-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-package-target.js","sourceRoot":"","sources":["../../../../src/module-resolver/esm/resolve-package-target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAEL,2BAA2B,EAC3B,yBAAyB,EACzB,KAAK,GACN,MAAM,YAAY,CAAC;AAQpB,uGAAuG;AACvG,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAA6B,EAC7B,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS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,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAC7E,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,OAA6B,EAAE,MAAc;IACxE,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3C,8BAA8B;IAC9B,MAAM,QAAQ,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3C,QAAQ,KAAK,CAAC,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,IACE,QAAQ,KAAK,CAAC,CAAC;QACf,QAAQ,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC;QAClC,uBAAuB,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,EAC7E,CAAC;QACD,MAAM,IAAI,yBAAyB,CAAC,OAAO,EAAE,qBAAqB,MAAM,IAAI,CAAC,CAAC;IAChF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface EsmResolutionContext {
|
|
2
|
+
/** Original import specifier */
|
|
3
|
+
readonly specifier: string;
|
|
4
|
+
/** URL of the current package */
|
|
5
|
+
readonly packageUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* List of condition to match
|
|
8
|
+
* @example `["import", "require"]`
|
|
9
|
+
*/
|
|
10
|
+
readonly conditions: readonly string[];
|
|
11
|
+
/**
|
|
12
|
+
* Folders where modules exist that are banned from being used in exports.
|
|
13
|
+
* @example `["node_modules"]`
|
|
14
|
+
*/
|
|
15
|
+
readonly moduleDirs: readonly string[];
|
|
16
|
+
resolveId(id: string, baseDir: string | URL): any;
|
|
17
|
+
/** Non standard option. Do not respect the default condition. */
|
|
18
|
+
readonly ignoreDefaultCondition?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class EsmResolveError extends Error {
|
|
21
|
+
}
|
|
22
|
+
export declare class InvalidConfigurationError extends EsmResolveError {
|
|
23
|
+
constructor(context: EsmResolutionContext, reason?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class InvalidModuleSpecifierError extends EsmResolveError {
|
|
26
|
+
constructor(context: EsmResolutionContext, isImports?: boolean, reason?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class InvalidPackageTargetError extends EsmResolveError {
|
|
29
|
+
constructor(context: EsmResolutionContext, reason?: string);
|
|
30
|
+
}
|
|
31
|
+
export declare class NoMatchingConditionsError extends InvalidPackageTargetError {
|
|
32
|
+
constructor(context: EsmResolutionContext);
|
|
33
|
+
}
|
|
34
|
+
export declare function isUrl(str: string): boolean;
|
|
35
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/module-resolver/esm/utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,gCAAgC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,iCAAiC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAEvC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IAEvC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC;IAElD,iEAAiE;IACjE,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC3C;AAaD,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAE7C,qBAAa,yBAA0B,SAAQ,eAAe;gBAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,MAAM;CAG3D;AAED,qBAAa,2BAA4B,SAAQ,eAAe;gBAClD,OAAO,EAAE,oBAAoB,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM;CAGhF;AAED,qBAAa,yBAA0B,SAAQ,eAAe;gBAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,CAAC,EAAE,MAAM;CAG3D;AAED,qBAAa,yBAA0B,SAAQ,yBAAyB;gBAC1D,OAAO,EAAE,oBAAoB;CAG1C;AAED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,WAMhC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
function createBaseErrorMsg(importSpecifier) {
|
|
2
|
+
return `Could not resolve import "${importSpecifier}" `;
|
|
3
|
+
}
|
|
4
|
+
function createErrorMsg(context, reason, isImports) {
|
|
5
|
+
const { specifier, packageUrl } = context;
|
|
6
|
+
const base = createBaseErrorMsg(specifier);
|
|
7
|
+
const field = isImports ? "imports" : "exports";
|
|
8
|
+
return `${base} using ${field} defined in ${packageUrl}.${reason ? ` ${reason}` : ""}`;
|
|
9
|
+
}
|
|
10
|
+
export class EsmResolveError extends Error {
|
|
11
|
+
}
|
|
12
|
+
export class InvalidConfigurationError extends EsmResolveError {
|
|
13
|
+
constructor(context, reason) {
|
|
14
|
+
super(createErrorMsg(context, `Invalid "exports" field. ${reason}`));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class InvalidModuleSpecifierError extends EsmResolveError {
|
|
18
|
+
constructor(context, isImports, reason) {
|
|
19
|
+
super(createErrorMsg(context, reason, isImports));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class InvalidPackageTargetError extends EsmResolveError {
|
|
23
|
+
constructor(context, reason) {
|
|
24
|
+
super(createErrorMsg(context, reason));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class NoMatchingConditionsError extends InvalidPackageTargetError {
|
|
28
|
+
constructor(context) {
|
|
29
|
+
super(context, `No conditions matched`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export function isUrl(str) {
|
|
33
|
+
try {
|
|
34
|
+
return !!new URL(str);
|
|
35
|
+
}
|
|
36
|
+
catch (_) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/module-resolver/esm/utils.ts"],"names":[],"mappings":"AAyBA,SAAS,kBAAkB,CAAC,eAAuB;IACjD,OAAO,6BAA6B,eAAe,IAAI,CAAC;AAC1D,CAAC;AAED,SAAS,cAAc,CAAC,OAA6B,EAAE,MAAe,EAAE,SAAmB;IACzF,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC1C,MAAM,IAAI,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAChD,OAAO,GAAG,IAAI,UAAU,KAAK,eAAe,UAAU,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACzF,CAAC;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAE7C,MAAM,OAAO,yBAA0B,SAAQ,eAAe;IAC5D,YAAY,OAA6B,EAAE,MAAe;QACxD,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,4BAA4B,MAAM,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;CACF;AAED,MAAM,OAAO,2BAA4B,SAAQ,eAAe;IAC9D,YAAY,OAA6B,EAAE,SAAmB,EAAE,MAAe;QAC7E,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,eAAe;IAC5D,YAAY,OAA6B,EAAE,MAAe;QACxD,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,yBAAyB;IACtE,YAAY,OAA6B;QACvC,KAAK,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,IAAI,CAAC;QACH,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PackageJson } from "../types/package-json.js";
|
|
1
2
|
export interface ResolveModuleOptions {
|
|
2
3
|
baseDir: string;
|
|
3
4
|
/**
|
|
@@ -7,9 +8,16 @@ export interface ResolveModuleOptions {
|
|
|
7
8
|
resolveMain?: (pkg: any) => string;
|
|
8
9
|
/**
|
|
9
10
|
* When resolution reach a directory without package.json look for those files to load in order.
|
|
10
|
-
* @default ["index.mjs", "index.js"]
|
|
11
|
+
* @default `["index.mjs", "index.js"]`
|
|
11
12
|
*/
|
|
12
13
|
directoryIndexFiles?: string[];
|
|
14
|
+
/** List of conditions to match in package exports */
|
|
15
|
+
readonly conditions?: string[];
|
|
16
|
+
/**
|
|
17
|
+
* If exports is defined ignore if the none of the given condition is found and fallback to using main field resolution.
|
|
18
|
+
* By default it will throw an error.
|
|
19
|
+
*/
|
|
20
|
+
readonly fallbackOnMissingCondition?: boolean;
|
|
13
21
|
}
|
|
14
22
|
export interface ResolveModuleHost {
|
|
15
23
|
/**
|
|
@@ -28,27 +36,9 @@ export interface ResolveModuleHost {
|
|
|
28
36
|
*/
|
|
29
37
|
readFile(path: string): Promise<string>;
|
|
30
38
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export interface NodePackage {
|
|
35
|
-
name: string;
|
|
36
|
-
description?: string;
|
|
37
|
-
type?: "module" | "commonjs";
|
|
38
|
-
main?: string;
|
|
39
|
-
version: string;
|
|
40
|
-
tspMain?: string;
|
|
41
|
-
homepage?: string;
|
|
42
|
-
bugs?: {
|
|
43
|
-
url?: string;
|
|
44
|
-
email?: string;
|
|
45
|
-
};
|
|
46
|
-
private?: boolean;
|
|
47
|
-
dependencies?: Record<string, string>;
|
|
48
|
-
peerDependencies?: Record<string, string>;
|
|
49
|
-
devDependencies?: Record<string, string>;
|
|
50
|
-
}
|
|
51
|
-
type ResolveModuleErrorCode = "MODULE_NOT_FOUND" | "INVALID_MAIN";
|
|
39
|
+
type ResolveModuleErrorCode = "MODULE_NOT_FOUND" | "INVALID_MAIN" | "INVALID_MODULE"
|
|
40
|
+
/** When an exports points to an invalid file. */
|
|
41
|
+
| "INVALID_MODULE_EXPORT_TARGET";
|
|
52
42
|
export declare class ResolveModuleError extends Error {
|
|
53
43
|
code: ResolveModuleErrorCode;
|
|
54
44
|
constructor(code: ResolveModuleErrorCode, message: string);
|
|
@@ -71,15 +61,16 @@ export interface ResolvedModule {
|
|
|
71
61
|
/**
|
|
72
62
|
* Value of package.json.
|
|
73
63
|
*/
|
|
74
|
-
manifest:
|
|
64
|
+
manifest: PackageJson;
|
|
75
65
|
}
|
|
76
66
|
/**
|
|
77
67
|
* Resolve a module
|
|
78
68
|
* @param host
|
|
79
|
-
* @param
|
|
69
|
+
* @param specifier
|
|
80
70
|
* @param options
|
|
81
71
|
* @returns
|
|
72
|
+
* @throws {ResolveModuleError} When the module cannot be resolved.
|
|
82
73
|
*/
|
|
83
|
-
export declare function resolveModule(host: ResolveModuleHost,
|
|
74
|
+
export declare function resolveModule(host: ResolveModuleHost, specifier: string, options: ResolveModuleOptions): Promise<ModuleResolutionResult>;
|
|
84
75
|
export {};
|
|
85
76
|
//# sourceMappingURL=module-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-resolver.d.ts","sourceRoot":"","sources":["../../../src/module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