@ng-native/migrate 0.17.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.
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns off `declarationMap` in each `tsconfig.typecheck.json` `@ng-native/nx:library` wrote.
|
|
3
|
+
*
|
|
4
|
+
* That config sets `composite: false` so `ngc` can run with `noEmit`, and Nx's TypeScript preset
|
|
5
|
+
* turns `declarationMap` on in `tsconfig.base.json`. With neither `composite` nor `declaration`,
|
|
6
|
+
* TypeScript stops with TS5069 before it checks anything, so `nx typecheck` fails. A config that
|
|
7
|
+
* sets `declarationMap` itself, either way, is left as it is.
|
|
8
|
+
*/
|
|
9
|
+
const { files } = require('./host.cjs');
|
|
10
|
+
const { formatted } = require('./sync-app-versions.cjs');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {import('./host.cjs').Host} host
|
|
14
|
+
* @returns {string[]} the configs that are not plain JSON, which are left for the developer
|
|
15
|
+
*/
|
|
16
|
+
function libraryTypecheckDeclarationMap(host) {
|
|
17
|
+
const notes = [];
|
|
18
|
+
for (const file of files(host)) {
|
|
19
|
+
if (file !== 'tsconfig.typecheck.json' && !file.endsWith('/tsconfig.typecheck.json')) continue;
|
|
20
|
+
const original = host.read(file) ?? '';
|
|
21
|
+
let config;
|
|
22
|
+
try {
|
|
23
|
+
config = JSON.parse(original);
|
|
24
|
+
} catch {
|
|
25
|
+
notes.push(
|
|
26
|
+
`${file}: not plain JSON, so it was left as it is. If ngc reports TS5069 for it, add ` +
|
|
27
|
+
'"declarationMap": false to its compilerOptions.',
|
|
28
|
+
);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// The generator's: ngc's options, over the library's own config. An app's extends its own.
|
|
32
|
+
const generated = config.extends === './tsconfig.lib.json' && config.angularCompilerOptions;
|
|
33
|
+
if (!generated || 'declarationMap' in (config.compilerOptions ?? {})) continue;
|
|
34
|
+
config.compilerOptions = { ...config.compilerOptions, declarationMap: false };
|
|
35
|
+
host.write(file, formatted(config, original));
|
|
36
|
+
}
|
|
37
|
+
return notes;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = { libraryTypecheckDeclarationMap };
|
package/migrations.cjs
CHANGED
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
const { deviceReactNativeImport } = require('./device-react-native-import.cjs');
|
|
21
21
|
const { engineNodeFields } = require('./engine-node-fields.cjs');
|
|
22
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');
|
|
23
25
|
const { splitStoreAndPlayer } = require('./split-store-and-player.cjs');
|
|
24
26
|
const { syncAppVersions } = require('./sync-app-versions.cjs');
|
|
25
27
|
const { trackingAvailableGetter } = require('./tracking-available-getter.cjs');
|
|
@@ -66,6 +68,19 @@ const migrations = [
|
|
|
66
68
|
description: "Read an engine node's children, text, kind, host and sheet by their new names.",
|
|
67
69
|
run: engineNodeFields,
|
|
68
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
|
+
},
|
|
69
84
|
];
|
|
70
85
|
|
|
71
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 };
|
package/package.json
CHANGED
package/sync-app-versions.cjs
CHANGED