rwsdk 0.1.0-alpha.7 → 0.1.0-alpha.8
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.
|
@@ -1,9 +1,31 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
1
3
|
import debug from "debug";
|
|
2
4
|
import { transformClientComponents } from "./transformClientComponents.mjs";
|
|
3
5
|
import { transformServerFunctions } from "./transformServerFunctions.mjs";
|
|
4
6
|
import { normalizeModulePath } from "./normalizeModulePath.mjs";
|
|
5
7
|
const log = debug("rwsdk:vite:rsc-directives-plugin");
|
|
6
8
|
const verboseLog = debug("verbose:rwsdk:vite:rsc-directives-plugin");
|
|
9
|
+
const getLoader = (filePath) => {
|
|
10
|
+
const ext = path.extname(filePath).slice(1);
|
|
11
|
+
switch (ext) {
|
|
12
|
+
case "mjs":
|
|
13
|
+
case "cjs":
|
|
14
|
+
return "js";
|
|
15
|
+
case "mts":
|
|
16
|
+
case "cts":
|
|
17
|
+
return "ts";
|
|
18
|
+
case "jsx":
|
|
19
|
+
return "jsx";
|
|
20
|
+
case "tsx":
|
|
21
|
+
return "tsx";
|
|
22
|
+
case "ts":
|
|
23
|
+
return "ts";
|
|
24
|
+
case "js":
|
|
25
|
+
default:
|
|
26
|
+
return "js";
|
|
27
|
+
}
|
|
28
|
+
};
|
|
7
29
|
export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, }) => ({
|
|
8
30
|
name: "rwsdk:rsc-directives",
|
|
9
31
|
async transform(code, id) {
|
|
@@ -39,10 +61,8 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
39
61
|
name: "rsc-directives-esbuild-transform",
|
|
40
62
|
setup(build) {
|
|
41
63
|
log("Setting up esbuild plugin for environment: %s", env);
|
|
42
|
-
build.onLoad({ filter:
|
|
64
|
+
build.onLoad({ filter: /\.(js|ts|jsx|tsx|mts|mjs|cjs)$/ }, async (args) => {
|
|
43
65
|
verboseLog("Esbuild onLoad called for path=%s", args.path);
|
|
44
|
-
const fs = await import("node:fs/promises");
|
|
45
|
-
const path = await import("node:path");
|
|
46
66
|
let code;
|
|
47
67
|
try {
|
|
48
68
|
code = await fs.readFile(args.path, "utf-8");
|
|
@@ -60,7 +80,7 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
60
80
|
log("Esbuild client component transformation successful for path=%s", args.path);
|
|
61
81
|
return {
|
|
62
82
|
contents: clientResult.code,
|
|
63
|
-
loader:
|
|
83
|
+
loader: getLoader(args.path),
|
|
64
84
|
};
|
|
65
85
|
}
|
|
66
86
|
const serverResult = transformServerFunctions(code, normalizeModulePath(projectRootDir, args.path), env, serverFiles);
|
|
@@ -68,7 +88,7 @@ export const directivesPlugin = ({ projectRootDir, clientFiles, serverFiles, })
|
|
|
68
88
|
log("Esbuild server function transformation successful for path=%s", args.path);
|
|
69
89
|
return {
|
|
70
90
|
contents: serverResult.code,
|
|
71
|
-
loader:
|
|
91
|
+
loader: getLoader(args.path),
|
|
72
92
|
};
|
|
73
93
|
}
|
|
74
94
|
verboseLog("Esbuild no transformation applied for path=%s", args.path);
|