Skip to content

refactor(@angular-devkit/architect): use standard node resolution methods where possible #15622

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

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion etc/api/angular_devkit/core/node/_golden-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export declare class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
}

export declare class NodeModuleJobRegistry<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> implements core_experimental.jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT> {
constructor(_resolveLocal?: boolean, _resolveGlobal?: boolean);
protected _resolve(name: string): string | null;
get<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(name: core_experimental.jobs.JobName): Observable<core_experimental.jobs.JobHandler<A, I, O> | null>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import { experimental, json, workspaces } from '@angular-devkit/core';
import { resolve } from '@angular-devkit/core/node';
import * as path from 'path';
import { BuilderInfo } from '../src';
import { Schema as BuilderSchema } from '../src/builders-schema';
Expand Down Expand Up @@ -56,11 +55,8 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModu
throw new Error('No builder name specified.');
}

const packageJsonPath = resolve(packageName, {
basedir: this._root,
checkLocal: true,
checkGlobal: true,
resolvePackageJson: true,
const packageJsonPath = require.resolve(packageName + '/package.json', {
paths: [this._root],
});

const packageJson = require(packageJsonPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,19 @@
*/
import { Observable, of } from 'rxjs';
import { JsonValue, experimental as core_experimental, schema } from '../../../src';
import { ModuleNotFoundException, resolve } from '../../resolve';

export class NodeModuleJobRegistry<MinimumArgumentValueT extends JsonValue = JsonValue,
MinimumInputValueT extends JsonValue = JsonValue,
MinimumOutputValueT extends JsonValue = JsonValue,
> implements core_experimental.jobs.Registry<MinimumArgumentValueT,
MinimumInputValueT,
MinimumOutputValueT> {
public constructor(private _resolveLocal = true, private _resolveGlobal = false) {
}

protected _resolve(name: string): string | null {
try {
return resolve(name, {
checkLocal: this._resolveLocal,
checkGlobal: this._resolveGlobal,
basedir: __dirname,
});
return require.resolve(name);
} catch (e) {
if (e instanceof ModuleNotFoundException) {
if (e.code === 'MODULE_NOT_FOUND') {
return null;
}
throw e;
Expand Down