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({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`)).replace(/\s+/g, ' ');
|
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`)).replace(/\s+/g, ' ');
|
||||||
|
@ -242,7 +242,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||||
|
@ -266,7 +266,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
const after = fs.readFile(_(`/node_modules/test-package/index.js`));
|
const after = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||||
|
@ -408,7 +408,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
const jsContents = fs.readFile(_(`/node_modules/test-package/index.js`));
|
||||||
|
@ -669,7 +669,7 @@ runInEachFileSystem(() => {
|
||||||
});
|
});
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
logger: new MockLogger(),
|
logger: new MockLogger(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -685,15 +685,15 @@ runInEachFileSystem(() => {
|
||||||
// Now run ngcc again to see that it cleans out the outdated artifacts
|
// Now run ngcc again to see that it cleans out the outdated artifacts
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
logger: new MockLogger(),
|
logger: new MockLogger(),
|
||||||
});
|
});
|
||||||
const newPackageJson = loadPackage('test-package', _('/node_modules'));
|
const newPackageJson = loadPackage('test-package', _('/node_modules'));
|
||||||
expect(newPackageJson.__processed_by_ivy_ngcc__).toEqual({
|
expect(newPackageJson.__processed_by_ivy_ngcc__).toEqual({
|
||||||
main: '0.0.0-PLACEHOLDER',
|
module: '0.0.0-PLACEHOLDER',
|
||||||
typings: '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'))).toBe(true);
|
||||||
expect(fs.exists(_('/node_modules/test-package/x.js.__ivy_ngcc_bak'))).toBe(false);
|
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');
|
expect(fs.readFile(_('/node_modules/test-package/x.js'))).toEqual('original content');
|
||||||
|
@ -1274,7 +1274,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1315,7 +1315,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1358,7 +1358,7 @@ runInEachFileSystem(() => {
|
||||||
mainNgcc({
|
mainNgcc({
|
||||||
basePath: '/node_modules',
|
basePath: '/node_modules',
|
||||||
targetEntryPointPath: 'test-package',
|
targetEntryPointPath: 'test-package',
|
||||||
propertiesToConsider: ['main'],
|
propertiesToConsider: ['module'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const dtsContents = fs.readFile(_(`/node_modules/test-package/index.d.ts`));
|
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, {
|
compileIntoFlatPackage(pkgName, sources, {
|
||||||
target: ts.ScriptTarget.ES5,
|
target: ts.ScriptTarget.ES5,
|
||||||
module: ts.ModuleKind.ESNext,
|
module: ts.ModuleKind.ESNext,
|
||||||
|
formatProperty: 'module',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +47,11 @@ export interface FlatLayoutOptions {
|
||||||
* The module kind to use in the compiled result.
|
* The module kind to use in the compiled result.
|
||||||
*/
|
*/
|
||||||
module: ts.ModuleKind;
|
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 = {
|
const pkgJson: unknown = {
|
||||||
name: pkgName,
|
name: pkgName,
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
main: './index.js',
|
[options.formatProperty]: './index.js',
|
||||||
typings: './index.d.ts',
|
typings: './index.d.ts',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue