fix(bazel): update type castings for JSON.parse usage (#40710)
Update usages of JSON.parse to be cast as specific types. PR Close #40710
This commit is contained in:
parent
e721a5d258
commit
2c90391d4b
|
@ -91,7 +91,7 @@ function main(args: string[]): number {
|
|||
const typeDefinitions = typeDefinitionsArg.split(',').filter(s => !!s);
|
||||
const srcs = srcsArg.split(',').filter(s => !!s);
|
||||
const dataFiles: string[] = dataArg.split(',').filter(s => !!s);
|
||||
const modulesManifest = JSON.parse(modulesManifestArg);
|
||||
const modulesManifest = JSON.parse(modulesManifestArg) as Record<string, any>;
|
||||
const dtsBundles: string[] = dtsBundleArg.split(',').filter(s => !!s);
|
||||
|
||||
/**
|
||||
|
@ -226,7 +226,7 @@ function main(args: string[]): number {
|
|||
let content = fs.readFileSync(src, 'utf-8');
|
||||
// Modify package.json files as necessary for publishing
|
||||
if (path.basename(src) === 'package.json') {
|
||||
const packageJson = JSON.parse(content);
|
||||
const packageJson = JSON.parse(content) as {[key: string]: string};
|
||||
content = amendPackageJson(src, packageJson, false);
|
||||
|
||||
const packageName = packageJson['name'];
|
||||
|
@ -439,7 +439,7 @@ export * from '${srcDirRelative(inputPath, typingsFile.replace(/\.d\.tsx?$/, '')
|
|||
* @param typingsPath the typings bundle entrypoint
|
||||
*/
|
||||
function rewireMetadata(metadataPath: string, typingsPath: string): string {
|
||||
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
|
||||
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf-8')) as {[key: string]: any};
|
||||
|
||||
let typingsRelativePath =
|
||||
normalizeSeparators(path.relative(path.dirname(metadataPath), typingsPath));
|
||||
|
|
|
@ -377,8 +377,9 @@ export function compile({
|
|||
if (importedFilePath.indexOf('node_modules') >= 0) {
|
||||
const maybeMetadataFile = importedFilePath.replace(EXT, '') + '.metadata.json';
|
||||
if (fs.existsSync(maybeMetadataFile)) {
|
||||
const moduleName =
|
||||
JSON.parse(fs.readFileSync(maybeMetadataFile, {encoding: 'utf-8'})).importAs;
|
||||
const moduleName = (JSON.parse(fs.readFileSync(maybeMetadataFile, {encoding: 'utf-8'})) as {
|
||||
importAs: string
|
||||
}).importAs;
|
||||
if (moduleName) {
|
||||
return moduleName;
|
||||
}
|
||||
|
|
|
@ -104,14 +104,20 @@ describe('@angular/common ng_package', () => {
|
|||
|
||||
|
||||
describe('should have module resolution properties in the package.json file for', () => {
|
||||
interface PackageJson {
|
||||
main: string;
|
||||
es2015: string;
|
||||
module: string;
|
||||
typings: string;
|
||||
}
|
||||
// https://github.com/angular/common-builds/blob/master/package.json
|
||||
it('/', () => {
|
||||
const actual = JSON.parse(fs.readFileSync('package.json', {encoding: 'utf-8'}));
|
||||
const actual = JSON.parse(fs.readFileSync('package.json', {encoding: 'utf-8'})) as PackageJson;
|
||||
expect(actual['main']).toEqual('./bundles/common.umd.js');
|
||||
});
|
||||
// https://github.com/angular/common-builds/blob/master/http/package.json
|
||||
it('/http', () => {
|
||||
const actual = JSON.parse(fs.readFileSync('http/package.json', {encoding: 'utf-8'}));
|
||||
const actual = JSON.parse(fs.readFileSync('http/package.json', {encoding: 'utf-8'})) as PackageJson;
|
||||
expect(actual['main']).toEqual('../bundles/common-http.umd.js');
|
||||
expect(actual['es2015']).toEqual('../fesm2015/http.js');
|
||||
expect(actual['module']).toEqual('../fesm2015/http.js');
|
||||
|
@ -119,12 +125,14 @@ describe('@angular/common ng_package', () => {
|
|||
});
|
||||
// https://github.com/angular/common-builds/blob/master/testing/package.json
|
||||
it('/testing', () => {
|
||||
const actual = JSON.parse(fs.readFileSync('testing/package.json', {encoding: 'utf-8'}));
|
||||
const actual =
|
||||
JSON.parse(fs.readFileSync('testing/package.json', {encoding: 'utf-8'})) as PackageJson;
|
||||
expect(actual['main']).toEqual('../bundles/common-testing.umd.js');
|
||||
});
|
||||
// https://github.com/angular/common-builds/blob/master/http/testing/package.json
|
||||
it('/http/testing', () => {
|
||||
const actual = JSON.parse(fs.readFileSync('http/testing/package.json', {encoding: 'utf-8'}));
|
||||
const actual =
|
||||
JSON.parse(fs.readFileSync('http/testing/package.json', {encoding: 'utf-8'})) as PackageJson;
|
||||
expect(actual['main']).toEqual('../../bundles/common-http-testing.umd.js');
|
||||
expect(actual['es2015']).toEqual('../../fesm2015/http/testing.js');
|
||||
expect(actual['module']).toEqual('../../fesm2015/http/testing.js');
|
||||
|
@ -132,7 +140,8 @@ describe('@angular/common ng_package', () => {
|
|||
});
|
||||
// https://github.com/angular/common-builds/blob/master/upgrade/package.json
|
||||
it('/upgrade', () => {
|
||||
const actual = JSON.parse(fs.readFileSync('upgrade/package.json', {encoding: 'utf-8'}));
|
||||
const actual =
|
||||
JSON.parse(fs.readFileSync('upgrade/package.json', {encoding: 'utf-8'})) as PackageJson;
|
||||
expect(actual['main']).toEqual('../bundles/common-upgrade.umd.js');
|
||||
expect(actual['es2015']).toEqual('../fesm2015/upgrade.js');
|
||||
expect(actual['module']).toEqual('../fesm2015/upgrade.js');
|
||||
|
|
|
@ -58,8 +58,11 @@ describe('@angular/core ng_package', () => {
|
|||
});
|
||||
|
||||
it('should contain metadata for ng update', () => {
|
||||
interface PackageJson {
|
||||
'ng-update': {packageGroup: string[];};
|
||||
}
|
||||
expect(shx.cat(packageJson)).not.toContain('NG_UPDATE_PACKAGE_GROUP');
|
||||
expect(JSON.parse(shx.cat(packageJson))['ng-update']['packageGroup'])
|
||||
expect((JSON.parse(shx.cat(packageJson)) as PackageJson)['ng-update'].packageGroup)
|
||||
.toContain('@angular/core');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue