rwsdk 0.1.0-alpha.3 → 0.1.0-alpha.4
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
|
+
}
|
|
@@ -73,6 +73,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
|
|
|
73
73
|
[path.basename(SSR_BRIDGE_PATH, ".js")]: enhancedResolve.sync(projectRootDir, "rwsdk/__ssr_bridge"),
|
|
74
74
|
},
|
|
75
75
|
formats: ["es"],
|
|
76
|
+
fileName: () => path.basename(SSR_BRIDGE_PATH),
|
|
76
77
|
},
|
|
77
78
|
outDir: path.dirname(SSR_BRIDGE_PATH),
|
|
78
79
|
},
|
|
@@ -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,
|