@parcel/transformer-react-refresh-wrap 2.0.0-nightly.92 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ReactRefreshWrapTransformer.js +40 -107
- package/lib/helpers/helpers.js +47 -38
- package/package.json +11 -13
- package/src/ReactRefreshWrapTransformer.js +35 -106
- package/src/helpers/helpers.js +53 -46
|
@@ -5,138 +5,71 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
_path = function () {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _utils = require("@parcel/utils");
|
|
15
|
-
|
|
16
|
-
var _sourceMap = _interopRequireDefault(require("@parcel/source-map"));
|
|
17
|
-
|
|
18
|
-
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
19
|
-
|
|
20
|
-
var _parser = require("@babel/parser");
|
|
21
|
-
|
|
22
|
-
var _template = _interopRequireDefault(require("@babel/template"));
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
23
17
|
|
|
24
|
-
|
|
18
|
+
function _plugin() {
|
|
19
|
+
const data = require("@parcel/plugin");
|
|
25
20
|
|
|
26
|
-
|
|
21
|
+
_plugin = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
29
27
|
|
|
30
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
29
|
|
|
32
|
-
const WRAPPER = _path.default.join(__dirname, 'helpers', 'helpers.js');
|
|
33
|
-
|
|
34
|
-
const wrapper = (0, _template.default)(`
|
|
35
|
-
var helpers = require(%%helper%%);
|
|
36
|
-
var prevRefreshReg = window.$RefreshReg$;
|
|
37
|
-
var prevRefreshSig = window.$RefreshSig$;
|
|
38
|
-
helpers.prelude(module);
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
%%module%%
|
|
42
|
-
helpers.postlude(module);
|
|
43
|
-
} finally {
|
|
44
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
45
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
46
|
-
}
|
|
47
|
-
`);
|
|
48
|
-
|
|
49
30
|
function shouldExclude(asset, options) {
|
|
50
|
-
return !asset.isSource || !options.
|
|
31
|
+
return !asset.isSource || !options.hmrOptions || !asset.env.isBrowser() || asset.env.isWorker() || asset.env.isWorklet() || options.mode !== 'development' || !asset.getDependencies().find(v => v.specifier === 'react' || v.specifier === 'react/jsx-runtime');
|
|
51
32
|
}
|
|
52
33
|
|
|
53
|
-
var _default = new _plugin.Transformer({
|
|
54
|
-
|
|
55
|
-
ast
|
|
56
|
-
}) {
|
|
57
|
-
return ast.type === 'babel' && _semver.default.satisfies(ast.version, '^7.0.0');
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
async parse({
|
|
34
|
+
var _default = new (_plugin().Transformer)({
|
|
35
|
+
async transform({
|
|
61
36
|
asset,
|
|
62
37
|
options
|
|
63
38
|
}) {
|
|
64
39
|
if (shouldExclude(asset, options)) {
|
|
65
|
-
return
|
|
40
|
+
return [asset];
|
|
66
41
|
}
|
|
67
42
|
|
|
43
|
+
let wrapperPath = `@parcel/transformer-react-refresh-wrap/${_path().default.basename(__dirname)}/helpers/helpers.js`;
|
|
68
44
|
let code = await asset.getCode();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
allowReturnOutsideFunction: true,
|
|
76
|
-
strictMode: false,
|
|
77
|
-
sourceType: 'module',
|
|
78
|
-
plugins: ['exportDefaultFrom', 'exportNamespaceFrom', 'dynamicImport']
|
|
79
|
-
})
|
|
80
|
-
};
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
transform({
|
|
84
|
-
asset,
|
|
85
|
-
options
|
|
86
|
-
}) {
|
|
87
|
-
let ast = asset.ast;
|
|
45
|
+
let map = await asset.getMap();
|
|
46
|
+
let name = `$parcel$ReactRefreshHelpers$${asset.id.slice(-4)}`;
|
|
47
|
+
code = `var ${name} = require(${JSON.stringify(wrapperPath)});
|
|
48
|
+
var prevRefreshReg = window.$RefreshReg$;
|
|
49
|
+
var prevRefreshSig = window.$RefreshSig$;
|
|
50
|
+
${name}.prelude(module);
|
|
88
51
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
52
|
+
try {
|
|
53
|
+
${code}
|
|
54
|
+
${name}.postlude(module);
|
|
55
|
+
} finally {
|
|
56
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
57
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
58
|
+
}`;
|
|
59
|
+
asset.setCode(code);
|
|
92
60
|
|
|
93
|
-
|
|
61
|
+
if (map) {
|
|
62
|
+
map.offsetLines(1, 6);
|
|
63
|
+
asset.setMap(map);
|
|
64
|
+
} // The JSTransformer has already run, do it manually
|
|
94
65
|
|
|
95
|
-
if (!wrapperPath.startsWith('.')) {
|
|
96
|
-
wrapperPath = './' + wrapperPath;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
ast.program.program.body = wrapper({
|
|
100
|
-
helper: t.stringLiteral(wrapperPath),
|
|
101
|
-
module: ast.program.program.body
|
|
102
|
-
});
|
|
103
|
-
ast.isDirty = true; // The JSTransformer has already run, do it manually
|
|
104
66
|
|
|
105
67
|
asset.addDependency({
|
|
106
|
-
|
|
68
|
+
specifier: wrapperPath,
|
|
69
|
+
specifierType: 'esm',
|
|
70
|
+
resolveFrom: __filename
|
|
107
71
|
});
|
|
108
72
|
return [asset];
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
async generate({
|
|
112
|
-
asset,
|
|
113
|
-
options
|
|
114
|
-
}) {
|
|
115
|
-
let code = await asset.getCode();
|
|
116
|
-
let res = {
|
|
117
|
-
code
|
|
118
|
-
};
|
|
119
|
-
let ast = asset.ast;
|
|
120
|
-
|
|
121
|
-
if (ast && ast.isDirty !== false) {
|
|
122
|
-
let sourceFileName = (0, _utils.relativeUrl)(options.projectRoot, asset.filePath);
|
|
123
|
-
let generated = (0, _generator.default)(ast.program, {
|
|
124
|
-
sourceMaps: options.sourceMaps,
|
|
125
|
-
sourceFileName: sourceFileName
|
|
126
|
-
}, code);
|
|
127
|
-
res.code = generated.code; // $FlowFixMe...
|
|
128
|
-
|
|
129
|
-
res.map = new _sourceMap.default(generated.rawMappings, {
|
|
130
|
-
[sourceFileName]: null
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (asset.meta.globals && asset.meta.globals.size > 0) {
|
|
135
|
-
res.code = Array.from(asset.meta.globals.values()).map(g => g ? g.code : '').join('\n') + '\n' + res.code;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
delete asset.meta.globals;
|
|
139
|
-
return res;
|
|
140
73
|
}
|
|
141
74
|
|
|
142
75
|
});
|
package/lib/helpers/helpers.js
CHANGED
|
@@ -36,43 +36,46 @@ module.exports.prelude = function (module) {
|
|
|
36
36
|
module.exports.postlude = function (module) {
|
|
37
37
|
if (isReactRefreshBoundary(module.exports)) {
|
|
38
38
|
registerExportsForReactRefresh(module);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var prevExports = module.hot.data.prevExports;
|
|
44
|
-
var nextExports = module.exports; // Since we just executed the code for it, it's possible
|
|
45
|
-
// that the new exports make it ineligible for being a boundary.
|
|
46
|
-
|
|
47
|
-
var isNoLongerABoundary = !isReactRefreshBoundary(nextExports); // It can also become ineligible if its exports are incompatible
|
|
48
|
-
// with the previous exports.
|
|
49
|
-
// For example, if you add/remove/change exports, we'll want
|
|
50
|
-
// to re-execute the importing modules, and force those components
|
|
51
|
-
// to re-render. Similarly, if you convert a class component
|
|
52
|
-
// to a function, we want to invalidate the boundary.
|
|
53
|
-
|
|
54
|
-
var didInvalidate = shouldInvalidateReactRefreshBoundary(prevExports, nextExports);
|
|
55
|
-
|
|
56
|
-
if (isNoLongerABoundary || didInvalidate) {
|
|
57
|
-
// We'll be conservative. The only case in which we won't do a full
|
|
58
|
-
// reload is if all parent modules are also refresh boundaries.
|
|
59
|
-
// In that case we'll add them to the current queue.
|
|
60
|
-
var parents = getParents();
|
|
61
|
-
|
|
62
|
-
if (parents.length === 0) {
|
|
63
|
-
// Looks like we bubbled to the root. Can't recover from that.
|
|
39
|
+
|
|
40
|
+
if (module.hot) {
|
|
41
|
+
module.hot.dispose(function (data) {
|
|
42
|
+
if (Refresh.hasUnrecoverableErrors()) {
|
|
64
43
|
window.location.reload();
|
|
65
|
-
return;
|
|
66
44
|
}
|
|
67
45
|
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
46
|
+
data.prevExports = module.exports;
|
|
47
|
+
});
|
|
48
|
+
module.hot.accept(function (getParents) {
|
|
49
|
+
var prevExports = module.hot.data.prevExports;
|
|
50
|
+
var nextExports = module.exports; // Since we just executed the code for it, it's possible
|
|
51
|
+
// that the new exports make it ineligible for being a boundary.
|
|
52
|
+
|
|
53
|
+
var isNoLongerABoundary = !isReactRefreshBoundary(nextExports); // It can also become ineligible if its exports are incompatible
|
|
54
|
+
// with the previous exports.
|
|
55
|
+
// For example, if you add/remove/change exports, we'll want
|
|
56
|
+
// to re-execute the importing modules, and force those components
|
|
57
|
+
// to re-render. Similarly, if you convert a class component
|
|
58
|
+
// to a function, we want to invalidate the boundary.
|
|
59
|
+
|
|
60
|
+
var didInvalidate = shouldInvalidateReactRefreshBoundary(prevExports, nextExports);
|
|
61
|
+
|
|
62
|
+
if (isNoLongerABoundary || didInvalidate) {
|
|
63
|
+
// We'll be conservative. The only case in which we won't do a full
|
|
64
|
+
// reload is if all parent modules are also refresh boundaries.
|
|
65
|
+
// In that case we'll add them to the current queue.
|
|
66
|
+
var parents = getParents();
|
|
67
|
+
|
|
68
|
+
if (parents.length === 0) {
|
|
69
|
+
// Looks like we bubbled to the root. Can't recover from that.
|
|
70
|
+
window.location.reload();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return parents;
|
|
75
|
+
}
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
enqueueUpdate();
|
|
78
|
+
});
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
};
|
|
@@ -89,6 +92,7 @@ function isReactRefreshBoundary(exports) {
|
|
|
89
92
|
|
|
90
93
|
var hasExports = false;
|
|
91
94
|
var areAllExportsComponents = true;
|
|
95
|
+
let isESM = ('__esModule' in exports);
|
|
92
96
|
|
|
93
97
|
for (var key in exports) {
|
|
94
98
|
hasExports = true;
|
|
@@ -99,8 +103,8 @@ function isReactRefreshBoundary(exports) {
|
|
|
99
103
|
|
|
100
104
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
101
105
|
|
|
102
|
-
if (desc && desc.get) {
|
|
103
|
-
// Don't invoke getters as they may have side effects.
|
|
106
|
+
if (desc && desc.get && !isESM) {
|
|
107
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
104
108
|
return false;
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -142,6 +146,8 @@ function getRefreshBoundarySignature(exports) {
|
|
|
142
146
|
return signature;
|
|
143
147
|
}
|
|
144
148
|
|
|
149
|
+
let isESM = ('__esModule' in exports);
|
|
150
|
+
|
|
145
151
|
for (var key in exports) {
|
|
146
152
|
if (key === '__esModule') {
|
|
147
153
|
continue;
|
|
@@ -149,7 +155,8 @@ function getRefreshBoundarySignature(exports) {
|
|
|
149
155
|
|
|
150
156
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
151
157
|
|
|
152
|
-
if (desc && desc.get) {
|
|
158
|
+
if (desc && desc.get && !isESM) {
|
|
159
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
153
160
|
continue;
|
|
154
161
|
}
|
|
155
162
|
|
|
@@ -172,11 +179,13 @@ function registerExportsForReactRefresh(module) {
|
|
|
172
179
|
return;
|
|
173
180
|
}
|
|
174
181
|
|
|
182
|
+
let isESM = ('__esModule' in exports);
|
|
183
|
+
|
|
175
184
|
for (var key in exports) {
|
|
176
185
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
177
186
|
|
|
178
|
-
if (desc && desc.get) {
|
|
179
|
-
// Don't invoke getters as they may have side effects.
|
|
187
|
+
if (desc && desc.get && !isESM) {
|
|
188
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
180
189
|
continue;
|
|
181
190
|
}
|
|
182
191
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-react-refresh-wrap",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
+
"funding": {
|
|
9
|
+
"type": "opencollective",
|
|
10
|
+
"url": "https://opencollective.com/parcel"
|
|
11
|
+
},
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
10
14
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
|
@@ -12,19 +16,13 @@
|
|
|
12
16
|
"main": "lib/ReactRefreshWrapTransformer.js",
|
|
13
17
|
"source": "src/ReactRefreshWrapTransformer.js",
|
|
14
18
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
16
|
-
"parcel": "^2.0.
|
|
19
|
+
"node": ">= 12.0.0",
|
|
20
|
+
"parcel": "^2.0.1"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"@babel/types": "^7.0.0",
|
|
23
|
-
"@parcel/plugin": "2.0.0-nightly.92+c0655c56",
|
|
24
|
-
"@parcel/source-map": "2.0.0-nightly.92+c0655c56",
|
|
25
|
-
"@parcel/utils": "2.0.0-nightly.92+c0655c56",
|
|
26
|
-
"react-refresh": "^0.6.0",
|
|
27
|
-
"semver": "^5.4.1"
|
|
23
|
+
"@parcel/plugin": "^2.0.1",
|
|
24
|
+
"@parcel/utils": "^2.0.1",
|
|
25
|
+
"react-refresh": "^0.9.0"
|
|
28
26
|
},
|
|
29
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "28b47e6bdca7de2a06b7cc39a4a0b1df89f3fe15"
|
|
30
28
|
}
|
|
@@ -1,133 +1,62 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import semver from 'semver';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
import {Transformer} from '@parcel/plugin';
|
|
6
|
-
import {relativeUrl} from '@parcel/utils';
|
|
7
|
-
import SourceMap from '@parcel/source-map';
|
|
8
|
-
import generate from '@babel/generator';
|
|
9
|
-
import {parse} from '@babel/parser';
|
|
10
|
-
import template from '@babel/template';
|
|
11
|
-
import * as t from '@babel/types';
|
|
12
|
-
|
|
13
|
-
const WRAPPER = path.join(__dirname, 'helpers', 'helpers.js');
|
|
14
|
-
|
|
15
|
-
const wrapper = template(`
|
|
16
|
-
var helpers = require(%%helper%%);
|
|
17
|
-
var prevRefreshReg = window.$RefreshReg$;
|
|
18
|
-
var prevRefreshSig = window.$RefreshSig$;
|
|
19
|
-
helpers.prelude(module);
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
%%module%%
|
|
23
|
-
helpers.postlude(module);
|
|
24
|
-
} finally {
|
|
25
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
26
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
27
|
-
}
|
|
28
|
-
`);
|
|
29
5
|
|
|
30
6
|
function shouldExclude(asset, options) {
|
|
31
7
|
return (
|
|
32
8
|
!asset.isSource ||
|
|
33
|
-
!options.
|
|
9
|
+
!options.hmrOptions ||
|
|
34
10
|
!asset.env.isBrowser() ||
|
|
11
|
+
asset.env.isWorker() ||
|
|
12
|
+
asset.env.isWorklet() ||
|
|
35
13
|
options.mode !== 'development' ||
|
|
36
|
-
!asset
|
|
14
|
+
!asset
|
|
15
|
+
.getDependencies()
|
|
16
|
+
.find(v => v.specifier === 'react' || v.specifier === 'react/jsx-runtime')
|
|
37
17
|
);
|
|
38
18
|
}
|
|
39
19
|
|
|
40
|
-
export default new Transformer({
|
|
41
|
-
|
|
42
|
-
return ast.type === 'babel' && semver.satisfies(ast.version, '^7.0.0');
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
async parse({asset, options}) {
|
|
20
|
+
export default (new Transformer({
|
|
21
|
+
async transform({asset, options}) {
|
|
46
22
|
if (shouldExclude(asset, options)) {
|
|
47
|
-
return
|
|
23
|
+
return [asset];
|
|
48
24
|
}
|
|
49
25
|
|
|
26
|
+
let wrapperPath = `@parcel/transformer-react-refresh-wrap/${path.basename(
|
|
27
|
+
__dirname,
|
|
28
|
+
)}/helpers/helpers.js`;
|
|
29
|
+
|
|
50
30
|
let code = await asset.getCode();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
version: '7.0.0',
|
|
54
|
-
isDirty: false,
|
|
55
|
-
program: parse(code, {
|
|
56
|
-
filename: this.name,
|
|
57
|
-
allowReturnOutsideFunction: true,
|
|
58
|
-
strictMode: false,
|
|
59
|
-
sourceType: 'module',
|
|
60
|
-
plugins: ['exportDefaultFrom', 'exportNamespaceFrom', 'dynamicImport'],
|
|
61
|
-
}),
|
|
62
|
-
};
|
|
63
|
-
},
|
|
31
|
+
let map = await asset.getMap();
|
|
32
|
+
let name = `$parcel$ReactRefreshHelpers$${asset.id.slice(-4)}`;
|
|
64
33
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
34
|
+
code = `var ${name} = require(${JSON.stringify(wrapperPath)});
|
|
35
|
+
var prevRefreshReg = window.$RefreshReg$;
|
|
36
|
+
var prevRefreshSig = window.$RefreshSig$;
|
|
37
|
+
${name}.prelude(module);
|
|
70
38
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
39
|
+
try {
|
|
40
|
+
${code}
|
|
41
|
+
${name}.postlude(module);
|
|
42
|
+
} finally {
|
|
43
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
44
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
45
|
+
}`;
|
|
77
46
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
47
|
+
asset.setCode(code);
|
|
48
|
+
if (map) {
|
|
49
|
+
map.offsetLines(1, 6);
|
|
50
|
+
asset.setMap(map);
|
|
51
|
+
}
|
|
83
52
|
|
|
84
53
|
// The JSTransformer has already run, do it manually
|
|
85
54
|
asset.addDependency({
|
|
86
|
-
|
|
55
|
+
specifier: wrapperPath,
|
|
56
|
+
specifierType: 'esm',
|
|
57
|
+
resolveFrom: __filename,
|
|
87
58
|
});
|
|
88
59
|
|
|
89
60
|
return [asset];
|
|
90
61
|
},
|
|
91
|
-
|
|
92
|
-
async generate({asset, options}) {
|
|
93
|
-
let code = await asset.getCode();
|
|
94
|
-
let res = {
|
|
95
|
-
code,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
let ast = asset.ast;
|
|
99
|
-
if (ast && ast.isDirty !== false) {
|
|
100
|
-
let sourceFileName: string = relativeUrl(
|
|
101
|
-
options.projectRoot,
|
|
102
|
-
asset.filePath,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
let generated = generate(
|
|
106
|
-
ast.program,
|
|
107
|
-
{
|
|
108
|
-
sourceMaps: options.sourceMaps,
|
|
109
|
-
sourceFileName: sourceFileName,
|
|
110
|
-
},
|
|
111
|
-
code,
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
res.code = generated.code;
|
|
115
|
-
// $FlowFixMe...
|
|
116
|
-
res.map = new SourceMap(generated.rawMappings, {
|
|
117
|
-
[sourceFileName]: null,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (asset.meta.globals && asset.meta.globals.size > 0) {
|
|
122
|
-
res.code =
|
|
123
|
-
Array.from(asset.meta.globals.values())
|
|
124
|
-
.map(g => (g ? g.code : ''))
|
|
125
|
-
.join('\n') +
|
|
126
|
-
'\n' +
|
|
127
|
-
res.code;
|
|
128
|
-
}
|
|
129
|
-
delete asset.meta.globals;
|
|
130
|
-
|
|
131
|
-
return res;
|
|
132
|
-
},
|
|
133
|
-
});
|
|
62
|
+
}): Transformer);
|
package/src/helpers/helpers.js
CHANGED
|
@@ -2,21 +2,21 @@ var Refresh = require('react-refresh/runtime');
|
|
|
2
2
|
|
|
3
3
|
function debounce(func, delay) {
|
|
4
4
|
if (process.env.NODE_ENV === 'test') {
|
|
5
|
-
return function(args) {
|
|
5
|
+
return function (args) {
|
|
6
6
|
func.call(null, args);
|
|
7
7
|
};
|
|
8
8
|
} else {
|
|
9
9
|
var timeout = undefined;
|
|
10
|
-
return function(args) {
|
|
10
|
+
return function (args) {
|
|
11
11
|
clearTimeout(timeout);
|
|
12
|
-
timeout = setTimeout(function() {
|
|
12
|
+
timeout = setTimeout(function () {
|
|
13
13
|
timeout = undefined;
|
|
14
14
|
func.call(null, args);
|
|
15
15
|
}, delay);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
var enqueueUpdate = debounce(function() {
|
|
19
|
+
var enqueueUpdate = debounce(function () {
|
|
20
20
|
Refresh.performReactRefresh();
|
|
21
21
|
}, 30);
|
|
22
22
|
|
|
@@ -24,53 +24,56 @@ var enqueueUpdate = debounce(function() {
|
|
|
24
24
|
// https://github.com/facebook/metro/blob/61de16bd1edd7e738dd0311c89555a644023ab2d/packages/metro/src/lib/polyfills/require.js
|
|
25
25
|
// MIT License - Copyright (c) Facebook, Inc. and its affiliates.
|
|
26
26
|
|
|
27
|
-
module.exports.prelude = function(module) {
|
|
28
|
-
window.$RefreshReg$ = function(type, id) {
|
|
27
|
+
module.exports.prelude = function (module) {
|
|
28
|
+
window.$RefreshReg$ = function (type, id) {
|
|
29
29
|
Refresh.register(type, module.id + ' ' + id);
|
|
30
30
|
};
|
|
31
31
|
window.$RefreshSig$ = Refresh.createSignatureFunctionForTransform;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
module.exports.postlude = function(module) {
|
|
34
|
+
module.exports.postlude = function (module) {
|
|
35
35
|
if (isReactRefreshBoundary(module.exports)) {
|
|
36
36
|
registerExportsForReactRefresh(module);
|
|
37
37
|
|
|
38
|
-
module.hot
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
module.hot.accept(function(getParents) {
|
|
43
|
-
var prevExports = module.hot.data.prevExports;
|
|
44
|
-
var nextExports = module.exports;
|
|
45
|
-
// Since we just executed the code for it, it's possible
|
|
46
|
-
// that the new exports make it ineligible for being a boundary.
|
|
47
|
-
var isNoLongerABoundary = !isReactRefreshBoundary(nextExports);
|
|
48
|
-
// It can also become ineligible if its exports are incompatible
|
|
49
|
-
// with the previous exports.
|
|
50
|
-
// For example, if you add/remove/change exports, we'll want
|
|
51
|
-
// to re-execute the importing modules, and force those components
|
|
52
|
-
// to re-render. Similarly, if you convert a class component
|
|
53
|
-
// to a function, we want to invalidate the boundary.
|
|
54
|
-
var didInvalidate = shouldInvalidateReactRefreshBoundary(
|
|
55
|
-
prevExports,
|
|
56
|
-
nextExports,
|
|
57
|
-
);
|
|
58
|
-
if (isNoLongerABoundary || didInvalidate) {
|
|
59
|
-
// We'll be conservative. The only case in which we won't do a full
|
|
60
|
-
// reload is if all parent modules are also refresh boundaries.
|
|
61
|
-
// In that case we'll add them to the current queue.
|
|
62
|
-
var parents = getParents();
|
|
63
|
-
if (parents.length === 0) {
|
|
64
|
-
// Looks like we bubbled to the root. Can't recover from that.
|
|
38
|
+
if (module.hot) {
|
|
39
|
+
module.hot.dispose(function (data) {
|
|
40
|
+
if (Refresh.hasUnrecoverableErrors()) {
|
|
65
41
|
window.location.reload();
|
|
66
|
-
return;
|
|
67
42
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
43
|
+
|
|
44
|
+
data.prevExports = module.exports;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
module.hot.accept(function (getParents) {
|
|
48
|
+
var prevExports = module.hot.data.prevExports;
|
|
49
|
+
var nextExports = module.exports;
|
|
50
|
+
// Since we just executed the code for it, it's possible
|
|
51
|
+
// that the new exports make it ineligible for being a boundary.
|
|
52
|
+
var isNoLongerABoundary = !isReactRefreshBoundary(nextExports);
|
|
53
|
+
// It can also become ineligible if its exports are incompatible
|
|
54
|
+
// with the previous exports.
|
|
55
|
+
// For example, if you add/remove/change exports, we'll want
|
|
56
|
+
// to re-execute the importing modules, and force those components
|
|
57
|
+
// to re-render. Similarly, if you convert a class component
|
|
58
|
+
// to a function, we want to invalidate the boundary.
|
|
59
|
+
var didInvalidate = shouldInvalidateReactRefreshBoundary(
|
|
60
|
+
prevExports,
|
|
61
|
+
nextExports,
|
|
62
|
+
);
|
|
63
|
+
if (isNoLongerABoundary || didInvalidate) {
|
|
64
|
+
// We'll be conservative. The only case in which we won't do a full
|
|
65
|
+
// reload is if all parent modules are also refresh boundaries.
|
|
66
|
+
// In that case we'll add them to the current queue.
|
|
67
|
+
var parents = getParents();
|
|
68
|
+
if (parents.length === 0) {
|
|
69
|
+
// Looks like we bubbled to the root. Can't recover from that.
|
|
70
|
+
window.location.reload();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return parents;
|
|
74
|
+
}
|
|
75
|
+
enqueueUpdate();
|
|
76
|
+
});
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
};
|
|
@@ -85,14 +88,15 @@ function isReactRefreshBoundary(exports) {
|
|
|
85
88
|
}
|
|
86
89
|
var hasExports = false;
|
|
87
90
|
var areAllExportsComponents = true;
|
|
91
|
+
let isESM = '__esModule' in exports;
|
|
88
92
|
for (var key in exports) {
|
|
89
93
|
hasExports = true;
|
|
90
94
|
if (key === '__esModule') {
|
|
91
95
|
continue;
|
|
92
96
|
}
|
|
93
97
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
94
|
-
if (desc && desc.get) {
|
|
95
|
-
// Don't invoke getters as they may have side effects.
|
|
98
|
+
if (desc && desc.get && !isESM) {
|
|
99
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
96
100
|
return false;
|
|
97
101
|
}
|
|
98
102
|
var exportValue = exports[key];
|
|
@@ -126,12 +130,14 @@ function getRefreshBoundarySignature(exports) {
|
|
|
126
130
|
// (This is important for legacy environments.)
|
|
127
131
|
return signature;
|
|
128
132
|
}
|
|
133
|
+
let isESM = '__esModule' in exports;
|
|
129
134
|
for (var key in exports) {
|
|
130
135
|
if (key === '__esModule') {
|
|
131
136
|
continue;
|
|
132
137
|
}
|
|
133
138
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
134
|
-
if (desc && desc.get) {
|
|
139
|
+
if (desc && desc.get && !isESM) {
|
|
140
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
135
141
|
continue;
|
|
136
142
|
}
|
|
137
143
|
var exportValue = exports[key];
|
|
@@ -150,10 +156,11 @@ function registerExportsForReactRefresh(module) {
|
|
|
150
156
|
// (This is important for legacy environments.)
|
|
151
157
|
return;
|
|
152
158
|
}
|
|
159
|
+
let isESM = '__esModule' in exports;
|
|
153
160
|
for (var key in exports) {
|
|
154
161
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
155
|
-
if (desc && desc.get) {
|
|
156
|
-
// Don't invoke getters as they may have side effects.
|
|
162
|
+
if (desc && desc.get && !isESM) {
|
|
163
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
157
164
|
continue;
|
|
158
165
|
}
|
|
159
166
|
var exportValue = exports[key];
|