I am currently building my first nx plugin and I am trying to add a target to the project.json and also add a file to the root of the project. I am currently passing the project name as a string to my generator.
export default async function (tree: Tree, options: {project: string}) {
const projectConfiguration = readProjectConfiguration(tree, options.project);
updateProjectConfiguration(tree, options.project, {
...projectConfiguration,
targets: {
...projectConfiguration.targets,
myExecutor: {
executor: '@package/my-executor',
},
},
});
generateFiles(tree, path.join(__dirname, 'files/projectFiles'), projectConfiguration.root, {
...fileReplacementOptions
})
};
When using this generator in an nx project before version 14, updateProjectConfiguration adds the target but removes the root key. When using this generator on a project > 14 projectConfiguration.root is undefined. This makes sense since the root key does not get added anymore when creating a project. What i found is this pull request which seems to confirm that https://github.com/nrwl/nx/pull/9977
Now I am wondering how I can make my plugin compatible to older nx versions and also how to find the root folder of a project. Especially when providing a project name like project-folder-project1-nested which root path would be /libs/project-folder/project1-nested.