-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Versioning the retail react app #1209
Changes from all commits
e2bb649
f4790fc
e18076c
694104e
7664191
2e1ec7f
80e29f9
389a1df
a456791
de04c3e
d1ca004
c843b5c
f675074
478276d
89795cc
d7f8861
71c037c
c7e9be5
1306b57
3f8939e
f650221
a5d3f01
2eecb75
3766818
24bb5c3
1b42d87
6fd8cdd
7f3c364
f0900d5
9a2252c
f4e332e
b2cad1d
b4ef5b9
93727d1
d664877
a11bbcc
34dc3f0
ca6a625
3863783
c562975
cee6d04
dfb656b
5f364df
cc30d3a
a22ef36
74f1d24
8b80436
b388e56
6541b8f
a654ef3
2cb9cce
fcd183b
7adceb1
de69faa
592931e
9e4b187
32e0ae0
c751bbf
d287a16
1dcb461
a8b593d
9d79b8e
6ebbe1a
38f3b92
be3bb04
0cb80f4
2b726b9
1ae6125
940565a
e76ee0a
1f9ac65
7345439
f9b1477
71f21b2
16cca08
4fcbf92
a8d9021
d3f6860
ef25c00
f0bed51
856427d
e8cc5b4
f2ce238
24622a6
6df83a6
edacf34
1862c9e
20c3042
69fcd79
240a9d5
78b6c53
4241eab
7bac071
dbaba8b
06cb1f0
98c382b
29e6e58
c3fa1f3
29f5bfc
ebf716d
13ff1bf
a827459
9b39529
b8fe972
02eb090
4014396
a33de20
50b2f09
67623a2
7eea73f
2d33647
148ea0a
4543a4d
11701dc
e1aabf1
c6b5e1f
2fe771e
83f07fe
7e3b678
95488be
8b6f5fb
a92b6ef
7c3030c
a29cc07
bdc1cfb
7367fd7
9fe7f69
d96c107
ce151a1
034e2d7
c9b13c4
c680256
e0cbc17
937fc25
253874f
ee66828
3aad2da
f8dcaa0
a0086fd
a9ec4bf
2afa605
94308c5
2c6be38
de5fd5c
5cb9f44
42a8bc1
342f294
13a7c26
58becd0
344a65e
e7eba97
79a1b55
e0c6c4b
e750b29
f5b14d0
65293a2
a9fae57
f382362
eafa3b1
151b96b
61e32b8
868f9b2
fe7c3ce
bf921b9
1115294
bef1c95
0622c8c
74d1191
2250b4e
fe78312
a45c24b
34bcdac
509b145
335b52b
06cbf0c
c432be9
fdda4b4
a73346d
3fa148b
915ced6
3e57e0b
dd5ba30
412c3f8
ac0e092
b2de157
b3d3ac1
3a9419e
6a53a96
ee25ccd
5195a2b
371dd71
d429521
8795667
bddb532
0ddd790
f074f3f
8524c0f
f5ce28b
e1b5bfd
8e73a02
d3407b3
20c9c9d
0a8d6fb
1af6712
49f3338
bf77140
bc774ea
534778c
e9fac09
7efe707
00b17ea
86de1b7
2a655a1
ea214fe
b29cb1f
ecb73d1
d6f64ce
116942b
f8501e2
88b26c1
7dafb99
9585094
e2c82d1
851366a
2b40687
911f1f9
9bd5fea
1b05f2c
c5f97b7
7e82d8e
c8a2b92
31ae716
33b3058
cbf8768
8c06d52
31cb7a8
2ecacca
9c2e3db
49cc1c4
61eceb3
315be52
e1059c2
8053cfa
1612d55
95a5cba
3210576
bb3fc73
7f66aec
0fcf9f3
6ea4a4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,7 +272,7 @@ jobs: | |
|
||
- name: Generate ${{ matrix.template }} project | ||
run: |- | ||
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir generated-${{ matrix.template }} | ||
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir ${{ env.PROJECT_DIR }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just some refactoring to make it consistent with what's happening in that file. |
||
env: | ||
GENERATOR_PRESET: ${{ matrix.template }} | ||
timeout-minutes: 7 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"name": "retail-react-app", | ||
"version": "3.0.0-dev", | ||
"license": "See license in LICENSE", | ||
"author": "[email protected]", | ||
"ccExtensibility": { | ||
"extendable": ["retail-react-app"] | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
module.exports = { | ||
extends: [require.resolve('../packages/pwa-kit-dev/dist/configs/eslint/no-react')] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding some eslint and prettier rules for the root's scripts folder. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
printWidth: 100 | ||
singleQuote: true | ||
semi: false | ||
bracketSpacing: false | ||
tabWidth: 4 | ||
arrowParens: 'always' | ||
trailingComma: 'none' |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* Copyright (c) 2023, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const sh = require('shelljs') | ||
const path = require('path') | ||
const {saveJSONToFile, setPackageVersion} = require('../utils') | ||
|
||
// Exit upon error | ||
sh.set('-e') | ||
|
||
const monorepoPackages = JSON.parse(sh.exec('lerna list --all --json', {silent: true})) | ||
|
||
const pathToPackage = (packageName) => { | ||
const pkg = monorepoPackages.find((pkg) => pkg.name === packageName) | ||
return pkg?.location | ||
} | ||
|
||
// Meant for setting the version of a package that has its own independent version | ||
const main = () => { | ||
const version = process.argv[2] | ||
const pkgName = process.argv[3] | ||
const otherPackages = monorepoPackages.filter((pkg) => pkg.name !== pkgName) | ||
|
||
setPackageVersion(version, {cwd: pathToPackage(pkgName)}) | ||
|
||
// Update other packages who depend on the current package | ||
otherPackages.forEach(({location}) => { | ||
const pathToPkgJson = path.join(location, 'package.json') | ||
const pkgJson = JSON.parse(sh.cat(pathToPkgJson)) | ||
|
||
if (pkgJson.dependencies?.[pkgName]) { | ||
pkgJson.dependencies[pkgName] = version | ||
} else if (pkgJson.devDependencies?.[pkgName]) { | ||
pkgJson.devDependencies[pkgName] = version | ||
} | ||
|
||
saveJSONToFile(pkgJson, pathToPkgJson) | ||
}) | ||
} | ||
|
||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* Copyright (c) 2023, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const sh = require('shelljs') | ||
const path = require('path') | ||
const program = require('commander') | ||
const {saveJSONToFile, setPackageVersion} = require('../utils') | ||
|
||
// Exit upon error | ||
sh.set('-e') | ||
|
||
const rootPath = path.join(__dirname, '..', '..') | ||
const lernaConfigPath = path.join(rootPath, 'lerna.json') | ||
|
||
const monorepoPackages = JSON.parse(sh.exec('lerna list --all --json', {silent: true})) | ||
const monorepoPackageNames = monorepoPackages.map((pkg) => pkg.name) | ||
|
||
const INDEPENDENT_PACKAGES = ['retail-react-app', 'commerce-sdk-react-preview'] | ||
const independentPackages = INDEPENDENT_PACKAGES.map((pkgName) => | ||
monorepoPackages.find((pkg) => pkg.name === pkgName) | ||
) | ||
|
||
/** | ||
* @param {import('commander').CommanderStatic} program | ||
*/ | ||
const main = (program) => { | ||
const targetVersion = program.args[0] | ||
if (!targetVersion) { | ||
program.help() | ||
} | ||
|
||
const opts = program.opts() | ||
if (opts.package !== 'sdk') { | ||
// Assume that we're bumping the version of package that has its own independent version | ||
|
||
const script1 = path.join(__dirname, 'independent-pkg-version.js') | ||
sh.exec(`node ${script1} ${targetVersion} ${opts.package}`) | ||
|
||
const script2 = path.join(__dirname, 'pwa-kit-deps-version.js') | ||
const updateDepsBehaviour = /-dev\b/.test(targetVersion) ? 'sync' : 'latest' | ||
sh.exec(`node ${script2} ${updateDepsBehaviour} ${opts.package}`) | ||
|
||
// After updating the dependencies, let's update the package lock files | ||
sh.exec('npm install') | ||
|
||
process.exit(0) | ||
} | ||
|
||
sh.exec(`lerna version --exact --no-push --no-git-tag-version --yes ${targetVersion}`) | ||
// `--exact` above is for pinning the version of the pwa-kit dependencies | ||
// https://github.com/lerna/lerna/tree/main/libs/commands/version#--exact | ||
|
||
const lernaConfig = JSON.parse(sh.cat(lernaConfigPath)) | ||
const newMonorepoVersion = lernaConfig.version | ||
|
||
// update versions for root package and root package lock | ||
setPackageVersion(newMonorepoVersion, {cwd: rootPath}) | ||
|
||
independentPackages.forEach((pkg) => { | ||
const {location, version: oldVersion} = pkg | ||
// Restore and then increment to the next pre-release version | ||
// TODO: is it possible to _not_ trigger the lifecycle scripts? See CHANGELOG.md | ||
setPackageVersion(oldVersion, {cwd: location}) | ||
setPackageVersion('prerelease', {cwd: location}) | ||
|
||
const newVersion = JSON.parse(sh.exec('npm pkg get version', {cwd: location, silent: true})) | ||
pkg.version = newVersion | ||
}) | ||
|
||
// Now that all of the package version updates are done, | ||
// let's make sure some dependencies' versions are updated accordingly | ||
monorepoPackages.forEach(({location}) => { | ||
const pathToPkgJson = path.join(location, 'package.json') | ||
const pkgJson = JSON.parse(sh.cat(pathToPkgJson)) | ||
|
||
updatePeerDeps(pkgJson, newMonorepoVersion) | ||
updateDeps(pkgJson) | ||
|
||
saveJSONToFile(pkgJson, pathToPkgJson) | ||
}) | ||
|
||
// After updating the dependencies, let's update the package lock files | ||
sh.exec('npm install') | ||
|
||
sh.echo('\nVersions of packages in the monorepo:\n') | ||
sh.exec('lerna list --all --long') | ||
} | ||
|
||
const updatePeerDeps = (pkgJson, newMonorepoVersion) => { | ||
const peerDependencies = pkgJson.peerDependencies | ||
if (!peerDependencies) return | ||
|
||
Object.keys(peerDependencies).forEach((dep) => { | ||
if (monorepoPackageNames.includes(dep)) { | ||
console.log(`Found lerna local package ${dep} as a peer dependency of ${pkgJson.name}.`) | ||
peerDependencies[dep] = `^${newMonorepoVersion}` | ||
} | ||
}) | ||
} | ||
|
||
const updateDeps = (pkgJson) => { | ||
independentPackages.forEach((independentPkg) => { | ||
const newVersion = independentPkg.version | ||
|
||
if (pkgJson.dependencies?.[independentPkg.name]) { | ||
pkgJson.dependencies[independentPkg.name] = newVersion | ||
} else if (pkgJson.devDependencies?.[independentPkg.name]) { | ||
pkgJson.devDependencies[independentPkg.name] = newVersion | ||
} | ||
}) | ||
} | ||
|
||
program.description('Bump the version of a package in our monorepo') | ||
program.arguments('<target-version>') | ||
|
||
program.option( | ||
'-p, --package <package-name>', | ||
'the package name or an alias to a group of packages', | ||
'sdk' | ||
) | ||
|
||
program.parse(process.argv) | ||
main(program) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2023, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const sh = require('shelljs') | ||
const path = require('path') | ||
const {saveJSONToFile} = require('../utils') | ||
|
||
// Exit upon error | ||
sh.set('-e') | ||
|
||
const publicPackages = JSON.parse(sh.exec('lerna list --json', {silent: true})) | ||
|
||
const pathToPackage = (packageName) => { | ||
const pkg = publicPackages.find((pkg) => pkg.name === packageName) | ||
return pkg?.location | ||
} | ||
|
||
// Assuming that this is run within a specific package, | ||
// the script would update its pwa-kit/sdk dependencies. | ||
const main = () => { | ||
const updateBehaviour = process.argv[2] | ||
const packageName = process.argv[3] | ||
|
||
const pathToPackageJson = path.join(pathToPackage(packageName), 'package.json') | ||
const pkgJson = JSON.parse(sh.cat(pathToPackageJson)) | ||
|
||
if (updateBehaviour === 'latest') { | ||
publicPackages.forEach(({name}) => { | ||
if (pkgJson.dependencies?.[name]) { | ||
pkgJson.dependencies[name] = getLatestVersion(name) | ||
} else if (pkgJson.devDependencies?.[name]) { | ||
pkgJson.devDependencies[name] = getLatestVersion(name) | ||
} | ||
}) | ||
} else if (updateBehaviour === 'sync') { | ||
// Sync version with what's in the monorepo | ||
publicPackages.forEach(({version, name}) => { | ||
if (pkgJson.dependencies?.[name]) { | ||
pkgJson.dependencies[name] = version | ||
} else if (pkgJson.devDependencies?.[name]) { | ||
pkgJson.devDependencies[name] = version | ||
} | ||
}) | ||
} | ||
|
||
saveJSONToFile(pkgJson, pathToPackageJson) | ||
} | ||
|
||
const getLatestVersion = (pkgName) => { | ||
return sh.exec(`npm info ${pkgName}@latest version`, {silent: true}).trim() | ||
} | ||
|
||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is resolved. Now our script would correctly assign the npm tag
latest
ornext
:pwa-kit/scripts/publish-to-npm.js
Line 68 in 88b26c1