diff --git a/src/utils/typescript.js b/src/utils/typescript.js index 584146ce..9bfe70bc 100644 --- a/src/utils/typescript.js +++ b/src/utils/typescript.js @@ -1,10 +1,17 @@ +import lodash from 'lodash'; +import builtInModules from 'builtin-modules'; + /* eslint-disable import/prefer-default-export */ const orgDepRegex = /@(.*?)\/(.*)/; // The name of the DefinitelyTyped package for a given package export function getAtTypesName(dep) { - const match = orgDepRegex.exec(dep); - const pkgName = match ? `${match[1]}__${match[2]}` : dep; - + let pkgName; + if (lodash.includes(builtInModules, dep)) { + pkgName = 'node'; + } else { + const match = orgDepRegex.exec(dep); + pkgName = match ? `${match[1]}__${match[2]}` : dep; + } return `@types/${pkgName}`; } diff --git a/test/fake_modules/typescript/esnext.ts b/test/fake_modules/typescript/esnext.ts index ab0d4337..5bc69681 100644 --- a/test/fake_modules/typescript/esnext.ts +++ b/test/fake_modules/typescript/esnext.ts @@ -1,9 +1,11 @@ import Dep from 'ts-dep-esnext'; import '@org/org-pkg'; +import * as path from 'path'; export const ObjRestSpread = () => { const a = {a: 1, b: 2}; const { b, ...rest } = a; const c = {...a, ...rest}; + path.resolve('/', 'home'); new Dep(c); } diff --git a/test/fake_modules/typescript/package.json b/test/fake_modules/typescript/package.json index 20ec4bd5..8eefc3de 100644 --- a/test/fake_modules/typescript/package.json +++ b/test/fake_modules/typescript/package.json @@ -3,6 +3,7 @@ "@org/org-pkg": "0.0.1", "@types/org__org-pkg": "0.0.1", "@types/react": "0.0.1", + "@types/node": "0.0.1", "react": "0.0.1", "ts-dep-1": "0.0.1", "ts-dep-2": "0.0.1", diff --git a/test/spec.js b/test/spec.js index 23628fb1..d3dd719e 100644 --- a/test/spec.js +++ b/test/spec.js @@ -223,6 +223,7 @@ export default [ using: { react: ['component.tsx'], '@types/react': ['component.tsx'], + '@types/node': ['esnext.ts'], '@types/org__org-pkg': ['esnext.ts'], '@org/org-pkg': ['esnext.ts'], 'ts-dep-1': ['index.ts'],