rwsdk 0.1.0-alpha.3 → 0.1.0-alpha.5
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.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets all source file paths by parsing tsconfig.json using TypeScript's compiler API.
|
|
3
|
+
* Falls back to a glob pattern if tsconfig parsing fails.
|
|
4
|
+
*
|
|
5
|
+
* @param rootDir - The root directory to search from (defaults to current working directory)
|
|
6
|
+
* @returns Promise<string[]> - Array of source file paths
|
|
7
|
+
*/
|
|
8
|
+
export declare function getSrcPaths(rootDir?: string): Promise<string[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Synchronous version of getSrcPaths
|
|
11
|
+
*
|
|
12
|
+
* @param rootDir - The root directory to search from (defaults to current working directory)
|
|
13
|
+
* @returns string[] - Array of source file paths
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSrcPathsSync(rootDir?: string): string[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { glob } from "glob";
|
|
4
|
+
/**
|
|
5
|
+
* Gets all source file paths by parsing tsconfig.json using TypeScript's compiler API.
|
|
6
|
+
* Falls back to a glob pattern if tsconfig parsing fails.
|
|
7
|
+
*
|
|
8
|
+
* @param rootDir - The root directory to search from (defaults to current working directory)
|
|
9
|
+
* @returns Promise<string[]> - Array of source file paths
|
|
10
|
+
*/
|
|
11
|
+
export async function getSrcPaths(rootDir = process.cwd()) {
|
|
12
|
+
try {
|
|
13
|
+
const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, "tsconfig.json");
|
|
14
|
+
if (configPath) {
|
|
15
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
16
|
+
if (!configFile.error) {
|
|
17
|
+
// Parse tsconfig
|
|
18
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
19
|
+
if (parsed.fileNames && parsed.fileNames.length > 0) {
|
|
20
|
+
return parsed.fileNames;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.warn("Failed to parse tsconfig.json, falling back to glob pattern:", error);
|
|
27
|
+
}
|
|
28
|
+
// Fallback to glob pattern
|
|
29
|
+
try {
|
|
30
|
+
const globPattern = path.join(rootDir, "src/**/*.{ts,mts,tsx,jsx,mjs,js}");
|
|
31
|
+
const files = await glob(globPattern, {
|
|
32
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/*.d.ts"],
|
|
33
|
+
absolute: true,
|
|
34
|
+
});
|
|
35
|
+
return files;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("Failed to get source paths with glob pattern:", error);
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Synchronous version of getSrcPaths
|
|
44
|
+
*
|
|
45
|
+
* @param rootDir - The root directory to search from (defaults to current working directory)
|
|
46
|
+
* @returns string[] - Array of source file paths
|
|
47
|
+
*/
|
|
48
|
+
export function getSrcPathsSync(rootDir = process.cwd()) {
|
|
49
|
+
try {
|
|
50
|
+
// Try TypeScript compiler API approach first
|
|
51
|
+
const configPath = ts.findConfigFile(rootDir, ts.sys.fileExists, "tsconfig.json");
|
|
52
|
+
if (configPath) {
|
|
53
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
54
|
+
if (!configFile.error) {
|
|
55
|
+
// Parse tsconfig
|
|
56
|
+
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
57
|
+
if (parsed.fileNames && parsed.fileNames.length > 0) {
|
|
58
|
+
return parsed.fileNames;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.warn("Failed to parse tsconfig.json, falling back to glob pattern:", error);
|
|
65
|
+
}
|
|
66
|
+
// Fallback to glob pattern
|
|
67
|
+
try {
|
|
68
|
+
const globPattern = path.join(rootDir, "src/**/*.{ts,mts,tsx,jsx,mjs,js}");
|
|
69
|
+
const files = glob.sync(globPattern, {
|
|
70
|
+
ignore: ["**/node_modules/**", "**/dist/**", "**/*.d.ts"],
|
|
71
|
+
absolute: true,
|
|
72
|
+
});
|
|
73
|
+
return files;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error("Failed to get source paths with glob pattern:", error);
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -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",
|
|
@@ -73,6 +85,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
73
85
|
[path.basename(SSR_BRIDGE_PATH, ".js")]: enhancedResolve.sync(projectRootDir, "rwsdk/__ssr_bridge"),
|
|
74
86
|
},
|
|
75
87
|
formats: ["es"],
|
|
88
|
+
fileName: () => path.basename(SSR_BRIDGE_PATH),
|
|
76
89
|
},
|
|
77
90
|
outDir: path.dirname(SSR_BRIDGE_PATH),
|
|
78
91
|
},
|
|
@@ -129,19 +142,6 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
129
142
|
},
|
|
130
143
|
},
|
|
131
144
|
};
|
|
132
|
-
if (command === "build") {
|
|
133
|
-
return mergeConfig(baseConfig, {
|
|
134
|
-
environments: {
|
|
135
|
-
worker: {
|
|
136
|
-
build: {
|
|
137
|
-
rollupOptions: {
|
|
138
|
-
external: ["cloudflare:workers", "node:stream"],
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
145
|
return baseConfig;
|
|
146
146
|
},
|
|
147
147
|
});
|
|
@@ -6,15 +6,12 @@ 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 { getSrcPaths } from "../lib/getSrcPaths.js";
|
|
9
10
|
export const findFilesContainingDirective = async ({ projectRootDir, files, directive, debugNamespace, }) => {
|
|
10
11
|
const log = debug(debugNamespace);
|
|
11
12
|
const verboseLog = debug(`verbose:${debugNamespace}`);
|
|
12
13
|
log("Starting search for '%s' files in projectRootDir=%s", directive, projectRootDir);
|
|
13
|
-
const filesOutsideNodeModules = await
|
|
14
|
-
cwd: projectRootDir,
|
|
15
|
-
absolute: true,
|
|
16
|
-
ignore: ["**/node_modules/**"],
|
|
17
|
-
});
|
|
14
|
+
const filesOutsideNodeModules = await getSrcPaths(projectRootDir);
|
|
18
15
|
const filesInsideNodeModules = await glob("**/node_modules/**/*.{js,mjs,cjs}", {
|
|
19
16
|
cwd: projectRootDir,
|
|
20
17
|
absolute: true,
|