Skip to content

Commit

Permalink
changes method of determining builtin modules to include missing buil…
Browse files Browse the repository at this point in the history
…tins (#4740)
  • Loading branch information
CNDW authored and cpojer committed Oct 22, 2017
1 parent 0748e6f commit 7db15f0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/jest-resolve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"main": "build/index.js",
"dependencies": {
"browser-resolve": "^1.11.2",
"chalk": "^2.0.1",
"is-builtin-module": "^1.0.0"
"chalk": "^2.0.1"
},
"devDependencies": {
"jest-haste-map": "^21.2.0"
Expand Down
19 changes: 19 additions & 0 deletions packages/jest-resolve/src/__tests__/is_builtin_module.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const isBuiltinModule = require('../is_builtin_module');

describe('isBuiltinModule', () => {
it('should return true for the `path` module', () => {
expect(isBuiltinModule('path')).toBe(true);
});

it('should return false for the `chalk` module', () => {
expect(isBuiltinModule('chalk')).toBe(false);
});

it('should return true for the `_http_common` module', () => {
expect(isBuiltinModule('_http_common')).toBe(true);
});

it('should return false for any internal node builtins', () => {
expect(isBuiltinModule('internal/http')).toBe(false);
});
});
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/default_resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ErrorWithCode = Error & {code?: string};

import fs from 'fs';
import path from 'path';
import isBuiltinModule from 'is-builtin-module';
import isBuiltinModule from './is_builtin_module';

import nodeModulesPaths from './node_modules_paths';

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {ResolveModuleConfig} from 'types/Resolve';
import fs from 'fs';
import path from 'path';
import nodeModulesPaths from './node_modules_paths';
import isBuiltinModule from 'is-builtin-module';
import isBuiltinModule from './is_builtin_module';
import defaultResolver from './default_resolver.js';
import chalk from 'chalk';

Expand Down
11 changes: 11 additions & 0 deletions packages/jest-resolve/src/is_builtin_module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
declare var process: {
binding(type: string): {},
};

const BUILTIN_MODULES = Object.keys(process.binding('natives')).filter(
(module: string) => !/^internal\//.test(module),
);

module.exports = function isBuiltinModule(module: string): boolean {
return BUILTIN_MODULES.indexOf(module) !== -1;
};

0 comments on commit 7db15f0

Please sign in to comment.