Skip to content

fix(@angular-devkit/build-angular): emit error when a script is not found. #16666

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
Jan 15, 2020
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 @@ -11,6 +11,7 @@ import {
} from '@angular-devkit/build-optimizer';
import { tags } from '@angular-devkit/core';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import { existsSync } from 'fs';
import * as path from 'path';
import { RollupOptions } from 'rollup';
import { ScriptTarget } from 'typescript';
Expand Down Expand Up @@ -214,23 +215,28 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
buildOptions.scripts,
'scripts',
).reduce((prev: { bundleName: string; paths: string[]; inject: boolean }[], curr) => {
const bundleName = curr.bundleName;
const resolvedPath = path.resolve(root, curr.input);
const { bundleName, inject, input } = curr;
const resolvedPath = path.resolve(root, input);

if (!existsSync(resolvedPath)) {
throw new Error(`Script file ${input} does not exist.`);
}

const existingEntry = prev.find(el => el.bundleName === bundleName);
if (existingEntry) {
if (existingEntry.inject && !curr.inject) {
if (existingEntry.inject && !inject) {
// All entries have to be lazy for the bundle to be lazy.
throw new Error(
`The ${curr.bundleName} bundle is mixing injected and non-injected scripts.`,
`The ${bundleName} bundle is mixing injected and non-injected scripts.`,
);
}

existingEntry.paths.push(resolvedPath);
} else {
prev.push({
bundleName,
inject,
paths: [resolvedPath],
inject: curr.inject,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,16 @@ describe('Browser Builder scripts array', () => {
expect(logs.join('\n')).toMatch(/\(renamed-script\) 78 bytes.*\[entry].*\[rendered]/);
expect(logs.join('\n')).toMatch(/\(renamed-lazy-script\) 88 bytes.*\[entry].*\[rendered]/);
});

it(`should error when a script doesn't exist`, async () => {
await expectAsync(browserBuild(
architect,
host,
target,
{
scripts: ['./invalid.js'],
},
))
.toBeRejectedWithError(`Script file ./invalid.js does not exist.`);
});
});