Skip to content

Commit

Permalink
feat(core): support Nx 10.2.x and tsconfig.base.json (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker authored Sep 25, 2020
1 parent bb6f26e commit b336329
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 71 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"@angular/service-worker": "~10.1.0",
"@angular/upgrade": "~10.1.0",
"@cypress/webpack-preprocessor": "^5.4.2",
"@nrwl/angular": "~10.1.0",
"@nrwl/express": "~10.1.0",
"@nrwl/nest": "~10.1.0",
"@nrwl/node": "~10.1.0",
"@nrwl/react": "~10.1.0",
"@nrwl/web": "~10.1.0",
"@nrwl/workspace": "~10.1.0",
"@nrwl/angular": "~10.2.0",
"@nrwl/express": "~10.2.0",
"@nrwl/nest": "~10.2.0",
"@nrwl/node": "~10.2.0",
"@nrwl/react": "~10.2.0",
"@nrwl/web": "~10.2.0",
"@nrwl/workspace": "~10.2.0",
"@schematics/angular": "~10.1.0",
"@types/express": "~4.17.0",
"@types/jasmine": "~3.5.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"migrations": "./migrations.json"
},
"dependencies": {
"@nrwl/angular": "^10.1.0"
"@nrwl/angular": "^10.2.0"
},
"peerDependencies": {
"@nstudio/xplat": "*"
Expand Down
11 changes: 8 additions & 3 deletions packages/angular/src/schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tree } from '@angular-devkit/schematics';
import { Schema } from './schema';
import { jsonParse } from '@nstudio/xplat-utils';
import { getRootTsConfigPath, jsonParse } from '@nstudio/xplat-utils';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic } from '../../utils/testing';

Expand Down Expand Up @@ -55,20 +55,25 @@ describe('app', () => {
expect(files.indexOf('/apps/foo-web/tsconfig.json')).toBeGreaterThanOrEqual(
0
);
let checkPath = getRootTsConfigPath();
let checkFile = getFileContent(tree, checkPath);
// console.log('tsconfig.base:', checkFile);
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/tsconfig.json')).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/apps/foo-web/src/main.ts')).toBeGreaterThanOrEqual(
0
);
expect(
files.indexOf('/apps/foo-web/src/app/app.module.ts')
).toBeGreaterThanOrEqual(0);

let checkPath = '/apps/foo-web/src/app/app.component.html';
checkPath = '/apps/foo-web/src/app/app.component.html';
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);

checkPath = '/package.json';
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);

let checkFile = getFileContent(tree, checkPath);
checkFile = getFileContent(tree, checkPath);
// console.log(checkFile);
const packageData: any = jsonParse(checkFile);
expect(packageData.scripts['start.foo.web']).toBeDefined();
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
getJsonFromFile,
updateJsonFile,
supportedPlatforms,
checkRootTsConfig,
} from '@nstudio/xplat-utils';
import { Schema } from './schema';

Expand Down Expand Up @@ -105,6 +106,11 @@ export default function (options: Schema) {
scripts[`start.${platformApp}`] = `nx serve ${options.name}`;
return updatePackageScripts(tree, scripts);
},
(tree: Tree) => {
// make sure tsconfig exists at root
// we do this here because Nrwl with 10.1 was actually removing it
checkRootTsConfig(tree);
},
<any>formatFiles({ skipFormat: options.skipFormat }),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const xplatVersion = '*';
export const nxVersion = '~10.1.0';
export const nxVersion = '~10.2.0';
export const angularVersion = '~10.1.0';
export const angularDevkitVersion = '~0.1001.0';
export const ngxTranslateVersion = '~13.0.0';
Expand Down
8 changes: 4 additions & 4 deletions packages/electron-angular/src/schematics/xplat/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tree } from '@angular-devkit/schematics';

