Skip to content

Commit

Permalink
fix(build): build executables with correct dependency versions (#654)
Browse files Browse the repository at this point in the history
This commit modifies the create-binaries.sh script so that it
removes the packages/validator/node_modules/@IBM-Cloud and
packages/ruleset/node_modules/@IBM-Cloud directories
prior to invoking pkg to build the executables.
This fixes a problem where the executables would end up with
the "old" versions of the openapi-ruleset and
openapi-ruleset-utilities dependencies in situations
where we're also publishing a new version of those dependencies
in the same build.
Removing the dependencies from packages/[validator,ruleset] means
that pkg would end up using the dependencies in the project's
top-level "node_modules" directory instead, which will have the correct
versions of the dependencies, whether or not we've published a new
version of them during the same build.

Signed-off-by: Phil Adams <phil_adams@us.ibm.com>
  • Loading branch information
padamstx committed Mar 22, 2024
1 parent 62c60e3 commit 7b8192d
Show file tree
Hide file tree
Showing 7 changed files with 1,945 additions and 11,796 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"files": "package-lock.json|^.secrets.baseline$",
"lines": null
},
"generated_at": "2023-09-22T21:09:16Z",
"generated_at": "2024-03-22T15:15:27Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -106,7 +106,7 @@
}
]
},
"version": "0.13.1+ibm.61.dss",
"version": "0.13.1+ibm.62.dss",
"word_list": {
"file": null,
"hash": null
Expand Down
13,680 changes: 1,904 additions & 11,776 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions packages/ruleset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
},
"dependencies": {
"@ibm-cloud/openapi-ruleset-utilities": "1.3.1",
"@stoplight/spectral-formats": "^1.5.0",
"@stoplight/spectral-formats": "^1.6.0",
"@stoplight/spectral-functions": "^1.7.2",
"@stoplight/spectral-rulesets": "^1.16.0",
"chalk": "^4.1.1",
"@stoplight/spectral-rulesets": "^1.18.1",
"chalk": "^4.1.2",
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"loglevel": "^1.9.1",
"loglevel-plugin-prefix": "0.8.4",
"minimatch": "^6.1.6",
"validator": "^13.7.0"
"minimatch": "^6.2.0",
"validator": "^13.11.0"
},
"devDependencies": {
"@stoplight/spectral-core": "^1.18.0",
"@stoplight/spectral-core": "^1.18.3",
"jest": "^27.4.5"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pkg": "echo no executables to build in this package"
},
"devDependencies": {
"@stoplight/spectral-core": "^1.18.0",
"@stoplight/spectral-core": "^1.18.3",
"jest": "^27.4.5"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions packages/validator/.releaserc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"branches": "main",
"debug": true,
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
Expand Down
15 changes: 6 additions & 9 deletions packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
},
"dependencies": {
"@ibm-cloud/openapi-ruleset": "1.15.4",
"@stoplight/spectral-cli": "^6.8.0",
"@stoplight/spectral-core": "^1.18.0",
"@stoplight/spectral-parsers": "^1.0.2",
"@stoplight/spectral-cli": "^6.11.0",
"@stoplight/spectral-core": "^1.18.3",
"@stoplight/spectral-parsers": "^1.0.3",
"ajv": "^8.12.0",
"chalk": "^4.1.1",
"commander": "^10.0.0",
"chalk": "^4.1.2",
"commander": "^10.0.1",
"find-up": "5.0.0",
"globby": "^11.0.4",
"js-yaml": "^3.14.1",
"json-dup-key-validator": "^1.0.3",
"lodash": "^4.17.21",
"pad": "^2.3.0",
"semver": "^7.5.3"
"semver": "^7.6.0"
},
"devDependencies": {
"jest": "^27.4.5",
Expand All @@ -50,9 +50,6 @@
"node": ">=16.0.0",
"npm": ">=8.3.0"
},
"pkg": {
"scripts": "src/**/*.js"
},
"jest": {
"collectCoverage": true,
"coverageDirectory": "./coverage/",
Expand Down
24 changes: 23 additions & 1 deletion scripts/create-binaries.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
#!/bin/bash

# Enable shell debug mode so we get a few additional details in the build log.
set -x

# This script will be run when "npm run pkg" is executed from within
# the "packages/validator" directory.
# The commands below assume that the current directory is packages/validator.

# Before creating the executables, we need to remove the "openapi-ruleset"
# and "openapi-ruleset-utilities" dependencies from the packages/validator/node_modules
# and packages/ruleset/node_modules directories (respectively).
# We need to do this because those locations will actually contain the prior version
# of the dependency if we've published a new release of it during the same build.
# By removing them from the packages/[validator,ruleset] directories, we ensure that
# the correct version of these dependencies is obtained from the project's top-level
# node_modules directory instead.
if [[ -e "node_modules/@ibm-cloud" ]]; then
rm -fr "node_modules/@ibm-cloud"
fi

if [[ -e "../ruleset/node_modules/@ibm-cloud" ]]; then
rm -fr "../ruleset/node_modules/@ibm-cloud"
fi

# Create the executables
../../node_modules/.bin/pkg --out-path=./bin ./package.json


# Rename the executables and set their execute bit.
cd ./bin
mv ibm-openapi-validator-macos lint-openapi-macos
mv ibm-openapi-validator-linux lint-openapi-linux
Expand Down

0 comments on commit 7b8192d

Please sign in to comment.