mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-19 04:26:01 +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 {
|
import {
|
||||||
|
InvalidJsonCharacterException,
|
||||||
JsonArray,
|
JsonArray,
|
||||||
JsonObject,
|
JsonObject,
|
||||||
JsonParseMode,
|
JsonParseMode,
|
||||||
@ -150,7 +151,15 @@ function normalizeValue(value: string, path: string): JsonValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
|
try {
|
||||||
return parseJson(value, JsonParseMode.Loose);
|
return parseJson(value, JsonParseMode.Loose);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof InvalidJsonCharacterException && !value.startsWith('{')) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {ng} from '../../../utils/process';
|
import { ng } from '../../../utils/process';
|
||||||
import {expectToFail} from '../../../utils/utils';
|
import { expectToFail } from '../../../utils/utils';
|
||||||
|
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
@ -12,9 +12,6 @@ export default function() {
|
|||||||
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
|
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', 'true'))
|
||||||
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle'))
|
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle'))
|
||||||
.then(({ stdout }) => {
|
.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 { 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() {
|
export default function() {
|
||||||
@ -16,9 +15,10 @@ export default function() {
|
|||||||
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
|
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => expectToFail(() => {
|
// This test requires schema querying capabilities
|
||||||
return ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle', 'INVALID_BOOLEAN');
|
// .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', 'true'))
|
||||||
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'))
|
.then(() => ng('config', '--global', 'schematics.@schematics/angular.component.inlineStyle'))
|
||||||
.then(({ stdout }) => {
|
.then(({ stdout }) => {
|
||||||
|
@ -1,13 +1,21 @@
|
|||||||
import {ng} from '../../../utils/process';
|
import { ng } from '../../../utils/process';
|
||||||
import {expectToFail} from '../../../utils/utils';
|
import { expectToFail } from '../../../utils/utils';
|
||||||
|
|
||||||
export default function() {
|
export default async function() {
|
||||||
return Promise.resolve()
|
|
||||||
.then(() => expectToFail(() => ng('config', 'schematics.@schematics/angular.component.aaa', 'bbb')))
|
// These tests require schema querying capabilities
|
||||||
.then(() => expectToFail(() => ng(
|
// .then(() => expectToFail(
|
||||||
|
// () => ng('config', 'schematics.@schematics/angular.component.aaa', 'bbb')),
|
||||||
|
// )
|
||||||
|
// .then(() => expectToFail(() => ng(
|
||||||
|
// 'config',
|
||||||
|
// 'schematics.@schematics/angular.component.viewEncapsulation',
|
||||||
|
// 'bbb',
|
||||||
|
// )))
|
||||||
|
|
||||||
|
await ng(
|
||||||
'config',
|
'config',
|
||||||
'schematics.@schematics/angular.component.viewEncapsulation',
|
'schematics.@schematics/angular.component.viewEncapsulation',
|
||||||
'bbb'
|
'Emulated',
|
||||||
)))
|
);
|
||||||
.then(() => ng('config', 'schematics.@schematics/angular.component.viewEncapsulation', '"Emulated"'));
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,14 @@
|
|||||||
import {ng} from '../../../utils/process';
|
import { ng } from '../../../utils/process';
|
||||||
import {expectToFail} from '../../../utils/utils';
|
import { expectToFail } from '../../../utils/utils';
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
export default function() {
|
export default function() {
|
||||||
return;
|
|
||||||
|
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => expectToFail(() => ng('config', 'apps.zzz.prefix')))
|
.then(() => expectToFail(() => ng('config', 'schematics.@schematics/angular.component.prefix')))
|
||||||
.then(() => ng('config', 'apps.0.prefix' , 'new-prefix'))
|
.then(() => ng('config', 'schematics.@schematics/angular.component.prefix' , 'new-prefix'))
|
||||||
.then(() => ng('config', 'apps.0.prefix'))
|
.then(() => ng('config', 'schematics.@schematics/angular.component.prefix'))
|
||||||
.then(({ stdout }) => {
|
.then(({ stdout }) => {
|
||||||
if (!stdout.match(/new-prefix/)) {
|
if (!stdout.match(/new-prefix/)) {
|
||||||
throw new Error(`Expected "new-prefix", received "${JSON.stringify(stdout)}".`);
|
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