Skip to content

Commit

Permalink
Versioning the retail react app (#1209)
Browse files Browse the repository at this point in the history
* more fixes for out of sync package / lockfiles

* add missing pwa-kit packages

* Fix regex matching patterns (#1057)

* resolve package lock errors

* clean console logs and code

* more cleanup, remove duplicate items in overrideregex

* upgrade minimatch version, match all file extensions, match with no file extension

* fix dependency dupes

* Remove all console logs / cleanup / unnecessary code

* fix some problems with final cleanup

* merge

* remove stress test files post-merge

* added pdp page override with small customization

* add constants file to spike project and tweak overrides values

* Fix bug where `<path>/dir/index.(js|jsx|etc)` was being picked up by template extensibility, but `<path>/dir/non-index-name.(js|jsx|etc)` was not

* fix package.json scripts

* fix falsy value defaulting causing errors in `path.join` fix broken `npm run push`

* delete `build/loadable-stat.json` from git, gitignore should work from there

* fix some file pathing issues in how SDK looks up default / universal / project components

* Perf enhancements, don't use regex all (.*) for module replacement, reduce conditional logic execution

* minor code style tweak

* cleanup

* initial work on moving code to use resolver

* fix getoverridepath and break on ^ imports

* add todos and comments

* rewrite requestcontext.request for path with caret

* perform overrideshashmap lookup for relative import

* progress

* fix conflicts

* fix package lockfiles that were out of sync

* Revert "fix package lockfiles that were out of sync"

This reverts commit 7f3c364.

* progress

* fix out of sync lockfiles

* merge conflict

* resolve merge conflict

* update spike project's engines / regen v3 lockfiles

* regenerate lock files

* add missing node engines

* add missing useToast (bad merge)

* updates from underlying template-retail-react-app

* drop unnecessary pages/product-detail override

* fix dupe useToast

* progress on making `charles-solution` work

* initial pass at migration to `resolver.getHook('resolve').tapAsync` working, TODO next... cleanup

* restore icons file and add extensible text to home

* add some comments and construct hashmap in new plugin

* working glob sync lookup??

* resolve lookup when there is no extension

* add component slot for testing

* fix some lookup errors

* migrate to new directory

* remove unnecessary directory nesting, remove unnecessary files for "minimum file project"

* add example of extending routes non-destructively, add example of quickly toggling some base constant values (e.g. categories shown on home page)

* Update example route

* add some demo examples of overrides

* cleanup

* commit package name change

* rewrite requests coming from underlying template

* cleanup

* rename plugin file

* remove unnecessary build files

* rename to overrides

* fix lookup errors

* fix some broken upstream changes, eslint fixes

* fix bad merge conflict

* Bring back the deleted package.json

* Install new eslint plugin

* No more relative imports in retail-react-app

* Create .prettierrc.yaml

* restore other deleted package lockfiles

* fix some eslint issues

* remove `^` imports and begin migrating logic away from previous API. TODO: get webpack to resolve `retail-react-app` base import path from within `template-retail-react-app`

* bring back deleted package lockfiles

* short circuit plugin temporarily, get webpack `alias` working for template to resolve self-referencing `retail-react-app` imports

* fix unreachable condition

* wow... freaking works 🚀

* cleanup, get `template-retail-react-app` working again

* cleanup

* Create .eslintrc.js

* fix routes.jsx which no longer pulled relative template

* make routes.jsx more concise

* update lockfiles

* add jsconfig.json for IDEs to have magic `retail-react-app` be discoverable

* more cleanup

* change package.json key from `mobify` => `ccExtensibility`

* cleanup

* Final cleanup, remove console.logs, make `extendable` dynamic for internal file resolution in `template-retail-react-app` (and future projects), remove some non-required files,

* fix straggler non-dynamic filepath

* cleanup

* remove code that shouldn't be in v3+

* bump-version script ignores the retail-react-app

* See if this `--pre-dist-tag` works as expected

* Clean up code

* Add todo

* sync package.json deps in extended example project

* cleanup / pr feedback

* Update npm scripts

* Disable `npm install` step

* List the packages' versions for easy review

* Fix bug with versioning the root package file

* A bit of refactoring

* Some clean up

* pr feedback, great catch @kevinxh

* fix problem with bad copy from underlying template file

* pr feedback / cleanup

* cleanup

Co-authored-by: Kevin He <kevin.he@salesforce.com>

* Update package-lock.json

* WIP

* drop unneeded complexity

* lockfiles

* moving toward an array of `alias`es

* Generator: try downloading retail-react-app@latest from npm

* Some refactoring

* Refactor template extensibility functionality to use `resolve.alias` + greatly reduce code footprint + make leading slash optional in `ccExtensibility.overridesDir`

* Tweak the versioning logic

* These are optional options

* Use a new npm tag for testing purpose

* add brand-logo with no clash for server side viewBox

* add `request-processor.js` (required for worker.js to load) and fix bad extensibility path loading in `build-dev-server.js`

* Add some comments

* Install shelljs

* retail-react-app: version updates scoped to this directory only

* Update versioning logic in the root

* retail-react-app: simplify the versioning logic

* fake sdk release v3

* fake release of retail-react-app v1

* lint fix

* fix failing pwa-kit-react-sdk tests

* cleanup

* regen package lockfiles

* lint:fix

* Explore publishing certain packages only

* Revert "fake release of retail-react-app v1"

This reverts commit f8dcaa0.

* Revert "fake sdk release v3"

This reverts commit 3aad2da.

* fix failing tests in CI re: `TextDecoder is not defined`

* take 2 attempting to fix TextDecoder global in jest

* fix jest module mapper

* fix jest moduleMapper config

* REALLY fix jest moduleNameMapper config for new pathing + fix node `util` global TextDecoder is not defined in jest

* add brand-logo

* remove previously added `AbovePDP` Template Hook component

* replay #1128 from bad merge

* eslint:fix for `retail-react-app` base paths

* de-duplicate deps in bundle

* fix path defaulting, don't pass nullish value to path.resolve

* improve pathing for overridesDir in pwa-kit-dev webapack config + add missing worker/main.js

* fix pathing

* fix pathing issue that was mysteriously UNFIXED

* fix `worker.js` path

* Now also increment the pre-release version of the templates

* Now allows for publishing one package only to npm

* fix app/static pathing in non-extensible builds

* Make sure Lerna uses the exact versions (without carrot)

* Update package.json

* What I expect to see from Ben's work

* Some refactoring

* Scale to multiple independent packages

* Make sure version updates are synced throughout

* Some refactoring

* Remove commented lines

* No need to do version-pinning ourselves

Because we now call `lerna version --exact`.

* Add eslint and prettier

* Move script to allow reuse by future templates

* [Extensibility] Remove Einstein proxy and send Einstein events directly from app (#1202)

* Remove Einstein proxy and send Einstein events directly from app

* Update ssrParameters

* Replace ExtendsCircularImportsPlugin with OverridesResolverPlugin (#1211)

* Replace ExtendsCircularImportsPlugin with OverridesResolverPlugin

* fix filepath problem

---------

Co-authored-by: Brian Feister <bfeister@salesforce.com>

* Move `npm install` to the publishing step

* Update console log

* Prep for fixing a bug

* Updating a package version checks deps in other packages

* remove irrelevant bundlesize check to pass CI

* Extract shared util functions

* Consistency: add newline to EOF

* Get the name of the current package

* Fix `vendor.js` inclusion of `retail-react-app` files (#1198)

* fix duplicate lilbs in bundle

* fix app/static pathing for non-extensible builds

* oof, fix extensible app/static filepaths

* Resolve conflicting npm deps via `resolve.alias`

* add missing worker/main.js

* cleanup unused imports

* WIP, add list of original overridable deps

* prevent template extensibility vendor.js from treating baseline route files as deps in vendor.js

* fix irrelevant bundlesize declaration to pass CI

* drop test:max-file-size test from my-extended-retail-app

* replace relative with absolute path fetchTranslations (#1215)

Co-authored-by: Brian Feister <47546998+bfeister@users.noreply.github.com>

* For now, make this package private

It's going to be deleted anyways in the near-future.

* Iterate over the other packages only

* Exclude these npm scripts from the smoke test

* Handle scenario of an SDK package with independent version

* Refactor for unit testing, fix pathing issue from old version of file parsing algoritihim

* Add a 'sync' version of the script

* Tweak conditions

* Some refactoring

* Some refactoring

* Script to run a local npm registry

* Add todos for bug fixes

* Verify where the npm registry is

* Ignore this linting error

* Update regex

* Add comments

* Checks for clean working tree

* Handle uncommitted changes

* Make sure to update the package lock files

* If error, make sure to still clean up

* Install from the root

* Some refactoring

* No longer needing this install step

Now that we've run install in earlier steps.

* For safety

* If not on CI, make sure to publish to local npm

In order to avoid accidental publishing to remote npm registry.

* Only exit if there's an error

* remove demo extensible app in light of soon-to-be-merged PR from @bendvc

* lockfiles from reaact18 / chakra2

* Feature/template extensibility (#1162)

* initial work on moving code to use resolver

* fix getoverridepath and break on ^ imports

* add todos and comments

* rewrite requestcontext.request for path with caret

* perform overrideshashmap lookup for relative import

* progress

* progress

* regenerate lock files

* fix dupe useToast

* progress on making `charles-solution` work

* initial pass at migration to `resolver.getHook('resolve').tapAsync` working, TODO next... cleanup

* restore icons file and add extensible text to home

* add some comments and construct hashmap in new plugin

* working glob sync lookup??

* resolve lookup when there is no extension

* add component slot for testing

* fix some lookup errors

* cleanup

* rewrite requests coming from underlying template

* cleanup

* rename plugin file

* remove unnecessary build files

* rename to overrides

* fix lookup errors

* fix some broken upstream changes, eslint fixes

* Bring back the deleted package.json

* Install new eslint plugin

* No more relative imports in retail-react-app

* Create .prettierrc.yaml

* restore other deleted package lockfiles

* fix some eslint issues

* remove `^` imports and begin migrating logic away from previous API. TODO: get webpack to resolve `retail-react-app` base import path from within `template-retail-react-app`

* short circuit plugin temporarily, get webpack `alias` working for template to resolve self-referencing `retail-react-app` imports

* fix unreachable condition

* wow... freaking works 🚀

* cleanup, get `template-retail-react-app` working again

* cleanup

* Create .eslintrc.js

* fix routes.jsx which no longer pulled relative template

* make routes.jsx more concise

* update lockfiles

* add jsconfig.json for IDEs to have magic `retail-react-app` be discoverable

* more cleanup

* change package.json key from `mobify` => `ccExtensibility`

* cleanup

* Final cleanup, remove console.logs, make `extendable` dynamic for internal file resolution in `template-retail-react-app` (and future projects), remove some non-required files,

* fix straggler non-dynamic filepath

* cleanup

* remove code that shouldn't be in v3+

* sync package.json deps in extended example project

* cleanup / pr feedback

* pr feedback, great catch @kevinxh

* fix problem with bad copy from underlying template file

* pr feedback / cleanup

* cleanup

Co-authored-by: Kevin He <kevin.he@salesforce.com>

* Update package-lock.json

* WIP

* drop unneeded complexity

* lockfiles

* moving toward an array of `alias`es

* Refactor template extensibility functionality to use `resolve.alias` + greatly reduce code footprint + make leading slash optional in `ccExtensibility.overridesDir`

* add brand-logo with no clash for server side viewBox

* add `request-processor.js` (required for worker.js to load) and fix bad extensibility path loading in `build-dev-server.js`

* lint fix

* fix failing pwa-kit-react-sdk tests

* cleanup

* lint:fix

* fix failing tests in CI re: `TextDecoder is not defined`

* take 2 attempting to fix TextDecoder global in jest

* fix jest module mapper

* fix jest moduleMapper config

* REALLY fix jest moduleNameMapper config for new pathing + fix node `util` global TextDecoder is not defined in jest

* add brand-logo

* remove previously added `AbovePDP` Template Hook component

* replay #1128 from bad merge

* eslint:fix for `retail-react-app` base paths

* de-duplicate deps in bundle

* fix path defaulting, don't pass nullish value to path.resolve

* improve pathing for overridesDir in pwa-kit-dev webapack config + add missing worker/main.js

* fix pathing

* fix pathing issue that was mysteriously UNFIXED

* fix `worker.js` path

* fix app/static pathing in non-extensible builds

* [Extensibility] Remove Einstein proxy and send Einstein events directly from app (#1202)

* Remove Einstein proxy and send Einstein events directly from app

* Update ssrParameters

* Replace ExtendsCircularImportsPlugin with OverridesResolverPlugin (#1211)

* Replace ExtendsCircularImportsPlugin with OverridesResolverPlugin

* fix filepath problem

---------

Co-authored-by: Brian Feister <bfeister@salesforce.com>

* remove irrelevant bundlesize check to pass CI

* Fix `vendor.js` inclusion of `retail-react-app` files (#1198)

* fix duplicate lilbs in bundle

* fix app/static pathing for non-extensible builds

* oof, fix extensible app/static filepaths

* Resolve conflicting npm deps via `resolve.alias`

* add missing worker/main.js

* cleanup unused imports

* WIP, add list of original overridable deps

* prevent template extensibility vendor.js from treating baseline route files as deps in vendor.js

* fix irrelevant bundlesize declaration to pass CI

* drop test:max-file-size test from my-extended-retail-app

* replace relative with absolute path fetchTranslations (#1215)

Co-authored-by: Brian Feister <47546998+bfeister@users.noreply.github.com>

* Refactor for unit testing, fix pathing issue from old version of file parsing algoritihim

* fix merge conflict resolution

* remove template extensible demo in prep for @bendvc's pr for generator work

* regen lockfiles for react 18 changes

* fix linting

---------

Co-authored-by: yunakim714 <yunakim@salesforce.com>
Co-authored-by: Vincent Marta <vmarta@salesforce.com>
Co-authored-by: Kevin He <kevin.he@salesforce.com>
Co-authored-by: vcua-mobify <vcua@salesforce.com>
Co-authored-by: vcua-mobify <47404250+vcua-mobify@users.noreply.github.com>
Co-authored-by: Alex Vuong <52219283+alexvuong@users.noreply.github.com>
Co-authored-by: Alex Vuong <alex.vuong@salesforce.com>

* support windows file paths

* Remove package

* Make sure versions are all 3.0.0-dev

* Update package lock files

* Follow up to recent merge conflicts

* Revert these changes to the generator

* Fix issue with failed tests because of react query dev tools

* Let the output of `npm version` pass through

* Revert "Let the output of `npm version` pass through"

This reverts commit 33b3058.

* Make sure to `npm install` after updating dependencies

* Prepare to consolidate all of the versioning scripts

And move them to the root of monorepo.

* Move the rest of scripts into the monorepo root

* commerce-sdk-react now has its own version

* Use correct package name

* Add todos

* Reconsider where to do `npm install`

* Clean up

* Remove todo

* Remove unused dependency

* Some code cleanup

* Move the versioning scripts into their own folder

* Delete run-local-npm.js

---------

Co-authored-by: Brian Feister <bfeister@salesforce.com>
Co-authored-by: yunakim714 <yunakim@salesforce.com>
Co-authored-by: Yuna Kim <84923642+yunakim714@users.noreply.github.com>
Co-authored-by: Brian Feister <47546998+bfeister@users.noreply.github.com>
Co-authored-by: Kevin He <kevin.he@salesforce.com>
Co-authored-by: vcua-mobify <vcua@salesforce.com>
Co-authored-by: vcua-mobify <47404250+vcua-mobify@users.noreply.github.com>
Co-authored-by: Alex Vuong <52219283+alexvuong@users.noreply.github.com>
Co-authored-by: Alex Vuong <alex.vuong@salesforce.com>
Co-authored-by: Ben Chypak <bchypak@salesforce.com>
  • Loading branch information
11 people authored May 29, 2023
1 parent f871e86 commit 2983781
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 58 deletions.
6 changes: 1 addition & 5 deletions .github/actions/publish_to_npm/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ inputs:
runs:
using: composite
steps:
# TODO: Figure out a way to specify whether to publish to "latest" or "next" tag
- name: Publish to NPM
run: |-
# Add NPM token to allow publishing
echo "//registry.npmjs.org/:_authToken=${{ inputs.NODE_AUTH_TOKEN }}" > ~/.npmrc
# Publish all changed packages. The "from-package" arg means "look
# at the version numbers in each package.json file and if that doesn't
# exist on NPM, publish"
npm run lerna -- publish from-package --yes --no-verify-access
npm run publish-to-npm
# Cleanup
rm ~/.npmrc
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
env:
GENERATOR_PRESET: ${{ matrix.template }}
timeout-minutes: 7
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "pwa-kit",
"version": "3.0.0-dev",
"scripts": {
"bump-version": "node ./scripts/bump-version.js",
"bump-version": "node ./scripts/bump-version/index.js",
"bump-version:retail-react-app": "node ./scripts/bump-version/index.js --package=retail-react-app",
"bump-version:commerce-sdk-react": "node ./scripts/bump-version/index.js --package=commerce-sdk-react-preview",
"publish-to-npm": "node ./scripts/publish-to-npm.js",
"format": "lerna run --stream format",
"preinstall": "node ./scripts/check-version.js",
"postinstall": "node ./scripts/bootstrap.js",
Expand Down
1 change: 1 addition & 0 deletions packages/template-retail-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "retail-react-app",
"version": "3.0.0-dev",
"license": "See license in LICENSE",
"author": "cc-pwa-kit@salesforce.com",
"ccExtensibility": {
"extendable": ["retail-react-app"]
},
Expand Down
10 changes: 10 additions & 0 deletions scripts/.eslintrc.js
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')]
}
7 changes: 7 additions & 0 deletions scripts/.prettierrc.yaml
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'
50 changes: 0 additions & 50 deletions scripts/bump-version.js

This file was deleted.

47 changes: 47 additions & 0 deletions scripts/bump-version/independent-pkg-version.js
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()
129 changes: 129 additions & 0 deletions scripts/bump-version/index.js
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)
58 changes: 58 additions & 0 deletions scripts/bump-version/pwa-kit-deps-version.js
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()
Loading

0 comments on commit 2983781

Please sign in to comment.