Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable useTsconfigDeclarationDir if declarationDir #468

Merged
merged 8 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export async function createRollupConfig(
},
},
check: !opts.transpileOnly,
useTsconfigDeclarationDir: Boolean(
tsconfigJSON?.compilerOptions?.declarationDir
),
}),
babelPluginTsdx({
exclude: 'node_modules/**',
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ here are some fixtures for manual testing things we don't have Jest tests for.
- `build-default` focuses on our zero config defaults
- `build-invalid` lets us check what happens when we have invalid builds due to type errors
- `build-withConfig` lets us check that `tsdx.config.js` works as expected
- `build-withTsconfig` lets us check that `tsconfig.json` options are correctly used
7 changes: 7 additions & 0 deletions test/fixtures/build-withTsconfig/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"scripts": {
"build": "tsdx build"
},
"name": "build-withtsconfig",
"license": "MIT"
}
6 changes: 6 additions & 0 deletions test/fixtures/build-withTsconfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
}
return a + b;
};
7 changes: 7 additions & 0 deletions test/fixtures/build-withTsconfig/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);
});
});
30 changes: 30 additions & 0 deletions test/fixtures/build-withTsconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compilerOptions": {
"module": "ESNext",
"lib": ["dom", "esnext"],
"declaration": true,
"declarationDir": "typings",
"declarationMap": true,
"sourceMap": true,
"rootDir": "./src",
etienne-dldc marked this conversation as resolved.
Show resolved Hide resolved
"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": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"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-withTsconfig');

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-withtsconfig.cjs.development.js')
).toBeTruthy();
expect(
shell.test('-f', 'dist/build-withtsconfig.cjs.production.min.js')
).toBeTruthy();
expect(shell.test('-f', 'dist/build-withtsconfig.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