@rnx-kit/cli 0.15.0 → 0.15.2

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 (48) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/coverage/clover.xml +23 -117
  3. package/coverage/coverage-final.json +1 -2
  4. package/coverage/lcov-report/index.html +20 -35
  5. package/coverage/lcov-report/src/bundle/defaultPlugins.ts.html +1 -1
  6. package/coverage/lcov-report/src/bundle/index.html +1 -1
  7. package/coverage/lcov-report/src/bundle/kit-config.ts.html +1 -1
  8. package/coverage/lcov-report/src/bundle/metro.ts.html +1 -1
  9. package/coverage/lcov-report/src/bundle/overrides.ts.html +1 -1
  10. package/coverage/lcov-report/src/copy-assets.ts.html +1 -1
  11. package/coverage/lcov-report/src/index.html +20 -20
  12. package/coverage/lcov-report/src/metro-config.ts.html +14 -323
  13. package/coverage/lcov.info +36 -209
  14. package/lib/align-deps.d.ts +1 -1
  15. package/lib/align-deps.d.ts.map +1 -1
  16. package/lib/bundle/overrides.d.ts +1 -1
  17. package/lib/bundle/overrides.d.ts.map +1 -1
  18. package/lib/bundle/types.d.ts +2 -2
  19. package/lib/bundle/types.d.ts.map +1 -1
  20. package/lib/bundle.d.ts +1 -1
  21. package/lib/bundle.d.ts.map +1 -1
  22. package/lib/clean.d.ts +1 -1
  23. package/lib/clean.d.ts.map +1 -1
  24. package/lib/copy-assets.d.ts +5 -5
  25. package/lib/copy-assets.d.ts.map +1 -1
  26. package/lib/metro-config.d.ts.map +1 -1
  27. package/lib/metro-config.js +2 -78
  28. package/lib/metro-config.js.map +1 -1
  29. package/lib/ram-bundle.d.ts +1 -1
  30. package/lib/ram-bundle.d.ts.map +1 -1
  31. package/lib/serve/kit-config.d.ts +2 -2
  32. package/lib/serve/kit-config.d.ts.map +1 -1
  33. package/lib/start.d.ts +1 -1
  34. package/lib/start.d.ts.map +1 -1
  35. package/lib/test.d.ts +2 -2
  36. package/lib/test.d.ts.map +1 -1
  37. package/lib/write-third-party-notices.d.ts +1 -1
  38. package/lib/write-third-party-notices.d.ts.map +1 -1
  39. package/package.json +5 -7
  40. package/src/metro-config.ts +3 -106
  41. package/test/metro-config.test.ts +1 -3
  42. package/coverage/lcov-report/src/typescript/index.html +0 -116
  43. package/coverage/lcov-report/src/typescript/project-cache.ts.html +0 -712
  44. package/lib/typescript/project-cache.d.ts +0 -42
  45. package/lib/typescript/project-cache.d.ts.map +0 -1
  46. package/lib/typescript/project-cache.js +0 -159
  47. package/lib/typescript/project-cache.js.map +0 -1
  48. package/src/typescript/project-cache.ts +0 -209
@@ -1,112 +1,14 @@
1
- import type {
2
- BundlerPlugins,
3
- TypeScriptValidationOptions,
4
- } from "@rnx-kit/config";
1
+ import type { BundlerPlugins } from "@rnx-kit/config";
5
2
  import { CyclicDependencies } from "@rnx-kit/metro-plugin-cyclic-dependencies-detector";
6
3
  import { DuplicateDependencies } from "@rnx-kit/metro-plugin-duplicates-checker";
4
+ import { TypeScriptPlugin } from "@rnx-kit/metro-plugin-typescript";
7
5
  import type { MetroPlugin } from "@rnx-kit/metro-serializer";
8
6
  import { MetroSerializer } from "@rnx-kit/metro-serializer";
9
7
  import {
10
8
  esbuildTransformerConfig,
11
9
  MetroSerializer as MetroSerializerEsbuild,
12
10
  } from "@rnx-kit/metro-serializer-esbuild";
13
- import type { AllPlatforms } from "@rnx-kit/tools-react-native/platform";
14
- import type { Project } from "@rnx-kit/typescript-service";
15
- import type { DeltaResult, Graph } from "metro";
16
11
  import type { InputConfigT, SerializerConfigT } from "metro-config";
17
- import { createProjectCache } from "./typescript/project-cache";
18
-
19
- /**
20
- * Create a hook function to be registered with Metro during serialization.
21
- * Each serialization pass runs the hook which type-checks each added/updated
22
- * source file.
23
- *
24
- * Source file in node_modules (external packages) are ignored.
25
- *
26
- * @param options TypeScript validation options
27
- * @param print Optional function to use when printing status messages to the Metro console
28
- * @returns Hook function
29
- */
30
- function createSerializerHook(
31
- options: TypeScriptValidationOptions,
32
- print?: (message: string) => void
33
- ) {
34
- const projectCache = createProjectCache(print);
35
-
36
- const patternNodeModules = /[/\\]node_modules[/\\]/;
37
- const excludeNodeModules = (p: string) => !patternNodeModules.test(p);
38
-
39
- const hook = (graph: Graph, delta: DeltaResult): void => {
40
- const platform = graph.transformOptions.platform as AllPlatforms;
41
- if (platform) {
42
- if (delta.reset) {
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);
47
- }
48
-
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
- // Try to map each file to a TypeScript project, and apply its delta operation.
66
- // Some projects may not actually be TypeScript projects (ignore those).
67
- const tsprojectsToValidate: Set<Project> = new Set();
68
- adds.concat(updates).forEach((sourceFile) => {
69
- const projectInfo = projectCache.getProjectInfo(sourceFile, platform);
70
- if (projectInfo) {
71
- // This is a TypeScript project. Validate it.
72
- const { tsproject, tssourceFiles } = projectInfo;
73
- if (tssourceFiles.has(sourceFile)) {
74
- tsproject.setFile(sourceFile);
75
- tsprojectsToValidate.add(tsproject);
76
- }
77
- }
78
- });
79
- deletes.forEach((sourceFile) => {
80
- const projectInfo = projectCache.getProjectInfo(sourceFile, platform);
81
- if (projectInfo) {
82
- // This is a TypeScript project. Validate it.
83
- const { tsproject } = projectInfo;
84
- tsproject.removeFile(sourceFile);
85
- tsprojectsToValidate.add(tsproject);
86
- }
87
- });
88
-
89
- // Validate all projects which changed, printing all type errors.
90
- let isValid = true;
91
- tsprojectsToValidate.forEach((p) => {
92
- if (!p.validate()) {
93
- isValid = false;
94
- }
95
- });
96
-
97
- if (!isValid && options.throwOnError) {
98
- // Type-checking failed. Fail the Metro operation (bundling or serving).
99
- throw new Error("Type validation failed");
100
- }
101
- }
102
- };
103
-
104
- return hook;
105
- }
106
-
107
- const emptySerializerHook = (_graph: Graph, _delta: DeltaResult): void => {
108
- // nop
109
- };
110
12
 
