-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): adjust ngcc postinstall command (#4641)
- Loading branch information
Showing
5 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import { runMigration } from '../../utils/testing'; | ||
|
||
function createAngularCLIPoweredWorkspace() { | ||
const tree = createEmptyWorkspace(Tree.empty()); | ||
tree.delete('workspace.json'); | ||
tree.create('angular.json', '{}'); | ||
return tree; | ||
} | ||
|
||
describe('Remove ngcc flags from postinstall script', () => { | ||
[ | ||
{ | ||
test: | ||
'node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points', | ||
expected: | ||
'node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main', | ||
}, | ||
{ | ||
test: | ||
'node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && echo "hi"', | ||
expected: | ||
'node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main && echo "hi"', | ||
}, | ||
{ | ||
test: | ||
'ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && node ./decorate-angular-cli.js && echo "hi"', | ||
expected: | ||
'ngcc --properties es2015 browser module main && node ./decorate-angular-cli.js && echo "hi"', | ||
}, | ||
{ | ||
test: | ||
'ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points && node ./decorate-angular-cli.js', | ||
expected: | ||
'ngcc --properties es2015 browser module main && node ./decorate-angular-cli.js', | ||
}, | ||
].forEach((testEntry) => { | ||
it(`should adjust ngcc for: "${testEntry.test}"`, async () => { | ||
const tree = createAngularCLIPoweredWorkspace(); | ||
|
||
tree.overwrite( | ||
'/package.json', | ||
JSON.stringify({ | ||
scripts: { | ||
postinstall: testEntry.test, | ||
}, | ||
}) | ||
); | ||
|
||
const result = await runMigration('update-ngcc-postinstall', {}, tree); | ||
|
||
const packageJson = JSON.parse(result.read('/package.json').toString()); | ||
expect(packageJson.scripts.postinstall).toEqual(testEntry.expected); | ||
}); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/angular/src/migrations/update-12-0-0/update-ngcc-postinstall.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { chain, SchematicContext, Tree } from '@angular-devkit/schematics'; | ||
import { updateJsonInTree } from '@nrwl/workspace'; | ||
import { formatFiles } from '@nrwl/workspace'; | ||
|
||
const udpateNgccPostinstallScript = (host: Tree, context: SchematicContext) => { | ||
updateJsonInTree('package.json', (json) => { | ||
if ( | ||
json.scripts && | ||
json.scripts.postinstall && | ||
json.scripts.postinstall.includes('ngcc') | ||
This comment has been minimized.
Sorry, something went wrong. |
||
) { | ||
// if exists, add execution of this script | ||
json.scripts.postinstall = json.scripts.postinstall.replace( | ||
/(.*)(ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points)(.*)/, | ||
'$1ngcc --properties es2015 browser module main$3' | ||
); | ||
} | ||
return json; | ||
})(host, context); | ||
}; | ||
|
||
export default function () { | ||
return chain([udpateNgccPostinstallScript, formatFiles()]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@juristr cannot use optional-chain here?