mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 19:13:34 +08:00
refactor: remove usages of the term whitelist
This commit is contained in:
parent
dd59bfcc60
commit
25aa2d5929
@ -1197,7 +1197,7 @@
|
|||||||
},
|
},
|
||||||
"allowedHosts": {
|
"allowedHosts": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"description": "Whitelist of hosts that are allowed to access the dev server.",
|
"description": "List of hosts that are allowed to access the dev server.",
|
||||||
"default": [],
|
"default": [],
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
},
|
},
|
||||||
"allowedHosts": {
|
"allowedHosts": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"description": "Whitelist of hosts that are allowed to access the dev server.",
|
"description": "List of hosts that are allowed to access the dev server.",
|
||||||
"default": [],
|
"default": [],
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
@ -23,7 +23,7 @@ import { getWrapEnumsTransformer } from '../transforms/wrap-enums';
|
|||||||
|
|
||||||
|
|
||||||
// Angular packages are known to have no side effects.
|
// Angular packages are known to have no side effects.
|
||||||
const whitelistedAngularModules = [
|
const knownSideEffectFreeAngularModules = [
|
||||||
/[\\/]node_modules[\\/]@angular[\\/]animations[\\/]/,
|
/[\\/]node_modules[\\/]@angular[\\/]animations[\\/]/,
|
||||||
/[\\/]node_modules[\\/]@angular[\\/]common[\\/]/,
|
/[\\/]node_modules[\\/]@angular[\\/]common[\\/]/,
|
||||||
/[\\/]node_modules[\\/]@angular[\\/]compiler[\\/]/,
|
/[\\/]node_modules[\\/]@angular[\\/]compiler[\\/]/,
|
||||||
@ -61,7 +61,7 @@ function isKnownCoreFile(filePath: string) {
|
|||||||
|
|
||||||
function isKnownSideEffectFree(filePath: string) {
|
function isKnownSideEffectFree(filePath: string) {
|
||||||
return ngFactories.some((re) => re.test(filePath)) ||
|
return ngFactories.some((re) => re.test(filePath)) ||
|
||||||
whitelistedAngularModules.some((re) => re.test(filePath));
|
knownSideEffectFreeAngularModules.some((re) => re.test(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BuildOptimizerOptions {
|
export interface BuildOptimizerOptions {
|
||||||
@ -117,7 +117,7 @@ export function buildOptimizer(options: BuildOptimizerOptions): TransformJavascr
|
|||||||
getTransforms.push(
|
getTransforms.push(
|
||||||
// getPrefixFunctionsTransformer is rather dangerous, apply only to known pure es5 modules.
|
// getPrefixFunctionsTransformer is rather dangerous, apply only to known pure es5 modules.
|
||||||
// It will mark both `require()` calls and `console.log(stuff)` as pure.
|
// It will mark both `require()` calls and `console.log(stuff)` as pure.
|
||||||
// We only apply it to whitelisted modules, since we know they are safe.
|
// We only apply it to modules known to be side effect free, since we know they are safe.
|
||||||
// getPrefixFunctionsTransformer needs to be before getFoldFileTransformer.
|
// getPrefixFunctionsTransformer needs to be before getFoldFileTransformer.
|
||||||
getPrefixFunctionsTransformer,
|
getPrefixFunctionsTransformer,
|
||||||
selectedGetScrubFileTransformer,
|
selectedGetScrubFileTransformer,
|
||||||
|
@ -254,25 +254,28 @@ describe('build-optimizer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('whitelisted modules', () => {
|
describe('known side effect free modules', () => {
|
||||||
// This statement is considered pure by getPrefixFunctionsTransformer on whitelisted modules.
|
// This statement is considered pure by getPrefixFunctionsTransformer on known side effect free
|
||||||
|
// modules.
|
||||||
const input = 'console.log(42);';
|
const input = 'console.log(42);';
|
||||||
const output = '/*@__PURE__*/ console.log(42);';
|
const output = '/*@__PURE__*/ console.log(42);';
|
||||||
|
|
||||||
it('should process whitelisted modules', () => {
|
it('should process known side effect free modules', () => {
|
||||||
const inputFilePath = '/node_modules/@angular/core/@angular/core.es5.js';
|
const inputFilePath = '/node_modules/@angular/core/@angular/core.es5.js';
|
||||||
const boOutput = buildOptimizer({ content: input, inputFilePath });
|
const boOutput = buildOptimizer({ content: input, inputFilePath });
|
||||||
expect(boOutput.content).toContain(output);
|
expect(boOutput.content).toContain(output);
|
||||||
expect(boOutput.emitSkipped).toEqual(false);
|
expect(boOutput.emitSkipped).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not process non-whitelisted modules', () => {
|
it('should not process modules which are not in the list of known side effect free modules',
|
||||||
|
() => {
|
||||||
const inputFilePath = '/node_modules/other-package/core.es5.js';
|
const inputFilePath = '/node_modules/other-package/core.es5.js';
|
||||||
const boOutput = buildOptimizer({ content: input, inputFilePath });
|
const boOutput = buildOptimizer({ content: input, inputFilePath });
|
||||||
expect(boOutput.emitSkipped).toEqual(true);
|
expect(boOutput.emitSkipped).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not process non-whitelisted umd modules', () => {
|
it('should not process umd modules which are not in the list of known side effect free modules',
|
||||||
|
() => {
|
||||||
const inputFilePath = '/node_modules/other_lib/index.js';
|
const inputFilePath = '/node_modules/other_lib/index.js';
|
||||||
const boOutput = buildOptimizer({ content: input, inputFilePath });
|
const boOutput = buildOptimizer({ content: input, inputFilePath });
|
||||||
expect(boOutput.emitSkipped).toEqual(true);
|
expect(boOutput.emitSkipped).toEqual(true);
|
||||||
|
@ -17,7 +17,8 @@ export * from './noop';
|
|||||||
*
|
*
|
||||||
* These cannot be in their respective schema.json file because we either change the type
|
* These cannot be in their respective schema.json file because we either change the type
|
||||||
* (e.g. --buildEventLog is string, but we want to know the usage of it, not its value), or
|
* (e.g. --buildEventLog is string, but we want to know the usage of it, not its value), or
|
||||||
* some validation needs to be done (we cannot record ng add --collection if it's not whitelisted).
|
* some validation needs to be done (we cannot record ng add --collection if it's not marked as
|
||||||
|
* allowed).
|
||||||
*/
|
*/
|
||||||
export enum NgCliAnalyticsDimensions {
|
export enum NgCliAnalyticsDimensions {
|
||||||
CpuCount = 1,
|
CpuCount = 1,
|
||||||
|
@ -59,7 +59,7 @@ export function angularMajorCompatGuarantee(range: string) {
|
|||||||
|
|
||||||
// This is a map of packageGroupName to range extending function. If it isn't found, the range is
|
// This is a map of packageGroupName to range extending function. If it isn't found, the range is
|
||||||
// kept the same.
|
// kept the same.
|
||||||
const peerCompatibleWhitelist: { [name: string]: PeerVersionTransform } = {
|
const knownPeerCompatibleList: { [name: string]: PeerVersionTransform } = {
|
||||||
'@angular/core': angularMajorCompatGuarantee,
|
'@angular/core': angularMajorCompatGuarantee,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ function _updatePeerVersion(infoMap: Map<string, PackageInfo>, name: string, ran
|
|||||||
name = maybePackageInfo.installed.updateMetadata.packageGroupName || name;
|
name = maybePackageInfo.installed.updateMetadata.packageGroupName || name;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maybeTransform = peerCompatibleWhitelist[name];
|
const maybeTransform = knownPeerCompatibleList[name];
|
||||||
if (maybeTransform) {
|
if (maybeTransform) {
|
||||||
if (typeof maybeTransform == 'function') {
|
if (typeof maybeTransform == 'function') {
|
||||||
return maybeTransform(range);
|
return maybeTransform(range);
|
||||||
@ -172,7 +172,7 @@ function _validateReversePeerDependencies(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override the peer version range if it's whitelisted.
|
// Override the peer version range if it's known as a compatible.
|
||||||
const extendedRange = _updatePeerVersion(infoMap, peer, range);
|
const extendedRange = _updatePeerVersion(infoMap, peer, range);
|
||||||
|
|
||||||
if (!semver.satisfies(version, extendedRange, { includePrerelease: next || undefined })) {
|
if (!semver.satisfies(version, extendedRange, { includePrerelease: next || undefined })) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user