Skip to content

Commit e055f71

Browse files
committed
feat: Nx 20.3+
1 parent fe47625 commit e055f71

File tree

3 files changed

+208
-0
lines changed

3 files changed

+208
-0
lines changed

packages/plugin-tools/migrations.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
"version": "5.4.0",
7878
"description": "Migrate tools to 5.4.0",
7979
"implementation": "./src/migrations/update-5-4-0/update-5-4-0"
80+
},
81+
"update-to-5.5.0": {
82+
"cli": "nx",
83+
"version": "5.5.0",
84+
"description": "Migrate tools to 5.5.0",
85+
"implementation": "./src/migrations/update-5-5-0/update-5-5-0"
8086
}
8187
}
8288
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"migrations": [
3+
{
4+
"version": "20.0.0-beta.7",
5+
"description": "Migration for v20.0.0-beta.7",
6+
"implementation": "./src/migrations/update-20-0-0/move-use-daemon-process",
7+
"package": "nx",
8+
"name": "move-use-daemon-process"
9+
},
10+
{
11+
"version": "20.0.1",
12+
"description": "Set `useLegacyCache` to true for migrating workspaces",
13+
"implementation": "./src/migrations/update-20-0-1/use-legacy-cache",
14+
"x-repair-skip": true,
15+
"package": "nx",
16+
"name": "use-legacy-cache"
17+
},
18+
{
19+
"version": "20.2.0-beta.5",
20+
"description": "Update TypeScript ESLint packages to v8.13.0 if they are already on v8",
21+
"implementation": "./src/migrations/update-20-2-0/update-typescript-eslint-v8-13-0",
22+
"package": "@nx/eslint",
23+
"name": "update-typescript-eslint-v8.13.0"
24+
},
25+
{
26+
"version": "20.3.0-beta.1",
27+
"description": "Update ESLint flat config to include .cjs, .mjs, .cts, and .mts files in overrides (if needed)",
28+
"implementation": "./src/migrations/update-20-3-0/add-file-extensions-to-overrides",
29+
"package": "@nx/eslint",
30+
"name": "add-file-extensions-to-overrides"
31+
},
32+
{
33+
"cli": "nx",
34+
"version": "20.0.0-beta.5",
35+
"description": "replace getJestProjects with getJestProjectsAsync",
36+
"implementation": "./src/migrations/update-20-0-0/replace-getJestProjects-with-getJestProjectsAsync",
37+
"package": "@nx/jest",
38+
"name": "replace-getJestProjects-with-getJestProjectsAsync"
39+
},
40+
{
41+
"version": "19.0.0",
42+
"description": "Updates non-standalone Directives, Component and Pipes to 'standalone:false' and removes 'standalone:true' from those who are standalone",
43+
"factory": "./bundles/explicit-standalone-flag#migrate",
44+
"package": "@angular/core",
45+
"name": "explicit-standalone-flag"
46+
}
47+
]
48+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { formatFiles, Tree, updateJson, updateNxJson } from '@nx/devkit';
2+
import { readModulePackageJson } from 'nx/src/utils/package-json';
3+
import { updateDemoAppPackages } from '../../utils/migrations';
4+
import { dirname } from 'path';
5+
const migrations = require('./migrations-to-run.json');
6+
7+
function readPackageMigrationConfig(packageName: string, dir?: string) {
8+
const { path: packageJsonPath, packageJson: json } = readModulePackageJson(packageName, dir ? [dir] : undefined);
9+
10+
const migrationConfigOrFile = json['nx-migrations'] || json['ng-update'];
11+
12+
if (!migrationConfigOrFile) {
13+
return { packageJson: json, migrations: null, packageGroup: [] };
14+
}
15+
16+
const migrationsConfig =
17+
typeof migrationConfigOrFile === 'string'
18+
? {
19+
migrations: migrationConfigOrFile,
20+
packageGroup: [],
21+
}
22+
: migrationConfigOrFile;
23+
24+
try {
25+
const migrationFile = require.resolve(migrationsConfig.migrations, {
26+
paths: [dirname(packageJsonPath)],
27+
});
28+
29+
return {
30+
packageJson: json,
31+
migrations: migrationFile,
32+
packageGroup: migrationsConfig.packageGroup,
33+
};
34+
} catch {
35+
return {
36+
packageJson: json,
37+
migrations: null,
38+
packageGroup: migrationsConfig.packageGroup,
39+
};
40+
}
41+
}
42+
43+
export default async function (tree: Tree) {
44+
updateDependencies(tree);
45+
updateJson(tree, 'tsconfig.base.json', (json) => {
46+
json.compilerOptions = json.compilerOptions || {};
47+
json.compilerOptions.target = 'ES2020';
48+
json.compilerOptions.module = 'ESNext';
49+
json.compilerOptions.lib = ['ESNext', 'dom'];
50+
return json;
51+
});
52+
updateDemoAppPackages(tree, {
53+
devDependencies: {
54+
'@nativescript/android': '~8.8.0',
55+
'@nativescript/ios': '~8.8.0',
56+
},
57+
});
58+
const angularDemoProject = 'apps/demo-angular/project.json';
59+
if (tree.exists(angularDemoProject)) {
60+
updateJson(tree, angularDemoProject, (json) => {
61+
if (json.targets?.build?.options) {
62+
// ensure migrations to run against it
63+
json.targets.build.options.tsConfig = 'apps/demo-angular/tsconfig.json';
64+
}
65+
return json;
66+
});
67+
}
68+
updateJson(tree, 'nx.json', (json) => {
69+
json.release = {
70+
releaseTagPattern: '{version}-{projectName}',
71+
projects: ['packages/*'],
72+
projectsRelationship: 'independent',
73+
changelog: {
74+
workspaceChangelog: false,
75+
projectChangelogs: {
76+
renderOptions: {
77+
authors: true,
78+
commitReferences: true,
79+
versionTitleDate: true,
80+
},
81+
},
82+
},
83+
};
84+
return json;
85+
});
86+
for (const migration of migrations.migrations) {
87+
const packageName = migration.package;
88+
const implRelativePath = migration.implementation || migration.factory;
89+
const collectionPath = readPackageMigrationConfig(packageName).migrations;
90+
let implPath: string;
91+
92+
if (collectionPath) {
93+
let fn: any;
94+
try {
95+
try {
96+
implPath = require.resolve(implRelativePath, {
97+
paths: [dirname(collectionPath)],
98+
});
99+
} catch (e) {
100+
// workaround for a bug in node 12
101+
implPath = require.resolve(`${dirname(collectionPath)}/${implRelativePath}`);
102+
}
103+
104+
fn = require(implPath).default;
105+
} catch (e) {
106+
// ignore, most likely missing package
107+
}
108+
if (fn) {
109+
await fn(tree, {});
110+
}
111+
}
112+
}
113+
// TODO: Edit the generators to use the new tsconfig
114+
115+
await formatFiles(tree);
116+
117+
console.log(`\n NOTE: Your plugin workspace is now migrated. Run this to finish the dependency cleanup:`);
118+
console.log(`\n`);
119+
console.log(` npm run setup`);
120+
console.log(`\n`);
121+
console.log(` This will ensure your workspace is properly reset with all the updates.`);
122+
console.log(` It is also recommended to clean all your demo apps.`);
123+
console.log(`\n`);
124+
}
125+
126+
function updateDependencies(tree: Tree) {
127+
updateJson(tree, 'package.json', (json) => {
128+
if (json.devDependencies['@angular/core']) {
129+
json.devDependencies['@angular-devkit/build-angular'] = '^19.0.0';
130+
for (const key in json.devDependencies) {
131+
if (key.indexOf('@angular/') > -1) {
132+
json.devDependencies[key] = '^19.0.0';
133+
}
134+
if (key.indexOf('@angular-eslint/') > -1) {
135+
json.devDependencies[key] = '^19.0.0';
136+
}
137+
}
138+
}
139+
json.devDependencies['@nativescript/angular'] = '^19.0.0';
140+
json.devDependencies['@nativescript/core'] = '~8.8.0';
141+
json.devDependencies['@nativescript/types'] = '~8.8.0';
142+
json.devDependencies['@ngtools/webpack'] = '^19.0.0';
143+
json.devDependencies['husky'] = '~9.0.0';
144+
json.devDependencies['ng-packagr'] = '^19.0.0';
145+
json.devDependencies['rxjs'] = '~7.8.0';
146+
json.devDependencies['zone.js'] = '~0.15.0';
147+
json.devDependencies['typescript'] = '~5.6.0';
148+
149+
if (json.devDependencies['ts-patch']) {
150+
json.devDependencies['ts-patch'] = '^3.0.0';
151+
}
152+
return json;
153+
});
154+
}

0 commit comments

Comments
 (0)