@rspack/core 0.0.6 → 0.0.8

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 (223) hide show
  1. package/dist/compilation.d.ts +64 -0
  2. package/dist/compilation.d.ts.map +1 -0
  3. package/dist/compilation.js +148 -0
  4. package/dist/compilation.js.map +1 -0
  5. package/dist/compiler.d.ts +52 -0
  6. package/dist/compiler.d.ts.map +1 -0
  7. package/dist/compiler.js +383 -0
  8. package/dist/compiler.js.map +1 -0
  9. package/dist/config/RspackOptions.d.ts +36 -0
  10. package/dist/config/RspackOptions.d.ts.map +1 -0
  11. package/{lib/config/define.js → dist/config/RspackOptions.js} +1 -0
  12. package/dist/config/RspackOptions.js.map +1 -0
  13. package/dist/config/browserslistTargetHandler.d.ts +20 -0
  14. package/dist/config/browserslistTargetHandler.d.ts.map +1 -0
  15. package/dist/config/browserslistTargetHandler.js +320 -0
  16. package/dist/config/browserslistTargetHandler.js.map +1 -0
  17. package/dist/config/builtins.d.ts +15 -0
  18. package/dist/config/builtins.d.ts.map +1 -0
  19. package/dist/config/builtins.js +49 -0
  20. package/dist/config/builtins.js.map +1 -0
  21. package/{lib → dist}/config/context.d.ts +1 -0
  22. package/dist/config/context.d.ts.map +1 -0
  23. package/{lib → dist}/config/context.js +1 -0
  24. package/dist/config/context.js.map +1 -0
  25. package/dist/config/defaults.d.ts +4 -0
  26. package/dist/config/defaults.d.ts.map +1 -0
  27. package/dist/config/defaults.js +57 -0
  28. package/dist/config/defaults.js.map +1 -0
  29. package/dist/config/devServer.d.ts +21 -0
  30. package/dist/config/devServer.d.ts.map +1 -0
  31. package/{lib/config/builtins.js → dist/config/devServer.js} +1 -0
  32. package/dist/config/devServer.js.map +1 -0
  33. package/dist/config/devtool.d.ts +5 -0
  34. package/dist/config/devtool.d.ts.map +1 -0
  35. package/dist/config/devtool.js +13 -0
  36. package/dist/config/devtool.js.map +1 -0
  37. package/dist/config/entry.d.ts +8 -0
  38. package/dist/config/entry.d.ts.map +1 -0
  39. package/dist/config/entry.js +39 -0
  40. package/dist/config/entry.js.map +1 -0
  41. package/dist/config/external.d.ts +5 -0
  42. package/dist/config/external.d.ts.map +1 -0
  43. package/{lib → dist}/config/external.js +1 -0
  44. package/dist/config/external.js.map +1 -0
  45. package/dist/config/index.d.ts +57 -0
  46. package/dist/config/index.d.ts.map +1 -0
  47. package/dist/config/index.js +55 -0
  48. package/dist/config/index.js.map +1 -0
  49. package/{lib → dist}/config/mode.d.ts +1 -0
  50. package/dist/config/mode.d.ts.map +1 -0
  51. package/{lib → dist}/config/mode.js +1 -0
  52. package/dist/config/mode.js.map +1 -0
  53. package/{lib → dist}/config/module.d.ts +22 -7
  54. package/dist/config/module.d.ts.map +1 -0
  55. package/{lib → dist}/config/module.js +29 -21
  56. package/dist/config/module.js.map +1 -0
  57. package/{lib → dist}/config/output.d.ts +6 -0
  58. package/dist/config/output.d.ts.map +1 -0
  59. package/dist/config/output.js +10 -0
  60. package/dist/config/output.js.map +1 -0
  61. package/dist/config/plugin.d.ts +6 -0
  62. package/dist/config/plugin.d.ts.map +1 -0
  63. package/{lib → dist}/config/plugin.js +1 -0
  64. package/dist/config/plugin.js.map +1 -0
  65. package/dist/config/resolve.d.ts +22 -0
  66. package/dist/config/resolve.d.ts.map +1 -0
  67. package/dist/config/resolve.js +33 -0
  68. package/dist/config/resolve.js.map +1 -0
  69. package/dist/config/stats.d.ts +21 -0
  70. package/dist/config/stats.d.ts.map +1 -0
  71. package/dist/config/stats.js +17 -0
  72. package/dist/config/stats.js.map +1 -0
  73. package/dist/config/target.d.ts +7 -0
  74. package/dist/config/target.d.ts.map +1 -0
  75. package/dist/config/target.js +21 -0
  76. package/dist/config/target.js.map +1 -0
  77. package/dist/config/watch.d.ts +8 -0
  78. package/dist/config/watch.d.ts.map +1 -0
  79. package/dist/config/watch.js +16 -0
  80. package/dist/config/watch.js.map +1 -0
  81. package/dist/index.d.ts +4 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +20 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/logging/Logger.d.ts +43 -0
  86. package/dist/logging/Logger.d.ts.map +1 -0
  87. package/dist/logging/Logger.js +136 -0
  88. package/dist/logging/Logger.js.map +1 -0
  89. package/dist/logging/createConsoleLogger.d.ts +7 -0
  90. package/dist/logging/createConsoleLogger.d.ts.map +1 -0
  91. package/dist/logging/createConsoleLogger.js +227 -0
  92. package/dist/logging/createConsoleLogger.js.map +1 -0
  93. package/dist/logging/runtime.d.ts +14 -0
  94. package/dist/logging/runtime.d.ts.map +1 -0
  95. package/dist/logging/runtime.js +42 -0
  96. package/dist/logging/runtime.js.map +1 -0
  97. package/dist/logging/truncateArgs.d.ts +8 -0
  98. package/dist/logging/truncateArgs.d.ts.map +1 -0
  99. package/dist/logging/truncateArgs.js +81 -0
  100. package/dist/logging/truncateArgs.js.map +1 -0
  101. package/dist/node/NodeTargetPlugin.d.ts +5 -0
  102. package/dist/node/NodeTargetPlugin.d.ts.map +1 -0
  103. package/dist/node/NodeTargetPlugin.js +70 -0
  104. package/dist/node/NodeTargetPlugin.js.map +1 -0
  105. package/dist/node/nodeConsole.d.ts +22 -0
  106. package/dist/node/nodeConsole.d.ts.map +1 -0
  107. package/dist/node/nodeConsole.js +121 -0
  108. package/dist/node/nodeConsole.js.map +1 -0
  109. package/dist/rspack.d.ts +8 -0
  110. package/dist/rspack.d.ts.map +1 -0
  111. package/dist/rspack.js +59 -0
  112. package/dist/rspack.js.map +1 -0
  113. package/dist/rspackOptionsApply.d.ts +6 -0
  114. package/dist/rspackOptionsApply.d.ts.map +1 -0
  115. package/dist/rspackOptionsApply.js +25 -0
  116. package/dist/rspackOptionsApply.js.map +1 -0
  117. package/dist/stats.d.ts +21 -0
  118. package/dist/stats.d.ts.map +1 -0
  119. package/dist/stats.js +870 -0
  120. package/dist/stats.js.map +1 -0
  121. package/dist/utils/createHash.d.ts +7 -0
  122. package/dist/utils/createHash.d.ts.map +1 -0
  123. package/dist/utils/createHash.js +166 -0
  124. package/dist/utils/createHash.js.map +1 -0
  125. package/dist/utils/createSource.d.ts +6 -0
  126. package/dist/utils/createSource.d.ts.map +1 -0
  127. package/dist/utils/createSource.js +48 -0
  128. package/dist/utils/createSource.js.map +1 -0
  129. package/dist/utils/hash/BatchedHash.d.ts +16 -0
  130. package/dist/utils/hash/BatchedHash.d.ts.map +1 -0
  131. package/dist/utils/hash/BatchedHash.js +61 -0
  132. package/dist/utils/hash/BatchedHash.js.map +1 -0
  133. package/dist/utils/hash/index.d.ts +19 -0
  134. package/dist/utils/hash/index.d.ts.map +1 -0
  135. package/dist/utils/hash/index.js +28 -0
  136. package/dist/utils/hash/index.js.map +1 -0
  137. package/dist/utils/hash/md4.d.ts +3 -0
  138. package/dist/utils/hash/md4.d.ts.map +1 -0
  139. package/dist/utils/hash/md4.js +13 -0
  140. package/dist/utils/hash/md4.js.map +1 -0
  141. package/dist/utils/hash/wasm-hash.d.ts +7 -0
  142. package/dist/utils/hash/wasm-hash.d.ts.map +1 -0
  143. package/dist/utils/hash/wasm-hash.js +162 -0
  144. package/dist/utils/hash/wasm-hash.js.map +1 -0
  145. package/dist/utils/hash/xxhash64.d.ts +3 -0
  146. package/dist/utils/hash/xxhash64.d.ts.map +1 -0
  147. package/dist/utils/hash/xxhash64.js +13 -0
  148. package/dist/utils/hash/xxhash64.js.map +1 -0
  149. package/dist/utils/index.d.ts +4 -0
  150. package/dist/utils/index.d.ts.map +1 -0
  151. package/dist/utils/index.js +8 -0
  152. package/dist/utils/index.js.map +1 -0
  153. package/dist/utils/memoize.d.ts +2 -0
  154. package/dist/utils/memoize.d.ts.map +1 -0
  155. package/dist/utils/memoize.js +22 -0
  156. package/dist/utils/memoize.js.map +1 -0
  157. package/dist/web/polyfillBuiltins.d.ts +5 -0
  158. package/dist/web/polyfillBuiltins.d.ts.map +1 -0
  159. package/dist/web/polyfillBuiltins.js +43 -0
  160. package/dist/web/polyfillBuiltins.js.map +1 -0
  161. package/package.json +28 -23
  162. package/CHANGELOG.md +0 -41
  163. package/bin.js +0 -1
  164. package/example/basic.ts +0 -71
  165. package/example/react-example/index.html +0 -12
  166. package/example/react-example/package.json +0 -17
  167. package/example/react-example/rspack.config.json +0 -13
  168. package/example/react-example/src/app.jsx +0 -44
  169. package/example/react-example/src/base.css +0 -9
  170. package/example/react-example/src/button.jsx +0 -3
  171. package/example/react-example/src/dark.svg +0 -1
  172. package/example/react-example/src/data.json +0 -5
  173. package/example/react-example/src/file.jpg +0 -0
  174. package/example/react-example/src/file.png +0 -0
  175. package/example/react-example/src/file.svg +0 -1
  176. package/example/react-example/src/foo.css +0 -3
  177. package/example/react-example/src/index.html +0 -32
  178. package/example/react-example/src/index.js +0 -1
  179. package/example/react-example/src/light.svg +0 -48
  180. package/example/react-example/src/logo.svg +0 -18
  181. package/example/react-with-sass.ts +0 -28
  182. package/lib/bin/index.d.ts +0 -1
  183. package/lib/bin/index.js +0 -32
  184. package/lib/build.d.ts +0 -1
  185. package/lib/build.js +0 -12
  186. package/lib/config/builtins.d.ts +0 -3
  187. package/lib/config/define.d.ts +0 -2
  188. package/lib/config/dev.d.ts +0 -17
  189. package/lib/config/dev.js +0 -17
  190. package/lib/config/entry.d.ts +0 -2
  191. package/lib/config/entry.js +0 -2
  192. package/lib/config/external.d.ts +0 -2
  193. package/lib/config/index.d.ts +0 -45
  194. package/lib/config/index.js +0 -37
  195. package/lib/config/output.js +0 -14
  196. package/lib/config/plugin.d.ts +0 -5
  197. package/lib/config/resolve.d.ts +0 -6
  198. package/lib/config/resolve.js +0 -2
  199. package/lib/config/target.d.ts +0 -5
  200. package/lib/config/target.js +0 -13
  201. package/lib/index.d.ts +0 -39
  202. package/lib/index.js +0 -154
  203. package/lib/server/index.d.ts +0 -0
  204. package/lib/server/index.js +0 -0
  205. package/src/bin/index.ts +0 -36
  206. package/src/build.ts +0 -8
  207. package/src/config/builtins.ts +0 -5
  208. package/src/config/context.ts +0 -3
  209. package/src/config/define.ts +0 -3
  210. package/src/config/dev.ts +0 -32
  211. package/src/config/entry.ts +0 -3
  212. package/src/config/external.ts +0 -3
  213. package/src/config/index.ts +0 -80
  214. package/src/config/mode.ts +0 -2
  215. package/src/config/module.ts +0 -240
  216. package/src/config/output.ts +0 -29
  217. package/src/config/plugin.ts +0 -6
  218. package/src/config/resolve.ts +0 -6
  219. package/src/config/target.ts +0 -28
  220. package/src/index.ts +0 -140
  221. package/src/server/index.ts +0 -0
  222. package/tests/config.test.ts +0 -40
  223. package/tsconfig.json +0 -14
