@evjs/webpack-plugin 0.0.1-alpha.5 → 0.0.1-alpha.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/README.md +9 -11
- package/esm/index.d.ts +2 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +116 -66
- package/esm/index.js.map +1 -1
- package/esm/server-fn-loader.d.ts +9 -0
- package/esm/server-fn-loader.d.ts.map +1 -1
- package/esm/server-fn-loader.js +9 -2
- package/esm/server-fn-loader.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -5,11 +5,12 @@ Build-time integration for React Server Functions in the **ev** framework.
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **`EvWebpackPlugin`**: Zero-config plugin that:
|
|
8
|
-
-
|
|
9
|
-
-
|
|
8
|
+
- Spawns a Node-targeted **Child Compiler** for server-side code.
|
|
9
|
+
- **Auto-discovers** `"use server"` files in `src/` dynamically.
|
|
10
|
+
- Watches for new files during development and triggers server rebuilds.
|
|
11
|
+
- Emits a versioned `manifest.json` mapping function IDs.
|
|
10
12
|
- **`server-fn-loader`**: Transforms files marked with `"use server"`.
|
|
11
|
-
-
|
|
12
|
-
- On the **client**: Replaces the implementation with an RPC stub.
|
|
13
|
+
- Automatically detects if it is running in a client or server compiler context.
|
|
13
14
|
|
|
14
15
|
## Usage
|
|
15
16
|
|
|
@@ -18,7 +19,7 @@ const { EvWebpackPlugin } = require("@evjs/webpack-plugin");
|
|
|
18
19
|
|
|
19
20
|
module.exports = {
|
|
20
21
|
plugins: [
|
|
21
|
-
new EvWebpackPlugin()
|
|
22
|
+
new EvWebpackPlugin() // Handles both client and server discovery
|
|
22
23
|
],
|
|
23
24
|
module: {
|
|
24
25
|
rules: [
|
|
@@ -26,11 +27,8 @@ module.exports = {
|
|
|
26
27
|
test: /\.tsx?$/,
|
|
27
28
|
exclude: /node_modules/,
|
|
28
29
|
use: [
|
|
29
|
-
{ loader: "swc-loader"
|
|
30
|
-
{
|
|
31
|
-
loader: "@evjs/webpack-plugin/server-fn-loader",
|
|
32
|
-
options: { isServer: false }
|
|
33
|
-
}
|
|
30
|
+
{ loader: "swc-loader" },
|
|
31
|
+
{ loader: "@evjs/webpack-plugin/server-fn-loader" }
|
|
34
32
|
]
|
|
35
33
|
}
|
|
36
34
|
]
|
|
@@ -38,4 +36,4 @@ module.exports = {
|
|
|
38
36
|
};
|
|
39
37
|
```
|
|
40
38
|
|
|
41
|
-
|
|
39
|
+
`EvWebpackPlugin` handles the heavy lifting of entry generation and child-compiler orchestration, allowing you to focus on writing your application logic.
|
package/esm/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import type { Compiler } from "webpack";
|
|
|
2
2
|
/**
|
|
3
3
|
* Webpack plugin for the ev framework.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
* On all builds, emits the `manifest.json` mapping function IDs to assets.
|
|
5
|
+
* Automatically discovers files with the "use server" directive based on the client dependencies
|
|
6
|
+
* and manages the server-side build via a child compiler.
|
|
8
7
|
*/
|
|
9
8
|
export declare class EvWebpackPlugin {
|
|
10
9
|
apply(compiler: Compiler): void;
|
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAmBxC;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA+KzB"}
|
package/esm/index.js
CHANGED
|
@@ -1,93 +1,143 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { glob } from "node:fs";
|
|
4
2
|
class ManifestCollector {
|
|
5
|
-
|
|
3
|
+
serverFns = {};
|
|
6
4
|
addServerFn(id, meta) {
|
|
7
|
-
this.
|
|
5
|
+
this.serverFns[id] = meta;
|
|
8
6
|
}
|
|
9
7
|
getManifest() {
|
|
10
8
|
return {
|
|
11
9
|
version: 1,
|
|
12
|
-
|
|
10
|
+
serverFns: this.serverFns,
|
|
13
11
|
};
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Check if a file starts with the "use server" directive.
|
|
18
|
-
*/
|
|
19
|
-
function hasUseServerDirective(filePath) {
|
|
20
|
-
try {
|
|
21
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
22
|
-
const firstLine = content.trimStart().split("\n")[0];
|
|
23
|
-
return /^["']use server["'];?\s*$/.test(firstLine.trim());
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
14
|
/**
|
|
30
15
|
* Webpack plugin for the ev framework.
|
|
31
16
|
*
|
|
32
|
-
*
|
|
33
|
-
* the
|
|
34
|
-
* On all builds, emits the `manifest.json` mapping function IDs to assets.
|
|
17
|
+
* Automatically discovers files with the "use server" directive based on the client dependencies
|
|
18
|
+
* and manages the server-side build via a child compiler.
|
|
35
19
|
*/
|
|
36
20
|
export class EvWebpackPlugin {
|
|
37
21
|
apply(compiler) {
|
|
38
22
|
const collector = new ManifestCollector();
|
|
39
23
|
// Attach collector to compiler so the loader can access it
|
|
40
24
|
compiler._ev_manifest_collector = collector;
|
|
41
|
-
//
|
|
42
|
-
const isServer = compiler.options.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (pending === 0) {
|
|
73
|
-
callback();
|
|
25
|
+
// Check if the current compiler is already the Node Child Compiler
|
|
26
|
+
const isServer = compiler.options.name === "evServer" ||
|
|
27
|
+
compiler.options.target === "node";
|
|
28
|
+
if (!isServer) {
|
|
29
|
+
// We are in the Client compiler.
|
|
30
|
+
compiler.hooks.make.tapAsync("EvWebpackPlugin", async (compilation, callback) => {
|
|
31
|
+
// In Webpack 5, we can use the finishModules hook to inspect all parsed modules
|
|
32
|
+
compilation.hooks.finishModules.tapAsync("EvWebpackPlugin", (modules, finishCallback) => {
|
|
33
|
+
let hasServer = false;
|
|
34
|
+
const imports = [];
|
|
35
|
+
imports.push(`import { createServer } from "@evjs/runtime/server";`);
|
|
36
|
+
let id = 0;
|
|
37
|
+
for (const module of modules) {
|
|
38
|
+
// Determine if this is a NormalModule with a resource path
|
|
39
|
+
const resource = "resource" in module ? module.resource : null;
|
|
40
|
+
if (!resource || typeof resource !== "string")
|
|
41
|
+
continue;
|
|
42
|
+
// Ensure it's a source file (not a node_module or internal webpack file)
|
|
43
|
+
if (resource.includes("node_modules") ||
|
|
44
|
+
!/\.(ts|tsx|js|jsx)$/.test(resource)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const content = fs.readFileSync(resource, "utf-8");
|
|
49
|
+
const firstLine = content.trimStart().split("\n")[0];
|
|
50
|
+
const isServerFile = /^["']use server["'];?\s*$/.test(firstLine.trim());
|
|
51
|
+
if (isServerFile) {
|
|
52
|
+
hasServer = true;
|
|
53
|
+
// Compute a relative path from the compiler context (or just use absolute path)
|
|
54
|
+
// But using absolute path avoids relative resolution issues completely.
|
|
55
|
+
imports.push(`import * as _fns_${id++} from ${JSON.stringify(resource)};`);
|
|
74
56
|
}
|
|
75
|
-
}
|
|
57
|
+
}
|
|
58
|
+
catch (_err) {
|
|
59
|
+
// Ignore read errors for dynamically generated Webpack modules
|
|
60
|
+
}
|
|
76
61
|
}
|
|
62
|
+
if (!hasServer) {
|
|
63
|
+
return finishCallback();
|
|
64
|
+
}
|
|
65
|
+
imports.push(`createServer();`);
|
|
66
|
+
const serverEntryContent = imports.join("\n");
|
|
67
|
+
// Use a Data URI as a virtual entry point
|
|
68
|
+
const serverEntryPath = `data:text/javascript,${encodeURIComponent(serverEntryContent)}`;
|
|
69
|
+
// 3. Spawn the Node Server compiler.
|
|
70
|
+
const outputOptions = {
|
|
71
|
+
filename: "../server/index.js",
|
|
72
|
+
library: { type: "commonjs", name: "evServer" },
|
|
73
|
+
chunkFormat: "commonjs",
|
|
74
|
+
};
|
|
75
|
+
const childCompiler = compilation.createChildCompiler("evServer", outputOptions, [
|
|
76
|
+
new compiler.webpack.node.NodeTemplatePlugin({
|
|
77
|
+
asyncChunkLoading: false,
|
|
78
|
+
}),
|
|
79
|
+
new compiler.webpack.node.NodeTargetPlugin(),
|
|
80
|
+
new compiler.webpack.ExternalsPlugin("commonjs", [
|
|
81
|
+
({ request }, cb) => {
|
|
82
|
+
if (request &&
|
|
83
|
+
typeof request === "string" &&
|
|
84
|
+
(request.startsWith("node:") ||
|
|
85
|
+
[
|
|
86
|
+
"http",
|
|
87
|
+
"https",
|
|
88
|
+
"http2",
|
|
89
|
+
"fs",
|
|
90
|
+
"path",
|
|
91
|
+
"crypto",
|
|
92
|
+
"stream",
|
|
93
|
+
"os",
|
|
94
|
+
"assert",
|
|
95
|
+
"util",
|
|
96
|
+
"events",
|
|
97
|
+
"url",
|
|
98
|
+
"buffer",
|
|
99
|
+
"zlib",
|
|
100
|
+
"child_process",
|
|
101
|
+
"net",
|
|
102
|
+
"tls",
|
|
103
|
+
"querystring",
|
|
104
|
+
"worker_threads",
|
|
105
|
+
].includes(request))) {
|
|
106
|
+
return cb(null, request);
|
|
107
|
+
}
|
|
108
|
+
cb();
|
|
109
|
+
},
|
|
110
|
+
]),
|
|
111
|
+
new compiler.webpack.EntryPlugin(compiler.context, serverEntryPath, { name: "main" }),
|
|
112
|
+
]);
|
|
113
|
+
childCompiler._ev_manifest_collector = collector;
|
|
114
|
+
childCompiler.runAsChild((err, _entries, childCompilation) => {
|
|
115
|
+
if (err)
|
|
116
|
+
return finishCallback(err);
|
|
117
|
+
if (childCompilation?.errors &&
|
|
118
|
+
childCompilation.errors.length > 0) {
|
|
119
|
+
return finishCallback(childCompilation.errors[0]);
|
|
120
|
+
}
|
|
121
|
+
finishCallback();
|
|
122
|
+
});
|
|
77
123
|
});
|
|
124
|
+
callback();
|
|
78
125
|
});
|
|
79
126
|
}
|
|
80
|
-
// Emit manifest
|
|
81
|
-
compiler.hooks.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
127
|
+
// Emit manifest using modern processAssets hook to avoid deprecation warnings
|
|
128
|
+
compiler.hooks.thisCompilation.tap("EvWebpackPlugin", (compilation) => {
|
|
129
|
+
compilation.hooks.processAssets.tap({
|
|
130
|
+
name: "EvWebpackPlugin",
|
|
131
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
132
|
+
}, () => {
|
|
133
|
+
const manifest = collector.getManifest();
|
|
134
|
+
if (Object.keys(manifest.serverFns).length === 0) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const content = JSON.stringify(manifest, null, 2);
|
|
138
|
+
// We place the manifest in the server folder (relative to parent output dist/client)
|
|
139
|
+
compilation.emitAsset("../server/manifest.json", new compiler.webpack.sources.RawSource(content));
|
|
140
|
+
});
|
|
91
141
|
});
|
|
92
142
|
}
|
|
93
143
|
}
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAIzB,MAAM,iBAAiB;IACrB,SAAS,GAAkC,EAAE,CAAC;IAE9C,WAAW,CAAC,EAAU,EAAE,IAAmB;QACzC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,WAAW;QACT,OAAO;YACL,OAAO,EAAE,CAAC;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;CACF;AAID;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAC1B,KAAK,CAAC,QAAkB;QACtB,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAE,CAAC;QAE1C,2DAA2D;QAC1D,QAAuB,CAAC,sBAAsB,GAAG,SAAS,CAAC;QAE5D,mEAAmE;QACnE,MAAM,QAAQ,GACZ,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU;YACpC,QAAQ,CAAC,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC;QAErC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,iCAAiC;YACjC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAC1B,iBAAiB,EACjB,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;gBAC9B,gFAAgF;gBAChF,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CACtC,iBAAiB,EACjB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE;oBAC1B,IAAI,SAAS,GAAG,KAAK,CAAC;oBACtB,MAAM,OAAO,GAAa,EAAE,CAAC;oBAC7B,OAAO,CAAC,IAAI,CACV,sDAAsD,CACvD,CAAC;oBAEF,IAAI,EAAE,GAAG,CAAC,CAAC;oBAC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,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
import type { Compiler } from "webpack";
|
|
1
2
|
interface LoaderContext {
|
|
2
3
|
getOptions(): {
|
|
3
4
|
isServer?: boolean;
|
|
4
5
|
};
|
|
5
6
|
resourcePath: string;
|
|
6
7
|
rootContext: string;
|
|
8
|
+
_compiler?: Compiler & {
|
|
9
|
+
_ev_manifest_collector?: {
|
|
10
|
+
addServerFn(id: string, meta: {
|
|
11
|
+
moduleId: string;
|
|
12
|
+
export: string;
|
|
13
|
+
}): void;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
7
16
|
}
|
|
8
17
|
export default function serverFnLoader(this: LoaderContext, source: string): Promise<string>;
|
|
9
18
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-fn-loader.d.ts","sourceRoot":"","sources":["../src/server-fn-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-fn-loader.d.ts","sourceRoot":"","sources":["../src/server-fn-loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,IAAI;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,QAAQ,GAAG;QACrB,sBAAsB,CAAC,EAAE;YACvB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;gBAAE,QAAQ,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,GAAG,IAAI,CAAC;SAC3E,CAAC;KACH,CAAC;CACH;AA2BD,wBAA8B,cAAc,CAC1C,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CA2FjB"}
|
package/esm/server-fn-loader.js
CHANGED
|
@@ -22,7 +22,14 @@ export default async function serverFnLoader(source) {
|
|
|
22
22
|
if (!hasUseServerDirective(source)) {
|
|
23
23
|
return source;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
// Adaptively check if we are building the server (Child Compiler) or client
|
|
26
|
+
const explicitOptions = this.getOptions() || {};
|
|
27
|
+
let isServer = explicitOptions.isServer;
|
|
28
|
+
if (typeof isServer === "undefined") {
|
|
29
|
+
const compilerName = this._compiler?.name;
|
|
30
|
+
const target = this._compiler?.options?.target;
|
|
31
|
+
isServer = compilerName === "evServer" || target === "node";
|
|
32
|
+
}
|
|
26
33
|
// Parse the source into an AST
|
|
27
34
|
const program = await parse(source, {
|
|
28
35
|
syntax: "typescript",
|
|
@@ -89,7 +96,7 @@ export default async function serverFnLoader(source) {
|
|
|
89
96
|
const stubCode = exportNames
|
|
90
97
|
.map((name) => {
|
|
91
98
|
const fnId = makeFnId(this.rootContext, this.resourcePath, name);
|
|
92
|
-
return `export function ${name}(...args) {\n return __ev_rpc("${fnId}", args);\n}
|
|
99
|
+
return `export function ${name}(...args) {\n return __ev_rpc("${fnId}", args);\n}\n${name}.evId = "${fnId}";`;
|
|
93
100
|
})
|
|
94
101
|
.join("\n\n");
|
|
95
102
|
return `import { __ev_rpc } from "@evjs/runtime/client";\n\n${stubCode}\n`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-fn-loader.js","sourceRoot":"","sources":["../src/server-fn-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"server-fn-loader.js","sourceRoot":"","sources":["../src/server-fn-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW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AAO,mBAAmB,IAAI,mCAAmC,IAAI,iBAAiB,IAAI,YAAY,IAAI,IAAI,CAAC;IACjH,CAAC,CAAC;SACD,IAAI,CAAC,MAAM,CAAC,CAAC;IAEhB,OAAO,uDAAuD,QAAQ,IAAI,CAAC;AAC7E,CAAC"}
|
package/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.0.1-alpha.
|
|
1
|
+
export declare const VERSION = "0.0.1-alpha.6";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "0.0.1-alpha.
|
|
1
|
+
export const VERSION = "0.0.1-alpha.6";
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evjs/webpack-plugin",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.6",
|
|
4
4
|
"description": "Webpack plugin and loaders for the ev framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"author": "xusd320",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@evjs/manifest": "0.0.1-alpha.
|
|
39
|
-
"@swc/core": "^1.15.18"
|
|
38
|
+
"@evjs/manifest": "0.0.1-alpha.6",
|
|
39
|
+
"@swc/core": "^1.15.18",
|
|
40
|
+
"glob": "^13.0.6"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"typescript": "^5.7.3",
|