rwsdk 1.0.0-beta.16 → 1.0.0-beta.18
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,8 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
export declare function linkWorkerBundle({ code, manifestContent, projectRootDir, }: {
|
|
2
|
+
export declare function linkWorkerBundle({ code, manifestContent, projectRootDir, base, }: {
|
|
3
3
|
code: string;
|
|
4
4
|
manifestContent: string;
|
|
5
5
|
projectRootDir: string;
|
|
6
|
+
base?: string;
|
|
6
7
|
}): {
|
|
7
8
|
code: string;
|
|
8
9
|
map: null;
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { CLIENT_MANIFEST_RELATIVE_PATH } from "../lib/constants.mjs";
|
|
5
5
|
import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
|
|
6
6
|
const log = debug("rwsdk:vite:linker-plugin");
|
|
7
|
-
export function linkWorkerBundle({ code, manifestContent, projectRootDir, }) {
|
|
7
|
+
export function linkWorkerBundle({ code, manifestContent, projectRootDir, base, }) {
|
|
8
8
|
let newCode = code;
|
|
9
9
|
const manifest = JSON.parse(manifestContent);
|
|
10
10
|
// 1. Replace the manifest placeholder with the actual manifest content.
|
|
@@ -16,7 +16,10 @@ export function linkWorkerBundle({ code, manifestContent, projectRootDir, }) {
|
|
|
16
16
|
const normalizedKey = normalizeModulePath(key, projectRootDir, {
|
|
17
17
|
isViteStyle: false,
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
// If base is provided, prepend it with the final hashed path.
|
|
20
|
+
// Base is assumed to have a trailing "/".
|
|
21
|
+
const assetPath = (base ? base : "/") + value.file;
|
|
22
|
+
newCode = newCode.replaceAll(`rwsdk_asset:${normalizedKey}`, assetPath);
|
|
20
23
|
}
|
|
21
24
|
// 3. Deprefix any remaining placeholders that were not in the manifest.
|
|
22
25
|
// This handles public assets that don't go through the bundler.
|
|
@@ -28,8 +31,12 @@ export function linkWorkerBundle({ code, manifestContent, projectRootDir, }) {
|
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
export const linkerPlugin = ({ projectRootDir, }) => {
|
|
34
|
+
let config;
|
|
31
35
|
return {
|
|
32
36
|
name: "rwsdk:linker",
|
|
37
|
+
configResolved(resolvedConfig) {
|
|
38
|
+
config = resolvedConfig;
|
|
39
|
+
},
|
|
33
40
|
async renderChunk(code) {
|
|
34
41
|
if (this.environment.name !== "worker" ||
|
|
35
42
|
process.env.RWSDK_BUILD_PASS !== "linker") {
|
|
@@ -41,6 +48,7 @@ export const linkerPlugin = ({ projectRootDir, }) => {
|
|
|
41
48
|
code,
|
|
42
49
|
manifestContent,
|
|
43
50
|
projectRootDir,
|
|
51
|
+
base: config.base,
|
|
44
52
|
});
|
|
45
53
|
log("Final worker chunk rendered");
|
|
46
54
|
return result;
|
|
@@ -29,6 +29,21 @@ describe("linkWorkerBundle", () => {
|
|
|
29
29
|
expect(result.code).toContain(`const stylesheet = "/assets/styles.123.css";`);
|
|
30
30
|
expect(result.code).toContain(`const logo = "/assets/logo.abc.svg";`);
|
|
31
31
|
});
|
|
32
|
+
it("should replace asset placeholder with a base + hashed paths from the manifest if base is provided", () => {
|
|
33
|
+
const code = `
|
|
34
|
+
const stylesheet = "rwsdk_asset:/src/styles.css";
|
|
35
|
+
const logo = "rwsdk_asset:/src/logo.svg";
|
|
36
|
+
`;
|
|
37
|
+
const base = "/base/";
|
|
38
|
+
const result = linkWorkerBundle({
|
|
39
|
+
code,
|
|
40
|
+
manifestContent,
|
|
41
|
+
projectRootDir,
|
|
42
|
+
base,
|
|
43
|
+
});
|
|
44
|
+
expect(result.code).toContain(`const stylesheet = "/base/assets/styles.123.css";`);
|
|
45
|
+
expect(result.code).toContain(`const logo = "/base/assets/logo.abc.svg";`);
|
|
46
|
+
});
|
|
32
47
|
it("should deprefix remaining asset placeholders not in the manifest", () => {
|
|
33
48
|
const code = `const publicImg = "rwsdk_asset:/images/photo.jpg";`;
|
|
34
49
|
const result = linkWorkerBundle({
|