Skip to content

Commit

Permalink
fix(@schematics/angular): migrate ng-packagr configurations in packag…
Browse files Browse the repository at this point in the history
…e.json

Currently ng-packagr, can be configured used in package.json. Previously, the migration didn't handle this case.

Closes #22129
  • Loading branch information
alan-agius4 authored and clydin committed Nov 10, 2021
1 parent b230d35 commit e9d2d98
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ import { allTargetOptions, getWorkspace } from '../../utility/workspace';

function* visit(directory: DirEntry): IterableIterator<string> {
for (const path of directory.subfiles) {
if (path === 'ng-package.json') {
yield join(directory.path, path);
if (path === 'package.json') {
const entry = directory.file(path);
if (entry?.content.toString().includes('ngPackage') !== true) {
continue;
}
} else if (path !== 'ng-package.json') {
continue;
}

yield join(directory.path, path);
}

for (const path of directory.subdirs) {
Expand All @@ -34,6 +41,9 @@ export default function (): Rule {
['lib', 'umdModuleIds'],
['lib', 'amdId'],
['lib', 'umdId'],
['ngPackage', 'lib', 'umdModuleIds'],
['ngPackage', 'lib', 'amdId'],
['ngPackage', 'lib', 'umdId'],
];

return async (tree, context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ function createWorkSpaceConfig(tree: UnitTestTree) {
2,
),
);

tree.create(
'/package.json',
JSON.stringify(
{
dependencies: { tslib: '^2.0.0' },
ngPackage: {
lib: {
entryFile: 'src/public-api.ts',
amdId: 'foo',
umdId: 'foo',
umdModuleIds: ['foo'],
},
},
},
undefined,
2,
),
);
}

const schematicName = 'update-libraries-v13';
Expand Down Expand Up @@ -135,4 +154,19 @@ describe(`Migration to update library projects. ${schematicName}`, () => {
expect(lib.umdModuleIds).toBeUndefined();
});
});

describe('Ng-packagr properties in package.json', () => {
it(`should remove UMD related options from package.json`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const pkg = readJsonFile(newTree, 'package.json');
expect(pkg).toEqual({
dependencies: { tslib: '^2.0.0' },
ngPackage: {
lib: {
entryFile: 'src/public-api.ts',
},
},
});
});
});
});

0 comments on commit e9d2d98

Please sign in to comment.