From 330ac5c271dcb30d6f3515ac11f69d818d3cd10b Mon Sep 17 00:00:00 2001 From: Travis Peterson Date: Sat, 21 Oct 2017 13:30:05 -0500 Subject: [PATCH] changes method of determining builtin modules to include missing builtins --- packages/jest-resolve/package.json | 3 +-- .../src/__tests__/is_builtin_module.test.js | 19 +++++++++++++++++++ packages/jest-resolve/src/default_resolver.js | 2 +- packages/jest-resolve/src/index.js | 2 +- .../jest-resolve/src/is_builtin_module.js | 11 +++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 packages/jest-resolve/src/__tests__/is_builtin_module.test.js create mode 100644 packages/jest-resolve/src/is_builtin_module.js diff --git a/packages/jest-resolve/package.json b/packages/jest-resolve/package.json index 4242c7283c76..d0879c90c1ef 100644 --- a/packages/jest-resolve/package.json +++ b/packages/jest-resolve/package.json @@ -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" diff --git a/packages/jest-resolve/src/__tests__/is_builtin_module.test.js b/packages/jest-resolve/src/__tests__/is_builtin_module.test.js new file mode 100644 index 000000000000..c57289b8fe82 --- /dev/null +++ b/packages/jest-resolve/src/__tests__/is_builtin_module.test.js @@ -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); + }); +}); diff --git a/packages/jest-resolve/src/default_resolver.js b/packages/jest-resolve/src/default_resolver.js index 6e6e7ba8b926..56c4fc539a38 100644 --- a/packages/jest-resolve/src/default_resolver.js +++ b/packages/jest-resolve/src/default_resolver.js @@ -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'; diff --git a/packages/jest-resolve/src/index.js b/packages/jest-resolve/src/index.js index 36bc5f0915d3..4451ed141528 100644 --- a/packages/jest-resolve/src/index.js +++ b/packages/jest-resolve/src/index.js @@ -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'; diff --git a/packages/jest-resolve/src/is_builtin_module.js b/packages/jest-resolve/src/is_builtin_module.js new file mode 100644 index 000000000000..a244c9f95af0 --- /dev/null +++ b/packages/jest-resolve/src/is_builtin_module.js @@ -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; +};