@dads-framework/testing 0.1.0 → 0.3.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/README.md +72 -10
- package/bin/dad-test-import-nx.js +3 -0
- package/bin/dad-test-nx.js +3 -0
- package/dist/init/init-testing-manifest.js +1 -1
- package/dist/init/init-testing-manifest.js.map +1 -1
- package/dist/nx/atomic-output.d.ts +9 -0
- package/dist/nx/atomic-output.d.ts.map +1 -0
- package/dist/nx/atomic-output.js +39 -0
- package/dist/nx/atomic-output.js.map +1 -0
- package/dist/nx/cli.d.ts +2 -0
- package/dist/nx/cli.d.ts.map +1 -0
- package/dist/nx/cli.js +21 -0
- package/dist/nx/cli.js.map +1 -0
- package/dist/nx/dads-identifier.d.ts +11 -0
- package/dist/nx/dads-identifier.d.ts.map +1 -0
- package/dist/nx/dads-identifier.js +14 -0
- package/dist/nx/dads-identifier.js.map +1 -0
- package/dist/nx/import-digest.d.ts +12 -0
- package/dist/nx/import-digest.d.ts.map +1 -0
- package/dist/nx/import-digest.js +69 -0
- package/dist/nx/import-digest.js.map +1 -0
- package/dist/nx/import-nx-types.d.ts +166 -0
- package/dist/nx/import-nx-types.d.ts.map +1 -0
- package/dist/nx/import-nx-types.js +2 -0
- package/dist/nx/import-nx-types.js.map +1 -0
- package/dist/nx/import-nx-workspace.d.ts +7 -0
- package/dist/nx/import-nx-workspace.d.ts.map +1 -0
- package/dist/nx/import-nx-workspace.js +292 -0
- package/dist/nx/import-nx-workspace.js.map +1 -0
- package/dist/nx/import-nx.d.ts +12 -0
- package/dist/nx/import-nx.d.ts.map +1 -0
- package/dist/nx/import-nx.js +12 -0
- package/dist/nx/import-nx.js.map +1 -0
- package/dist/nx/index.d.ts +4 -0
- package/dist/nx/index.d.ts.map +1 -0
- package/dist/nx/index.js +4 -0
- package/dist/nx/index.js.map +1 -0
- package/dist/nx/json-values.d.ts +43 -0
- package/dist/nx/json-values.d.ts.map +1 -0
- package/dist/nx/json-values.js +76 -0
- package/dist/nx/json-values.js.map +1 -0
- package/dist/nx/nx-graph-fallback.d.ts +18 -0
- package/dist/nx/nx-graph-fallback.d.ts.map +1 -0
- package/dist/nx/nx-graph-fallback.js +61 -0
- package/dist/nx/nx-graph-fallback.js.map +1 -0
- package/dist/nx/nx-installation.d.ts +4 -0
- package/dist/nx/nx-installation.d.ts.map +1 -0
- package/dist/nx/nx-installation.js +97 -0
- package/dist/nx/nx-installation.js.map +1 -0
- package/dist/nx/nx-jsonc.d.ts +3 -0
- package/dist/nx/nx-jsonc.d.ts.map +1 -0
- package/dist/nx/nx-jsonc.js +91 -0
- package/dist/nx/nx-jsonc.js.map +1 -0
- package/dist/nx/nx-native-cli.d.ts +2 -0
- package/dist/nx/nx-native-cli.d.ts.map +1 -0
- package/dist/nx/nx-native-cli.js +64 -0
- package/dist/nx/nx-native-cli.js.map +1 -0
- package/dist/nx/nx-native-graph.d.ts +11 -0
- package/dist/nx/nx-native-graph.d.ts.map +1 -0
- package/dist/nx/nx-native-graph.js +130 -0
- package/dist/nx/nx-native-graph.js.map +1 -0
- package/dist/nx/nx-native-input-expansion.d.ts +9 -0
- package/dist/nx/nx-native-input-expansion.d.ts.map +1 -0
- package/dist/nx/nx-native-input-expansion.js +114 -0
- package/dist/nx/nx-native-input-expansion.js.map +1 -0
- package/dist/nx/nx-native-inputs.d.ts +9 -0
- package/dist/nx/nx-native-inputs.d.ts.map +1 -0
- package/dist/nx/nx-native-inputs.js +212 -0
- package/dist/nx/nx-native-inputs.js.map +1 -0
- package/dist/nx/nx-native-model.d.ts +28 -0
- package/dist/nx/nx-native-model.d.ts.map +1 -0
- package/dist/nx/nx-native-model.js +119 -0
- package/dist/nx/nx-native-model.js.map +1 -0
- package/dist/nx/nx-native-process.d.ts +2 -0
- package/dist/nx/nx-native-process.d.ts.map +1 -0
- package/dist/nx/nx-native-process.js +18 -0
- package/dist/nx/nx-native-process.js.map +1 -0
- package/dist/nx/nx-native-scope.d.ts +4 -0
- package/dist/nx/nx-native-scope.d.ts.map +1 -0
- package/dist/nx/nx-native-scope.js +21 -0
- package/dist/nx/nx-native-scope.js.map +1 -0
- package/dist/nx/nx-native-scratch.d.ts +5 -0
- package/dist/nx/nx-native-scratch.d.ts.map +1 -0
- package/dist/nx/nx-native-scratch.js +78 -0
- package/dist/nx/nx-native-scratch.js.map +1 -0
- package/dist/nx/nx-native-workspace.d.ts +16 -0
- package/dist/nx/nx-native-workspace.d.ts.map +1 -0
- package/dist/nx/nx-native-workspace.js +72 -0
- package/dist/nx/nx-native-workspace.js.map +1 -0
- package/dist/nx/nx-target-conversion.d.ts +9 -0
- package/dist/nx/nx-target-conversion.d.ts.map +1 -0
- package/dist/nx/nx-target-conversion.js +284 -0
- package/dist/nx/nx-target-conversion.js.map +1 -0
- package/dist/nx/nx-workspace-reader.d.ts +42 -0
- package/dist/nx/nx-workspace-reader.d.ts.map +1 -0
- package/dist/nx/nx-workspace-reader.js +302 -0
- package/dist/nx/nx-workspace-reader.js.map +1 -0
- package/dist/path-aliases/alias-file-system.d.ts +26 -0
- package/dist/path-aliases/alias-file-system.d.ts.map +1 -0
- package/dist/path-aliases/alias-file-system.js +16 -0
- package/dist/path-aliases/alias-file-system.js.map +1 -0
- package/dist/path-aliases/alias-resolver-conformance-cases.d.ts +40 -0
- package/dist/path-aliases/alias-resolver-conformance-cases.d.ts.map +1 -0
- package/dist/path-aliases/alias-resolver-conformance-cases.js +324 -0
- package/dist/path-aliases/alias-resolver-conformance-cases.js.map +1 -0
- package/dist/path-aliases/alias-resolver-conformance.d.ts +41 -0
- package/dist/path-aliases/alias-resolver-conformance.d.ts.map +1 -0
- package/dist/path-aliases/alias-resolver-conformance.js +141 -0
- package/dist/path-aliases/alias-resolver-conformance.js.map +1 -0
- package/dist/path-aliases/alias-resolver.d.ts +23 -0
- package/dist/path-aliases/alias-resolver.d.ts.map +1 -0
- package/dist/path-aliases/alias-resolver.js +199 -0
- package/dist/path-aliases/alias-resolver.js.map +1 -0
- package/dist/path-aliases/in-memory-file-system.d.ts +16 -0
- package/dist/path-aliases/in-memory-file-system.d.ts.map +1 -0
- package/dist/path-aliases/in-memory-file-system.js +43 -0
- package/dist/path-aliases/in-memory-file-system.js.map +1 -0
- package/dist/path-aliases/index.d.ts +6 -0
- package/dist/path-aliases/index.d.ts.map +1 -0
- package/dist/path-aliases/index.js +6 -0
- package/dist/path-aliases/index.js.map +1 -0
- package/dist/path-aliases/json-with-comments.d.ts +14 -0
- package/dist/path-aliases/json-with-comments.d.ts.map +1 -0
- package/dist/path-aliases/json-with-comments.js +245 -0
- package/dist/path-aliases/json-with-comments.js.map +1 -0
- package/dist/path-aliases/node-file-system.d.ts +10 -0
- package/dist/path-aliases/node-file-system.d.ts.map +1 -0
- package/dist/path-aliases/node-file-system.js +29 -0
- package/dist/path-aliases/node-file-system.js.map +1 -0
- package/dist/path-aliases/tsconfig-chain.d.ts +40 -0
- package/dist/path-aliases/tsconfig-chain.d.ts.map +1 -0
- package/dist/path-aliases/tsconfig-chain.js +139 -0
- package/dist/path-aliases/tsconfig-chain.js.map +1 -0
- package/dist/testing.tsbuildinfo +1 -1
- package/dist/vitest/dads-tsconfig-paths.d.ts +17 -0
- package/dist/vitest/dads-tsconfig-paths.d.ts.map +1 -0
- package/dist/vitest/dads-tsconfig-paths.js +38 -0
- package/dist/vitest/dads-tsconfig-paths.js.map +1 -0
- package/dist/vitest/index.d.ts +2 -0
- package/dist/vitest/index.d.ts.map +1 -0
- package/dist/vitest/index.js +2 -0
- package/dist/vitest/index.js.map +1 -0
- package/nx/README.md +259 -0
- package/package.json +35 -8
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tsconfig's path aliases, resolved to files.
|
|
3
|
+
*
|
|
4
|
+
* The resolver is built once, from one named tsconfig, and every alias shape
|
|
5
|
+
* it cannot honor exactly is refused while it is being built rather than
|
|
6
|
+
* quietly resolving less at run time. What it answers is an absolute path to a
|
|
7
|
+
* file that exists, or `null` for a specifier it does not own — a bare
|
|
8
|
+
* specifier, an absolute path, or an alias whose target names nothing.
|
|
9
|
+
*
|
|
10
|
+
* Every file question goes through the `AliasFileSystem` port, so the same
|
|
11
|
+
* rules run over a directory on disk and over a map in memory.
|
|
12
|
+
*/
|
|
13
|
+
import { isAbsolute, resolve } from "node:path";
|
|
14
|
+
import { isRecord, readDeclaredAliases, readTsconfigChain, } from "./tsconfig-chain.js";
|
|
15
|
+
const supportedExtensions = [
|
|
16
|
+
".ts",
|
|
17
|
+
".tsx",
|
|
18
|
+
".js",
|
|
19
|
+
".jsx",
|
|
20
|
+
".json",
|
|
21
|
+
".mts",
|
|
22
|
+
".mjs",
|
|
23
|
+
".cts",
|
|
24
|
+
".cjs",
|
|
25
|
+
".css",
|
|
26
|
+
".scss",
|
|
27
|
+
".less",
|
|
28
|
+
];
|
|
29
|
+
export function createAliasResolver(options) {
|
|
30
|
+
const { fileSystem } = options;
|
|
31
|
+
const absoluteTsconfig = resolve(process.cwd(), requireTsconfigOption(options.tsconfig));
|
|
32
|
+
const chain = readTsconfigChain(fileSystem, absoluteTsconfig);
|
|
33
|
+
const declared = readDeclaredAliases(chain, absoluteTsconfig);
|
|
34
|
+
const entries = Object.entries(declared.paths);
|
|
35
|
+
if (entries.length === 0) {
|
|
36
|
+
throw new Error(`Dads path aliases tsconfig ${absoluteTsconfig} does not declare or inherit compilerOptions.paths.`);
|
|
37
|
+
}
|
|
38
|
+
const mappings = entries.map(([pattern, targets]) => parseAliasMapping(pattern, targets, absoluteTsconfig));
|
|
39
|
+
return (specifier) => resolveSpecifier(fileSystem, mappings, declared.baseUrl, specifier);
|
|
40
|
+
}
|
|
41
|
+
function requireTsconfigOption(tsconfig) {
|
|
42
|
+
if (tsconfig.trim().length === 0) {
|
|
43
|
+
throw new Error("Dads path aliases requires a non-empty tsconfig path.");
|
|
44
|
+
}
|
|
45
|
+
return tsconfig;
|
|
46
|
+
}
|
|
47
|
+
// --- The alias map -------------------------------------------------------
|
|
48
|
+
/** One usable target, or none: a target list of any other shape is refused. */
|
|
49
|
+
function parseAliasMapping(pattern, targets, tsconfig) {
|
|
50
|
+
const target = onlyTarget(targets);
|
|
51
|
+
if (target === undefined) {
|
|
52
|
+
throw new Error(`Dads path alias ${pattern} in ${tsconfig} must have exactly one target.`);
|
|
53
|
+
}
|
|
54
|
+
const patternStars = countStars(pattern);
|
|
55
|
+
const targetStars = countStars(target);
|
|
56
|
+
if (patternStars > 1 || targetStars !== patternStars) {
|
|
57
|
+
throw new Error(`Dads path alias ${pattern} in ${tsconfig} must use zero or one matching wildcard.`);
|
|
58
|
+
}
|
|
59
|
+
return { pattern, target };
|
|
60
|
+
}
|
|
61
|
+
function onlyTarget(targets) {
|
|
62
|
+
if (!Array.isArray(targets) || targets.length !== 1)
|
|
63
|
+
return undefined;
|
|
64
|
+
const first = targets[0];
|
|
65
|
+
return typeof first === "string" ? first : undefined;
|
|
66
|
+
}
|
|
67
|
+
function countStars(value) {
|
|
68
|
+
let stars = 0;
|
|
69
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
70
|
+
if (value[index] === "*")
|
|
71
|
+
stars += 1;
|
|
72
|
+
}
|
|
73
|
+
return stars;
|
|
74
|
+
}
|
|
75
|
+
// --- Resolving one specifier ---------------------------------------------
|
|
76
|
+
function resolveSpecifier(fileSystem, mappings, baseUrl, rawSpecifier) {
|
|
77
|
+
if (shouldDefer(rawSpecifier))
|
|
78
|
+
return null;
|
|
79
|
+
const specifier = rawSpecifier.replace(/\?\S*$/, "");
|
|
80
|
+
for (const mapping of mappings) {
|
|
81
|
+
const wildcard = matchAlias(mapping.pattern, specifier);
|
|
82
|
+
if (wildcard === undefined)
|
|
83
|
+
continue;
|
|
84
|
+
const candidate = resolve(baseUrl, mapping.target.replace("*", wildcard));
|
|
85
|
+
const resolved = resolveCandidate(fileSystem, candidate);
|
|
86
|
+
if (resolved !== null)
|
|
87
|
+
return resolved;
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/** An absolute specifier is the caller's own path, and stays theirs to resolve. */
|
|
92
|
+
function shouldDefer(specifier) {
|
|
93
|
+
return specifier.startsWith("/") || isAbsolute(specifier);
|
|
94
|
+
}
|
|
95
|
+
function matchAlias(pattern, specifier) {
|
|
96
|
+
const wildcardIndex = pattern.indexOf("*");
|
|
97
|
+
if (wildcardIndex < 0)
|
|
98
|
+
return pattern === specifier ? "" : undefined;
|
|
99
|
+
const prefix = pattern.slice(0, wildcardIndex);
|
|
100
|
+
const suffix = pattern.slice(wildcardIndex + 1);
|
|
101
|
+
if (!specifier.startsWith(prefix) || !specifier.endsWith(suffix))
|
|
102
|
+
return undefined;
|
|
103
|
+
return specifier.slice(prefix.length, specifier.length - suffix.length);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* What one alias target names, in the order a target can name it: the file
|
|
107
|
+
* itself, the entry point of a package directory, the file under a supported
|
|
108
|
+
* extension or an `index` inside it, and finally the source file behind a
|
|
109
|
+
* specifier written with an explicit extension.
|
|
110
|
+
*/
|
|
111
|
+
function resolveCandidate(fileSystem, candidate) {
|
|
112
|
+
if (fileSystem.isFile(candidate))
|
|
113
|
+
return resolve(candidate);
|
|
114
|
+
const entry = packageEntryFile(fileSystem, candidate);
|
|
115
|
+
if (entry !== null)
|
|
116
|
+
return entry;
|
|
117
|
+
const supported = findSupportedFile(fileSystem, candidate);
|
|
118
|
+
if (supported !== null)
|
|
119
|
+
return supported;
|
|
120
|
+
return explicitExtensionSource(fileSystem, candidate);
|
|
121
|
+
}
|
|
122
|
+
function findSupportedFile(fileSystem, candidate) {
|
|
123
|
+
if (fileSystem.isFile(candidate))
|
|
124
|
+
return resolve(candidate);
|
|
125
|
+
for (const extension of supportedExtensions) {
|
|
126
|
+
const withExtension = `${candidate}${extension}`;
|
|
127
|
+
if (fileSystem.isFile(withExtension))
|
|
128
|
+
return resolve(withExtension);
|
|
129
|
+
const indexFile = resolve(candidate, `index${extension}`);
|
|
130
|
+
if (fileSystem.isFile(indexFile))
|
|
131
|
+
return indexFile;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/** `@app/source.js` finds `src/source.ts`, the file the extension stands for. */
|
|
136
|
+
function explicitExtensionSource(fileSystem, candidate) {
|
|
137
|
+
const extension = supportedExtensions.find((one) => candidate.endsWith(one));
|
|
138
|
+
if (extension === undefined)
|
|
139
|
+
return null;
|
|
140
|
+
return findSupportedFile(fileSystem, candidate.slice(0, -extension.length));
|
|
141
|
+
}
|
|
142
|
+
// --- A package directory -------------------------------------------------
|
|
143
|
+
/**
|
|
144
|
+
* The entry point of a package directory an alias points at: the first of
|
|
145
|
+
* `exports`, `module`, and `main` that names a file which exists. A manifest
|
|
146
|
+
* that cannot be read is no manifest at all, so resolution falls through to
|
|
147
|
+
* the extension and index probes.
|
|
148
|
+
*/
|
|
149
|
+
function packageEntryFile(fileSystem, directory) {
|
|
150
|
+
const manifest = readPackageManifest(fileSystem, resolve(directory, "package.json"));
|
|
151
|
+
if (manifest === undefined)
|
|
152
|
+
return null;
|
|
153
|
+
const fields = [packageEntry(manifest), manifest["module"], manifest["main"]];
|
|
154
|
+
for (const field of fields) {
|
|
155
|
+
if (typeof field !== "string")
|
|
156
|
+
continue;
|
|
157
|
+
const entry = resolve(directory, field);
|
|
158
|
+
if (fileSystem.isFile(entry))
|
|
159
|
+
return entry;
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
function readPackageManifest(fileSystem, packageJsonPath) {
|
|
164
|
+
if (!fileSystem.isFile(packageJsonPath))
|
|
165
|
+
return undefined;
|
|
166
|
+
try {
|
|
167
|
+
const parsed = JSON.parse(fileSystem.readText(packageJsonPath));
|
|
168
|
+
return isRecord(parsed) ? parsed : undefined;
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The entry point a package declares for this resolver: `exports["."]` as a
|
|
176
|
+
* string, or its `import` condition, or its `default` condition. Anything else
|
|
177
|
+
* is absent, which leaves `module` and `main` to answer.
|
|
178
|
+
*/
|
|
179
|
+
function packageEntry(manifest) {
|
|
180
|
+
const exported = manifest["exports"];
|
|
181
|
+
if (typeof exported === "string")
|
|
182
|
+
return exported;
|
|
183
|
+
if (!isRecord(exported))
|
|
184
|
+
return undefined;
|
|
185
|
+
const root = exported["."];
|
|
186
|
+
if (typeof root === "string")
|
|
187
|
+
return root;
|
|
188
|
+
if (!isRecord(root))
|
|
189
|
+
return undefined;
|
|
190
|
+
return firstString([root["import"], root["default"]]);
|
|
191
|
+
}
|
|
192
|
+
function firstString(values) {
|
|
193
|
+
for (const value of values) {
|
|
194
|
+
if (typeof value === "string")
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=alias-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alias-resolver.js","sourceRoot":"","sources":["../../src/path-aliases/alias-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,mBAAmB,GAAG;IAC1B,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;CACC,CAAC;AAiBX,MAAM,UAAU,mBAAmB,CACjC,OAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,MAAM,gBAAgB,GAAG,OAAO,CAC9B,OAAO,CAAC,GAAG,EAAE,EACb,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,CACxC,CAAC;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IAClD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1C,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACtC,OAAO,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,SAAS,WAAW,CAAC,MAA0B;IAC7C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;IAC9C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider that binds no disk, so the seam has a second implementation.
|
|
3
|
+
*
|
|
4
|
+
* It is a map of absolute paths to text. Everything a resolver asks of a file
|
|
5
|
+
* system is answered from that map: a path is a file when the map holds it, a
|
|
6
|
+
* read is a lookup, and a package resolves by the walk Node itself does —
|
|
7
|
+
* `node_modules/<specifier>` in this directory, then its parent, and up.
|
|
8
|
+
*
|
|
9
|
+
* It exists to be run through the conformance suite beside the Node provider.
|
|
10
|
+
* A boundary with one implementation is a folder name, and Dad's test is the
|
|
11
|
+
* stand-in.
|
|
12
|
+
*/
|
|
13
|
+
import type { AliasFileSystem } from "./alias-file-system.js";
|
|
14
|
+
/** A file system over `files`, keyed by absolute path. */
|
|
15
|
+
export declare function inMemoryFileSystem(files: Readonly<Record<string, string>>): AliasFileSystem;
|
|
16
|
+
//# sourceMappingURL=in-memory-file-system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-file-system.d.ts","sourceRoot":"","sources":["../../src/path-aliases/in-memory-file-system.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACtC,eAAe,CAUjB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A provider that binds no disk, so the seam has a second implementation.
|
|
3
|
+
*
|
|
4
|
+
* It is a map of absolute paths to text. Everything a resolver asks of a file
|
|
5
|
+
* system is answered from that map: a path is a file when the map holds it, a
|
|
6
|
+
* read is a lookup, and a package resolves by the walk Node itself does —
|
|
7
|
+
* `node_modules/<specifier>` in this directory, then its parent, and up.
|
|
8
|
+
*
|
|
9
|
+
* It exists to be run through the conformance suite beside the Node provider.
|
|
10
|
+
* A boundary with one implementation is a folder name, and Dad's test is the
|
|
11
|
+
* stand-in.
|
|
12
|
+
*/
|
|
13
|
+
import { dirname, resolve } from "node:path";
|
|
14
|
+
/** A file system over `files`, keyed by absolute path. */
|
|
15
|
+
export function inMemoryFileSystem(files) {
|
|
16
|
+
const byPath = new Map(Object.entries(files).map(([path, text]) => [resolve(path), text]));
|
|
17
|
+
return {
|
|
18
|
+
isFile: (path) => byPath.has(resolve(path)),
|
|
19
|
+
readText: (path) => readOrRefuse(byPath, path),
|
|
20
|
+
resolvePackage: (specifier, fromFile) => findInNodeModules(byPath, specifier, fromFile),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function readOrRefuse(byPath, path) {
|
|
24
|
+
const text = byPath.get(resolve(path));
|
|
25
|
+
if (text === undefined) {
|
|
26
|
+
throw new Error(`This in-memory file system holds no file at ${path}.`);
|
|
27
|
+
}
|
|
28
|
+
return text;
|
|
29
|
+
}
|
|
30
|
+
/** Node's own lookup, over the map: `node_modules/<specifier>` upwards. */
|
|
31
|
+
function findInNodeModules(byPath, specifier, fromFile) {
|
|
32
|
+
let directory = dirname(resolve(fromFile));
|
|
33
|
+
for (;;) {
|
|
34
|
+
const candidate = resolve(directory, "node_modules", specifier);
|
|
35
|
+
if (byPath.has(candidate))
|
|
36
|
+
return candidate;
|
|
37
|
+
const parent = dirname(directory);
|
|
38
|
+
if (parent === directory)
|
|
39
|
+
return undefined;
|
|
40
|
+
directory = parent;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=in-memory-file-system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-file-system.js","sourceRoot":"","sources":["../../src/path-aliases/in-memory-file-system.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG7C,0DAA0D;AAC1D,MAAM,UAAU,kBAAkB,CAChC,KAAuC;IAEvC,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,CACnE,CAAC;IACF,OAAO;QACL,MAAM,EAAE,CAAC,IAAY,EAAW,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5D,QAAQ,EAAE,CAAC,IAAY,EAAU,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC;QAC9D,cAAc,EAAE,CAAC,SAAiB,EAAE,QAAgB,EAAsB,EAAE,CAC1E,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,MAAmC,EAAE,IAAY;IACrE,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IACvC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,GAAG,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2EAA2E;AAC3E,SAAS,iBAAiB,CACxB,MAAmC,EACnC,SAAiB,EACjB,QAAgB;IAEhB,IAAI,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3C,SAAS,CAAC;QACR,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;QAChE,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QAClC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;QAC3C,SAAS,GAAG,MAAM,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/path-aliases/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/path-aliases/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tsconfig is JSON with comments and trailing commas, which `JSON.parse`
|
|
3
|
+
* cannot read. This is the package's own reader for that dialect, so resolving
|
|
4
|
+
* an alias never needs the TypeScript compiler: TypeScript 7 ships no
|
|
5
|
+
* JavaScript API, and an adopter's compiler version is their business rather
|
|
6
|
+
* than this plugin's.
|
|
7
|
+
*
|
|
8
|
+
* The text is tokenized rather than matched with patterns, because a string
|
|
9
|
+
* may contain a comment opener, a comment closer, and escaped quotes that are
|
|
10
|
+
* content and not syntax. Text this reader cannot parse fails with the line
|
|
11
|
+
* and column it stopped at.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseJsonWithComments(source: string): unknown;
|
|
14
|
+
//# sourceMappingURL=json-with-comments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-with-comments.d.ts","sourceRoot":"","sources":["../../src/path-aliases/json-with-comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA0BH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAQ7D"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tsconfig is JSON with comments and trailing commas, which `JSON.parse`
|
|
3
|
+
* cannot read. This is the package's own reader for that dialect, so resolving
|
|
4
|
+
* an alias never needs the TypeScript compiler: TypeScript 7 ships no
|
|
5
|
+
* JavaScript API, and an adopter's compiler version is their business rather
|
|
6
|
+
* than this plugin's.
|
|
7
|
+
*
|
|
8
|
+
* The text is tokenized rather than matched with patterns, because a string
|
|
9
|
+
* may contain a comment opener, a comment closer, and escaped quotes that are
|
|
10
|
+
* content and not syntax. Text this reader cannot parse fails with the line
|
|
11
|
+
* and column it stopped at.
|
|
12
|
+
*/
|
|
13
|
+
const punctuationCharacters = "{}[]:,";
|
|
14
|
+
const whitespaceCharacters = " \t\r\n";
|
|
15
|
+
/** An editor may have written a byte-order mark before the first brace. */
|
|
16
|
+
const byteOrderMark = 0xfe_ff;
|
|
17
|
+
export function parseJsonWithComments(source) {
|
|
18
|
+
const cursor = { source, offset: 0, pending: undefined };
|
|
19
|
+
const value = readValue(cursor);
|
|
20
|
+
const trailing = nextToken(cursor);
|
|
21
|
+
if (trailing !== undefined) {
|
|
22
|
+
throw syntaxError(source, trailing.offset, "expected the end of the file");
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
// --- Tokens --------------------------------------------------------------
|
|
27
|
+
/** Whitespace, a byte-order mark, and comments are all read as nothing. */
|
|
28
|
+
function skipIgnorable(source, from) {
|
|
29
|
+
let index = from;
|
|
30
|
+
while (index < source.length) {
|
|
31
|
+
if (isBlank(source[index])) {
|
|
32
|
+
index += 1;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const comment = commentEnd(source, index);
|
|
36
|
+
if (comment === undefined)
|
|
37
|
+
return index;
|
|
38
|
+
index = comment;
|
|
39
|
+
}
|
|
40
|
+
return index;
|
|
41
|
+
}
|
|
42
|
+
/** Where the comment starting at `from` ends, or nothing when none starts there. */
|
|
43
|
+
function commentEnd(source, from) {
|
|
44
|
+
if (source[from] !== "/")
|
|
45
|
+
return undefined;
|
|
46
|
+
const second = source[from + 1];
|
|
47
|
+
if (second === "/") {
|
|
48
|
+
const newline = source.indexOf("\n", from + 2);
|
|
49
|
+
return newline === -1 ? source.length : newline + 1;
|
|
50
|
+
}
|
|
51
|
+
if (second !== "*")
|
|
52
|
+
return undefined;
|
|
53
|
+
const closing = source.indexOf("*/", from + 2);
|
|
54
|
+
if (closing === -1) {
|
|
55
|
+
throw syntaxError(source, from, "expected the end of a block comment");
|
|
56
|
+
}
|
|
57
|
+
return closing + 2;
|
|
58
|
+
}
|
|
59
|
+
function readToken(source, offset) {
|
|
60
|
+
const character = source[offset];
|
|
61
|
+
if (character !== undefined && punctuationCharacters.includes(character)) {
|
|
62
|
+
return { text: character, offset, punctuation: true };
|
|
63
|
+
}
|
|
64
|
+
const text = character === '"'
|
|
65
|
+
? readStringLiteral(source, offset)
|
|
66
|
+
: readBareLiteral(source, offset);
|
|
67
|
+
return { text, offset, punctuation: false };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* From the opening quote to the matching one. A backslash carries the
|
|
71
|
+
* character after it, so an escaped quote never ends the string and a comment
|
|
72
|
+
* opener inside one stays content.
|
|
73
|
+
*/
|
|
74
|
+
function readStringLiteral(source, offset) {
|
|
75
|
+
let index = offset + 1;
|
|
76
|
+
while (index < source.length) {
|
|
77
|
+
const character = source[index];
|
|
78
|
+
if (character === "\\") {
|
|
79
|
+
index += 2;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
index += 1;
|
|
83
|
+
if (character === '"')
|
|
84
|
+
return source.slice(offset, index);
|
|
85
|
+
}
|
|
86
|
+
throw syntaxError(source, offset, "expected the end of a string");
|
|
87
|
+
}
|
|
88
|
+
/** A number, `true`, `false`, `null`, or whatever else was written there. */
|
|
89
|
+
function readBareLiteral(source, offset) {
|
|
90
|
+
let index = offset + 1;
|
|
91
|
+
while (index < source.length && !endsBareLiteral(source, index))
|
|
92
|
+
index += 1;
|
|
93
|
+
return source.slice(offset, index);
|
|
94
|
+
}
|
|
95
|
+
function endsBareLiteral(source, index) {
|
|
96
|
+
const character = source[index];
|
|
97
|
+
if (character === undefined)
|
|
98
|
+
return true;
|
|
99
|
+
if (isBlank(character) || character === '"')
|
|
100
|
+
return true;
|
|
101
|
+
if (punctuationCharacters.includes(character))
|
|
102
|
+
return true;
|
|
103
|
+
const following = source[index + 1];
|
|
104
|
+
return character === "/" && (following === "/" || following === "*");
|
|
105
|
+
}
|
|
106
|
+
function isBlank(character) {
|
|
107
|
+
if (character === undefined)
|
|
108
|
+
return false;
|
|
109
|
+
return (whitespaceCharacters.includes(character) ||
|
|
110
|
+
character.codePointAt(0) === byteOrderMark);
|
|
111
|
+
}
|
|
112
|
+
// --- Values --------------------------------------------------------------
|
|
113
|
+
function readValue(cursor) {
|
|
114
|
+
const token = requireToken(cursor, "expected a value");
|
|
115
|
+
if (token.text === "{")
|
|
116
|
+
return readObject(cursor);
|
|
117
|
+
if (token.text === "[")
|
|
118
|
+
return parseJsonArray(cursor);
|
|
119
|
+
if (token.punctuation) {
|
|
120
|
+
throw syntaxError(cursor.source, token.offset, "expected a value");
|
|
121
|
+
}
|
|
122
|
+
return literalValue(cursor.source, token);
|
|
123
|
+
}
|
|
124
|
+
function readObject(cursor) {
|
|
125
|
+
const value = {};
|
|
126
|
+
if (consume(cursor, "}"))
|
|
127
|
+
return value;
|
|
128
|
+
for (;;) {
|
|
129
|
+
const name = requireToken(cursor, "expected a property name");
|
|
130
|
+
const key = propertyName(cursor.source, name);
|
|
131
|
+
requirePunctuation(cursor, ":", "expected a colon after a property name");
|
|
132
|
+
value[key] = readValue(cursor);
|
|
133
|
+
if (readSeparator(cursor, "}"))
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function parseJsonArray(cursor) {
|
|
138
|
+
const values = [];
|
|
139
|
+
if (consume(cursor, "]"))
|
|
140
|
+
return values;
|
|
141
|
+
for (;;) {
|
|
142
|
+
values.push(readValue(cursor));
|
|
143
|
+
if (readSeparator(cursor, "]"))
|
|
144
|
+
return values;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reads what separates one member from the next and reports whether the
|
|
149
|
+
* collection is finished: the closing bracket ends it, and a comma continues
|
|
150
|
+
* it — including a trailing comma, which a tsconfig is allowed to carry.
|
|
151
|
+
*/
|
|
152
|
+
function readSeparator(cursor, closing) {
|
|
153
|
+
const expectation = `expected a comma or ${closing}`;
|
|
154
|
+
const token = requireToken(cursor, expectation);
|
|
155
|
+
if (token.text === closing)
|
|
156
|
+
return true;
|
|
157
|
+
if (token.text !== ",") {
|
|
158
|
+
throw syntaxError(cursor.source, token.offset, expectation);
|
|
159
|
+
}
|
|
160
|
+
return consume(cursor, closing);
|
|
161
|
+
}
|
|
162
|
+
function propertyName(source, token) {
|
|
163
|
+
const value = token.punctuation
|
|
164
|
+
? undefined
|
|
165
|
+
: jsonValueOrNothing(token.text);
|
|
166
|
+
if (typeof value !== "string") {
|
|
167
|
+
throw syntaxError(source, token.offset, "expected a property name");
|
|
168
|
+
}
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
function literalValue(source, token) {
|
|
172
|
+
try {
|
|
173
|
+
return JSON.parse(token.text);
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
throw syntaxError(source, token.offset, "expected a value");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** The text's JSON value, or nothing when JSON does not accept that text. */
|
|
180
|
+
function jsonValueOrNothing(text) {
|
|
181
|
+
try {
|
|
182
|
+
return JSON.parse(text);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// --- The cursor ----------------------------------------------------------
|
|
189
|
+
/** Reads the next token, or reports the end of the text, without consuming it. */
|
|
190
|
+
function peekToken(cursor) {
|
|
191
|
+
if (cursor.pending !== undefined)
|
|
192
|
+
return cursor.pending;
|
|
193
|
+
const start = skipIgnorable(cursor.source, cursor.offset);
|
|
194
|
+
cursor.offset = start;
|
|
195
|
+
if (start >= cursor.source.length)
|
|
196
|
+
return undefined;
|
|
197
|
+
const token = readToken(cursor.source, start);
|
|
198
|
+
cursor.pending = token;
|
|
199
|
+
cursor.offset = token.offset + token.text.length;
|
|
200
|
+
return token;
|
|
201
|
+
}
|
|
202
|
+
function nextToken(cursor) {
|
|
203
|
+
const token = peekToken(cursor);
|
|
204
|
+
cursor.pending = undefined;
|
|
205
|
+
return token;
|
|
206
|
+
}
|
|
207
|
+
function requireToken(cursor, expectation) {
|
|
208
|
+
const token = nextToken(cursor);
|
|
209
|
+
if (token === undefined) {
|
|
210
|
+
throw syntaxError(cursor.source, cursor.source.length, expectation);
|
|
211
|
+
}
|
|
212
|
+
return token;
|
|
213
|
+
}
|
|
214
|
+
/** Takes the next token when it reads `text`, and leaves the cursor otherwise. */
|
|
215
|
+
function consume(cursor, text) {
|
|
216
|
+
if (peekToken(cursor)?.text !== text)
|
|
217
|
+
return false;
|
|
218
|
+
cursor.pending = undefined;
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
function requirePunctuation(cursor, text, expectation) {
|
|
222
|
+
const token = requireToken(cursor, expectation);
|
|
223
|
+
if (token.text !== text) {
|
|
224
|
+
throw syntaxError(cursor.source, token.offset, expectation);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// --- Positions -----------------------------------------------------------
|
|
228
|
+
/** Every failure names where reading stopped, in the file's own coordinates. */
|
|
229
|
+
function syntaxError(source, offset, expectation) {
|
|
230
|
+
const position = positionOf(source, offset);
|
|
231
|
+
return new Error(`${expectation} at line ${position.line}, column ${position.column}`);
|
|
232
|
+
}
|
|
233
|
+
function positionOf(source, offset) {
|
|
234
|
+
const end = Math.min(offset, source.length);
|
|
235
|
+
let line = 1;
|
|
236
|
+
let lineStart = 0;
|
|
237
|
+
for (let index = 0; index < end; index += 1) {
|
|
238
|
+
if (source[index] !== "\n")
|
|
239
|
+
continue;
|
|
240
|
+
line += 1;
|
|
241
|
+
lineStart = index + 1;
|
|
242
|
+
}
|
|
243
|
+
return { line, column: end - lineStart + 1 };
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=json-with-comments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-with-comments.js","sourceRoot":"","sources":["../../src/path-aliases/json-with-comments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,qBAAqB,GAAG,QAAQ,CAAC;AACvC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AACvC,2EAA2E;AAC3E,MAAM,aAAa,GAAG,OAAO,CAAC;AAqB9B,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,MAAM,MAAM,GAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,E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,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider that answers from the disk the process is running on.
|
|
3
|
+
*
|
|
4
|
+
* It is the whole of this package's contact with `node:fs` and `node:module`:
|
|
5
|
+
* every rule about aliases, chains, and refusals is written against the port
|
|
6
|
+
* instead, so a resolver can be run without a disk at all.
|
|
7
|
+
*/
|
|
8
|
+
import type { AliasFileSystem } from "./alias-file-system.js";
|
|
9
|
+
export declare const nodeFileSystem: AliasFileSystem;
|
|
10
|
+
//# sourceMappingURL=node-file-system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-file-system.d.ts","sourceRoot":"","sources":["../../src/path-aliases/node-file-system.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,eAAO,MAAM,cAAc,EAAE,eAgB5B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provider that answers from the disk the process is running on.
|
|
3
|
+
*
|
|
4
|
+
* It is the whole of this package's contact with `node:fs` and `node:module`:
|
|
5
|
+
* every rule about aliases, chains, and refusals is written against the port
|
|
6
|
+
* instead, so a resolver can be run without a disk at all.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
export const nodeFileSystem = {
|
|
11
|
+
isFile: (path) => {
|
|
12
|
+
try {
|
|
13
|
+
return existsSync(path) && statSync(path).isFile();
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
readText: (path) => readFileSync(path, "utf8"),
|
|
20
|
+
resolvePackage: (specifier, fromFile) => {
|
|
21
|
+
try {
|
|
22
|
+
return createRequire(fromFile).resolve(specifier);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=node-file-system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-file-system.js","sourceRoot":"","sources":["../../src/path-aliases/node-file-system.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,MAAM,EAAE,CAAC,IAAY,EAAW,EAAE;QAChC,IAAI,CAAC;YACH,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,QAAQ,EAAE,CAAC,IAAY,EAAU,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC;IAC9D,cAAc,EAAE,CAAC,SAAiB,EAAE,QAAgB,EAAsB,EAAE;QAC1E,IAAI,CAAC;YACH,OAAO,aAAa,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACpD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF,CAAC"}
|