NX workspace-generator exception when using directory property

Viewed 228

I created an NX workspace-generator to create Angular libraries with custom settings.

All works fine and I can generate the library using the libraryGenerator() method.

However, if I pass the --directory parameter, I get the following exception:

Cannot find configuration for 'myLib' in /workspace.json.

The terminal process "/bin/zsh '-c', 
'npx nx workspace-generator ng-library myLib --teamName=myTeam --directory=parentDir --dry-run'" 
terminated with exit code: 1.

Any idea why passing the directory property triggers such an error? I could move the library into the parentDir, but I would like to avoid it since specifying a directory inside the given libraryGenerator() method seems to be the legit way. I use "@nrwl/angular": "13.1.5" and I cannot (for the moment) update to a newer version.

My index.ts file:

import {
    Tree,
    formatFiles,
    installPackagesTask,
    readProjectConfiguration,
    generateFiles,
    joinPathFragments,
    updateProjectConfiguration,
    getProjects,
    ProjectConfiguration
} from '@nrwl/devkit';
import { libraryGenerator } from '@nrwl/angular/generators';
import { LibSchemaModel } from './lib-schema.model';

export default async function (tree: Tree, schema: LibSchemaModel) {
    const libraryName = schema.name;

    await libraryGenerator(tree, {
        name: libraryName,
        importPath: `@${schema.importPathPrefix}/${libraryName}`,
        publishable: schema.libraryType === 'publishable',
        buildable: schema.libraryType === 'buildable',

        directory: schema.directory // <- If I comment this line, all works fine
    });

...

}

My generator schema.json:

{
    "$schema": "http://json-schema.org/schema",
    "cli": "nx",
    "$id": "ng-library",
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "The name of the library.",
            "x-prompt": "Which name do you want to use for the library?",
            "$default": {
                "$source": "argv",
                "index": 0
            }
        },
        "teamName": {
            "type": "string",
            "description": "The team name.",
            "x-prompt": "Which is the library's team name?"
        },
        "importPathPrefix": {
            "type": "string",
            "description": "The prefix used for the library importPath."
        },
        "directory": {
            "type": "string",
            "description": "The directory that will contain the new library."
        },
        "libraryType": {
            "description": "Library type: `Publishable` to publish it outside the workspace or `Buildable` to use it internally in the workspace.",
            "type": "string",
            "default": "publishable",
            "enum": [
                "publishable",
                "buildable"
            ],
            "x-prompt": {
                "message": "Which library type do you want to generate?",
                "type": "list",
                "items": [
                    {
                        "value": "publishable",
                        "label": "Publishable"
                    },
                    {
                        "value": "buildable",
                        "label": "Buildable"
                    }
                ]
            }
        },
        "installDeps": {
            "type": "boolean",
            "description": "Install dependencies",
            "default": true
        }
    },
    "required": ["name", "teamName", "teamEmail"]
}
0 Answers
Related