Skip to content

Commit

Permalink
feat(npmrc): automatically manage pnpm and node versions [INFRA-33946] (
Browse files Browse the repository at this point in the history
#313)

* feat(npmrc): automatically manage pnpm and node versions [INFRA-33946]

* cdk is a subclass of ts

* maybe leave the package-manager-strict=false ?

---------

Co-authored-by: Andrew Hammond <[email protected]>
  • Loading branch information
mattlewis92 and ahammond authored Feb 6, 2025
1 parent 76a46f4 commit 8aa1502
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 6 deletions.
27 changes: 26 additions & 1 deletion src/clickup-cdk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { awscdk, Component, JsonPatch, SampleDir, SampleReadme } from 'projen';
import { awscdk, Component, javascript, JsonPatch, SampleDir, SampleReadme } from 'projen';
import * as semver from 'semver';
import merge from 'ts-deepmerge';

Expand All @@ -14,6 +14,7 @@ import { nodeVersion } from './node-version';
import { renovateWorkflow } from './renovate-workflow';
import { slackAlert } from './slack-alert';
import { updateProjen } from './update-projen';
import { parameters } from './utils/parameters';

export module clickupCdk {
const minCdkVersion = '2.138.0'; // https://github.com/aws/aws-cdk/issues/29746
Expand Down Expand Up @@ -174,6 +175,19 @@ export module clickupCdk {
if (options.sendSlackWebhookOnRelease !== false) {
slackAlert.addReleaseEvent(this, options.sendSlackWebhookOnReleaseOpts);
}

if (this.package.packageManager === javascript.NodePackageManager.PNPM) {
// Automate part of https://app.clickup-stg.com/333/v/dc/ad-757629/ad-3577645
this.package.addField('packageManager', `pnpm@${parameters.PROJEN_PNPM_VERSION}`);
// necessary to allow minor/patch version updates of pnpm on dev boxes
this.npmrc.addConfig('package-manager-strict', 'false');
// pnpm will manage the version of the package manager (pnpm)
this.npmrc.addConfig('manage-package-manager-versions', 'true');
// pnpm checks this value before running commands and will use (and install if missing) the specified version
this.npmrc.addConfig('use-node-version', parameters.PROJEN_NODE_VERSION);
// PNPM support for bundledDeps https://pnpm.io/npmrc#node-linker
this.npmrc.addConfig('node-linker', 'hoisted');
}
}
}

Expand Down Expand Up @@ -270,6 +284,17 @@ export module clickupCdk {
if (options.serviceCatalogOptions) {
datadogServiceCatalog.addServiceCatalogEvent(this, options.serviceCatalogOptions);
}

// While this is a subclass of AwsCdkTypeScriptApp,
// it doesn't seem to be inheriting this stuff
if (this.package.packageManager === javascript.NodePackageManager.PNPM) {
// Automate part of https://app.clickup-stg.com/333/v/dc/ad-757629/ad-3577645
this.package.addField('packageManager', `pnpm@${parameters.PROJEN_PNPM_VERSION}`);
// pnpm will manage the version of the package manager (pnpm)
this.npmrc.addConfig('manage-package-manager-versions', 'true');
// pnpm checks this value before running commands and will use (and install if missing) the specified version
this.npmrc.addConfig('use-node-version', parameters.PROJEN_NODE_VERSION);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/clickup-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,13 @@ export module clickupTs {

if (this.package.packageManager === javascript.NodePackageManager.PNPM) {
// Automate part of https://app.clickup-stg.com/333/v/dc/ad-757629/ad-3577645
this.package.addField('packageManager', 'pnpm@9.15.4');
this.package.addField('packageManager', `pnpm@${parameters.PROJEN_PNPM_VERSION}`);
// necessary to allow minor/patch version updates of pnpm on dev boxes
this.npmrc.addConfig('package-manager-strict', 'false');
// pnpm will manage the version of the package manager (pnpm)
this.npmrc.addConfig('manage-package-manager-versions', 'true');
// pnpm checks this value before running commands and will use (and install if missing) the specified version
this.npmrc.addConfig('use-node-version', parameters.PROJEN_NODE_VERSION);
}
}
}
Expand Down
137 changes: 137 additions & 0 deletions test/__snapshots__/clickup-cdk.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 48 additions & 1 deletion test/clickup-cdk.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { Testing } from 'projen';
import { javascript, Testing } from 'projen';
import { requiredParams } from './requiredParams';
import { clickupCdk } from '../src';
import { datadogServiceCatalog } from '../src/datadog-service-catalog';
Expand Down Expand Up @@ -51,6 +51,32 @@ describe('ClickUpCdkTypeScriptApp', () => {
});
});
});

describe('pnpm', () => {
p = new clickupCdk.ClickUpCdkTypeScriptApp({
...requiredParams,
packageManager: javascript.NodePackageManager.PNPM,
});
const synth = Testing.synth(p);
it('packageManager', () => {
expect(synth['package.json'].packageManager).toBe('[email protected]');
});

const npmrcEntries = [
// 'package-manager-strict=false',
'manage-package-manager-versions=true',
'use-node-version=22.13.1',
];
it.each(npmrcEntries)('%s', (npmrcEntry) => {
expect(synth['.npmrc']).toContain(npmrcEntry);
});

['.npmrc', 'package.json'].forEach((file) => {
test(file, () => {
expect(synth[file]).toMatchSnapshot();
});
});
});
});
});

Expand Down Expand Up @@ -93,6 +119,27 @@ describe('ClickUpCdkConstructLibrary', () => {
const releaseFile = synth['.github/workflows/release.yml'];
expect(releaseFile).toMatchSnapshot();
});

describe('pnpm', () => {
p = new clickupCdk.ClickUpCdkConstructLibrary({
...commonProps,
packageManager: javascript.NodePackageManager.PNPM,
});
const synth = Testing.synth(p);
it('packageManager', () => {
expect(synth['package.json'].packageManager).toBe('[email protected]');
});

const npmrcEntries = [
'package-manager-strict=false',
'manage-package-manager-versions=true',
'use-node-version=22.13.1',
'node-linker=hoisted',
];
it.each(npmrcEntries)('%s', (npmrcEntry) => {
expect(synth['.npmrc']).toContain(npmrcEntry);
});
});
});
});

Expand Down
12 changes: 9 additions & 3 deletions test/clickup-ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ describe('ClickUpTypeScriptProject', () => {
});
const synth = Testing.synth(p);
it('packageManager', () => {
expect(synth['package.json'].packageManager).toBe('[email protected].4');
expect(synth['package.json'].packageManager).toBe('[email protected].5');
});
it('package-manager-strict=false', () => {
expect(synth['.npmrc']).toMatch(/package-manager-strict=false/);

const npmrcEntries = [
'package-manager-strict=false',
'manage-package-manager-versions=true',
'use-node-version=22.13.1',
];
it.each(npmrcEntries)('%s', (npmrcEntry) => {
expect(synth['.npmrc']).toContain(npmrcEntry);
});
});
});
Expand Down

0 comments on commit 8aa1502

Please sign in to comment.