@ng-native/migrate 0.16.0 → 0.17.1

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/migrations.cjs CHANGED
@@ -18,7 +18,10 @@
18
18
  * what is left for the developer to do, one line each.
19
19
  */
20
20
  const { deviceReactNativeImport } = require('./device-react-native-import.cjs');
21
+ const { engineNodeFields } = require('./engine-node-fields.cjs');
21
22
  const { engineNodeTag } = require('./engine-node-tag.cjs');
23
+ const { libraryTypecheckDeclarationMap } = require('./library-typecheck-declaration-map.cjs');
24
+ const { nativeTypecheckTarget } = require('./native-typecheck-target.cjs');
22
25
  const { splitStoreAndPlayer } = require('./split-store-and-player.cjs');
23
26
  const { syncAppVersions } = require('./sync-app-versions.cjs');
24
27
  const { trackingAvailableGetter } = require('./tracking-available-getter.cjs');
@@ -59,6 +62,25 @@ const migrations = [
59
62
  description: "Read an engine node's element tag as tag rather than name.",
60
63
  run: engineNodeTag,
61
64
  },
65
+ {
66
+ name: 'engine-node-fields',
67
+ version: '0.17.0',
68
+ description: "Read an engine node's children, text, kind, host and sheet by their new names.",
69
+ run: engineNodeFields,
70
+ },
71
+ {
72
+ name: 'library-typecheck-declaration-map',
73
+ version: '0.17.1',
74
+ description:
75
+ "Turn off declarationMap in each Nx library's tsconfig.typecheck.json, which TypeScript refuses beside composite: false.",
76
+ run: libraryTypecheckDeclarationMap,
77
+ },
78
+ {
79
+ name: 'native-typecheck-target',
80
+ version: '0.17.1',
81
+ description: 'Give each Angular Native project in angular.json a typecheck target, run by ngc.',
82
+ run: nativeTypecheckTarget,
83
+ },
62
84
  ];
63
85
 
64
86
  module.exports = { migrations };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Gives each Angular Native project in `angular.json` a `typecheck` target, as `ng add` now writes.
3
+ *
4
+ * `ng run <project>:typecheck` runs `ngc` on the project, which checks its templates as well as its
5
+ * code; without it a binding to an input a component does not have goes unchecked. A project is
6
+ * Angular Native's when one of its targets runs one of `@ng-native/schematics`' builders. A
7
+ * `typecheck` target the project already has, whatever runs it, stays.
8
+ */
9
+ const { formatted } = require('./sync-app-versions.cjs');
10
+
11
+ const TARGET = { builder: '@ng-native/schematics:typecheck', options: {} };
12
+
13
+ /** @param {Record<string, { builder?: string }> | undefined} targets */
14
+ const isNative = (targets) =>
15
+ Object.values(targets ?? {}).some((target) =>
16
+ String(target?.builder).startsWith('@ng-native/schematics:'),
17
+ );
18
+
19
+ /**
20
+ * @param {import('./host.cjs').Host} host
21
+ * @returns {string[]} what is left to do by hand: the target, when `angular.json` has comments or
22
+ * trailing commas, which the Angular CLI allows and rewriting it here would lose
23
+ */
24
+ function nativeTypecheckTarget(host) {
25
+ const original = host.read('angular.json');
26
+ if (original === null) return [];
27
+ let workspace;
28
+ try {
29
+ workspace = JSON.parse(original);
30
+ } catch {
31
+ return [
32
+ 'angular.json: not plain JSON, so no typecheck target was added. Give each Angular Native ' +
33
+ 'project one by hand: "typecheck": { "builder": "@ng-native/schematics:typecheck" } in its ' +
34
+ 'architect.',
35
+ ];
36
+ }
37
+ let changed = false;
38
+ for (const project of Object.values(workspace.projects ?? {})) {
39
+ if (!project || typeof project !== 'object') continue;
40
+ const targets = project.architect ?? project.targets;
41
+ if (!isNative(targets) || targets.typecheck) continue;
42
+ targets.typecheck = { ...TARGET };
43
+ changed = true;
44
+ }
45
+ if (changed) host.write('angular.json', formatted(workspace, original));
46
+ return [];
47
+ }
48
+
49
+ module.exports = { nativeTypecheckTarget };