diff --git a/package.json b/package.json index bb81abcdb..814238284 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "dependencies": { "@oclif/core": "^1.26.1", "@salesforce/core": "^3.32.11", - "@salesforce/kit": "^1.8.4", + "@salesforce/kit": "^1.9.2", "@salesforce/schemas": "^1.5.0", "@salesforce/source-deploy-retrieve": "^7.7.5", "@salesforce/ts-types": "^1.7.1", @@ -58,7 +58,7 @@ "xml2js": "^0.4.23" }, "devDependencies": { - "@salesforce/cli-plugins-testkit": "^3.2.20", + "@salesforce/cli-plugins-testkit": "^3.2.24", "@salesforce/dev-config": "^3.1.0", "@salesforce/dev-scripts": "^4.1.2", "@salesforce/prettier-config": "^0.0.2", diff --git a/src/package/packageVersionCreate.ts b/src/package/packageVersionCreate.ts index c4d0d926d..79e38b1d9 100644 --- a/src/package/packageVersionCreate.ts +++ b/src/package/packageVersionCreate.ts @@ -254,6 +254,7 @@ export class PackageVersionCreate { SourceOrg: this.options.sourceorg, CalculateCodeCoverage: this.options.codecoverage || false, SkipValidation: this.options.skipvalidation || false, + // note: the createRequest's Language corresponds to the AllPackageVersion's language Language: this.options.language, }; @@ -314,6 +315,8 @@ export class PackageVersionCreate { await fs.promises.mkdir(packageVersBlobDirectory, { recursive: true }); const settingsGenerator = new SettingsGenerator({ asDirectory: true }); const packageDescriptorJson = cloneJson(this.packageObject) as PackageDescriptorJson; + const apvLanguage = packageDescriptorJson.language; + // Copy all the metadata from the workspace to a tmp folder const componentSet = await this.metadataResolver.generateMDFolderForArtifact(mdOptions); this.verifyHasSource(componentSet); @@ -323,6 +326,12 @@ export class PackageVersionCreate { packageDescriptorJson.id = this.packageId; } + if (packageDescriptorJson.language) { + // the cloneJson() call above added the packageDir's language to the descriptor; + // remove that from the descriptor here; it will be set correctly from the definitionFile values below + delete packageDescriptorJson.language; + } + const definitionFile = this.options.definitionfile ? this.options.definitionfile : packageDescriptorJson.definitionFile; @@ -344,14 +353,17 @@ export class PackageVersionCreate { throw messages.createError('signupDuplicateSettingsSpecified'); } - ['country', 'edition', 'features', 'orgPreferences', 'snapshot', 'release', 'sourceOrg'].forEach((prop) => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const propValue = definitionFileJson[prop]; - if (propValue) { + // these scratch org definition file values will be applied to the build org + ['country', 'language', 'edition', 'features', 'orgPreferences', 'snapshot', 'release', 'sourceOrg'].forEach( + (prop) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - packageDescriptorJson[prop] = propValue; + const propValue = definitionFileJson[prop]; + if (propValue) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + packageDescriptorJson[prop] = propValue; + } } - }); + ); } this.resolveApexTestPermissions(packageDescriptorJson); @@ -360,9 +372,9 @@ export class PackageVersionCreate { // (see _retrieveSubscriberPackageVersionId for details) const dependencies = packageDescriptorJson.dependencies; - // branch and language can be set via options or descriptor; option takes precedence + // branch and APV language can be set via options or packageDirectory; option takes precedence this.options.branch = this.options.branch ?? packageDescriptorJson.branch; - this.options.language = this.options.language ?? packageDescriptorJson.language; + this.options.language = this.options.language ?? apvLanguage; const resultValues = await Promise.all( !dependencies ? [] : dependencies.map((dependency) => this.retrieveSubscriberPackageVersionId(dependency)) diff --git a/test/package/packageVersionCreate.test.ts b/test/package/packageVersionCreate.test.ts index 87e193184..8a348fe31 100644 --- a/test/package/packageVersionCreate.test.ts +++ b/test/package/packageVersionCreate.test.ts @@ -375,6 +375,36 @@ describe('Package Version Create', () => { ); }); + it("should set the build org language (i.e., package2-descriptor.json's language) from the scratch org definition file's language", async () => { + const scratchOrgDefFileContent = '{ "language": "buildOrgLanguage" }'; + const scratchOrgDefFileName = 'project-scratch-def.json'; + $$.SANDBOX.stub(fs.promises, 'readFile').withArgs(scratchOrgDefFileName).resolves(scratchOrgDefFileContent); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + $$.SANDBOX.stub(MetadataResolver.prototype, 'generateMDFolderForArtifact' as any).resolves(); + $$.SANDBOX.stub(fs, 'existsSync').returns(true); + const writeFileSpy = $$.SANDBOX.spy(fs.promises, 'writeFile'); + + const pvc = new PackageVersionCreate({ connection, project, definitionfile: scratchOrgDefFileName, packageId }); + const result = await pvc.createPackageVersion(); + expect(result).to.have.all.keys( + 'Branch', + 'CreatedBy', + 'CreatedDate', + 'Error', + 'HasMetadataRemoved', + 'Id', + 'Package2Id', + 'Package2VersionId', + 'Status', + 'SubscriberPackageVersionId', + 'Tag' + ); + + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const package2DescriptorJson = writeFileSpy.firstCall.args[1]; // package2-descriptor.json contents + expect(package2DescriptorJson).to.have.string('buildOrgLanguage'); + }); + it('should validate options when package type = unlocked (scripts) - postinstall script', async () => { packageTypeQuery.restore(); // @ts-ignore diff --git a/yarn.lock b/yarn.lock index 1c258360c..5cabb78f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -897,14 +897,14 @@ mv "~2" safe-json-stringify "~1" -"@salesforce/cli-plugins-testkit@^3.2.20": - version "3.2.20" - resolved "https://registry.yarnpkg.com/@salesforce/cli-plugins-testkit/-/cli-plugins-testkit-3.2.20.tgz#15f0e3a50e2242c482bb89fb18464473f8cc2cbc" - integrity sha512-EOKTZQrTiyZWPUKwbjZTJf9UvLlUrnXGN2qDgi65S7OH4W/bR1syRlrVDJ8w/F5mSqKaExhGGoFviycRrWrW8g== +"@salesforce/cli-plugins-testkit@^3.2.24": + version "3.2.24" + resolved "https://registry.yarnpkg.com/@salesforce/cli-plugins-testkit/-/cli-plugins-testkit-3.2.24.tgz#4a57f4ed5549ad908bc13ab05cb8c17e683f1a8a" + integrity sha512-FhP8s0aerfDax8+ZNx0u8BKG1jau+Iyci9jCcdmWlT6gcc06zQWBlRCNsRbjF9rWyiAeSEB1ObTYpVUzVQkFUw== dependencies: - "@salesforce/core" "^3.33.1" - "@salesforce/kit" "^1.8.0" - "@salesforce/ts-types" "^1.7.2" + "@salesforce/core" "^3.33.6" + "@salesforce/kit" "^1.9.0" + "@salesforce/ts-types" "^1.7.3" "@types/shelljs" "^0.8.11" archiver "^5.2.0" debug "^4.3.1" @@ -912,16 +912,16 @@ strip-ansi "6.0.1" ts-retry-promise "^0.7.0" -"@salesforce/core@^3.32.11", "@salesforce/core@^3.32.13", "@salesforce/core@^3.33.1": - version "3.33.1" - resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.33.1.tgz#3dd0a44ba22763e8e0c2c97df03393e5c2c845d9" - integrity sha512-jaed8rK+NhSxB6MjYUN8f/2VkvtbFN/Ce/l6JvgFE+cvOf2g+lPv1pSsnKKlaSiiYcXkOvIRDT9d9ns1RLJzUw== +"@salesforce/core@^3.32.11", "@salesforce/core@^3.32.13", "@salesforce/core@^3.33.6": + version "3.33.6" + resolved "https://registry.yarnpkg.com/@salesforce/core/-/core-3.33.6.tgz#48a3e8c708f4a0ed153e5e2d43c343fd5bf2c923" + integrity sha512-HxA0OIt6NSMdZwu2X7wIru8OJN8x8XxNiazXpLNW5MUi9rBupBAWYNROjDMPilxBgnoiBcJ5I84xdl+jWD3vqA== dependencies: "@salesforce/bunyan" "^2.0.0" - "@salesforce/kit" "^1.8.0" - "@salesforce/schemas" "^1.4.0" + "@salesforce/kit" "^1.9.0" + "@salesforce/schemas" "^1.5.0" "@salesforce/ts-types" "^1.7.2" - "@types/graceful-fs" "^4.1.5" + "@types/graceful-fs" "^4.1.6" "@types/semver" "^7.3.13" ajv "^8.11.2" archiver "^5.3.0" @@ -980,12 +980,12 @@ typescript "^4.1.3" wireit "^0.9.5" -"@salesforce/kit@^1.8.0", "@salesforce/kit@^1.8.4": - version "1.8.4" - resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.8.4.tgz#19918938d5f89ecb4e78a363b38605a529bcd7d4" - integrity sha512-H2KWT2soWEDf+QbcMLYBNt2iHEEDIihxoWufphu8FGySiAibEZcl2SPZJ87nbUW/Yu+dLqPEKTUZxvDEx7t3UQ== +"@salesforce/kit@^1.8.0", "@salesforce/kit@^1.9.0", "@salesforce/kit@^1.9.2": + version "1.9.2" + resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-1.9.2.tgz#d232f135428363cdfe2649cb99a94bc2eb0a12fd" + integrity sha512-kjZvjFNP6njhAiEa/ErdLXSDWZKafHYJyKCKz1wnSFmDM8TOpKHCCVw5cQo87ZQr8OqxqwUDIAlSBLyMzKi4Lg== dependencies: - "@salesforce/ts-types" "^1.7.2" + "@salesforce/ts-types" "^1.7.3" shx "^0.3.3" tslib "^2.5.0" @@ -994,7 +994,7 @@ resolved "https://registry.yarnpkg.com/@salesforce/prettier-config/-/prettier-config-0.0.2.tgz#ded39bf7cb75238edc9db6dd093649111350f8bc" integrity sha512-KExM355BLbxCW6siGBV7oUOotXvvVp0tAWERgzUkM2FcMb9fWrjwXDrIHc8V0UdDlA3UXtFltDWgN+Yqi+BA/g== -"@salesforce/schemas@^1.4.0", "@salesforce/schemas@^1.5.0": +"@salesforce/schemas@^1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@salesforce/schemas/-/schemas-1.5.0.tgz#8bfe2cb5d7cb29d3394b3b9cfb71bb527009c82c" integrity sha512-EKFBURBuON7cj8XZCW+ybeSRRw7wUP1XUXZVHzFgx8KiYmSeGiRHBYbDjQOsQMho2uOLsTozMPEt2ehYnji0YA== @@ -1207,10 +1207,10 @@ dependencies: globby "*" -"@types/graceful-fs@^4.1.5": - version "4.1.5" - resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15" - integrity sha512-anKkLmZZ+xm4p8JWBf4hElkM4XR+EZeA2M9BAkkTldmcyDY4mbdIJnRghDJH3Ov5ooY7/UAoENtmdMSkaAd7Cw== +"@types/graceful-fs@^4.1.6": + version "4.1.6" + resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.6.tgz#e14b2576a1c25026b7f02ede1de3b84c3a1efeae" + integrity sha512-Sig0SNORX9fdW+bQuTEovKj3uHcUL6LQKbCrrqb1X7J6/ReAbhCXRAhc+SMejhLELFj2QcyuxmUooZ4bt5ReSw== dependencies: "@types/node" "*"