Skip to content

Commit 7db15f0

Browse files
CNDWcpojer
authored andcommitted
changes method of determining builtin modules to include missing builtins (#4740)
1 parent 0748e6f commit 7db15f0

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

packages/jest-resolve/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"main": "build/index.js",
1010
"dependencies": {
1111
"browser-resolve": "^1.11.2",
12-
"chalk": "^2.0.1",
13-
"is-builtin-module": "^1.0.0"
12+
"chalk": "^2.0.1"
1413
},
1514
"devDependencies": {
1615
"jest-haste-map": "^21.2.0"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const isBuiltinModule = require('../is_builtin_module');
2+
3+
describe('isBuiltinModule', () => {
4+
it('should return true for the `path` module', () => {
5+
expect(isBuiltinModule('path')).toBe(true);
6+
});
7+
8+
it('should return false for the `chalk` module', () => {
9+
expect(isBuiltinModule('chalk')).toBe(false);
10+
});
11+
12+
it('should return true for the `_http_common` module', () => {
13+
expect(isBuiltinModule('_http_common')).toBe(true);
14+
});
15+
16+
it('should return false for any internal node builtins', () => {
17+
expect(isBuiltinModule('internal/http')).toBe(false);
18+
});
19+
});

packages/jest-resolve/src/default_resolver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ErrorWithCode = Error & {code?: string};
4242

4343
import fs from 'fs';
4444
import path from 'path';
45-
import isBuiltinModule from 'is-builtin-module';
45+
import isBuiltinModule from './is_builtin_module';
4646

4747
import nodeModulesPaths from './node_modules_paths';
4848

packages/jest-resolve/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {ResolveModuleConfig} from 'types/Resolve';
1414
import fs from 'fs';
1515
import path from 'path';
1616
import nodeModulesPaths from './node_modules_paths';
17-
import isBuiltinModule from 'is-builtin-module';
17+
import isBuiltinModule from './is_builtin_module';
1818
import defaultResolver from './default_resolver.js';
1919
import chalk from 'chalk';
2020

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare var process: {
2+
binding(type: string): {},
3+
};
4+
5+
const BUILTIN_MODULES = Object.keys(process.binding('natives')).filter(
6+
(module: string) => !/^internal\//.test(module),
7+
);
8+
9+
module.exports = function isBuiltinModule(module: string): boolean {
10+
return BUILTIN_MODULES.indexOf(module) !== -1;
11+
};

0 commit comments

Comments
 (0)