mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 19:13:34 +08:00
fix(@angular/cli): handle raw strings in config command
This commit is contained in:
parent
3db1a1861d
commit
4e53bfde75
@ -1,4 +1,5 @@
|
||||
import {
|
||||
InvalidJsonCharacterException,
|
||||
JsonArray,
|
||||
JsonObject,
|
||||
JsonParseMode,
|
||||
@ -150,7 +151,15 @@ function normalizeValue(value: string, path: string): JsonValue {
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
return parseJson(value, JsonParseMode.Loose);
|
||||
try {
|
||||
return parseJson(value, JsonParseMode.Loose);
|
||||
} catch (e) {
|
||||
if (e instanceof InvalidJsonCharacterException && !value.startsWith('{')) {
|
||||
return value;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {ng} from '../../../utils/process';
|
||||
import {expectToFail} from '../../../utils/utils';
|
||||
import { ng } from '../../../utils/process';
|
||||
import { expectToFail } from '../../../utils/utils';
|
||||
|
||||
|
||||
export default function() {
|
||||
@ -12,9 +12,6 @@ export default function() {
|
||||
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
|
||||
}
|
||||
})
|
||||
.then(() => expectToFail(() => {
|
||||
return ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
|
||||
}))
|
||||
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'true'))
|
||||
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle'))
|
||||
.then(({ stdout }) => {
|
||||
|
@ -1,9 +1,8 @@
|
||||
import {ng} from '../../../utils/process';
|
||||
import {expectToFail} from '../../../utils/utils';
|
||||
import { expectFileToExist } from '../../../utils/fs';
|
||||
import * as path from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { deleteFile } from '../../../utils/fs';
|
||||
import * as path from 'path';
|
||||
import { deleteFile, expectFileToExist } from '../../../utils/fs';
|
||||
import { ng } from '../../../utils/process';
|
||||
import { expectToFail } from '../../../utils/utils';
|
||||
|
||||
|
||||
export default function() {
|
||||
@ -16,9 +15,10 @@ export default function() {
|
||||
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
|
||||
}
|
||||
})
|
||||
.then(() => expectToFail(() => {
|
||||
return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
|
||||
}))
|
||||
// This test requires schema querying capabilities
|
||||
// .then(() => expectToFail(() => {
|
||||
// return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
|
||||
// }))
|
||||
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'true'))
|
||||
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'))
|
||||
.then(({ stdout }) => {
|
||||
|
@ -1,13 +1,21 @@
|
||||
import {ng} from '../../../utils/process';
|
||||
import {expectToFail} from '../../../utils/utils';
|
||||
import { ng } from '../../../utils/process';
|
||||
import { expectToFail } from '../../../utils/utils';
|
||||
|
||||
export default function() {
|
||||
return Promise.resolve()
|
||||
.then(() => expectToFail(() => ng('config', 'schematics.@schematics/angular.component.aaa', 'bbb')))
|
||||
.then(() => expectToFail(() => ng(
|
||||
'config',
|
||||
'schematics.@schematics/angular.component.viewEncapsulation',
|
||||
'bbb'
|
||||
)))
|
||||
.then(() => ng('config', 'schematics.@schematics/angular.component.viewEncapsulation', '"Emulated"'));
|
||||
export default async function() {
|
||||
|
||||
// These tests require schema querying capabilities
|
||||
// .then(() => expectToFail(
|
||||
// () => ng('config', 'schematics.@schematics/angular.component.aaa', 'bbb')),
|
||||
// )
|
||||
// .then(() => expectToFail(() => ng(
|
||||
// 'config',
|
||||
// 'schematics.@schematics/angular.component.viewEncapsulation',
|
||||
// 'bbb',
|
||||
// )))
|
||||
|
||||
await ng(
|
||||
'config',
|
||||
'schematics.@schematics/angular.component.viewEncapsulation',
|
||||
'Emulated',
|
||||
);
|
||||
}
|
||||
|
@ -1,23 +1,14 @@
|
||||
import {ng} from '../../../utils/process';
|
||||
import {expectToFail} from '../../../utils/utils';
|
||||
import * as fs from 'fs';
|
||||
import { ng } from '../../../utils/process';
|
||||
import { expectToFail } from '../../../utils/utils';
|
||||
|
||||
export default function() {
|
||||
return;
|
||||
|
||||
return Promise.resolve()
|
||||
.then(() => expectToFail(() => ng('config', 'apps.zzz.prefix')))
|
||||
.then(() => ng('config', 'apps.0.prefix' , 'new-prefix'))
|
||||
.then(() => ng('config', 'apps.0.prefix'))
|
||||
.then(() => expectToFail(() => ng('config', 'schematics.@schematics/angular.component.prefix')))
|
||||
.then(() => ng('config', 'schematics.@schematics/angular.component.prefix' , 'new-prefix'))
|
||||
.then(() => ng('config', 'schematics.@schematics/angular.component.prefix'))
|
||||
.then(({ stdout }) => {
|
||||
if (!stdout.match(/new-prefix/)) {
|
||||
throw new Error(`Expected "new-prefix", received "${JSON.stringify(stdout)}".`);
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
const tsLint = JSON.parse(fs.readFileSync(process.cwd() + '/tslint.json', 'utf8'));
|
||||
if (tsLint.rules['component-selector'][2] !== 'new-prefix') {
|
||||
throw new Error(`Expected "new-prefix" Found: ${tsLint.rules['component-selector'][2]}.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user