Skip to content

Commit

Permalink
[nx] Upgrade lerna version, now powered by nx
Browse files Browse the repository at this point in the history
Add local-publish script that rebuilds and publishes only the
subset of packages required for your target package. Backed by
nx so build outputs are cached if no changes!

Change-Id: I490a90d67b3e936c9e9d3edc68f75557606c02ac
  • Loading branch information
chungwu committed Jan 7, 2023
1 parent aa1f3fd commit 8131cdb
Show file tree
Hide file tree
Showing 7 changed files with 1,611 additions and 1,083 deletions.
1 change: 1 addition & 0 deletions .nxignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ npm --registry=http://localhost:4873 adduser

1. Make some changes!

1. If you're ready to test, run `yarn local-canary`. This builds canary versions of your packages to your local registry.
1. If you're ready to test, run `yarn local-publish YOURPKG`. This unpublishes YOURPKG and its dependencies from your verdaccio, re-builds them, and publishes them to your local verdaccio. Note that this does not bump versions! We are using nx under the hood, so if your dependencies haven't changed, this should be fast.

1. Install the canary version into wherever you're trying to test, via `yarn add ... --registry=http://localhost:4873`

Expand Down
18 changes: 18 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"options": {
"cacheableOperations": ["build", "test"]
}
}
},
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
},
"publish": {
"dependsOn": "build"
}
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"private": true,
"devDependencies": {
"if-env": "^1.0.4",
"lerna": "^4.0.0",
"lerna": "^6.3.0",
"prettier": "2.3.0"
},
"scripts": {
"bootstrap": "lerna bootstrap --force-local && lerna link && lerna run build",
"release": "echo 'Use the jenkins job release_public_packages instead: https://jenkins.aws.plasmic.app/job/release_public_packages/'",
"bump": "echo 'Use the jenkins job release_public_packages instead: https://jenkins.aws.plasmic.app/job/release_public_packages/'",
"local-canary": "yarn local-unpublish && lerna publish --canary --yes --include-merged-tags --no-git-tag-version --no-push --registry=http://localhost:4873 --force-publish",
"local-publish": "lerna exec -- npm publish --registry=http://localhost:4873",
"local-publish": "./scripts/local-publish.sh",
"local-unpublish": "lerna exec -- npm unpublish -f --registry=\"http://localhost:4873/\" \"\\${LERNA_PACKAGE_NAME}\"",
"deps": "lerna list --include-dependencies --scope"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/host/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"module": "dist/host.esm.js",
"nx": {
"targets": {
"build": {
"inputs": [
"{projectRoot}/**/*",
"!{projectRoot}/**/dist/**/*"
]
}
}
},
"files": [
"dist",
"registerComponent",
Expand Down
17 changes: 17 additions & 0 deletions scripts/local-publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#/bin/bash

pkg=$1

echo "Locally publishing $pkg"

# First, locally unpublish
./node_modules/.bin/lerna exec --loglevel=silent --scope "$pkg" --include-dependencies -- npm --registry=http://localhost:4873 unpublish -f "${LERNA_PACKAGE_NAME}"

# Next, build the packages using nx
./node_modules/.bin/lerna exec --loglevel=silent --scope "$pkg" --include-dependencies -- yarn nx build

# Finally, locally publish, skipping the build step
export PREPARE_NO_BUILD=true
./node_modules/.bin/lerna exec --loglevel=silent --scope "$pkg" --include-dependencies -- npm publish --registry=http://localhost:4873

unset PREPARE_NO_BUILD
Loading

0 comments on commit 8131cdb

Please sign in to comment.