@mikrojs/analyze-imports 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Bjørge Næss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ ### ESM import analyzer
2
+
3
+ A slimmed down version of [@vercel/nft](https://github.com/vercel/nft), removing support for:
4
+
5
+ - CommonJS / `require()`
6
+ - `__dirname`, `__filename` support
7
+ - global `process` variable
8
+ - Node builtins like `os`, `path` etc (and `node:`-prefixed equivalents)
9
+ - `.node` native imports
10
+ - legacy `main` and `module` package.json fields. Only `exports` supported.
11
+ - - other legacy dependency handling
12
+
13
+ It follows symlinks, but does not resolve them to real paths. The returned file list reflects how the runtime sees them.
@@ -0,0 +1,6 @@
1
+ import type { Tracer } from './trace.js';
2
+ export interface AnalyzeResult {
3
+ imports: Set<string>;
4
+ }
5
+ export default function analyze(id: string, code: string, job: Tracer): Promise<AnalyzeResult>;
6
+ //# sourceMappingURL=analyze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyze.d.ts","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,YAAY,CAAA;AAetC,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CACrB;AAED,wBAA8B,OAAO,CACnC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,aAAa,CAAC,CA8ExB"}
@@ -0,0 +1,89 @@
1
+ import { tsPlugin } from '@sveltejs/acorn-typescript';
2
+ import { Parser as AcornParser } from 'acorn';
3
+ import { asyncWalk } from 'estree-walker';
4
+ import { evaluate } from './utils/static-eval.js';
5
+ const Parser = AcornParser.extend(tsPlugin());
6
+ const globalBindings = {
7
+ URL: URL,
8
+ Object: {
9
+ assign: Object.assign,
10
+ },
11
+ };
12
+ globalBindings['globalThis'] = globalBindings;
13
+ export default async function analyze(id, code, job) {
14
+ const imports = new Set();
15
+ // remove shebang
16
+ code = code.replace(/^#![^\n\r]*[\r\n]/, '');
17
+ let ast;
18
+ try {
19
+ ast = Parser.parse(code, {
20
+ ecmaVersion: 2025,
21
+ sourceType: 'module',
22
+ allowAwaitOutsideFunction: true,
23
+ });
24
+ }
25
+ catch (e) {
26
+ job.warnings.add(new Error(`Failed to parse ${id} as module:\n${e instanceof Error ? e.message : String(e)}`));
27
+ return { imports };
28
+ }
29
+ // Process top-level ESM declarations
30
+ if (isAst(ast)) {
31
+ for (const decl of ast.body) {
32
+ if (decl.type === 'ImportDeclaration') {
33
+ const source = String(decl.source.value);
34
+ imports.add(source);
35
+ }
36
+ else if (decl.type === 'ExportNamedDeclaration' || decl.type === 'ExportAllDeclaration') {
37
+ if (decl.source)
38
+ imports.add(String(decl.source.value));
39
+ }
40
+ }
41
+ }
42
+ async function computePureStaticValue(expr, computeBranches = true) {
43
+ const vars = Object.create(null);
44
+ Object.keys(globalBindings).forEach((name) => {
45
+ vars[name] = { value: globalBindings[name] };
46
+ });
47
+ return evaluate(expr, vars, computeBranches);
48
+ }
49
+ async function processImportArg(expression) {
50
+ if (expression.type === 'ConditionalExpression') {
51
+ await processImportArg(expression.consequent);
52
+ await processImportArg(expression.alternate);
53
+ return;
54
+ }
55
+ if (expression.type === 'LogicalExpression') {
56
+ await processImportArg(expression.left);
57
+ await processImportArg(expression.right);
58
+ return;
59
+ }
60
+ const computed = await computePureStaticValue(expression, true);
61
+ if (!computed)
62
+ return;
63
+ if ('value' in computed && typeof computed.value === 'string') {
64
+ imports.add(computed.value);
65
+ }
66
+ else if ('ifTrue' in computed) {
67
+ if (typeof computed.ifTrue === 'string')
68
+ imports.add(computed.ifTrue);
69
+ if (typeof computed.else === 'string')
70
+ imports.add(computed.else);
71
+ }
72
+ }
73
+ await asyncWalk(ast, {
74
+ async enter(_node, _parent) {
75
+ const node = _node;
76
+ const parent = _parent;
77
+ if (!parent)
78
+ return;
79
+ if (node.type === 'ImportExpression') {
80
+ await processImportArg(node.source);
81
+ }
82
+ },
83
+ });
84
+ return { imports };
85
+ }
86
+ function isAst(ast) {
87
+ return typeof ast === 'object' && ast !== null && 'body' in ast;
88
+ }
89
+ //# sourceMappingURL=analyze.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyze.js","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAC,MAAM,IAAI,WAAW,EAAC,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAoB,SAAS,EAAC,MAAM,eAAe,CAAA;AAG1D,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAG/C,MAAM,M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AAI,OAAO,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9D,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAC7B,CAAC;aAAM,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;YAChC,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ;gBAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YACrE,IAAI,OAAO,QAAQ,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;IAED,MAAM,SAAS,CAAC,GAAsC,EAAE;QACtD,KAAK,CAAC,KAAK,CAAwC,KAAc,EAAE,OAAgB;YACjF,MAAM,IAAI,GAAS,KAAa,CAAA;YAChC,MAAM,MAAM,GAAS,OAAe,CAAA;YAEpC,IAAI,CAAC,MAAM;gBAAE,OAAM;YAEnB,IAAI,IAAI,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;gBACrC,MAAM,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,EAAC,OAAO,EAAC,CAAA;AAClB,CAAC;AAED,SAAS,KAAK,CAAC,GAAY;IACzB,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAI,MAAM,IAAI,GAAG,CAAA;AACjE,CAAC"}
package/dist/fs.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import type { Stats } from './types.js';
2
+ export declare class CachedFileSystem {
3
+ private fileCache;
4
+ private statCache;
5
+ private symlinkCache;
6
+ private fileIOQueue;
7
+ constructor({ cache, fileIOConcurrency, }: {
8
+ cache?: {
9
+ fileCache?: Map<string, Promise<string | null>>;
10
+ statCache?: Map<string, Promise<Stats | null>>;
11
+ symlinkCache?: Map<string, Promise<string | null>>;
12
+ };
13
+ fileIOConcurrency: number;
14
+ });
15
+ readlink(path: string): Promise<string | null>;
16
+ readFile(path: string): Promise<string | null>;
17
+ stat(path: string): Promise<Stats | null>;
18
+ private _internalReadlink;
19
+ private _internalReadFile;
20
+ private _internalStat;
21
+ private executeFileIO;
22
+ }
23
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,YAAY,CAAA;AAErC,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,SAAS,CAAoC;IACrD,OAAO,CAAC,YAAY,CAAqC;IACzD,OAAO,CAAC,WAAW,CAAM;gBAEb,EACV,KAAK,EACL,iBAAiB,GAClB,EAAE;QACD,KAAK,CAAC,EAAE;YACN,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAA;YAC/C,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAA;YAC9C,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAA;SACnD,CAAA;QACD,iBAAiB,EAAE,MAAM,CAAA;KAC1B;IAaK,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW9C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW9C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;YAWjC,iBAAiB;YAajB,iBAAiB;YAWjB,aAAa;YAWb,aAAa;CAY5B"}
package/dist/fs.js ADDED
@@ -0,0 +1,97 @@
1
+ import { Sema } from 'async-sema';
2
+ import { readFile as fsReadFile, readlink as fsReadlink, stat as fsStat } from 'fs/promises';
3
+ import { resolve } from 'path';
4
+ export class CachedFileSystem {
5
+ fileCache;
6
+ statCache;
7
+ symlinkCache;
8
+ fileIOQueue;
9
+ constructor({ cache, fileIOConcurrency, }) {
10
+ this.fileIOQueue = new Sema(fileIOConcurrency);
11
+ this.fileCache = cache?.fileCache ?? new Map();
12
+ this.statCache = cache?.statCache ?? new Map();
13
+ this.symlinkCache = cache?.symlinkCache ?? new Map();
14
+ if (cache) {
15
+ cache.fileCache = this.fileCache;
16
+ cache.statCache = this.statCache;
17
+ cache.symlinkCache = this.symlinkCache;
18
+ }
19
+ }
20
+ async readlink(path) {
21
+ const cached = this.symlinkCache.get(path);
22
+ if (cached !== undefined)
23
+ return cached;
24
+ // This is not awaiting the response, so that the cache is instantly populated and
25
+ // future calls serve the Promise from the cache
26
+ const readlinkPromise = this.executeFileIO(path, this._internalReadlink);
27
+ this.symlinkCache.set(path, readlinkPromise);
28
+ return readlinkPromise;
29
+ }
30
+ async readFile(path) {
31
+ const cached = this.fileCache.get(path);
32
+ if (cached !== undefined)
33
+ return cached;
34
+ // This is not awaiting the response, so that the cache is instantly populated and
35
+ // future calls serve the Promise from the cache
36
+ const readFilePromise = this.executeFileIO(path, this._internalReadFile);
37
+ this.fileCache.set(path, readFilePromise);
38
+ return readFilePromise;
39
+ }
40
+ async stat(path) {
41
+ const cached = this.statCache.get(path);
42
+ if (cached !== undefined)
43
+ return cached;
44
+ // This is not awaiting the response, so that the cache is instantly populated and
45
+ // future calls serve the Promise from the cache
46
+ const statPromise = this.executeFileIO(path, this._internalStat);
47
+ this.statCache.set(path, statPromise);
48
+ return statPromise;
49
+ }
50
+ async _internalReadlink(path) {
51
+ try {
52
+ const link = await fsReadlink(path);
53
+ // also copy stat cache to symlink
54
+ const stats = this.statCache.get(path);
55
+ if (stats)
56
+ this.statCache.set(resolve(path, link), stats);
57
+ return link;
58
+ }
59
+ catch (e) {
60
+ if (e.code !== 'EINVAL' && e.code !== 'ENOENT' && e.code !== 'UNKNOWN')
61
+ throw e;
62
+ return null;
63
+ }
64
+ }
65
+ async _internalReadFile(path) {
66
+ try {
67
+ return (await fsReadFile(path)).toString();
68
+ }
69
+ catch (e) {
70
+ if (e.code === 'ENOENT' || e.code === 'EISDIR') {
71
+ return null;
72
+ }
73
+ throw e;
74
+ }
75
+ }
76
+ async _internalStat(path) {
77
+ try {
78
+ return await fsStat(path);
79
+ }
80
+ catch (e) {
81
+ if (e.code === 'ENOENT') {
82
+ return null;
83
+ }
84
+ throw e;
85
+ }
86
+ }
87
+ async executeFileIO(path, fileIO) {
88
+ await this.fileIOQueue.acquire();
89
+ try {
90
+ return fileIO.call(this, path);
91
+ }
92
+ finally {
93
+ this.fileIOQueue.release();
94
+ }
95
+ }
96
+ }
97
+ //# sourceMappingURL=fs.js.map
package/dist/fs.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAA;AAC/B,OAAO,EAAC,QAAQ,IAAI,UAAU,EAAE,QAAQ,IAAI,UAAU,EAAE,IAAI,IAAI,MAAM,EAAC,MAAM,aAAa,CAAA;AAC1F,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAA;AAI5B,MAAM,OAAO,gBAAgB;IACnB,SAAS,CAAqC;IAC9C,SAAS,CAAoC;IAC7C,YAAY,CAAqC;IACjD,WAAW,CAAM;IAEzB,YAAY,EACV,KAAK,EACL,iBAAiB,GAQlB;QACC,IAAI,CAAC,WAAW,GAAG,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAC9C,IAAI,CAAC,SAAS,GAAG,KAAK,EAAE,SAAS,IAAI,IAAI,GAAG,EAAE,CAAA;QAC9C,IAAI,CA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CAAA;QACT,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,aAAa,CAAC,IAAY;QACtC,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,CAAC,IAAI,CAAC,CAAA;QAC3B,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACxB,OAAO,IAAI,CAAA;YACb,CAAC;YACD,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,aAAa,CACzB,IAAY,EACZ,MAAyC;QAEzC,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAA;QAEhC,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAChC,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAA;QAC5B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ export { nodeFileTrace } from './trace.js';
2
+ export * from './types.js';
3
+ import resolveDependency from './resolve.js';
4
+ export { resolveDependency as resolve };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AACxC,cAAc,YAAY,CAAA;AAC1B,OAAO,iBAAiB,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAC,iBAAiB,IAAI,OAAO,EAAC,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { nodeFileTrace } from './trace.js';
2
+ export * from './types.js';
3
+ import resolveDependency from './resolve.js';
4
+ export { resolveDependency as resolve };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAA;AACxC,cAAc,YAAY,CAAA;AAC1B,OAAO,iBAAiB,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAC,iBAAiB,IAAI,OAAO,EAAC,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { Tracer } from './trace.js';
2
+ export default function resolveDependency(specifier: string, parent: string, job: Tracer): Promise<string | string[]>;
3
+ export declare class NotFoundError extends Error {
4
+ code: string;
5
+ constructor(specifier: string, parent: string);
6
+ }
7
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,YAAY,CAAA;AAKtC,wBAA8B,iBAAiB,CAC7C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAsB5B;AAiCD,qBAAa,aAAc,SAAQ,KAAK;IAC/B,IAAI,EAAE,MAAM,CAAA;gBACP,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAI9C"}
@@ -0,0 +1,244 @@
1
+ import { isAbsolute, resolve, sep } from 'path';
2
+ // ESM-only node resolver.
3
+ // Custom implementation to emit only needed package.json files for resolver
4
+ // (package.json files are emitted as they are hit).
5
+ export default async function resolveDependency(specifier, parent, job) {
6
+ let resolved;
7
+ if (isAbsolute(specifier) ||
8
+ specifier === '.' ||
9
+ specifier === '..' ||
10
+ specifier.startsWith('./') ||
11
+ specifier.startsWith('../')) {
12
+ const trailingSlash = specifier.endsWith('/');
13
+ resolved = await resolvePath(resolve(parent, '..', specifier) + (trailingSlash ? '/' : ''), parent, job);
14
+ }
15
+ else if (specifier[0] === '#') {
16
+ resolved = await packageImportsResolve(specifier, parent, job);
17
+ }
18
+ else {
19
+ resolved = await resolvePackage(specifier, parent, job);
20
+ }
21
+ return resolved;
22
+ }
23
+ async function resolvePath(path, parent, job) {
24
+ const result = await resolveFile(path, parent, job);
25
+ if (!result) {
26
+ throw new NotFoundError(path, parent);
27
+ }
28
+ return result;
29
+ }
30
+ async function resolveFile(path, parent, job) {
31
+ if (path.endsWith('/'))
32
+ return undefined;
33
+ //path = await job.realpath(path, parent)
34
+ if (await job.isFile(path))
35
+ return path;
36
+ if (job.ts &&
37
+ path.startsWith(job.base) &&
38
+ path.slice(job.base.length).indexOf(sep + 'node_modules' + sep) === -1 &&
39
+ (await job.isFile(path + '.ts')))
40
+ return path + '.ts';
41
+ if (job.ts &&
42
+ path.startsWith(job.base) &&
43
+ path.slice(job.base.length).indexOf(sep + 'node_modules' + sep) === -1 &&
44
+ (await job.isFile(path + '.tsx')))
45
+ return path + '.tsx';
46
+ if (await job.isFile(path + '.js'))
47
+ return path + '.js';
48
+ if (await job.isFile(path + '.json'))
49
+ return path + '.json';
50
+ return undefined;
51
+ }
52
+ export class NotFoundError extends Error {
53
+ code;
54
+ constructor(specifier, parent) {
55
+ super("Cannot find module '" + specifier + "' loaded from " + parent);
56
+ this.code = 'MODULE_NOT_FOUND';
57
+ }
58
+ }
59
+ function getPkgName(name) {
60
+ const segments = name.split('/');
61
+ if (name[0] === '@' && segments.length > 1)
62
+ return segments.length > 1 ? segments.slice(0, 2).join('/') : null;
63
+ return segments.length ? segments[0] : null;
64
+ }
65
+ async function getPkgCfg(pkgPath, job) {
66
+ const pjsonSource = await job.readFile(pkgPath + sep + 'package.json');
67
+ if (pjsonSource) {
68
+ try {
69
+ return JSON.parse(pjsonSource.toString());
70
+ }
71
+ catch { }
72
+ }
73
+ return undefined;
74
+ }
75
+ function getExportsTarget(exports, conditions) {
76
+ if (typeof exports === 'string') {
77
+ return exports;
78
+ }
79
+ else if (exports === null) {
80
+ return exports;
81
+ }
82
+ else if (Array.isArray(exports)) {
83
+ for (const item of exports) {
84
+ const target = getExportsTarget(item, conditions);
85
+ if (target === null || (typeof target === 'string' && target.startsWith('./')))
86
+ return target;
87
+ }
88
+ }
89
+ else if (typeof exports === 'object') {
90
+ for (const condition of Object.keys(exports)) {
91
+ if (condition === 'default' || condition === 'import' || conditions.includes(condition)) {
92
+ const target = getExportsTarget(exports[condition], conditions);
93
+ if (target !== undefined)
94
+ return target;
95
+ }
96
+ }
97
+ }
98
+ return undefined;
99
+ }
100
+ async function validateAndResolvePaths(paths, parent, job) {
101
+ const validatedPaths = [];
102
+ for (const path of paths) {
103
+ if (!(await job.isFile(path)))
104
+ throw new NotFoundError(path, parent);
105
+ validatedPaths.push(path);
106
+ }
107
+ return validatedPaths;
108
+ }
109
+ async function resolveExportsImports(pkgPath, obj, subpath, job, isImports, parent) {
110
+ let matchObj;
111
+ if (isImports) {
112
+ if (!(typeof obj === 'object' && !Array.isArray(obj) && obj !== null))
113
+ return undefined;
114
+ matchObj = obj;
115
+ }
116
+ else if (typeof obj === 'string' ||
117
+ Array.isArray(obj) ||
118
+ obj === null ||
119
+ (typeof obj === 'object' && Object.keys(obj).length && Object.keys(obj)[0][0] !== '.')) {
120
+ matchObj = { '.': obj };
121
+ }
122
+ else {
123
+ matchObj = obj;
124
+ }
125
+ if (subpath in matchObj) {
126
+ const target = getExportsTarget(matchObj[subpath], job.conditions);
127
+ if (typeof target === 'string' && target.startsWith('./')) {
128
+ const resolvedPath = pkgPath + target.slice(1);
129
+ return await validateAndResolvePaths([resolvedPath], parent, job);
130
+ }
131
+ }
132
+ for (const match of Object.keys(matchObj).sort((a, b) => b.length - a.length)) {
133
+ if (match.endsWith('*') && subpath.startsWith(match.slice(0, -1))) {
134
+ const target = getExportsTarget(matchObj[match], job.conditions);
135
+ if (typeof target === 'string' && target.startsWith('./')) {
136
+ const resolvedPath = pkgPath + target.slice(1).replace(/\*/g, subpath.slice(match.length - 1));
137
+ return await validateAndResolvePaths([resolvedPath], parent, job);
138
+ }
139
+ }
140
+ if (!match.endsWith('/'))
141
+ continue;
142
+ if (subpath.startsWith(match)) {
143
+ const target = getExportsTarget(matchObj[match], job.conditions);
144
+ if (typeof target === 'string' && target.endsWith('/') && target.startsWith('./')) {
145
+ const resolvedPath = pkgPath + target.slice(1) + subpath.slice(match.length);
146
+ return await validateAndResolvePaths([resolvedPath], parent, job);
147
+ }
148
+ }
149
+ }
150
+ return undefined;
151
+ }
152
+ async function packageImportsResolve(name, parent, job) {
153
+ if (name !== '#' && !name.startsWith('#/') && job.conditions) {
154
+ const pjsonBoundary = await job.getPjsonBoundary(parent);
155
+ if (pjsonBoundary) {
156
+ const pkgCfg = await getPkgCfg(pjsonBoundary, job);
157
+ const { imports: pkgImports } = pkgCfg || {};
158
+ if (pkgCfg && pkgImports !== null && pkgImports !== undefined) {
159
+ const importsResolved = await resolveExportsImports(pjsonBoundary, pkgImports, name, job, true, parent);
160
+ if (importsResolved) {
161
+ await job.emitFile(pjsonBoundary + sep + 'package.json', 'resolve', parent);
162
+ return importsResolved;
163
+ }
164
+ }
165
+ }
166
+ }
167
+ throw new NotFoundError(name, parent);
168
+ }
169
+ async function resolvePackage(name, parent, job) {
170
+ let packageParent = parent;
171
+ if (name.startsWith('node:')) {
172
+ throw new Error('node: imports not supported');
173
+ }
174
+ const pkgName = getPkgName(name) || '';
175
+ // package own name resolution
176
+ let selfResolved;
177
+ if (job.conditions) {
178
+ const pjsonBoundary = await job.getPjsonBoundary(parent);
179
+ if (pjsonBoundary) {
180
+ const pkgCfg = await getPkgCfg(pjsonBoundary, job);
181
+ const { exports: pkgExports } = pkgCfg || {};
182
+ if (pkgCfg &&
183
+ pkgCfg.name &&
184
+ pkgCfg.name === pkgName &&
185
+ pkgExports !== null &&
186
+ pkgExports !== undefined) {
187
+ selfResolved = await resolveExportsImports(pjsonBoundary, pkgExports, '.' + name.slice(pkgName.length), job, false, parent);
188
+ if (selfResolved)
189
+ await job.emitFile(pjsonBoundary + sep + 'package.json', 'resolve', parent);
190
+ }
191
+ }
192
+ }
193
+ let separatorIndex;
194
+ const rootSeparatorIndex = packageParent.indexOf(sep);
195
+ while ((separatorIndex = packageParent.lastIndexOf(sep)) > rootSeparatorIndex) {
196
+ packageParent = packageParent.slice(0, separatorIndex);
197
+ const nodeModulesDir = packageParent + sep + 'node_modules';
198
+ const stat = await job.stat(nodeModulesDir);
199
+ if (!stat || !stat.isDirectory())
200
+ continue;
201
+ const pkgCfg = await getPkgCfg(nodeModulesDir + sep + pkgName, job);
202
+ const { exports: pkgExports } = pkgCfg || {};
203
+ if (job.conditions && pkgExports !== undefined && pkgExports !== null && !selfResolved) {
204
+ const resolved = await resolveExportsImports(nodeModulesDir + sep + pkgName, pkgExports, '.' + name.slice(pkgName.length), job, false, parent);
205
+ if (resolved) {
206
+ await job.emitFile(nodeModulesDir + sep + pkgName + sep + 'package.json', 'resolve', parent);
207
+ return resolved;
208
+ }
209
+ }
210
+ else {
211
+ const resolved = await resolveFile(nodeModulesDir + sep + name, parent, job);
212
+ if (resolved) {
213
+ if (selfResolved) {
214
+ if (Array.isArray(selfResolved)) {
215
+ if (!selfResolved.includes(resolved))
216
+ return [resolved, ...selfResolved];
217
+ return selfResolved;
218
+ }
219
+ else if (selfResolved !== resolved) {
220
+ return [resolved, selfResolved];
221
+ }
222
+ }
223
+ return resolved;
224
+ }
225
+ }
226
+ }
227
+ if (selfResolved)
228
+ return selfResolved;
229
+ if (Object.hasOwnProperty.call(job.paths, name)) {
230
+ return job.paths[name];
231
+ }
232
+ for (const path of Object.keys(job.paths)) {
233
+ if (path.endsWith('/') && name.startsWith(path)) {
234
+ const pathTarget = job.paths[path] + name.slice(path.length);
235
+ const resolved = await resolveFile(pathTarget, parent, job);
236
+ if (!resolved) {
237
+ throw new NotFoundError(name, parent);
238
+ }
239
+ return resolved;
240
+ }
241
+ }
242
+ throw new NotFoundError(name, parent);
243
+ }
244
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE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,CAAC,CAAA;oBACjC,CAAC;gBACH,CAAC;gBACD,OAAO,QAAQ,CAAA;YACjB,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,YAAY;QAAE,OAAO,YAAY,CAAA;IACrC,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;QAChD,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAE,CAAA;IACzB,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1C,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,MAAM,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAC5D,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;YAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YACvC,CAAC;YACD,OAAO,QAAQ,CAAA;QACjB,CAAC;IACH,CAAC;IACD,MAAM,IAAI,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AACvC,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { NodeFileTraceOptions, NodeFileTraceReasons, NodeFileTraceReasonType, NodeFileTraceResult } from './types.js';
2
+ export declare function nodeFileTrace(files: string[], opts?: NodeFileTraceOptions): Promise<NodeFileTraceResult>;
3
+ export declare class Tracer {
4
+ ts: boolean;
5
+ base: string;
6
+ cwd: string;
7
+ conditions: string[];
8
+ paths: Record<string, string>;
9
+ ignoreFn: (path: string, parent?: string) => boolean;
10
+ log: boolean;
11
+ depth: number;
12
+ assetExtensions: string[];
13
+ analysis: {
14
+ evaluatePureExpressions?: boolean;
15
+ };
16
+ private analysisCache;
17
+ fileList: Set<string>;
18
+ processed: Set<string>;
19
+ warnings: Set<Error>;
20
+ reasons: NodeFileTraceReasons;
21
+ private cachedFileSystem;
22
+ virtualPathToRealPath: Map<string, string>;
23
+ constructor({ base, processCwd, exports, conditions, paths, ignore, log, ts, analysis, cache, fileIOConcurrency, depth, assetExtensions, }: NodeFileTraceOptions);
24
+ readlink(path: string): Promise<string | null>;
25
+ isFile(path: string): Promise<boolean>;
26
+ stat(path: string): Promise<import("./types.js").Stats | null>;
27
+ private resolveWithTs;
28
+ private remapToVirtualPath;
29
+ private remapResolved;
30
+ private maybeEmitDep;
31
+ resolve(id: string, parent: string, job: Tracer): Promise<string | string[]>;
32
+ readFile(path: string): Promise<Buffer | string | null>;
33
+ realpath(path: string, parent?: string, seen?: Set<unknown>): Promise<string>;
34
+ emitFile(path: string, reasonType: NodeFileTraceReasonType, parent?: string): Promise<boolean>;
35
+ getPjsonBoundary(path: string): Promise<string | undefined>;
36
+ emitDependency(path: string, parent?: string, depth?: number): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=trace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,YAAY,CAAA;AAOnB,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,GAAE,oBAAyB,GAC9B,OAAO,CAAC,mBAAmB,CAAC,CAmC9B;AAUD,qBAAa,MAAM;IACV,EAAE,EAAE,OAAO,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,KAAK,EAAE,MAAM,CAAC,MAA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