@rnx-kit/cli 0.12.3 → 0.12.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/coverage/clover.xml +206 -194
  3. package/coverage/coverage-final.json +3 -3
  4. package/coverage/lcov-report/index.html +26 -26
  5. package/coverage/lcov-report/src/bundle/index.html +1 -1
  6. package/coverage/lcov-report/src/bundle/kit-config.ts.html +1 -1
  7. package/coverage/lcov-report/src/bundle/metro.ts.html +1 -1
  8. package/coverage/lcov-report/src/bundle/overrides.ts.html +1 -1
  9. package/coverage/lcov-report/src/copy-assets.ts.html +36 -12
  10. package/coverage/lcov-report/src/index.html +27 -27
  11. package/coverage/lcov-report/src/metro-config.ts.html +40 -22
  12. package/coverage/lcov-report/src/typescript/index.html +13 -13
  13. package/coverage/lcov-report/src/typescript/project-cache.ts.html +97 -16
  14. package/coverage/lcov.info +368 -342
  15. package/lib/copy-assets.d.ts.map +1 -1
  16. package/lib/copy-assets.js +8 -2
  17. package/lib/copy-assets.js.map +1 -1
  18. package/lib/metro-config.d.ts.map +1 -1
  19. package/lib/metro-config.js +17 -8
  20. package/lib/metro-config.js.map +1 -1
  21. package/lib/start.d.ts.map +1 -1
  22. package/lib/start.js +27 -8
  23. package/lib/start.js.map +1 -1
  24. package/lib/typescript/project-cache.d.ts +1 -1
  25. package/lib/typescript/project-cache.d.ts.map +1 -1
  26. package/lib/typescript/project-cache.js +26 -4
  27. package/lib/typescript/project-cache.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/copy-assets.ts +10 -2
  30. package/src/metro-config.ts +17 -11
  31. package/src/start.ts +48 -8
  32. package/src/typescript/project-cache.ts +35 -8
  33. package/test/__mocks__/child_process.js +1 -1
  34. package/test/copy-assets/assembleAarBundle.test.ts +6 -6
@@ -9,6 +9,7 @@ import {
9
9
  Project,
10
10
  readConfigFile,
11
11
  } from "@rnx-kit/typescript-service";
12
+ import fs from "fs";
12
13
  import path from "path";
13
14
  import ts from "typescript";
14
15
 
@@ -44,7 +45,10 @@ export interface ProjectCache {
44
45
  * @param sourceFile Source file
45
46
  * @returns Project targeting the given platform and containing the given source file
46
47
  */
47
- getProjectInfo(sourceFile: string, platform: AllPlatforms): ProjectInfo;
48
+ getProjectInfo(
49
+ sourceFile: string,
50
+ platform: AllPlatforms
51
+ ): ProjectInfo | undefined;
48
52
  }
49
53
 
