Skip to content

Commit 1bc00b6

Browse files
alan-agius4clydin
authored andcommittedNov 10, 2021
fix(@schematics/angular): migrate ng-packagr configurations in package.json
Currently ng-packagr, can be configured used in package.json. Previously, the migration didn't handle this case. Closes #22129 (cherry picked from commit e9d2d98)
1 parent 57ae543 commit 1bc00b6

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed
 

‎packages/schematics/angular/migrations/update-13/update-libraries.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ import { allTargetOptions, getWorkspace } from '../../utility/workspace';
1313

1414
function* visit(directory: DirEntry): IterableIterator<string> {
1515
for (const path of directory.subfiles) {
16-
if (path === 'ng-package.json') {
17-
yield join(directory.path, path);
16+
if (path === 'package.json') {
17+
const entry = directory.file(path);
18+
if (entry?.content.toString().includes('ngPackage') !== true) {
19+
continue;
20+
}
21+
} else if (path !== 'ng-package.json') {
22+
continue;
1823
}
24+
25+
yield join(directory.path, path);
1926
}
2027

2128
for (const path of directory.subdirs) {
@@ -34,6 +41,9 @@ export default function (): Rule {
3441
['lib', 'umdModuleIds'],
3542
['lib', 'amdId'],
3643
['lib', 'umdId'],
44+
['ngPackage', 'lib', 'umdModuleIds'],
45+
['ngPackage', 'lib', 'amdId'],
46+
['ngPackage', 'lib', 'umdId'],
3747
];
3848

3949
return async (tree, context) => {

‎packages/schematics/angular/migrations/update-13/update-libraries_spec.ts

+34
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ function createWorkSpaceConfig(tree: UnitTestTree) {
6969
2,
7070
),
7171
);
72+
73+
tree.create(
74+
'/package.json',
75+
JSON.stringify(
76+
{
77+
dependencies: { tslib: '^2.0.0' },
78+
ngPackage: {
79+
lib: {
80+
entryFile: 'src/public-api.ts',
81+
amdId: 'foo',
82+
umdId: 'foo',
83+
umdModuleIds: ['foo'],
84+
},
85+
},
86+
},
87+
undefined,
88+
2,
89+
),
90+
);
7291
}
7392

7493
const schematicName = 'update-libraries-v13';
@@ -135,4 +154,19 @@ describe(`Migration to update library projects. ${schematicName}`, () => {
135154
expect(lib.umdModuleIds).toBeUndefined();
136155
});
137156
});
157+
158+
describe('Ng-packagr properties in package.json', () => {
159+
it(`should remove UMD related options from package.json`, async () => {
160+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
161+
const pkg = readJsonFile(newTree, 'package.json');
162+
expect(pkg).toEqual({
163+
dependencies: { tslib: '^2.0.0' },
164+
ngPackage: {
165+
lib: {
166+
entryFile: 'src/public-api.ts',
167+
},
168+
},
169+
});
170+
});
171+
});
138172
});

0 commit comments

Comments
 (0)
Please sign in to comment.