@@ -0,0 +1,64 @@
1
+ import * as tapable from "tapable";
2
+ import { Source } from "webpack-sources";
3
+ import { JsCompilation, AssetInfo } from "@rspack/binding";
4
+ import { RspackOptionsNormalized } from "./config";
5
+ export declare class Compilation {
6
+ #private;
7
+ hooks: {
8
+ processAssets: tapable.AsyncSeriesHook<Record<string, Source>>;
9
+ };
10
+ fullHash: string;
11
+ hash: string;
12
+ options: RspackOptionsNormalized;
13
+ constructor(options: RspackOptionsNormalized, inner: JsCompilation);
14
+ /**
15
+ * Get a map of all assets.
16
+ *
17
+ * Source: [assets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L1008-L1009)
18
+ */
19
+ get assets(): Record<string, Source>;
20
+ /**
21
+ * Update an existing asset. Trying to update an asset that doesn't exist will throw an error.
22
+ *
23
+ * See: [Compilation.updateAsset](https://webpack.js.org/api/compilation-object/#updateasset)
24
+ * Source: [updateAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4320)
25
+ *
26
+ * FIXME: *AssetInfo* may be undefined in update fn for webpack impl, but still not implemented in rspack
27
+ *
28
+ * @param {string} file file name
29
+ * @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new
30
+ * @param {AssetInfo | function(AssetInfo): AssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new
31
+ */
32
+ updateAsset(filename: string, newSourceOrFunction: Source | ((source: Source) => Source), assetInfoUpdateOrFunction: AssetInfo | ((assetInfo: AssetInfo) => AssetInfo)): void;
33
+ /**
34
+ * Emit an not existing asset. Trying to emit an asset that already exists will throw an error.
35
+ *
36
+ * See: [Compilation.emitAsset](https://webpack.js.org/api/compilation-object/#emitasset)
37
+ * Source: [emitAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4239)
38
+ *
39
+ * @param {string} file file name
40
+ * @param {Source} source asset source
41
+ * @param {AssetInfo} assetInfo extra asset information
42
+ * @returns {void}
43
+ */
44
+ emitAsset(filename: string, source: Source, assetInfo?: AssetInfo): void;
45
+ /**
46
+ * Get an array of Asset
47
+ *
48
+ * See: [Compilation.getAssets](https://webpack.js.org/api/compilation-object/#getassets)
49
+ * Source: [getAssets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4448)
50
+ *
51
+ * @return {Readonly<Asset>[]}
52
+ */
53
+ getAssets(): {
54
+ source: Source;
55
+ name: string;
56
+ info: AssetInfo;
57
+ }[];
58
+ getPath(filename: string, data?: Record<string, any>): any;
59
+ getAssetPath(filename: any, data: any): any;
60
+ createStats(): {};
61
+ seal(): void;
62
+ unseal(): void;
63
+ }
64
+ //# sourceMappingURL=compilation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilation.d.ts","sourceRoot":"","sources":["../src/compilation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAa,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAkB,MAAM,iBAAiB,CAAC;AAG3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAKnD,qBAAa,WAAW;;IAGvB,KAAK,EAAE;QACN,aAAa,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;KAC/D,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,uBAAuB,CAAC;gBAErB,OAAO,EAAE,uBAAuB,EAAE,KAAK,EAAE,aAAa;IAalE;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnC;IAED;;;;;;;;;;;OAWG;IACH,WAAW,CACV,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,EAC1D,yBAAyB,EAAE,SAAS,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,KAAK,SAAS,CAAC;IAyB7E;;;;;;;;;;OAUG;IACH,SAAS,CACR,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAIV;IAKF;;;;;;;OAOG;IACH,SAAS;;;;;IAaT,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAWxD,YAAY,CAAC,QAAQ,KAAA,EAAE,IAAI,KAAA;IAI3B,WAAW;IAIX,IAAI;IACJ,MAAM;CACN"}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
+ if (kind === "m") throw new TypeError("Private method is not writable");
27
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
28
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
29
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
30
+ };
31
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
34
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
+ };
36
+ var _Compilation_inner;
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.Compilation = void 0;
39
+ const tapable = __importStar(require("tapable"));
40
+ const createHash_1 = require("./utils/createHash");
41
+ const createSource_1 = require("./utils/createSource");
42
+ const hashDigestLength = 8;
43
+ class Compilation {
44
+ constructor(options, inner) {
45
+ _Compilation_inner.set(this, void 0);
46
+ this.hooks = {
47
+ processAssets: new tapable.AsyncSeriesHook([
48
+ "assets"
49
+ ])
50
+ };
51
+ this.options = options;
52
+ const hash = (0, createHash_1.createHash)(this.options.output.hashFunction);
53
+ this.fullHash = hash.digest(options.output.hashDigest);
54
+ this.hash = this.fullHash.slice(0, hashDigestLength);
55
+ __classPrivateFieldSet(this, _Compilation_inner, inner, "f");
56
+ }
57
+ /**
58
+ * Get a map of all assets.
59
+ *
60
+ * Source: [assets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L1008-L1009)
61
+ */
62
+ get assets() {
63
+ const iterator = Object.entries(__classPrivateFieldGet(this, _Compilation_inner, "f").assets).map(([filename, source]) => [filename, (0, createSource_1.createSourceFromRaw)(source)]);
64
+ return Object.fromEntries(iterator);
65
+ }
66
+ /**
67
+ * Update an existing asset. Trying to update an asset that doesn't exist will throw an error.
68
+ *
69
+ * See: [Compilation.updateAsset](https://webpack.js.org/api/compilation-object/#updateasset)
70
+ * Source: [updateAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4320)
71
+ *
72
+ * FIXME: *AssetInfo* may be undefined in update fn for webpack impl, but still not implemented in rspack
73
+ *
74
+ * @param {string} file file name
75
+ * @param {Source | function(Source): Source} newSourceOrFunction new asset source or function converting old to new
76
+ * @param {AssetInfo | function(AssetInfo): AssetInfo} assetInfoUpdateOrFunction new asset info or function converting old to new
77
+ */
78
+ updateAsset(filename, newSourceOrFunction, assetInfoUpdateOrFunction) {
79
+ let compatNewSourceOrFunction;
80
+ if (typeof newSourceOrFunction === "function") {
81
+ compatNewSourceOrFunction = function newSourceFunction(source) {
82
+ return (0, createSource_1.createRawFromSource)(newSourceOrFunction((0, createSource_1.createSourceFromRaw)(source)));
83
+ };
84
+ }
85
+ else {
86
+ compatNewSourceOrFunction = (0, createSource_1.createRawFromSource)(newSourceOrFunction);
87
+ }
88
+ __classPrivateFieldGet(this, _Compilation_inner, "f").updateAsset(filename, compatNewSourceOrFunction, assetInfoUpdateOrFunction);
89
+ }
90
+ /**
91
+ * Emit an not existing asset. Trying to emit an asset that already exists will throw an error.
92
+ *
93
+ * See: [Compilation.emitAsset](https://webpack.js.org/api/compilation-object/#emitasset)
94
+ * Source: [emitAsset](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4239)
95
+ *
96
+ * @param {string} file file name
97
+ * @param {Source} source asset source
98
+ * @param {AssetInfo} assetInfo extra asset information
99
+ * @returns {void}
100
+ */
101
+ emitAsset(filename, source, assetInfo = {
102
+ minimized: false,
103
+ development: false,
104
+ related: {}
105
+ }) {
106
+ __classPrivateFieldGet(this, _Compilation_inner, "f").emitAsset(filename, (0, createSource_1.createRawFromSource)(source), assetInfo);
107
+ }
108
+ /**
109
+ * Get an array of Asset
110
+ *
111
+ * See: [Compilation.getAssets](https://webpack.js.org/api/compilation-object/#getassets)
112
+ * Source: [getAssets](https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/Compilation.js#L4448)
113
+ *
114
+ * @return {Readonly<Asset>[]}
115
+ */
116
+ getAssets() {
117
+ const assets = __classPrivateFieldGet(this, _Compilation_inner, "f").getAssets();
118
+ return assets.map(asset => {
119
+ const source = (0, createSource_1.createSourceFromRaw)(asset.source);
120
+ return {
121
+ ...asset,
122
+ source
123
+ };
124
+ });
125
+ }
126
+ // TODO: full alignment
127
+ getPath(filename, data = {}) {
128
+ if (!data.hash) {
129
+ data = {
130
+ hash: this.hash,
131
+ ...data
132
+ };
133
+ }
134
+ return this.getAssetPath(filename, data);
135
+ }
136
+ // TODO: full alignment
137
+ getAssetPath(filename, data) {
138
+ return filename;
139
+ }
140
+ createStats() {
141
+ return {};
142
+ }
143
+ seal() { }
144
+ unseal() { }
145
+ }
146
+ exports.Compilation = Compilation;
147
+ _Compilation_inner = new WeakMap();
148
+ //# sourceMappingURL=compilation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilation.js","sourceRoot":"","sources":["../src/compilation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AAKnC,mDAAgD;AAEhD,uDAAgF;AAEhF,MAAM,gBAAgB,GAAG,CAAC,CAAC;A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,52 @@
1
+ import * as tapable from "tapable";
2
+ import { Callback } from "tapable";
3
+ import * as binding from "@rspack/binding";
4
+ import { Logger } from "./logging/Logger";
5
+ import type { Watch } from "./config/watch";
6
+ import { RspackOptionsNormalized } from "./config";
7
+ import { Stats } from "./stats";
8
+ import { Compilation } from "./compilation";
9
+ declare class Compiler {
10
+ #private;
11
+ webpack: any;
12
+ compilation: Compilation;
13
+ infrastructureLogger: any;
14
+ outputPath: string;
15
+ name: string;
16
+ inputFileSystem: any;
17
+ outputFileSystem: any;
18
+ hooks: {
19
+ done: tapable.AsyncSeriesHook<Stats>;
20
+ afterDone: tapable.SyncHook<Stats>;
21
+ compilation: tapable.SyncHook<Compilation>;
22
+ thisCompilation: tapable.SyncHook<[Compilation]>;
23
+ invalid: tapable.SyncHook<[string | null, number]>;
24
+ compile: tapable.SyncHook<[any]>;
25
+ initialize: tapable.SyncHook<[]>;
26
+ infrastructureLog: tapable.SyncBailHook<[string, string, any[]], true>;
27
+ beforeRun: tapable.AsyncSeriesHook<[Compiler]>;
28
+ run: tapable.AsyncSeriesHook<[Compiler]>;
29
+ failed: tapable.SyncHook<[Error]>;
30
+ };
31
+ options: RspackOptionsNormalized;
32
+ constructor(context: string, options: RspackOptionsNormalized);
33
+ getInfrastructureLogger(name: string | Function): Logger;
34
+ run(callback: any): void;
35
+ build(cb: Callback<Error, binding.StatsCompilation>): void;
36
+ rebuild(changedFiles: string[], cb: (error?: Error, stats?: {
37
+ diff: binding.DiffStat;
38
+ stats: binding.StatsCompilation;
39
+ }) => void): void;
40
+ watch(watchOptions?: Watch, ws?: any): Promise<Watching>;
41
+ purgeInputFileSystem(): void;
42
+ /**
43
+ * @todo
44
+ */
45
+ close(callback: any): void;
46
+ emitAssets(compilation: Compilation, callback: any): void;
47
+ }
48
+ export interface Watching {
49
+ close(): Promise<void>;
50
+ }
51
+ export { Compiler };
52
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.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
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
28
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ var _Compiler_instances, _Compiler_instance_get, _Compiler_done, _Compiler_processAssets, _Compiler_compilation, _Compiler_newCompilation;
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.Compiler = void 0;
36
+ const path_1 = __importDefault(require("path"));
37
+ const fs_1 = __importDefault(require("fs"));
38
+ const util_1 = __importDefault(require("util"));
39
+ const tapable = __importStar(require("tapable"));
40
+ const tapable_1 = require("tapable");
41
+ const neo_async_1 = __importDefault(require("neo-async"));
42
+ const binding = __importStar(require("@rspack/binding"));
43
+ const Logger_1 = require("./logging/Logger");
44
+ const watch_1 = require("./config/watch");
45
+ const stats_1 = require("./stats");
46
+ const compilation_1 = require("./compilation");
47
+ const createSource_1 = require("./utils/createSource");
48
+ class EntryPlugin {
49
+ apply() { }
50
+ }
51
+ class HotModuleReplacementPlugin {
52
+ apply() { }
53
+ }
54
+ class Compiler {
55
+ constructor(context, options) {
56
+ _Compiler_instances.add(this);
57
+ this.options = options;
58
+ // to workaround some plugin access webpack, we may change dev-server to avoid this hack in the future
59
+ this.webpack = {
60
+ EntryPlugin,
61
+ HotModuleReplacementPlugin // modernjs/server will auto inject this this plugin not set
62
+ };
63
+ this.hooks = {
64
+ initialize: new tapable_1.SyncHook([]),
65
+ done: new tapable.AsyncSeriesHook(["stats"]),
66
+ afterDone: new tapable.SyncHook(["stats"]),
67
+ beforeRun: new tapable.AsyncSeriesHook(["compiler"]),
68
+ run: new tapable.AsyncSeriesHook(["compiler"]),
69
+ thisCompilation: new tapable.SyncHook([
70
+ "compilation"
71
+ // "params"
72
+ ]),
73
+ compilation: new tapable.SyncHook(["compilation"]),
74
+ invalid: new tapable_1.SyncHook(["filename", "changeTime"]),
75
+ compile: new tapable_1.SyncHook(["params"]),
76
+ infrastructureLog: new tapable_1.SyncBailHook(["origin", "type", "args"]),
77
+ failed: new tapable_1.SyncHook(["error"])
78
+ };
79
+ }
80
+ getInfrastructureLogger(name) {
81
+ if (!name) {
82
+ throw new TypeError("Compiler.getInfrastructureLogger(name) called without a name");
83
+ }
84
+ return new Logger_1.Logger((type, args) => {
85
+ if (typeof name === "function") {
86
+ name = name();
87
+ if (!name) {
88
+ throw new TypeError("Compiler.getInfrastructureLogger(name) called with a function not returning a name");
89
+ }
90
+ }
91
+ else {
92
+ if (this.hooks.infrastructureLog.call(name, type, args) === undefined) {
93
+ if (this.infrastructureLogger !== undefined) {
94
+ this.infrastructureLogger(name, type, args);
95
+ }
96
+ }
97
+ }
98
+ }, childName => {
99
+ if (typeof name === "function") {
100
+ if (typeof childName === "function") {
101
+ return this.getInfrastructureLogger(_ => {
102
+ if (typeof name === "function") {
103
+ name = name();
104
+ if (!name) {
105
+ throw new TypeError("Compiler.getInfrastructureLogger(name) called with a function not returning a name");
106
+ }
107
+ }
108
+ if (typeof childName === "function") {
109
+ childName = childName();
110
+ if (!childName) {
111
+ throw new TypeError("Logger.getChildLogger(name) called with a function not returning a name");
112
+ }
113
+ }
114
+ return `${name}/${childName}`;
115
+ });
116
+ }
117
+ else {
118
+ return this.getInfrastructureLogger(() => {
119
+ if (typeof name === "function") {
120
+ name = name();
121
+ if (!name) {
122
+ throw new TypeError("Compiler.getInfrastructureLogger(name) called with a function not returning a name");
123
+ }
124
+ }
125
+ return `${name}/${childName}`;
126
+ });
127
+ }
128
+ }
129
+ else {
130
+ if (typeof childName === "function") {
131
+ return this.getInfrastructureLogger(() => {
132
+ if (typeof childName === "function") {
133
+ childName = childName();
134
+ if (!childName) {
135
+ throw new TypeError("Logger.getChildLogger(name) called with a function not returning a name");
136
+ }
137
+ }
138
+ return `${name}/${childName}`;
139
+ });
140
+ }
141
+ else {
142
+ return this.getInfrastructureLogger(`${name}/${childName}`);
143
+ }
144
+ }
145
+ });
146
+ }
147
+ run(callback) {
148
+ const doRun = () => {
149
+ const finalCallback = (err, stats) => {
150
+ if (err) {
151
+ this.hooks.failed.call(err);
152
+ }
153
+ if (callback) {
154
+ callback(err, stats);
155
+ }
156
+ this.hooks.afterDone.call(stats);
157
+ };
158
+ this.hooks.beforeRun.callAsync(this, err => {
159
+ if (err) {
160
+ return finalCallback(err);
161
+ }
162
+ this.hooks.run.callAsync(this, err => {
163
+ if (err) {
164
+ return finalCallback(err);
165
+ }
166
+ this.build((err, rawStats) => {
167
+ if (err) {
168
+ return finalCallback(err);
169
+ }
170
+ const stats = new stats_1.Stats(rawStats);
171
+ this.hooks.done.callAsync(stats, err => {
172
+ if (err) {
173
+ return finalCallback(err);
174
+ }
175
+ else {
176
+ return finalCallback(null, stats);
177
+ }
178
+ });
179
+ });
180
+ });
181
+ });
182
+ };
183
+ doRun();
184
+ }
185
+ // Safety: This method is only valid to call if the previous build task is finished, or there will be data races.
186
+ build(cb) {
187
+ const build_cb = __classPrivateFieldGet(this, _Compiler_instances, "a", _Compiler_instance_get).unsafe_build.bind(__classPrivateFieldGet(this, _Compiler_instances, "a", _Compiler_instance_get));
188
+ build_cb((err, stats) => {
189
+ if (err) {
190
+ cb(err);
191
+ }
192
+ else {
193
+ cb(null, stats);
194
+ }
195
+ });
196
+ }
197
+ // Safety: This method is only valid to call if the previous rebuild task is finished, or there will be data races.
198
+ rebuild(changedFiles, cb) {
199
+ const rebuild_cb = __classPrivateFieldGet(this, _Compiler_instances, "a", _Compiler_instance_get).unsafe_rebuild.bind(__classPrivateFieldGet(this, _Compiler_instances, "a", _Compiler_instance_get));
200
+ rebuild_cb(changedFiles, [], (err, stats) => {
201
+ if (err) {
202
+ cb(err);
203
+ }
204
+ else {
205
+ cb(null, stats);
206
+ }
207
+ });
208
+ }
209
+ // TODO: use ws to send message to client temporary.
210
+ // TODO: we should use `Stats` which got from `hooks.done`
211
+ // TODO: in `dev-server`
212
+ async watch(watchOptions, ws) {
213
+ const options = (0, watch_1.resolveWatchOption)(watchOptions);
214
+ let logger = this.getInfrastructureLogger("watch");
215
+ const watcher = (await Promise.resolve().then(() => __importStar(require("chokidar")))).default.watch(this.options.context, {
216
+ ignoreInitial: true,
217
+ ...options
218
+ });
219
+ const begin = Date.now();
220
+ let rawStats = await util_1.default.promisify(this.build.bind(this))();
221
+ let stats = new stats_1.Stats(rawStats);
222
+ // TODO: log stats string should move to cli
223
+ console.log(stats.toString(this.options.stats));
224
+ console.log("build success, time cost", Date.now() - begin, "ms");
225
+ let pendingChangedFilepaths = new Set();
226
+ let isBuildFinished = true;
227
+ // TODO: should use aggregated
228
+ watcher.on("change", async (changedFilepath) => {
229
+ // TODO: only build because we lack the snapshot info of file.
230
+ // TODO: it means there a lot of things to do....
231
+ // store the changed file path, it may or may not be consumed right now
232
+ if (!isBuildFinished) {
233
+ pendingChangedFilepaths.add(changedFilepath);
234
+ console.log("hit change but rebuild is not finished, caching files: ", pendingChangedFilepaths);
235
+ return;
236
+ }
237
+ const rebuildWithFilepaths = (changedFilepath) => {
238
+ // Rebuild finished, we can start to rebuild again
239
+ isBuildFinished = false;
240
+ console.log("hit change and start to build");
241
+ const begin = Date.now();
242
+ this.rebuild(changedFilepath, (error, { diff, stats: rawStats }) => {
243
+ let stats = new stats_1.Stats(rawStats);
244
+ // TODO: log stats string should move to cli
245
+ console.log(stats.toString(this.options.stats));
246
+ isBuildFinished = true;
247
+ const hasPending = Boolean(pendingChangedFilepaths.size);
248
+ // If we have any pending task left, we should rebuild again with the pending files
249
+ if (hasPending) {
250
+ const pending = [...pendingChangedFilepaths];
251
+ pendingChangedFilepaths.clear();
252
+ rebuildWithFilepaths(pending);
253
+ }
254
+ if (error) {
255
+ throw error;
256
+ }
257
+ for (const [uri, stats] of Object.entries(diff)) {
258
+ let relativePath = path_1.default.relative(this.options.context, uri);
259
+ if (!(relativePath.startsWith("../") ||
260
+ relativePath.startsWith("./"))) {
261
+ relativePath = "./" + relativePath;
262
+ }
263
+ // send Message
264
+ if (ws) {
265
+ const data = {
266
+ uri: relativePath,
267
+ content: stats.content
268
+ };
269
+ if (/\.[less|css|sass|scss]$/.test(data.uri)) {
270
+ const cssOutput = fs_1.default
271
+ .readFileSync(path_1.default.resolve(this.options.output.path, "main.css"))
272
+ .toString("utf-8");
273
+ // TODO: need support more
274
+ data.content = [
275
+ `var cssStyleTag = document.querySelector("style[id='hot-css']")`,
276
+ `if (cssStyleTag) {`,
277
+ ` cssStyleTag.innerText = \`${cssOutput}\``,
278
+ `} else {`,
279
+ ` var newCSStyleTag = document.createElement('style')`,
280
+ ` newCSStyleTag.setAttribute('id', 'hot-css')`,
281
+ ` newCSStyleTag.innerText = \`${cssOutput}\``,
282
+ ` document.head.appendChild(newCSStyleTag)`,
283
+ `}`,
284
+ ``,
285
+ `var outdataCSSLinkTag = document.querySelector("link[href='main.css']")`,
286
+ `outdataCSSLinkTag && outdataCSSLinkTag.parentNode && outdataCSSLinkTag.parentNode.removeChild(outdataCSSLinkTag)`
287
+ ].join("\n");
288
+ }
289
+ for (const client of ws.clients) {
290
+ // the type of "ok" means rebuild success.
291
+ // the data should deleted after we had hash in stats.
292
+ client.send(JSON.stringify({ type: "ok", data: JSON.stringify(data) }));
293
+ }
294
+ }
295
+ }
296
+ console.log("rebuild success, time cost", Date.now() - begin, "ms");
297
+ });
298
+ };
299
+ rebuildWithFilepaths([...pendingChangedFilepaths, changedFilepath]);
300
+ });
301
+ return {
302
+ async close() {
303
+ await watcher.close();
304
+ }
305
+ };
306
+ }
307
+ purgeInputFileSystem() {
308
+ if (this.inputFileSystem && this.inputFileSystem.purge) {
309
+ this.inputFileSystem.purge();
310
+ }
311
+ }
312
+ /**
313
+ * @todo
314
+ */
315
+ close(callback) {
316
+ callback();
317
+ }
318
+ emitAssets(compilation, callback) {
319
+ const outputPath = compilation.getPath(this.outputPath, {});
320
+ fs_1.default.mkdirSync(outputPath, { recursive: true });
321
+ const assets = compilation.getAssets();
322
+ neo_async_1.default.forEachLimit(assets, 15, ({ name: file, source, info }, callback) => {
323
+ let targetFile = file;
324
+ const absPath = path_1.default.resolve(outputPath, targetFile);
325
+ const getContent = () => {
326
+ if (typeof source.buffer === "function") {
327
+ return source.buffer();
328
+ }
329
+ else {
330
+ const bufferOrString = source.source();
331
+ if (Buffer.isBuffer(bufferOrString)) {
332
+ return bufferOrString;
333
+ }
334
+ else {
335
+ return Buffer.from(bufferOrString, "utf-8");
336
+ }
337
+ }
338
+ };
339
+ const doWrite = content => {
340
+ this.outputFileSystem.writeFile(absPath, content, callback);
341
+ };
342
+ let content = getContent();
343
+ doWrite(content);
344
+ });
345
+ }
346
+ }
347
+ exports.Compiler = Compiler;
348
+ _Compiler_instances = new WeakSet(), _Compiler_instance_get = function _Compiler_instance_get() {
349
+ // @ts-ignored
350
+ this._instance =
351
+ // @ts-ignored
352
+ this._instance ||
353
+ // @ts-ignored
354
+ new binding.Rspack(this.options, {
355
+ doneCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_done).bind(this),
356
+ processAssetsCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this),
357
+ // `Compilation` should be created with hook `thisCompilation`, and here is the reason:
358
+ // We know that the hook `thisCompilation` will not be called from a child compiler(it doesn't matter whether the child compiler is created on the Rust or the Node side).
359
+ // See webpack's API: https://webpack.js.org/api/compiler-hooks/#thiscompilation
360
+ // So it is safe to create a new compilation here.
361
+ thisCompilationCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_newCompilation).bind(this),
362
+ // The hook `Compilation` should be called whenever it's a call from the child compiler or normal compiler and
363
+ // still it does not matter where the child compiler is created(Rust or Node) as calling the hook `compilation` is a required task.
364
+ // No matter how it will be implemented, it will be copied to the child compiler.
365
+ compilationCallback: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_compilation).bind(this)
366
+ });
367
+ // @ts-ignored
368
+ return this._instance;
369
+ }, _Compiler_done = function _Compiler_done(statsJson) { }, _Compiler_processAssets = async function _Compiler_processAssets(assets) {
370
+ let iterator = Object.entries(assets).map(([filename, source]) => [
371
+ filename,
372
+ (0, createSource_1.createSourceFromRaw)(source)
373
+ ]);
374
+ await this.compilation.hooks.processAssets.promise(Object.fromEntries(iterator));
375
+ }, _Compiler_compilation = function _Compiler_compilation(native) {
376
+ // TODO: implement this based on the child compiler impl.
377
+ this.hooks.compilation.call(this.compilation);
378
+ }, _Compiler_newCompilation = function _Compiler_newCompilation(native) {
379
+ const compilation = new compilation_1.Compilation(this.options, native);
380
+ this.compilation = compilation;
381
+ this.hooks.thisCompilation.call(this.compilation);
382
+ };
383
+ //# sourceMappingURL=compiler.js.map