fix(core): allow nx build scripts in generated pnpm-workspace.yaml (#35564)
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com> Co-authored-by: Miroslav Jonaš <missing.manual@gmail.com>
This commit is contained in:
@@ -385,13 +385,43 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
|
||||
workspaceGlobs: ['apps/*', 'packages/*'],
|
||||
});
|
||||
|
||||
const packageJson = tree.read('/proj/pnpm-workspace.yaml', 'utf-8');
|
||||
expect(packageJson).toMatchInlineSnapshot(`
|
||||
const pnpmWorkspace = tree.read('/proj/pnpm-workspace.yaml', 'utf-8');
|
||||
expect(pnpmWorkspace).toMatchInlineSnapshot(`
|
||||
"packages:
|
||||
- "apps/*"
|
||||
- "packages/*"
|
||||
|
||||
autoInstallPeers: true
|
||||
onlyBuiltDependencies:
|
||||
- nx
|
||||
"
|
||||
`);
|
||||
expect(tree.exists('proj/.npmrc')).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should configure the pnpm settings in pnpm-workspace.yaml with allowBuilds for pnpm 11+', async () => {
|
||||
tree.write('proj/package.json', JSON.stringify({}));
|
||||
jest.spyOn(devkit, 'getPackageManagerVersion').mockReturnValue('11.0.0');
|
||||
|
||||
await generateWorkspaceFiles(tree, {
|
||||
name: 'proj',
|
||||
directory: 'proj',
|
||||
preset: Preset.NPM,
|
||||
defaultBase: 'main',
|
||||
packageManager: 'pnpm',
|
||||
isCustomPreset: false,
|
||||
workspaceGlobs: ['apps/*', 'packages/*'],
|
||||
});
|
||||
|
||||
const pnpmWorkspace = tree.read('/proj/pnpm-workspace.yaml', 'utf-8');
|
||||
expect(pnpmWorkspace).toMatchInlineSnapshot(`
|
||||
"packages:
|
||||
- "apps/*"
|
||||
- "packages/*"
|
||||
|
||||
autoInstallPeers: true
|
||||
allowBuilds:
|
||||
nx: true
|
||||
"
|
||||
`);
|
||||
expect(tree.exists('proj/.npmrc')).toBeFalsy();
|
||||
|
||||
@@ -198,7 +198,7 @@ export async function generateWorkspaceFiles(
|
||||
const [packageMajor] = packageManagerVersion.split('.');
|
||||
if (options.packageManager === 'pnpm' && +packageMajor >= 7) {
|
||||
if (gte(packageManagerVersion, '10.6.0')) {
|
||||
addPnpmSettings(tree, options);
|
||||
addPnpmSettings(tree, options, packageManagerVersion);
|
||||
} else {
|
||||
createNpmrc(tree, options);
|
||||
}
|
||||
@@ -345,13 +345,18 @@ async function createReadme(
|
||||
});
|
||||
}
|
||||
|
||||
// ensure that pnpm install add all the missing peer deps
|
||||
function addPnpmSettings(
|
||||
tree: Tree,
|
||||
options: NormalizedSchema,
|
||||
packageManagerVersion: string
|
||||
) {
|
||||
const buildAllowlist = gte(packageManagerVersion, '11.0.0')
|
||||
? `allowBuilds:\n nx: true`
|
||||
: `onlyBuiltDependencies:\n - nx`;
|
||||
|
||||
function addPnpmSettings(tree: Tree, options: NormalizedSchema) {
|
||||
tree.write(
|
||||
join(options.directory, 'pnpm-workspace.yaml'),
|
||||
`autoInstallPeers: true
|
||||
`
|
||||
`autoInstallPeers: true\n${buildAllowlist}\n`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user