Skip to content

Commit 51d8ed9

Browse files
martinbigiofacebook-github-bot-5
authored andcommitted
Move HMR to internal transform
Summary: public We want to support Hot Loading on the packager itself instead of on the transformer. This will allow us to enable it on OSS (and for any scripting language, yay!). For now to enable Hot Loading the packager's internals transforms need to be manually enabled (start packager with `--enable-internal-transforms`). I think the internal pipeline should always be enabled as it doesn't affect performance if there're no transforms and the user can disable Hot Loading through the setting on the app though. I'll tweak this on a follow up commit. Reviewed By: vjeux Differential Revision: D2801343 fb-gh-sync-id: 563984d77b10c3925fda6fd5616b814cdbea2c66
1 parent d875aac commit 51d8ed9

File tree

8 files changed

+27
-37
lines changed

8 files changed

+27
-37
lines changed

local-cli/server/runServer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ function getAppMiddleware(args, config) {
6868
cacheVersion: '3',
6969
getTransformOptionsModulePath: config.getTransformOptionsModulePath,
7070
transformModulePath: transformerPath,
71-
enableInternalTransforms: args['enable-internal-transforms'],
7271
assetRoots: args.assetRoots,
7372
assetExts: ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp'],
7473
resetCache: args.resetCache || args['reset-cache'],

local-cli/server/server.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ function _server(argv, config, resolve, reject) {
5353
type: 'string',
5454
default: require.resolve('../../packager/transformer'),
5555
description: 'Specify a custom transformer to be used (absolute path)'
56-
}, {
57-
command: 'enable-internal-transforms',
58-
type: 'boolean',
59-
default: false
6056
}, {
6157
command: 'resetCache',
6258
description: 'Removes cached files',

packager/react-packager/src/Bundler/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ const validateOpts = declareOpts({
5656
type:'string',
5757
required: false,
5858
},
59-
enableInternalTransforms: {
60-
type: 'boolean',
61-
default: false,
62-
},
6359
nonPersistent: {
6460
type: 'boolean',
6561
default: false,
@@ -135,7 +131,6 @@ class Bundler {
135131
blacklistRE: opts.blacklistRE,
136132
cache: this._cache,
137133
transformModulePath: opts.transformModulePath,
138-
enableInternalTransforms: opts.enableInternalTransforms,
139134
});
140135

141136
this._projectRoots = opts.projectRoots;

packager/react-packager/src/JSTransformer/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ const validateOpts = declareOpts({
5353
type: 'number',
5454
default: DEFAULT_MAX_CALL_TIME,
5555
},
56-
enableInternalTransforms: {
57-
type: 'boolean',
58-
default: false,
59-
},
6056
});
6157

6258
class Transformer {
@@ -65,7 +61,6 @@ class Transformer {
6561

6662
this._cache = opts.cache;
6763
this._transformModulePath = opts.transformModulePath;
68-
this._enableInternalTransforms = opts.enableInternalTransforms;
6964

7065
if (opts.transformModulePath != null) {
7166
this._workers = workerFarm({
@@ -111,7 +106,6 @@ class Transformer {
111106
options: {
112107
...options,
113108
externalTransformModulePath: this._transformModulePath,
114-
enableInternalTransforms: this._enableInternalTransforms,
115109
},
116110
}).then(res => {
117111
if (res.error) {

packager/react-packager/src/JSTransformer/worker.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function internalTransforms(sourceCode, filename, options) {
2222
filename: filename,
2323
sourceFileName: filename,
2424
sourceMaps: false,
25-
plugins: Transforms.getAll()
25+
plugins: Transforms.getAll(options)
2626
});
2727

2828
return {
@@ -37,16 +37,11 @@ function onExternalTransformDone(data, callback, error, externalOutput) {
3737
return;
3838
}
3939

40-
var result;
41-
if (data.options.enableInternalTransforms) {
42-
result = internalTransforms(
43-
externalOutput.code,
44-
externalOutput.filename,
45-
data.options
46-
);
47-
} else {
48-
result = externalOutput;
49-
}
40+
var result = internalTransforms(
41+
externalOutput.code,
42+
externalOutput.filename,
43+
data.options
44+
);
5045

5146
callback(null, result);
5247
}

packager/react-packager/src/Server/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ const validateOpts = declareOpts({
5252
type: 'boolean',
5353
default: false,
5454
},
55-
enableInternalTransforms: {
56-
type: 'boolean',
57-
default: false,
58-
},
5955
assetRoots: {
6056
type: 'array',
6157
required: false,

packager/react-packager/src/transforms/index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,26 @@
88
*/
99
'use strict';
1010

11-
exports.getAll = function() {
12-
return [
13-
require('./babel-plugin-system-import'),
14-
];
11+
exports.getAll = function(options) {
12+
var plugins = [];
13+
if (options.hot) {
14+
plugins = plugins.concat([
15+
[
16+
'react-transform',
17+
{
18+
transforms: [{
19+
transform: 'react-transform-hmr/lib/index.js',
20+
imports: ['React'],
21+
locals: ['module'],
22+
}]
23+
},
24+
],
25+
'transform-es2015-block-scoping',
26+
'transform-es2015-constants',
27+
['transform-es2015-modules-commonjs', {strict: false, allowTopLevelThis: true}],
28+
]);
29+
}
30+
31+
return plugins;
1532
};
1633

packager/transformer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ function transform(src, filename, options) {
5454
return plugin;
5555
});
5656

57-
config.plugins = config.plugins.concat(ReactPackager.getTransforms());
58-
5957
const result = babel.transform(src, Object.assign({}, babelRC, config));
6058

6159
return {

0 commit comments

Comments
 (0)