Skip to content

Commit

Permalink
feat: Nx 17 support (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker authored Oct 23, 2023
1 parent 273dbe7 commit 540c755
Show file tree
Hide file tree
Showing 45 changed files with 2,396 additions and 4,212 deletions.
124 changes: 35 additions & 89 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
},
"license": "MIT",
"devDependencies": {
"@angular-devkit/architect": "~0.1601.0",
"@angular-devkit/architect": "~0.1602.0",
"@angular-devkit/build-angular": "~16.2.0",
"@angular-devkit/core": "~16.2.0",
"@angular-devkit/schematics": "~16.2.0",
"@angular-eslint/eslint-plugin": "~16.1.1",
"@angular-eslint/eslint-plugin-template": "~16.1.1",
"@angular-eslint/template-parser": "~16.1.1",
"@angular-eslint/eslint-plugin": "~16.2.0",
"@angular-eslint/eslint-plugin-template": "~16.2.0",
"@angular-eslint/template-parser": "~16.2.0",
"@angular/cli": "~16.2.0",
"@angular/common": "~16.2.0",
"@angular/compiler": "~16.2.0",
Expand All @@ -50,89 +50,59 @@
"@ngrx/effects": "~16.2.0",
"@ngrx/router-store": "~16.2.0",
"@ngrx/store": "~16.2.0",
"@nx/angular": "16.7.4",
"@nx/devkit": "16.7.4",
"@nx/eslint-plugin": "16.7.4",
"@nx/express": "16.7.4",
"@nx/jest": "16.7.4",
"@nx/js": "16.7.4",
"@nx/linter": "16.7.4",
"@nrwl/nx-cloud": "16.3.0",
"@nx/web": "16.7.4",
"@nx/angular": "17.0.1",
"@nx/devkit": "17.0.1",
"@nx/eslint-plugin": "17.0.1",
"@nx/express": "17.0.1",
"@nx/jest": "17.0.1",
"@nx/js": "17.0.1",
"@nx/linter": "17.0.1",
"@nrwl/nx-cloud": "16.5.2",
"@nx/web": "17.0.1",
"@schematics/angular": "~16.2.0",
"@types/eslint": "~8.44.0",
"@types/express": "~4.17.13",
"@types/flat": "^5.0.1",
"@types/fs-extra": "^11.0.1",
"@types/is-ci": "^3.0.0",
"@types/jasmine": "~4.3.5",
"@types/jasmine": "~5.1.1",
"@types/jasminewd2": "~2.0.3",
"@types/jest": "29.5.4",
"@types/marked": "^5.0.1",
"@types/node": "^18.7.18",
"@types/jest": "^29.5.6",
"@types/node": "^20.0.0",
"@types/prettier": "^2.6.2",
"@types/semver": "^7.3.8",
"@types/tar-stream": "^2.2.2",
"@types/tmp": "^0.2.0",
"@types/yargs": "^17.0.10",
"@types/yarnpkg__lockfile": "^1.1.5",
"@typescript-eslint/eslint-plugin": "~6.5.0",
"@typescript-eslint/parser": "~6.5.0",
"@typescript-eslint/type-utils": "~6.5.0",
"@typescript-eslint/utils": "~6.5.0",
"ajv": "^8.11.0",
"autoprefixer": "10.4.15",
"babel-jest": "29.6.4",
"@typescript-eslint/eslint-plugin": "~6.8.0",
"@typescript-eslint/parser": "~6.8.0",
"@typescript-eslint/type-utils": "~6.8.0",
"@typescript-eslint/utils": "~6.8.0",
"babel-jest": "~29.7.0",
"babel-loader": "^9.1.3",
"chalk": "5.3.0",
"chokidar": "^3.5.1",
"commitizen": "^4.0.3",
"chalk": "~5.3.0",
"commitizen": "^4.3.0",
"conventional-changelog-cli": "^4.0.0",
"cz-conventional-changelog": "^3.3.0",
"cz-customizable": "^7.0.0",
"depcheck": "^1.3.1",
"dotenv": "~16.3.0",
"ejs": "^3.1.7",
"enhanced-resolve": "^5.8.3",
"eslint": "8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "2.28.1",
"express": "^4.18.1",
"fast-xml-parser": "^4.0.9",
"file-loader": "^6.2.0",
"file-type": "^16.2.0",
"flat": "^5.0.2",
"fork-ts-checker-webpack-plugin": "8.0.0",
"flat": "^6.0.0",
"fs-extra": "^11.1.0",
"github-contributors-list": "~1.2.3",
"http-server": "14.1.0",
"http-server": "~14.1.0",
"husky": "^8.0.1",
"identity-obj-proxy": "3.0.0",
"ignore": "^5.0.4",
"immer": "^10.0.0",
"import-fresh": "^3.1.0",
"injection-js": "^2.4.0",
"is-ci": "^3.0.0",
"is-windows": "^1.0.2",
"ignore": "^5.2.0",
"jasmine": "~5.1.0",
"jasmine-core": "~5.1.1",
"jasmine-marbles": "~0.9.2",
"jasmine-spec-reporter": "~7.0.0",
"jest": "~29.6.0",
"jest-environment-jsdom": "~29.6.0",
"js-yaml": "4.1.0",
"jest": "~29.7.0",
"jest-environment-jsdom": "~29.7.0",
"jsonc-eslint-parser": "^2.1.0",
"jsonc-parser": "3.2.0",
"kill-port": "^2.0.1",
"lint-staged": "^14.0.0",
"loader-utils": "3.2.1",
"lockfile-lint": "^4.7.6",
"magic-string": "~0.30.0",
"memfs": "^4.2.1",
"mini-css-extract-plugin": "~2.7.6",
"minimatch": "~9.0.0",
"lint-staged": "^15.0.0",
"ng-packagr": "~16.2.0",
"node-fetch": "^3.3.2",
"nx": "16.7.4",
"nx": "17.0.1",
"open": "^9.1.0",
"parse-markdown-links": "^1.0.4",
"parse5": "~7.1.2",
Expand All @@ -142,43 +112,19 @@
"postcss-url": "~10.1.3",
"prettier": "^2.6.2",
"prettier-plugin-tailwindcss": "^0.5.4",
"pretty-quick": "^3.1.0",
"raw-loader": "^4.0.2",
"regenerator-runtime": "0.14.0",
"rxjs": "~7.8.0",
"rxjs-for-await": "~1.0.0",
"sass": "^1.55.0",
"sass-loader": "^13.3.0",
"semver": "~7.5.4",
"source-map": "0.7.4",
"source-map-loader": "^4.0.0",
"source-map-support": "~0.5.21",
"style-loader": "^3.3.0",
"styled-components": "~6.0.0",
"stylus": "^0.60.0",
"stylus-loader": "^7.1.3",
"tar-fs": "^3.0.0",
"tar-stream": "~3.1.0",
"tcp-port-used": "^1.0.2",
"tmp": "~0.2.1",
"tree-kill": "1.2.2",
"ts-jest": "29.1.1",
"ts-loader": "^9.4.4",
"ts-loader": "^9.5.0",
"ts-node": "10.9.1",
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-webpack-plugin": "~4.1.0",
"tslint-to-eslint-config": "^2.14.0",
"typedoc": "0.25.0",
"typedoc-plugin-markdown": "3.16.0",
"typedoc": "~0.25.0",
"typedoc-plugin-markdown": "~3.16.0",
"typescript": "~5.1.6",
"url-loader": "^4.1.1",
"verdaccio": "^5.0.4",
"webpack": "^5.58.1",
"webpack-dev-server": "^4.9.3",
"webpack-merge": "^5.8.0",
"webpack-node-externals": "^3.0.0",
"webpack-sources": "^3.2.3",
"xml2js": "^0.4.23",
"xml2js": "^0.6.2",
"yargs": "^17.4.0",
"yargs-parser": "~21.1.0"
},
Expand Down
7 changes: 1 addition & 6 deletions packages/angular/collection.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nstudio/angular",
"version": "0.1",
"extends": ["@nx/angular", "@nstudio/xplat"],
"extends": ["@nstudio/xplat"],
"schematics": {
"ng-add": {
"factory": "./src/schematics/ng-add/ng-add",
Expand Down Expand Up @@ -49,11 +49,6 @@
"schema": "./src/schematics/ngrx/schema.json",
"description": "Create a ngrx store."
},
"elements": {
"factory": "./src/schematics/elements",
"schema": "./src/schematics/elements/schema.json",
"description": "Create custom elements for the web with Angular."
},
"helpers": {
"factory": "./src/schematics/helpers",
"schema": "./src/schematics/helpers/schema.json",
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": {
"@nx/angular": "^16.0.0"
"@nx/angular": "^17.0.0"
},
"peerDependencies": {
"@nstudio/xplat": "*"
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/src/schematics/application/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Tree } from '@angular-devkit/schematics';
import { Schema } from './schema';
import { getRootTsConfigPath, jsonParse } from '@nstudio/xplat-utils';
import { createEmptyWorkspace, getFileContent } from '@nstudio/xplat/testing';
import { createEmptyWorkspace } from '@nstudio/xplat/testing';
import { runSchematic } from '../../utils/testing';

describe('app', () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('app', () => {
expect(tree.exists('/libs/xplat/web/scss/src/package.json')).toBeTruthy();

// let checkPath = 'angular.json'
// let checkFile = getFileContent(tree, checkPath);
// let checkFile = tree.readContent(checkPath)
// console.log(checkPath, checkFile)
});

Expand All @@ -59,7 +59,7 @@ describe('app', () => {
0
);
let checkPath = getRootTsConfigPath();
let checkFile = getFileContent(tree, checkPath);
let checkFile = tree.readContent(checkPath)
// console.log('tsconfig.base:', checkFile);
expect(files.indexOf(checkPath)).toBeGreaterThanOrEqual(0);
expect(files.indexOf('/tsconfig.base.json')).toBeGreaterThanOrEqual(0);
Expand Down
83 changes: 9 additions & 74 deletions packages/angular/src/schematics/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import {
noop,
ExecutionOptions,
} from '@angular-devkit/schematics';
import { formatFiles, updateWorkspace, getWorkspace } from '@nx/workspace';
import { convertNxGenerator } from '@nx/devkit';
import { applicationGenerator } from '@nx/angular/generators';
import {
stringUtils,
updatePackageScripts,
missingArgument,
getDefaultTemplateOptions,
XplatHelpers,
convertNgTreeToDevKit,
} from '@nstudio/xplat';
import {
prerun,
Expand Down Expand Up @@ -82,21 +84,13 @@ export default function (options: Schema) {
// ensure ends up in apps directory
nrwlWebOptions.directory = `apps/${options.directory}`;
}
let executionOptions: Partial<ExecutionOptions>;
if (options.useXplat) {
// when generating xplat architecture, ensure:
// 1. sass is used
nrwlWebOptions.style = 'scss';
// executionOptions = {
// interactive: false
// };
}
return externalSchematic(
'@nx/angular',
'app',
nrwlWebOptions,
executionOptions
)(tree, context);
// NOTE: This is what this needs to be:
return convertNxGenerator(applicationGenerator)(nrwlWebOptions as any)
},
(tree: Tree, context: SchematicContext) =>
addHeadlessE2e(options)(tree, context),
Expand All @@ -110,61 +104,18 @@ export default function (options: Schema) {
: noop(),
// adjust app files
options.useXplat
? (tree: Tree, context: SchematicContext) => adjustAppFiles(options, tree)
? (tree: Tree, context: SchematicContext) => adjustAppFiles(options, tree, context)
: noop(),
<any>formatFiles({ skipFormat: options.skipFormat }),
]);
}

/**
* Add a Protractor config with headless Chrome and create a
* target configuration to use the config created.
*
* @param options
*/
function addProtractorCiConfig(options: Schema) {
return (tree: Tree, context: SchematicContext) => {
const config = `
const defaultConfig = require('./protractor.conf').config;
defaultConfig.capabilities.chromeOptions = {
args: ['--headless']
};
exports.config = defaultConfig;
`;
const directory = options.directory ? `${options.directory}/` : '';
const e2eProjectName = `${options.name}-e2e`;
const confFile = 'protractor.headless.js';
tree.create(`/apps/${directory}${e2eProjectName}/${confFile}`, config);

return updateWorkspace((workspace) => {
if (workspace.projects.has(e2eProjectName)) {
const projectDef = workspace.projects.get(e2eProjectName);
const e2eDef = projectDef.targets.get('e2e');
if (e2eDef) {
e2eDef.configurations.ci = {
protractorConfig: `apps/${directory}${e2eProjectName}/${confFile}`,
};
projectDef.targets.set('e2e', e2eDef);
}
}
});
};
}

/**
* Add headless options to e2e tests
* @param options
*/
function addHeadlessE2e(options: Schema): Rule {
const framework: 'protractor' | 'cypress' | 'none' = options.e2eTestRunner;
switch (framework) {
case 'protractor':
return <any>addProtractorCiConfig(options);

default:
return noop();
}
return noop();
}

function addAppFiles(options: Schema, extra: string = ''): Rule {
Expand All @@ -184,7 +135,7 @@ function addAppFiles(options: Schema, extra: string = ''): Rule {
);
}

async function adjustAppFiles(options: Schema, tree: Tree): Promise<Rule> {
async function adjustAppFiles(options: Schema, tree: Tree, context: SchematicContext): Promise<Rule> {
const directory = options.directory ? `${options.directory}/` : '';
tree.overwrite(
`/apps/${directory}${options.name}/src/index.html`,
Expand Down Expand Up @@ -223,24 +174,8 @@ async function adjustAppFiles(options: Schema, tree: Tree): Promise<Rule> {
`/apps/${directory}${options.name}/src/app/app.module.ts`,
appModuleContent(options)
);
// update cli config for shared web specific scss

const workspace = await getWorkspace(tree);
const project = workspace.projects.get(options.name);
if (project && project.targets) {
const buildOptions = project.targets.get('build').options;
if (buildOptions) {
project.targets.get('build').options.styles = [
`libs/xplat/${XplatHelpers.getXplatFoldername(
'web',
'angular'
)}/scss/src/_index.scss`,
`apps/${directory}${options.name}/src/styles.scss`,
];
}
}

return updateWorkspace(workspace);
return noop();
}

function indexContent(name: string) {
Expand Down
2 changes: 0 additions & 2 deletions packages/angular/src/schematics/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
ITargetPlatforms,
PlatformTypes,
} from '@nstudio/xplat-utils';
import { formatFiles } from '@nx/workspace';
import { addToFeature, adjustBarrelIndex } from '@nstudio/angular';
import { ComponentHelpers } from '../../utils/xplat';

Expand Down Expand Up @@ -132,6 +131,5 @@ export default function (options: XplatComponentHelpers.Schema) {

// add platform chains
(tree: Tree, context: SchematicContext) => chain(externalChains),
formatFiles({ skipFormat: options.skipFormat }),
]);
}
Loading

0 comments on commit 540c755

Please sign in to comment.