@rspack/test-tools 2.0.1 → 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.
Files changed (118) hide show
  1. package/dist/case/builtin.js +106 -66
  2. package/dist/case/cache.js +152 -132
  3. package/dist/case/common.d.ts +4 -4
  4. package/dist/case/common.js +162 -157
  5. package/dist/case/compiler.d.ts +4 -4
  6. package/dist/case/compiler.js +75 -64
  7. package/dist/case/config.js +112 -74
  8. package/dist/case/defaults.js +136 -83
  9. package/dist/case/diagnostic.js +112 -84
  10. package/dist/case/error.d.ts +4 -4
  11. package/dist/case/error.js +105 -89
  12. package/dist/case/esm-output.js +118 -87
  13. package/dist/case/example.js +73 -35
  14. package/dist/case/hash.js +74 -59
  15. package/dist/case/hook.js +151 -138
  16. package/dist/case/hot-step.js +130 -161
  17. package/dist/case/hot.js +148 -134
  18. package/dist/case/incremental.js +91 -58
  19. package/dist/case/index.js +134 -51
  20. package/dist/case/multi-compiler.d.ts +4 -4
  21. package/dist/case/multi-compiler.js +81 -56
  22. package/dist/case/native-watcher.js +62 -30
  23. package/dist/case/normal.js +253 -185
  24. package/dist/case/runner.js +80 -51
  25. package/dist/case/serial.js +47 -16
  26. package/dist/case/stats-api.d.ts +4 -4
  27. package/dist/case/stats-api.js +63 -43
  28. package/dist/case/stats-output.d.ts +3 -3
  29. package/dist/case/stats-output.js +147 -152
  30. package/dist/case/treeshaking.js +66 -35
  31. package/dist/case/watch.d.ts +3 -19
  32. package/dist/case/watch.js +204 -224
  33. package/dist/compiler.js +222 -195
  34. package/dist/helper/directory.js +83 -71
  35. package/dist/helper/disable-iconv-lite-warning.js +35 -9
  36. package/dist/helper/expect/diff.js +39 -10
  37. package/dist/helper/expect/error.js +62 -30
  38. package/dist/helper/expect/placeholder.js +47 -21
  39. package/dist/helper/expect/rspack.js +35 -13
  40. package/dist/helper/expect/to-be-typeof.js +39 -7
  41. package/dist/helper/expect/to-end-with.js +40 -8
  42. package/dist/helper/expect/to-match-file-snapshot.js +103 -80
  43. package/dist/helper/hot-update/index.js +35 -4
  44. package/dist/helper/hot-update/loader.d.ts +1 -0
  45. package/dist/helper/hot-update/loader.js +39 -4
  46. package/dist/helper/hot-update/plugin.d.ts +1 -1
  47. package/dist/helper/hot-update/plugin.js +87 -74
  48. package/dist/helper/index.js +138 -24
  49. package/dist/helper/is.js +51 -10
  50. package/dist/helper/legacy/EventSourceForNode.d.ts +11 -3
  51. package/dist/helper/legacy/EventSourceForNode.js +83 -37
  52. package/dist/helper/legacy/LogTestPlugin.d.ts +2 -3
  53. package/dist/helper/legacy/LogTestPlugin.js +39 -6
  54. package/dist/helper/legacy/asModule.d.ts +3 -3
  55. package/dist/helper/legacy/asModule.js +68 -19
  56. package/dist/helper/legacy/captureStdio.d.ts +1 -2
  57. package/dist/helper/legacy/captureStdio.js +69 -29
  58. package/dist/helper/legacy/checkArrayExpectation.d.ts +1 -2
  59. package/dist/helper/legacy/checkArrayExpectation.js +132 -121
  60. package/dist/helper/legacy/copyDiff.d.ts +1 -2
  61. package/dist/helper/legacy/copyDiff.js +86 -42
  62. package/dist/helper/legacy/createFakeWorker.d.ts +2 -3
  63. package/dist/helper/legacy/createFakeWorker.js +90 -47
  64. package/dist/helper/legacy/createLazyTestEnv.d.ts +2 -3
  65. package/dist/helper/legacy/createLazyTestEnv.js +70 -59
  66. package/dist/helper/legacy/currentScript.d.ts +2 -2
  67. package/dist/helper/legacy/currentScript.js +35 -2
  68. package/dist/helper/legacy/deprecationTracking.d.ts +1 -1
  69. package/dist/helper/legacy/deprecationTracking.js +53 -28
  70. package/dist/helper/legacy/expectSource.d.ts +3 -2
  71. package/dist/helper/legacy/expectSource.js +42 -18
  72. package/dist/helper/legacy/fakeSystem.d.ts +12 -9
  73. package/dist/helper/legacy/fakeSystem.js +68 -58
  74. package/dist/helper/legacy/findOutputFiles.d.ts +7 -2
  75. package/dist/helper/legacy/findOutputFiles.js +60 -13
  76. package/dist/helper/legacy/parseResource.d.ts +1 -1
  77. package/dist/helper/legacy/parseResource.js +36 -6
  78. package/dist/helper/legacy/regexEscape.d.ts +1 -2
  79. package/dist/helper/legacy/regexEscape.js +39 -5
  80. package/dist/helper/legacy/supportDefaultAssignment.d.ts +1 -2
  81. package/dist/helper/legacy/supportDefaultAssignment.js +40 -7
  82. package/dist/helper/legacy/supportsTextDecoder.d.ts +1 -2
  83. package/dist/helper/legacy/supportsTextDecoder.js +40 -6
  84. package/dist/helper/legacy/supportsUsing.d.ts +1 -2
  85. package/dist/helper/legacy/supportsUsing.js +40 -7
  86. package/dist/helper/legacy/urlToRelativePath.d.ts +2 -2
  87. package/dist/helper/legacy/urlToRelativePath.js +56 -7
  88. package/dist/helper/parse-modules.js +52 -42
  89. package/dist/helper/read-config-file.js +60 -18
  90. package/dist/helper/serializers.js +62 -33
  91. package/dist/helper/setup-env.js +81 -91
  92. package/dist/helper/setup-expect.js +13 -13
  93. package/dist/helper/setup-wasm.js +18 -9
  94. package/dist/helper/stringify-config.js +44 -26
  95. package/dist/helper/update-snapshot.js +35 -3
  96. package/dist/helper/util/checkSourceMap.js +119 -80
  97. package/dist/helper/util/checkStats.d.ts +1 -1
  98. package/dist/helper/util/checkStats.js +42 -17
  99. package/dist/helper/util/expectWarningFactory.d.ts +1 -2
  100. package/dist/helper/util/expectWarningFactory.js +41 -8
  101. package/dist/helper/util/filterUtil.d.ts +9 -8
  102. package/dist/helper/util/filterUtil.js +63 -23
  103. package/dist/helper/win.js +46 -7
  104. package/dist/index.js +115 -23
  105. package/dist/plugin/index.js +55 -14
  106. package/dist/plugin/lazy-compilation-test-plugin.js +55 -41
  107. package/dist/reporter/index.js +55 -14
  108. package/dist/reporter/streamed-events-reporter.js +51 -77
  109. package/dist/runner/index.js +62 -15
  110. package/dist/runner/node/index.js +365 -431
  111. package/dist/runner/web/index.js +278 -263
  112. package/dist/test/context.js +67 -41
  113. package/dist/test/creator.js +135 -167
  114. package/dist/test/debug.js +89 -58
  115. package/dist/test/tester.js +94 -74
  116. package/dist/type.d.ts +10 -9
  117. package/dist/type.js +43 -9
  118. package/package.json +24 -23
@@ -1,108 +1,131 @@
1
1
  "use strict";
2
- // @ts-nocheck
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.toMatchFileSnapshotSync = toMatchFileSnapshotSync;
8
- /* istanbul ignore file */
9
- const node_fs_1 = __importDefault(require("node:fs"));
10
- const node_path_1 = __importDefault(require("node:path"));
11
- const chalk_1 = __importDefault(require("chalk"));
12
- const filenamify_1 = __importDefault(require("filenamify"));
13
- const jest_diff_1 = require("jest-diff");
14
- const serializers_1 = require("../serializers");
15
- const { serialize } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve('jest-snapshot')), './utils.js'));
16
- // get jest builtin serializers
17
- const { getSerializers } = require(node_path_1.default.join(node_path_1.default.dirname(require.resolve('jest-snapshot')), './plugins.js'));
18
- /**
19
- * Check if 2 strings or buffer are equal
20
- */
21
- const isEqual = (a, b) => {
22
- // @ts-expect-error: TypeScript gives error if we pass string to buffer.equals
23
- return Buffer.isBuffer(a) ? a.equals(b) : a === b;
24
- };
25
- /**
26
- * Match given content against content of the specified file.
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 = filepath === undefined
44
- ? // If file name is not specified, generate one from the test title
45
- node_path_1.default.join(node_path_1.default.dirname(this.testPath), '__file_snapshots__', `${(0, filenamify_1.default)(this.currentTestName, {
46
- replacement: '-',
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: () => `New output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} was ${chalk_1.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 ${chalk_1.default.blue('continuous integration (CI) environment')} in which snapshots are not written by default.\n\n`,
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 (node_fs_1.default.existsSync(filename)) {
58
- const output = node_fs_1.default
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
- // The matcher is being used with `.not`
63
- if (!isEqual(content, output)) {
64
- // The value of `pass` is reversed when used with `.not`
65
- return { pass: false, message: () => '' };
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: () => `Expected received content ${chalk_1.default.red('to not match')} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.`,
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
- return { pass: true, message: () => '' };
75
- }
76
- if (snapshotState._updateSnapshot === 'all') {
77
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
78
- node_fs_1.default.writeFileSync(filename, content);
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 { pass: true, message: () => '' };
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
- : `\n\n${(0, jest_diff_1.diff)(output, content, Object.assign({
86
- expand: false,
87
- contextLines: 5,
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: () => `Received content ${chalk_1.default.red("doesn't match")} the file ${chalk_1.default.blue(node_path_1.default.basename(filename))}.${difference}`,
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
- (snapshotState._updateSnapshot === 'new' ||
97
- snapshotState._updateSnapshot === 'all')) {
98
- node_fs_1.default.mkdirSync(node_path_1.default.dirname(filename), { recursive: true });
99
- node_fs_1.default.writeFileSync(filename, content);
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 { pass: true, message: () => '' };
114
+ return {
115
+ pass: true,
116
+ message: ()=>''
117
+ };
102
118
  }
103
119
  snapshotState.unmatched++;
104
120
  return {
105
121
  pass: true,
106
- message: () => `The output file ${chalk_1.default.blue(node_path_1.default.basename(filename))} ${chalk_1.default.bold.red("doesn't exist")}.`,
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
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HotUpdatePlugin = void 0;
4
- var plugin_1 = require("./plugin");
5
- Object.defineProperty(exports, "HotUpdatePlugin", { enumerable: true, get: function () { return plugin_1.HotUpdatePlugin; } });
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,2 +1,3 @@
1
1
  declare const loader: (c: string) => string;
2
+ export { loader };
2
3
  export default loader;
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader = function (c) {
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
- module.exports = loader;
7
- exports.default = loader;
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
+ });
@@ -13,6 +13,6 @@ export declare class HotUpdatePlugin {
13
13
  getUpdateIndex(): number;
14
14
  getTotalUpdates(): number;
15
15
  goNext(): Promise<void>;
16
- moveTempDir(): Promise<string>;
16
+ moveTempDir(): string;
17
17
  apply(compiler: Compiler): void;
18
18
  }
@@ -1,39 +1,71 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HotUpdatePlugin = void 0;
7
- const node_path_1 = __importDefault(require("node:path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const rimraf_1 = require("rimraf");
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 fs_extra_1.default.readdir(dir);
12
- await Promise.all(children.map(async (filename) => {
13
- const filePath = node_path_1.default.join(dir, filename);
14
- const stat = await fs_extra_1.default.stat(filePath);
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 fs_extra_1.default.readFile(filePath);
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
- constructor(projectDir, tempDir) {
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] === undefined ? contents.at(-1) || '' : 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
- // match command
52
- if (command === 'delete') {
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 !== 0 && content === oldContent) {
63
- return;
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, rimraf_1.rimrafSync)(this.tempDir);
74
- fs_extra_1.default.copySync(this.projectDir, this.tempDir);
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
- async moveTempDir() {
102
- // generate next temp dir path.
103
- const nextTempDir = this.tempDir.replace(/(___[0-9]+)?[/\\]*$/, '') +
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
- // move files.
113
- (0, rimraf_1.rimrafSync)(nextTempDir);
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: node_path_1.default.resolve(__dirname, './loader.js'),
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 === 'DefinePropertyGettersRuntimeModule') {
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
+ });