111
13
  /**
112
14
  * Customize the Metro configuration.
@@ -162,11 +64,6 @@ export function customizeMetroConfig(
162
64
  delete metroConfig.serializer.customSerializer;
163
65
  }
164
66
 
165
- let hook = emptySerializerHook;
166
- if (typeof typescriptValidation === "object") {
167
- hook = createSerializerHook(typescriptValidation, print);
168
- } else if (typescriptValidation !== false) {
169
- hook = createSerializerHook({}, print);
170
- }
67
+ const hook = TypeScriptPlugin(typescriptValidation, print);
171
68
  metroConfig.serializer.experimentalSerializerHook = hook;
172
69
  }
@@ -154,9 +154,7 @@ describe("cli/metro-config/customizeMetroConfig", () => {
154
154
  experimentalSerializerHook: expect.anything(),
155
155
  },
156
156
  transformer: expect.objectContaining({
157
- minifierPath: expect.stringContaining(
158
- "@rnx-kit/metro-serializer-esbuild"
159
- ),
157
+ minifierPath: expect.stringContaining("metro-serializer-esbuild"),
160
158
  }),
161
159
  });
162
160
  expect(typeof inputConfig.serializer.customSerializer).toBe("function");
@@ -1,116 +0,0 @@
1
-
2
- <!doctype html>
3
- <html lang="en">
4
-
5
- <head>
6
- <title>Code coverage report for src/typescript</title>
7
- <meta charset="utf-8" />
8
- <link rel="stylesheet" href="../../prettify.css" />
9
- <link rel="stylesheet" href="../../base.css" />
10
- <link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
11
- <meta name="viewport" content="width=device-width, initial-scale=1" />
12
- <style type='text/css'>
13
- .coverage-summary .sorter {
14
- background-image: url(../../sort-arrow-sprite.png);
15
- }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <div class='wrapper'>
21
- <div class='pad1'>
22
- <h1><a href="../../index.html">All files</a> src/typescript</h1>
23
- <div class='clearfix'>
24
-
25
- <div class='fl pad1y space-right2'>
26
- <span class="strong">7.84% </span>
27
- <span class="quiet">Statements</span>
28
- <span class='fraction'>4/51</span>
29
- </div>
30
-
31
-
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">0% </span>
34
- <span class="quiet">Branches</span>
35
- <span class='fraction'>0/18</span>
36
- </div>
37
-
38
-
39
- <div class='fl pad1y space-right2'>
40
- <span class="strong">10% </span>
41
- <span class="quiet">Functions</span>
42
- <span class='fraction'>1/10</span>
43
- </div>
44
-
45
-
46
- <div class='fl pad1y space-right2'>
47
- <span class="strong">8.16% </span>
48
- <span class="quiet">Lines</span>
49
- <span class='fraction'>4/49</span>
50
- </div>
51
-
52
-
53
- </div>
54
- <p class="quiet">
55
- Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
- </p>
57
- <template id="filterTemplate">
58
- <div class="quiet">
59
- Filter:
60
- <input oninput="onInput()" type="search" id="fileSearch">
61
- </div>
62
- </template>
63
- </div>
64
- <div class='status-line low'></div>
65
- <div class="pad1">
66
- <table class="coverage-summary">
67
- <thead>
68
- <tr>
69
- <th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
70
- <th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
71
- <th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
72
- <th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
73
- <th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
74
- <th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
75
- <th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
76
- <th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
77
- <th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
78
- <th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
79
- </tr>
80
- </thead>
81
- <tbody><tr>
82
- <td class="file low" data-value="project-cache.ts"><a href="project-cache.ts.html">project-cache.ts</a></td>
83
- <td data-value="7.84" class="pic low">
84
- <div class="chart"><div class="cover-fill" style="width: 7%"></div><div class="cover-empty" style="width: 93%"></div></div>
85
- </td>
86
- <td data-value="7.84" class="pct low">7.84%</td>
87
- <td data-value="51" class="abs low">4/51</td>
88
- <td data-value="0" class="pct low">0%</td>
89
- <td data-value="18" class="abs low">0/18</td>
90
- <td data-value="10" class="pct low">10%</td>
91
- <td data-value="10" class="abs low">1/10</td>
92
- <td data-value="8.16" class="pct low">8.16%</td>
93
- <td data-value="49" class="abs low">4/49</td>
94
- </tr>
95
-
96
- </tbody>
97
- </table>
98
- </div>
99
- <div class='push'></div><!-- for sticky footer -->
100
- </div><!-- /wrapper -->
101
- <div class='footer quiet pad2 space-top1 center small'>
102
- Code coverage generated by
103
- <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
104
- at Fri Nov 11 2022 09:03:36 GMT+0000 (Coordinated Universal Time)
105
- </div>
106
- <script src="../../prettify.js"></script>
107
- <script>
108
- window.onload = function () {
109
- prettyPrint();
110
- };
111
- </script>
112
- <script src="../../sorter.js"></script>
113
- <script src="../../block-navigation.js"></script>
114
- </body>
115
- </html>
116
-