-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
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
Nx Migration fails for a custom migration of a package #15014
Comments
Hey @sonikasharma1403! This sounds like it could be an issue in our compatibility layer, but its hard to tell without some of the information above. Can you run Additionally, a reproduction here would be super helpful. If I were you and wanted to create the repro, I'd take the migrations.json file that was generated and copy it into a new Nx workspace. Copy the built migration files over into that workspace as well under some folder (call it migration or something), and update the path in the migrations.json file to point to it. At this point, strip out as much from the migration itself as you can while still getting the same error. This will help us find where the issue is occurring. |
migrations/test/index.ts import { Rule, Tree } from '@angular-devkit/schematics';
import { updateWorkspace } from '@schematics/angular/utility/workspace';
import { ProjectType } from '@schematics/angular/utility/workspace-models';
export default function (): Rule {
return async (host: Tree) => {
return updateWorkspace(workspace => {
workspace.projects.forEach(project => {
if (project.extensions.projectType === ProjectType.Application) {
project.architect.build.options.assets = [ // add something here]
}
});
});
};
}
migrations.json
...
"migration-v23-test": {
"version": "23.0.0",
"description": "Modify assets",
"factory": "./migrations/test"
}
The above migrations work fine for a non-NX workspace by updating angular.json. But fail to update the project.json in an NX workspace |
@AgentEnder - do let me know if you need more details to reproduce the issue |
@AgentEnder - any update? |
hey @sonikasharma1403! Could you please post the error stack trace you're getting? Make sure you run the migration with |
@sonikasharma1403 there were a couple of issues with our Angular DevKit interoperability layer that you might have encountered when reporting this. Those issues were solved in 15.7.2. Could you try again with the latest version? Also, the migration schematic code you shared here doesn't seem correct. I ran it and I get a valid error: That error is legit, import { Rule, Tree } from '@angular-devkit/schematics';
import { updateWorkspace } from '@schematics/angular/utility/workspace';
import { ProjectType } from '@schematics/angular/utility/workspace-models';
export function foo(): Rule {
return async (host: Tree) => {
return updateWorkspace((workspace) => {
workspace.projects.forEach((project) => {
if (
project.extensions.projectType === ProjectType.Application &&
project.targets.has('build')
) {
project.targets.get('build').options.assets = ['some-asset.css'];
}
});
});
};
} Using latest with the code above runs the migration successfully, but I doesn't make changes to the |
@leosvelperez - Thanks for the quick fix.. |
@leosvelperez - I tried the code you have shared above with the |
@sonikasharma1403 running If you can't wait for the stable |
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. |
Current Behavior
We have written custom schematics for our npm package, which uses
updateWorkspace
provided by@angular/devkit
. This executes fine when we dong update <packageName>
in an application not dependent on NX.Create a new NX application and do
nx migrate <packageName>
. Notice that the migrations.json is updated. But as soon as you try to run the migration. It fails with unable to run migration trying to accessangular.json
(which should not be part of NX).wondering, if we have any docs or recommendation for such a scenario
Expected Behavior
Migrations should work as expected
GitHub Repo
No response
Steps to Reproduce
Mentioned above
Nx Report
Failure Logs
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: