Skip to content

Commit 2298ab8

Browse files
committed
refactor(@angular-devkit/build-angular): remove deprecated browser build option rebaseRootRelativeCssUrls
BREAKING CHANGE: Deprecated `rebaseRootRelativeCssUrls` browser builder option has been removed without replacement. This option was used to change root relative URLs in stylesheets to include base HREF and deploy URL and was used only for compatibility and transition as this behavior is non-standard.
1 parent 46ef4cf commit 2298ab8

File tree

6 files changed

+2
-150
lines changed

6 files changed

+2
-150
lines changed

packages/angular/cli/lib/config/schema.json

-6
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,6 @@
970970
},
971971
"default": []
972972
},
973-
"rebaseRootRelativeCssUrls": {
974-
"description": "Change root relative URLs in stylesheets to include base HREF and deploy URL. Use only for compatibility and transition. The behavior of this option is non-standard and will be removed in the next major release.",
975-
"type": "boolean",
976-
"default": false,
977-
"x-deprecated": true
978-
},
979973
"webWorkerTsConfig": {
980974
"type": "string",
981975
"description": "TypeScript configuration for Web Worker modules."

packages/angular_devkit/build_angular/src/browser/schema.json

-6
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,6 @@
348348
},
349349
"default": []
350350
},
351-
"rebaseRootRelativeCssUrls": {
352-
"description": "Change root relative URLs in stylesheets to include base HREF and deploy URL. Use only for compatibility and transition. The behavior of this option is non-standard and will be removed in the next major release.",
353-
"type": "boolean",
354-
"default": false,
355-
"x-deprecated": true
356-
},
357351
"webWorkerTsConfig": {
358352
"type": "string",
359353
"description": "TypeScript configuration for Web Worker modules."

packages/angular_devkit/build_angular/src/browser/specs/styles_spec.ts

+1-113
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ describe('Browser Builder styles', () => {
354354
});
355355

356356
// TODO: consider making this a unit test in the url processing plugins.
357-
it(`supports baseHref/deployUrl in resource urls without rebaseRootRelativeCssUrls`, async () => {
357+
it(`supports baseHref/deployUrl in resource urls`, async () => {
358358
// Use a large image for the relative ref so it cannot be inlined.
359359
host.copyFile('src/spectrum.png', './src/assets/global-img-relative.png');
360360
host.copyFile('src/spectrum.png', './src/assets/component-img-relative.png');
@@ -458,118 +458,6 @@ describe('Browser Builder styles', () => {
458458
expect(main).toContain(`url('/assets/component-img-absolute.svg')`);
459459
}, 90000);
460460

461-
it(`supports baseHref/deployUrl in resource urls with rebaseRootRelativeCssUrls`, async () => {
462-
// Use a large image for the relative ref so it cannot be inlined.
463-
host.copyFile('src/spectrum.png', './src/assets/global-img-relative.png');
464-
host.copyFile('src/spectrum.png', './src/assets/component-img-relative.png');
465-
host.writeMultipleFiles({
466-
'src/styles.css': `
467-
h1 { background: url('/assets/global-img-absolute.svg'); }
468-
h2 { background: url('./assets/global-img-relative.png'); }
469-
`,
470-
'src/app/app.component.css': `
471-
h3 { background: url('/assets/component-img-absolute.svg'); }
472-
h4 { background: url('../assets/component-img-relative.png'); }
473-
`,
474-
'src/assets/global-img-absolute.svg': imgSvg,
475-
'src/assets/component-img-absolute.svg': imgSvg,
476-
});
477-
478-
// Check base paths are correctly generated.
479-
const overrides = {
480-
extractCss: true,
481-
rebaseRootRelativeCssUrls: true,
482-
};
483-
let { files } = await browserBuild(architect, host, target, {
484-
...overrides,
485-
aot: true,
486-
});
487-
488-
let styles = await files['styles.css'];
489-
let main = await files['main.js'];
490-
expect(styles).toContain(`url('/assets/global-img-absolute.svg')`);
491-
expect(styles).toContain(`url('global-img-relative.png')`);
492-
expect(main).toContain(`url('/assets/component-img-absolute.svg')`);
493-
expect(main).toContain(`url('component-img-relative.png')`);
494-
expect(host.scopedSync().exists(normalize('dist/assets/global-img-absolute.svg'))).toBe(true);
495-
expect(host.scopedSync().exists(normalize('dist/global-img-relative.png'))).toBe(true);
496-
expect(host.scopedSync().exists(normalize('dist/assets/component-img-absolute.svg'))).toBe(
497-
true,
498-
);
499-
expect(host.scopedSync().exists(normalize('dist/component-img-relative.png'))).toBe(true);
500-
501-
// Check urls with deploy-url scheme are used as is.
502-
files = (await browserBuild(architect, host, target, {
503-
...overrides,
504-
baseHref: '/base/',
505-
deployUrl: 'http://deploy.url/',
506-
})).files;
507-
508-
styles = await files['styles.css'];
509-
main = await files['main.js'];
510-
expect(styles).toContain(`url('http://deploy.url/assets/global-img-absolute.svg')`);
511-
expect(main).toContain(`url('http://deploy.url/assets/component-img-absolute.svg')`);
512-
513-
// Check urls with base-href scheme are used as is (with deploy-url).
514-
files = (await browserBuild(architect, host, target, {
515-
...overrides,
516-
baseHref: 'http://base.url/',
517-
deployUrl: 'deploy/',
518-
})).files;
519-
520-
styles = await files['styles.css'];
521-
main = await files['main.js'];
522-
expect(styles).toContain(`url('http://base.url/deploy/assets/global-img-absolute.svg')`);
523-
expect(main).toContain(`url('http://base.url/deploy/assets/component-img-absolute.svg')`);
524-
525-
// Check urls with deploy-url and base-href scheme only use deploy-url.
526-
files = (await browserBuild(architect, host, target, {
527-
...overrides,
528-
baseHref: 'http://base.url/',
529-
deployUrl: 'http://deploy.url/',
530-
})).files;
531-
532-
styles = await files['styles.css'];
533-
main = await files['main.js'];
534-
expect(styles).toContain(`url('http://deploy.url/assets/global-img-absolute.svg')`);
535-
expect(main).toContain(`url('http://deploy.url/assets/component-img-absolute.svg')`);
536-
537-
// Check with schemeless base-href and deploy-url flags.
538-
files = (await browserBuild(architect, host, target, {
539-
...overrides,
540-
baseHref: '/base/',
541-
deployUrl: 'deploy/',
542-
})).files;
543-
544-
styles = await files['styles.css'];
545-
main = await files['main.js'];
546-
expect(styles).toContain(`url('/base/deploy/assets/global-img-absolute.svg')`);
547-
expect(main).toContain(`url('/base/deploy/assets/component-img-absolute.svg')`);
548-
549-
// Check with identical base-href and deploy-url flags.
550-
files = (await browserBuild(architect, host, target, {
551-
...overrides,
552-
baseHref: '/base/',
553-
deployUrl: '/base/',
554-
})).files;
555-
556-
styles = await files['styles.css'];
557-
main = await files['main.js'];
558-
expect(styles).toContain(`url('/base/assets/global-img-absolute.svg')`);
559-
expect(main).toContain(`url('/base/assets/component-img-absolute.svg')`);
560-
561-
// Check with only base-href flag.
562-
files = (await browserBuild(architect, host, target, {
563-
...overrides,
564-
baseHref: '/base/',
565-
})).files;
566-
567-
styles = await files['styles.css'];
568-
main = await files['main.js'];
569-
expect(styles).toContain(`url('/base/assets/global-img-absolute.svg')`);
570-
expect(main).toContain(`url('/base/assets/component-img-absolute.svg')`);
571-
}, 90000);
572-
573461
it(`supports bootstrap@4 with full path`, async () => {
574462
const bootstrapPath = dirname(require.resolve('bootstrap/package.json'));
575463

packages/angular_devkit/build_angular/src/utils/build-options.ts

-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ export interface BuildOptions {
7575
lazyModules: string[];
7676
platform?: 'browser' | 'server';
7777
fileReplacements: NormalizedFileReplacement[];
78-
/** @deprecated use only for compatibility in 8.x; will be removed in 9.0 */
79-
rebaseRootRelativeCssUrls?: boolean;
8078

8179
experimentalRollupPass?: boolean;
8280
allowedCommonJsDependencies?: string[];

packages/angular_devkit/build_angular/src/webpack/configs/styles.ts

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
184184
deployUrl: buildOptions.deployUrl,
185185
resourcesOutputPath: buildOptions.resourcesOutputPath,
186186
loader,
187-
rebaseRootRelative: buildOptions.rebaseRootRelativeCssUrls,
188187
filename: `[name]${hashFormat.file}.[ext]`,
189188
emitFile: buildOptions.platform !== 'server',
190189
extracted,

packages/angular_devkit/build_angular/src/webpack/plugins/postcss-cli-resources.ts

+1-22
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,19 @@ export default postcss.plugin('postcss-cli-resources', (options: PostcssCliResou
5757
deployUrl = '',
5858
baseHref = '',
5959
resourcesOutputPath = '',
60-
rebaseRootRelative = false,
6160
filename,
6261
loader,
6362
emitFile,
6463
extracted,
6564
} = options;
6665

67-
const dedupeSlashes = (url: string) => url.replace(/\/\/+/g, '/');
68-
6966
const process = async (inputUrl: string, context: string, resourceCache: Map<string, string>) => {
7067
// If root-relative, absolute or protocol relative url, leave as is
7168
if (/^((?:\w+:)?\/\/|data:|chrome:|#)/.test(inputUrl)) {
7269
return inputUrl;
7370
}
7471

75-
if (!rebaseRootRelative && /^\//.test(inputUrl)) {
72+
if (/^\//.test(inputUrl)) {
7673
return inputUrl;
7774
}
7875

@@ -88,24 +85,6 @@ export default postcss.plugin('postcss-cli-resources', (options: PostcssCliResou
8885
return cachedUrl;
8986
}
9087

91-
if (rebaseRootRelative && inputUrl.startsWith('/')) {
92-
let outputUrl = '';
93-
if (deployUrl.match(/:\/\//) || deployUrl.startsWith('/')) {
94-
// If deployUrl is absolute or root relative, ignore baseHref & use deployUrl as is.
95-
outputUrl = `${deployUrl.replace(/\/$/, '')}${inputUrl}`;
96-
} else if (baseHref.match(/:\/\//)) {
97-
// If baseHref contains a scheme, include it as is.
98-
outputUrl = baseHref.replace(/\/$/, '') + dedupeSlashes(`/${deployUrl}/${inputUrl}`);
99-
} else {
100-
// Join together base-href, deploy-url and the original URL.
101-
outputUrl = dedupeSlashes(`/${baseHref}/${deployUrl}/${inputUrl}`);
102-
}
103-
104-
resourceCache.set(cacheKey, outputUrl);
105-
106-
return outputUrl;
107-
}
108-
10988
if (inputUrl.startsWith('~')) {
11089
inputUrl = inputUrl.substr(1);
11190
}

0 commit comments

Comments
 (0)