import { setTest, jsonParse } from '@nstudio/xplat-utils';
import { setTest, jsonParse, getRootTsConfigPath } from '@nstudio/xplat-utils';
import { XplatHelpers } from '@nstudio/xplat';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic } from '../../utils/testing';
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('xplat schematic', () => {
expect(hasNativeScript).toBeUndefined();
const hasElectron = packageFile.devDependencies[`electron`];
expect(hasElectron).toBeDefined();
let filePath = '/tsconfig.json';
let filePath = '/tsconfig.base.json';
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@testing/electron']).toBeTruthy();
Expand All @@ -60,7 +60,7 @@ describe('xplat schematic', () => {

const tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/electron-angular/index.ts')).toBeTruthy();
const filePath = '/tsconfig.json';
const filePath = getRootTsConfigPath();
const fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(
Expand All @@ -79,7 +79,7 @@ describe('xplat schematic', () => {

let tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/electron/index.ts')).toBeTruthy();
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@testing/electron']).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-angular/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const xplatVersion = '*';
export const nxVersion = '~10.1.0';
export const nxVersion = '~10.2.0';
13 changes: 9 additions & 4 deletions packages/ionic-angular/src/schematics/xplat/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Tree } from '@angular-devkit/schematics';
import { supportedPlatforms, setTest, jsonParse } from '@nstudio/xplat-utils';
import {
supportedPlatforms,
setTest,
jsonParse,
getRootTsConfigPath,
} from '@nstudio/xplat-utils';
import { XplatHelpers } from '@nstudio/xplat';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic } from '../../utils/testing';
Expand Down Expand Up @@ -37,7 +42,7 @@ describe('xplat ionic angular', () => {
// should not include these root packages
const hasNativeScript = packageFile.dependencies[`nativescript-angular`];
expect(hasNativeScript).toBeUndefined();
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@testing/ionic']).toBeTruthy();
Expand All @@ -55,7 +60,7 @@ describe('xplat ionic angular', () => {

const tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/ionic-angular/index.ts')).toBeTruthy();
const filePath = '/tsconfig.json';
const filePath = getRootTsConfigPath();
const fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(
Expand All @@ -74,7 +79,7 @@ describe('xplat ionic angular', () => {

let tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/ionic/index.ts')).toBeTruthy();
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@testing/ionic']).toBeTruthy();
Expand Down
35 changes: 5 additions & 30 deletions packages/nativescript-angular/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,18 @@ export default function (options: Schema) {
},
},
architect: {
serve: {
builder: '@nrwl/workspace:run-commands',
options: {
commands: [
{
command: `yarn start.${platformApp}.preview`,
},
],
},
},
ios: {
builder: '@nrwl/workspace:run-commands',
options: {
commands: [
{
command: 'ns debug ios --no-hmr',
},
],
commands: ['ns debug ios --no-hmr'],
cwd: `apps/${directory}${options.name}`,
parallel: false,
},
},
android: {
builder: '@nrwl/workspace:run-commands',
options: {
commands: [
{
command: 'ns debug android --no-hmr',
},
],
commands: ['ns debug android --no-hmr'],
cwd: `apps/${directory}${options.name}`,
parallel: false,
},
Expand All @@ -189,16 +171,9 @@ export default function (options: Schema) {
builder: '@nrwl/workspace:run-commands',
options: {
commands: [
{
command:
'npx rimraf -- hooks node_modules platforms package-lock.json',
},
{
command: 'npm i',
},
{
command: 'npx rimraf -- package-lock.json',
},
'npx rimraf hooks node_modules platforms package-lock.json',
'npm i',
'npx rimraf package-lock.json',
],
cwd: `apps/${directory}${options.name}`,
parallel: false,
Expand Down
13 changes: 9 additions & 4 deletions packages/nativescript-angular/src/schematics/xplat/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Tree } from '@angular-devkit/schematics';
import { supportedPlatforms, setTest, jsonParse } from '@nstudio/xplat-utils';
import {
supportedPlatforms,
setTest,
jsonParse,
getRootTsConfigPath,
} from '@nstudio/xplat-utils';
import { XplatHelpers } from '@nstudio/xplat';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic } from '../../utils/testing';
Expand Down Expand Up @@ -43,7 +48,7 @@ describe('xplat schematic', () => {
expect(
packageFile.devDependencies[`@nativescript/types`]
).not.toBeUndefined();
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(
Expand All @@ -68,7 +73,7 @@ describe('xplat schematic', () => {
expect(tree.exists('/libs/core/index.ts')).toBeTruthy();
expect(tree.exists('/libs/scss/_index.scss')).toBeTruthy();
expect(tree.exists('/xplat/nativescript-angular/index.ts')).toBeTruthy();
const filePath = '/tsconfig.json';
const filePath = getRootTsConfigPath();
const fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(
Expand All @@ -87,7 +92,7 @@ describe('xplat schematic', () => {

let tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/nativescript/index.ts')).toBeTruthy();
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(
Expand Down
4 changes: 2 additions & 2 deletions packages/nativescript/src/schematics/helpers/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tree } from '@angular-devkit/schematics';
import { Schema } from '../application/schema';
import { setTest, jsonParse } from '@nstudio/xplat-utils';
import { setTest, jsonParse, getRootTsConfigPath } from '@nstudio/xplat-utils';
import { IHelperSchema, stringUtils } from '@nstudio/xplat';
import {
createXplatWithApps,
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('helpers schematic', () => {
).toBeGreaterThanOrEqual(0);

// should update tsconfig files
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@nativescript/*'][0]).toBe(
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"migrations": "./migrations/migrations.json"
},
"dependencies": {
"@nrwl/angular": "~10.1.0",
"@nrwl/angular": "~10.2.0",
"@nstudio/xplat-utils": "*"
},
"devDependencies": {
Expand Down
11 changes: 8 additions & 3 deletions packages/web-angular/src/schematics/xplat/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Tree } from '@angular-devkit/schematics';
import { supportedPlatforms, setTest, jsonParse } from '@nstudio/xplat-utils';
import {
supportedPlatforms,
setTest,
jsonParse,
getRootTsConfigPath,
} from '@nstudio/xplat-utils';
import { XplatHelpers } from '@nstudio/xplat';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { runSchematic } from '../../utils/testing';
Expand All @@ -24,7 +29,7 @@ describe('xplat schematic', () => {
const tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/web/index.ts')).toBeTruthy();
expect(tree.exists('/xplat/nativescript/index.ts')).toBeFalsy();
let filePath = '/tsconfig.json';
let filePath = getRootTsConfigPath();
let fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(fileContent.compilerOptions.paths['@testing/web']).toBeTruthy();
Expand All @@ -49,7 +54,7 @@ describe('xplat schematic', () => {

const tree = await runSchematic('xplat', options, appTree);
expect(tree.exists('/xplat/web-angular/index.ts')).toBeTruthy();
const filePath = '/tsconfig.json';
const filePath = getRootTsConfigPath();
const fileContent = jsonParse(getFileContent(tree, filePath));
// console.log(fileContent);
expect(
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"migrations": "./migrations.json"
},
"dependencies": {
"@nrwl/web": "^10.1.0"
"@nrwl/web": "^10.2.0"
},
"peerDependencies": {
"@nstudio/xplat": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/xplat-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@angular-devkit/core": "~10.1.0",
"@angular-devkit/schematics": "~10.1.0",
"@nrwl/workspace": "~10.1.0",
"@nrwl/workspace": "~10.2.0",
"chalk": "~4.1.0",
"strip-json-comments": "~3.1.1"
},
Expand Down
26 changes: 25 additions & 1 deletion packages/xplat-utils/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import * as stripJsonComments from 'strip-json-comments';
import { serializeJson } from '@nrwl/workspace';
import { createOrUpdate, serializeJson } from '@nrwl/workspace';

export const supportedPlatforms: Array<PlatformTypes> = [
'web',
Expand Down Expand Up @@ -148,12 +148,36 @@ export const copy = (tree: Tree, from: string, to: string) => {
tree.create(to, file.content);
};

export function getRootTsConfigPath() {
return '/tsconfig.base.json';
}

export function checkRootTsConfig(tree: Tree) {
if (!tree.exists('/tsconfig.json') && tree.exists('/tsconfig.base.json')) {
// to support Nx 10.1+
// NOTE: We may end up creating tsconfig's at libs and xplat levels in future
// This allows ts resolution to work as normal
tree.create(
'/tsconfig.json',
JSON.stringify(
{
extends: `.${getRootTsConfigPath()}`,
},
null,
2
)
);
}
return tree;
}

export function prerun(options?: any, init?: boolean) {
return (tree: Tree) => {
const nxJson = getNxWorkspaceConfig(tree);
if (nxJson) {
npmScope = nxJson.npmScope || 'workspace';
}
tree = checkRootTsConfig(tree);
// console.log('npmScope:', npmScope);
const packageJson = getJsonFromFile(tree, 'package.json');

Expand Down
8 changes: 7 additions & 1 deletion packages/xplat/migrations.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"schematics": {}
"schematics": {
"update-to-10.2.0": {
"version": "10.2.0",
"description": "Migrate workspace to 10.2.0",
"factory": "./migrations/update-10-2-0/update-10-2-0"
}
}
}
Loading

0 comments on commit b336329

Please sign in to comment.