@rnx-kit/cli 0.9.54 → 0.9.58
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 +24 -3
- package/coverage/clover.xml +116 -73
- 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 +112 -121
- package/coverage/lcov-report/src/typescript/index.html +111 -0
- package/coverage/lcov-report/src/typescript/project-cache.ts.html +626 -0
- package/coverage/lcov.info +208 -128
- 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 +58 -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 +42 -0
- package/lib/typescript/project-cache.d.ts.map +1 -0
- package/lib/typescript/project-cache.js +114 -0
- package/lib/typescript/project-cache.js.map +1 -0
- package/package.json +2 -2
- package/src/bundle/metro.ts +6 -27
- package/src/bundle.ts +1 -4
- package/src/metro-config.ts +78 -81
- package/src/start.ts +7 -26
- package/src/types.ts +3 -5
- package/src/typescript/project-cache.ts +182 -0
- package/CHANGELOG.json +0 -3289
package/lib/metro-config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metro-config.js","sourceRoot":"","sources":["../src/metro-config.ts"],"names":[],"mappings":";;;AAAA,kHAG4D;AAC5D,8FAGkD;AAClD,gEAAyE;AACzE,gFAG2C;
|
|
1
|
+
{"version":3,"file":"metro-config.js","sourceRoot":"","sources":["../src/metro-config.ts"],"names":[],"mappings":";;;AAAA,kHAG4D;AAC5D,8FAGkD;AAClD,gEAAyE;AACzE,gFAG2C;AAI3C,8DAAgE;AAMhE;;;;;;;;;GASG;AACH,SAAS,oBAAoB,CAAC,OAAoC;IAChE,MAAM,YAAY,GAAG,IAAA,kCAAkB,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEvD,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;IACpD,MAAM,kBAAkB,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEtE,MAAM,IAAI,GAAG,CAAC,KAAY,EAAE,KAAkB,EAAQ,EAAE;QACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,gBAAgB,CAAC,QAAwB,CAAC;QACjE,IAAI,QAAQ,EAAE;YACZ,IAAI,KAAK,CAAC,KAAK,EAAE;gBACf,oEAAoE;gBACpE,oEAAoE;gBACpE,gCAAgC;gBAChC,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;aACtC;YAED,uEAAuE;YACvE,8DAA8D;YAC9D,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CACrB,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EACpB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CACxB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;YAE7B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CACxB,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,EACvB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CACxB,CAAC,MAAM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CAAC,gBAAgB,GAAG,IAAA,kCAAe,EACvD,OAAO,CACiC,CAAC;KAC5C;SAAM;QACL,OAAO,WAAW,CAAC,UAAU,CAAC,gBAAgB,CAAC;KAChD;IAED,IAAI,IAAI,GAAG,mBAAmB,CAAC;IAC/B,IAAI,OAAO,oBAAoB,KAAK,QAAQ,EAAE;QAC5C,IAAI,GAAG,oBAAoB,CAAC,oBAAoB,CAAC,CAAC;KACnD;SAAM,IAAI,oBAAoB,KAAK,KAAK,EAAE;QACzC,IAAI,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAAC;KACjC;IACD,WAAW,CAAC,UAAU,CAAC,0BAA0B,GAAG,IAAI,CAAC;AAC3D,CAAC;AAnDD,oDAmDC"}
|
package/lib/start.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAgB7E,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAYF,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,EACpB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,eAAe,GAC1B,OAAO,CAAC,IAAI,CAAC,CAoKf"}
|
package/lib/start.js
CHANGED
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.rnxStart = void 0;
|
|
16
16
|
const metro_service_1 = require("@rnx-kit/metro-service");
|
|
17
|
-
const typescript_service_1 = require("@rnx-kit/typescript-service");
|
|
18
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
19
18
|
const path_1 = __importDefault(require("path"));
|
|
20
19
|
const readline_1 = __importDefault(require("readline"));
|
|
@@ -76,23 +75,13 @@ function rnxStart(_argv, cliConfig, cliOptions) {
|
|
|
76
75
|
assetPlugins: serverConfig.assetPlugins.map((p) => require.resolve(p)),
|
|
77
76
|
}
|
|
78
77
|
: undefined)));
|
|
79
|
-
// prepare for typescript validation, if requested
|
|
80
|
-
let tsprojectInfo;
|
|
81
|
-
if (serverConfig.typescriptValidation) {
|
|
82
|
-
const tsservice = new typescript_service_1.Service((message) => terminal.log(message));
|
|
83
|
-
const configFileName = (0, typescript_service_1.findConfigFile)(metroConfig.projectRoot, "tsconfig.json");
|
|
84
|
-
if (!configFileName) {
|
|
85
|
-
terminal.log(chalk_1.default.yellow(`Warning: cannot find tsconfig.json under project root '${metroConfig.projectRoot}' -- skipping TypeScript validation`));
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
tsprojectInfo = {
|
|
89
|
-
service: tsservice,
|
|
90
|
-
configFileName,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
78
|
// customize the metro config to include plugins, presets, etc.
|
|
95
|
-
|
|
79
|
+
const typescriptValidationOptions = {
|
|
80
|
+
print: (message) => {
|
|
81
|
+
terminal.log(message);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
(0, metro_config_1.customizeMetroConfig)(metroConfig, serverConfig.detectCyclicDependencies, serverConfig.detectDuplicateDependencies, serverConfig.typescriptValidation ? typescriptValidationOptions : false, serverConfig.experimental_treeShake);
|
|
96
85
|
// create middleware -- a collection of plugins which handle incoming
|
|
97
86
|
// http(s) requests, routing them to static pages or JS functions.
|
|
98
87
|
const { middleware, attachToServer } = createDevServerMiddleware({
|
package/lib/start.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,0DAIgC;AAChC,
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,0DAIgC;AAChC,kDAA0B;AAI1B,gDAAwB;AACxB,wDAAgC;AAChC,mDAAwD;AACxD,iDAAsD;AAoBtD,SAAS,eAAe,CAAI,MAAc;IACxC,IAAI;QACF,OAAO,OAAO,CAAC,MAAM,CAAM,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,IAAI,KAAK,CACb,uBAAuB,MAAM,iTAAiT,CAC/U,CAAC;KACH;AACH,CAAC;AAED,SAAsB,QAAQ,CAC5B,KAAoB,EACpB,SAAoB,EACpB,UAA2B;;QAE3B,MAAM,YAAY,GAAG,IAAA,+BAAkB,EAAC,UAAU,CAAC,CAAC;QACpD,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;SAC1B;QAED,MAAM,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,GAAG,eAAe,CAExE,wCAAwC,CAAC,CAAC;QAE5C,gDAAgD;QAChD,IAAI,WAAW,GAAG,UAAU,CAAC,WAA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AAC;4BACxC,OAAO,CAAC,IAAI,EAAE,CAAC;4BACf,MAAM;wBACR,KAAK,GAAG;4BACN,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;4BACnC,MAAM;qBACT;iBACF;qBAAM,IAAI,IAAI,KAAK,GAAG,EAAE;oBACvB,QAAQ,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC;oBAC9C,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;iBAC9C;qBAAM,IAAI,IAAI,KAAK,GAAG,EAAE;oBACvB,QAAQ,CAAC,GAAG,CAAC,eAAK,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC;oBACvD,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;iBAC/C;qBAAM;oBACL,QAAQ,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;iBAChC;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CAAA;AAxKD,4BAwKC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
configFileName: string;
|
|
1
|
+
export declare type TypeScriptValidationOptions = {
|
|
2
|
+
print?: (message: string) => void;
|
|
3
|
+
throwOnError?: boolean;
|
|
5
4
|
};
|
|
6
5
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,2BAA2B,GAAG;IACxC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
2
|
+
import { Project } from "@rnx-kit/typescript-service";
|
|
3
|
+
export declare type ProjectInfo = {
|
|
4
|
+
tsproject: Project;
|
|
5
|
+
tssourceFiles: Set<string>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Collection of TypeScript projects, separated by their target platform.
|
|
9
|
+
*
|
|
10
|
+
* Target platform is a react-native concept, not a TypeScript concept.
|
|
11
|
+
* However, each project is configured with react-native module resolution,
|
|
12
|
+
* which means the module file graph could vary by platform. And that means
|
|
13
|
+
* each platform could yield different type errors.
|
|
14
|
+
*
|
|
15
|
+
* For example, `import { f } from "./utils"` could load `./utils.android.ts`
|
|
16
|
+
* for Android and `./utils.ios.ts` iOS.
|
|
17
|
+
*/
|
|
18
|
+
export interface ProjectCache {
|
|
19
|
+
/**
|
|
20
|
+
* Discard all cached projects targeting a specific platform.
|
|
21
|
+
*
|
|
22
|
+
* @param platform Target platform
|
|
23
|
+
*/
|
|
24
|
+
clearPlatform(platform: AllPlatforms): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get info on the project which targets a specific platform and contains a specific
|
|
27
|
+
* source file. If the project is not cached, load it and add it to the cache.
|
|
28
|
+
*
|
|
29
|
+
* @param platform Target platform
|
|
30
|
+
* @param sourceFile Source file
|
|
31
|
+
* @returns Project targeting the given platform and containing the given source file
|
|
32
|
+
*/
|
|
33
|
+
getProjectInfo(sourceFile: string, platform: AllPlatforms): ProjectInfo;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create an empty cache for holding TypeScript projects.
|
|
37
|
+
*
|
|
38
|
+
* @param print Optional method for printing messages. When not set, messages are printed to the console.
|
|
39
|
+
* @returns Empty project cache
|
|
40
|
+
*/
|
|
41
|
+
export declare function createProjectCache(print?: (message: string) => void): ProjectCache;
|
|
42
|
+
//# sourceMappingURL=project-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-cache.d.ts","sourceRoot":"","sources":["../../src/typescript/project-cache.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EAEb,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAEL,OAAO,EAER,MAAM,6BAA6B,CAAC;AAIrC,oBAAY,WAAW,GAAG;IACxB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,aAAa,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAE5C;;;;;;;OAOG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,WAAW,CAAC;CACzE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAChC,YAAY,CA4Hd"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createProjectCache = void 0;
|
|
7
|
+
const tools_node_1 = require("@rnx-kit/tools-node");
|
|
8
|
+
const platform_1 = require("@rnx-kit/tools-react-native/platform");
|
|
9
|
+
const typescript_react_native_resolver_1 = require("@rnx-kit/typescript-react-native-resolver");
|
|
10
|
+
const typescript_service_1 = require("@rnx-kit/typescript-service");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
13
|
+
/**
|
|
14
|
+
* Create an empty cache for holding TypeScript projects.
|
|
15
|
+
*
|
|
16
|
+
* @param print Optional method for printing messages. When not set, messages are printed to the console.
|
|
17
|
+
* @returns Empty project cache
|
|
18
|
+
*/
|
|
19
|
+
function createProjectCache(print) {
|
|
20
|
+
const documentRegistry = typescript_1.default.createDocumentRegistry();
|
|
21
|
+
const diagnosticWriter = (0, typescript_service_1.createDiagnosticWriter)(print);
|
|
22
|
+
// Collection of projects organized by root directory, then by platform.
|
|
23
|
+
const projects = {};
|
|
24
|
+
function findProjectRoot(sourceFile) {
|
|
25
|
+
// Search known root directories to see if the source file is in one of them.
|
|
26
|
+
for (const root of Object.keys(projects)) {
|
|
27
|
+
if (sourceFile.startsWith(root)) {
|
|
28
|
+
return root;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// Search the file system for the root of source file's package.
|
|
32
|
+
const root = (0, tools_node_1.findPackageDir)(path_1.default.dirname(sourceFile));
|
|
33
|
+
if (!root) {
|
|
34
|
+
throw new Error(`Cannot find project root for source file '${sourceFile}'`);
|
|
35
|
+
}
|
|
36
|
+
return root;
|
|
37
|
+
}
|
|
38
|
+
function readTSConfig(root) {
|
|
39
|
+
const configFileName = path_1.default.join(root, "tsconfig.json");
|
|
40
|
+
const cmdLine = (0, typescript_service_1.readConfigFile)(configFileName);
|
|
41
|
+
if (!cmdLine) {
|
|
42
|
+
throw new Error(`Failed to load '${configFileName}'`);
|
|
43
|
+
}
|
|
44
|
+
else if (cmdLine.errors.length > 0) {
|
|
45
|
+
const writer = (0, typescript_service_1.createDiagnosticWriter)();
|
|
46
|
+
cmdLine.errors.forEach((e) => writer.print(e));
|
|
47
|
+
throw new Error(`Failed to load '${configFileName}'`);
|
|
48
|
+
}
|
|
49
|
+
return cmdLine;
|
|
50
|
+
}
|
|
51
|
+
function createProjectInfo(root, platform) {
|
|
52
|
+
// Load the TypeScript configuration file for this project.
|
|
53
|
+
const cmdLine = readTSConfig(root);
|
|
54
|
+
// Trim down the list of source files found by TypeScript. This ensures
|
|
55
|
+
// that only explicitly added files are loaded and parsed by TypeScript.
|
|
56
|
+
// This is a perf optimization. We don't want to spend cycles on files
|
|
57
|
+
// that won't be used, such as *.android.ts when bundling for ios.
|
|
58
|
+
//
|
|
59
|
+
// The exception to this rule are .d.ts files. They hold global types,
|
|
60
|
+
// modules and namespaces, and having them in the project is the only
|
|
61
|
+
// way they can be loaded.
|
|
62
|
+
const tssourceFiles = new Set(cmdLine.fileNames);
|
|
63
|
+
cmdLine.fileNames = cmdLine.fileNames.filter((f) => f.endsWith(".d.ts"));
|
|
64
|
+
// Create a TypeScript project using the configuration file. Enhance the
|
|
65
|
+
// underlying TS language service with our react-native module resolver.
|
|
66
|
+
const enhanceLanguageServiceHost = (host) => {
|
|
67
|
+
const platformExtensionNames = (0, platform_1.platformExtensions)(platform);
|
|
68
|
+
const disableReactNativePackageSubstitution = true;
|
|
69
|
+
const traceReactNativeModuleResolutionErrors = false;
|
|
70
|
+
const traceResolutionLog = undefined;
|
|
71
|
+
(0, typescript_react_native_resolver_1.changeHostToUseReactNativeResolver)({
|
|
72
|
+
host,
|
|
73
|
+
options: cmdLine.options,
|
|
74
|
+
platform,
|
|
75
|
+
platformExtensionNames,
|
|
76
|
+
disableReactNativePackageSubstitution,
|
|
77
|
+
traceReactNativeModuleResolutionErrors,
|
|
78
|
+
traceResolutionLog,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const tsproject = new typescript_service_1.Project(documentRegistry, diagnosticWriter, cmdLine, enhanceLanguageServiceHost);
|
|
82
|
+
return {
|
|
83
|
+
tsproject,
|
|
84
|
+
tssourceFiles,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function getProjectInfo(sourceFile, platform) {
|
|
88
|
+
const root = findProjectRoot(sourceFile);
|
|
89
|
+
projects[root] || (projects[root] = {});
|
|
90
|
+
let info = projects[root][platform];
|
|
91
|
+
if (!info) {
|
|
92
|
+
info = createProjectInfo(root, platform);
|
|
93
|
+
projects[root][platform] = info;
|
|
94
|
+
}
|
|
95
|
+
return info;
|
|
96
|
+
}
|
|
97
|
+
function clearPlatform(platform) {
|
|
98
|
+
Object.values(projects).forEach((projectsByPlatform) => {
|
|
99
|
+
const info = projectsByPlatform[platform];
|
|
100
|
+
if (info) {
|
|
101
|
+
if (info.tsproject) {
|
|
102
|
+
info.tsproject.dispose();
|
|
103
|
+
}
|
|
104
|
+
delete projectsByPlatform[platform];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
clearPlatform,
|
|
110
|
+
getProjectInfo,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.createProjectCache = createProjectCache;
|
|
114
|
+
//# sourceMappingURL=project-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-cache.js","sourceRoot":"","sources":["../../src/typescript/project-cache.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAqD;AACrD,mEAG8C;AAC9C,gGAA+F;AAC/F,oEAIqC;AACrC,gDAAwB;AACxB,4DAA4B;AAqC5B;;;;;GAKG;AACH,SAAgB,kBAAkB,CAChC,KAAiC;IAEjC,MAAM,gBAAgB,GAAG,oBAAE,CAAC,sBAAsB,EAAE,CAAC;IACrD,MAAM,gBAAgB,GAAG,IAAA,2CAAsB,EAAC,KAAK,CAAC,CAAC;IAEvD,wEAAwE;IACxE,MAAM,QAAQ,GAGV,EAAE,CAAC;IAEP,SAAS,eAAe,CAAC,UAAkB;QACzC,6EAA6E;QAC7E,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YACxC,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;gBAC/B,OAAO,IAAI,CAAC;aACb;SACF;QAED,gEAAgE;QAChE,MAAM,IAAI,GAAG,IAAA,2BAAc,EAAC,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,EAAE;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AC,SAAS,CAAC,OAAO,EAAE,CAAC;iBAC1B;gBACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;aACrC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,aAAa;QACb,cAAc;KACf,CAAC;AACJ,CAAC;AA9HD,gDA8HC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnx-kit/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.58",
|
|
4
4
|
"description": "Command-line interface for working with kit packages in your repo",
|
|
5
5
|
"homepage": "https://github.com/microsoft/rnx-kit/tree/main/packages/cli",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@rnx-kit/tools-language": "^1.2.6",
|
|
32
32
|
"@rnx-kit/tools-node": "^1.2.6",
|
|
33
33
|
"@rnx-kit/tools-react-native": "^1.0.10",
|
|
34
|
-
"@rnx-kit/typescript-react-native-resolver": "^0.
|
|
34
|
+
"@rnx-kit/typescript-react-native-resolver": "^0.2.0",
|
|
35
35
|
"@rnx-kit/typescript-service": "^1.5.3",
|
|
36
36
|
"chalk": "^4.1.0",
|
|
37
37
|
"readline": "^1.3.0"
|
package/src/bundle/metro.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { info
|
|
1
|
+
import { info } from "@rnx-kit/console";
|
|
2
2
|
import { bundle, BundleArgs as MetroBundleArgs } from "@rnx-kit/metro-service";
|
|
3
3
|
import { createDirectory } from "@rnx-kit/tools-node/fs";
|
|
4
|
-
import { findConfigFile, Service } from "@rnx-kit/typescript-service";
|
|
5
|
-
import chalk from "chalk";
|
|
6
4
|
import type { ConfigT } from "metro-config";
|
|
7
5
|
import path from "path";
|
|
8
6
|
import { customizeMetroConfig } from "../metro-config";
|
|
9
|
-
import type { TSProjectInfo } from "../types";
|
|
10
7
|
import type { BundleConfig } from "./types";
|
|
8
|
+
import type { TypeScriptValidationOptions } from "../types";
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* Create Metro bundler arguments from a bundle configuration.
|
|
@@ -64,38 +62,19 @@ export function createMetroBundleArgs({
|
|
|
64
62
|
* @param bundleConfig Bundle configuration
|
|
65
63
|
*/
|
|
66
64
|
export async function metroBundle(
|
|
67
|
-
tsservice: Service,
|
|
68
65
|
metroConfig: ConfigT,
|
|
69
66
|
bundleConfig: BundleConfig
|
|
70
67
|
): Promise<void> {
|
|
71
68
|
info(`Bundling ${bundleConfig.platform}...`);
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
bundleConfig.entryPath,
|
|
77
|
-
"tsconfig.json"
|
|
78
|
-
);
|
|
79
|
-
if (!configFileName) {
|
|
80
|
-
warn(
|
|
81
|
-
chalk.yellow(
|
|
82
|
-
"skipping TypeScript validation -- cannot find tsconfig.json for entry file %o"
|
|
83
|
-
),
|
|
84
|
-
bundleConfig.entryPath
|
|
85
|
-
);
|
|
86
|
-
} else {
|
|
87
|
-
tsprojectInfo = {
|
|
88
|
-
service: tsservice,
|
|
89
|
-
configFileName,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
70
|
+
const typescriptValidationOptions: TypeScriptValidationOptions = {
|
|
71
|
+
throwOnError: true,
|
|
72
|
+
};
|
|
94
73
|
customizeMetroConfig(
|
|
95
74
|
metroConfig,
|
|
96
75
|
bundleConfig.detectCyclicDependencies,
|
|
97
76
|
bundleConfig.detectDuplicateDependencies,
|
|
98
|
-
|
|
77
|
+
bundleConfig.typescriptValidation ? typescriptValidationOptions : false,
|
|
99
78
|
bundleConfig.experimental_treeShake
|
|
100
79
|
);
|
|
101
80
|
|
package/src/bundle.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { Config as CLIConfig } from "@react-native-community/cli-types";
|
|
|
2
2
|
import { BundleArgs, loadMetroConfig } from "@rnx-kit/metro-service";
|
|
3
3
|
import { extendObjectArray } from "@rnx-kit/tools-language/properties";
|
|
4
4
|
import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
5
|
-
import { Service } from "@rnx-kit/typescript-service";
|
|
6
5
|
import { getKitBundleConfigs } from "./bundle/kit-config";
|
|
7
6
|
import { metroBundle } from "./bundle/metro";
|
|
8
7
|
import { applyKitBundleConfigOverrides } from "./bundle/overrides";
|
|
@@ -51,10 +50,8 @@ export async function rnxBundle(
|
|
|
51
50
|
}
|
|
52
51
|
);
|
|
53
52
|
|
|
54
|
-
const tsservice = new Service();
|
|
55
|
-
|
|
56
53
|
for (const bundleConfig of bundleConfigs) {
|
|
57
|
-
await metroBundle(
|
|
54
|
+
await metroBundle(metroConfig, bundleConfig);
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
return Promise.resolve();
|
package/src/metro-config.ts
CHANGED
|
@@ -11,94 +11,87 @@ import {
|
|
|
11
11
|
esbuildTransformerConfig,
|
|
12
12
|
MetroSerializer as MetroSerializerEsbuild,
|
|
13
13
|
} from "@rnx-kit/metro-serializer-esbuild";
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
Project,
|
|
18
|
-
readConfigFile,
|
|
19
|
-
createDiagnosticWriter,
|
|
20
|
-
} from "@rnx-kit/typescript-service";
|
|
21
|
-
import type { DeltaResult, Graph } from "metro";
|
|
22
|
-
import type { InputConfigT, SerializerConfigT } from "metro-config";
|
|
23
|
-
import type { LanguageServiceHost } from "typescript";
|
|
14
|
+
import { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
|
|
15
|
+
import { Project } from "@rnx-kit/typescript-service";
|
|
24
16
|
|
|
25
|
-
import
|
|
17
|
+
import { createProjectCache } from "./typescript/project-cache";
|
|
18
|
+
import type { TypeScriptValidationOptions } from "./types";
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function resetProject(platform: AllPlatforms): void {
|
|
31
|
-
const tsproject = tsprojectByPlatform.get(platform);
|
|
32
|
-
if (tsproject) {
|
|
33
|
-
tsproject.dispose();
|
|
34
|
-
tsprojectByPlatform.delete(platform);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
20
|
+
import type { DeltaResult, Graph } from "metro";
|
|
21
|
+
import type { InputConfigT, SerializerConfigT } from "metro-config";
|
|
37
22
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Create a hook function to be registered with Metro during serialization.
|
|
25
|
+
* Each serialization pass runs the hook which type-checks each added/updated
|
|
26
|
+
* source file.
|
|
27
|
+
*
|
|
28
|
+
* Source file in node_modules (external packages) are ignored.
|
|
29
|
+
*
|
|
30
|
+
* @param options TypeScript validation options
|
|
31
|
+
* @returns Hook function
|
|
32
|
+
*/
|
|
33
|
+
function createSerializerHook(options: TypeScriptValidationOptions) {
|
|
34
|
+
const projectCache = createProjectCache(options.print);
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
platform === "windows" || platform === "win32"
|
|
54
|
-
? ["win", "native"]
|
|
55
|
-
: ["native"];
|
|
56
|
-
const disableReactNativePackageSubstitution = true;
|
|
57
|
-
const traceReactNativeModuleResolutionErrors = false;
|
|
58
|
-
const traceResolutionLog = undefined;
|
|
59
|
-
changeHostToUseReactNativeResolver({
|
|
60
|
-
host,
|
|
61
|
-
options: cmdLine.options,
|
|
62
|
-
platform,
|
|
63
|
-
platformExtensionNames,
|
|
64
|
-
disableReactNativePackageSubstitution,
|
|
65
|
-
traceReactNativeModuleResolutionErrors,
|
|
66
|
-
traceResolutionLog,
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
tsproject = service.openProject(cmdLine, enhanceLanguageServiceHost);
|
|
71
|
-
tsproject.removeAllFiles();
|
|
72
|
-
|
|
73
|
-
tsprojectByPlatform.set(platform, tsproject);
|
|
74
|
-
}
|
|
75
|
-
return tsproject;
|
|
76
|
-
}
|
|
36
|
+
const patternNodeModules = /[/\\]node_modules[/\\]/;
|
|
37
|
+
const excludeNodeModules = (p: string) => !patternNodeModules.test(p);
|
|
77
38
|
|
|
78
39
|
const hook = (graph: Graph, delta: DeltaResult): void => {
|
|
79
40
|
const platform = graph.transformOptions.platform as AllPlatforms;
|
|
80
41
|
if (platform) {
|
|
81
42
|
if (delta.reset) {
|
|
82
|
-
|
|
43
|
+
// Metro is signaling that all cached data for this Graph should be
|
|
44
|
+
// thrown out. Each Graph is scoped to one platform, so discard all
|
|
45
|
+
// of that platform's projects.
|
|
46
|
+
projectCache.clearPlatform(platform);
|
|
83
47
|
}
|
|
84
48
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
49
|
+
// Filter adds, updates, and deletes coming from Metro. Do not look at
|
|
50
|
+
// anything in an external package (e.g. under node_modules).
|
|
51
|
+
const adds = Array.from(
|
|
52
|
+
delta.added.values(),
|
|
53
|
+
(module) => module.path
|
|
54
|
+
).filter(excludeNodeModules);
|
|
55
|
+
|
|
56
|
+
const updates = Array.from(
|
|
57
|
+
delta.modified.values(),
|
|
58
|
+
(module) => module.path
|
|
59
|
+
).filter(excludeNodeModules);
|
|
60
|
+
|
|
61
|
+
const deletes = Array.from(delta.deleted.values()).filter(
|
|
62
|
+
excludeNodeModules
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// Map each file to a TypeScript project, and apply its delta operation.
|
|
66
|
+
const tsprojectsToValidate: Set<Project> = new Set();
|
|
67
|
+
adds.concat(updates).forEach((sourceFile) => {
|
|
68
|
+
const { tsproject, tssourceFiles } = projectCache.getProjectInfo(
|
|
69
|
+
sourceFile,
|
|
70
|
+
platform
|
|
71
|
+
);
|
|
72
|
+
if (tssourceFiles.has(sourceFile)) {
|
|
73
|
+
tsproject.setFile(sourceFile);
|
|
74
|
+
tsprojectsToValidate.add(tsproject);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
deletes.forEach((sourceFile) => {
|
|
78
|
+
const { tsproject } = projectCache.getProjectInfo(sourceFile, platform);
|
|
79
|
+
tsproject.removeFile(sourceFile);
|
|
80
|
+
tsprojectsToValidate.add(tsproject);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Validate all projects which changed, printing all type errors.
|
|
84
|
+
let isValid = true;
|
|
85
|
+
tsprojectsToValidate.forEach((p) => {
|
|
86
|
+
if (!p.validate()) {
|
|
87
|
+
isValid = false;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (!isValid && options.throwOnError) {
|
|
92
|
+
// Type-checking failed. Fail the Metro operation (bundling or serving).
|
|
93
|
+
throw new Error("Type validation failed");
|
|
99
94
|
}
|
|
100
|
-
|
|
101
|
-
tsproject.validate();
|
|
102
95
|
}
|
|
103
96
|
};
|
|
104
97
|
|
|
@@ -115,14 +108,14 @@ const emptySerializerHook = (_graph: Graph, _delta: DeltaResult): void => {
|
|
|
115
108
|
* @param metroConfigReadonly Metro configuration
|
|
116
109
|
* @param detectCyclicDependencies When true, cyclic dependency checking is enabled with a default set of options. Otherwise the object allows for fine-grained control over the detection process.
|
|
117
110
|
* @param detectDuplicateDependencies When true, duplicate dependency checking is enabled with a default set of options. Otherwise, the object allows for fine-grained control over the detection process.
|
|
118
|
-
* @param
|
|
111
|
+
* @param typescriptValidation When true, TypeScript type-checking is enabled with a default set of options. Otherwise, the object allows for fine-grained control over the type-checking process.
|
|
119
112
|
* @param experimental_treeShake When true, experimental tree-shaking is enabled.
|
|
120
113
|
*/
|
|
121
114
|
export function customizeMetroConfig(
|
|
122
115
|
metroConfigReadonly: InputConfigT,
|
|
123
116
|
detectCyclicDependencies: boolean | CyclicDetectorOptions,
|
|
124
117
|
detectDuplicateDependencies: boolean | DuplicateDetectorOptions,
|
|
125
|
-
|
|
118
|
+
typescriptValidation: boolean | TypeScriptValidationOptions,
|
|
126
119
|
experimental_treeShake: boolean
|
|
127
120
|
): void {
|
|
128
121
|
// We will be making changes to the Metro configuration. Coerce from a
|
|
@@ -162,7 +155,11 @@ export function customizeMetroConfig(
|
|
|
162
155
|
delete metroConfig.serializer.customSerializer;
|
|
163
156
|
}
|
|
164
157
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
158
|
+
let hook = emptySerializerHook;
|
|
159
|
+
if (typeof typescriptValidation === "object") {
|
|
160
|
+
hook = createSerializerHook(typescriptValidation);
|
|
161
|
+
} else if (typescriptValidation !== false) {
|
|
162
|
+
hook = createSerializerHook({});
|
|
163
|
+
}
|
|
164
|
+
metroConfig.serializer.experimentalSerializerHook = hook;
|
|
168
165
|
}
|
package/src/start.ts
CHANGED
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
loadMetroConfig,
|
|
6
6
|
startServer,
|
|
7
7
|
} from "@rnx-kit/metro-service";
|
|
8
|
-
import { findConfigFile, Service } from "@rnx-kit/typescript-service";
|
|
9
8
|
import chalk from "chalk";
|
|
10
9
|
import type { Reporter, ReportableEvent } from "metro";
|
|
11
10
|
import type Server from "metro/src/Server";
|
|
@@ -14,7 +13,7 @@ import path from "path";
|
|
|
14
13
|
import readline from "readline";
|
|
15
14
|
import { getKitServerConfig } from "./serve/kit-config";
|
|
16
15
|
import { customizeMetroConfig } from "./metro-config";
|
|
17
|
-
import type {
|
|
16
|
+
import type { TypeScriptValidationOptions } from "./types";
|
|
18
17
|
|
|
19
18
|
export type CLIStartOptions = {
|
|
20
19
|
host: string;
|
|
@@ -120,35 +119,17 @@ export async function rnxStart(
|
|
|
120
119
|
: undefined),
|
|
121
120
|
});
|
|
122
121
|
|
|
123
|
-
// prepare for typescript validation, if requested
|
|
124
|
-
let tsprojectInfo: TSProjectInfo | undefined;
|
|
125
|
-
if (serverConfig.typescriptValidation) {
|
|
126
|
-
const tsservice = new Service((message) => terminal.log(message));
|
|
127
|
-
|
|
128
|
-
const configFileName = findConfigFile(
|
|
129
|
-
metroConfig.projectRoot,
|
|
130
|
-
"tsconfig.json"
|
|
131
|
-
);
|
|
132
|
-
if (!configFileName) {
|
|
133
|
-
terminal.log(
|
|
134
|
-
chalk.yellow(
|
|
135
|
-
`Warning: cannot find tsconfig.json under project root '${metroConfig.projectRoot}' -- skipping TypeScript validation`
|
|
136
|
-
)
|
|
137
|
-
);
|
|
138
|
-
} else {
|
|
139
|
-
tsprojectInfo = {
|
|
140
|
-
service: tsservice,
|
|
141
|
-
configFileName,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
122
|
// customize the metro config to include plugins, presets, etc.
|
|
123
|
+
const typescriptValidationOptions: TypeScriptValidationOptions = {
|
|
124
|
+
print: (message: string): void => {
|
|
125
|
+
terminal.log(message);
|
|
126
|
+
},
|
|
127
|
+
};
|
|
147
128
|
customizeMetroConfig(
|
|
148
129
|
metroConfig,
|
|
149
130
|
serverConfig.detectCyclicDependencies,
|
|
150
131
|
serverConfig.detectDuplicateDependencies,
|
|
151
|
-
|
|
132
|
+
serverConfig.typescriptValidation ? typescriptValidationOptions : false,
|
|
152
133
|
serverConfig.experimental_treeShake
|
|
153
134
|
);
|
|
154
135
|
|