Skip to content

Commit

Permalink
fix(js): fix typo so exports field in package.json is properly sort…
Browse files Browse the repository at this point in the history
…ed (#29643)

## Current Behavior

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

## Expected Behavior

It should sort `exports`.

## Related Issue(s)

Fixes #

(cherry picked from commit ed6b220)
  • Loading branch information
leosvelperez authored and FrozenPandaz committed Jan 17, 2025
1 parent a899385 commit 117f756
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
28 changes: 25 additions & 3 deletions e2e/angular/src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
23 changes: 23 additions & 0 deletions e2e/utils/create-project-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/js/src/utils/package-json/sort-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function sortPackageJsonFields(tree: Tree, projectRoot: string) {
'main',
'module',
'types',
'exported',
'exports',
]);
const orderedBottomFields = new Set([
'dependencies',
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/generators/library/library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,8 @@ module.exports = withNx(
"main",
"module",
"types",
"nx",
"exports",
"nx",
]
`);
expect(readJson(tree, 'mylib/tsconfig.json')).toMatchInlineSnapshot(`
Expand Down

0 comments on commit 117f756

Please sign in to comment.