rwsdk 0.1.0-alpha.4 → 0.1.0-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/dist/lib/getSrcPaths.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
|
+
export declare const cloudflareBuiltInModules: string[];
|
|
3
|
+
export declare const externalModules: string[];
|
|
2
4
|
export declare const configPlugin: ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, }: {
|
|
3
5
|
mode: "development" | "production";
|
|
4
6
|
silent: boolean;
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import path, { resolve } from "node:path";
|
|
2
|
-
import { mergeConfig } from "vite";
|
|
3
2
|
import enhancedResolve from "enhanced-resolve";
|
|
4
3
|
import { SSR_BRIDGE_PATH } from "../lib/constants.mjs";
|
|
5
4
|
import { builtinModules } from "node:module";
|
|
5
|
+
// port(justinvdm, 09 Jun 2025):
|
|
6
|
+
// https://github.com/cloudflare/workers-sdk/blob/d533f5ee7da69c205d8d5e2a5f264d2370fc612b/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts#L123-L128
|
|
7
|
+
export const cloudflareBuiltInModules = [
|
|
8
|
+
"cloudflare:email",
|
|
9
|
+
"cloudflare:sockets",
|
|
10
|
+
"cloudflare:workers",
|
|
11
|
+
"cloudflare:workflows",
|
|
12
|
+
];
|
|
13
|
+
export const externalModules = [
|
|
14
|
+
...cloudflareBuiltInModules,
|
|
15
|
+
...builtinModules,
|
|
16
|
+
...builtinModules.map((m) => `node:${m}`),
|
|
17
|
+
];
|
|
6
18
|
export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, }) => ({
|
|
7
19
|
name: "rwsdk:config",
|
|
8
20
|
config: (_, { command }) => {
|
|
@@ -58,7 +70,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
58
70
|
optimizeDeps: {
|
|
59
71
|
noDiscovery: false,
|
|
60
72
|
entries: [workerEntryPathname],
|
|
61
|
-
exclude:
|
|
73
|
+
exclude: externalModules,
|
|
62
74
|
include: ["rwsdk/__ssr_bridge"],
|
|
63
75
|
esbuildOptions: {
|
|
64
76
|
jsx: "automatic",
|
|
@@ -130,19 +142,6 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
130
142
|
},
|
|
131
143
|
},
|
|
132
144
|
};
|
|
133
|
-
if (command === "build") {
|
|
134
|
-
return mergeConfig(baseConfig, {
|
|
135
|
-
environments: {
|
|
136
|
-
worker: {
|
|
137
|
-
build: {
|
|
138
|
-
rollupOptions: {
|
|
139
|
-
external: ["cloudflare:workers", "node:stream"],
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
145
|
return baseConfig;
|
|
147
146
|
},
|
|
148
147
|
});
|
|
@@ -6,6 +6,7 @@ import debug from "debug";
|
|
|
6
6
|
import { normalizeModulePath } from "./normalizeModulePath.mjs";
|
|
7
7
|
import { ensureAliasArray } from "./ensureAliasArray.mjs";
|
|
8
8
|
import { pathExists } from "fs-extra";
|
|
9
|
+
import { stat } from "fs/promises";
|
|
9
10
|
import { getSrcPaths } from "../lib/getSrcPaths.js";
|
|
10
11
|
export const findFilesContainingDirective = async ({ projectRootDir, files, directive, debugNamespace, }) => {
|
|
11
12
|
const log = debug(debugNamespace);
|
|
@@ -15,11 +16,17 @@ export const findFilesContainingDirective = async ({ projectRootDir, files, dire
|
|
|
15
16
|
const filesInsideNodeModules = await glob("**/node_modules/**/*.{js,mjs,cjs}", {
|
|
16
17
|
cwd: projectRootDir,
|
|
17
18
|
absolute: true,
|
|
19
|
+
nodir: true,
|
|
18
20
|
});
|
|
19
21
|
const allFiles = [...filesOutsideNodeModules, ...filesInsideNodeModules];
|
|
20
22
|
log("Found %d files to scan for '%s' directive", allFiles.length, directive);
|
|
21
23
|
for (const file of allFiles) {
|
|
22
24
|
try {
|
|
25
|
+
const stats = await stat(file);
|
|
26
|
+
if (!stats.isFile()) {
|
|
27
|
+
verboseLog("Skipping %s (not a file)", file);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
23
30
|
verboseLog("Scanning file: %s", file);
|
|
24
31
|
const content = await readFile(file, "utf-8");
|
|
25
32
|
const lines = content.split("\n");
|