Skip to content

Commit

Permalink
fix(core): ensure createPackageJson does not override existing config (
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Jun 12, 2023
1 parent 81a499a commit 2653809
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,15 @@ describe('updatePackageJson', () => {
"dependencies": {
"external1": "~1.0.0",
"external2": "^4.0.0",
"lib2": "^0.0.1",
},
"devDependencies": {
"jest": "27",
},
"main": "./main.js",
"name": "@org/lib1",
"types": "./main.d.ts",
"version": "0.0.1",
"version": "0.0.3",
}
`);
});
Expand Down
12 changes: 8 additions & 4 deletions packages/nx/src/plugins/js/package-json/create-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../../hasher/task-hasher';
import { readNxJson } from '../../../config/configuration';
import { readProjectFileMapCache } from '../../../project-graph/nx-deps-cache';
import { join } from 'path';

interface NpmDeps {
readonly dependencies: Record<string, string>;
Expand Down Expand Up @@ -80,11 +81,14 @@ export function createPackageJson(
name: projectName,
version: '0.0.1',
};
if (existsSync(`${graph.nodes[projectName].data.root}/package.json`)) {
const projectPackageJsonPath = join(
options.root || workspaceRoot,
projectNode.data.root,
'package.json'
);
if (existsSync(projectPackageJsonPath)) {
try {
packageJson = readJsonFile(
`${graph.nodes[projectName].data.root}/package.json`
);
packageJson = readJsonFile(projectPackageJsonPath);
// for standalone projects we don't want to include all the root dependencies
if (graph.nodes[projectName].data.root === '.') {
// TODO: We should probably think more on this - Nx can't always
Expand Down

1 comment on commit 2653809

@vercel
Copy link

@vercel vercel bot commented on 2653809 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app

Please sign in to comment.