From 60d2a79891cf6dd5d3bdfc0a2bcfecb3c4873c6e Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Thu, 6 Feb 2020 09:57:35 -0800 Subject: [PATCH] fix(typescript): Use builtin extends resolution (#199) --- .gitignore | 1 + packages/typescript/src/options.ts | 6 ------ .../fixtures/tsconfig-extends-module/main.tsx | 3 +++ .../node_modules/shared-config/package.json | 4 ++++ .../node_modules/shared-config/tsconfig.json | 5 +++++ .../tsconfig-extends-module/tsconfig.json | 6 ++++++ packages/typescript/test/test.js | 16 ++++++++++++++++ 7 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 packages/typescript/test/fixtures/tsconfig-extends-module/main.tsx create mode 100644 packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/package.json create mode 100644 packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/tsconfig.json create mode 100644 packages/typescript/test/fixtures/tsconfig-extends-module/tsconfig.json diff --git a/.gitignore b/.gitignore index 7dfe0318f..c4396fb79 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ pnpm-debug.log !packages/node-resolve/test/fixtures/**/node_modules !packages/commonjs/test/**/node_modules +!packages/typescript/test/fixtures/**/node_modules diff --git a/packages/typescript/src/options.ts b/packages/typescript/src/options.ts index 2d8af381a..b76cbfc84 100644 --- a/packages/typescript/src/options.ts +++ b/packages/typescript/src/options.ts @@ -114,12 +114,6 @@ function readTsConfigFile(ts: typeof import('typescript'), tsConfigPath: string) throw Object.assign(Error(), diagnosticToWarning(ts, null, error)); } - const extendedTsConfig: string = config?.extends; - if (extendedTsConfig) { - // Get absolute path of `extends`, starting at basedir of the tsconfig file. - config.extends = resolve(process.cwd(), tsConfigPath, '..', extendedTsConfig); - } - return config || {}; } diff --git a/packages/typescript/test/fixtures/tsconfig-extends-module/main.tsx b/packages/typescript/test/fixtures/tsconfig-extends-module/main.tsx new file mode 100644 index 000000000..d62ec86a9 --- /dev/null +++ b/packages/typescript/test/fixtures/tsconfig-extends-module/main.tsx @@ -0,0 +1,3 @@ +const props = {}; +// @ts-ignore +export default Yo!; diff --git a/packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/package.json b/packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/package.json new file mode 100644 index 000000000..4d7970ea7 --- /dev/null +++ b/packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/package.json @@ -0,0 +1,4 @@ +{ + "name": "shared-config", + "tsconfig": "tsconfig.json" +} diff --git a/packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/tsconfig.json b/packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/tsconfig.json new file mode 100644 index 000000000..0705bf051 --- /dev/null +++ b/packages/typescript/test/fixtures/tsconfig-extends-module/node_modules/shared-config/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "jsx": "react" + } +} diff --git a/packages/typescript/test/fixtures/tsconfig-extends-module/tsconfig.json b/packages/typescript/test/fixtures/tsconfig-extends-module/tsconfig.json new file mode 100644 index 000000000..5222ba6cb --- /dev/null +++ b/packages/typescript/test/fixtures/tsconfig-extends-module/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "shared-config", + "compilerOptions": { + "allowJs": true + } +} diff --git a/packages/typescript/test/test.js b/packages/typescript/test/test.js index 3bba4ca11..3cc168ecc 100644 --- a/packages/typescript/test/test.js +++ b/packages/typescript/test/test.js @@ -347,6 +347,22 @@ test.serial('should support extends property with given tsconfig', async (t) => t.not(usage, -1, 'should contain usage'); }); +test.serial('should support extends property with node resolution', async (t) => { + process.chdir('fixtures/tsconfig-extends-module'); + + const bundle = await rollup({ + input: 'main.tsx', + plugins: [ + typescript() + ], + onwarn + }); + const code = await getCode(bundle, outputOptions); + + const usage = code.includes('React.createElement("span", __assign({}, props), "Yo!")'); + t.true(usage, 'should contain usage'); +}); + test('complies code that uses browser functions', async (t) => { const bundle = await rollup({ input: 'fixtures/dom/main.ts',