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
This commit is contained in:
parent
a1e00f82f4
commit
1bc3893c65
|
@ -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`));
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue