fix(js): fix typo so exports field in package.json is properly sorted (#29643)

## Current Behavior

It tries to sort `exported` which is an invalid field.

## Expected Behavior

It should sort `exports`.

## Related Issue(s)

Fixes #
This commit is contained in:
Leosvel Pérez Espinosa 2025-01-16 14:44:31 +01:00 committed by GitHub
parent d0078d050e
commit ed6b220214
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 5 deletions

View File

@ -153,10 +153,32 @@ function runNgNew(projectName: string, cwd: string): void {
const pmc = getPackageManagerCommand({ packageManager });
const command = `${pmc.runUninstalledPackage} @angular/cli@${angularCliVersion} new ${projectName} --package-manager=${packageManager}`;
cwd = join(tmpProjPath(), cwd);
ensureDirSync(cwd);
const fullCwd = join(tmpProjPath(), cwd);
ensureDirSync(fullCwd);
execSync(command, {
cwd,
cwd: fullCwd,
stdio: isVerbose() ? 'inherit' : 'pipe',
env: process.env,
encoding: 'utf-8',
});
// ensure angular packages are installed with ~ instead of ^ to prevent
// potential failures when new minor versions are released
function updateAngularDependencies(dependencies: any): void {
Object.keys(dependencies).forEach((key) => {
if (key.startsWith('@angular/') || key.startsWith('@angular-devkit/')) {
dependencies[key] = dependencies[key].replace(/^\^/, '~');
}
});
}
updateJson(join(cwd, projectName, 'package.json'), (json) => {
updateAngularDependencies(json.dependencies ?? {});
updateAngularDependencies(json.devDependencies ?? {});
return json;
});
execSync(pmc.install, {
cwd: join(fullCwd, projectName),
stdio: isVerbose() ? 'inherit' : 'pipe',
env: process.env,
encoding: 'utf-8',

View File

@ -486,6 +486,29 @@ export function runNgNew(
env: process.env,
encoding: 'utf-8',
});
// ensure angular packages are installed with ~ instead of ^ to prevent
// potential failures when new minor versions are released
function updateAngularDependencies(dependencies: any): void {
Object.keys(dependencies).forEach((key) => {
if (key.startsWith('@angular/') || key.startsWith('@angular-devkit/')) {
dependencies[key] = dependencies[key].replace(/^\^/, '~');
}
});
}
updateJson('package.json', (json) => {
updateAngularDependencies(json.dependencies ?? {});
updateAngularDependencies(json.devDependencies ?? {});
return json;
});
execSync(pmc.install, {
cwd: join(e2eCwd, projName),
stdio: isVerbose() ? 'inherit' : 'pipe',
env: process.env,
encoding: 'utf-8',
});
copySync(tmpProjPath(), tmpBackupNgCliProjPath());
if (isVerboseE2ERun()) {

View File

@ -14,7 +14,7 @@ export function sortPackageJsonFields(tree: Tree, projectRoot: string) {
'main',
'module',
'types',
'exported',
'exports',
]);
const orderedBottomFields = new Set([
'dependencies',

View File

@ -1027,8 +1027,8 @@ module.exports = withNx(
"main",
"module",
"types",
"nx",
"exports",
"nx",
]
`);
expect(readJson(tree, 'mylib/tsconfig.json')).toMatchInlineSnapshot(`