Skip to content

Commit

Permalink
Split @babel/runtime into 2 modules via @babel/runtime-corejs2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 28, 2018
1 parent 034769d commit 6b1d0be
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
15 changes: 15 additions & 0 deletions __tests__/__snapshots__/packageData.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ Object {
}
`;

exports[`upgradeDeps doesn't add runtime-corejs2 if it is already there 1`] = `
Object {
"@babel/runtime": "7.0.0-beta.39",
"@babel/runtime-corejs2": "7.0.0-beta.39",
}
`;

exports[`upgradeDeps splits runtime into runtime and runtime-corejs2 1`] = `
Object {
"@babel/runtime": "7.0.0-beta.39",
"@babel/runtime-corejs2": "7.0.0-beta.39",
}
`;

exports[`upgradeDeps upgrades from earlier v7 version 1`] = `
Object {
"@babel/core": "7.0.0-beta.39",
Expand Down Expand Up @@ -219,6 +233,7 @@ Object {
"@babel/preset-typescript": "7.0.0-beta.39",
"@babel/register": "7.0.0-beta.39",
"@babel/runtime": "7.0.0-beta.39",
"@babel/runtime-corejs2": "7.0.0-beta.39",
"@babel/standalone": "7.0.0-beta.39",
"@babel/template": "7.0.0-beta.39",
"@babel/traverse": "7.0.0-beta.39",
Expand Down
13 changes: 13 additions & 0 deletions __tests__/__snapshots__/upgradeConfig.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`adds corejs to transform-runtime 1`] = `
Object {
"plugins": Array [
Array [
"@babel/plugin-transform-runtime",
Object {
"corejs": 2,
},
],
],
}
`;

exports[`adds flow preset if hasFlow option passed 1`] = `
Object {
"presets": Array [
Expand Down
13 changes: 13 additions & 0 deletions __tests__/packageData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ describe('upgradeDeps', () => {
test('upgrades from earlier v7 version', () => {
expect(upgradeDeps(depsFixtureEarlierBeta, VERSION)).toMatchSnapshot();
});

test('splits runtime into runtime and runtime-corejs2', () => {
expect(upgradeDeps({
"@babel/runtime": "7.0.0-alpha.0",
}, VERSION)).toMatchSnapshot();
});

test("doesn't add runtime-corejs2 if it is already there", () => {
expect(upgradeDeps({
"@babel/runtime": "7.0.0-alpha.0",
"@babel/runtime-corejs2": "7.0.0-alpha.0",
}, VERSION)).toMatchSnapshot();
});
});

test('scripts', async () => {
Expand Down
6 changes: 6 additions & 0 deletions __tests__/upgradeConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@ test("replaces stage presets", () => {

expect(upgradeConfig(config)).toMatchSnapshot();
});

test("adds corejs to transform-runtime", () => {
const config = { "plugins": ["transform-runtime"] };

expect(upgradeConfig(config)).toMatchSnapshot();
});
5 changes: 4 additions & 1 deletion src/packageData.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ const packages = Object.assign(
misc,
);

const latestPackages = new Set(Object.values(packages));
const latestPackages = new Set([
...Object.values(packages),
"@babel/runtime-corejs2",
]);

const stagePresets = Object.create(null);
stagePresets[3] = [
Expand Down
4 changes: 4 additions & 0 deletions src/upgradeDeps.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,9 @@ module.exports = function upgradeDeps(dependencies, version, options = {}) {
}
}

if (dependencies['@babel/runtime'] && !dependencies['@babel/runtime-corejs2']) {
dependencies['@babel/runtime-corejs2'] = version;
}

return dependencies;
}
2 changes: 2 additions & 0 deletions src/upgradeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const updaters = {

"@babel/plugin-proposal-pipeline-operator": define({ proposal: "minimal" }),
"@babel/plugin-syntax-pipeline-operator": define({ proposal: "minimal" }),

"@babel/plugin-transform-runtime": define({ corejs: 2 }),
};

module.exports = function updateOptions(entry) {
Expand Down

0 comments on commit 6b1d0be

Please sign in to comment.