Skip to content

Commit

Permalink
Upgrade to webpack@4 and babel@7 (fusionjs#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGrandon authored Mar 17, 2018
1 parent cc67425 commit 88fe6cb
Show file tree
Hide file tree
Showing 43 changed files with 1,636 additions and 1,658 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assetUrl } from 'fusion-core';
import { assetUrl as assetUrlOther } from 'assetUrl';

const path = './test';
assetUrl(require('__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!./path'));
assetUrl(require("__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!./path"));
assetUrlOther(path);
assetUrl(require('__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!./path'));
assetUrl(require("__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!./path"));
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assetUrl as frameworkAssetUrl } from 'fusion-core';
import assetUrl from 'assetURL';

assetUrl('./path');
frameworkAssetUrl(require('__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!./path'));
frameworkAssetUrl(require("__SECRET_FILE_LOADER__?storeFile=true&storeFileTarget=node!./path"));
2 changes: 1 addition & 1 deletion build/babel-plugins/babel-plugin-asseturl/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-env node */
const fs = require('fs');
const test = require('tape');
const {transformFileSync} = require('babel-core');
const {transformFileSync} = require('@babel/core');
const plugin = require('../');

test('import assetURL', t => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { chunkId } from 'fusion-core';
import { chunkId as chunkIdOther } from 'chunkId';

const path = './test';
chunkId(require('__SECRET_CHUNK_ID_LOADER__!./path'));
chunkId(require("__SECRET_CHUNK_ID_LOADER__!./path"));
chunkIdOther(path);
chunkId(require('__SECRET_CHUNK_ID_LOADER__!./path'));
chunkId(require("__SECRET_CHUNK_ID_LOADER__!./path"));
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { chunkId as frameworkChunkId } from 'fusion-core';
import chunkId from 'chunkId';

chunkId('./path');
frameworkChunkId(require('__SECRET_CHUNK_ID_LOADER__!./path'));
frameworkChunkId(require("__SECRET_CHUNK_ID_LOADER__!./path"));
2 changes: 1 addition & 1 deletion build/babel-plugins/babel-plugin-chunkid/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-env node */
const fs = require('fs');
const test = require('tape');
const {transformFileSync} = require('babel-core');
const {transformFileSync} = require('@babel/core');
const plugin = require('../');

test('import assetURL', t => {
Expand Down
2 changes: 1 addition & 1 deletion build/babel-plugins/babel-plugin-experimentation/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
/* eslint-env node */
const template = require('babel-template');
const template = require('@babel/template').default;
const createModuleVisitor = require('../babel-plugin-utils/visit-named-module');

const PACKAGE_NAME = [
Expand Down
11 changes: 9 additions & 2 deletions build/babel-plugins/babel-plugin-experimentation/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ test('withExperiment hoc', t => {
return <div>Hello World</div>;
}
export default withExperiment({ experimentName: 'test-experiment', onError: () => {} })(Component);
export default withExperiment({
experimentName: 'test-experiment',
onError: () => {}
})(Component);
`
);
t.equal(result, expected);
Expand Down Expand Up @@ -55,7 +58,11 @@ test('withExperiment hoc, manualInclusionLogging', t => {
return <div>Hello World</div>;
}
export default withExperiment({ experimentName: 'test-experiment', onError: () => {}, manualInclusionLogging: true })(Component);
export default withExperiment({
experimentName: 'test-experiment',
onError: () => {},
manualInclusionLogging: true
})(Component);
`
);
t.equal(result, expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */
const {transform} = require('babel-core');
const {transform} = require('@babel/core');
const plugin = require('../');
const babelPluginSyntaxJsx = require('babel-plugin-syntax-jsx');
const babelPluginSyntaxJsx = require('@babel/plugin-syntax-jsx');

module.exports = function doTransform(inputString) {
return (
Expand Down
3 changes: 2 additions & 1 deletion build/babel-plugins/babel-plugin-i18n/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
/* eslint-env node */
const template = require('babel-template');
const template = require('@babel/template').default;

const createModuleVisitor = require('../babel-plugin-utils/visit-named-module');

const PACKAGE_NAME = ['fusion-plugin-i18n-react', 'fusion-plugin-i18n-preact'];
Expand Down
2 changes: 1 addition & 1 deletion build/babel-plugins/babel-plugin-i18n/test/get-expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ const sharedExpectedContent = require('./shared-expected-content.js');

module.exports = function getExpected(inputString, includeShared = true) {
const sharedContent = includeShared ? '\n' + sharedExpectedContent() : '';
return (stripIndent(inputString).trim() + sharedContent).replace(/"/g, "'");
return (stripIndent(inputString) + sharedContent).replace(/"/g, "'");
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ const stripIndent = require('strip-indent');

module.exports = () =>
stripIndent(
`
import { chunkId as _chunkId } from 'fusion-core';
`import { chunkId as _chunkId } from 'fusion-core';
const _CHUNKIDS_ID = _chunkId('fake-file.js');
const _CHUNKIDS_ID = _chunkId('fake-file.js');
import _singleton from 'fusion-plugin-i18n-react/singleton';
import _singleton from 'fusion-plugin-i18n-react/singleton';
_singleton.add('fake-file.js', _CHUNKIDS_ID, _translations);
_singleton.add('fake-file.js', _CHUNKIDS_ID, _translations);
if (module.hot) {
module.hot.dispose(() => {
_singleton.dispose('fake-file.js', _CHUNKIDS_ID, _translations);
});
}
if (module.hot) {
module.hot.dispose(() => {
_singleton.dispose('fake-file.js', _CHUNKIDS_ID, _translations);
});
}
`
).trim();
4 changes: 2 additions & 2 deletions build/babel-plugins/babel-plugin-i18n/test/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */
const {transform} = require('babel-core');
const {transform} = require('@babel/core');
const plugin = require('../');
const babelPluginSyntaxJsx = require('babel-plugin-syntax-jsx');
const babelPluginSyntaxJsx = require('@babel/plugin-syntax-jsx');

module.exports = function doTransform(inputString) {
return (
Expand Down
22 changes: 9 additions & 13 deletions build/babel-plugins/babel-plugin-i18n/test/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ test('translation component', t => {
`
);
const expected = getExpected(
`
var _translations = ['foo'];
import { Translate } from 'fusion-plugin-i18n-react';
`var _translations = ['foo'];
import { Translate } from 'fusion-plugin-i18n-react';
function Component() {
return <Translate id='foo' />;
}
`
function Component() {
return <Translate id='foo' />;
}\n`
);
t.equal(result, expected);
t.end();
Expand All @@ -41,13 +39,11 @@ test('no translations', t => {
`
);
const expected = getExpected(
`
import { Translate } from 'fusion-plugin-i18n-react';
`import { Translate } from 'fusion-plugin-i18n-react';
function Component() {
return <div>foo</div>;
}
`,
function Component() {
return <div>foo</div>;
}`,
false
);
t.equal(result, expected);
Expand Down
38 changes: 16 additions & 22 deletions build/babel-plugins/babel-plugin-i18n/test/with-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ test('withTranslations hoc', t => {
`
);
const expected = getExpected(
`
var _translations = ['foo'];
import { withTranslations } from 'fusion-plugin-i18n-react';
`var _translations = ['foo'];
import { withTranslations } from 'fusion-plugin-i18n-react';
function Component() {
return <div>Hello World</div>;
}
function Component() {
return <div>Hello World</div>;
}
export default withTranslations(['foo'])(Component);
`
export default withTranslations(['foo'])(Component);`
);
t.equal(result, expected);
t.end();
Expand All @@ -47,16 +45,14 @@ test('withTranslations hoc with multiple translations', t => {
`
);
const expected = getExpected(
`
var _translations = ['foo', 'baz'];
import { withTranslations } from 'fusion-plugin-i18n-react';
`var _translations = ['foo', 'baz'];
import { withTranslations } from 'fusion-plugin-i18n-react';
function Component() {
return <div>Hello World</div>;
}
function Component() {
return <div>Hello World</div>;
}
export default withTranslations(['foo', 'baz'])(Component);
`
export default withTranslations(['foo', 'baz'])(Component);`
);
t.equal(result, expected);
t.end();
Expand Down Expand Up @@ -91,13 +87,11 @@ test('withTranslations hoc with no translations', t => {
`
);
const expected = getExpected(
`
import { withTranslations } from 'fusion-plugin-i18n-react';
`import { withTranslations } from 'fusion-plugin-i18n-react';
function Component() {
return <div>foo</div>;
}
`,
function Component() {
return <div>foo</div>;
}`,
false
);
t.equal(result, expected);
Expand Down
2 changes: 1 addition & 1 deletion build/babel-plugins/babel-plugin-sw/test/transform.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {transform} = require('babel-core');
const {transform} = require('@babel/core');
const plugin = require('../');
/* eslint-env node */
module.exports = function doTransform(inputString) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { syncChunkIds } from 'fusion-core';
import { syncChunkIds as otherSyncChunkIds } from 'syncChunkIds';

syncChunkIds(require('__SECRET_SYNC_CHUNK_IDS_LOADER__!'));
otherSyncChunkIds();
syncChunkIds(require("__SECRET_SYNC_CHUNK_IDS_LOADER__!"));
otherSyncChunkIds();
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { syncChunkIds as frameworkSyncChunkIds } from 'fusion-core';
import syncChunkIds from 'syncChunkIds';

frameworkSyncChunkIds(require('__SECRET_SYNC_CHUNK_IDS_LOADER__!'));
syncChunkIds();
frameworkSyncChunkIds(require("__SECRET_SYNC_CHUNK_IDS_LOADER__!"));
syncChunkIds();
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-env node */
const fs = require('fs');
const test = require('tape');
const {transformFileSync} = require('babel-core');
const {transformFileSync} = require('@babel/core');
const plugin = require('../');

test('import syncChunkIds', t => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { syncChunkPaths } from 'fusion-core';
import { syncChunkPaths as otherSyncChunkPaths } from 'syncChunkPaths';

syncChunkPaths(require('__SECRET_SYNC_CHUNK_PATHS_LOADER__!'));
otherSyncChunkPaths();
syncChunkPaths(require("__SECRET_SYNC_CHUNK_PATHS_LOADER__!"));
otherSyncChunkPaths();
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { syncChunkPaths as frameworkSyncChunkPaths } from 'fusion-core';
import syncChunkPaths from 'syncChunkPaths';

frameworkSyncChunkPaths(require('__SECRET_SYNC_CHUNK_PATHS_LOADER__!'));
syncChunkPaths();
frameworkSyncChunkPaths(require("__SECRET_SYNC_CHUNK_PATHS_LOADER__!"));
syncChunkPaths();
20 changes: 19 additions & 1 deletion build/babel-plugins/babel-plugin-utils/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
/* eslint-env node */
const test = require('tape');
const {transform} = require('babel-core');
const {transform} = require('@babel/core');
const createNamedModuleVisitor = require('../visit-named-module');
const replaceImportDeclaration = require('../replace-import-declaration');

Expand All @@ -17,6 +17,24 @@ function createTestPlugin(handler) {
};
}

test('with flow types', t => {
t.plan(2);

const plugin = createTestPlugin((types, context, refs) => {
t.equal(refs.length, 1);
t.ok(types.isCallExpression(refs[0].parent));
});

transform(
`
import {foo} from 'bar';
import type {footype} from 'bar';
let baz: string = foo();
`,
{plugins: [plugin, require('@babel/plugin-transform-flow-strip-types')]}
);
});

test('import case', t => {
t.plan(2);

Expand Down
3 changes: 3 additions & 0 deletions build/babel-plugins/babel-plugin-utils/visit-named-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function createNamedModuleVisitor(
path.get('specifiers').forEach(specifier => {
const localPath = specifier.get('local');
const localName = localPath.node.name;
if (!localPath.scope.bindings[localName]) {
return;
}
const refPaths = localPath.scope.bindings[localName].referencePaths;
if (t.isImportSpecifier(specifier)) {
// import {moduleName} from 'packageName';
Expand Down
12 changes: 7 additions & 5 deletions build/babel-preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ module.exports = function buildPreset(
return {
presets: [
[
require('babel-preset-env'),
require('@babel/preset-env'),
{
targets: targets,
modules: modules,
exclude: ['transform-regenerator', 'transform-async-to-generator'],
},
],
require('babel-preset-react'),
require('@babel/preset-react'),
require('@babel/preset-flow'),
],
plugins: [
require('babel-plugin-transform-async-generator-functions'),
require('babel-plugin-transform-class-properties'),
require('@babel/plugin-transform-flow-strip-types'),
require('@babel/plugin-proposal-async-generator-functions'),
require('@babel/plugin-proposal-class-properties'),
[
require('babel-plugin-transform-object-rest-spread'),
require('@babel/plugin-proposal-object-rest-spread'),
{
useBuiltIns: true,
},
Expand Down
Loading

0 comments on commit 88fe6cb

Please sign in to comment.