From e9d28eb5a1a9aca2058b18f8fd8dbcd2146c309c Mon Sep 17 00:00:00 2001 From: Jeff Goldschrafe Date: Thu, 29 Dec 2022 12:46:30 -0500 Subject: [PATCH] feat: add full support for SEMANTIC_RELEASE_PACKAGE, non-JS packages --- src/index.js | 4 ++-- src/only-package-commits.js | 6 +++--- src/package-info.js | 14 ++++++++++++++ src/version-to-git-tag.js | 4 ++-- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/package-info.js diff --git a/src/index.js b/src/index.js index 0e94a9f..1251686 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,8 @@ -const readPkg = require('read-pkg'); const { compose } = require('ramda'); const withOnlyPackageCommits = require('./only-package-commits'); const versionToGitTag = require('./version-to-git-tag'); const logPluginVersion = require('./log-plugin-version'); +const { getPackageInfoSync } = require('./package-info'); const { wrapStep } = require('semantic-release-plugin-decorators'); const { @@ -59,5 +59,5 @@ module.exports = { generateNotes, success, fail, - tagFormat: readPkg.sync().name + '-v${version}', + tagFormat: getPackageInfoSync().name + '-v${version}', }; diff --git a/src/only-package-commits.js b/src/only-package-commits.js index 306064e..3cb3fb4 100644 --- a/src/only-package-commits.js +++ b/src/only-package-commits.js @@ -1,10 +1,10 @@ const { identity, memoizeWith, pipeP } = require('ramda'); const pkgUp = require('pkg-up'); -const readPkg = require('read-pkg'); const path = require('path'); const pLimit = require('p-limit'); const debug = require('debug')('semantic-release:monorepo'); const { getCommitFiles, getRoot } = require('./git-utils'); +const { getPackageInfo } = require('./package-info'); const { mapCommits } = require('./options-transforms'); const memoizedGetCommitFiles = memoizeWith(identity, getCommitFiles); @@ -13,7 +13,7 @@ const memoizedGetCommitFiles = memoizeWith(identity, getCommitFiles); * Get the normalized PACKAGE root path, relative to the git PROJECT root. */ const getPackagePath = async () => { - const packagePath = await pkgUp(); + const packagePath = await pkgUp() || './package.json'; const gitRoot = await getRoot(); return path.relative(gitRoot, path.resolve(packagePath, '..')); @@ -68,7 +68,7 @@ const tapA = fn => async x => { }; const logFilteredCommitCount = logger => async ({ commits }) => { - const { name } = await readPkg(); + const { name } = await getPackageInfo(); logger.log( 'Found %s commits for package %s since last release', diff --git a/src/package-info.js b/src/package-info.js new file mode 100644 index 0000000..97248e1 --- /dev/null +++ b/src/package-info.js @@ -0,0 +1,14 @@ +const readPkg = require('read-pkg'); + +const getPackageInfo = async () => ({ + name: process.env.SEMANTIC_RELEASE_PACKAGE || (await readPkg()).name, +}); + +const getPackageInfoSync = () => ({ + name: process.env.SEMANTIC_RELEASE_PACKAGE || readPkg.sync().name, +}); + +module.exports = { + getPackageInfo, + getPackageInfoSync, +}; diff --git a/src/version-to-git-tag.js b/src/version-to-git-tag.js index 884b2fe..56dd038 100644 --- a/src/version-to-git-tag.js +++ b/src/version-to-git-tag.js @@ -1,10 +1,10 @@ -const readPkg = require('read-pkg'); +const { getPackageInfo } = require('./package-info') module.exports = async version => { if (!version) { return null; } - const { name } = await readPkg(); + const name = (await getPackageInfo()).name; return `${name}-v${version}`; };