@shuvi/toolpack 1.0.0-rc.1 → 1.0.0-rc.12
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/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
- package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +8 -8
- package/lib/babel/preset.js +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +2 -1
- package/lib/utils/formatWebpackMessages.d.ts +18 -4
- package/lib/utils/formatWebpackMessages.js +15 -13
- package/lib/webpack/config/base.d.ts +3 -1
- package/lib/webpack/config/base.js +43 -22
- package/lib/webpack/config/browser.js +47 -31
- package/lib/webpack/config/node.js +3 -3
- package/lib/webpack/config/parts/helpers.d.ts +1 -0
- package/lib/webpack/config/parts/helpers.js +8 -1
- package/lib/webpack/config/parts/style.js +0 -6
- package/lib/webpack/dynamic-dll/bundler/webpack-config.js +1 -1
- package/lib/webpack/dynamic-dll/index.d.ts +2 -2
- package/lib/webpack/dynamic-dll/index.js +26 -26
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +0 -1
- package/lib/webpack/index.d.ts +3 -5
- package/lib/webpack/index.js +4 -6
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +9 -2
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +2 -1
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
- package/lib/webpack/loaders/{shuvi-swc-loader.d.ts → shuvi-swc-loader/index.d.ts} +0 -0
- package/lib/webpack/loaders/{shuvi-swc-loader.js → shuvi-swc-loader/index.js} +50 -86
- package/lib/webpack/plugins/dynamic-public-path-plugin.js +3 -2
- package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +1 -0
- package/lib/webpack/plugins/module-replace-plugin/plugin.js +9 -1
- package/package.json +13 -48
- package/lib/swc/tests/fixture/auto-css-module/no-flag/input.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/no-flag/input.js +0 -4
- package/lib/swc/tests/fixture/auto-css-module/no-flag/output.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/no-flag/output.js +0 -4
- package/lib/swc/tests/fixture/auto-css-module/with-flag/input.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/with-flag/input.js +0 -2
- package/lib/swc/tests/fixture/auto-css-module/with-flag/output.d.ts +0 -1
- package/lib/swc/tests/fixture/auto-css-module/with-flag/output.js +0 -2
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.js +0 -5
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.js +0 -11
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.js +0 -12
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.js +0 -8
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.js +0 -5
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.js +0 -11
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.js +0 -9
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.js +0 -12
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.js +0 -4
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.js +0 -8
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.js +0 -7
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.d.ts +0 -1
- package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.js +0 -9
- package/lib/swc/tests/full/auto-cjs/1/input.d.ts +0 -1
- package/lib/swc/tests/full/auto-cjs/1/input.js +0 -8
- package/lib/swc/tests/full/auto-cjs/1/output.d.ts +0 -1
- package/lib/swc/tests/full/auto-cjs/1/output.js +0 -8
- package/lib/utils/build-loaders.d.ts +0 -2
- package/lib/utils/build-loaders.js +0 -131
- package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
- package/lib/utils/hotDevClient/eventsource.js +0 -64
- package/lib/utils/hotDevClient/index.d.ts +0 -4
- package/lib/utils/hotDevClient/index.js +0 -362
- package/lib/utils/load-sources.d.ts +0 -3
- package/lib/utils/load-sources.js +0 -94
- package/swc-source/native/shuvi-swc.darwin-arm64.node +0 -0
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable camelcase */
|
|
3
|
-
/**
|
|
4
|
-
MIT License
|
|
5
|
-
|
|
6
|
-
Copyright (c) 2013-present, Facebook, Inc.
|
|
7
|
-
|
|
8
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
in the Software without restriction, including without limitation the rights
|
|
11
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
furnished to do so, subject to the following conditions:
|
|
14
|
-
|
|
15
|
-
The above copyright notice and this permission notice shall be included in all
|
|
16
|
-
copies or substantial portions of the Software.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
-
SOFTWARE.
|
|
25
|
-
*/
|
|
26
|
-
// This file is based on https://github.com/facebook/create-react-app/blob/v1.1.4/packages/react-dev-utils/webpackHotDevClient.js
|
|
27
|
-
// It's been edited to rely on webpack-hot-middleware.
|
|
28
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
-
if (k2 === undefined) k2 = k;
|
|
30
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
-
}
|
|
34
|
-
Object.defineProperty(o, k2, desc);
|
|
35
|
-
}) : (function(o, m, k, k2) {
|
|
36
|
-
if (k2 === undefined) k2 = k;
|
|
37
|
-
o[k2] = m[k];
|
|
38
|
-
}));
|
|
39
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
-
}) : function(o, v) {
|
|
42
|
-
o["default"] = v;
|
|
43
|
-
});
|
|
44
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
45
|
-
if (mod && mod.__esModule) return mod;
|
|
46
|
-
var result = {};
|
|
47
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
48
|
-
__setModuleDefault(result, mod);
|
|
49
|
-
return result;
|
|
50
|
-
};
|
|
51
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
52
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
53
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
54
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
55
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
56
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
57
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
|
-
};
|
|
63
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
const ErrorOverlay = __importStar(require("react-error-overlay"));
|
|
65
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
66
|
-
const formatWebpackMessages_1 = __importDefault(require("../formatWebpackMessages"));
|
|
67
|
-
const eventsource_1 = require("./eventsource");
|
|
68
|
-
// This alternative WebpackDevServer combines the functionality of:
|
|
69
|
-
// https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js
|
|
70
|
-
// https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js
|
|
71
|
-
// It only supports their simplest configuration (hot updates on same server).
|
|
72
|
-
// It makes some opinionated choices on top, like adding a syntax error overlay
|
|
73
|
-
// that looks similar to our console output. The error overlay is inspired by:
|
|
74
|
-
// https://github.com/glenjamin/webpack-hot-middleware
|
|
75
|
-
// This is a modified version of create-react-app's webpackHotDevClient.js
|
|
76
|
-
// It implements webpack-hot-middleware's EventSource events instead of webpack-dev-server's websocket.
|
|
77
|
-
// https://github.com/facebook/create-react-app/blob/25184c4e91ebabd16fe1cde3d8630830e4a36a01/packages/react-dev-utils/webpackHotDevClient.js
|
|
78
|
-
let hadRuntimeError = false;
|
|
79
|
-
let customHmrEventHandler;
|
|
80
|
-
function connect(options) {
|
|
81
|
-
// Open stack traces in an editor.
|
|
82
|
-
ErrorOverlay.setEditorHandler(function editorHandler({ fileName, lineNumber, colNumber }) {
|
|
83
|
-
// Resolve invalid paths coming from react-error-overlay
|
|
84
|
-
const resolvedFilename = fileName.replace(/^webpack:\/\/[^/]+/ /* webpack://namaspcae/resourcepath */, '');
|
|
85
|
-
fetch(options.launchEditorEndpoint +
|
|
86
|
-
'?fileName=' +
|
|
87
|
-
window.encodeURIComponent(resolvedFilename) +
|
|
88
|
-
'&lineNumber=' +
|
|
89
|
-
window.encodeURIComponent(lineNumber || 1) +
|
|
90
|
-
'&colNumber=' +
|
|
91
|
-
window.encodeURIComponent(colNumber || 1));
|
|
92
|
-
});
|
|
93
|
-
// We need to keep track of if there has been a runtime error.
|
|
94
|
-
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
95
|
-
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
96
|
-
// application. This is handled below when we are notified of a compile (code
|
|
97
|
-
// change).
|
|
98
|
-
// See https://github.com/facebook/create-react-app/issues/3096
|
|
99
|
-
ErrorOverlay.startReportingRuntimeErrors({
|
|
100
|
-
onError: function () {
|
|
101
|
-
hadRuntimeError = true;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
if (module.hot && typeof module.hot.dispose === 'function') {
|
|
105
|
-
module.hot.dispose(function () {
|
|
106
|
-
// TODO: why do we need this?
|
|
107
|
-
ErrorOverlay.stopReportingRuntimeErrors();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
(0, eventsource_1.getEventSourceWrapper)(options).addMessageListener(event => {
|
|
111
|
-
// This is the heartbeat event
|
|
112
|
-
if (event.data === '\uD83D\uDC93') {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
processMessage(event);
|
|
117
|
-
}
|
|
118
|
-
catch (ex) {
|
|
119
|
-
console.warn('Invalid HMR message: ' + event.data + '\n' + ex);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
return {
|
|
123
|
-
subscribeToHmrEvent(handler) {
|
|
124
|
-
customHmrEventHandler = handler;
|
|
125
|
-
},
|
|
126
|
-
reportRuntimeError(err) {
|
|
127
|
-
ErrorOverlay.reportRuntimeError(err);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
exports.default = connect;
|
|
132
|
-
// Remember some state related to hot module replacement.
|
|
133
|
-
var isFirstCompilation = true;
|
|
134
|
-
var mostRecentCompilationHash = null;
|
|
135
|
-
var hasCompileErrors = false;
|
|
136
|
-
function clearOutdatedErrors() {
|
|
137
|
-
// Clean up outdated compile errors, if any.
|
|
138
|
-
if (typeof console !== 'undefined' && typeof console.clear === 'function') {
|
|
139
|
-
if (hasCompileErrors) {
|
|
140
|
-
console.clear();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
function afterApplyUpdate() {
|
|
145
|
-
tryDismissErrorOverlay();
|
|
146
|
-
console.log('[Fast Refresh] Done.');
|
|
147
|
-
}
|
|
148
|
-
// Successful compilation.
|
|
149
|
-
function handleSuccess() {
|
|
150
|
-
clearOutdatedErrors();
|
|
151
|
-
const isHotUpdate = !isFirstCompilation;
|
|
152
|
-
isFirstCompilation = false;
|
|
153
|
-
hasCompileErrors = false;
|
|
154
|
-
// Attempt to apply hot updates or reload.
|
|
155
|
-
if (isHotUpdate) {
|
|
156
|
-
tryApplyUpdates(function onHotUpdateSuccess() {
|
|
157
|
-
// Only dismiss it when we're sure it's a hot update.
|
|
158
|
-
// Otherwise it would flicker right before the reload.
|
|
159
|
-
afterApplyUpdate();
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// Compilation with warnings (e.g. ESLint).
|
|
164
|
-
function handleWarnings(warnings) {
|
|
165
|
-
clearOutdatedErrors();
|
|
166
|
-
var isHotUpdate = !isFirstCompilation;
|
|
167
|
-
isFirstCompilation = false;
|
|
168
|
-
hasCompileErrors = false;
|
|
169
|
-
// Print warnings to the console.
|
|
170
|
-
const formatted = (0, formatWebpackMessages_1.default)({
|
|
171
|
-
warnings: warnings,
|
|
172
|
-
errors: []
|
|
173
|
-
});
|
|
174
|
-
if (typeof console !== 'undefined' && typeof console.warn === 'function') {
|
|
175
|
-
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
176
|
-
if (i === 5) {
|
|
177
|
-
console.warn('There were more warnings in other files.\n' +
|
|
178
|
-
'You can find a complete log in the terminal.');
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
console.warn((0, strip_ansi_1.default)(formatted.warnings[i]));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Attempt to apply hot updates or reload.
|
|
185
|
-
if (isHotUpdate) {
|
|
186
|
-
tryApplyUpdates(function onSuccessfulHotUpdate() {
|
|
187
|
-
// Only dismiss it when we're sure it's a hot update.
|
|
188
|
-
// Otherwise it would flicker right before the reload.
|
|
189
|
-
tryDismissErrorOverlay();
|
|
190
|
-
afterApplyUpdate();
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
// Compilation with errors (e.g. syntax error or missing modules).
|
|
195
|
-
function handleErrors(errors) {
|
|
196
|
-
clearOutdatedErrors();
|
|
197
|
-
isFirstCompilation = false;
|
|
198
|
-
hasCompileErrors = true;
|
|
199
|
-
// "Massage" webpack messages.
|
|
200
|
-
var formatted = (0, formatWebpackMessages_1.default)({
|
|
201
|
-
errors: errors,
|
|
202
|
-
warnings: []
|
|
203
|
-
});
|
|
204
|
-
// Only show the first error.
|
|
205
|
-
ErrorOverlay.reportBuildError(formatted.errors[0]);
|
|
206
|
-
// Also log them to the console.
|
|
207
|
-
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
208
|
-
for (var i = 0; i < formatted.errors.length; i++) {
|
|
209
|
-
console.error((0, strip_ansi_1.default)(formatted.errors[i]));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function tryDismissErrorOverlay() {
|
|
214
|
-
if (!hasCompileErrors) {
|
|
215
|
-
ErrorOverlay.dismissBuildError();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
// There is a newer version of the code available.
|
|
219
|
-
function handleAvailableHash(hash) {
|
|
220
|
-
// Update last known compilation hash.
|
|
221
|
-
mostRecentCompilationHash = hash;
|
|
222
|
-
}
|
|
223
|
-
// Handle messages from the server.
|
|
224
|
-
function processMessage(e) {
|
|
225
|
-
const obj = JSON.parse(e.data);
|
|
226
|
-
switch (obj.action) {
|
|
227
|
-
case 'building': {
|
|
228
|
-
console.log('[Fast Refresh] bundle ' +
|
|
229
|
-
(obj.name ? "'" + obj.name + "' " : '') +
|
|
230
|
-
'rebuilding');
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
case 'built':
|
|
234
|
-
case 'sync': {
|
|
235
|
-
if (obj.hash) {
|
|
236
|
-
handleAvailableHash(obj.hash);
|
|
237
|
-
}
|
|
238
|
-
const { errors, warnings } = obj;
|
|
239
|
-
const hasErrors = Boolean(errors && errors.length);
|
|
240
|
-
if (hasErrors) {
|
|
241
|
-
return handleErrors(errors);
|
|
242
|
-
}
|
|
243
|
-
const hasWarnings = Boolean(warnings && warnings.length);
|
|
244
|
-
if (hasWarnings) {
|
|
245
|
-
return handleWarnings(warnings);
|
|
246
|
-
}
|
|
247
|
-
handleSuccess();
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
case 'warnings':
|
|
251
|
-
handleWarnings(obj.data);
|
|
252
|
-
break;
|
|
253
|
-
case 'errors':
|
|
254
|
-
handleErrors(obj.data);
|
|
255
|
-
break;
|
|
256
|
-
default: {
|
|
257
|
-
if (customHmrEventHandler) {
|
|
258
|
-
customHmrEventHandler(obj);
|
|
259
|
-
break;
|
|
260
|
-
}
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
// Is there a newer version of this code available?
|
|
266
|
-
function isUpdateAvailable() {
|
|
267
|
-
/* globals __webpack_hash__ */
|
|
268
|
-
// __webpack_hash__ is the hash of the current compilation.
|
|
269
|
-
// It's a global variable injected by Webpack.
|
|
270
|
-
return mostRecentCompilationHash !== __webpack_hash__;
|
|
271
|
-
}
|
|
272
|
-
// Webpack disallows updates in other states.
|
|
273
|
-
function canApplyUpdates() {
|
|
274
|
-
return module.hot.status() === 'idle';
|
|
275
|
-
}
|
|
276
|
-
function waitForReady() {
|
|
277
|
-
return new Promise((resolve, reject) => {
|
|
278
|
-
if (module.hot.status() !== 'prepare') {
|
|
279
|
-
reject();
|
|
280
|
-
}
|
|
281
|
-
const handler = status => {
|
|
282
|
-
module.hot.removeStatusHandler(handler);
|
|
283
|
-
if (status === 'ready') {
|
|
284
|
-
resolve();
|
|
285
|
-
}
|
|
286
|
-
if (status === 'abort' || status === 'fail') {
|
|
287
|
-
reject();
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
module.hot.addStatusHandler(handler);
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
// Attempt to update code on the fly, fall back to a hard reload.
|
|
294
|
-
function tryApplyUpdates(onHotUpdateSuccess) {
|
|
295
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
-
if (!module.hot) {
|
|
297
|
-
// HotModuleReplacementPlugin is not in Webpack configuration.
|
|
298
|
-
console.error('HotModuleReplacementPlugin is not in Webpack configuration.');
|
|
299
|
-
window.location.reload();
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
if (!isUpdateAvailable() || !canApplyUpdates()) {
|
|
303
|
-
ErrorOverlay.dismissBuildError();
|
|
304
|
-
// HMR failed, need to refresh
|
|
305
|
-
const hmrStatus = module.hot.status();
|
|
306
|
-
if (hmrStatus === 'abort' || hmrStatus === 'fail') {
|
|
307
|
-
window.location.reload();
|
|
308
|
-
}
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
function handleApplyUpdates(err, updatedModules) {
|
|
312
|
-
const needForcedReload = err || hadRuntimeError;
|
|
313
|
-
if (needForcedReload) {
|
|
314
|
-
if (hadRuntimeError) {
|
|
315
|
-
hadRuntimeError = false;
|
|
316
|
-
window.location.reload();
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
ErrorOverlay.reportRuntimeError(err);
|
|
320
|
-
hadRuntimeError = true;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
if (typeof onHotUpdateSuccess === 'function') {
|
|
324
|
-
// Maybe we want to do something.
|
|
325
|
-
onHotUpdateSuccess();
|
|
326
|
-
}
|
|
327
|
-
if (isUpdateAvailable()) {
|
|
328
|
-
// While we were updating, there was a new update! Do it again.
|
|
329
|
-
tryApplyUpdates(onHotUpdateSuccess);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
try {
|
|
333
|
-
// https://webpack.js.org/api/hot-module-replacement/#check
|
|
334
|
-
let updatedModules = yield module.hot.check(/* autoApply */ false);
|
|
335
|
-
if (!updatedModules) {
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
// if there is another updating, delay the update
|
|
339
|
-
// multiple hotupdate occurs during import() will cause hmr error
|
|
340
|
-
// so we delay the adjacent hotupdates
|
|
341
|
-
// import() == loade module script ----> require(module)
|
|
342
|
-
// |
|
|
343
|
-
// |
|
|
344
|
-
// if applyUpdate happens here, require will cause a error
|
|
345
|
-
if (isUpdateAvailable()) {
|
|
346
|
-
yield new Promise(resolve => {
|
|
347
|
-
setTimeout(resolve, 50);
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
if (updatedModules) {
|
|
351
|
-
if (module.hot.status() !== 'ready') {
|
|
352
|
-
yield waitForReady();
|
|
353
|
-
}
|
|
354
|
-
updatedModules = yield module.hot.apply();
|
|
355
|
-
}
|
|
356
|
-
handleApplyUpdates(null, updatedModules);
|
|
357
|
-
}
|
|
358
|
-
catch (err) {
|
|
359
|
-
handleApplyUpdates(err, null);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.bundle = exports.minifySync = exports.minify = void 0;
|
|
13
|
-
const fs = require('fs');
|
|
14
|
-
const { platform, arch } = require('os');
|
|
15
|
-
const path = require('path');
|
|
16
|
-
const { platformArchTriples } = require('@napi-rs/triples');
|
|
17
|
-
const ArchName = arch();
|
|
18
|
-
const PlatformName = platform();
|
|
19
|
-
let bindings;
|
|
20
|
-
let loadError;
|
|
21
|
-
const triples = platformArchTriples[PlatformName][ArchName];
|
|
22
|
-
for (const triple of triples) {
|
|
23
|
-
try {
|
|
24
|
-
const swcSource = path.join(__dirname, '../../swc-source');
|
|
25
|
-
const localFilePath = path.join(swcSource, `native/shuvi-swc.${triple.platformArchABI}.node`);
|
|
26
|
-
if (fs.existsSync(localFilePath)) {
|
|
27
|
-
console.log('Using locally built binary of shuvi-swc');
|
|
28
|
-
try {
|
|
29
|
-
bindings = require(localFilePath);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
if ((e === null || e === void 0 ? void 0 : e.code) !== 'MODULE_NOT_FOUND') {
|
|
33
|
-
loadError = e;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
bindings = require(`@shuvi/swc-${triple.platformArchABI}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (!bindings) {
|
|
45
|
-
if (loadError) {
|
|
46
|
-
console.error(loadError);
|
|
47
|
-
}
|
|
48
|
-
console.error(`Failed to load SWC binary`);
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
loadError = null;
|
|
53
|
-
}
|
|
54
|
-
function transform(src, options) {
|
|
55
|
-
var _a, _b;
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const isModule = typeof src !== 'string' && !Buffer.isBuffer(src);
|
|
58
|
-
options = options || {};
|
|
59
|
-
if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
|
|
60
|
-
options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
|
|
61
|
-
}
|
|
62
|
-
return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function transformSync(src, options) {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
const isModule = typeof src !== 'string' && !Buffer.isBuffer(src);
|
|
68
|
-
options = options || {};
|
|
69
|
-
if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
|
|
70
|
-
options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
|
|
71
|
-
}
|
|
72
|
-
return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
|
|
73
|
-
}
|
|
74
|
-
function toBuffer(t) {
|
|
75
|
-
return Buffer.from(JSON.stringify(t));
|
|
76
|
-
}
|
|
77
|
-
function minify(src, opts) {
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
exports.minify = minify;
|
|
83
|
-
function minifySync(src, opts) {
|
|
84
|
-
return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
|
|
85
|
-
}
|
|
86
|
-
exports.minifySync = minifySync;
|
|
87
|
-
function bundle(options) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
return bindings.bundle(toBuffer(options));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
exports.bundle = bundle;
|
|
93
|
-
module.exports.transform = transform;
|
|
94
|
-
module.exports.transformSync = transformSync;
|
|
Binary file
|