@rspack/core 0.0.2 → 0.0.6

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 (58) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/example/basic.ts +30 -2
  3. package/{dist → lib}/bin/index.d.ts +0 -0
  4. package/{dist → lib}/bin/index.js +2 -2
  5. package/{dist → lib}/build.d.ts +0 -0
  6. package/{dist → lib}/build.js +0 -0
  7. package/lib/config/builtins.d.ts +3 -0
  8. package/lib/config/builtins.js +2 -0
  9. package/lib/config/context.d.ts +2 -0
  10. package/lib/config/context.js +2 -0
  11. package/lib/config/define.d.ts +2 -0
  12. package/lib/config/define.js +2 -0
  13. package/lib/config/dev.d.ts +17 -0
  14. package/lib/config/dev.js +17 -0
  15. package/lib/config/entry.d.ts +2 -0
  16. package/lib/config/entry.js +2 -0
  17. package/lib/config/external.d.ts +2 -0
  18. package/lib/config/external.js +2 -0
  19. package/lib/config/index.d.ts +45 -0
  20. package/lib/config/index.js +37 -0
  21. package/lib/config/mode.d.ts +2 -0
  22. package/lib/config/mode.js +2 -0
  23. package/{dist/index.d.ts → lib/config/module.d.ts} +41 -29
  24. package/lib/config/module.js +121 -0
  25. package/lib/config/output.d.ts +17 -0
  26. package/lib/config/output.js +14 -0
  27. package/lib/config/plugin.d.ts +5 -0
  28. package/lib/config/plugin.js +2 -0
  29. package/lib/config/resolve.d.ts +6 -0
  30. package/lib/config/resolve.js +2 -0
  31. package/lib/config/target.d.ts +5 -0
  32. package/lib/config/target.js +13 -0
  33. package/lib/index.d.ts +39 -0
  34. package/lib/index.js +154 -0
  35. package/{dist → lib}/server/index.d.ts +0 -0
  36. package/{dist → lib}/server/index.js +0 -0
  37. package/package.json +26 -11
  38. package/src/bin/index.ts +1 -1
  39. package/src/config/builtins.ts +5 -0
  40. package/src/config/context.ts +3 -0
  41. package/src/config/define.ts +3 -0
  42. package/src/config/dev.ts +32 -0
  43. package/src/config/entry.ts +3 -0
  44. package/src/config/external.ts +3 -0
  45. package/src/config/index.ts +80 -0
  46. package/src/config/mode.ts +2 -0
  47. package/src/config/module.ts +240 -0
  48. package/src/config/output.ts +29 -0
  49. package/src/config/plugin.ts +6 -0
  50. package/src/config/resolve.ts +6 -0
  51. package/src/config/target.ts +28 -0
  52. package/src/index.ts +107 -219
  53. package/tests/config.test.ts +40 -0
  54. package/tsconfig.json +6 -5
  55. package/dist/config.d.ts +0 -43
  56. package/dist/config.js +0 -25
  57. package/dist/index.js +0 -184
  58. package/src/config.ts +0 -66
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @rspack/core
2
2
 
3
+ ## 0.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - e6d0926a: unify version
8
+ - Updated dependencies [e6d0926a]
9
+ - @rspack/binding@0.0.6
10
+ - @rspack/dev-server@0.0.6
11
+ - @rspack/plugin-postcss@0.0.6
12
+
13
+ ## 0.0.4
14
+
15
+ ### Patch Changes
16
+
17
+ - d466288: add process_assets hook
18
+ - Updated dependencies [d466288]
19
+ - @rspack/binding@0.0.5
20
+ - @rspack/dev-server@0.0.4
21
+ - @rspack/plugin-postcss@0.0.4
22
+
23
+ ## 0.0.3
24
+
25
+ ### Patch Changes
26
+
27
+ - 536f6f70: fix broken lib
28
+ - Updated dependencies [536f6f70]
29
+ - @rspack/binding@0.0.4
30
+ - @rspack/dev-server@0.0.3
31
+ - @rspack/plugin-postcss@0.0.3
32
+
3
33
  ## 0.0.2
4
34
 
5
35
  ### Patch Changes
package/example/basic.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import postcssLoader from "rspack-plugin-postcss";
2
+ import postcssLoader from "@rspack/plugin-postcss";
3
3
  import { Rspack } from "../src";
4
4
 
5
5
  const rspack = new Rspack({
@@ -7,7 +7,35 @@ const rspack = new Rspack({
7
7
  main: path.resolve(__dirname, "../../../examples/postcss/index.js")
8
8
  },
9
9
  context: path.resolve(__dirname, "../../../examples/postcss"),
10
- plugins: ["html"],
10
+ plugins: [
11
+ {
12
+ name: "test",
13
+ apply(compiler) {
14
+ compiler.hooks.done.tap("done1", () => {
15
+ console.log("done1");
16
+ });
17
+ compiler.hooks.done.tap("done2", () => {
18
+ console.log("done2");
19
+ });
20
+ compiler.hooks.compilation.tap("compilation", compilation => {
21
+ compilation.hooks.processAssets.tapPromise(
22
+ "processAssets1",
23
+ async assets => {
24
+ for (const value of Object.values(assets)) {
25
+ console.log("value:", value.buffer(), value.source());
26
+ }
27
+ compilation.emitAsset("test.js", {
28
+ source: "hello world"
29
+ });
30
+ compilation.updateAsset("main.js", {
31
+ source: "hello main"
32
+ });
33
+ }
34
+ );
35
+ });
36
+ }
37
+ }
38
+ ],
11
39
  module: {
12
40
  rules: [
13
41
  {
File without changes
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const commander_1 = require("commander");
4
- const rspack_dev_server_1 = require("rspack-dev-server");
4
+ const dev_server_1 = require("@rspack/dev-server");
5
5
  const __1 = require("..");
6
6
  const build_1 = require("../build");
7
7
  const program = new commander_1.Command();
@@ -26,7 +26,7 @@ program
26
26
  const rspack = new __1.Rspack(config);
27
27
  const { options: { dev: { port = 8080 } = {} } = {} } = rspack;
28
28
  await rspack.build();
29
- const server = await (0, rspack_dev_server_1.createServer)(rspack.options);
29
+ const server = await (0, dev_server_1.createServer)(rspack.options);
30
30
  server.listen(port, () => console.log(`Server listening on port: ${port}`));
31
31
  });
32
32
  program.parse();
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ import type { RawBuiltins } from "@rspack/binding";
2
+ export declare type Builtins = RawBuiltins;
3
+ export declare type ResolvedBuiltins = RawBuiltins | any[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare type Context = string;
2
+ export declare type ResolvedContext = string;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare type Define = Record<string, string>;
2
+ export declare type ResolvedDefine = Record<string, string>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ export interface Dev {
2
+ port?: number;
3
+ static?: {
4
+ directory?: string;
5
+ };
6
+ }
7
+ export interface ResolvedDev {
8
+ port: number;
9
+ static: {
10
+ directory: string;
11
+ };
12
+ }
13
+ interface ResolveDevConfigContext {
14
+ context: string;
15
+ }
16
+ export declare function resolveDevOptions(devConfig: Dev, context: ResolveDevConfigContext): ResolvedDev;
17
+ export {};
@@ -0,0 +1,17 @@
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.resolveDevOptions = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ function resolveDevOptions(devConfig = {}, context) {
9
+ var _a, _b, _c;
10
+ return {
11
+ port: (_a = devConfig.port) !== null && _a !== void 0 ? _a : 8080,
12
+ static: {
13
+ directory: (_c = (_b = devConfig.static) === null || _b === void 0 ? void 0 : _b.directory) !== null && _c !== void 0 ? _c : node_path_1.default.resolve(context.context, "dist")
14
+ }
15
+ };
16
+ }
17
+ exports.resolveDevOptions = resolveDevOptions;
@@ -0,0 +1,2 @@
1
+ export declare type Entry = Record<string, string>;
2
+ export declare type ResolvedEntry = Record<string, string>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export declare type External = Record<string, string>;
2
+ export declare type ResolvedExternal = Record<string, string>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,45 @@
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 { Builtins, ResolvedBuiltins } from "./builtins";
12
+ import { Resolve, ResolvedResolve } from "./resolve";
13
+ export declare type Asset = {
14
+ source: string;
15
+ };
16
+ export declare type Assets = Record<string, Asset>;
17
+ export interface RspackOptions {
18
+ entry?: Entry;
19
+ context?: Context;
20
+ plugins?: Plugin[];
21
+ dev?: Dev;
22
+ module?: Module;
23
+ define?: Define;
24
+ target?: Target;
25
+ mode?: Mode;
26
+ external?: External;
27
+ output?: Output;
28
+ builtins: Builtins;
29
+ resolve: Resolve;
30
+ }
31
+ export interface ResolvedRspackOptions {
32
+ entry: ResolvedEntry;
33
+ context: ResolvedContext;
34
+ plugins: Plugin[];
35
+ dev: ResolvedDev;
36
+ module: ResolvedModule;
37
+ define: ResolvedDefine;
38
+ target: ResolvedTarget;
39
+ mode: ResolvedMode;
40
+ external: ResolvedExternal;
41
+ output: ResolvedOutput;
42
+ builtins: ResolvedBuiltins;
43
+ resolve: ResolvedResolve;
44
+ }
45
+ export declare function resolveOptions(config: RspackOptions): ResolvedRspackOptions;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveOptions = void 0;
4
+ const target_1 = require("./target");
5
+ const output_1 = require("./output");
6
+ const dev_1 = require("./dev");
7
+ const module_1 = require("./module");
8
+ function resolveOptions(config) {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h;
10
+ const context = (_a = config.context) !== null && _a !== void 0 ? _a : process.cwd();
11
+ const mode = (_b = config.mode) !== null && _b !== void 0 ? _b : "development";
12
+ const dev = (0, dev_1.resolveDevOptions)(config.dev, { context });
13
+ const entry = (_c = config.entry) !== null && _c !== void 0 ? _c : {};
14
+ const output = (0, output_1.resolveOutputOptions)(config.output);
15
+ const define = (_d = config.define) !== null && _d !== void 0 ? _d : {};
16
+ const target = (0, target_1.resolveTargetOptions)(config.target);
17
+ const external = (_e = config.external) !== null && _e !== void 0 ? _e : {};
18
+ const plugins = (_f = config.plugins) !== null && _f !== void 0 ? _f : [];
19
+ const builtins = (_g = config.builtins) !== null && _g !== void 0 ? _g : [];
20
+ const resolve = (_h = config.resolve) !== null && _h !== void 0 ? _h : {};
21
+ const module = (0, module_1.resolveModuleOptions)(config.module);
22
+ return {
23
+ context,
24
+ mode,
25
+ dev,
26
+ entry,
27
+ output,
28
+ define,
29
+ target,
30
+ external,
31
+ plugins,
32
+ builtins,
33
+ module,
34
+ resolve
35
+ };
36
+ }
37
+ exports.resolveOptions = resolveOptions;
@@ -0,0 +1,2 @@
1
+ export declare type Mode = string;
2
+ export declare type ResolvedMode = string;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +1,35 @@
1
1
  /// <reference types="node" />
2
- export * from "./build";
3
- import * as binding from "@rspack/binding";
4
2
  import type { RawModuleRuleUse, RawModuleRule } from "@rspack/binding";
5
- import type { RspackOptions } from "./config";
6
- interface ModuleRule {
3
+ export interface ModuleRule {
7
4
  test?: RawModuleRule["test"];
8
5
  resource?: RawModuleRule["resource"];
9
6
  resourceQuery?: RawModuleRule["resourceQuery"];
10
7
  uses?: ModuleRuleUse[];
11
8
  type?: RawModuleRule["type"];
12
9
  }
13
- declare type ModuleRuleUse = {
14
- builtinLoader: BuiltinLoader;
15
- options?: unknown;
16
- } | {
17
- loader: JsLoader;
18
- options?: unknown;
19
- };
20
- interface JsLoader {
21
- (this: LoaderContext, loaderContext: LoaderContext): Promise<LoaderResult | void> | LoaderResult | void;
22
- displayName?: string;
10
+ export interface Module {
11
+ rules?: ModuleRule[];
12
+ parser?: {
13
+ dataUrlCondition?: {
14
+ maxSize?: number;
15
+ };
16
+ };
17
+ }
18
+ interface ResolvedModuleRule {
19
+ test?: RawModuleRule["test"];
20
+ resource?: RawModuleRule["resource"];
21
+ resourceQuery?: RawModuleRule["resourceQuery"];
22
+ uses?: RawModuleRuleUse[];
23
+ type?: RawModuleRule["type"];
24
+ }
25
+ export interface ResolvedModule {
26
+ rules: ResolvedModuleRule[];
27
+ parser?: {
28
+ dataUrlCondition: {
29
+ maxSize: number;
30
+ };
31
+ };
23
32
  }
24
- declare type BuiltinLoader = string;
25
33
  interface LoaderContextInternal {
26
34
  source: number[];
27
35
  resource: String;
@@ -29,24 +37,28 @@ interface LoaderContextInternal {
29
37
  resourceQuery: String | null;
30
38
  resourceFragment: String | null;
31
39
  }
40
+ interface LoaderResult {
41
+ content: Buffer | string;
42
+ meta: Buffer | string;
43
+ }
32
44
  interface LoaderContext extends Pick<LoaderContextInternal, "resource" | "resourcePath" | "resourceQuery" | "resourceFragment"> {
33
45
  source: {
34
46
  getCode(): string;
35
47
  getBuffer(): Buffer;
36
48
  };
37
49
  }
38
- interface LoaderResult {
39
- content: Buffer | string;
40
- meta: Buffer | string;
50
+ interface JsLoader {
51
+ (this: LoaderContext, loaderContext: LoaderContext): Promise<LoaderResult | void> | LoaderResult | void;
52
+ displayName?: string;
41
53
  }
42
- declare function createRawModuleRuleUses(uses: ModuleRuleUse[]): RawModuleRuleUse[];
43
- declare class Rspack {
44
- #private;
45
- options: RspackOptions;
46
- constructor(options: RspackOptions);
47
- build(): Promise<binding.Stats>;
48
- rebuild(): Promise<Record<string, string>>;
49
- }
50
- export { Rspack, createRawModuleRuleUses };
51
- export type { ModuleRule };
52
- export default Rspack;
54
+ declare type BuiltinLoader = string;
55
+ declare type ModuleRuleUse = {
56
+ builtinLoader: BuiltinLoader;
57
+ options?: unknown;
58
+ } | {
59
+ loader: JsLoader;
60
+ options?: unknown;
61
+ };
62
+ export declare function createRawModuleRuleUses(uses: ModuleRuleUse[]): RawModuleRuleUse[];
63
+ export declare function resolveModuleOptions(module?: Module): ResolvedModule;
64
+ export {};
@@ -0,0 +1,121 @@
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.resolveModuleOptions = exports.createRawModuleRuleUses = void 0;
7
+ const node_assert_1 = __importDefault(require("node:assert"));
8
+ const toBuffer = (bufLike) => {
9
+ if (Buffer.isBuffer(bufLike)) {
10
+ return bufLike;
11
+ }
12
+ else if (typeof bufLike === "string") {
13
+ return Buffer.from(bufLike);
14
+ }
15
+ throw new Error("Buffer or string expected");
16
+ };
17
+ function composeJsUse(uses) {
18
+ if (!uses.length) {
19
+ return null;
20
+ }
21
+ async function loader(err, data) {
22
+ if (err) {
23
+ throw err;
24
+ }
25
+ const loaderThreadsafeContext = JSON.parse(data.toString("utf-8"));
26
+ const { p: payload, id } = loaderThreadsafeContext;
27
+ const loaderContextInternal = {
28
+ source: payload.source,
29
+ resourcePath: payload.resourcePath,
30
+ resourceQuery: payload.resourceQuery,
31
+ resource: payload.resource,
32
+ resourceFragment: payload.resourceFragment
33
+ };
34
+ let sourceBuffer = Buffer.from(loaderContextInternal.source);
35
+ let meta = Buffer.from("");
36
+ // Loader is executed from right to left
37
+ for (const use of uses) {
38
+ (0, node_assert_1.default)("loader" in use);
39
+ const loaderContext = {
40
+ ...loaderContextInternal,
41
+ source: {
42
+ getCode() {
43
+ return sourceBuffer.toString("utf-8");
44
+ },
45
+ getBuffer() {
46
+ return sourceBuffer;
47
+ }
48
+ },
49
+ getOptions() {
50
+ return use.options;
51
+ }
52
+ };
53
+ let loaderResult;
54
+ if ((loaderResult = await Promise.resolve().then(() => use.loader.apply(loaderContext, [loaderContext])))) {
55
+ const content = loaderResult.content;
56
+ meta = meta.length > 0 ? meta : toBuffer(loaderResult.meta);
57
+ sourceBuffer = toBuffer(content);
58
+ }
59
+ }
60
+ const loaderResultPayload = {
61
+ content: [...sourceBuffer],
62
+ meta: [...meta]
63
+ };
64
+ const loaderThreadsafeResult = {
65
+ id: id,
66
+ p: loaderResultPayload
67
+ };
68
+ return Buffer.from(JSON.stringify(loaderThreadsafeResult), "utf-8");
69
+ }
70
+ loader.displayName = `NodeLoaderAdapter(${uses
71
+ .map(item => {
72
+ (0, node_assert_1.default)("loader" in item);
73
+ return item.loader.displayName || item.loader.name || "unknown-loader";
74
+ })
75
+ .join(" -> ")})`;
76
+ return {
77
+ loader
78
+ };
79
+ }
80
+ function createRawModuleRuleUses(uses) {
81
+ return createRawModuleRuleUsesImpl([...uses].reverse());
82
+ }
83
+ exports.createRawModuleRuleUses = createRawModuleRuleUses;
84
+ function createRawModuleRuleUsesImpl(uses) {
85
+ if (!uses.length) {
86
+ return [];
87
+ }
88
+ const index = uses.findIndex(use => "builtinLoader" in use);
89
+ if (index < 0) {
90
+ return [composeJsUse(uses)];
91
+ }
92
+ const before = uses.slice(0, index);
93
+ const after = uses.slice(index + 1);
94
+ return [
95
+ composeJsUse(before),
96
+ createNativeUse(uses[index]),
97
+ ...createRawModuleRuleUsesImpl(after)
98
+ ].filter((item) => Boolean(item));
99
+ }
100
+ function createNativeUse(use) {
101
+ var _a;
102
+ (0, node_assert_1.default)("builtinLoader" in use);
103
+ if (use.builtinLoader === "sass-loader") {
104
+ ((_a = use.options) !== null && _a !== void 0 ? _a : (use.options = {})).__exePath = require.resolve(`@tmp-sass-embedded/${process.platform}-${process.arch}/dart-sass-embedded/dart-sass-embedded${process.platform === "win32" ? ".bat" : ""}`);
105
+ }
106
+ return {
107
+ builtinLoader: use.builtinLoader,
108
+ options: JSON.stringify(use.options)
109
+ };
110
+ }
111
+ function resolveModuleOptions(module = {}) {
112
+ var _a;
113
+ const rules = ((_a = module.rules) !== null && _a !== void 0 ? _a : []).map(rule => ({
114
+ ...rule,
115
+ uses: createRawModuleRuleUses(rule.uses || [])
116
+ }));
117
+ return {
118
+ rules
119
+ };
120
+ }
121
+ exports.resolveModuleOptions = resolveModuleOptions;
@@ -0,0 +1,17 @@
1
+ export interface Output {
2
+ path?: string;
3
+ publicPath?: string;
4
+ assetModuleFilename?: string;
5
+ filename?: string;
6
+ chunkFilename?: string;
7
+ uniqueName?: string;
8
+ }
9
+ export interface ResolvedOutput {
10
+ path?: string;
11
+ publicPath?: string;
12
+ assetModuleFilename?: string;
13
+ filename?: string;
14
+ chunkFilename?: string;
15
+ uniqueName?: string;
16
+ }
17
+ export declare function resolveOutputOptions(output?: Output): ResolvedOutput;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveOutputOptions = void 0;
4
+ function resolveOutputOptions(output = {}) {
5
+ return {
6
+ path: output.path,
7
+ publicPath: output.publicPath,
8
+ chunkFilename: output.chunkFilename,
9
+ filename: output.publicPath,
10
+ assetModuleFilename: output.assetModuleFilename,
11
+ uniqueName: output.uniqueName
12
+ };
13
+ }
14
+ exports.resolveOutputOptions = resolveOutputOptions;
@@ -0,0 +1,5 @@
1
+ import Rspack from "..";
2
+ export interface Plugin {
3
+ name: string;
4
+ apply(compiler: Rspack): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare type Resolve = {
2
+ preferRelative?: boolean;
3
+ };
4
+ export declare type ResolvedResolve = {
5
+ preferRelative?: boolean;
6
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ declare type TargetItem = "web" | "webworker" | "browserslist" | "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022";
2
+ export declare type Target = TargetItem | TargetItem[] | false;
3
+ export declare type ResolvedTarget = TargetItem[];
4
+ export declare function resolveTargetOptions(target?: Target): ResolvedTarget;
5
+ export {};
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTargetOptions = void 0;
4
+ function resolveTargetOptions(target = "web") {
5
+ if (!target) {
6
+ return [];
7
+ }
8
+ if (!Array.isArray(target)) {
9
+ return [target];
10
+ }
11
+ return target;
12
+ }
13
+ exports.resolveTargetOptions = resolveTargetOptions;
package/lib/index.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ export * from "./build";
2
+ import * as binding from "@rspack/binding";
3
+ import * as tapable from "tapable";
4
+ import { RspackOptions, ResolvedRspackOptions, Asset } from "./config";
5
+ import { Source } from "webpack-sources";
6
+ declare class RspackCompilation {
7
+ #private;
8
+ hooks: {
9
+ processAssets: tapable.AsyncSeriesHook<Record<string, Source>>;
10
+ };
11
+ constructor();
12
+ /**
13
+ * unsafe to call out of processAssets
14
+ * @param filename
15
+ * @param asset
16
+ */
17
+ updateAsset(filename: string, asset: Asset): void;
18
+ /**
19
+ * unsafe to call out of processAssets
20
+ * @param filename
21
+ * @param asset
22
+ */
23
+ emitAsset(filename: string, asset: Asset): void;
24
+ processAssets(err: Error, value: string, emitAsset: any): Promise<string>;
25
+ }
26
+ declare class Rspack {
27
+ #private;
28
+ compilation: RspackCompilation;
29
+ hooks: {
30
+ done: tapable.AsyncSeriesHook<void>;
31
+ compilation: tapable.SyncHook<RspackCompilation>;
32
+ };
33
+ options: ResolvedRspackOptions;
34
+ constructor(options: RspackOptions);
35
+ build(): Promise<binding.Stats>;
36
+ rebuild(changeFiles: string[]): Promise<Record<string, string>>;
37
+ }
38
+ export { Rspack };
39
+ export default Rspack;