We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We are trying to run a local Angular Schematic in an Nx monorepo, but Angular's schematic context is being ignored when we attempt to use it.
context
/*********************************************** packages/automation/src/generators/ng-schematics/generator.ts ***********************************************/ import { Rule } from '@angular-devkit/schematics' import { Tree as NxTree } from '@nx/devkit' import { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter' import { Schema } from 'nx/src/utils/params' export async function ngSchematicsGenerator(nxTree: NxTree, options: Schema): Promise<Rule> { return await myTestNgSchematic(nxTree, options); } export const myTestNgSchematic = wrapAngularDevkitSchematic( 'packages/libs/mylib/collections.json', 'my-test', );
/*********************************************** packages/libs/mylib/schematics/my-test/index.ts ***********************************************/ import { SchematicContext, Tree, chain } from '@angular-devkit/schematics' import { installDependencies } from './install-dependencies' import { updateTsconfigJson } from './update-tsconfig-json' export function myTest(): Rule { return (tree: Tree, context: SchematicContext): Rule => { return chain([ // Install dependencies by triggering NPM install task. installDependencies(), ])(tree, context) as Rule; }; }
/*********************************************** packages/libs/mylib/schematics/my-test/install-dependencies.ts ***********************************************/ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' export function installDependencies(): Rule { return (tree: Tree, context: SchematicContext): Tree => { console.log('plain js log'); console.log(context.logger.info); context.addTask(new NodePackageInstallTask()); // ignored context.logger.info('✅️ Installing dependencies'); // ignored return tree; }; }
my-project git: ✗ npx nx g automation:ng-schematics > NX Generating automation:ng-schematics plain js log [Function: info]
Both the context.addTask() and context.logger.info are ignored.
context.addTask()
context.logger.info
We expect the context.logger to log a message, and the context.addTask() to install dependencies.
context.logger
No response
wrapAngularDevkitSchematic
export async function ngSchematicsGenerator(nxTree: NxTree, options: Schema): Promise<Rule> { return await myTestNgSchematic(nxTree, options); } export const myTestNgSchematic = wrapAngularDevkitSchematic( 'packages/libs/mylib/collections.json', 'my-test', );
{ "$schema": "../../../../node_modules/@angular-devkit/schematics/collection-schema.json", "schematics": { "my-test": { "description": "My Test schematic for running in Nx", "factory": "./my-test/index#myTest", "schema": "./my-test/schema.json" } } }
export function myTest(): Rule { return (tree: Tree, context: SchematicContext): Rule => { return chain([ installDependencies(), ])(tree, context) as Rule; }; }
export function installDependencies(): Rule { return (tree: Tree, context: SchematicContext): Tree => { console.log('plain js log'); console.log(context.logger.info); context.addTask(new NodePackageInstallTask()); // ignored context.logger.info('✅️ Installing dependencies'); // ignored return tree; }; }
npx nx g automation:ng-schematics
> NX Generating automation:ng-schematics plain js log [Function: info]
NX Report complete - copy this into the issue template Node : 20.4.0 OS : darwin-arm64 npm : 9.7.2 nx : 16.9.1 @nx/js : 16.9.1 @nx/jest : 16.9.1 @nx/linter : 16.9.1 @nx/workspace : 16.9.1 @nx/angular : 16.9.1 @nx/cypress : 16.9.1 @nx/devkit : 16.9.1 @nx/esbuild : 16.9.1 @nx/eslint-plugin : 16.9.1 @nx/plugin : 16.9.1 @nrwl/tao : 16.9.1 @nx/web : 16.9.1 @nx/webpack : 16.9.1 typescript : 5.1.6 --------------------------------------- Community plugins: @jscutlery/semver : 3.4.1 @ngrx/effects : 16.3.0 @ngrx/store : 16.3.0 @ngrx/store-devtools : 16.3.0 ngx-bootstrap : 11.0.2 --------------------------------------- Local workspace plugins: mylib automation
The text was updated successfully, but these errors were encountered:
@FrozenPandaz Has there been any discoveries with this issue?
Sorry, something went wrong.
@leosvelperez If we are on Nx 16.9.1, how can we get this fix? Has it been released yet?
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
leosvelperez
Successfully merging a pull request may close this issue.
Current Behavior
We are trying to run a local Angular Schematic in an Nx monorepo, but Angular's schematic
context
is being ignored when we attempt to use it.Generator file
Angular Schematic Example
An Angular Schematic Rule Example
Terminal Output
my-project git: ✗ npx nx g automation:ng-schematics > NX Generating automation:ng-schematics plain js log [Function: info]
Both the
context.addTask()
andcontext.logger.info
are ignored.Expected Behavior
We expect the
context.logger
to log a message, and thecontext.addTask()
to install dependencies.GitHub Repo
No response
Steps to Reproduce
wrapAngularDevkitSchematic
with a local Angular schematiccontext
context
methods are never called> NX Generating automation:ng-schematics plain js log [Function: info]
Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: