@rspack/test-tools 2.0.2 → 2.0.3
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/dist/case/builtin.js +106 -66
- package/dist/case/cache.js +136 -122
- package/dist/case/common.d.ts +4 -4
- package/dist/case/common.js +162 -157
- package/dist/case/compiler.d.ts +4 -4
- package/dist/case/compiler.js +75 -64
- package/dist/case/config.js +112 -74
- package/dist/case/defaults.js +136 -83
- package/dist/case/diagnostic.js +112 -84
- package/dist/case/error.d.ts +4 -4
- package/dist/case/error.js +105 -89
- package/dist/case/esm-output.js +118 -87
- package/dist/case/example.js +73 -35
- package/dist/case/hash.js +74 -59
- package/dist/case/hook.js +151 -138
- package/dist/case/hot-step.js +130 -161
- package/dist/case/hot.js +148 -134
- package/dist/case/incremental.js +91 -58
- package/dist/case/index.js +134 -51
- package/dist/case/multi-compiler.d.ts +4 -4
- package/dist/case/multi-compiler.js +81 -56
- package/dist/case/native-watcher.js +62 -30
- package/dist/case/normal.js +253 -185
- package/dist/case/runner.js +80 -51
- package/dist/case/serial.js +47 -16
- package/dist/case/stats-api.d.ts +4 -4
- package/dist/case/stats-api.js +63 -43
- package/dist/case/stats-output.d.ts +3 -3
- package/dist/case/stats-output.js +147 -152
- package/dist/case/treeshaking.js +66 -35
- package/dist/case/watch.d.ts +3 -19
- package/dist/case/watch.js +204 -224
- package/dist/compiler.js +222 -195
- package/dist/helper/directory.js +83 -71
- package/dist/helper/disable-iconv-lite-warning.js +35 -9
- package/dist/helper/expect/diff.js +39 -10
- package/dist/helper/expect/error.js +62 -30
- package/dist/helper/expect/placeholder.js +47 -21
- package/dist/helper/expect/rspack.js +35 -13
- package/dist/helper/expect/to-be-typeof.js +39 -7
- package/dist/helper/expect/to-end-with.js +40 -8
- package/dist/helper/expect/to-match-file-snapshot.js +103 -80
- package/dist/helper/hot-update/index.js +35 -4
- package/dist/helper/hot-update/loader.d.ts +1 -0
- package/dist/helper/hot-update/loader.js +39 -4
- package/dist/helper/hot-update/plugin.d.ts +1 -1
- package/dist/helper/hot-update/plugin.js +87 -74
- package/dist/helper/index.js +138 -24
- package/dist/helper/is.js +51 -10
- package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
- package/dist/helper/legacy/EventSourceForNode.js +83 -37
- package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
- package/dist/helper/legacy/LogTestPlugin.js +39 -6
- package/dist/helper/legacy/asModule.d.ts +3 -3
- package/dist/helper/legacy/asModule.js +68 -19
- package/dist/helper/legacy/captureStdio.d.ts +1 -2
- package/dist/helper/legacy/captureStdio.js +69 -29
- package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
- package/dist/helper/legacy/checkArrayExpectation.js +132 -121
- package/dist/helper/legacy/copyDiff.d.ts +1 -2
- package/dist/helper/legacy/copyDiff.js +86 -42
- package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
- package/dist/helper/legacy/createFakeWorker.js +90 -47
- package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
- package/dist/helper/legacy/createLazyTestEnv.js +70 -59
- package/dist/helper/legacy/currentScript.d.ts +2 -2
- package/dist/helper/legacy/currentScript.js +35 -2
- package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
- package/dist/helper/legacy/deprecationTracking.js +53 -28
- package/dist/helper/legacy/expectSource.d.ts +3 -2
- package/dist/helper/legacy/expectSource.js +42 -18
- package/dist/helper/legacy/fakeSystem.d.ts +12 -9
- package/dist/helper/legacy/fakeSystem.js +68 -58
- package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
- package/dist/helper/legacy/findOutputFiles.js +60 -13
- package/dist/helper/legacy/parseResource.d.ts +1 -1
- package/dist/helper/legacy/parseResource.js +36 -6
- package/dist/helper/legacy/regexEscape.d.ts +1 -2
- package/dist/helper/legacy/regexEscape.js +39 -5
- package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
- package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
- package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
- package/dist/helper/legacy/supportsTextDecoder.js +40 -6
- package/dist/helper/legacy/supportsUsing.d.ts +1 -2
- package/dist/helper/legacy/supportsUsing.js +40 -7
- package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
- package/dist/helper/legacy/urlToRelativePath.js +56 -7
- package/dist/helper/parse-modules.js +52 -42
- package/dist/helper/read-config-file.js +60 -18
- package/dist/helper/serializers.js +62 -33
- package/dist/helper/setup-env.js +81 -91
- package/dist/helper/setup-expect.js +13 -13
- package/dist/helper/setup-wasm.js +18 -9
- package/dist/helper/stringify-config.js +44 -26
- package/dist/helper/update-snapshot.js +35 -3
- package/dist/helper/util/checkSourceMap.js +119 -80
- package/dist/helper/util/checkStats.d.ts +1 -1
- package/dist/helper/util/checkStats.js +42 -17
- package/dist/helper/util/expectWarningFactory.d.ts +1 -2
- package/dist/helper/util/expectWarningFactory.js +41 -8
- package/dist/helper/util/filterUtil.d.ts +9 -8
- package/dist/helper/util/filterUtil.js +63 -23
- package/dist/helper/win.js +46 -7
- package/dist/index.js +115 -23
- package/dist/plugin/index.js +55 -14
- package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
- package/dist/reporter/index.js +55 -14
- package/dist/reporter/streamed-events-reporter.js +51 -77
- package/dist/runner/index.js +62 -15
- package/dist/runner/node/index.js +365 -431
- package/dist/runner/web/index.js +278 -263
- package/dist/test/context.js +67 -41
- package/dist/test/creator.js +135 -167
- package/dist/test/debug.js +89 -58
- package/dist/test/tester.js +94 -74
- package/dist/type.d.ts +10 -9
- package/dist/type.js +43 -9
- package/package.json +21 -20
|
@@ -1,108 +1,131 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
* @param content Output content to match
|
|
29
|
-
* @param filepath Path to the file to match against
|
|
30
|
-
* @param options Additional options for matching
|
|
31
|
-
*/
|
|
32
|
-
function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
33
|
-
const content = Buffer.isBuffer(rawContent)
|
|
34
|
-
? rawContent
|
|
35
|
-
: serialize(rawContent, /* ident */ 2, {
|
|
36
|
-
plugins: [
|
|
37
|
-
...getSerializers(),
|
|
38
|
-
// Rspack serializers
|
|
39
|
-
...serializers_1.serializers,
|
|
40
|
-
],
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
41
27
|
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
toMatchFileSnapshotSync: ()=>toMatchFileSnapshotSync
|
|
37
|
+
});
|
|
38
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
39
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
40
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
41
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
42
|
+
const external_chalk_namespaceObject = require("chalk");
|
|
43
|
+
var external_chalk_default = /*#__PURE__*/ __webpack_require__.n(external_chalk_namespaceObject);
|
|
44
|
+
const external_filenamify_namespaceObject = require("filenamify");
|
|
45
|
+
var external_filenamify_default = /*#__PURE__*/ __webpack_require__.n(external_filenamify_namespaceObject);
|
|
46
|
+
const external_jest_diff_namespaceObject = require("jest-diff");
|
|
47
|
+
const external_serializers_js_namespaceObject = require("../serializers.js");
|
|
48
|
+
const { serialize } = require(external_node_path_default().join(external_node_path_default().dirname(require.resolve('jest-snapshot')), './utils.js'));
|
|
49
|
+
const { getSerializers } = require(external_node_path_default().join(external_node_path_default().dirname(require.resolve('jest-snapshot')), './plugins.js'));
|
|
50
|
+
const isEqual = (a, b)=>Buffer.isBuffer(a) ? a.equals(b) : a === b;
|
|
51
|
+
function toMatchFileSnapshotSync(rawContent, filepath, options = {}) {
|
|
52
|
+
const content = Buffer.isBuffer(rawContent) ? rawContent : serialize(rawContent, 2, {
|
|
53
|
+
plugins: [
|
|
54
|
+
...getSerializers(),
|
|
55
|
+
...external_serializers_js_namespaceObject.serializers
|
|
56
|
+
]
|
|
57
|
+
});
|
|
42
58
|
const { isNot, snapshotState } = this;
|
|
43
|
-
const filename =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}).replace(/\s/g, '-')}-${this.assertionCalls}`)
|
|
48
|
-
: filepath;
|
|
49
|
-
if (snapshotState._updateSnapshot === 'none' && !node_fs_1.default.existsSync(filename)) {
|
|
50
|
-
// We're probably running in CI environment
|
|
59
|
+
const filename = void 0 === filepath ? external_node_path_default().join(external_node_path_default().dirname(this.testPath), '__file_snapshots__', `${external_filenamify_default()(this.currentTestName, {
|
|
60
|
+
replacement: '-'
|
|
61
|
+
}).replace(/\s/g, '-')}-${this.assertionCalls}`) : filepath;
|
|
62
|
+
if ('none' === snapshotState._updateSnapshot && !external_node_fs_default().existsSync(filename)) {
|
|
51
63
|
snapshotState.unmatched++;
|
|
52
64
|
return {
|
|
53
65
|
pass: isNot,
|
|
54
|
-
message: ()
|
|
66
|
+
message: ()=>`New output file ${external_chalk_default().blue(external_node_path_default().basename(filename))} was ${external_chalk_default().bold.red('not written')}.\n\nThe update flag must be explicitly passed to write a new snapshot.\n\nThis is likely because this test is run in a ${external_chalk_default().blue('continuous integration (CI) environment')} in which snapshots are not written by default.\n\n`
|
|
55
67
|
};
|
|
56
68
|
}
|
|
57
|
-
if (
|
|
58
|
-
const output =
|
|
59
|
-
.readFileSync(filename, Buffer.isBuffer(content) ? null : 'utf8')
|
|
60
|
-
.replace(/\r\n/g, '\n');
|
|
69
|
+
if (external_node_fs_default().existsSync(filename)) {
|
|
70
|
+
const output = external_node_fs_default().readFileSync(filename, Buffer.isBuffer(content) ? null : 'utf8').replace(/\r\n/g, '\n');
|
|
61
71
|
if (isNot) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
72
|
+
if (!isEqual(content, output)) return {
|
|
73
|
+
pass: false,
|
|
74
|
+
message: ()=>''
|
|
75
|
+
};
|
|
67
76
|
snapshotState.unmatched++;
|
|
68
77
|
return {
|
|
69
78
|
pass: true,
|
|
70
|
-
message: ()
|
|
79
|
+
message: ()=>`Expected received content ${external_chalk_default().red('to not match')} the file ${external_chalk_default().blue(external_node_path_default().basename(filename))}.`
|
|
71
80
|
};
|
|
72
81
|
}
|
|
73
|
-
if (isEqual(content, output)) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
if (isEqual(content, output)) return {
|
|
83
|
+
pass: true,
|
|
84
|
+
message: ()=>''
|
|
85
|
+
};
|
|
86
|
+
if ('all' === snapshotState._updateSnapshot) {
|
|
87
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(filename), {
|
|
88
|
+
recursive: true
|
|
89
|
+
});
|
|
90
|
+
external_node_fs_default().writeFileSync(filename, content);
|
|
79
91
|
snapshotState.updated++;
|
|
80
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
pass: true,
|
|
94
|
+
message: ()=>''
|
|
95
|
+
};
|
|
81
96
|
}
|
|
82
97
|
snapshotState.unmatched++;
|
|
83
|
-
const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output)
|
|
84
|
-
|
|
85
|
-
:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
aAnnotation: 'Snapshot',
|
|
89
|
-
}, options.diff || {}))}`;
|
|
98
|
+
const difference = Buffer.isBuffer(content) || Buffer.isBuffer(output) ? '' : `\n\n${(0, external_jest_diff_namespaceObject.diff)(output, content, Object.assign({
|
|
99
|
+
expand: false,
|
|
100
|
+
contextLines: 5,
|
|
101
|
+
aAnnotation: 'Snapshot'
|
|
102
|
+
}, options.diff || {}))}`;
|
|
90
103
|
return {
|
|
91
104
|
pass: false,
|
|
92
|
-
message: ()
|
|
105
|
+
message: ()=>`Received content ${external_chalk_default().red("doesn't match")} the file ${external_chalk_default().blue(external_node_path_default().basename(filename))}.${difference}`
|
|
93
106
|
};
|
|
94
107
|
}
|
|
95
|
-
if (!isNot &&
|
|
96
|
-
(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
108
|
+
if (!isNot && ('new' === snapshotState._updateSnapshot || 'all' === snapshotState._updateSnapshot)) {
|
|
109
|
+
external_node_fs_default().mkdirSync(external_node_path_default().dirname(filename), {
|
|
110
|
+
recursive: true
|
|
111
|
+
});
|
|
112
|
+
external_node_fs_default().writeFileSync(filename, content);
|
|
100
113
|
snapshotState.added++;
|
|
101
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
pass: true,
|
|
116
|
+
message: ()=>''
|
|
117
|
+
};
|
|
102
118
|
}
|
|
103
119
|
snapshotState.unmatched++;
|
|
104
120
|
return {
|
|
105
121
|
pass: true,
|
|
106
|
-
message: ()
|
|
122
|
+
message: ()=>`The output file ${external_chalk_default().blue(external_node_path_default().basename(filename))} ${external_chalk_default().bold.red("doesn't exist")}.`
|
|
107
123
|
};
|
|
108
124
|
}
|
|
125
|
+
exports.toMatchFileSnapshotSync = __webpack_exports__.toMatchFileSnapshotSync;
|
|
126
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
127
|
+
"toMatchFileSnapshotSync"
|
|
128
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
129
|
+
Object.defineProperty(exports, '__esModule', {
|
|
130
|
+
value: true
|
|
131
|
+
});
|
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
HotUpdatePlugin: ()=>external_plugin_js_namespaceObject.HotUpdatePlugin
|
|
28
|
+
});
|
|
29
|
+
const external_plugin_js_namespaceObject = require("./plugin.js");
|
|
30
|
+
exports.HotUpdatePlugin = __webpack_exports__.HotUpdatePlugin;
|
|
31
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
32
|
+
"HotUpdatePlugin"
|
|
33
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
34
|
+
Object.defineProperty(exports, '__esModule', {
|
|
35
|
+
value: true
|
|
36
|
+
});
|
|
@@ -1,7 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>__rspack_default_export,
|
|
28
|
+
loader: ()=>loader
|
|
29
|
+
});
|
|
30
|
+
const loader = function(c) {
|
|
4
31
|
return c.replace(/NEXT_HMR/g, 'NEXT_HMR.bind(null, module)');
|
|
5
32
|
};
|
|
6
|
-
|
|
7
|
-
exports
|
|
33
|
+
const __rspack_default_export = loader;
|
|
34
|
+
exports["default"] = __webpack_exports__["default"];
|
|
35
|
+
exports.loader = __webpack_exports__.loader;
|
|
36
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
37
|
+
"default",
|
|
38
|
+
"loader"
|
|
39
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
40
|
+
Object.defineProperty(exports, '__esModule', {
|
|
41
|
+
value: true
|
|
42
|
+
});
|
|
@@ -1,39 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
HotUpdatePlugin: ()=>HotUpdatePlugin
|
|
37
|
+
});
|
|
38
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
39
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
40
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
41
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
42
|
+
const external_rimraf_namespaceObject = require("rimraf");
|
|
10
43
|
async function loopFile(dir, callback) {
|
|
11
|
-
const children = await
|
|
12
|
-
await Promise.all(children.map(async (filename)
|
|
13
|
-
const filePath =
|
|
14
|
-
const stat = await
|
|
44
|
+
const children = await external_fs_extra_default().readdir(dir);
|
|
45
|
+
await Promise.all(children.map(async (filename)=>{
|
|
46
|
+
const filePath = external_node_path_default().join(dir, filename);
|
|
47
|
+
const stat = await external_fs_extra_default().stat(filePath);
|
|
15
48
|
if (stat.isFile()) {
|
|
16
|
-
const content = await
|
|
49
|
+
const content = await external_fs_extra_default().readFile(filePath);
|
|
17
50
|
callback(filePath, content.toString());
|
|
18
|
-
}
|
|
19
|
-
else if (stat.isDirectory()) {
|
|
20
|
-
return loopFile(filePath, callback);
|
|
21
|
-
}
|
|
51
|
+
} else if (stat.isDirectory()) return loopFile(filePath, callback);
|
|
22
52
|
}));
|
|
23
53
|
}
|
|
24
54
|
const PLUGIN_NAME = 'HotUpdatePlugin';
|
|
25
55
|
const MAX_UPDATE_INDEX = 100;
|
|
26
56
|
class HotUpdatePlugin {
|
|
27
|
-
|
|
57
|
+
projectDir;
|
|
58
|
+
tempDir;
|
|
59
|
+
initialized = false;
|
|
60
|
+
updateIndex = 0;
|
|
61
|
+
files = {};
|
|
62
|
+
constructor(projectDir, tempDir){
|
|
28
63
|
this.projectDir = projectDir;
|
|
29
64
|
this.tempDir = tempDir;
|
|
30
|
-
this.initialized = false;
|
|
31
|
-
this.updateIndex = 0;
|
|
32
|
-
this.files = {};
|
|
33
65
|
}
|
|
34
66
|
getContent(filePath, index) {
|
|
35
67
|
const contents = this.files[filePath] || [];
|
|
36
|
-
let content = contents[index]
|
|
68
|
+
let content = void 0 === contents[index] ? contents.at(-1) || '' : contents[index];
|
|
37
69
|
let command = '';
|
|
38
70
|
const matchResult = content.match(/^<(.+?)>([\w\W]*)$/);
|
|
39
71
|
if (matchResult) {
|
|
@@ -42,41 +74,27 @@ class HotUpdatePlugin {
|
|
|
42
74
|
}
|
|
43
75
|
return {
|
|
44
76
|
content,
|
|
45
|
-
command
|
|
77
|
+
command
|
|
46
78
|
};
|
|
47
79
|
}
|
|
48
80
|
async updateFiles() {
|
|
49
|
-
await Promise.all(this.getModifiedFiles().map(async (filePath)
|
|
81
|
+
await Promise.all(this.getModifiedFiles().map(async (filePath)=>{
|
|
50
82
|
const { content, command } = this.getContent(filePath, this.updateIndex);
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
await fs_extra_1.default.remove(filePath);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (command === 'force_write') {
|
|
57
|
-
await fs_extra_1.default.writeFile(filePath, content);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
// default
|
|
83
|
+
if ('delete' === command) return void await external_fs_extra_default().remove(filePath);
|
|
84
|
+
if ('force_write' === command) return void await external_fs_extra_default().writeFile(filePath, content);
|
|
61
85
|
const { content: oldContent } = this.getContent(filePath, this.updateIndex - 1);
|
|
62
|
-
if (this.updateIndex
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
await fs_extra_1.default.writeFile(filePath, content);
|
|
86
|
+
if (0 !== this.updateIndex && content === oldContent) return;
|
|
87
|
+
await external_fs_extra_default().writeFile(filePath, content);
|
|
66
88
|
}));
|
|
67
89
|
}
|
|
68
90
|
async initialize() {
|
|
69
|
-
if (this.initialized)
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
91
|
+
if (this.initialized) return;
|
|
72
92
|
this.initialized = true;
|
|
73
|
-
(0,
|
|
74
|
-
|
|
75
|
-
await loopFile(this.tempDir, (filePath, content)
|
|
93
|
+
(0, external_rimraf_namespaceObject.rimrafSync)(this.tempDir);
|
|
94
|
+
external_fs_extra_default().copySync(this.projectDir, this.tempDir);
|
|
95
|
+
await loopFile(this.tempDir, (filePath, content)=>{
|
|
76
96
|
const contents = content.split(/---+\r?\n/g);
|
|
77
|
-
if (contents.length > 1)
|
|
78
|
-
this.files[filePath] = contents;
|
|
79
|
-
}
|
|
97
|
+
if (contents.length > 1) this.files[filePath] = contents;
|
|
80
98
|
});
|
|
81
99
|
await this.updateFiles();
|
|
82
100
|
}
|
|
@@ -87,31 +105,22 @@ class HotUpdatePlugin {
|
|
|
87
105
|
return this.updateIndex;
|
|
88
106
|
}
|
|
89
107
|
getTotalUpdates() {
|
|
90
|
-
return Object.values(this.files).reduce((max, item)
|
|
91
|
-
return Math.max(max, item.length);
|
|
92
|
-
}, 1);
|
|
108
|
+
return Object.values(this.files).reduce((max, item)=>Math.max(max, item.length), 1);
|
|
93
109
|
}
|
|
94
110
|
async goNext() {
|
|
95
|
-
if (this.updateIndex > MAX_UPDATE_INDEX)
|
|
96
|
-
throw new Error('NEXT_* has been called more than the maximum times');
|
|
97
|
-
}
|
|
111
|
+
if (this.updateIndex > MAX_UPDATE_INDEX) throw new Error('NEXT_* has been called more than the maximum times');
|
|
98
112
|
this.updateIndex++;
|
|
99
113
|
await this.updateFiles();
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
'___' +
|
|
105
|
-
this.updateIndex;
|
|
106
|
-
// update this.files.
|
|
107
|
-
for (const key of Object.keys(this.files)) {
|
|
115
|
+
moveTempDir() {
|
|
116
|
+
const nextTempDir = this.tempDir.replace(/(___[0-9]+)?[/\\]*$/, '') + '___' + this.updateIndex;
|
|
117
|
+
for (const key of Object.keys(this.files)){
|
|
108
118
|
const nextKey = key.replace(this.tempDir, nextTempDir);
|
|
109
119
|
this.files[nextKey] = this.files[key];
|
|
110
120
|
delete this.files[key];
|
|
111
121
|
}
|
|
112
|
-
|
|
113
|
-
(
|
|
114
|
-
fs_extra_1.default.renameSync(this.tempDir, nextTempDir);
|
|
122
|
+
(0, external_rimraf_namespaceObject.rimrafSync)(nextTempDir);
|
|
123
|
+
external_fs_extra_default().renameSync(this.tempDir, nextTempDir);
|
|
115
124
|
this.tempDir = nextTempDir;
|
|
116
125
|
return this.tempDir;
|
|
117
126
|
}
|
|
@@ -124,22 +133,21 @@ class HotUpdatePlugin {
|
|
|
124
133
|
test: /\.(js|css|json)/,
|
|
125
134
|
use: [
|
|
126
135
|
{
|
|
127
|
-
loader:
|
|
128
|
-
}
|
|
129
|
-
]
|
|
136
|
+
loader: external_node_path_default().resolve(__dirname, './loader.js')
|
|
137
|
+
}
|
|
138
|
+
]
|
|
130
139
|
});
|
|
131
140
|
let isRebuild = false;
|
|
132
|
-
compiler.hooks.beforeRun.tap(PLUGIN_NAME, ()
|
|
141
|
+
compiler.hooks.beforeRun.tap(PLUGIN_NAME, ()=>{
|
|
133
142
|
compiler.modifiedFiles = new Set(isRebuild ? this.getModifiedFiles() : []);
|
|
134
143
|
isRebuild = true;
|
|
135
144
|
});
|
|
136
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)
|
|
137
|
-
compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_chunk, set)
|
|
145
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
|
|
146
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap(PLUGIN_NAME, (_chunk, set)=>{
|
|
138
147
|
set.add(compiler.rspack.RuntimeGlobals.moduleCache);
|
|
139
148
|
});
|
|
140
|
-
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module, _set)
|
|
141
|
-
if (module.constructor.name
|
|
142
|
-
module.source.source = Buffer.from(`
|
|
149
|
+
compilation.hooks.runtimeModule.tap(PLUGIN_NAME, (module, _set)=>{
|
|
150
|
+
if ('DefinePropertyGettersRuntimeModule' === module.constructor.name) module.source.source = Buffer.from(`
|
|
143
151
|
${RuntimeGlobals.definePropertyGetters} = function (exports, definition) {
|
|
144
152
|
for (var key in definition) {
|
|
145
153
|
if (${RuntimeGlobals.hasOwnProperty}(definition, key) && !${RuntimeGlobals.hasOwnProperty}(exports, key)) {
|
|
@@ -148,9 +156,14 @@ class HotUpdatePlugin {
|
|
|
148
156
|
}
|
|
149
157
|
};
|
|
150
158
|
`, 'utf-8');
|
|
151
|
-
}
|
|
152
159
|
});
|
|
153
160
|
});
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
|
-
exports.HotUpdatePlugin = HotUpdatePlugin;
|
|
163
|
+
exports.HotUpdatePlugin = __webpack_exports__.HotUpdatePlugin;
|
|
164
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
165
|
+
"HotUpdatePlugin"
|
|
166
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
167
|
+
Object.defineProperty(exports, '__esModule', {
|
|
168
|
+
value: true
|
|
169
|
+
});
|