Skip to content

Commit

Permalink
Enable useTsconfigDeclarationDir if declarationDir
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-dldc committed Jan 29, 2020
1 parent 95ff6da commit d4a884c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export async function createRollupConfig(
},
},
check: opts.transpileOnly === false,
useTsconfigDeclarationDir: Boolean(
tsconfigJSON?.compilerOptions?.declarationDir
),
}),
babelPluginTsdx({
exclude: 'node_modules/**',
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/build-declarationDir/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"scripts": {
"build": "tsdx build"
},
"name": "build-declarationdir",
"license": "MIT"
}
1 change: 1 addition & 0 deletions test/fixtures/build-declarationDir/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = () => 'bar';
11 changes: 11 additions & 0 deletions test/fixtures/build-declarationDir/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import './syntax/nullish-coalescing';
import './syntax/optional-chaining';

export { foo } from './foo';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
}
return a + b;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing

const bar = () => {};
const foo = false;
export const x = foo ?? bar();
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining

export const foo = (foo?: { bar: string }) => foo?.bar || 'bar';
7 changes: 7 additions & 0 deletions test/fixtures/build-declarationDir/test/blah.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from '../src';

describe('fuck', () => {
it('works', () => {
expect(sum(1, 1)).toEqual(2);
});
});
28 changes: 28 additions & 0 deletions test/fixtures/build-declarationDir/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"target": "es5",
"module": "ESNext",
"lib": ["dom", "esnext"],
"declaration": true,
"declarationDir": "typings",
"declarationMap": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": ".",
"jsx": "react",
"esModuleInterop": true
},
"include": ["src", "types"]
}
21 changes: 21 additions & 0 deletions test/tests/tsdx-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ describe('tsdx build', () => {
expect(code).toBe(0);
});

it('should use the declarationDir when set in tsconfig', () => {
util.setupStageWithFixture(stageName, 'build-declarationDir');

const output = shell.exec('node ../dist/index.js build --format esm,cjs');

expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
shell.test('-f', 'dist/build-declarationdir.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-declarationdir.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-declarationdir.esm.js')).toBeTruthy();

expect(shell.test('-f', 'dist/index.d.ts')).toBeFalsy();
expect(shell.test('-f', 'typings/index.d.ts')).toBeTruthy();
expect(shell.test('-f', 'typings/index.d.ts.map')).toBeTruthy();

expect(output.code).toBe(0);
});

afterEach(() => {
util.teardownStage(stageName);
});
Expand Down

0 comments on commit d4a884c

Please sign in to comment.