Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit fb3de6b

Browse files
committed
follow, walker: replace core module routines with "is-core-module"
1 parent c18c3c6 commit fb3de6b

4 files changed

Lines changed: 20 additions & 24 deletions

File tree

lib/follow.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
import { core, sync, SyncOpts } from 'resolve';
2-
import assert from 'assert';
1+
import { sync, SyncOpts } from 'resolve';
32
import fs from 'fs';
43
import path from 'path';
54
import { toNormalizedRealPath } from './common';
65

76
import type { PackageJson } from './types';
87

9-
Object.keys(core).forEach((key) => {
10-
// 'resolve' hardcodes the list to host's one, but i need
11-
// to be able to allow 'worker_threads' (target 12) on host 8
12-
assert(typeof core[key] === 'boolean');
13-
core[key] = true;
14-
});
15-
16-
export const natives = core;
17-
188
const PROOF = 'a-proof-that-main-is-captured.js';
199

2010
function parentDirectoriesContain(parent: string, directory: string) {

lib/walker.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import assert from 'assert';
44
import fs from 'fs-extra';
5+
import isCore from 'is-core-module';
56
import globby from 'globby';
67
import path from 'path';
78
import chalk from 'chalk';
@@ -21,7 +22,7 @@ import {
2122
toNormalizedRealPath,
2223
} from './common';
2324

24-
import { follow, natives } from './follow';
25+
import { follow } from './follow';
2526
import { log, wasReported } from './log';
2627
import * as detector from './detector';
2728
import {
@@ -845,11 +846,9 @@ class Walker {
845846
derivatives: Derivative[]
846847
) {
847848
for (const derivative of derivatives) {
848-
if (natives[derivative.alias]) continue;
849-
if (derivative.alias.startsWith('node:')) {
850-
if (natives[derivative.alias.slice(5)]) continue;
851-
}
852-
849+
// TODO: actually use the target node version
850+
if (isCore(derivative.alias, '99.0.0')) continue;
851+
853852
switch (derivative.aliasType) {
854853
case ALIAS_AS_RELATIVE:
855854
await this.stepDerivatives_ALIAS_AS_RELATIVE(

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"fs-extra": "^9.1.0",
2727
"globby": "^11.1.0",
2828
"into-stream": "^6.0.0",
29+
"is-core-module": "2.9.0",
2930
"minimist": "^1.2.6",
3031
"multistream": "^4.1.0",
3132
"pkg-fetch": "3.3.0",
@@ -39,6 +40,7 @@
3940
"@babel/core": "7.17.10",
4041
"@types/escodegen": "0.0.7",
4142
"@types/fs-extra": "9.0.13",
43+
"@types/is-core-module": "2.2.0",
4244
"@types/minimist": "1.2.2",
4345
"@types/multistream": "2.1.2",
4446
"@types/node": "14.18.16",

yarn.lock

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@
306306
dependencies:
307307
"@types/node" "*"
308308

309+
"@types/is-core-module@2.2.0":
310+
version "2.2.0"
311+
resolved "https://registry.yarnpkg.com/@types/is-core-module/-/is-core-module-2.2.0.tgz#a6f01308db449fb9200cc8b8b05aa26f404f0ddb"
312+
integrity sha512-4jdbEoadP1B6v5/6YoVFPKUr2NC+knEWMSllpX3cL4FAZktVmveeWTcUHQY7bU6Vx8TEt/ARbQyQapkZvGgFog==
313+
309314
"@types/json-schema@^7.0.7":
310315
version "7.0.9"
311316
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
@@ -1540,20 +1545,20 @@ is-callable@^1.1.4, is-callable@^1.2.4:
15401545
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.4.tgz#47301d58dd0259407865547853df6d61fe471945"
15411546
integrity sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==
15421547

1548+
is-core-module@2.9.0, is-core-module@^2.8.1:
1549+
version "2.9.0"
1550+
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69"
1551+
integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==
1552+
dependencies:
1553+
has "^1.0.3"
1554+
15431555
is-core-module@^2.2.0:
15441556
version "2.8.0"
15451557
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.8.0.tgz#0321336c3d0925e497fd97f5d95cb114a5ccd548"
15461558
integrity sha512-vd15qHsaqrRL7dtH6QNuy0ndJmRDrS9HAM1CAiSifNUFv4x1a0CCVsj18hJ1mShxIG6T2i1sO78MkP56r0nYRw==
15471559
dependencies:
15481560
has "^1.0.3"
15491561

1550-
is-core-module@^2.8.1:
1551-
version "2.9.0"
1552-
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69"
1553-
integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==
1554-
dependencies:
1555-
has "^1.0.3"
1556-
15571562
is-date-object@^1.0.1:
15581563
version "1.0.5"
15591564
resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.5.tgz#0841d5536e724c25597bf6ea62e1bd38298df31f"

0 commit comments

Comments
 (0)