Skip to content

Commit 06e89c5

Browse files
committed
refactor(@ngtools/webpack): allow paths plugin to update compiler options
This change allows the compiler options used by the TypeScript paths plugin to be updated if the TypeScript configuration file is changed during a rebuild.
1 parent f8fac8f commit 06e89c5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/ngtools/webpack/src/paths-plugin.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export interface TypeScriptPathsPluginOptions extends Pick<CompilerOptions, 'pat
1616
}
1717

1818
export class TypeScriptPathsPlugin {
19-
constructor(private _options: TypeScriptPathsPluginOptions) { }
19+
constructor(private options?: TypeScriptPathsPluginOptions) {}
20+
21+
update(options: TypeScriptPathsPluginOptions): void {
22+
this.options = options;
23+
}
2024

2125
// tslint:disable-next-line:no-any
2226
apply(resolver: any) {
23-
if (!this._options.paths || Object.keys(this._options.paths).length === 0) {
24-
return;
25-
}
26-
2727
const target = resolver.ensureHook('resolve');
2828
const resolveAsync = (request: NormalModuleFactoryRequest, requestContext: {}) => {
2929
return new Promise<NormalModuleFactoryRequest | undefined>((resolve, reject) => {
@@ -46,6 +46,10 @@ export class TypeScriptPathsPlugin {
4646
resolver.getHook('described-resolve').tapPromise(
4747
'TypeScriptPathsPlugin',
4848
async (request: NormalModuleFactoryRequest, resolveContext: {}) => {
49+
if (!this.options) {
50+
throw new Error('TypeScriptPathsPlugin options were not provided.');
51+
}
52+
4953
if (!request || request.typescriptPathMapped) {
5054
return;
5155
}
@@ -70,11 +74,11 @@ export class TypeScriptPathsPlugin {
7074
return;
7175
}
7276

73-
const replacements = findReplacements(originalRequest, this._options.paths || {});
77+
const replacements = findReplacements(originalRequest, this.options.paths || {});
7478
for (const potential of replacements) {
7579
const potentialRequest = {
7680
...request,
77-
request: path.resolve(this._options.baseUrl || '', potential),
81+
request: path.resolve(this.options.baseUrl || '', potential),
7882
typescriptPathMapped: true,
7983
};
8084
const result = await resolveAsync(potentialRequest, resolveContext);

0 commit comments

Comments
 (0)