@rnx-kit/cli 0.9.51 → 0.9.55
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/CHANGELOG.md +56 -3
- package/coverage/clover.xml +110 -71
- package/coverage/coverage-final.json +3 -2
- package/coverage/lcov-report/index.html +43 -28
- package/coverage/lcov-report/src/bundle/index.html +15 -15
- package/coverage/lcov-report/src/bundle/kit-config.ts.html +1 -1
- package/coverage/lcov-report/src/bundle/metro.ts.html +15 -78
- package/coverage/lcov-report/src/bundle/overrides.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +21 -21
- package/coverage/lcov-report/src/metro-config.ts.html +105 -129
- package/coverage/lcov-report/src/typescript/index.html +111 -0
- package/coverage/lcov-report/src/typescript/project-cache.ts.html +539 -0
- package/coverage/lcov.info +198 -126
- package/lib/bundle/metro.d.ts +1 -2
- package/lib/bundle/metro.d.ts.map +1 -1
- package/lib/bundle/metro.js +5 -17
- package/lib/bundle/metro.js.map +1 -1
- package/lib/bundle.d.ts.map +1 -1
- package/lib/bundle.js +1 -3
- package/lib/bundle.js.map +1 -1
- package/lib/metro-config.d.ts +3 -3
- package/lib/metro-config.d.ts.map +1 -1
- package/lib/metro-config.js +56 -67
- package/lib/metro-config.js.map +1 -1
- package/lib/start.d.ts.map +1 -1
- package/lib/start.js +6 -17
- package/lib/start.js.map +1 -1
- package/lib/types.d.ts +3 -4
- package/lib/types.d.ts.map +1 -1
- package/lib/typescript/project-cache.d.ts +38 -0
- package/lib/typescript/project-cache.d.ts.map +1 -0
- package/lib/typescript/project-cache.js +101 -0
- package/lib/typescript/project-cache.js.map +1 -0
- package/package.json +15 -15
- package/src/bundle/metro.ts +6 -27
- package/src/bundle.ts +1 -4
- package/src/metro-config.ts +73 -81
- package/src/start.ts +7 -26
- package/src/types.ts +3 -5
- package/src/typescript/project-cache.ts +153 -0
- package/CHANGELOG.json +0 -3074
- package/just.config.js +0 -2
package/src/types.ts
CHANGED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { findPackageDir } from "@rnx-kit/tools-node";
|
|
2
|
+
import {
|
|
3
|
+
AllPlatforms,
|
|
4
|
+
platformExtensions,
|
|
5
|
+
} from "@rnx-kit/tools-react-native/platform";
|
|
6
|
+
import { changeHostToUseReactNativeResolver } from "@rnx-kit/typescript-react-native-resolver";
|
|
7
|
+
import {
|
|
8
|
+
createDiagnosticWriter,
|
|
9
|
+
Project,
|
|
10
|
+
readConfigFile,
|
|
11
|
+
} from "@rnx-kit/typescript-service";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Collection of TypeScript projects, separated by their target platform.
|
|
17
|
+
*
|
|
18
|
+
* Target platform is a react-native concept, not a TypeScript concept.
|
|
19
|
+
* However, each project is configured with react-native module resolution,
|
|
20
|
+
* which means the module file graph could vary by platform. And that means
|
|
21
|
+
* each platform could yield different type errors.
|
|
22
|
+
*
|
|
23
|
+
* For example, `import { f } from "./utils"` could load `./utils.android.ts`
|
|
24
|
+
* for Android and `./utils.ios.ts` iOS.
|
|
25
|
+
*/
|
|
26
|
+
export interface ProjectCache {
|
|
27
|
+
/**
|
|
28
|
+
* Discard all cached projects targeting a specific platform.
|
|
29
|
+
*
|
|
30
|
+
* @param platform Target platform
|
|
31
|
+
*/
|
|
32
|
+
clearPlatform(platform: AllPlatforms): void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the project which targets a specific platform and contains a specific
|
|
36
|
+
* source file. If the project is not cached, load it and add it to the cache.
|
|
37
|
+
*
|
|
38
|
+
* @param platform Target platform
|
|
39
|
+
* @param sourceFile Source file
|
|
40
|
+
* @returns Project targeting the given platform and containing the given source file
|
|
41
|
+
*/
|
|
42
|
+
getProject(sourceFile: string, platform: AllPlatforms): Project;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Create an empty cache for holding TypeScript projects.
|
|
47
|
+
*
|
|
48
|
+
* @param print Optional method for printing messages. When not set, messages are printed to the console.
|
|
49
|
+
* @returns Empty project cache
|
|
50
|
+
*/
|
|
51
|
+
export function createProjectCache(
|
|
52
|
+
print?: (message: string) => void
|
|
53
|
+
): ProjectCache {
|
|
54
|
+
const documentRegistry = ts.createDocumentRegistry();
|
|
55
|
+
const diagnosticWriter = createDiagnosticWriter(print);
|
|
56
|
+
|
|
57
|
+
// Collection of projects organized by root directory, then by platform.
|
|
58
|
+
const projects: Record<string, Partial<Record<AllPlatforms, Project>>> = {};
|
|
59
|
+
|
|
60
|
+
function findProjectRoot(sourceFile: string): string {
|
|
61
|
+
// Search known root directories to see if the source file is in one of them.
|
|
62
|
+
for (const root of Object.keys(projects)) {
|
|
63
|
+
if (sourceFile.startsWith(root)) {
|
|
64
|
+
return root;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Search the file system for the root of source file's package.
|
|
69
|
+
const root = findPackageDir(path.dirname(sourceFile));
|
|
70
|
+
if (!root) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Cannot find project root for source file '${sourceFile}'`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return root;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function readTSConfig(root: string): ts.ParsedCommandLine {
|
|
80
|
+
const configFileName = path.join(root, "tsconfig.json");
|
|
81
|
+
|
|
82
|
+
const cmdLine = readConfigFile(configFileName);
|
|
83
|
+
if (!cmdLine) {
|
|
84
|
+
throw new Error(`Failed to load '${configFileName}'`);
|
|
85
|
+
} else if (cmdLine.errors.length > 0) {
|
|
86
|
+
const writer = createDiagnosticWriter();
|
|
87
|
+
cmdLine.errors.forEach((e) => writer.print(e));
|
|
88
|
+
throw new Error(`Failed to load '${configFileName}'`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return cmdLine;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function createProject(root: string, platform: AllPlatforms): Project {
|
|
95
|
+
// Load the TypeScript configuration file for this project.
|
|
96
|
+
const cmdLine = readTSConfig(root);
|
|
97
|
+
|
|
98
|
+
// Create a TypeScript project using the configuration file. Enhance the
|
|
99
|
+
// underlying TS language service with our react-native module resolver.
|
|
100
|
+
const enhanceLanguageServiceHost = (host: ts.LanguageServiceHost): void => {
|
|
101
|
+
const platformExtensionNames = platformExtensions(platform);
|
|
102
|
+
const disableReactNativePackageSubstitution = true;
|
|
103
|
+
const traceReactNativeModuleResolutionErrors = false;
|
|
104
|
+
const traceResolutionLog = undefined;
|
|
105
|
+
changeHostToUseReactNativeResolver({
|
|
106
|
+
host,
|
|
107
|
+
options: cmdLine.options,
|
|
108
|
+
platform,
|
|
109
|
+
platformExtensionNames,
|
|
110
|
+
disableReactNativePackageSubstitution,
|
|
111
|
+
traceReactNativeModuleResolutionErrors,
|
|
112
|
+
traceResolutionLog,
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const tsproject = new Project(
|
|
116
|
+
documentRegistry,
|
|
117
|
+
diagnosticWriter,
|
|
118
|
+
cmdLine,
|
|
119
|
+
enhanceLanguageServiceHost
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// Start with an empty project, ignoring the file graph from tsconfig.json.
|
|
123
|
+
tsproject.removeAllFiles();
|
|
124
|
+
|
|
125
|
+
return tsproject;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getProject(sourceFile: string, platform: AllPlatforms): Project {
|
|
129
|
+
const root = findProjectRoot(sourceFile);
|
|
130
|
+
if (!projects[root]) {
|
|
131
|
+
projects[root] = {};
|
|
132
|
+
}
|
|
133
|
+
if (!projects[root][platform]) {
|
|
134
|
+
projects[root][platform] = createProject(root, platform);
|
|
135
|
+
}
|
|
136
|
+
return projects[root][platform]!;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function clearPlatform(platform: AllPlatforms): void {
|
|
140
|
+
Object.values(projects).forEach((projectsByPlatform) => {
|
|
141
|
+
const project = projectsByPlatform[platform];
|
|
142
|
+
if (project) {
|
|
143
|
+
project.dispose();
|
|
144
|
+
delete projectsByPlatform[platform];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
clearPlatform,
|
|
151
|
+
getProject,
|
|
152
|
+
};
|
|
153
|
+
}
|