Skip to content

Commit

Permalink
Fix TS failing if module is set to CommonJS (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Jun 1, 2020
1 parent a71918b commit c8b46cf
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ function createConfig(options, entry, format, writeMeta) {
tsconfig: options.tsconfig,
tsconfigOverride: {
compilerOptions: {
module: 'ESNext',
target: 'esnext',
},
},
Expand Down
62 changes: 62 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2514,3 +2514,65 @@ exports[`fixtures build ts-mixed-exports with microbundle 7`] = `
//# sourceMappingURL=ts-mixed-exports.umd.js.map
"
`;
exports[`fixtures build ts-module with microbundle 1`] = `
"Used script: microbundle
Directory tree:
ts-module
dist
foo.d.ts
index.d.ts
ts-module.esm.js
ts-module.esm.js.map
ts-module.js
ts-module.js.map
ts-module.umd.js
ts-module.umd.js.map
node_modules
package.json
src
foo.ts
index.ts
tsconfig.json
Build \\"tsModule\\" to dist:
59 B: ts-module.js.gz
42 B: ts-module.js.br
65 B: ts-module.esm.js.gz
49 B: ts-module.esm.js.br
168 B: ts-module.umd.js.gz
128 B: ts-module.umd.js.br"
`;
exports[`fixtures build ts-module with microbundle 2`] = `8`;
exports[`fixtures build ts-module with microbundle 3`] = `
"export declare function foo(): string;
"
`;
exports[`fixtures build ts-module with microbundle 4`] = `
"export declare function foobar(): string;
"
`;
exports[`fixtures build ts-module with microbundle 5`] = `
"function o(){return\\"foobar\\"}export{o as foobar};
//# sourceMappingURL=ts-module.esm.js.map
"
`;
exports[`fixtures build ts-module with microbundle 6`] = `
"exports.foobar=function(){return\\"foobar\\"};
//# sourceMappingURL=ts-module.js.map
"
`;
exports[`fixtures build ts-module with microbundle 7`] = `
"!function(e,o){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?o(exports):\\"function\\"==typeof define&&define.amd?define([\\"exports\\"],o):o((e=e||self).tsModule={})}(this,function(e){e.foobar=function(){return\\"foobar\\"}});
//# sourceMappingURL=ts-module.umd.js.map
"
`;
3 changes: 3 additions & 0 deletions test/fixtures/ts-module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "ts-module"
}
3 changes: 3 additions & 0 deletions test/fixtures/ts-module/src/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo() {
return 'foo';
}
5 changes: 5 additions & 0 deletions test/fixtures/ts-module/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { foo } from './foo';

export function foobar() {
return foo() + 'bar';
}
5 changes: 5 additions & 0 deletions test/fixtures/ts-module/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "CommonJS"
}
}

0 comments on commit c8b46cf

Please sign in to comment.