50
54
  /**
@@ -84,8 +88,19 @@ export function createProjectCache(
84
88
  return root;
85
89
  }
86
90
 
87
- function readTSConfig(root: string): ts.ParsedCommandLine {
91
+ function readTSConfig(root: string): ts.ParsedCommandLine | undefined {
88
92
  const configFileName = path.join(root, "tsconfig.json");
93
+ if (!fs.existsSync(configFileName)) {
94
+ // Allow for packages that aren't TypeScript.
95
+ //
96
+ // Example: Users who enable bundling with all the config defaults will
97
+ // have type validation enabled automatically. They may not actually be
98
+ // using TypeScript.
99
+ //
100
+ // We shouldn't break them. We should use TS validation only for TS packages.
101
+ //
102
+ return undefined;
103
+ }
89
104
 
90
105
  const cmdLine = readConfigFile(configFileName);
91
106
  if (!cmdLine) {
@@ -102,9 +117,13 @@ export function createProjectCache(
102
117
  function createProjectInfo(
103
118
  root: string,
104
119
  platform: AllPlatforms
105
- ): ProjectInfo {
120
+ ): ProjectInfo | undefined {
106
121
  // Load the TypeScript configuration file for this project.
107
122
  const cmdLine = readTSConfig(root);
123
+ if (!cmdLine) {
124
+ // Not a TypeScript project
125
+ return undefined;
126
+ }
108
127
 
109
128
  // Trim down the list of source files found by TypeScript. This ensures
110
129
  // that only explicitly added files are loaded and parsed by TypeScript.
@@ -151,15 +170,23 @@ export function createProjectCache(
151
170
  function getProjectInfo(
152
171
  sourceFile: string,
153
172
  platform: AllPlatforms
154
- ): ProjectInfo {
173
+ ): ProjectInfo | undefined {
155
174
  const root = findProjectRoot(sourceFile);
156
175
  projects[root] ||= {};
157
176
 
158
- let info = projects[root][platform];
159
- if (!info) {
160
- info = createProjectInfo(root, platform);
161
- projects[root][platform] = info;
177
+ const platforms = projects[root];
178
+
179
+ // Have we seen the project/platform for this source file before,
180
+ // even if what we saw is 'undefined' (e.g. not a TS project)?
181
+ if (Object.prototype.hasOwnProperty.call(platforms, platform)) {
182
+ return platforms[platform];
162
183
  }
184
+
185
+ // We haven't seen this project/platform before. Try to load it,
186
+ // even if it isn't a TS project. Cache the result so we don't
187
+ // do this again.
188
+ const info = createProjectInfo(root, platform);
189
+ platforms[platform] = info;
163
190
  return info;
164
191
  }
165
192
 
@@ -1,5 +1,5 @@
1
1
  const child_process = jest.createMockFromModule("child_process");
2
2
 
3
- child_process.spawnSync(() => undefined);
3
+ child_process.spawnSync = () => ({ status: 0 });
4
4
 
5
5
  module.exports = child_process;
@@ -23,11 +23,11 @@ export const context = {
23
23
 
24
24
  describe("assembleAarBundle", () => {
25
25
  const consoleWarnSpy = jest.spyOn(global.console, "warn");
26
+ const spawnSyncSpy = jest.spyOn(require("child_process"), "spawnSync");
26
27
 
27
28
  afterEach(() => {
28
29
  mockFiles();
29
30
  consoleWarnSpy.mockReset();
30
- spawnSync.mockReset();
31
31
  });
32
32
 
33
33
  afterAll(() => {
@@ -48,7 +48,7 @@ describe("assembleAarBundle", () => {
48
48
  expect.anything(),
49
49
  expect.stringMatching(/cannot find `gradlew`$/)
50
50
  );
51
- expect(spawnSync).not.toHaveBeenCalled();
51
+ expect(spawnSyncSpy).not.toHaveBeenCalled();
52
52
  expect(findFiles()).toEqual([]);
53
53
  });
54
54
 
@@ -82,7 +82,7 @@ describe("assembleAarBundle", () => {
82
82
  expect.anything(),
83
83
  expect.stringMatching(/cannot find `build.gradle`/)
84
84
  );
85
- expect(spawnSync).not.toHaveBeenCalled();
85
+ expect(spawnSyncSpy).not.toHaveBeenCalled();
86
86
  expect(findFiles()).toEqual([
87
87
  [expect.stringMatching(/[/\\]gradlew$/), ""],
88
88
  [expect.stringMatching(/[/\\]gradlew.bat$/), ""],
@@ -114,7 +114,7 @@ describe("assembleAarBundle", () => {
114
114
  await assembleAarBundle(context, "@rnx-kit/react-native-auth", { aar: {} });
115
115
 
116
116
  expect(consoleWarnSpy).not.toHaveBeenCalled();
117
- expect(spawnSync).toHaveBeenCalledWith(
117
+ expect(spawnSyncSpy).toHaveBeenCalledWith(
118
118
  expect.stringMatching(/[/\\]gradlew(?:\.bat)?$/),
119
119
  [":rnx-kit_react-native-auth:assembleRelease"],
120
120
  expect.objectContaining({
@@ -200,7 +200,7 @@ describe("assembleAarBundle", () => {
200
200
  await assembleAarBundle(context, "@rnx-kit/react-native-auth", { aar: {} });
201
201
 
202
202
  expect(consoleWarnSpy).not.toHaveBeenCalled();
203
- expect(spawnSync).toHaveBeenCalledWith(
203
+ expect(spawnSyncSpy).toHaveBeenCalledWith(
204
204
  expect.stringMatching(/[/\\]gradlew(?:\.bat)?$/),
205
205
  [":rnx-kit_react-native-auth:assembleRelease"],
206
206
  expect.objectContaining({
@@ -281,7 +281,7 @@ describe("assembleAarBundle", () => {
281
281
  });
282
282
 
283
283
  expect(consoleWarnSpy).not.toHaveBeenCalled();
284
- expect(spawnSync).toHaveBeenCalledWith(
284
+ expect(spawnSyncSpy).toHaveBeenCalledWith(
285
285
  expect.stringMatching(/[/\\]gradlew(?:\.bat)?$/),
286
286
  [":rnx-kit_react-native-auth:assembleRelease"],
287
287
  expect.objectContaining({