@parcel/transformer-react-refresh-wrap 2.0.0-nightly.121 → 2.0.0-nightly.1211
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 +65 -43
- package/package.json +11 -13
- package/src/ReactRefreshWrapTransformer.js +44 -106
- package/src/helpers/helpers.js +69 -50
|
@@ -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.isLibrary || asset.env.isWorker() || asset.env.isWorklet() || options.mode !== 'development' || !asset.getDependencies().find(v => v.specifier === 'react' || v.specifier === 'react/jsx-runtime' || v.specifier === 'react/jsx-dev-runtime' || v.specifier === '@emotion/react' || v.specifier === '@emotion/react/jsx-runtime' || v.specifier === '@emotion/react/jsx-dev-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
|
@@ -8,13 +8,26 @@ function debounce(func, delay) {
|
|
|
8
8
|
func.call(null, args);
|
|
9
9
|
};
|
|
10
10
|
} else {
|
|
11
|
-
|
|
11
|
+
let timeout = undefined;
|
|
12
|
+
let lastTime = 0;
|
|
12
13
|
return function (args) {
|
|
13
|
-
|
|
14
|
-
timeout
|
|
15
|
-
|
|
14
|
+
// Call immediately if last call was more than the delay ago.
|
|
15
|
+
// Otherwise, set a timeout. This means the first call is fast
|
|
16
|
+
// (for the common case of a single update), and subsequent updates
|
|
17
|
+
// are batched.
|
|
18
|
+
let now = Date.now();
|
|
19
|
+
|
|
20
|
+
if (now - lastTime > delay) {
|
|
21
|
+
lastTime = now;
|
|
16
22
|
func.call(null, args);
|
|
17
|
-
}
|
|
23
|
+
} else {
|
|
24
|
+
clearTimeout(timeout);
|
|
25
|
+
timeout = setTimeout(function () {
|
|
26
|
+
timeout = undefined;
|
|
27
|
+
lastTime = Date.now();
|
|
28
|
+
func.call(null, args);
|
|
29
|
+
}, delay);
|
|
30
|
+
}
|
|
18
31
|
};
|
|
19
32
|
}
|
|
20
33
|
}
|
|
@@ -36,43 +49,46 @@ module.exports.prelude = function (module) {
|
|
|
36
49
|
module.exports.postlude = function (module) {
|
|
37
50
|
if (isReactRefreshBoundary(module.exports)) {
|
|
38
51
|
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.
|
|
52
|
+
|
|
53
|
+
if (module.hot) {
|
|
54
|
+
module.hot.dispose(function (data) {
|
|
55
|
+
if (Refresh.hasUnrecoverableErrors()) {
|
|
64
56
|
window.location.reload();
|
|
65
|
-
return;
|
|
66
57
|
}
|
|
67
58
|
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
data.prevExports = module.exports;
|
|
60
|
+
});
|
|
61
|
+
module.hot.accept(function (getParents) {
|
|
62
|
+
var prevExports = module.hot.data.prevExports;
|
|
63
|
+
var nextExports = module.exports; // Since we just executed the code for it, it's possible
|
|
64
|
+
// that the new exports make it ineligible for being a boundary.
|
|
65
|
+
|
|
66
|
+
var isNoLongerABoundary = !isReactRefreshBoundary(nextExports); // It can also become ineligible if its exports are incompatible
|
|
67
|
+
// with the previous exports.
|
|
68
|
+
// For example, if you add/remove/change exports, we'll want
|
|
69
|
+
// to re-execute the importing modules, and force those components
|
|
70
|
+
// to re-render. Similarly, if you convert a class component
|
|
71
|
+
// to a function, we want to invalidate the boundary.
|
|
72
|
+
|
|
73
|
+
var didInvalidate = shouldInvalidateReactRefreshBoundary(prevExports, nextExports);
|
|
74
|
+
|
|
75
|
+
if (isNoLongerABoundary || didInvalidate) {
|
|
76
|
+
// We'll be conservative. The only case in which we won't do a full
|
|
77
|
+
// reload is if all parent modules are also refresh boundaries.
|
|
78
|
+
// In that case we'll add them to the current queue.
|
|
79
|
+
var parents = getParents();
|
|
80
|
+
|
|
81
|
+
if (parents.length === 0) {
|
|
82
|
+
// Looks like we bubbled to the root. Can't recover from that.
|
|
83
|
+
window.location.reload();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return parents;
|
|
88
|
+
}
|
|
73
89
|
|
|
74
|
-
|
|
75
|
-
|
|
90
|
+
enqueueUpdate();
|
|
91
|
+
});
|
|
76
92
|
}
|
|
77
93
|
}
|
|
78
94
|
};
|
|
@@ -89,6 +105,7 @@ function isReactRefreshBoundary(exports) {
|
|
|
89
105
|
|
|
90
106
|
var hasExports = false;
|
|
91
107
|
var areAllExportsComponents = true;
|
|
108
|
+
let isESM = ('__esModule' in exports);
|
|
92
109
|
|
|
93
110
|
for (var key in exports) {
|
|
94
111
|
hasExports = true;
|
|
@@ -99,8 +116,8 @@ function isReactRefreshBoundary(exports) {
|
|
|
99
116
|
|
|
100
117
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
101
118
|
|
|
102
|
-
if (desc && desc.get) {
|
|
103
|
-
// Don't invoke getters as they may have side effects.
|
|
119
|
+
if (desc && desc.get && !isESM) {
|
|
120
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
104
121
|
return false;
|
|
105
122
|
}
|
|
106
123
|
|
|
@@ -142,6 +159,8 @@ function getRefreshBoundarySignature(exports) {
|
|
|
142
159
|
return signature;
|
|
143
160
|
}
|
|
144
161
|
|
|
162
|
+
let isESM = ('__esModule' in exports);
|
|
163
|
+
|
|
145
164
|
for (var key in exports) {
|
|
146
165
|
if (key === '__esModule') {
|
|
147
166
|
continue;
|
|
@@ -149,7 +168,8 @@ function getRefreshBoundarySignature(exports) {
|
|
|
149
168
|
|
|
150
169
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
151
170
|
|
|
152
|
-
if (desc && desc.get) {
|
|
171
|
+
if (desc && desc.get && !isESM) {
|
|
172
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
153
173
|
continue;
|
|
154
174
|
}
|
|
155
175
|
|
|
@@ -172,11 +192,13 @@ function registerExportsForReactRefresh(module) {
|
|
|
172
192
|
return;
|
|
173
193
|
}
|
|
174
194
|
|
|
195
|
+
let isESM = ('__esModule' in exports);
|
|
196
|
+
|
|
175
197
|
for (var key in exports) {
|
|
176
198
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
177
199
|
|
|
178
|
-
if (desc && desc.get) {
|
|
179
|
-
// Don't invoke getters as they may have side effects.
|
|
200
|
+
if (desc && desc.get && !isESM) {
|
|
201
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
180
202
|
continue;
|
|
181
203
|
}
|
|
182
204
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-react-refresh-wrap",
|
|
3
|
-
"version": "2.0.0-nightly.
|
|
3
|
+
"version": "2.0.0-nightly.1211+ae31c3c85",
|
|
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": "
|
|
19
|
+
"node": ">= 12.0.0",
|
|
20
|
+
"parcel": "2.0.0-nightly.1209+ae31c3c85"
|
|
17
21
|
},
|
|
18
22
|
"dependencies": {
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"@babel/types": "^7.0.0",
|
|
23
|
-
"@parcel/plugin": "2.0.0-nightly.121+8dc29d37",
|
|
24
|
-
"@parcel/source-map": "2.0.0-nightly.121+8dc29d37",
|
|
25
|
-
"@parcel/utils": "2.0.0-nightly.121+8dc29d37",
|
|
26
|
-
"react-refresh": "^0.6.0",
|
|
27
|
-
"semver": "^5.4.1"
|
|
23
|
+
"@parcel/plugin": "2.0.0-nightly.1211+ae31c3c85",
|
|
24
|
+
"@parcel/utils": "2.0.0-nightly.1211+ae31c3c85",
|
|
25
|
+
"react-refresh": "^0.9.0"
|
|
28
26
|
},
|
|
29
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "ae31c3c85ff2a3f8353d5c40928d46d9bc3a0545"
|
|
30
28
|
}
|
|
@@ -1,133 +1,71 @@
|
|
|
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.isLibrary ||
|
|
12
|
+
asset.env.isWorker() ||
|
|
13
|
+
asset.env.isWorklet() ||
|
|
35
14
|
options.mode !== 'development' ||
|
|
36
|
-
!asset
|
|
15
|
+
!asset
|
|
16
|
+
.getDependencies()
|
|
17
|
+
.find(
|
|
18
|
+
v =>
|
|
19
|
+
v.specifier === 'react' ||
|
|
20
|
+
v.specifier === 'react/jsx-runtime' ||
|
|
21
|
+
v.specifier === 'react/jsx-dev-runtime' ||
|
|
22
|
+
v.specifier === '@emotion/react' ||
|
|
23
|
+
v.specifier === '@emotion/react/jsx-runtime' ||
|
|
24
|
+
v.specifier === '@emotion/react/jsx-dev-runtime',
|
|
25
|
+
)
|
|
37
26
|
);
|
|
38
27
|
}
|
|
39
28
|
|
|
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}) {
|
|
29
|
+
export default (new Transformer({
|
|
30
|
+
async transform({asset, options}) {
|
|
46
31
|
if (shouldExclude(asset, options)) {
|
|
47
|
-
return
|
|
32
|
+
return [asset];
|
|
48
33
|
}
|
|
49
34
|
|
|
35
|
+
let wrapperPath = `@parcel/transformer-react-refresh-wrap/${path.basename(
|
|
36
|
+
__dirname,
|
|
37
|
+
)}/helpers/helpers.js`;
|
|
38
|
+
|
|
50
39
|
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
|
-
},
|
|
40
|
+
let map = await asset.getMap();
|
|
41
|
+
let name = `$parcel$ReactRefreshHelpers$${asset.id.slice(-4)}`;
|
|
64
42
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
43
|
+
code = `var ${name} = require(${JSON.stringify(wrapperPath)});
|
|
44
|
+
var prevRefreshReg = window.$RefreshReg$;
|
|
45
|
+
var prevRefreshSig = window.$RefreshSig$;
|
|
46
|
+
${name}.prelude(module);
|
|
70
47
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
48
|
+
try {
|
|
49
|
+
${code}
|
|
50
|
+
${name}.postlude(module);
|
|
51
|
+
} finally {
|
|
52
|
+
window.$RefreshReg$ = prevRefreshReg;
|
|
53
|
+
window.$RefreshSig$ = prevRefreshSig;
|
|
54
|
+
}`;
|
|
77
55
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
56
|
+
asset.setCode(code);
|
|
57
|
+
if (map) {
|
|
58
|
+
map.offsetLines(1, 6);
|
|
59
|
+
asset.setMap(map);
|
|
60
|
+
}
|
|
83
61
|
|
|
84
62
|
// The JSTransformer has already run, do it manually
|
|
85
63
|
asset.addDependency({
|
|
86
|
-
|
|
64
|
+
specifier: wrapperPath,
|
|
65
|
+
specifierType: 'esm',
|
|
66
|
+
resolveFrom: __filename,
|
|
87
67
|
});
|
|
88
68
|
|
|
89
69
|
return [asset];
|
|
90
70
|
},
|
|
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
|
-
});
|
|
71
|
+
}): Transformer);
|
package/src/helpers/helpers.js
CHANGED
|
@@ -2,21 +2,33 @@ 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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
let timeout = undefined;
|
|
10
|
+
let lastTime = 0;
|
|
11
|
+
return function (args) {
|
|
12
|
+
// Call immediately if last call was more than the delay ago.
|
|
13
|
+
// Otherwise, set a timeout. This means the first call is fast
|
|
14
|
+
// (for the common case of a single update), and subsequent updates
|
|
15
|
+
// are batched.
|
|
16
|
+
let now = Date.now();
|
|
17
|
+
if (now - lastTime > delay) {
|
|
18
|
+
lastTime = now;
|
|
14
19
|
func.call(null, args);
|
|
15
|
-
}
|
|
20
|
+
} else {
|
|
21
|
+
clearTimeout(timeout);
|
|
22
|
+
timeout = setTimeout(function () {
|
|
23
|
+
timeout = undefined;
|
|
24
|
+
lastTime = Date.now();
|
|
25
|
+
func.call(null, args);
|
|
26
|
+
}, delay);
|
|
27
|
+
}
|
|
16
28
|
};
|
|
17
29
|
}
|
|
18
30
|
}
|
|
19
|
-
var enqueueUpdate = debounce(function() {
|
|
31
|
+
var enqueueUpdate = debounce(function () {
|
|
20
32
|
Refresh.performReactRefresh();
|
|
21
33
|
}, 30);
|
|
22
34
|
|
|
@@ -24,53 +36,56 @@ var enqueueUpdate = debounce(function() {
|
|
|
24
36
|
// https://github.com/facebook/metro/blob/61de16bd1edd7e738dd0311c89555a644023ab2d/packages/metro/src/lib/polyfills/require.js
|
|
25
37
|
// MIT License - Copyright (c) Facebook, Inc. and its affiliates.
|
|
26
38
|
|
|
27
|
-
module.exports.prelude = function(module) {
|
|
28
|
-
window.$RefreshReg$ = function(type, id) {
|
|
39
|
+
module.exports.prelude = function (module) {
|
|
40
|
+
window.$RefreshReg$ = function (type, id) {
|
|
29
41
|
Refresh.register(type, module.id + ' ' + id);
|
|
30
42
|
};
|
|
31
43
|
window.$RefreshSig$ = Refresh.createSignatureFunctionForTransform;
|
|
32
44
|
};
|
|
33
45
|
|
|
34
|
-
module.exports.postlude = function(module) {
|
|
46
|
+
module.exports.postlude = function (module) {
|
|
35
47
|
if (isReactRefreshBoundary(module.exports)) {
|
|
36
48
|
registerExportsForReactRefresh(module);
|
|
37
49
|
|
|
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.
|
|
50
|
+
if (module.hot) {
|
|
51
|
+
module.hot.dispose(function (data) {
|
|
52
|
+
if (Refresh.hasUnrecoverableErrors()) {
|
|
65
53
|
window.location.reload();
|
|
66
|
-
return;
|
|
67
54
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
55
|
+
|
|
56
|
+
data.prevExports = module.exports;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
module.hot.accept(function (getParents) {
|
|
60
|
+
var prevExports = module.hot.data.prevExports;
|
|
61
|
+
var nextExports = module.exports;
|
|
62
|
+
// Since we just executed the code for it, it's possible
|
|
63
|
+
// that the new exports make it ineligible for being a boundary.
|
|
64
|
+
var isNoLongerABoundary = !isReactRefreshBoundary(nextExports);
|
|
65
|
+
// It can also become ineligible if its exports are incompatible
|
|
66
|
+
// with the previous exports.
|
|
67
|
+
// For example, if you add/remove/change exports, we'll want
|
|
68
|
+
// to re-execute the importing modules, and force those components
|
|
69
|
+
// to re-render. Similarly, if you convert a class component
|
|
70
|
+
// to a function, we want to invalidate the boundary.
|
|
71
|
+
var didInvalidate = shouldInvalidateReactRefreshBoundary(
|
|
72
|
+
prevExports,
|
|
73
|
+
nextExports,
|
|
74
|
+
);
|
|
75
|
+
if (isNoLongerABoundary || didInvalidate) {
|
|
76
|
+
// We'll be conservative. The only case in which we won't do a full
|
|
77
|
+
// reload is if all parent modules are also refresh boundaries.
|
|
78
|
+
// In that case we'll add them to the current queue.
|
|
79
|
+
var parents = getParents();
|
|
80
|
+
if (parents.length === 0) {
|
|
81
|
+
// Looks like we bubbled to the root. Can't recover from that.
|
|
82
|
+
window.location.reload();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
return parents;
|
|
86
|
+
}
|
|
87
|
+
enqueueUpdate();
|
|
88
|
+
});
|
|
74
89
|
}
|
|
75
90
|
}
|
|
76
91
|
};
|
|
@@ -85,14 +100,15 @@ function isReactRefreshBoundary(exports) {
|
|
|
85
100
|
}
|
|
86
101
|
var hasExports = false;
|
|
87
102
|
var areAllExportsComponents = true;
|
|
103
|
+
let isESM = '__esModule' in exports;
|
|
88
104
|
for (var key in exports) {
|
|
89
105
|
hasExports = true;
|
|
90
106
|
if (key === '__esModule') {
|
|
91
107
|
continue;
|
|
92
108
|
}
|
|
93
109
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
94
|
-
if (desc && desc.get) {
|
|
95
|
-
// Don't invoke getters as they may have side effects.
|
|
110
|
+
if (desc && desc.get && !isESM) {
|
|
111
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
96
112
|
return false;
|
|
97
113
|
}
|
|
98
114
|
var exportValue = exports[key];
|
|
@@ -126,12 +142,14 @@ function getRefreshBoundarySignature(exports) {
|
|
|
126
142
|
// (This is important for legacy environments.)
|
|
127
143
|
return signature;
|
|
128
144
|
}
|
|
145
|
+
let isESM = '__esModule' in exports;
|
|
129
146
|
for (var key in exports) {
|
|
130
147
|
if (key === '__esModule') {
|
|
131
148
|
continue;
|
|
132
149
|
}
|
|
133
150
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
134
|
-
if (desc && desc.get) {
|
|
151
|
+
if (desc && desc.get && !isESM) {
|
|
152
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
135
153
|
continue;
|
|
136
154
|
}
|
|
137
155
|
var exportValue = exports[key];
|
|
@@ -150,10 +168,11 @@ function registerExportsForReactRefresh(module) {
|
|
|
150
168
|
// (This is important for legacy environments.)
|
|
151
169
|
return;
|
|
152
170
|
}
|
|
171
|
+
let isESM = '__esModule' in exports;
|
|
153
172
|
for (var key in exports) {
|
|
154
173
|
var desc = Object.getOwnPropertyDescriptor(exports, key);
|
|
155
|
-
if (desc && desc.get) {
|
|
156
|
-
// Don't invoke getters as they may have side effects.
|
|
174
|
+
if (desc && desc.get && !isESM) {
|
|
175
|
+
// Don't invoke getters for CJS as they may have side effects.
|
|
157
176
|
continue;
|
|
158
177
|
}
|
|
159
178
|
var exportValue = exports[key];
|