@rspack/core 0.0.4 → 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.
- package/CHANGELOG.md +10 -0
- package/lib/bin/index.d.ts +1 -0
- package/lib/bin/index.js +32 -0
- package/lib/build.d.ts +1 -0
- package/lib/build.js +12 -0
- package/lib/config/builtins.d.ts +3 -0
- package/lib/config/builtins.js +2 -0
- package/lib/config/context.d.ts +2 -0
- package/lib/config/context.js +2 -0
- package/lib/config/define.d.ts +2 -0
- package/lib/config/define.js +2 -0
- package/lib/config/dev.d.ts +17 -0
- package/lib/config/dev.js +17 -0
- package/lib/config/entry.d.ts +2 -0
- package/lib/config/entry.js +2 -0
- package/lib/config/external.d.ts +2 -0
- package/lib/config/external.js +2 -0
- package/lib/config/index.d.ts +45 -0
- package/lib/config/index.js +37 -0
- package/lib/config/mode.d.ts +2 -0
- package/lib/config/mode.js +2 -0
- package/lib/config/module.d.ts +64 -0
- package/lib/config/module.js +121 -0
- package/lib/config/output.d.ts +17 -0
- package/lib/config/output.js +14 -0
- package/lib/config/plugin.d.ts +5 -0
- package/lib/config/plugin.js +2 -0
- package/lib/config/resolve.d.ts +6 -0
- package/lib/config/resolve.js +2 -0
- package/lib/config/target.d.ts +5 -0
- package/lib/config/target.js +13 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.js +154 -0
- package/lib/server/index.d.ts +0 -0
- package/lib/server/index.js +0 -0
- package/package.json +6 -7
- package/src/bin/index.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/bin/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const commander_1 = require("commander");
|
|
4
|
+
const dev_server_1 = require("@rspack/dev-server");
|
|
5
|
+
const __1 = require("..");
|
|
6
|
+
const build_1 = require("../build");
|
|
7
|
+
const program = new commander_1.Command();
|
|
8
|
+
program
|
|
9
|
+
.option("--env", "env")
|
|
10
|
+
.command("build", {
|
|
11
|
+
isDefault: true
|
|
12
|
+
})
|
|
13
|
+
.description("Rspack build cli")
|
|
14
|
+
.argument("<config-file>", "rspack config file path")
|
|
15
|
+
.action(async (configPath) => {
|
|
16
|
+
const config = require(configPath);
|
|
17
|
+
const stats = await (0, build_1.build)(config);
|
|
18
|
+
console.log(stats);
|
|
19
|
+
});
|
|
20
|
+
program
|
|
21
|
+
.command("dev")
|
|
22
|
+
.description("Rspack build cli")
|
|
23
|
+
.argument("<config-file>", "rspack config file path")
|
|
24
|
+
.action(async (configPath) => {
|
|
25
|
+
const config = require(configPath);
|
|
26
|
+
const rspack = new __1.Rspack(config);
|
|
27
|
+
const { options: { dev: { port = 8080 } = {} } = {} } = rspack;
|
|
28
|
+
await rspack.build();
|
|
29
|
+
const server = await (0, dev_server_1.createServer)(rspack.options);
|
|
30
|
+
server.listen(port, () => console.log(`Server listening on port: ${port}`));
|
|
31
|
+
});
|
|
32
|
+
program.parse();
|
package/lib/build.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function build(config: any): Promise<void>;
|
package/lib/build.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
async function build(config) {
|
|
6
|
+
const rspack = new _1.Rspack(config);
|
|
7
|
+
const stats = await rspack.build();
|
|
8
|
+
if (stats.errors.length > 0) {
|
|
9
|
+
throw new Error(stats.errors[0].message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.build = build;
|
|
@@ -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,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,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { RawModuleRuleUse, RawModuleRule } from "@rspack/binding";
|
|
3
|
+
export interface ModuleRule {
|
|
4
|
+
test?: RawModuleRule["test"];
|
|
5
|
+
resource?: RawModuleRule["resource"];
|
|
6
|
+
resourceQuery?: RawModuleRule["resourceQuery"];
|
|
7
|
+
uses?: ModuleRuleUse[];
|
|
8
|
+
type?: RawModuleRule["type"];
|
|
9
|
+
}
|
|
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
|
+
};
|
|
32
|
+
}
|
|
33
|
+
interface LoaderContextInternal {
|
|
34
|
+
source: number[];
|
|
35
|
+
resource: String;
|
|
36
|
+
resourcePath: String;
|
|
37
|
+
resourceQuery: String | null;
|
|
38
|
+
resourceFragment: String | null;
|
|
39
|
+
}
|
|
40
|
+
interface LoaderResult {
|
|
41
|
+
content: Buffer | string;
|
|
42
|
+
meta: Buffer | string;
|
|
43
|
+
}
|
|
44
|
+
interface LoaderContext extends Pick<LoaderContextInternal, "resource" | "resourcePath" | "resourceQuery" | "resourceFragment"> {
|
|
45
|
+
source: {
|
|
46
|
+
getCode(): string;
|
|
47
|
+
getBuffer(): Buffer;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface JsLoader {
|
|
51
|
+
(this: LoaderContext, loaderContext: LoaderContext): Promise<LoaderResult | void> | LoaderResult | void;
|
|
52
|
+
displayName?: string;
|
|
53
|
+
}
|
|
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
|
+
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;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
29
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
30
|
+
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");
|
|
31
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
32
|
+
};
|
|
33
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
34
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
35
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
36
|
+
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");
|
|
37
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
38
|
+
};
|
|
39
|
+
var _RspackCompilation_emitAssetCallback, _Rspack_instances, _Rspack_plugins, _Rspack_instance, _Rspack_done, _Rspack_processAssets, _Rspack_newCompilation;
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.Rspack = void 0;
|
|
42
|
+
__exportStar(require("./build"), exports);
|
|
43
|
+
const binding = __importStar(require("@rspack/binding"));
|
|
44
|
+
const tapable = __importStar(require("tapable"));
|
|
45
|
+
const config_1 = require("./config");
|
|
46
|
+
const webpack_sources_1 = require("webpack-sources");
|
|
47
|
+
const createDummyResult = (id) => {
|
|
48
|
+
const result = {
|
|
49
|
+
id,
|
|
50
|
+
inner: null
|
|
51
|
+
};
|
|
52
|
+
return JSON.stringify(result);
|
|
53
|
+
};
|
|
54
|
+
class RspackCompilation {
|
|
55
|
+
constructor() {
|
|
56
|
+
_RspackCompilation_emitAssetCallback.set(this, void 0);
|
|
57
|
+
this.hooks = {
|
|
58
|
+
processAssets: new tapable.AsyncSeriesHook([
|
|
59
|
+
"assets"
|
|
60
|
+
])
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* unsafe to call out of processAssets
|
|
65
|
+
* @param filename
|
|
66
|
+
* @param asset
|
|
67
|
+
*/
|
|
68
|
+
updateAsset(filename, asset) {
|
|
69
|
+
this.emitAsset(filename, asset);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* unsafe to call out of processAssets
|
|
73
|
+
* @param filename
|
|
74
|
+
* @param asset
|
|
75
|
+
*/
|
|
76
|
+
emitAsset(filename, asset) {
|
|
77
|
+
if (!__classPrivateFieldGet(this, _RspackCompilation_emitAssetCallback, "f")) {
|
|
78
|
+
throw new Error("can't call emitAsset outof processAssets hook for now");
|
|
79
|
+
}
|
|
80
|
+
__classPrivateFieldGet(this, _RspackCompilation_emitAssetCallback, "f").call(this, {
|
|
81
|
+
filename: filename,
|
|
82
|
+
asset
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async processAssets(err, value, emitAsset) {
|
|
86
|
+
var _a;
|
|
87
|
+
__classPrivateFieldSet(this, _RspackCompilation_emitAssetCallback, emitAsset, "f");
|
|
88
|
+
if (err) {
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
const context = JSON.parse(value);
|
|
92
|
+
let content = (_a = context.inner) !== null && _a !== void 0 ? _a : {};
|
|
93
|
+
let assets = {};
|
|
94
|
+
for (const [key, value] of Object.entries(content)) {
|
|
95
|
+
// webpack-sources's type definition is wrong, it actually could accept Buffer type
|
|
96
|
+
let source = value.source;
|
|
97
|
+
if (Array.isArray(value.source)) {
|
|
98
|
+
source = Buffer.from(value.source);
|
|
99
|
+
}
|
|
100
|
+
assets[key] = new webpack_sources_1.RawSource(source);
|
|
101
|
+
}
|
|
102
|
+
await this.hooks.processAssets.promise(assets);
|
|
103
|
+
return createDummyResult(context.id);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
_RspackCompilation_emitAssetCallback = new WeakMap();
|
|
107
|
+
class Rspack {
|
|
108
|
+
constructor(options) {
|
|
109
|
+
var _a;
|
|
110
|
+
_Rspack_instances.add(this);
|
|
111
|
+
_Rspack_plugins.set(this, void 0);
|
|
112
|
+
_Rspack_instance.set(this, void 0);
|
|
113
|
+
this.options = (0, config_1.resolveOptions)(options);
|
|
114
|
+
// @ts-ignored
|
|
115
|
+
__classPrivateFieldSet(this, _Rspack_instance, binding.newRspack(this.options, {
|
|
116
|
+
doneCallback: __classPrivateFieldGet(this, _Rspack_instances, "m", _Rspack_done).bind(this),
|
|
117
|
+
processAssetsCallback: __classPrivateFieldGet(this, _Rspack_instances, "m", _Rspack_processAssets).bind(this)
|
|
118
|
+
}), "f");
|
|
119
|
+
this.hooks = {
|
|
120
|
+
done: new tapable.AsyncSeriesHook(),
|
|
121
|
+
compilation: new tapable.SyncHook(["compilation"])
|
|
122
|
+
};
|
|
123
|
+
__classPrivateFieldSet(this, _Rspack_plugins, (_a = options.plugins) !== null && _a !== void 0 ? _a : [], "f");
|
|
124
|
+
for (const plugin of __classPrivateFieldGet(this, _Rspack_plugins, "f")) {
|
|
125
|
+
plugin.apply(this);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async build() {
|
|
129
|
+
const compilation = __classPrivateFieldGet(this, _Rspack_instances, "m", _Rspack_newCompilation).call(this);
|
|
130
|
+
const stats = await binding.build(__classPrivateFieldGet(this, _Rspack_instance, "f"));
|
|
131
|
+
return stats;
|
|
132
|
+
}
|
|
133
|
+
async rebuild(changeFiles) {
|
|
134
|
+
const stats = await binding.rebuild(__classPrivateFieldGet(this, _Rspack_instance, "f"), changeFiles);
|
|
135
|
+
return stats;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.Rspack = Rspack;
|
|
139
|
+
_Rspack_plugins = new WeakMap(), _Rspack_instance = new WeakMap(), _Rspack_instances = new WeakSet(), _Rspack_done = async function _Rspack_done(err, value) {
|
|
140
|
+
if (err) {
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
const context = JSON.parse(value);
|
|
144
|
+
await this.hooks.done.promise();
|
|
145
|
+
return createDummyResult(context.id);
|
|
146
|
+
}, _Rspack_processAssets = async function _Rspack_processAssets(err, value, emitAsset) {
|
|
147
|
+
return this.compilation.processAssets(err, value, emitAsset);
|
|
148
|
+
}, _Rspack_newCompilation = function _Rspack_newCompilation() {
|
|
149
|
+
const compilation = new RspackCompilation();
|
|
150
|
+
this.compilation = compilation;
|
|
151
|
+
this.hooks.compilation.call(compilation);
|
|
152
|
+
return compilation;
|
|
153
|
+
};
|
|
154
|
+
exports.default = Rspack;
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"bin": {
|
|
5
5
|
"rspack": "./bin.js"
|
|
6
6
|
},
|
|
@@ -14,20 +14,20 @@
|
|
|
14
14
|
"@types/ws": "8.5.3",
|
|
15
15
|
"@types/connect": "3.4.35",
|
|
16
16
|
"uvu": "0.5.6",
|
|
17
|
-
"@rspack/core": "0.0.
|
|
17
|
+
"@rspack/core": "0.0.6",
|
|
18
18
|
"@types/webpack-sources": "3.2.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@rspack/binding": "0.0.
|
|
21
|
+
"@rspack/binding": "0.0.6",
|
|
22
22
|
"commander": "9.4.0",
|
|
23
23
|
"ws": "8.8.1",
|
|
24
24
|
"connect": "3.7.0",
|
|
25
25
|
"chokidar": "3.5.3",
|
|
26
26
|
"open": "8.4.0",
|
|
27
27
|
"clipanion": "3.2.0-rc.11",
|
|
28
|
-
"@rspack/dev-server": "^0.0.
|
|
28
|
+
"@rspack/dev-server": "^0.0.6",
|
|
29
29
|
"sirv": "2.0.2",
|
|
30
|
-
"@rspack/plugin-postcss": "^0.0.
|
|
30
|
+
"@rspack/plugin-postcss": "^0.0.6",
|
|
31
31
|
"tapable": "2.2.1",
|
|
32
32
|
"webpack-sources": "3.2.3"
|
|
33
33
|
},
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
"dev": "tsc -w",
|
|
46
46
|
"example": "node -r ts-node/register ./example/basic.ts",
|
|
47
47
|
"test": "uvu -r tsm tests"
|
|
48
|
-
}
|
|
49
|
-
"readme": "# rspack\n"
|
|
48
|
+
}
|
|
50
49
|
}
|
package/src/bin/index.ts
CHANGED
|
File without changes
|