Skip to content

feat(@angular-devkit/build-angular): validate file extensions for scripts and styles options #22613

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 31, 2022
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
18 changes: 4 additions & 14 deletions goldens/public-api/angular_devkit/build_angular/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export interface BrowserBuilderOptions {
preserveSymlinks?: boolean;
progress?: boolean;
resourcesOutputPath?: string;
scripts?: ExtraEntryPoint[];
scripts?: ScriptElement[];
serviceWorker?: boolean;
// @deprecated
showCircularDependencies?: boolean;
sourceMap?: SourceMapUnion;
statsJson?: boolean;
stylePreprocessorOptions?: StylePreprocessorOptions;
styles?: ExtraEntryPoint[];
styles?: StyleElement[];
subresourceIntegrity?: boolean;
tsConfig: string;
vendorChunk?: boolean;
Expand Down Expand Up @@ -155,16 +155,6 @@ export type ExecutionTransformer<T> = (input: T) => T | Promise<T>;
// @public (undocumented)
export type ExtractI18nBuilderOptions = Schema_2 & JsonObject;

// @public (undocumented)
export type ExtraEntryPoint = ExtraEntryPointObject | string;

// @public (undocumented)
export interface ExtraEntryPointObject {
bundleName?: string;
inject?: boolean;
input: string;
}

// @public (undocumented)
export interface FileReplacement {
// (undocumented)
Expand Down Expand Up @@ -193,10 +183,10 @@ export interface KarmaBuilderOptions {
preserveSymlinks?: boolean;
progress?: boolean;
reporters?: string[];
scripts?: ExtraEntryPoint_2[];
scripts?: ScriptElement_2[];
sourceMap?: SourceMapUnion_2;
stylePreprocessorOptions?: StylePreprocessorOptions_2;
styles?: ExtraEntryPoint_2[];
styles?: StyleElement_2[];
tsConfig: string;
watch?: boolean;
webWorkerTsConfig?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,71 @@
"type": "array",
"default": [],
"items": {
"$ref": "#/definitions/extraEntryPoint"
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"pattern": "\\.[cm]?jsx?$"
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"pattern": "\\.[cm]?jsx?$"
}
]
}
},
"styles": {
"description": "Global styles to be included in the build.",
"type": "array",
"default": [],
"items": {
"$ref": "#/definitions/extraEntryPoint"
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"pattern": "\\.(?:css|scss|sass|less|styl)$"
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"pattern": "\\.(?:css|scss|sass|less|styl)$"
}
]
}
},
"inlineStyleLanguage": {
Expand Down Expand Up @@ -437,35 +493,6 @@
}
]
},
"extraEntryPoint": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include."
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include."
}
]
},
"budget": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,71 @@
"type": "array",
"default": [],
"items": {
"$ref": "#/definitions/extraEntryPoint"
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"pattern": "\\.[cm]?jsx?$"
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"pattern": "\\.[cm]?jsx?$"
}
]
}
},
"styles": {
"description": "Global styles to be included in the build.",
"type": "array",
"default": [],
"items": {
"$ref": "#/definitions/extraEntryPoint"
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include.",
"pattern": "\\.(?:css|scss|sass|less|styl)$"
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include.",
"pattern": "\\.(?:css|scss|sass|less|styl)$"
}
]
}
},
"inlineStyleLanguage": {
Expand Down Expand Up @@ -218,35 +274,6 @@
"type": "string"
}
]
},
"extraEntryPoint": {
"oneOf": [
{
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The file to include."
},
"bundleName": {
"type": "string",
"pattern": "^[\\w\\-.]*$",
"description": "The bundle name for this extra entry point."
},
"inject": {
"type": "boolean",
"description": "If the bundle will be referenced in the HTML file.",
"default": true
}
},
"additionalProperties": false,
"required": ["input"]
},
{
"type": "string",
"description": "The file to include."
}
]
}
}
}
2 changes: 0 additions & 2 deletions packages/angular_devkit/build_angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export {
AssetPatternClass as AssetPatternObject,
Budget,
CrossOrigin,
ExtraEntryPoint,
ExtraEntryPointClass as ExtraEntryPointObject,
FileReplacement,
OptimizationClass as OptimizationObject,
OptimizationUnion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
AssetPatternClass,
Budget,
CrossOrigin,
ExtraEntryPoint,
I18NTranslation,
IndexUnion,
InlineStyleLanguage,
Localize,
ScriptElement,
SourceMapClass,
StyleElement,
} from '../builders/browser/schema';
import { Schema as DevServerSchema } from '../builders/dev-server/schema';
import { NormalizedCachedOptions } from './normalize-cache';
Expand Down Expand Up @@ -61,8 +62,8 @@ export interface BuildOptions {
polyfills?: string;
budgets: Budget[];
assets: AssetPatternClass[];
scripts: ExtraEntryPoint[];
styles: ExtraEntryPoint[];
scripts: ScriptElement[];
styles: StyleElement[];
stylePreprocessorOptions?: { includePaths: string[] };
platform?: 'browser' | 'server';
fileReplacements: NormalizedFileReplacement[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
* found in the LICENSE file at https://angular.io/license
*/

import { ExtraEntryPoint } from '../builders/browser/schema';
import { ScriptElement, StyleElement } from '../builders/browser/schema';
import { normalizeExtraEntryPoints } from '../webpack/utils/helpers';

export type EntryPointsType = [name: string, isModule: boolean];

export function generateEntryPoints(options: {
styles: ExtraEntryPoint[];
scripts: ExtraEntryPoint[];
styles: StyleElement[];
scripts: ScriptElement[];
isHMREnabled?: boolean;
}): EntryPointsType[] {
// Add all styles/scripts, except lazy-loaded ones.
const extraEntryPoints = (extraEntryPoints: ExtraEntryPoint[], defaultBundleName: string) => {
const extraEntryPoints = (
extraEntryPoints: (ScriptElement | ScriptElement)[],
defaultBundleName: string,
) => {
const entryPoints = normalizeExtraEntryPoints(extraEntryPoints, defaultBundleName)
.filter((entry) => entry.inject)
.map((entry) => entry.bundleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as fs from 'fs';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as path from 'path';
import { Configuration, RuleSetUseItem } from 'webpack';
import { ExtraEntryPoint } from '../../builders/browser/schema';
import { StyleElement } from '../../builders/browser/schema';
import { SassWorkerImplementation } from '../../sass/sass-service';
import { WebpackConfigOptions } from '../../utils/build-options';
import {
Expand All @@ -27,7 +27,7 @@ import {
} from '../utils/helpers';

function resolveGlobalStyles(
styleEntrypoints: ExtraEntryPoint[],
styleEntrypoints: StyleElement[],
root: string,
preserveSymlinks: boolean,
): { entryPoints: Record<string, string[]>; noInjectNames: string[]; paths: string[] } {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import glob from 'glob';
import * as path from 'path';
import { ScriptTarget } from 'typescript';
import type { Configuration, WebpackOptionsNormalized } from 'webpack';
import {
AssetPatternClass,
ExtraEntryPoint,
ExtraEntryPointClass,
} from '../../builders/browser/schema';
import { AssetPatternClass, ScriptElement, StyleElement } from '../../builders/browser/schema';
import { WebpackConfigOptions } from '../../utils/build-options';
import { VERSION } from '../../utils/package-version';

Expand Down Expand Up @@ -49,10 +45,10 @@ export function getOutputHashFormat(option: string, length = 20): HashFormat {
return hashFormats[option] || hashFormats['none'];
}

export type NormalizedEntryPoint = Required<ExtraEntryPointClass>;
export type NormalizedEntryPoint = Required<Exclude<ScriptElement | StyleElement, string>>;

export function normalizeExtraEntryPoints(
extraEntryPoints: ExtraEntryPoint[],
extraEntryPoints: (ScriptElement | StyleElement)[],
defaultBundleName: string,
): NormalizedEntryPoint[] {
return extraEntryPoints.map((entry) => {
Expand Down Expand Up @@ -160,7 +156,7 @@ export function getCacheSettings(

export function globalScriptsByBundleName(
root: string,
scripts: ExtraEntryPoint[],
scripts: ScriptElement[],
): { bundleName: string; inject: boolean; paths: string[] }[] {
return normalizeExtraEntryPoints(scripts, 'scripts').reduce(
(prev: { bundleName: string; paths: string[]; inject: boolean }[], curr) => {
Expand Down