Skip to content

Commit

Permalink
feat(core): add a migration to replace nrwl/cli and nrwl/tao with nx
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Mar 15, 2022
1 parent 03e9015 commit 48a5d19
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 256 deletions.
29 changes: 14 additions & 15 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@nrwl/nx-source",
"version": "13.8.8",
"version": "13.9.0-beta.1",
"description": "Smart, Fast and Extensible Build System",
"homepage": "https://nx.dev",
"private": true,
Expand Down Expand Up @@ -60,19 +60,18 @@
"@ngrx/schematics": "~13.0.0",
"@ngrx/store": "~13.0.0",
"@ngrx/store-devtools": "~13.0.0",
"@nrwl/cli": "13.8.8-beta.1",
"@nrwl/cypress": "13.8.8-beta.1",
"@nrwl/eslint-plugin-nx": "13.8.8-beta.1",
"@nrwl/jest": "13.8.8-beta.1",
"@nrwl/js": "13.8.8-beta.1",
"@nrwl/linter": "13.8.8-beta.1",
"@nrwl/next": "13.8.8-beta.1",
"@nrwl/node": "13.8.8-beta.1",
"@nrwl/cypress": "13.9.0-beta.1",
"@nrwl/eslint-plugin-nx": "13.9.0-beta.1",
"@nrwl/jest": "13.9.0-beta.1",
"@nrwl/js": "13.9.0-beta.1",
"@nrwl/linter": "13.9.0-beta.1",
"@nrwl/next": "13.9.0-beta.1",
"@nrwl/node": "13.9.0-beta.1",
"@nrwl/nx-cloud": "13.1.6",
"@nrwl/react": "13.8.8-beta.1",
"@nrwl/tao": "13.8.8-beta.1",
"@nrwl/web": "13.8.8-beta.1",
"@nrwl/workspace": "13.8.8-beta.1",
"@nrwl/react": "13.9.0-beta.1",
"@nrwl/web": "13.9.0-beta.1",
"@nrwl/workspace": "13.9.0-beta.1",
"nx": "13.9.0-beta.1",
"@parcel/watcher": "2.0.4",
"@phenomnomnominal/tsquery": "4.1.1",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.1",
Expand Down Expand Up @@ -142,7 +141,7 @@
"ejs": "^3.1.5",
"enhanced-resolve": "^5.8.3",
"eslint": "8.7.0",
"eslint-config-next": "^12.1.0",
"eslint-config-next": "12.1.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "2.25.2",
Expand Down Expand Up @@ -188,7 +187,7 @@
"mime": "2.4.4",
"mini-css-extract-plugin": "~2.4.7",
"minimatch": "3.0.4",
"next": "^12.1.0",
"next": "12.1.0",
"next-sitemap": "^1.6.108",
"ng-packagr": "~13.2.0",
"ngrx-store-freeze": "0.2.4",
Expand Down
19 changes: 15 additions & 4 deletions packages/nx/bin/nx.ts
Expand Up @@ -4,6 +4,7 @@ import * as chalk from 'chalk';
import { initLocal } from '../src/cli/init-local';
import { output } from '../src/cli/output';
import { detectPackageManager } from '../src/shared/package-manager';
import { Workspace } from '../src/cli/workspace';

