Skip to content

Commit

Permalink
fix(angular): resolve generator collections when generating a extende…
Browse files Browse the repository at this point in the history
…d schematic (#19815)
  • Loading branch information
leosvelperez authored Oct 25, 2023
1 parent 0475f6f commit 5552b3b
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,62 @@ export async function scheduleTarget(
);
}

function createNodeModulesEngineHost(
resolvePaths: string[]
): import('@angular-devkit/schematics/tools').NodeModulesEngineHost {
const NodeModulesEngineHost = require('@angular-devkit/schematics/tools')
.NodeModulesEngineHost as typeof import('@angular-devkit/schematics/tools').NodeModulesEngineHost;

class NxNodeModulesEngineHost extends NodeModulesEngineHost {
constructor() {
super(resolvePaths);
}

override _resolveCollectionPath(name: string, requester?: string): string {
let collectionFilePath: string;
const paths = requester
? [dirname(requester), ...(resolvePaths || [])]
: resolvePaths || [];

if (name.endsWith('.json')) {
collectionFilePath = require.resolve(name, { paths });
} else {
const {
json: { generators, schematics },
path: packageJsonPath,
} = readPluginPackageJson(name, paths);

if (!schematics && !generators) {
throw new Error(
`The "${name}" package does not support Nx generators or Angular Devkit schematics.`
);
}

collectionFilePath = require.resolve(
join(dirname(packageJsonPath), schematics ?? generators)
);
}

return collectionFilePath;
}

override _transformCollectionDescription(name: string, desc: any) {
desc.schematics ??= desc.generators;

return super._transformCollectionDescription(name, desc);
}
}

return new NxNodeModulesEngineHost();
}

function createWorkflow(
fsHost: virtualFs.Host<Stats>,
root: string,
opts: any
): import('@angular-devkit/schematics/tools').NodeWorkflow {
const NodeWorkflow = require('@angular-devkit/schematics/tools').NodeWorkflow;
const NodeWorkflow: typeof import('@angular-devkit/schematics/tools').NodeWorkflow =
require('@angular-devkit/schematics/tools').NodeWorkflow;
const workflow = new NodeWorkflow(fsHost, {
force: false,
dryRun: opts.dryRun,
Expand All @@ -218,6 +268,8 @@ function createWorkflow(
require('@angular-devkit/schematics').formats.standardFormats
),
resolvePaths: [process.cwd(), root],
engineHostCreator: (options) =>
createNodeModulesEngineHost(options.resolvePaths),
});
workflow.registry.addPostTransform(schema.transforms.addUndefinedDefaults);
workflow.engineHost.registerOptionsTransform(
Expand Down

1 comment on commit 5552b3b

@vercel
Copy link

@vercel vercel bot commented on 5552b3b Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.