-
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(core): handle packageManager property with createPackageJson (#26726
) This PR was originally authored by @stephenwade. It adds the `packageManager` property to the `createPackageJson` function that ensures the generated `package.json` uses the same package manager that was used when generating it. ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: Stephen Wade <[email protected]> Co-authored-by: Stephen Wade <[email protected]>
- Loading branch information
1 parent
336d371
commit fdd89a6
Showing
2 changed files
with
111 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,7 +397,7 @@ describe('createPackageJson', () => { | |
}); | ||
}); | ||
|
||
describe('parsing "package.json" versions', () => { | ||
describe('parsing "package.json"', () => { | ||
const appDependencies = [ | ||
{ source: 'app1', target: 'npm:@nx/devkit', type: 'static' }, | ||
{ source: 'app1', target: 'npm:typescript', type: 'static' }, | ||
|
@@ -654,6 +654,98 @@ describe('createPackageJson', () => { | |
}, | ||
}); | ||
}); | ||
|
||
it('should add packageManager if missing', () => { | ||
spies.push( | ||
jest.spyOn(fs, 'existsSync').mockImplementation((path) => { | ||
if (path === 'libs/lib1/package.json') { | ||
return true; | ||
} | ||
if (path === 'package.json') { | ||
return true; | ||
} | ||
}) | ||
); | ||
spies.push( | ||
jest | ||
.spyOn(fileutilsModule, 'readJsonFile') | ||
.mockImplementation((path) => { | ||
if (path === 'package.json') { | ||
return { | ||
...rootPackageJson(), | ||
packageManager: 'yarn', | ||
}; | ||
} | ||
if (path === 'libs/lib1/package.json') { | ||
return projectPackageJson(); | ||
} | ||
}) | ||
); | ||
|
||
expect( | ||
createPackageJson('lib1', graph, { | ||
root: '', | ||
}) | ||
).toEqual({ | ||
dependencies: { | ||
random: '1.0.0', | ||
typescript: '^4.8.4', | ||
}, | ||
name: 'other-name', | ||
packageManager: 'yarn', | ||
version: '1.2.3', | ||
}); | ||
}); | ||
|
||
it('should replace packageManager if not in sync with root and show warning', () => { | ||
spies.push( | ||
jest.spyOn(fs, 'existsSync').mockImplementation((path) => { | ||
if (path === 'libs/lib1/package.json') { | ||
return true; | ||
} | ||
if (path === 'package.json') { | ||
return true; | ||
} | ||
}) | ||
); | ||
const consoleWarnSpy = jest.spyOn(process.stdout, 'write'); | ||
spies.push(consoleWarnSpy); | ||
spies.push( | ||
jest | ||
.spyOn(fileutilsModule, 'readJsonFile') | ||
.mockImplementation((path) => { | ||
if (path === 'package.json') { | ||
return { | ||
...rootPackageJson(), | ||
packageManager: '[email protected]', | ||
}; | ||
} | ||
if (path === 'libs/lib1/package.json') { | ||
return { | ||
...projectPackageJson(), | ||
packageManager: '[email protected]', | ||
}; | ||
} | ||
}) | ||
); | ||
|
||
expect( | ||
createPackageJson('lib1', graph, { | ||
root: '', | ||
}) | ||
).toEqual({ | ||
dependencies: { | ||
random: '1.0.0', | ||
typescript: '^4.8.4', | ||
}, | ||
name: 'other-name', | ||
packageManager: '[email protected]', | ||
version: '1.2.3', | ||
}); | ||
expect(JSON.stringify(consoleWarnSpy.mock.calls)).toMatch( | ||
/Package Manager Mismatch/ | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
|
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