if (process.argv[2] === 'new' || process.argv[2] === '_migrate') {
require('../src/cli/index');
Expand Down Expand Up @@ -35,9 +36,7 @@ if (process.argv[2] === 'new' || process.argv[2] === '_migrate') {
// Make sure that a local copy of Nx exists in workspace
let localNx: string;
try {
localNx = require.resolve('nx/bin/nx.js', {
paths: [workspace.dir],
});
localNx = resolveNx(workspace);
} catch {
output.error({
title: `Could not find Nx modules in this workspace.`,
Expand All @@ -46,7 +45,7 @@ if (process.argv[2] === 'new' || process.argv[2] === '_migrate') {
process.exit(1);
}

if (localNx === require.resolve('nx/bin/nx.js')) {
if (localNx === resolveNx(null)) {
initLocal(workspace);
} else {
const packageManager = detectPackageManager();
Expand All @@ -71,3 +70,15 @@ if (process.argv[2] === 'new' || process.argv[2] === '_migrate') {
require(localNx);
}
}

function resolveNx(workspace: Workspace | null) {
try {
return require.resolve('nx/bin/nx.js', {
paths: workspace ? [workspace.dir] : undefined,
});
} catch {
return require.resolve('@nrwl/cli/bin/nx.js', {
paths: workspace ? [workspace.dir] : undefined,
});
}
}
6 changes: 6 additions & 0 deletions packages/nx/project.json
Expand Up @@ -53,6 +53,12 @@
},
{
"command": "node ./scripts/copy-readme.js nx"
},
{
"command": "node ./scripts/add-dependency-to-build.js nx @nrwl/cli"
},
{
"command": "node ./scripts/add-dependency-to-build.js nx @nrwl/tao"
}
],
"parallel": false
Expand Down

This file was deleted.

Expand Up @@ -8,7 +8,6 @@ import {
import { join } from 'path';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
import { JestExecutorOptions } from '@nrwl/jest/src/executors/jest/schema';
import { getJestObject } from '@nrwl/jest/src/migrations/update-10-0-0/require-jest-config';

/**
* This function update jest.config.js and test.setup.ts for react native project for Jest 27.
Expand All @@ -26,7 +25,7 @@ function updateJestConfig(tree: Tree) {
}

const jestConfigPath = options.jestConfig;
const jestConfig = getJestObject(join(tree.root, jestConfigPath));
const jestConfig = require(join(tree.root, jestConfigPath));
const testEnvironment = jestConfig.testEnvironment;
const preset = jestConfig.preset;

Expand Down
6 changes: 6 additions & 0 deletions packages/workspace/migrations.json
Expand Up @@ -41,6 +41,12 @@
"description": "Update the decorate-angular-cli script to require nx instead of @nrwl/cli",
"cli": "nx",
"implementation": "./src/migrations/update-13-9-0/update-decorate-cli"
},
"13-9-0-replace-tao-and-cli-with-nx": {
"version": "13.9.0-beta.0",
"description": "Replace @nrwl/tao and @nrwl/cli with nx",
"cli": "nx",
"implementation": "./src/migrations/update-13-9-0/replace-tao-and-cli-with-nx"
}
},
"packageJsonUpdates": {
Expand Down
@@ -0,0 +1,22 @@
import { Tree, updateJson } from '@nrwl/devkit';

export function replaceTaoAndCLIWithNx(host: Tree) {
updateJson(host, 'package.json', (json: any) => {
if (json.dependencies['@nrwl/workspace']) {
json.dependencies['nx'] = json.dependencies['@nrwl/workspace'];
} else if (json.devDependencices['@nrwl/workspace']) {
json.dependencies['nx'] = json.devDependencices['@nrwl/workspace'];
}
removeTaoAndCLI(json.dependencies);
removeTaoAndCLI(json.devDependencices);
return json;
});
}

function removeTaoAndCLI(json: any) {
if (!json) return;
json['@nrwl/tao'] = undefined;
json['@nrwl/cli1'] = undefined;
}

export default replaceTaoAndCLIWithNx;
@@ -1,7 +1,7 @@
import { Tree } from '@nrwl/devkit';

export function updateDecorateAngularCLI(host: Tree) {
const decorate = host.read('decorate-angular-cli.js').toString();
const decorate = host.read('decorate-angular-cli.js')?.toString();
if (decorate) {
host.write(
'decorate-angular-cli.js',
Expand Down
2 changes: 1 addition & 1 deletion scripts/depcheck/discrepancies.ts
Expand Up @@ -13,7 +13,7 @@ export default function getDiscrepancies(
devDependencies: JSON
) {
return Object.keys(projectDependencies)
.filter((p) => !p.startsWith('@nrwl/'))
.filter((p) => !p.startsWith('@nrwl/') && p !== 'nx')
.filter((p) =>
!IGNORE_MATCHES['*'].includes(p) && IGNORE_MATCHES[name]
? !IGNORE_MATCHES[name].includes(p)
Expand Down
11 changes: 9 additions & 2 deletions scripts/depcheck/missing.ts
Expand Up @@ -2,7 +2,14 @@ import * as depcheck from 'depcheck';

// Ignore packages that are defined here per package
const IGNORE_MATCHES = {
'*': ['nx', '@nrwl/workspace', 'prettier', 'typescript', 'dotenv'],
'*': [
'nx',
'@nrwl/cli',
'@nrwl/workspace',
'prettier',
'typescript',
'dotenv',
],
angular: [
'@angular-devkit/architect',
'@angular-devkit/build-angular',
Expand Down Expand Up @@ -36,7 +43,7 @@ const IGNORE_MATCHES = {
'stylus',
'tailwindcss',
],
cli: ['@nrwl/cli'],
cli: ['nx'],
cypress: ['cypress', '@angular-devkit/schematics', '@nrwl/cypress'],
devkit: ['@angular-devkit/architect', 'rxjs'],
'eslint-plugin-nx': ['@angular-eslint/eslint-plugin'],
Expand Down

1 comment on commit 48a5d19

@vercel
Copy link

@vercel vercel bot commented on 48a5d19 Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.