From 2bd7441a7b87efc7065170298ea4a17eb85f6269 Mon Sep 17 00:00:00 2001 From: Joram van den Boezem Date: Thu, 8 Dec 2022 11:13:45 +0100 Subject: [PATCH] chore: more logging --- .github/workflows/release.yml | 2 +- CHANGELOG.md | 4 +-- src/get-registry.ts | 66 +++++++++++++++++++++++++++++------ src/get-yarn-config.ts | 2 +- test/get-registry.test.ts | 38 ++++++++++++++------ 5 files changed, 87 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4663e60d..9967dd2e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,5 +19,5 @@ jobs: - run: yarn build - run: yarn release env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.GH_PAT }} YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8859c9bb..88389ff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ ## [0.2.1](https://github.com/hongaar/semantic-release-yarn/compare/v0.2.0...v0.2.1) (2022-12-07) - ### Bug Fixes -* don't run husky install on postinstall ([6d541a4](https://github.com/hongaar/semantic-release-yarn/commit/6d541a479afdf63062c51d05ba414d2477421f2b)) +- don't run husky install on postinstall + ([6d541a4](https://github.com/hongaar/semantic-release-yarn/commit/6d541a479afdf63062c51d05ba414d2477421f2b)) # [0.2.0](https://github.com/hongaar/semantic-release-yarn/compare/v0.1.1...v0.2.0) (2022-12-07) diff --git a/src/get-registry.ts b/src/get-registry.ts index daa68a21..b61d7e14 100644 --- a/src/get-registry.ts +++ b/src/get-registry.ts @@ -1,23 +1,69 @@ import type { PackageJson } from "read-pkg"; -import { DEFAULT_NPM_REGISTRY } from "./definitions/constants.js"; +import { + DEFAULT_NPM_REGISTRY, + YARNRC_FILENAME, +} from "./definitions/constants.js"; import type { CommonContext } from "./definitions/context.js"; import type { Yarnrc } from "./definitions/yarnrc.js"; export function getRegistry( { publishConfig }: PackageJson, { npmRegistryServer, npmPublishRegistry }: Yarnrc, - { env }: { env?: CommonContext["env"] } + { + env, + logger, + }: { env: CommonContext["env"]; logger: CommonContext["logger"] } ) { const publishConfigRegistry = publishConfig?.["registry"] as | string | undefined; - return ( - publishConfigRegistry || - env?.["YARN_NPM_PUBLISH_REGISTRY"] || - npmPublishRegistry || - env?.["YARN_NPM_REGISTRY_SERVER"] || - npmRegistryServer || - DEFAULT_NPM_REGISTRY - ); + if (publishConfigRegistry) { + logger.log( + `Using registry "%s" from "package.json: publishConfig.registry"`, + publishConfigRegistry + ); + + return publishConfigRegistry; + } + + if (env["YARN_NPM_PUBLISH_REGISTRY"]) { + logger.log( + `Using registry "%s" from environment variable YARN_NPM_PUBLISH_REGISTRY`, + env["YARN_NPM_PUBLISH_REGISTRY"] + ); + + return env["YARN_NPM_PUBLISH_REGISTRY"]; + } + + if (npmPublishRegistry) { + logger.log( + `Using registry "%s" from "${YARNRC_FILENAME}: npmPublishRegistry"`, + npmPublishRegistry + ); + + return npmPublishRegistry; + } + + if (env["YARN_NPM_REGISTRY_SERVER"]) { + logger.log( + `Using registry "%s" from environment variable YARN_NPM_REGISTRY_SERVER`, + env["YARN_NPM_REGISTRY_SERVER"] + ); + + return env["YARN_NPM_REGISTRY_SERVER"]; + } + + if (npmRegistryServer) { + logger.log( + `Using registry "%s" from "${YARNRC_FILENAME}: npmRegistryServer"`, + npmRegistryServer + ); + + return npmRegistryServer; + } + + logger.log(`Using default registry "%s"`, DEFAULT_NPM_REGISTRY); + + return DEFAULT_NPM_REGISTRY; } diff --git a/src/get-yarn-config.ts b/src/get-yarn-config.ts index e51cb757..c506e75a 100644 --- a/src/get-yarn-config.ts +++ b/src/get-yarn-config.ts @@ -23,7 +23,7 @@ export async function getYarnConfig({ return {}; } - logger.log("Reading yarn config from %s", result.files.join(", ")); + logger.log('Reading yarn config from "%s"', result.files.join(", ")); return result.config; } diff --git a/test/get-registry.test.ts b/test/get-registry.test.ts index 4211a770..1e9ae9e8 100644 --- a/test/get-registry.test.ts +++ b/test/get-registry.test.ts @@ -1,39 +1,44 @@ import test from "ava"; import { getRegistry } from "../src/get-registry.js"; +import { createContext } from "./helpers/create-context.js"; test("Get default registry", async (t) => { - t.is(getRegistry({}, {}, {}), "https://registry.npmjs.org"); + const context = createContext(); + + t.is(getRegistry({}, {}, context), "https://registry.npmjs.org"); t.is( - getRegistry({ publishConfig: {} }, {}, {}), + getRegistry({ publishConfig: {} }, {}, context), "https://registry.npmjs.org" ); t.is( - getRegistry({}, { npmPublishRegistry: "" }, {}), + getRegistry({}, { npmPublishRegistry: "" }, context), "https://registry.npmjs.org" ); t.is( - getRegistry({}, { npmRegistryServer: "" }, {}), + getRegistry({}, { npmRegistryServer: "" }, context), "https://registry.npmjs.org" ); - t.is(getRegistry({}, {}, { env: {} }), "https://registry.npmjs.org"); + t.is(getRegistry({}, {}, context), "https://registry.npmjs.org"); t.is( - getRegistry({}, {}, { env: { YARN_NPM_PUBLISH_REGISTRY: "" } }), + getRegistry({}, {}, { ...context, env: { YARN_NPM_PUBLISH_REGISTRY: "" } }), "https://registry.npmjs.org" ); t.is( - getRegistry({}, {}, { env: { YARN_NPM_REGISTRY_SERVER: "" } }), + getRegistry({}, {}, { ...context, env: { YARN_NPM_REGISTRY_SERVER: "" } }), "https://registry.npmjs.org" ); }); test("Get registry from yarnrc", async (t) => { + const context = createContext(); + t.is( getRegistry( {}, { npmPublishRegistry: "https://custom1.registry.com", }, - {} + context ), "https://custom1.registry.com" ); @@ -43,7 +48,7 @@ test("Get registry from yarnrc", async (t) => { { npmRegistryServer: "https://custom1.registry.com", }, - {} + context ), "https://custom1.registry.com" ); @@ -54,18 +59,21 @@ test("Get registry from yarnrc", async (t) => { npmPublishRegistry: "https://custom1.registry.com", npmRegistryServer: "https://custom2.registry.com", }, - {} + context ), "https://custom1.registry.com" ); }); test("Get registry from environment variables", async (t) => { + const context = createContext(); + t.is( getRegistry( {}, {}, { + ...context, env: { YARN_NPM_PUBLISH_REGISTRY: "https://custom1.registry.com" }, } ), @@ -76,6 +84,7 @@ test("Get registry from environment variables", async (t) => { {}, {}, { + ...context, env: { YARN_NPM_REGISTRY_SERVER: "https://custom1.registry.com" }, } ), @@ -86,6 +95,7 @@ test("Get registry from environment variables", async (t) => { {}, {}, { + ...context, env: { YARN_NPM_PUBLISH_REGISTRY: "https://custom1.registry.com", YARN_NPM_REGISTRY_SERVER: "https://custom2.registry.com", @@ -97,17 +107,21 @@ test("Get registry from environment variables", async (t) => { }); test("Get registry from publishConfig", async (t) => { + const context = createContext(); + t.is( getRegistry( { publishConfig: { registry: "https://custom1.registry.com" } }, {}, - {} + context ), "https://custom1.registry.com" ); }); test("Precedence: publishConfig > environment variables > yarnrc", async (t) => { + const context = createContext(); + t.is( getRegistry( { publishConfig: { registry: "https://custom1.registry.com" } }, @@ -115,6 +129,7 @@ test("Precedence: publishConfig > environment variables > yarnrc", async (t) => npmPublishRegistry: "https://custom2.registry.com", }, { + ...context, env: { YARN_NPM_PUBLISH_REGISTRY: "https://custom3.registry.com", }, @@ -129,6 +144,7 @@ test("Precedence: publishConfig > environment variables > yarnrc", async (t) => npmPublishRegistry: "https://custom1.registry.com", }, { + ...context, env: { YARN_NPM_PUBLISH_REGISTRY: "https://custom2.registry.com", },