diff --git a/src/createRollupConfig.ts b/src/createRollupConfig.ts index cd3c4ccb3..b1610f3d4 100644 --- a/src/createRollupConfig.ts +++ b/src/createRollupConfig.ts @@ -143,6 +143,7 @@ export async function createRollupConfig( compilerOptions: { sourceMap: true, declaration: true, + declarationDir: paths.appDist, jsx: 'react', }, }, @@ -153,9 +154,8 @@ export async function createRollupConfig( }, }, check: opts.transpileOnly === false, - useTsconfigDeclarationDir: Boolean( - tsconfigJSON?.compilerOptions?.declarationDir - ), + // declarationDir is used internally above as a default + useTsconfigDeclarationDir: true, }), babelPluginTsdx({ exclude: 'node_modules/**', diff --git a/src/index.ts b/src/index.ts index 0c2532044..09d0d384d 100755 --- a/src/index.ts +++ b/src/index.ts @@ -99,16 +99,6 @@ async function getInputs( return concatAllArray(inputs); } -async function moveTypes() { - try { - // Move the typescript types to the base of the ./dist folder - await fs.copy(paths.appDist + '/src', paths.appDist, { - overwrite: true, - }); - await fs.remove(paths.appDist + '/src'); - } catch (e) {} -} - prog .version(pkg.version) .command('create ') @@ -371,8 +361,6 @@ prog `); try { - await moveTypes(); - if (firstTime && opts.onFirstSuccess) { firstTime = false; run(opts.onFirstSuccess); @@ -422,7 +410,6 @@ prog async (inputOptions: RollupOptions & { output: OutputOptions }) => { let bundle = await rollup(inputOptions); await bundle.write(inputOptions.output); - await moveTypes(); } ) .catch((e: any) => { diff --git a/test/fixtures/build-default/tsconfig.json b/test/fixtures/build-default/tsconfig.json index d8ff04c12..88855c679 100644 --- a/test/fixtures/build-default/tsconfig.json +++ b/test/fixtures/build-default/tsconfig.json @@ -3,6 +3,7 @@ "module": "ESNext", "lib": ["dom", "esnext"], "declaration": true, + "declarationMap": true, "sourceMap": true, "rootDir": "./", "strict": true, diff --git a/test/tests/tsdx-build.test.js b/test/tests/tsdx-build.test.js index b38887193..f4b7b6a7c 100644 --- a/test/tests/tsdx-build.test.js +++ b/test/tests/tsdx-build.test.js @@ -3,6 +3,8 @@ */ const shell = require('shelljs'); +const fs = require('fs-extra'); + const util = require('../fixtures/util'); shell.config.silent = false; @@ -42,6 +44,17 @@ describe('tsdx build', () => { expect(lib.foo()).toBe('bar'); }); + it('should create declarationMap files (*.d.ts.map) correctly', async () => { + util.setupStageWithFixture(stageName, 'build-default'); + + shell.exec('node ../dist/index.js build'); + + expect(shell.test('-f', 'dist/index.d.ts.map')).toBeTruthy(); + + const dtsmap = await fs.readJSON('dist/index.d.ts.map'); + expect(dtsmap.sources[0]).toBe('../src/index.ts'); + }); + it('should clean the dist directory before rebuilding', () => { util.setupStageWithFixture(stageName, 'build-default'); @@ -102,7 +115,7 @@ describe('tsdx build', () => { expect(code).toBe(0); }); - it('should use the declarationDir when set in tsconfig', () => { + it('should use the declarationDir when set in tsconfig', async () => { util.setupStageWithFixture(stageName, 'build-withTsconfig'); const output = shell.exec('node ../dist/index.js build --format esm,cjs'); @@ -120,6 +133,9 @@ describe('tsdx build', () => { expect(shell.test('-f', 'typings/index.d.ts')).toBeTruthy(); expect(shell.test('-f', 'typings/index.d.ts.map')).toBeTruthy(); + const dtsmap = await fs.readJSON('typings/index.d.ts.map'); + expect(dtsmap.sources[0]).toBe('../src/index.ts'); + expect(output.code).toBe(0); });