resolve-everything 0.1.1 → 0.1.3
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/.node-version +1 -0
- package/.npm-version +1 -0
- package/README.md +18 -3
- package/dist/cli.js +7 -5
- package/dist/default-resolver.d.ts +3 -1
- package/dist/default-resolver.js +38 -6
- package/dist/help-text.js +14 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/module.d.ts +3 -0
- package/dist/module.js +51 -8
- package/dist/serialize.js +1 -2
- package/dist/test-helpers.js +4 -4
- package/dist/types.d.ts +4 -1
- package/dist/walk.d.ts +28 -0
- package/dist/walk.js +45 -12
- package/dist/walker.d.ts +4 -1
- package/dist/walker.js +105 -14
- package/package.json +15 -13
package/.node-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v24.14.0
|
package/.npm-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
11.9.0
|
package/README.md
CHANGED
|
@@ -45,17 +45,20 @@ which outputs JSON shaped like:
|
|
|
45
45
|
|
|
46
46
|
- `--only-entrypoint` (boolean): if true, only the imports/requires in the entrypoint file will be resolved, and no other files will be walked over.
|
|
47
47
|
|
|
48
|
-
- `--
|
|
48
|
+
- `--sort` (boolean): if true, results will be sorted lexicographically. If you want results to be stable, you should enable this, as the order is non-deterministic otherwise (because we crawl the filesystem concurrently).
|
|
49
|
+
|
|
50
|
+
- `--resolver` (path): module which exports a JS function that locates modules. Uses a resolver format compatible with [kame](https://github.com/suchipi/kame#config-hell), but with an added optional `async` property.
|
|
49
51
|
|
|
50
52
|
- `--full-errors` (boolean): If reading, parsing, traversal, or resolution errors occur, print as much error information as possible.
|
|
51
53
|
|
|
52
54
|
### Node API
|
|
53
55
|
|
|
54
56
|
```ts
|
|
55
|
-
import { walk } from "resolve-everything";
|
|
57
|
+
import { walk, walkAsync } from "resolve-everything";
|
|
56
58
|
|
|
57
59
|
const entrypoint = "/home/someone/some-file.js";
|
|
58
60
|
const { errors, modules } = walk(entrypoint /* , options */);
|
|
61
|
+
// or you could do: await walkAsync(entrypoint, /* options */);
|
|
59
62
|
|
|
60
63
|
// modules is a Map<string, { id: string, requests: Map<string, string> }>
|
|
61
64
|
```
|
|
@@ -78,12 +81,24 @@ export type WalkOptions = {
|
|
|
78
81
|
*/
|
|
79
82
|
onlyEntrypoint?: boolean;
|
|
80
83
|
|
|
84
|
+
/**
|
|
85
|
+
* If true, results will be sorted lexicographically. If you want results to
|
|
86
|
+
* be stable when using `walkSync`, you should enable this, as the order is
|
|
87
|
+
* non-deterministic otherwise (because we walk the filesystem concurrently).
|
|
88
|
+
*/
|
|
89
|
+
sort?: boolean;
|
|
90
|
+
|
|
81
91
|
/**
|
|
82
92
|
* A function which translates the string-part of an import/require into the
|
|
83
93
|
* absolute path to the file on disk, OR, if there is no file for that module
|
|
84
94
|
* (ie. it's a node builtin), a string starting with "external:".
|
|
95
|
+
*
|
|
96
|
+
* The 'async' property is optional and will only be used by `walkAsync`.
|
|
97
|
+
* If not present, the normal synchronous resolver will be used.
|
|
85
98
|
*/
|
|
86
|
-
resolver?: (id: string, fromFilePath: string) => string
|
|
99
|
+
resolver?: ((id: string, fromFilePath: string) => string) & {
|
|
100
|
+
async?: (id: string, fromFilePath: string) => Promise<string>;
|
|
101
|
+
};
|
|
87
102
|
};
|
|
88
103
|
```
|
|
89
104
|
|
package/dist/cli.js
CHANGED
|
@@ -15,9 +15,10 @@ const _1 = require(".");
|
|
|
15
15
|
skip: clefairy_1.optionalString,
|
|
16
16
|
json: clefairy_1.optionalBoolean,
|
|
17
17
|
onlyEntrypoint: clefairy_1.optionalBoolean,
|
|
18
|
+
sort: clefairy_1.optionalBoolean,
|
|
18
19
|
help: clefairy_1.optionalBoolean,
|
|
19
20
|
h: clefairy_1.optionalBoolean,
|
|
20
|
-
}, async ({ entrypoint, resolver, fullErrors, skip, json, onlyEntrypoint, help, h, }) => {
|
|
21
|
+
}, async ({ entrypoint, resolver, fullErrors, skip, json, onlyEntrypoint, sort, help, h, }) => {
|
|
21
22
|
if (help || h) {
|
|
22
23
|
const helpText = require("./help-text").default;
|
|
23
24
|
console.log(helpText);
|
|
@@ -26,10 +27,11 @@ const _1 = require(".");
|
|
|
26
27
|
if (entrypoint == null) {
|
|
27
28
|
throw new Error(`You must specify an --entrypoint. Run with --help for more info.`);
|
|
28
29
|
}
|
|
29
|
-
if (!node_fs_1.default.existsSync(entrypoint)) {
|
|
30
|
+
if (!node_fs_1.default.existsSync(entrypoint.toString())) {
|
|
30
31
|
throw new Error("No such file: " + entrypoint);
|
|
31
32
|
}
|
|
32
33
|
const walkOptions = {
|
|
34
|
+
sort,
|
|
33
35
|
onError: (err) => {
|
|
34
36
|
if (!fullErrors && /node_modules/.test(err.filename || "")) {
|
|
35
37
|
// Don't report resolution errors under node_modules dirs because
|
|
@@ -67,7 +69,7 @@ const _1 = require(".");
|
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
if (resolver) {
|
|
70
|
-
const exps = require(resolver);
|
|
72
|
+
const exps = require(resolver.toString());
|
|
71
73
|
if (typeof exps === "function") {
|
|
72
74
|
walkOptions.resolver = exps;
|
|
73
75
|
}
|
|
@@ -86,10 +88,10 @@ const _1 = require(".");
|
|
|
86
88
|
throw new Error(`Resolver at ${JSON.stringify(resolver)} didn't export a 'resolve' function.`);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
|
-
const result = (0, _1.
|
|
91
|
+
const result = await (0, _1.walkAsync)(entrypoint.toString(), walkOptions);
|
|
90
92
|
let toPrint = (0, _1.serialize)(result.modules);
|
|
91
93
|
if (onlyEntrypoint) {
|
|
92
|
-
toPrint = toPrint[entrypoint];
|
|
94
|
+
toPrint = toPrint[entrypoint.toString()];
|
|
93
95
|
}
|
|
94
96
|
if (json === undefined && !process.stdout.isTTY) {
|
|
95
97
|
json = true;
|
package/dist/default-resolver.js
CHANGED
|
@@ -6,16 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.defaultResolver = void 0;
|
|
7
7
|
const node_module_1 = __importDefault(require("node:module"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
9
10
|
const resolve_1 = __importDefault(require("resolve"));
|
|
10
11
|
if (!Array.isArray(node_module_1.default.builtinModules)) {
|
|
11
12
|
throw new Error("your node version seriously way too old bruh");
|
|
12
13
|
}
|
|
13
14
|
const allBuiltins = new Set(node_module_1.default.builtinModules);
|
|
14
|
-
|
|
15
|
-
//
|
|
15
|
+
const resolveAsync = node_util_1.default.promisify(resolve_1.default);
|
|
16
|
+
// This is (more or less) a direct copy-paste of kame's default resolver, with
|
|
17
|
+
// async added.
|
|
16
18
|
//
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
+
// Part of why we copy-paste it instead of depending on it directly is because
|
|
20
|
+
// kame has a LOT of deps and we just need this piece
|
|
21
|
+
//
|
|
22
|
+
// https://github.com/suchipi/kame/blob/ae317caf325d5cbe4925fe30273159b6c04651a6/src/default-resolver.ts#L10
|
|
23
|
+
exports.defaultResolver = Object.assign(function defaultResolver(id, fromFilePath) {
|
|
19
24
|
if (id.includes(":") && !id.startsWith("file:")) {
|
|
20
25
|
return "external:" + id;
|
|
21
26
|
}
|
|
@@ -29,6 +34,7 @@ function defaultResolver(id, fromFilePath) {
|
|
|
29
34
|
".js",
|
|
30
35
|
".json",
|
|
31
36
|
".mjs",
|
|
37
|
+
".cjs",
|
|
32
38
|
".jsx",
|
|
33
39
|
".ts",
|
|
34
40
|
".tsx",
|
|
@@ -40,5 +46,31 @@ function defaultResolver(id, fromFilePath) {
|
|
|
40
46
|
return "external:" + result;
|
|
41
47
|
}
|
|
42
48
|
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
49
|
+
}, {
|
|
50
|
+
async: async function defaultResolverAsync(id, fromFilePath) {
|
|
51
|
+
if (id.includes(":") && !id.startsWith("file:")) {
|
|
52
|
+
return "external:" + id;
|
|
53
|
+
}
|
|
54
|
+
if (allBuiltins.has(id.split("/")[0])) {
|
|
55
|
+
return "external:" + id;
|
|
56
|
+
}
|
|
57
|
+
const result = await resolveAsync(id, {
|
|
58
|
+
basedir: node_path_1.default.dirname(fromFilePath),
|
|
59
|
+
preserveSymlinks: false,
|
|
60
|
+
extensions: [
|
|
61
|
+
".js",
|
|
62
|
+
".json",
|
|
63
|
+
".mjs",
|
|
64
|
+
".jsx",
|
|
65
|
+
".ts",
|
|
66
|
+
".tsx",
|
|
67
|
+
".node",
|
|
68
|
+
".wasm",
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
if (result.endsWith(".node") || result.endsWith(".wasm")) {
|
|
72
|
+
return "external:" + result;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
},
|
|
76
|
+
});
|
package/dist/help-text.js
CHANGED
|
@@ -60,11 +60,22 @@ ${opt("--only-entrypoint")} (boolean):
|
|
|
60
60
|
If true, only the imports/requires in the entrypoint file will be resolved,
|
|
61
61
|
and no other files will be walked over.
|
|
62
62
|
|
|
63
|
+
${opt("--sort")} (boolean):
|
|
64
|
+
If true, results will be sorted lexicographically. If you want results to be
|
|
65
|
+
stable, you should enable this, as the order is non-deterministic otherwise
|
|
66
|
+
(because we crawl the filesystem concurrently).
|
|
67
|
+
|
|
63
68
|
${opt("--resolver")} (path):
|
|
64
|
-
Module which exports a JS function that locates modules. Uses
|
|
65
|
-
|
|
69
|
+
Module which exports a JS function that locates modules. Uses a resolver
|
|
70
|
+
format compatible with https://github.com/suchipi/kame, namely:
|
|
71
|
+
|
|
72
|
+
export const resolve: {
|
|
73
|
+
(id: string, fromFilePath: string): string;
|
|
74
|
+
async?: (id: string, fromFilePath: string) => Promise<string>;
|
|
75
|
+
}
|
|
66
76
|
|
|
67
|
-
|
|
77
|
+
The 'async' property is optional; if not present, the normal synchronous
|
|
78
|
+
resolver will be used.
|
|
68
79
|
|
|
69
80
|
${opt("--full-errors")} (boolean):
|
|
70
81
|
If reading, parsing, traversal, or resolution errors occur, print as much
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { walk, type WalkOptions } from "./walk";
|
|
1
|
+
export { walk, walkAsync, type WalkOptions } from "./walk";
|
|
2
2
|
export type { ErrorReport as ReportedError, ResolverFunction } from "./types";
|
|
3
3
|
export { defaultResolver } from "./default-resolver";
|
|
4
4
|
export { Walker, type WalkerOptions } from "./walker";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serialize = exports.Module = exports.Walker = exports.defaultResolver = exports.walk = void 0;
|
|
3
|
+
exports.serialize = exports.Module = exports.Walker = exports.defaultResolver = exports.walkAsync = exports.walk = void 0;
|
|
4
4
|
var walk_1 = require("./walk");
|
|
5
5
|
Object.defineProperty(exports, "walk", { enumerable: true, get: function () { return walk_1.walk; } });
|
|
6
|
+
Object.defineProperty(exports, "walkAsync", { enumerable: true, get: function () { return walk_1.walkAsync; } });
|
|
6
7
|
var default_resolver_1 = require("./default-resolver");
|
|
7
8
|
Object.defineProperty(exports, "defaultResolver", { enumerable: true, get: function () { return default_resolver_1.defaultResolver; } });
|
|
8
9
|
var walker_1 = require("./walker");
|
package/dist/module.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ export declare class Module {
|
|
|
5
5
|
requests: Map<string, string>;
|
|
6
6
|
constructor(id: string);
|
|
7
7
|
read(): string | null;
|
|
8
|
+
readAsync(): Promise<string | null>;
|
|
8
9
|
parse(code: string): ee.types.File;
|
|
9
10
|
getRequests(ast: ee.types.File): Array<string>;
|
|
10
11
|
resolve(request: string, resolver: ResolverFunction): string;
|
|
12
|
+
resolveAsync(request: string, resolver: ResolverFunction): Promise<string>;
|
|
13
|
+
get dependencies(): Set<string>;
|
|
11
14
|
}
|
package/dist/module.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.Module = void 0;
|
|
27
37
|
const fs = __importStar(require("node:fs"));
|
|
@@ -51,10 +61,25 @@ class Module {
|
|
|
51
61
|
debug_logger_1.debugLogger.returns("Module.read ->", code);
|
|
52
62
|
return code;
|
|
53
63
|
}
|
|
64
|
+
async readAsync() {
|
|
65
|
+
debug_logger_1.debugLogger.summary("Module.readAsync", this.id);
|
|
66
|
+
if (!/\.[cm]?[tj]sx?$/.test(this.id)) {
|
|
67
|
+
debug_logger_1.debugLogger.summary("doesn't appear to be js/ts:", this.id);
|
|
68
|
+
debug_logger_1.debugLogger.returns("Module.readAsync -> null");
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const code = await fs.promises.readFile(this.id, "utf-8");
|
|
72
|
+
debug_logger_1.debugLogger.fileContent(code);
|
|
73
|
+
debug_logger_1.debugLogger.returns("Module.readAsync ->", code);
|
|
74
|
+
return code;
|
|
75
|
+
}
|
|
54
76
|
parse(code) {
|
|
55
77
|
debug_logger_1.debugLogger.summary("Module.parse", this.id);
|
|
56
78
|
debug_logger_1.debugLogger.args("Module.parse", code);
|
|
57
|
-
const ast = ee.
|
|
79
|
+
const ast = ee.parse(code, {
|
|
80
|
+
fileName: this.id,
|
|
81
|
+
parseOptions: { skipRecast: true },
|
|
82
|
+
});
|
|
58
83
|
debug_logger_1.debugLogger.ast(formatAst(ast, { color: true }));
|
|
59
84
|
debug_logger_1.debugLogger.returns("Module.parse ->", ast);
|
|
60
85
|
return ast;
|
|
@@ -122,5 +147,23 @@ class Module {
|
|
|
122
147
|
debug_logger_1.debugLogger.returns("Module.resolve ->", resolved);
|
|
123
148
|
return resolved;
|
|
124
149
|
}
|
|
150
|
+
async resolveAsync(request, resolver) {
|
|
151
|
+
debug_logger_1.debugLogger.summary("Module.resolveAsync", this.id, request);
|
|
152
|
+
debug_logger_1.debugLogger.args("Module.resolveAsync", request, resolver);
|
|
153
|
+
let resolved;
|
|
154
|
+
if (resolver.async == null) {
|
|
155
|
+
debug_logger_1.debugLogger.summary("Module.resolveAsync falling back to sync as user-provided resolver doesn't have an 'async' property");
|
|
156
|
+
resolved = resolver(request, this.id);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
resolved = await resolver.async(request, this.id);
|
|
160
|
+
}
|
|
161
|
+
this.requests.set(request, resolved);
|
|
162
|
+
debug_logger_1.debugLogger.returns("Module.resolveAsync ->", resolved);
|
|
163
|
+
return resolved;
|
|
164
|
+
}
|
|
165
|
+
get dependencies() {
|
|
166
|
+
return new Set(this.requests.values());
|
|
167
|
+
}
|
|
125
168
|
}
|
|
126
169
|
exports.Module = Module;
|
package/dist/serialize.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serialize =
|
|
3
|
+
exports.serialize = serialize;
|
|
4
4
|
function serialize(modules) {
|
|
5
5
|
const result = {};
|
|
6
6
|
for (const [id, mod] of modules) {
|
|
@@ -16,4 +16,3 @@ function serialize(modules) {
|
|
|
16
16
|
}
|
|
17
17
|
return result;
|
|
18
18
|
}
|
|
19
|
-
exports.serialize = serialize;
|
package/dist/test-helpers.js
CHANGED
|
@@ -3,7 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.cliPath = exports.rootDir = void 0;
|
|
7
|
+
exports.cleanString = cleanString;
|
|
8
|
+
exports.inspectAndClean = inspectAndClean;
|
|
9
|
+
exports.cleanRunResult = cleanRunResult;
|
|
7
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
11
|
const node_util_1 = __importDefault(require("node:util"));
|
|
9
12
|
const path_less_traveled_1 = require("path-less-traveled");
|
|
@@ -12,11 +15,9 @@ exports.cliPath = (0, exports.rootDir)("dist/cli.js");
|
|
|
12
15
|
function cleanString(str) {
|
|
13
16
|
return str.replaceAll((0, exports.rootDir)(), "<rootDir>");
|
|
14
17
|
}
|
|
15
|
-
exports.cleanString = cleanString;
|
|
16
18
|
function inspectAndClean(value) {
|
|
17
19
|
return cleanString(node_util_1.default.inspect(value, { depth: Infinity }));
|
|
18
20
|
}
|
|
19
|
-
exports.inspectAndClean = inspectAndClean;
|
|
20
21
|
function cleanRunResult(result) {
|
|
21
22
|
return {
|
|
22
23
|
...result,
|
|
@@ -24,4 +25,3 @@ function cleanRunResult(result) {
|
|
|
24
25
|
stderr: cleanString(result.stderr),
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
|
-
exports.cleanRunResult = cleanRunResult;
|
package/dist/types.d.ts
CHANGED
|
@@ -4,4 +4,7 @@ export type ErrorReport = {
|
|
|
4
4
|
stage: "read" | "parse" | "getRequests" | "resolve";
|
|
5
5
|
error: Error;
|
|
6
6
|
};
|
|
7
|
-
export type ResolverFunction =
|
|
7
|
+
export type ResolverFunction = {
|
|
8
|
+
(id: string, fromFilePath: string): string;
|
|
9
|
+
async?(id: string, fromFilePath: string): Promise<string>;
|
|
10
|
+
};
|
package/dist/walk.d.ts
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
import type { Module } from "./module";
|
|
2
2
|
import type { ErrorReport, ResolverFunction } from "./types";
|
|
3
3
|
export type WalkOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* A function to call whenever an error occurs.
|
|
6
|
+
*/
|
|
4
7
|
onError?: (error: ErrorReport) => void;
|
|
8
|
+
/**
|
|
9
|
+
* A function which translates the string-part of an import/require into the
|
|
10
|
+
* absolute path to the file on disk, OR, if there is no file for that module
|
|
11
|
+
* (ie. it's a node builtin), a string starting with "external:".
|
|
12
|
+
*/
|
|
5
13
|
resolver?: ResolverFunction;
|
|
14
|
+
/**
|
|
15
|
+
* Which files not to parse and find requires/imports in.
|
|
16
|
+
*
|
|
17
|
+
* Defaults to `/node_modules/`.
|
|
18
|
+
* Specify `null` to include node_modules.
|
|
19
|
+
*/
|
|
6
20
|
skip?: RegExp | null;
|
|
21
|
+
/**
|
|
22
|
+
* If true, only the imports/requires in the entrypoint file will be
|
|
23
|
+
* resolved, and no other files will be walked over.
|
|
24
|
+
*/
|
|
7
25
|
onlyEntrypoint?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* If true, results will be sorted lexicographically. If you want results to
|
|
28
|
+
* be stable when using `walkSync`, you should enable this, as the order is
|
|
29
|
+
* non-deterministic otherwise (because we walk the filesystem concurrently).
|
|
30
|
+
*/
|
|
31
|
+
sort?: boolean;
|
|
8
32
|
};
|
|
9
33
|
export declare function walk(entrypoint: string, options?: WalkOptions): {
|
|
10
34
|
errors: ErrorReport[];
|
|
11
35
|
modules: Map<string, Module>;
|
|
12
36
|
};
|
|
37
|
+
export declare function walkAsync(entrypoint: string, options?: WalkOptions): Promise<{
|
|
38
|
+
errors: ErrorReport[];
|
|
39
|
+
modules: Map<string, Module>;
|
|
40
|
+
}>;
|
package/dist/walk.js
CHANGED
|
@@ -15,22 +15,31 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.walk =
|
|
36
|
+
exports.walk = walk;
|
|
37
|
+
exports.walkAsync = walkAsync;
|
|
27
38
|
const path = __importStar(require("node:path"));
|
|
28
39
|
const walker_1 = require("./walker");
|
|
29
40
|
const debug_logger_1 = require("./debug-logger");
|
|
30
41
|
const default_resolver_1 = require("./default-resolver");
|
|
31
|
-
function
|
|
32
|
-
debug_logger_1.debugLogger.summary("walk", entrypoint);
|
|
33
|
-
debug_logger_1.debugLogger.args("walk", entrypoint, options);
|
|
42
|
+
function makeWalker(entrypoint, options) {
|
|
34
43
|
if (!path.isAbsolute(entrypoint)) {
|
|
35
44
|
throw new Error(`entrypoint must be an absolute path. received: ${entrypoint}`);
|
|
36
45
|
}
|
|
@@ -45,6 +54,15 @@ function walk(entrypoint, options) {
|
|
|
45
54
|
if (options?.onError) {
|
|
46
55
|
walker.on("error", options.onError);
|
|
47
56
|
}
|
|
57
|
+
return walker;
|
|
58
|
+
}
|
|
59
|
+
function walk(entrypoint, options) {
|
|
60
|
+
debug_logger_1.debugLogger.summary("walk", entrypoint);
|
|
61
|
+
debug_logger_1.debugLogger.args("walk", entrypoint, options);
|
|
62
|
+
const walker = makeWalker(entrypoint, options);
|
|
63
|
+
if (options?.sort) {
|
|
64
|
+
walker.sort();
|
|
65
|
+
}
|
|
48
66
|
const { errors } = walker.walk();
|
|
49
67
|
const modules = walker.modules;
|
|
50
68
|
const ret = {
|
|
@@ -54,4 +72,19 @@ function walk(entrypoint, options) {
|
|
|
54
72
|
debug_logger_1.debugLogger.returns("walk ->", ret);
|
|
55
73
|
return ret;
|
|
56
74
|
}
|
|
57
|
-
|
|
75
|
+
async function walkAsync(entrypoint, options) {
|
|
76
|
+
debug_logger_1.debugLogger.summary("walkAsync", entrypoint);
|
|
77
|
+
debug_logger_1.debugLogger.args("walkAsync", entrypoint, options);
|
|
78
|
+
const walker = makeWalker(entrypoint, options);
|
|
79
|
+
const { errors } = await walker.walkAsync();
|
|
80
|
+
if (options?.sort) {
|
|
81
|
+
walker.sort();
|
|
82
|
+
}
|
|
83
|
+
const modules = walker.modules;
|
|
84
|
+
const ret = {
|
|
85
|
+
errors,
|
|
86
|
+
modules,
|
|
87
|
+
};
|
|
88
|
+
debug_logger_1.debugLogger.returns("walkAsync ->", ret);
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
package/dist/walker.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { EventEmitter } from "node:events";
|
|
3
2
|
import { Module } from "./module";
|
|
4
3
|
import type { ErrorReport, ResolverFunction } from "./types";
|
|
@@ -15,4 +14,8 @@ export declare class Walker extends EventEmitter {
|
|
|
15
14
|
walk(): {
|
|
16
15
|
errors: Array<ErrorReport>;
|
|
17
16
|
};
|
|
17
|
+
walkAsync(): Promise<{
|
|
18
|
+
errors: Array<ErrorReport>;
|
|
19
|
+
}>;
|
|
20
|
+
sort(): void;
|
|
18
21
|
}
|
package/dist/walker.js
CHANGED
|
@@ -15,17 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.Walker = void 0;
|
|
27
37
|
const path = __importStar(require("node:path"));
|
|
28
38
|
const node_events_1 = require("node:events");
|
|
39
|
+
const parallel_park_1 = require("parallel-park");
|
|
29
40
|
const module_1 = require("./module");
|
|
30
41
|
const debug_logger_1 = require("./debug-logger");
|
|
31
42
|
class Walker extends node_events_1.EventEmitter {
|
|
@@ -44,12 +55,10 @@ class Walker extends node_events_1.EventEmitter {
|
|
|
44
55
|
let filename;
|
|
45
56
|
const errors = [];
|
|
46
57
|
let errorStage = "read";
|
|
47
|
-
|
|
48
|
-
const reportError = (error) => {
|
|
58
|
+
const reportError = (error, request) => {
|
|
49
59
|
const report = {
|
|
50
60
|
filename,
|
|
51
61
|
stage: errorStage,
|
|
52
|
-
request: errorRequest,
|
|
53
62
|
error,
|
|
54
63
|
};
|
|
55
64
|
debug_logger_1.debugLogger.summary("error reported:", report);
|
|
@@ -76,9 +85,7 @@ class Walker extends node_events_1.EventEmitter {
|
|
|
76
85
|
errorStage = "getRequests";
|
|
77
86
|
const requests = mod.getRequests(ast);
|
|
78
87
|
errorStage = "resolve";
|
|
79
|
-
errorRequest = undefined;
|
|
80
88
|
for (const request of requests) {
|
|
81
|
-
errorRequest = request;
|
|
82
89
|
try {
|
|
83
90
|
const target = mod.resolve(request, this._options.resolver);
|
|
84
91
|
if (target.startsWith("external:")) {
|
|
@@ -94,10 +101,9 @@ class Walker extends node_events_1.EventEmitter {
|
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
catch (error) {
|
|
97
|
-
reportError(error);
|
|
104
|
+
reportError(error, request);
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
|
-
errorRequest = undefined;
|
|
101
107
|
}
|
|
102
108
|
catch (error) {
|
|
103
109
|
reportError(error);
|
|
@@ -110,5 +116,90 @@ class Walker extends node_events_1.EventEmitter {
|
|
|
110
116
|
debug_logger_1.debugLogger.returns("Walker.walk ->", ret);
|
|
111
117
|
return ret;
|
|
112
118
|
}
|
|
119
|
+
async walkAsync() {
|
|
120
|
+
debug_logger_1.debugLogger.summary("Walker.walkAsync");
|
|
121
|
+
const filesToProcess = [this.entrypoint];
|
|
122
|
+
let filename;
|
|
123
|
+
const errors = [];
|
|
124
|
+
let errorStage = "read";
|
|
125
|
+
const reportError = (error, request) => {
|
|
126
|
+
const report = {
|
|
127
|
+
filename,
|
|
128
|
+
stage: errorStage,
|
|
129
|
+
request,
|
|
130
|
+
error,
|
|
131
|
+
};
|
|
132
|
+
debug_logger_1.debugLogger.summary("error reported:", report);
|
|
133
|
+
this.emit("error", report);
|
|
134
|
+
errors.push(report);
|
|
135
|
+
};
|
|
136
|
+
while ((filename = filesToProcess.shift())) {
|
|
137
|
+
debug_logger_1.debugLogger.summary("Walker.walkAsync -> processing", filename);
|
|
138
|
+
this.emit("processing", filename);
|
|
139
|
+
if (this.modules.has(filename)) {
|
|
140
|
+
// already processed
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const mod = new module_1.Module(filename);
|
|
144
|
+
this.modules.set(filename, mod);
|
|
145
|
+
try {
|
|
146
|
+
const code = await mod.readAsync();
|
|
147
|
+
if (code == null) {
|
|
148
|
+
// not a js/ts file
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
errorStage = "parse";
|
|
152
|
+
const ast = mod.parse(code);
|
|
153
|
+
errorStage = "getRequests";
|
|
154
|
+
const requests = mod.getRequests(ast);
|
|
155
|
+
errorStage = "resolve";
|
|
156
|
+
await (0, parallel_park_1.runJobs)(requests, async (request) => {
|
|
157
|
+
try {
|
|
158
|
+
const target = await mod.resolveAsync(request, this._options.resolver);
|
|
159
|
+
if (target.startsWith("external:")) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (this._options.skip != null && this._options.skip.test(target)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!this.modules.has(target)) {
|
|
166
|
+
debug_logger_1.debugLogger.summary("Walker.walkAsync -> queueing", target);
|
|
167
|
+
this.emit("queueing", target);
|
|
168
|
+
filesToProcess.push(target);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
reportError(error, request);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
reportError(error);
|
|
178
|
+
}
|
|
179
|
+
if (this._options.onlyEntrypoint) {
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const ret = { errors };
|
|
184
|
+
debug_logger_1.debugLogger.returns("Walker.walkAsync ->", ret);
|
|
185
|
+
return ret;
|
|
186
|
+
}
|
|
187
|
+
sort() {
|
|
188
|
+
const newModules = new Map();
|
|
189
|
+
const keys = Array.from(this.modules.keys());
|
|
190
|
+
keys.sort();
|
|
191
|
+
for (const key of keys) {
|
|
192
|
+
const mod = this.modules.get(key);
|
|
193
|
+
const newRequests = new Map();
|
|
194
|
+
const reqKeys = Array.from(mod.requests.keys());
|
|
195
|
+
reqKeys.sort();
|
|
196
|
+
for (const reqKey of reqKeys) {
|
|
197
|
+
newRequests.set(reqKey, mod.requests.get(reqKey));
|
|
198
|
+
}
|
|
199
|
+
mod.requests = newRequests;
|
|
200
|
+
newModules.set(key, mod);
|
|
201
|
+
}
|
|
202
|
+
this.modules = newModules;
|
|
203
|
+
}
|
|
113
204
|
}
|
|
114
205
|
exports.Walker = Walker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "resolve-everything",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "walk your project's import/require tree and print all the relationships",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"resolve-everything": "dist/cli.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "rm -rf dist && bunx --bun tsc && chmod +x dist/cli.js",
|
|
11
|
+
"build": "rm -rf dist && bunx --bun tsc && chmod +x dist/cli.js && rm dist/*.test.*",
|
|
12
12
|
"test": "vitest",
|
|
13
13
|
"cli": "bun src/cli.ts"
|
|
14
14
|
},
|
|
@@ -23,22 +23,24 @@
|
|
|
23
23
|
"author": "Lily Skye <me@suchipi.com>",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@types/debug": "^4.1.
|
|
27
|
-
"@types/
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
26
|
+
"@types/debug": "^4.1.13",
|
|
27
|
+
"@types/node": "^25.5.0",
|
|
28
|
+
"@types/resolve": "^1.20.6",
|
|
29
|
+
"first-base": "^1.6.1",
|
|
30
|
+
"path-less-traveled": "^2.2.1",
|
|
31
|
+
"prettier": "^3.8.1",
|
|
32
|
+
"typescript": "^5.9.3",
|
|
33
|
+
"vitest": "^4.1.0"
|
|
33
34
|
},
|
|
34
35
|
"prettier": {},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"clefairy": "^
|
|
37
|
-
"debug": "^4.3
|
|
38
|
-
"equivalent-exchange": "^
|
|
37
|
+
"clefairy": "^2.1.0",
|
|
38
|
+
"debug": "^4.4.3",
|
|
39
|
+
"equivalent-exchange": "^3.2.0",
|
|
39
40
|
"kleur": "^4.1.5",
|
|
41
|
+
"parallel-park": "^0.3.1",
|
|
40
42
|
"pretty-print-ast": "^1.0.1",
|
|
41
|
-
"resolve": "^1.22.
|
|
43
|
+
"resolve": "^1.22.11"
|
|
42
44
|
},
|
|
43
45
|
"repository": {
|
|
44
46
|
"type": "git",
|