From d74164082477dcafc4ca3b5a43f610d30cf5e7f9 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 28 Jan 2018 17:50:59 +0100 Subject: [PATCH] fix: get builtin modules from node core --- CHANGELOG.md | 7 ++++--- packages/jest-resolve/src/is_builtin_module.js | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed454b4f67d7..cc517b61ab50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,9 @@ * `[docs]` Add tutorial page for ES6 class mocks. ([#5383]https://github.com/facebook/jest/pull/5383)) * `[jest-resolve]` Search required modules in node_modules and then in custom - paths. - ([#5403](https://github.com/facebook/jest/pull/5403)) + paths. ([#5403](https://github.com/facebook/jest/pull/5403)) +* `[jest-resolve]` Get builtin modules from node core. + ([#5411](https://github.com/facebook/jest/pull/5411)) ## jest 22.1.4 @@ -1493,4 +1494,4 @@ See https://facebook.github.io/jest/blog/2016/12/15/2016-in-jest.html ## <=0.4.0 -* See commit history for changes in previous versions of jest. \ No newline at end of file +* See commit history for changes in previous versions of jest. diff --git a/packages/jest-resolve/src/is_builtin_module.js b/packages/jest-resolve/src/is_builtin_module.js index c7dd31efbd3a..67762edc1ee8 100644 --- a/packages/jest-resolve/src/is_builtin_module.js +++ b/packages/jest-resolve/src/is_builtin_module.js @@ -7,18 +7,20 @@ * @flow */ +// $FlowFixMe: Flow doesn't know about the `module` module +import {builtinModules} from 'module'; + // https://github.com/facebook/flow/pull/5160 declare var process: { binding(type: string): {}, }; const BUILTIN_MODULES = - module.builtinModules || + builtinModules || Object.keys(process.binding('natives')).filter( (module: string) => !/^internal\//.test(module), ); export default function isBuiltinModule(module: string): boolean { - // $FlowFixMe: module.builtinModules is not added to the flow type definitions yet return BUILTIN_MODULES.indexOf(module) !== -1; }