rwsdk 1.0.0-beta.37 → 1.0.0-beta.39
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/runtime/worker.js +6 -0
- package/dist/scripts/worker-run.mjs +8 -1
- package/dist/vite/configPlugin.mjs +1 -0
- package/dist/vite/diagnosticAssetGraphPlugin.d.mts +4 -0
- package/dist/vite/diagnosticAssetGraphPlugin.mjs +41 -0
- package/dist/vite/moveStaticAssetsPlugin.mjs +19 -1
- package/package.json +1 -1
package/dist/runtime/worker.js
CHANGED
|
@@ -26,6 +26,12 @@ export const defineApp = (routes) => {
|
|
|
26
26
|
}
|
|
27
27
|
else if (import.meta.env.VITE_IS_DEV_SERVER &&
|
|
28
28
|
new URL(request.url).pathname === "/__worker-run") {
|
|
29
|
+
const expectedToken = import.meta.env
|
|
30
|
+
.VITE_RWSDK_WORKER_RUN_TOKEN;
|
|
31
|
+
const requestToken = request.headers.get("x-rwsdk-worker-run-token");
|
|
32
|
+
if (!expectedToken || expectedToken !== requestToken) {
|
|
33
|
+
return new Response("Forbidden", { status: 403 });
|
|
34
|
+
}
|
|
29
35
|
const url = new URL(request.url);
|
|
30
36
|
const scriptPath = url.searchParams.get("script");
|
|
31
37
|
if (!scriptPath) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
1
2
|
import dbg from "debug";
|
|
2
3
|
import getPort from "get-port";
|
|
3
4
|
import path from "path";
|
|
@@ -7,6 +8,8 @@ import { createLogger } from "vite";
|
|
|
7
8
|
const debug = dbg("rwsdk:worker-run");
|
|
8
9
|
const main = async () => {
|
|
9
10
|
process.env.RWSDK_WORKER_RUN = "1";
|
|
11
|
+
const token = crypto.randomBytes(32).toString("hex");
|
|
12
|
+
process.env.VITE_RWSDK_WORKER_RUN_TOKEN = token;
|
|
10
13
|
const relativeScriptPath = process.argv[2];
|
|
11
14
|
if (!relativeScriptPath) {
|
|
12
15
|
console.error("Error: Script path is required");
|
|
@@ -46,7 +49,11 @@ const main = async () => {
|
|
|
46
49
|
const fileUrl = pathToFileURL(scriptPath).href;
|
|
47
50
|
const url = `http://localhost:${port}/__worker-run?script=${encodeURIComponent(fileUrl)}`;
|
|
48
51
|
debug("Fetching %s", url);
|
|
49
|
-
const response = await fetch(url
|
|
52
|
+
const response = await fetch(url, {
|
|
53
|
+
headers: {
|
|
54
|
+
"x-rwsdk-worker-run-token": token,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
50
57
|
debug("Response from worker: %s", response);
|
|
51
58
|
if (!response.ok) {
|
|
52
59
|
const errorText = await response.text();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const diagnosticAssetGraphPlugin = ({ rootDir, }) => ({
|
|
2
|
+
name: "rwsdk:diagnostic-asset-graph",
|
|
3
|
+
apply: "build",
|
|
4
|
+
async buildEnd() {
|
|
5
|
+
if (this.environment.name === "worker" &&
|
|
6
|
+
process.env.RWSDK_BUILD_PASS === "worker") {
|
|
7
|
+
console.log("\n=== Asset Graph Diagnostic ===");
|
|
8
|
+
const moduleIds = Array.from(this.getModuleIds());
|
|
9
|
+
console.log(`Total modules: ${moduleIds.length}`);
|
|
10
|
+
const urlImportedModules = new Set();
|
|
11
|
+
const publicAssets = new Set();
|
|
12
|
+
for (const moduleId of moduleIds) {
|
|
13
|
+
const moduleInfo = this.getModuleInfo(moduleId);
|
|
14
|
+
if (moduleInfo) {
|
|
15
|
+
const isImportedByUrl = moduleInfo.importers.some((importer) => importer.includes("?url")) || moduleId.includes("?url");
|
|
16
|
+
if (isImportedByUrl) {
|
|
17
|
+
urlImportedModules.add(moduleId);
|
|
18
|
+
console.log(`\nModule imported with ?url: ${moduleId}`);
|
|
19
|
+
console.log(` Importers: ${moduleInfo.importers.join(", ")}`);
|
|
20
|
+
if (moduleInfo.importedIds) {
|
|
21
|
+
console.log(` Imports: ${moduleInfo.importedIds.join(", ")}`);
|
|
22
|
+
for (const importedId of moduleInfo.importedIds) {
|
|
23
|
+
publicAssets.add(importedId);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (moduleInfo.importers.some((importer) => importer.includes("Document.tsx"))) {
|
|
28
|
+
console.log(`\nModule imported by Document.tsx: ${moduleId}`);
|
|
29
|
+
console.log(` Importers: ${moduleInfo.importers.join(", ")}`);
|
|
30
|
+
if (moduleInfo.importedIds) {
|
|
31
|
+
console.log(` Imports: ${moduleInfo.importedIds.join(", ")}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
console.log(`\nTotal modules imported with ?url: ${urlImportedModules.size}`);
|
|
37
|
+
console.log(`Total transitive dependencies: ${publicAssets.size}`);
|
|
38
|
+
console.log("\n=== End Asset Graph Diagnostic ===\n");
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -11,8 +11,25 @@ export const moveStaticAssetsPlugin = ({ rootDir, }) => ({
|
|
|
11
11
|
if (!(await fs.pathExists(sourceDir))) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
+
const ssrManifestPath = path.join(rootDir, "dist", "worker", ".vite", "ssr-manifest.json");
|
|
15
|
+
if (!(await fs.pathExists(ssrManifestPath))) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const manifestContent = await fs.readFile(ssrManifestPath, "utf-8");
|
|
19
|
+
const ssrManifest = JSON.parse(manifestContent);
|
|
20
|
+
const publicAssets = new Set();
|
|
21
|
+
for (const [moduleId, assetPaths] of Object.entries(ssrManifest)) {
|
|
22
|
+
if (moduleId.includes("?url")) {
|
|
23
|
+
for (const assetPath of assetPaths) {
|
|
24
|
+
const assetFileName = path.basename(assetPath);
|
|
25
|
+
publicAssets.add(assetFileName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
14
29
|
const allFiles = await fs.readdir(sourceDir);
|
|
15
|
-
const filesToMove = allFiles.filter((file) => !file.endsWith(".js") &&
|
|
30
|
+
const filesToMove = allFiles.filter((file) => !file.endsWith(".js") &&
|
|
31
|
+
!file.endsWith(".map") &&
|
|
32
|
+
publicAssets.has(file));
|
|
16
33
|
if (filesToMove.length > 0) {
|
|
17
34
|
await fs.ensureDir(destDir);
|
|
18
35
|
for (const file of filesToMove) {
|
|
@@ -21,6 +38,7 @@ export const moveStaticAssetsPlugin = ({ rootDir, }) => ({
|
|
|
21
38
|
await fs.move(sourceFile, destFile, { overwrite: true });
|
|
22
39
|
}
|
|
23
40
|
}
|
|
41
|
+
await fs.remove(ssrManifestPath);
|
|
24
42
|
}
|
|
25
43
|
},
|
|
26
44
|
});
|