diff --git a/packages/bazel/src/ng_package/packager.ts b/packages/bazel/src/ng_package/packager.ts index 7f08ca943b..246a264a87 100644 --- a/packages/bazel/src/ng_package/packager.ts +++ b/packages/bazel/src/ng_package/packager.ts @@ -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; 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)); diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index c6127b4d91..842a00a94d 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -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; } diff --git a/packages/bazel/test/ng_package/common_package.spec.ts b/packages/bazel/test/ng_package/common_package.spec.ts index c0aaafbcf2..5035f4c392 100644 --- a/packages/bazel/test/ng_package/common_package.spec.ts +++ b/packages/bazel/test/ng_package/common_package.spec.ts @@ -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'); diff --git a/packages/bazel/test/ng_package/core_package.spec.ts b/packages/bazel/test/ng_package/core_package.spec.ts index cf54cabde6..d86b92c44b 100644 --- a/packages/bazel/test/ng_package/core_package.spec.ts +++ b/packages/bazel/test/ng_package/core_package.spec.ts @@ -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'); }); });