Skip to content

Commit 1bf976f

Browse files
clydinalan-agius4
authored andcommitted
fix(@schematics/angular): set inlineStyleLanguage when application style option is used
The `style` option for the application schematic specifies the language/preprocessor to use for the application's external style files and should also setup the default for inline styles as well via the `inlineStyleLanguage` build option. The value can be adjusted after application generation if needed. (cherry picked from commit fdf41b2)
1 parent 88bea1a commit 1bf976f

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

packages/schematics/angular/application/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
140140
];
141141
}
142142

143+
const inlineStyleLanguage =
144+
options.style && options.style !== Style.Css && options.style !== Style.Styl
145+
? options.style
146+
: undefined;
147+
143148
const project = {
144149
root: normalize(projectRoot),
145150
sourceRoot,
@@ -157,6 +162,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
157162
polyfills: `${sourceRoot}/polyfills.ts`,
158163
tsConfig: `${projectRoot}tsconfig.app.json`,
159164
aot: true,
165+
inlineStyleLanguage,
160166
assets: [
161167
`${sourceRoot}/favicon.ico`,
162168
`${sourceRoot}/assets`,
@@ -212,6 +218,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, appDir: string): Rul
212218
polyfills: `${sourceRoot}/polyfills.ts`,
213219
tsConfig: `${projectRoot}tsconfig.spec.json`,
214220
karmaConfig: `${projectRoot}karma.conf.js`,
221+
inlineStyleLanguage,
215222
assets: [
216223
`${sourceRoot}/favicon.ico`,
217224
`${sourceRoot}/assets`,

packages/schematics/angular/application/index_spec.ts

+60
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,66 @@ describe('Application Schematic', () => {
399399
expect(tree.exists('src/styles.sass')).toBe(true);
400400
});
401401

402+
it('sets "inlineStyleLanguage" in angular.json when using a style preprocessor', async () => {
403+
const options = { ...defaultOptions, projectRoot: '', style: Style.Sass };
404+
const tree = await schematicRunner
405+
.runSchematicAsync('application', options, workspaceTree)
406+
.toPromise();
407+
const config = JSON.parse(tree.readContent('/angular.json'));
408+
const prj = config.projects.foo;
409+
410+
const buildOpt = prj.architect.build.options;
411+
expect(buildOpt.inlineStyleLanguage).toBe('sass');
412+
413+
const testOpt = prj.architect.test.options;
414+
expect(testOpt.inlineStyleLanguage).toBe('sass');
415+
});
416+
417+
it('does not set "inlineStyleLanguage" in angular.json when not using a style preprocessor', async () => {
418+
const options = { ...defaultOptions, projectRoot: ''};
419+
const tree = await schematicRunner
420+
.runSchematicAsync('application', options, workspaceTree)
421+
.toPromise();
422+
const config = JSON.parse(tree.readContent('/angular.json'));
423+
const prj = config.projects.foo;
424+
425+
const buildOpt = prj.architect.build.options;
426+
expect(buildOpt.inlineStyleLanguage).toBeUndefined();
427+
428+
const testOpt = prj.architect.test.options;
429+
expect(testOpt.inlineStyleLanguage).toBeUndefined();
430+
});
431+
432+
it('does not set "inlineStyleLanguage" in angular.json when using CSS styles', async () => {
433+
const options = { ...defaultOptions, projectRoot: '', style: Style.Css };
434+
const tree = await schematicRunner
435+
.runSchematicAsync('application', options, workspaceTree)
436+
.toPromise();
437+
const config = JSON.parse(tree.readContent('/angular.json'));
438+
const prj = config.projects.foo;
439+
440+
const buildOpt = prj.architect.build.options;
441+
expect(buildOpt.inlineStyleLanguage).toBeUndefined();
442+
443+
const testOpt = prj.architect.test.options;
444+
expect(testOpt.inlineStyleLanguage).toBeUndefined();
445+
});
446+
447+
it('does not set "inlineStyleLanguage" in angular.json when using Stylus styles', async () => {
448+
const options = { ...defaultOptions, projectRoot: '', style: Style.Styl };
449+
const tree = await schematicRunner
450+
.runSchematicAsync('application', options, workspaceTree)
451+
.toPromise();
452+
const config = JSON.parse(tree.readContent('/angular.json'));
453+
const prj = config.projects.foo;
454+
455+
const buildOpt = prj.architect.build.options;
456+
expect(buildOpt.inlineStyleLanguage).toBeUndefined();
457+
458+
const testOpt = prj.architect.test.options;
459+
expect(testOpt.inlineStyleLanguage).toBeUndefined();
460+
});
461+
402462
it('should set the relative tsconfig paths', async () => {
403463
const options = { ...defaultOptions, projectRoot: '' };
404464
const tree = await schematicRunner.runSchematicAsync('application', options, workspaceTree)

0 commit comments

Comments
 (0)