From 1bc3893c650eae5c8c88cf252b571f79f29dd7b4 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sun, 23 Feb 2020 18:02:13 +0100 Subject: [PATCH] test(ngcc): use "module" format property for ES5 bundles (#36089) The format property for ES5 bundles should be "module" or "es5"/"esm5", but was "main" instead. The "main" property is appropriate for CommonJS and UMD bundles, not for ES5 bundles. PR Close #36089 --- .../ngcc/test/integration/ngcc_spec.ts | 24 +++++++++---------- .../ngcc/test/integration/util.ts | 8 ++++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts index 0d68b90943..819ec4f9d0 100644 --- a/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts +++ b/packages/compiler-cli/ngcc/test/integration/ngcc_spec.ts @@ -132,7 +132,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`)).replace(/\s+/g, ' '); @@ -242,7 +242,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`)); @@ -266,7 +266,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); const after = fs.readFile(_(`/node_modules/test-package/index.js`)); @@ -298,7 +298,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`)); @@ -408,7 +408,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`)); @@ -669,7 +669,7 @@ runInEachFileSystem(() => { }); mainNgcc({ basePath: '/node_modules', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], logger: new MockLogger(), }); @@ -685,15 +685,15 @@ runInEachFileSystem(() => { // Now run ngcc again to see that it cleans out the outdated artifacts mainNgcc({ basePath: '/node_modules', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], logger: new MockLogger(), }); const newPackageJson = loadPackage('test-package', _('/node_modules')); expect(newPackageJson.__processed_by_ivy_ngcc__).toEqual({ - main: '0.0.0-PLACEHOLDER', + module: '0.0.0-PLACEHOLDER', typings: '0.0.0-PLACEHOLDER', }); - expect(newPackageJson.main_ivy_ngcc).toBeUndefined(); + expect(newPackageJson.module_ivy_ngcc).toBeUndefined(); expect(fs.exists(_('/node_modules/test-package/x.js'))).toBe(true); expect(fs.exists(_('/node_modules/test-package/x.js.__ivy_ngcc_bak'))).toBe(false); expect(fs.readFile(_('/node_modules/test-package/x.js'))).toEqual('original content'); @@ -1274,7 +1274,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); @@ -1315,7 +1315,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); @@ -1358,7 +1358,7 @@ runInEachFileSystem(() => { mainNgcc({ basePath: '/node_modules', targetEntryPointPath: 'test-package', - propertiesToConsider: ['main'], + propertiesToConsider: ['module'], }); const dtsContents = fs.readFile(_(`/node_modules/test-package/index.d.ts`)); diff --git a/packages/compiler-cli/ngcc/test/integration/util.ts b/packages/compiler-cli/ngcc/test/integration/util.ts index 32a42a2078..e088007483 100644 --- a/packages/compiler-cli/ngcc/test/integration/util.ts +++ b/packages/compiler-cli/ngcc/test/integration/util.ts @@ -33,6 +33,7 @@ export function compileIntoFlatEs5Package(pkgName: string, sources: PackageSourc compileIntoFlatPackage(pkgName, sources, { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.ESNext, + formatProperty: 'module', }); } @@ -46,6 +47,11 @@ export interface FlatLayoutOptions { * The module kind to use in the compiled result. */ module: ts.ModuleKind; + + /** + * The name of the property in package.json that refers to the root source file. + */ + formatProperty: string; } /** @@ -90,7 +96,7 @@ function compileIntoFlatPackage( const pkgJson: unknown = { name: pkgName, version: '0.0.1', - main: './index.js', + [options.formatProperty]: './index.js', typings: './index.d.ts', };