@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.
- package/dist/compilation.d.ts +64 -0
- package/dist/compilation.d.ts.map +1 -0
- package/dist/compilation.js +148 -0
- package/dist/compilation.js.map +1 -0
- package/dist/compiler.d.ts +52 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +383 -0
- package/dist/compiler.js.map +1 -0
- package/dist/config/RspackOptions.d.ts +36 -0
- package/dist/config/RspackOptions.d.ts.map +1 -0
- package/{lib/config/define.js → dist/config/RspackOptions.js} +1 -0
- package/dist/config/RspackOptions.js.map +1 -0
- package/dist/config/browserslistTargetHandler.d.ts +20 -0
- package/dist/config/browserslistTargetHandler.d.ts.map +1 -0
- package/dist/config/browserslistTargetHandler.js +320 -0
- package/dist/config/browserslistTargetHandler.js.map +1 -0
- package/dist/config/builtins.d.ts +15 -0
- package/dist/config/builtins.d.ts.map +1 -0
- package/dist/config/builtins.js +49 -0
- package/dist/config/builtins.js.map +1 -0
- package/{lib → dist}/config/context.d.ts +1 -0
- package/dist/config/context.d.ts.map +1 -0
- package/{lib → dist}/config/context.js +1 -0
- package/dist/config/context.js.map +1 -0
- package/dist/config/defaults.d.ts +4 -0
- package/dist/config/defaults.d.ts.map +1 -0
- package/dist/config/defaults.js +57 -0
- package/dist/config/defaults.js.map +1 -0
- package/dist/config/devServer.d.ts +21 -0
- package/dist/config/devServer.d.ts.map +1 -0
- package/{lib/config/builtins.js → dist/config/devServer.js} +1 -0
- package/dist/config/devServer.js.map +1 -0
- package/dist/config/devtool.d.ts +5 -0
- package/dist/config/devtool.d.ts.map +1 -0
- package/dist/config/devtool.js +13 -0
- package/dist/config/devtool.js.map +1 -0
- package/dist/config/entry.d.ts +8 -0
- package/dist/config/entry.d.ts.map +1 -0
- package/dist/config/entry.js +39 -0
- package/dist/config/entry.js.map +1 -0
- package/dist/config/external.d.ts +5 -0
- package/dist/config/external.d.ts.map +1 -0
- package/{lib → dist}/config/external.js +1 -0
- package/dist/config/external.js.map +1 -0
- package/dist/config/index.d.ts +57 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +55 -0
- package/dist/config/index.js.map +1 -0
- package/{lib → dist}/config/mode.d.ts +1 -0
- package/dist/config/mode.d.ts.map +1 -0
- package/{lib → dist}/config/mode.js +1 -0
- package/dist/config/mode.js.map +1 -0
- package/{lib → dist}/config/module.d.ts +22 -7
- package/dist/config/module.d.ts.map +1 -0
- package/{lib → dist}/config/module.js +29 -21
- package/dist/config/module.js.map +1 -0
- package/{lib → dist}/config/output.d.ts +6 -0
- package/dist/config/output.d.ts.map +1 -0
- package/dist/config/output.js +10 -0
- package/dist/config/output.js.map +1 -0
- package/dist/config/plugin.d.ts +6 -0
- package/dist/config/plugin.d.ts.map +1 -0
- package/{lib → dist}/config/plugin.js +1 -0
- package/dist/config/plugin.js.map +1 -0
- package/dist/config/resolve.d.ts +22 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +33 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/config/stats.d.ts +21 -0
- package/dist/config/stats.d.ts.map +1 -0
- package/dist/config/stats.js +17 -0
- package/dist/config/stats.js.map +1 -0
- package/dist/config/target.d.ts +7 -0
- package/dist/config/target.d.ts.map +1 -0
- package/dist/config/target.js +21 -0
- package/dist/config/target.js.map +1 -0
- package/dist/config/watch.d.ts +8 -0
- package/dist/config/watch.d.ts.map +1 -0
- package/dist/config/watch.js +16 -0
- package/dist/config/watch.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/Logger.d.ts +43 -0
- package/dist/logging/Logger.d.ts.map +1 -0
- package/dist/logging/Logger.js +136 -0
- package/dist/logging/Logger.js.map +1 -0
- package/dist/logging/createConsoleLogger.d.ts +7 -0
- package/dist/logging/createConsoleLogger.d.ts.map +1 -0
- package/dist/logging/createConsoleLogger.js +227 -0
- package/dist/logging/createConsoleLogger.js.map +1 -0
- package/dist/logging/runtime.d.ts +14 -0
- package/dist/logging/runtime.d.ts.map +1 -0
- package/dist/logging/runtime.js +42 -0
- package/dist/logging/runtime.js.map +1 -0
- package/dist/logging/truncateArgs.d.ts +8 -0
- package/dist/logging/truncateArgs.d.ts.map +1 -0
- package/dist/logging/truncateArgs.js +81 -0
- package/dist/logging/truncateArgs.js.map +1 -0
- package/dist/node/NodeTargetPlugin.d.ts +5 -0
- package/dist/node/NodeTargetPlugin.d.ts.map +1 -0
- package/dist/node/NodeTargetPlugin.js +70 -0
- package/dist/node/NodeTargetPlugin.js.map +1 -0
- package/dist/node/nodeConsole.d.ts +22 -0
- package/dist/node/nodeConsole.d.ts.map +1 -0
- package/dist/node/nodeConsole.js +121 -0
- package/dist/node/nodeConsole.js.map +1 -0
- package/dist/rspack.d.ts +8 -0
- package/dist/rspack.d.ts.map +1 -0
- package/dist/rspack.js +59 -0
- package/dist/rspack.js.map +1 -0
- package/dist/rspackOptionsApply.d.ts +6 -0
- package/dist/rspackOptionsApply.d.ts.map +1 -0
- package/dist/rspackOptionsApply.js +25 -0
- package/dist/rspackOptionsApply.js.map +1 -0
- package/dist/stats.d.ts +21 -0
- package/dist/stats.d.ts.map +1 -0
- package/dist/stats.js +870 -0
- package/dist/stats.js.map +1 -0
- package/dist/utils/createHash.d.ts +7 -0
- package/dist/utils/createHash.d.ts.map +1 -0
- package/dist/utils/createHash.js +166 -0
- package/dist/utils/createHash.js.map +1 -0
- package/dist/utils/createSource.d.ts +6 -0
- package/dist/utils/createSource.d.ts.map +1 -0
- package/dist/utils/createSource.js +48 -0
- package/dist/utils/createSource.js.map +1 -0
- package/dist/utils/hash/BatchedHash.d.ts +16 -0
- package/dist/utils/hash/BatchedHash.d.ts.map +1 -0
- package/dist/utils/hash/BatchedHash.js +61 -0
- package/dist/utils/hash/BatchedHash.js.map +1 -0
- package/dist/utils/hash/index.d.ts +19 -0
- package/dist/utils/hash/index.d.ts.map +1 -0
- package/dist/utils/hash/index.js +28 -0
- package/dist/utils/hash/index.js.map +1 -0
- package/dist/utils/hash/md4.d.ts +3 -0
- package/dist/utils/hash/md4.d.ts.map +1 -0
- package/dist/utils/hash/md4.js +13 -0
- package/dist/utils/hash/md4.js.map +1 -0
- package/dist/utils/hash/wasm-hash.d.ts +7 -0
- package/dist/utils/hash/wasm-hash.d.ts.map +1 -0
- package/dist/utils/hash/wasm-hash.js +162 -0
- package/dist/utils/hash/wasm-hash.js.map +1 -0
- package/dist/utils/hash/xxhash64.d.ts +3 -0
- package/dist/utils/hash/xxhash64.d.ts.map +1 -0
- package/dist/utils/hash/xxhash64.js +13 -0
- package/dist/utils/hash/xxhash64.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/memoize.d.ts +2 -0
- package/dist/utils/memoize.d.ts.map +1 -0
- package/dist/utils/memoize.js +22 -0
- package/dist/utils/memoize.js.map +1 -0
- package/dist/web/polyfillBuiltins.d.ts +5 -0
- package/dist/web/polyfillBuiltins.d.ts.map +1 -0
- package/dist/web/polyfillBuiltins.js +43 -0
- package/dist/web/polyfillBuiltins.js.map +1 -0
- package/package.json +28 -23
- package/CHANGELOG.md +0 -51
- package/bin.js +0 -1
- package/example/basic.ts +0 -71
- package/example/react-example/index.html +0 -12
- package/example/react-example/package.json +0 -17
- package/example/react-example/rspack.config.json +0 -13
- package/example/react-example/src/app.jsx +0 -44
- package/example/react-example/src/base.css +0 -9
- package/example/react-example/src/button.jsx +0 -3
- package/example/react-example/src/dark.svg +0 -1
- package/example/react-example/src/data.json +0 -5
- package/example/react-example/src/file.jpg +0 -0
- package/example/react-example/src/file.png +0 -0
- package/example/react-example/src/file.svg +0 -1
- package/example/react-example/src/foo.css +0 -3
- package/example/react-example/src/index.html +0 -32
- package/example/react-example/src/index.js +0 -1
- package/example/react-example/src/light.svg +0 -48
- package/example/react-example/src/logo.svg +0 -18
- package/example/react-with-sass.ts +0 -28
- package/lib/bin/index.d.ts +0 -1
- package/lib/bin/index.js +0 -32
- package/lib/build.d.ts +0 -1
- package/lib/build.js +0 -12
- package/lib/config/builtins.d.ts +0 -3
- package/lib/config/define.d.ts +0 -2
- package/lib/config/dev.d.ts +0 -17
- package/lib/config/dev.js +0 -17
- package/lib/config/entry.d.ts +0 -2
- package/lib/config/entry.js +0 -2
- package/lib/config/external.d.ts +0 -2
- package/lib/config/index.d.ts +0 -45
- package/lib/config/index.js +0 -37
- package/lib/config/output.js +0 -14
- package/lib/config/plugin.d.ts +0 -5
- package/lib/config/resolve.d.ts +0 -6
- package/lib/config/resolve.js +0 -2
- package/lib/config/target.d.ts +0 -5
- package/lib/config/target.js +0 -13
- package/lib/index.d.ts +0 -39
- package/lib/index.js +0 -154
- package/lib/server/index.d.ts +0 -0
- package/lib/server/index.js +0 -0
- package/src/bin/index.ts +0 -36
- package/src/build.ts +0 -8
- package/src/config/builtins.ts +0 -5
- package/src/config/context.ts +0 -3
- package/src/config/define.ts +0 -3
- package/src/config/dev.ts +0 -32
- package/src/config/entry.ts +0 -3
- package/src/config/external.ts +0 -3
- package/src/config/index.ts +0 -80
- package/src/config/mode.ts +0 -2
- package/src/config/module.ts +0 -240
- package/src/config/output.ts +0 -29
- package/src/config/plugin.ts +0 -6
- package/src/config/resolve.ts +0 -6
- package/src/config/target.ts +0 -28
- package/src/index.ts +0 -140
- package/src/server/index.ts +0 -0
- package/tests/config.test.ts +0 -40
- 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
|
-
}
|
package/src/config/entry.ts
DELETED
package/src/config/external.ts
DELETED
package/src/config/index.ts
DELETED
|
@@ -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
|
-
}
|
package/src/config/mode.ts
DELETED
package/src/config/module.ts
DELETED
|
@@ -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
|
-
}
|
package/src/config/output.ts
DELETED
|
@@ -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
|
-
}
|
package/src/config/plugin.ts
DELETED
package/src/config/resolve.ts
DELETED
package/src/config/target.ts
DELETED
|
@@ -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;
|
package/src/server/index.ts
DELETED
|
File without changes
|
package/tests/config.test.ts
DELETED
|
@@ -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