Skip to content
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
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"@babel/core": "^7.4.4",
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-transform-regenerator": "^7.4.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.11.0",
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-json": "^4.0.0",
Expand All @@ -60,7 +58,7 @@
"babel-plugin-annotate-pure-calls": "^0.4.0",
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-macros": "^2.6.1",
"babel-plugin-transform-async-to-promises": "^0.8.14",
"babel-plugin-polyfill-regenerator": "^0.0.4",
"babel-plugin-transform-rename-import": "^2.3.0",
"babel-traverse": "^6.26.0",
"babylon": "^6.18.0",
Expand All @@ -86,6 +84,7 @@
"pascal-case": "^3.1.1",
"prettier": "^1.19.1",
"progress-estimator": "^0.2.2",
"regenerator-runtime": "^0.13.7",
"rollup": "^1.32.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-sourcemaps": "^0.5.0",
Expand All @@ -100,7 +99,6 @@
"typescript": "^3.7.3"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.6.0",
"@types/eslint": "^6.1.2",
"@types/fs-extra": "^8.0.0",
"@types/node": "^13.1.0",
Expand Down
15 changes: 3 additions & 12 deletions src/babelPluginTsdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,14 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
replacements,
},
{
name: 'babel-plugin-transform-async-to-promises',
inlineHelpers: true,
externalHelpers: true,
name: 'babel-plugin-polyfill-regenerator',
// don't pollute global env as this is being used in a library
method: 'usage-pure',
},
{
name: '@babel/plugin-proposal-class-properties',
loose: true,
},
{
name: '@babel/plugin-transform-regenerator',
async: false,
},
isTruthy(customOptions.extractErrors) && {
name: './errors/transformErrorMessages',
},
Expand Down Expand Up @@ -114,10 +110,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
presetEnv.options,
{
modules: false,
exclude: merge(
['transform-async-to-generator', 'transform-regenerator'],
(presetEnv.options && presetEnv.options.exclude) || []
),
}
),
],
Expand All @@ -133,7 +125,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
targets: customOptions.targets,
modules: false,
loose: true,
exclude: ['transform-async-to-generator', 'transform-regenerator'],
},
]);

Expand Down
17 changes: 11 additions & 6 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ export async function createRollupConfig(
input: opts.input,
// Tell Rollup which packages to ignore
external: (id: string) => {
if (id === 'babel-plugin-transform-async-to-promises/helpers') {
// bundle in polyfills as TSDX can't (yet) ensure they're installed as deps
if (id.startsWith('regenerator-runtime')) {
return false;
}

return external(id);
},
// Rollup has treeshaking by default, but we can optimize it further...
Expand Down Expand Up @@ -118,11 +120,14 @@ export async function createRollupConfig(
// defaults + .jsx
extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],
}),
opts.format === 'umd' &&
commonjs({
// use a regex to make sure to include eventual hoisted packages
include: /\/node_modules\//,
}),
// all bundled external modules need to be converted from CJS to ESM
commonjs({
// use a regex to make sure to include eventual hoisted packages
include:
opts.format === 'umd'
? /\/node_modules\//
: /\/regenerator-runtime\//,
}),
json(),
{
// Custom plugin that removes shebang from code because newer
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/fixtures/build-default/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import './syntax/optional-chaining';

import './syntax/jsx-import/JSX-import-JSX';

import './syntax/async';
export { testGenerator } from './syntax/generator';

export { foo } from './foo';

export const sum = (a: number, b: number) => {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/fixtures/build-default/src/syntax/async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// regression test for async/await
// code inspired by https://github.com/formium/tsdx/issues/869
(async () => {
await Promise.resolve();
console.log('a side effect to make sure this is output');
Comment thread
agilgur5 marked this conversation as resolved.
})();
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// regression test for generators
export function* testGenerator() {
return yield 'blah';
}
18 changes: 17 additions & 1 deletion test/e2e/tsdx-build-default.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as shell from 'shelljs';

import * as util from '../utils/fixture';
import { execWithCache } from '../utils/shell';
import { execWithCache, grep } from '../utils/shell';

shell.config.silent = false;

Expand Down Expand Up @@ -51,6 +51,22 @@ describe('tsdx build :: zero-config defaults', () => {
expect(output.code).toBe(0);
});

it('should bundle regeneratorRuntime', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);

const matched = grep(/regeneratorRuntime = r/, ['dist/build-default.*.js']);
expect(matched).toBeTruthy();
});

it('should not bundle regeneratorRuntime when targeting Node', () => {
const output = execWithCache('node ../dist/index.js build --target node');
Comment thread
agilgur5 marked this conversation as resolved.
expect(output.code).toBe(0);

const matched = grep(/regeneratorRuntime = r/, ['dist/build-default.*.js']);
expect(matched).toBeFalsy();
});

it('should clean the dist directory before rebuilding', () => {
let output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
Expand Down
3 changes: 0 additions & 3 deletions test/integration/fixtures/build-withBabel/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@ module.exports = {
presets: [
// ensure Babel presets are merged and applied
'./test-babel-preset'
],
plugins: [
['@babel/plugin-transform-runtime', { helpers: false }],
]
}
2 changes: 0 additions & 2 deletions test/integration/fixtures/build-withBabel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export { Title } from './styled';

export { testGenerator } from './generator';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
Expand Down
10 changes: 0 additions & 10 deletions test/integration/tsdx-build-withBabel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ describe('integration :: tsdx build :: .babelrc.js', () => {
expect(matched).toBeFalsy();
});

it('should add an import of regeneratorRuntime', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);

const matched = grep(/@babel\/runtime\/regenerator/, [
'dist/build-withbabel.*.js',
]);
expect(matched).toBeTruthy();
});

it('should merge and apply presets', () => {
const output = execWithCache('node ../dist/index.js build');
expect(output.code).toBe(0);
Expand Down
Loading