From 0a0cebc0804964afc45db687ae521aaa083596b6 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 1 Nov 2022 08:38:33 -0600 Subject: [PATCH 1/6] fix: clonse sfdx-project.json deps to avoid writing back to the file --- src/package/packageVersionCreate.ts | 2 +- test/package/packageVersionCreate.test.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index 3974d31a5..026789eb8 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -368,7 +368,7 @@ export class PackageVersionCreate { // All dependencies for the packaging dir should be resolved to an 04t id to be passed to the server. // (see _retrieveSubscriberPackageVersionId for details) - const dependencies = packageDescriptorJson.dependencies; + const dependencies = structuredClone(packageDescriptorJson.dependencies); // branch can be set via options or descriptor; option takes precedence this.options.branch = this.options.branch ?? packageDescriptorJson.branch; diff --git a/test/package/packageVersionCreate.test.ts b/test/package/packageVersionCreate.test.ts index 50fa21db4..30b723357 100644 --- a/test/package/packageVersionCreate.test.ts +++ b/test/package/packageVersionCreate.test.ts @@ -31,6 +31,14 @@ describe('Package Version Create', () => { project = SfProject.getInstance(); await project.getSfProjectJson().write({ packageDirectories: [ + { + path: 'pkg', + package: 'dep', + versionName: 'ver 0.1', + versionNumber: '0.1.0.NEXT', + default: false, + name: 'pkg', + }, { path: 'force-app', package: 'TEST', @@ -38,11 +46,18 @@ describe('Package Version Create', () => { versionNumber: '0.1.0.NEXT', default: true, ancestorId: 'TEST2', + dependencies: [ + { + package: 'DEP@0.1.0-1', + }, + ], }, ], packageAliases: { TEST: packageId, TEST2: '05i3i000000Gmj6XXX', + DEP: '05i3i000000Gmj6XXX', + 'DEP@0.1.0-1': '04t3i000002eyYXXXX', }, }); await fs.promises.mkdir(path.join(project.getPath(), 'force-app')); @@ -117,6 +132,12 @@ describe('Package Version Create', () => { 'SubscriberPackageVersionId', 'Tag' ); + + expect(project.getSfProjectJson().getContents().packageDirectories[1].dependencies).to.deep.equal([ + { + package: 'DEP@0.1.0-1', + }, + ]); }); it('should create the package version create request with codecoverage=true', async () => { From 62ed1227610ca63aaf4ac9c9e95d08e67b9bd10d Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Tue, 1 Nov 2022 14:32:47 -0600 Subject: [PATCH 2/6] chore: node 16 way of copying --- src/package/packageVersionCreate.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index 026789eb8..75314d685 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -368,7 +368,8 @@ export class PackageVersionCreate { // All dependencies for the packaging dir should be resolved to an 04t id to be passed to the server. // (see _retrieveSubscriberPackageVersionId for details) - const dependencies = structuredClone(packageDescriptorJson.dependencies); + // can be changed to structuredClone once node18 is the minimum version + const dependencies = JSON.parse(JSON.stringify(packageDescriptorJson.dependencies)) as PackageDirDependency[]; // branch can be set via options or descriptor; option takes precedence this.options.branch = this.options.branch ?? packageDescriptorJson.branch; From 13df132e7cf490d0eb2e04cb132c745f8804b24e Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 7 Nov 2022 09:39:59 -0700 Subject: [PATCH 3/6] chore: change to cloneJson from kit --- src/package/packageVersionCreate.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index 75314d685..e20ede9cf 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -23,6 +23,7 @@ import { ComponentSetBuilder, ConvertResult, MetadataConverter } from '@salesfor import SettingsGenerator from '@salesforce/core/lib/org/scratchOrgSettingsGenerator'; import * as xml2js from 'xml2js'; import { PackageDirDependency } from '@salesforce/core/lib/sfProject'; +import { cloneJson } from '@salesforce/kit'; import { uniqid } from '../utils/uniqid'; import * as pkgUtils from '../utils/packageUtils'; import { BuildNumberToken, VersionNumber } from '../utils'; @@ -368,8 +369,7 @@ export class PackageVersionCreate { // All dependencies for the packaging dir should be resolved to an 04t id to be passed to the server. // (see _retrieveSubscriberPackageVersionId for details) - // can be changed to structuredClone once node18 is the minimum version - const dependencies = JSON.parse(JSON.stringify(packageDescriptorJson.dependencies)) as PackageDirDependency[]; + const dependencies = cloneJson(packageDescriptorJson.dependencies); // branch can be set via options or descriptor; option takes precedence this.options.branch = this.options.branch ?? packageDescriptorJson.branch; @@ -485,7 +485,7 @@ export class PackageVersionCreate { if (excludedProfiles.length > 0) { const profileIdx = typesArr.findIndex((e) => e.name[0] === 'Profile'); - typesArr[profileIdx].members = typesArr[profileIdx].members.filter((e) => excludedProfiles.indexOf(e) === -1); + typesArr[profileIdx].members = typesArr[profileIdx].members.filter((e) => !excludedProfiles.includes(e)); } packageJson.Package.types = typesArr; @@ -663,7 +663,7 @@ export class PackageVersionCreate { const shouldGenerateProfileInformation = this.logger.shouldLog(LoggerLevel.INFO) || this.logger.shouldLog(LoggerLevel.DEBUG); - return await PackageProfileApi.create({ + return PackageProfileApi.create({ project: this.project, includeUserLicenses, generateProfileInformation: shouldGenerateProfileInformation, From 120e05b5a86c4b5ae44f7739c5c2d5af023ba1bd Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Mon, 7 Nov 2022 15:15:01 -0700 Subject: [PATCH 4/6] chore: guard against no deps when cloning --- src/package/packageVersionCreate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index e20ede9cf..80fca5611 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -369,7 +369,7 @@ export class PackageVersionCreate { // All dependencies for the packaging dir should be resolved to an 04t id to be passed to the server. // (see _retrieveSubscriberPackageVersionId for details) - const dependencies = cloneJson(packageDescriptorJson.dependencies); + const dependencies = packageDescriptorJson.dependencies ? cloneJson(packageDescriptorJson.dependencies) : []; // branch can be set via options or descriptor; option takes precedence this.options.branch = this.options.branch ?? packageDescriptorJson.branch; From f789dbe88e948bbf7d5f0302233ea870a93663fe Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 9 Nov 2022 09:54:31 -0700 Subject: [PATCH 5/6] fix: clone entry to include unpackagedMetadata entry, add UT --- src/package/packageVersionCreate.ts | 4 ++-- test/package/packageVersionCreate.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index 30ac08b2d..0a9d856fe 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -328,7 +328,7 @@ export class PackageVersionCreate { // Copy all the metadata from the workspace to a tmp folder const componentSet = await this.generateMDFolderForArtifact(mdOptions); this.verifyHasSource(componentSet); - const packageDescriptorJson = this.packageObject as PackageDescriptorJson; + const packageDescriptorJson = cloneJson(this.packageObject) as PackageDescriptorJson; if (packageDescriptorJson.package) { delete packageDescriptorJson.package; @@ -563,7 +563,7 @@ export class PackageVersionCreate { codeCoverage: boolean ): Promise { // Add the Unpackaged Metadata, if any, to the output directory, only when code coverage is specified - if (codeCoverage && packageDescriptorJson.unpackagedMetadata && packageDescriptorJson.unpackagedMetadata.path) { + if (codeCoverage && packageDescriptorJson.unpackagedMetadata?.path) { const unpackagedPath = path.join(process.cwd(), packageDescriptorJson.unpackagedMetadata.path); if (!fs.existsSync(unpackagedPath)) { throw messages.createError('unpackagedMDDirectoryDoesNotExist', [ diff --git a/test/package/packageVersionCreate.test.ts b/test/package/packageVersionCreate.test.ts index 30b723357..8eab514de 100644 --- a/test/package/packageVersionCreate.test.ts +++ b/test/package/packageVersionCreate.test.ts @@ -46,6 +46,9 @@ describe('Package Version Create', () => { versionNumber: '0.1.0.NEXT', default: true, ancestorId: 'TEST2', + unpackagedMetadata: { + path: 'unpackaged', + }, dependencies: [ { package: 'DEP@0.1.0-1', @@ -142,6 +145,12 @@ describe('Package Version Create', () => { it('should create the package version create request with codecoverage=true', async () => { const pvc = new PackageVersionCreate({ connection, project, codecoverage: true, packageId }); + // @ts-ignore + const hasUnpackagedMdSpy = $$.SANDBOX.spy(pvc, 'resolveUnpackagedMetadata'); + // @ts-ignore + $$.SANDBOX.stub(pvc, 'generateMDFolderForArtifact').resolves(); + $$.SANDBOX.stub(fs, 'existsSync').returns(true); + $$.SANDBOX.stub(fs.promises, 'readFile').resolves(); const result = await pvc.createPackageVersion(); expect(packageCreateStub.firstCall.args[1].CalculateCodeCoverage).to.equal(true); expect(result).to.have.all.keys( @@ -157,6 +166,11 @@ describe('Package Version Create', () => { 'SubscriberPackageVersionId', 'Tag' ); + const unpackagedMD = (hasUnpackagedMdSpy.firstCall.args.at(0) as { unpackagedMetadata: Record }) + .unpackagedMetadata; + expect(unpackagedMD).to.deep.equal({ + path: 'unpackaged', + }); }); it('should create the package version create request with codecoverage=false', async () => { From 04d133344e9303beb529c8dd16b318f963117c72 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 9 Nov 2022 10:08:25 -0700 Subject: [PATCH 6/6] chore: clone at top level only --- src/package/packageVersionCreate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index 0a9d856fe..c5f3365ec 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -372,7 +372,7 @@ export class PackageVersionCreate { // All dependencies for the packaging dir should be resolved to an 04t id to be passed to the server. // (see _retrieveSubscriberPackageVersionId for details) - const dependencies = packageDescriptorJson.dependencies ? cloneJson(packageDescriptorJson.dependencies) : []; + const dependencies = packageDescriptorJson.dependencies; // branch can be set via options or descriptor; option takes precedence this.options.branch = this.options.branch ?? packageDescriptorJson.branch;