Skip to content

fix(@ngtools/webpack): changes in non module code are not picked up w… #13977

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 1 commit into from
Mar 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,42 @@ describe('Browser Builder rebuilds', () => {
).toPromise();
await run.stop();
});

it('rebuilds on changes in barrel file dependency', async () => {
host.writeMultipleFiles({
'src/index.ts': `export * from './interface'`,
'src/interface.ts': `export interface Foo { bar: boolean };`,
});
host.appendToFile('src/main.ts', `
import { Foo } from './index';
const x: Foo = { bar: true };
`);

const overrides = { watch: true, aot: false };
let buildNumber = 0;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
debounceTime(1000),
tap((buildEvent) => {
buildNumber += 1;
switch (buildNumber) {
case 1:
expect(buildEvent.success).toBe(true);
host.writeMultipleFiles({
'src/interface.ts': `export interface Foo {
bar: boolean;
baz?: string;
};`,
});
break;

case 2:
expect(buildEvent.success).toBe(true);
break;
}
}),
take(2),
).toPromise();
await run.stop();
});
});
13 changes: 11 additions & 2 deletions packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,18 @@ export class AngularCompilerPlugin {
const host = this._compilerHost;
const cache = this._moduleResolutionCache;

const esImports = collectDeepNodes<ts.ImportDeclaration>(sourceFile,
ts.SyntaxKind.ImportDeclaration)
const esImports = collectDeepNodes<ts.ImportDeclaration | ts.ExportDeclaration>(
sourceFile,
[
ts.SyntaxKind.ImportDeclaration,
ts.SyntaxKind.ExportDeclaration,
],
)
.map(decl => {
if (!decl.moduleSpecifier) {
return null;
}

const moduleName = (decl.moduleSpecifier as ts.StringLiteral).text;
const resolved = ts.resolveModuleName(moduleName, resolvedFileName, options, host, cache);

Expand Down
6 changes: 5 additions & 1 deletion packages/ngtools/webpack/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ export function ngcLoader(this: loader.LoaderContext) {
if (sourceFileName.endsWith('.ts')) {
result.errorDependencies.forEach(dep => this.addDependency(dep));
const dependencies = plugin.getDependencies(sourceFileName);
dependencies.forEach(dep => {
dependencies
.filter(d => d.endsWith('index.ts'))
.forEach(d => dependencies.push(...plugin.getDependencies(d)));

[...new Set(dependencies)].forEach(dep => {
plugin.updateChangedFileExtensions(path.extname(dep));
this.addDependency(dep);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/ngtools/webpack/src/transformers/ast_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import { WebpackCompilerHost } from '../compiler_host';


// Find all nodes from the AST in the subtree of node of SyntaxKind kind.
export function collectDeepNodes<T extends ts.Node>(node: ts.Node, kind: ts.SyntaxKind): T[] {
export function collectDeepNodes<T extends ts.Node>(
node: ts.Node,
kind: ts.SyntaxKind | ts.SyntaxKind[],
): T[] {
const kinds = Array.isArray(kind) ? kind : [kind];
const nodes: T[] = [];
const helper = (child: ts.Node) => {
if (child.kind === kind) {
if (kinds.includes(child.kind)) {
nodes.push(child as T);
}
ts.forEachChild(child, helper);
Expand Down