@rspack/core 0.0.7 → 0.0.9

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 -51
  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
package/src/config/dev.ts DELETED
@@ -1,32 +0,0 @@
1
- import path from "node:path";
2
-
3
- export interface Dev {
4
- port?: number;
5
- static?: {
6
- directory?: string;
7
- };
8
- }
9
-
10
- export interface ResolvedDev {
11
- port: number;
12
- static: {
13
- directory: string;
14
- };
15
- }
16
-
17
- interface ResolveDevConfigContext {
18
- context: string;
19
- }
20
-
21
- export function resolveDevOptions(
22
- devConfig: Dev = {},
23
- context: ResolveDevConfigContext
24
- ): ResolvedDev {
25
- return {
26
- port: devConfig.port ?? 8080,
27
- static: {
28
- directory:
29
- devConfig.static?.directory ?? path.resolve(context.context, "dist")
30
- }
31
- };
32
- }
@@ -1,3 +0,0 @@
1
- export type Entry = Record<string, string>;
2
-
3
- export type ResolvedEntry = Record<string, string>;
@@ -1,3 +0,0 @@
1
- export type External = Record<string, string>;
2
-
3
- export type ResolvedExternal = Record<string, string>;
@@ -1,80 +0,0 @@
1
- import type { Context, ResolvedContext } from "./context";
2
- import type { Define, ResolvedDefine } from "./define";
3
- import type { Dev, ResolvedDev } from "./dev";
4
- import type { Entry, ResolvedEntry } from "./entry";
5
- import type { External, ResolvedExternal } from "./external";
6
- import type { Mode, ResolvedMode } from "./mode";
7
- import type { Module, ResolvedModule } from "./module";
8
- import type { Plugin } from "./plugin";
9
- import type { ResolvedTarget, Target } from "./target";
10
- import type { Output, ResolvedOutput } from "./output";
11
- import { resolveTargetOptions } from "./target";
12
- import { resolveOutputOptions } from "./output";
13
- import { resolveDevOptions } from "./dev";
14
- import { resolveModuleOptions } from "./module";
15
- import { Builtins, ResolvedBuiltins } from "./builtins";
16
- import { Resolve, ResolvedResolve } from "./resolve";
17
-
18
- export type Asset = {
19
- source: string;
20
- };
21
- export type Assets = Record<string, Asset>;
22
-
23
- export interface RspackOptions {
24
- entry?: Entry;
25
- context?: Context;
26
- plugins?: Plugin[];
27
- dev?: Dev;
28
- module?: Module;
29
- define?: Define;
30
- target?: Target;
31
- mode?: Mode;
32
- external?: External;
33
- output?: Output;
34
- builtins: Builtins;
35
- resolve: Resolve;
36
- }
37
-
38
- export interface ResolvedRspackOptions {
39
- entry: ResolvedEntry;
40
- context: ResolvedContext;
41
- plugins: Plugin[];
42
- dev: ResolvedDev;
43
- module: ResolvedModule;
44
- define: ResolvedDefine;
45
- target: ResolvedTarget;
46
- mode: ResolvedMode;
47
- external: ResolvedExternal;
48
- output: ResolvedOutput;
49
- builtins: ResolvedBuiltins;
50
- resolve: ResolvedResolve;
51
- }
52
-
53
- export function resolveOptions(config: RspackOptions): ResolvedRspackOptions {
54
- const context = config.context ?? process.cwd();
55
- const mode = config.mode ?? "development";
56
- const dev = resolveDevOptions(config.dev, { context });
57
- const entry = config.entry ?? {};
58
- const output = resolveOutputOptions(config.output);
59
- const define = config.define ?? {};
60
- const target = resolveTargetOptions(config.target);
61
- const external = config.external ?? {};
62
- const plugins = config.plugins ?? [];
63
- const builtins = config.builtins ?? [];
64
- const resolve = config.resolve ?? {};
65
- const module = resolveModuleOptions(config.module);
66
- return {
67
- context,
68
- mode,
69
- dev,
70
- entry,
71
- output,
72
- define,
73
- target,
74
- external,
75
- plugins,
76
- builtins,
77
- module,
78
- resolve
79
- };
80
- }
@@ -1,2 +0,0 @@
1
- export type Mode = string;
2
- export type ResolvedMode = string;
@@ -1,240 +0,0 @@
1
- import type { RawModuleRuleUse, RawModuleRule } from "@rspack/binding";
2
- import assert from "node:assert";
3
-
4
- export interface ModuleRule {
5
- test?: RawModuleRule["test"];
6
- resource?: RawModuleRule["resource"];
7
- resourceQuery?: RawModuleRule["resourceQuery"];
8
- uses?: ModuleRuleUse[];
9
- type?: RawModuleRule["type"];
10
- }
11
-
12
- export interface Module {
13
- rules?: ModuleRule[];
14
- parser?: {
15
- dataUrlCondition?: {
16
- maxSize?: number;
17
- };
18
- };
19
- }
20
-
21
- interface ResolvedModuleRule {
22
- test?: RawModuleRule["test"];
23
- resource?: RawModuleRule["resource"];
24
- resourceQuery?: RawModuleRule["resourceQuery"];
25
- uses?: RawModuleRuleUse[];
26
- type?: RawModuleRule["type"];
27
- }
28
-
29
- export interface ResolvedModule {
30
- rules: ResolvedModuleRule[];
31
- parser?: {
32
- dataUrlCondition: {
33
- maxSize: number;
34
- };
35
- };
36
- }
37
-
38
- interface LoaderContextInternal {
39
- // TODO: It's not a good way to do this, we should split the `source` into a separate type and avoid using `serde_json`, but it's a temporary solution.
40
- source: number[];
41
- resource: String;
42
- resourcePath: String;
43
- resourceQuery: String | null;
44
- resourceFragment: String | null;
45
- }
46
-
47
- interface LoaderResult {
48
- content: Buffer | string;
49
- meta: Buffer | string;
50
- }
51
-
52
- interface LoaderThreadsafeResult {
53
- id: number;
54
- p: LoaderResultInternal | null | undefined;
55
- }
56
-
57
- interface LoaderResultInternal {
58
- content: number[];
59
- meta: number[];
60
- }
61
-
62
- interface LoaderContext
63
- extends Pick<
64
- LoaderContextInternal,
65
- "resource" | "resourcePath" | "resourceQuery" | "resourceFragment"
66
- > {
67
- source: {
68
- getCode(): string;
69
- getBuffer(): Buffer;
70
- };
71
- }
72
-
73
- const toBuffer = (bufLike: string | Buffer): Buffer => {
74
- if (Buffer.isBuffer(bufLike)) {
75
- return bufLike;
76
- } else if (typeof bufLike === "string") {
77
- return Buffer.from(bufLike);
78
- }
79
-
80
- throw new Error("Buffer or string expected");
81
- };
82
-
83
- interface LoaderThreadsafeContext {
84
- id: number;
85
- p: LoaderContextInternal;
86
- }
87
-
88
- function composeJsUse(uses: ModuleRuleUse[]): RawModuleRuleUse | null {
89
- if (!uses.length) {
90
- return null;
91
- }
92
-
93
- async function loader(err: any, data: Buffer): Promise<Buffer> {
94
- if (err) {
95
- throw err;
96
- }
97
-
98
- const loaderThreadsafeContext: LoaderThreadsafeContext = JSON.parse(
99
- data.toString("utf-8")
100
- );
101
-
102
- const { p: payload, id } = loaderThreadsafeContext;
103
-
104
- const loaderContextInternal: LoaderContextInternal = {
105
- source: payload.source,
106
- resourcePath: payload.resourcePath,
107
- resourceQuery: payload.resourceQuery,
108
- resource: payload.resource,
109
- resourceFragment: payload.resourceFragment
110
- };
111
-
112
- let sourceBuffer = Buffer.from(loaderContextInternal.source);
113
- let meta = Buffer.from("");
114
- // Loader is executed from right to left
115
- for (const use of uses) {
116
- assert("loader" in use);
117
- const loaderContext = {
118
- ...loaderContextInternal,
119
- source: {
120
- getCode(): string {
121
- return sourceBuffer.toString("utf-8");
122
- },
123
- getBuffer(): Buffer {
124
- return sourceBuffer;
125
- }
126
- },
127
- getOptions() {
128
- return use.options;
129
- }
130
- };
131
-
132
- let loaderResult: LoaderResult;
133
- if (
134
- (loaderResult = await Promise.resolve().then(() =>
135
- use.loader.apply(loaderContext, [loaderContext])
136
- ))
137
- ) {
138
- const content = loaderResult.content;
139
- meta = meta.length > 0 ? meta : toBuffer(loaderResult.meta);
140
- sourceBuffer = toBuffer(content);
141
- }
142
- }
143
-
144
- const loaderResultPayload: LoaderResultInternal = {
145
- content: [...sourceBuffer],
146
- meta: [...meta]
147
- };
148
-
149
- const loaderThreadsafeResult: LoaderThreadsafeResult = {
150
- id: id,
151
- p: loaderResultPayload
152
- };
153
- return Buffer.from(JSON.stringify(loaderThreadsafeResult), "utf-8");
154
- }
155
- loader.displayName = `NodeLoaderAdapter(${uses
156
- .map(item => {
157
- assert("loader" in item);
158
- return item.loader.displayName || item.loader.name || "unknown-loader";
159
- })
160
- .join(" -> ")})`;
161
- return {
162
- loader
163
- };
164
- }
165
-
166
- interface JsLoader {
167
- (this: LoaderContext, loaderContext: LoaderContext):
168
- | Promise<LoaderResult | void>
169
- | LoaderResult
170
- | void;
171
- displayName?: string;
172
- }
173
-
174
- type BuiltinLoader = string;
175
-
176
- type ModuleRuleUse =
177
- | {
178
- builtinLoader: BuiltinLoader;
179
- options?: unknown;
180
- }
181
- | {
182
- loader: JsLoader;
183
- options?: unknown;
184
- };
185
-
186
- export function createRawModuleRuleUses(
187
- uses: ModuleRuleUse[]
188
- ): RawModuleRuleUse[] {
189
- return createRawModuleRuleUsesImpl([...uses].reverse());
190
- }
191
-
192
- function createRawModuleRuleUsesImpl(
193
- uses: ModuleRuleUse[]
194
- ): RawModuleRuleUse[] {
195
- if (!uses.length) {
196
- return [];
197
- }
198
-
199
- const index = uses.findIndex(use => "builtinLoader" in use);
200
- if (index < 0) {
201
- return [composeJsUse(uses)];
202
- }
203
-
204
- const before = uses.slice(0, index);
205
- const after = uses.slice(index + 1);
206
- return [
207
- composeJsUse(before),
208
- createNativeUse(uses[index]),
209
- ...createRawModuleRuleUsesImpl(after)
210
- ].filter((item): item is RawModuleRuleUse => Boolean(item));
211
- }
212
-
213
- function createNativeUse(use: ModuleRuleUse): RawModuleRuleUse {
214
- assert("builtinLoader" in use);
215
-
216
- if (use.builtinLoader === "sass-loader") {
217
- (use.options ??= {} as any).__exePath = require.resolve(
218
- `@tmp-sass-embedded/${process.platform}-${
219
- process.arch
220
- }/dart-sass-embedded/dart-sass-embedded${
221
- process.platform === "win32" ? ".bat" : ""
222
- }`
223
- );
224
- }
225
-
226
- return {
227
- builtinLoader: use.builtinLoader,
228
- options: JSON.stringify(use.options)
229
- };
230
- }
231
-
232
- export function resolveModuleOptions(module: Module = {}): ResolvedModule {
233
- const rules = (module.rules ?? []).map(rule => ({
234
- ...rule,
235
- uses: createRawModuleRuleUses(rule.uses || [])
236
- }));
237
- return {
238
- rules
239
- };
240
- }
@@ -1,29 +0,0 @@
1
- export interface Output {
2
- path?: string;
3
- publicPath?: string;
4
- assetModuleFilename?: string;
5
- filename?: string;
6
- chunkFilename?: string;
7
- uniqueName?: string;
8
- }
9
-
10
- // TODO: fix it
11
- export interface ResolvedOutput {
12
- path?: string;
13
- publicPath?: string;
14
- assetModuleFilename?: string;
15
- filename?: string;
16
- chunkFilename?: string;
17
- uniqueName?: string;
18
- }
19
-
20
- export function resolveOutputOptions(output: Output = {}): ResolvedOutput {
21
- return {
22
- path: output.path,
23
- publicPath: output.publicPath,
24
- chunkFilename: output.chunkFilename,
25
- filename: output.publicPath,
26
- assetModuleFilename: output.assetModuleFilename,
27
- uniqueName: output.uniqueName
28
- };
29
- }
@@ -1,6 +0,0 @@
1
- import Rspack from "..";
2
-
3
- export interface Plugin {
4
- name: string;
5
- apply(compiler: Rspack): void;
6
- }
@@ -1,6 +0,0 @@
1
- export type Resolve = {
2
- preferRelative?: boolean;
3
- };
4
- export type ResolvedResolve = {
5
- preferRelative?: boolean;
6
- };
@@ -1,28 +0,0 @@
1
- type TargetItem =
2
- | "web"
3
- | "webworker"
4
- | "browserslist"
5
- | "es3"
6
- | "es5"
7
- | "es2015"
8
- | "es2016"
9
- | "es2017"
10
- | "es2018"
11
- | "es2019"
12
- | "es2020"
13
- | "es2021"
14
- | "es2022";
15
-
16
- export type Target = TargetItem | TargetItem[] | false;
17
- export type ResolvedTarget = TargetItem[];
18
-
19
- export function resolveTargetOptions(target: Target = "web"): ResolvedTarget {
20
- if (!target) {
21
- return [];
22
- }
23
- if (!Array.isArray(target)) {
24
- return [target];
25
- }
26
-
27
- return target;
28
- }
package/src/index.ts DELETED
@@ -1,140 +0,0 @@
1
- export * from "./build";
2
- import * as binding from "@rspack/binding";
3
- import type { ExternalObject, RspackInternal } from "@rspack/binding";
4
- import * as tapable from "tapable";
5
- import {
6
- RspackOptions,
7
- ResolvedRspackOptions,
8
- Assets,
9
- Asset,
10
- resolveOptions
11
- } from "./config";
12
-
13
- import { RawSource, Source } from "webpack-sources";
14
- interface RspackThreadsafeContext<T> {
15
- readonly id: number;
16
- readonly inner: T;
17
- }
18
- interface RspackThreadsafeResult<T> {
19
- readonly id: number;
20
- readonly inner: T;
21
- }
22
- const createDummyResult = (id: number): string => {
23
- const result: RspackThreadsafeResult<null> = {
24
- id,
25
- inner: null
26
- };
27
- return JSON.stringify(result);
28
- };
29
- type EmitAssetCallback = (options: { filename: string; asset: Asset }) => void;
30
- class RspackCompilation {
31
- #emitAssetCallback: EmitAssetCallback;
32
- hooks: {
33
- processAssets: tapable.AsyncSeriesHook<Record<string, Source>>;
34
- };
35
- constructor() {
36
- this.hooks = {
37
- processAssets: new tapable.AsyncSeriesHook<Record<string, Source>>([
38
- "assets"
39
- ])
40
- };
41
- }
42
- /**
43
- * unsafe to call out of processAssets
44
- * @param filename
45
- * @param asset
46
- */
47
- updateAsset(filename: string, asset: Asset) {
48
- this.emitAsset(filename, asset);
49
- }
50
- /**
51
- * unsafe to call out of processAssets
52
- * @param filename
53
- * @param asset
54
- */
55
- emitAsset(filename: string, asset: Asset) {
56
- if (!this.#emitAssetCallback) {
57
- throw new Error("can't call emitAsset outof processAssets hook for now");
58
- }
59
- this.#emitAssetCallback({
60
- filename: filename,
61
- asset
62
- });
63
- }
64
- async processAssets(err: Error, value: string, emitAsset: any) {
65
- this.#emitAssetCallback = emitAsset;
66
- if (err) {
67
- throw err;
68
- }
69
- const context: RspackThreadsafeContext<
70
- Record<string, { source: string | Buffer }>
71
- > = JSON.parse(value);
72
- let content: Record<string, { source: string | Buffer }> =
73
- context.inner ?? {};
74
- let assets = {};
75
- for (const [key, value] of Object.entries(content)) {
76
- // webpack-sources's type definition is wrong, it actually could accept Buffer type
77
- let source = value.source;
78
- if (Array.isArray(value.source)) {
79
- source = Buffer.from(value.source);
80
- }
81
- assets[key] = new RawSource(source as string);
82
- }
83
- await this.hooks.processAssets.promise(assets);
84
- return createDummyResult(context.id);
85
- }
86
- }
87
- class Rspack {
88
- #plugins: RspackOptions["plugins"];
89
- #instance: ExternalObject<RspackInternal>;
90
- compilation: RspackCompilation;
91
- hooks: {
92
- done: tapable.AsyncSeriesHook<void>;
93
- compilation: tapable.SyncHook<RspackCompilation>;
94
- };
95
- options: ResolvedRspackOptions;
96
- constructor(options: RspackOptions) {
97
- this.options = resolveOptions(options);
98
- // @ts-ignored
99
- this.#instance = binding.newRspack(this.options, {
100
- doneCallback: this.#done.bind(this),
101
- processAssetsCallback: this.#processAssets.bind(this)
102
- });
103
- this.hooks = {
104
- done: new tapable.AsyncSeriesHook<void>(),
105
- compilation: new tapable.SyncHook<RspackCompilation>(["compilation"])
106
- };
107
- this.#plugins = options.plugins ?? [];
108
- for (const plugin of this.#plugins) {
109
- plugin.apply(this);
110
- }
111
- }
112
- async #done(err: Error, value: string) {
113
- if (err) {
114
- throw err;
115
- }
116
- const context: RspackThreadsafeContext<void> = JSON.parse(value);
117
- await this.hooks.done.promise();
118
- return createDummyResult(context.id);
119
- }
120
- async #processAssets(err: Error, value: string, emitAsset: any) {
121
- return this.compilation.processAssets(err, value, emitAsset);
122
- }
123
- #newCompilation() {
124
- const compilation = new RspackCompilation();
125
- this.compilation = compilation;
126
- this.hooks.compilation.call(compilation);
127
- return compilation;
128
- }
129
- async build() {
130
- const compilation = this.#newCompilation();
131
- const stats = await binding.build(this.#instance);
132
- return stats;
133
- }
134
- async rebuild(changeFiles: string[]) {
135
- const stats = await binding.rebuild(this.#instance, changeFiles);
136
- return stats;
137
- }
138
- }
139
- export { Rspack };
140
- export default Rspack;
File without changes
@@ -1,40 +0,0 @@
1
- import { test } from "uvu";
2
- import * as assert from "uvu/assert";
3
- import { Rspack } from "@rspack/core";
4
- import path from "path";
5
-
6
- test("default config snapshot", () => {
7
- const resolvedOptions = new Rspack({}).options;
8
-
9
- assert.equal(resolvedOptions.context, process.cwd());
10
- assert.equal(
11
- resolvedOptions.dev.static.directory,
12
- path.resolve(process.cwd(), "./dist")
13
- );
14
-
15
- // TypeScript will throw `The operand of a 'delete' operator must be optional`.
16
- // But we remove these configurations with absolute paths.
17
- // @ts-expect-error
18
- delete resolvedOptions.context;
19
- // @ts-expect-error
20
- delete resolvedOptions.dev.static.directory;
21
-
22
- assert.snapshot(
23
- JSON.stringify(resolvedOptions),
24
- JSON.stringify({
25
- mode: "development",
26
- dev: { port: 8080, static: {} },
27
- entry: {},
28
- output: {},
29
- define: {},
30
- target: ["web"],
31
- external: {},
32
- plugins: [],
33
- builtins: [],
34
- module: { rules: [] },
35
- resolve: {}
36
- })
37
- );
38
- });
39
-
40
- test.run();
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "CommonJS",
4
- "target": "ES2018",
5
- "moduleResolution": "node",
6
- "esModuleInterop": true,
7
- "outDir": "lib",
8
- "declaration": true
9
- },
10
- "include": ["src"],
11
- "ts-node": {
12
- "transpileOnly": true
13
- }
14
- }