Skip to content

Commit

Permalink
fix(@angular-devkit/schematics): ensure collections can be resolved v…
Browse files Browse the repository at this point in the history
…ia test runner in pnpm workspaces

Currently when operating within a pnpm workspace and leveraging the
schematic test runner, there are situations where e.g.
`@schematics/angular` cannot be resolved. Consider this pnpm node
modules structure:

```
packages/
  pwa/
    node_modules/@schematics/angular --> .pnpm-store/@schematics/angular/...
    node_modules/@angular-devkit/schematics --> .pnpm-store/@angular-devkit/schematics/...
    index_spec.js // trying to call external schematic `@schematics/angular`
```

This above setup will fail because `@schematics/angular` is attempted to
be resolved from within the devkit schematics code, which doesn't have
access, or a dependency on `@schematics/angular`. We can use the
specified collection of the test runner to determine a good "resolution
lookup site", similiar to how it happens with the real `ng update`
command.
  • Loading branch information
devversion authored and alan-agius4 committed Jan 21, 2025
1 parent ff8192a commit aa6f0d0
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,23 @@ export class UnitTestTree extends DelegateTree {
}

export class SchematicTestRunner {
private _engineHost = new NodeModulesTestEngineHost();
private _engine: SchematicEngine<{}, {}> = new SchematicEngine(this._engineHost);
private _engineHost: NodeModulesTestEngineHost;
private _engine: SchematicEngine<{}, {}>;
private _collection: Collection<{}, {}>;
private _logger: logging.Logger;

constructor(
private _collectionName: string,
collectionPath: string,
) {
this._engineHost = new NodeModulesTestEngineHost([
// Leverage the specified collection path as an additional base for resolving other
// collections by name. This is useful in e.g. pnpm workspaces where `@angular-devkit/schematics`
// doesn't necessarily have access to e.g. `@schematics/angular`.
collectionPath,
]);
this._engine = new SchematicEngine(this._engineHost);

this._engineHost.registerCollection(_collectionName, collectionPath);
this._logger = new logging.Logger('test');

Expand Down

0 comments on commit aa6f0d0

Please sign in to comment.