Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/commands/cli/release/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { promisify } from 'node:util';
import { exec as execSync, ExecException } from 'node:child_process';
import { arrayWithDeprecation, Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { ensureString } from '@salesforce/ts-types';
import { Env } from '@salesforce/kit';
import { Octokit } from '@octokit/core';
Expand Down Expand Up @@ -51,8 +51,10 @@ export default class build extends SfCommand<void> {
default: true,
allowNo: true,
}),
only: arrayWithDeprecation({
Comment thread
iowillhoit marked this conversation as resolved.
only: Flags.string({
summary: messages.getMessage('flags.only.summary'),
multiple: true,
delimiter: ',',
}),
'pinned-deps': Flags.boolean({
summary: messages.getMessage('flags.pinned-deps.summary'),
Expand Down
4 changes: 3 additions & 1 deletion src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,10 @@ export class Package extends AsyncOptionalCreatable {
// find dependency in package.json (could be an npm alias)
const depInfo = this.getDependencyInfo(name, { ...dependencies, ...resolutions, ...jitPlugins });

const isPinned: boolean = (this.packageJson.pinnedDependencies ?? []).includes(depInfo.packageName);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I forgot that jitPlugins were not in the pinnedDep list. All of the jitPlugins also need to be pinned, no matter what.

Example in the sf package.json https://github.com/salesforcecli/cli/blob/2017716e9c61c80db1c2b289d59ae12963673b18/package.json#L78


// if a version is not provided, we'll look up the "latest" version
depInfo.finalVersion = version ?? this.getDistTags(depInfo.packageName).latest;
depInfo.finalVersion = `${isPinned ? '' : '^'}${version ?? this.getDistTags(depInfo.packageName).latest}`;

// return if version did not change
if (depInfo.currentVersion === depInfo.finalVersion) return;
Expand Down
42 changes: 29 additions & 13 deletions test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ describe('Package', () => {
'@salesforce/plugin-config': '1.2.3',
'left-pad': '1.1.1',
},
pinnedDependencies: ['left-pad'],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For sf consistency sake, let's use @salesforce/plugin-config as the pinned dep and left-pad as the one that will get the ^

resolutions: {
'@salesforce/source-deploy-retrieve': '1.0.0',
},
Expand All @@ -149,51 +150,66 @@ describe('Package', () => {
});
it('should look up latest version if not provided', async () => {
const pkg = await Package.create();
const results = pkg.bumpDependencyVersions(['@salesforce/plugin-config', '@salesforce/jit-me']);
const results = pkg.bumpDependencyVersions(['@salesforce/plugin-config', '@salesforce/jit-me', 'left-pad']);

expect(results).to.deep.equal([
{
packageName: '@salesforce/plugin-config',
currentVersion: '1.2.3',
finalVersion: '9.9.9',
// Dependency should be unpinned because it is not listed in `pinnedDependencies`
finalVersion: '^9.9.9',
},
{
packageName: '@salesforce/jit-me',
currentVersion: '1.0.0',
// Dependency should be unpinned because it is not listed in `pinnedDependencies`
finalVersion: '^9.9.9',
},
{
packageName: 'left-pad',
currentVersion: '1.1.1',
// Dependency should be pinned because it is listed in `pinnedDependencies`
finalVersion: '9.9.9',
},
]);
});

it('should used passed in version', async () => {
const pkg = await Package.create();
const results = pkg.bumpDependencyVersions(['@salesforce/plugin-config@11.0.0']);
const results = pkg.bumpDependencyVersions(['@salesforce/plugin-config@11.0.0', 'left-pad@11.0.0']);

expect(results).to.deep.equal([
{
packageName: '@salesforce/plugin-config',
currentVersion: '1.2.3',
// Dependency should be unpinned because it's not in `pinnedDependencies`
finalVersion: '^11.0.0',
},
{
packageName: 'left-pad',
currentVersion: '1.1.1',
// Dependency should be pinned because it's in `pinnedDependencies`
finalVersion: '11.0.0',
},
]);
});

it('should work with non-namespaced package', async () => {
it('should unpin a pinned version even if it is already up-to-date', async () => {
const pkg = await Package.create();
const results = pkg.bumpDependencyVersions(['left-pad']);
const results = pkg.bumpDependencyVersions(['@salesforce/plugin-config@1.2.3']);

expect(results).to.deep.equal([
{
packageName: 'left-pad',
currentVersion: '1.1.1',
finalVersion: '9.9.9',
packageName: '@salesforce/plugin-config',
currentVersion: '1.2.3',
finalVersion: '^1.2.3',
},
]);
});

it('should return an empty array if all versions are already up to date', async () => {
it('should return an empty array if all bumped versions are already up to date', async () => {
const pkg = await Package.create();
const results = pkg.bumpDependencyVersions(['@salesforce/plugin-config@1.2.3']);
const results = pkg.bumpDependencyVersions(['left-pad@1.1.1']);

expect(results).to.deep.equal([]);
});
Expand All @@ -202,21 +218,21 @@ describe('Package', () => {
const pkg = await Package.create();
pkg.bumpDependencyVersions(['@salesforce/plugin-config@3.3.3']);

expect(pkg.packageJson.dependencies['@salesforce/plugin-config']).to.equal('3.3.3');
expect(pkg.packageJson.dependencies['@salesforce/plugin-config']).to.equal('^3.3.3');
});

it('should update resolutions in package.json', async () => {
const pkg = await Package.create();
pkg.bumpDependencyVersions(['@salesforce/source-deploy-retrieve@1.0.1']);
assert(pkg.packageJson.resolutions);
expect(pkg.packageJson.resolutions['@salesforce/source-deploy-retrieve']).to.equal('1.0.1');
expect(pkg.packageJson.resolutions['@salesforce/source-deploy-retrieve']).to.equal('^1.0.1');
});

it('should update jit in package.json', async () => {
const pkg = await Package.create();
pkg.bumpDependencyVersions(['@salesforce/jit-me@1.0.1']);
assert(pkg.packageJson.oclif?.jitPlugins);
expect(pkg.packageJson.oclif.jitPlugins['@salesforce/jit-me']).to.equal('1.0.1');
expect(pkg.packageJson.oclif.jitPlugins['@salesforce/jit-me']).to.equal('^1.0.1');
});
});

Expand Down
Loading