From fd0f04d730e7b844dd6f57a77b21d913b16dd1c9 Mon Sep 17 00:00:00 2001 From: Thomas Caillier <thomascaillier@gmail.com> Date: Sun, 8 Sep 2024 14:56:57 +0000 Subject: [PATCH] fix: set node-publish default registry --- README.md | 4 +++- templates/gitlab-ci-node.yml | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2f352b9..86b11a3 100644 --- a/README.md +++ b/README.md @@ -420,7 +420,9 @@ It uses the following variables: #### Configure the target registry -The target registry url for publication shall be configured in the `publishConfig` of your `package.json` file. Examples: +The target registry url for publication shall be configured in the `publishConfig` of your `package.json` file. \ +If no registry is configured in `publishConfig`, it will publish to default target registry 'https://registry.npmjs.org/' only if `access` is set to 'public' in the `publishConfig` of your `package.json` file. \ +Examples: - for an unscoped package: diff --git a/templates/gitlab-ci-node.yml b/templates/gitlab-ci-node.yml index ccca4df..f446c06 100644 --- a/templates/gitlab-ci-node.yml +++ b/templates/gitlab-ci-node.yml @@ -554,12 +554,14 @@ stages: pkg_fullname=$(node -pe "require('./package.json').name") publish_registry_key=$(node -pe "parts='$pkg_fullname'.split('/');parts.length>1?parts[0]+':registry':'registry'") publish_registry_url=$(node -pe "require('./package.json').publishConfig?.['$publish_registry_key'] || ''") - if [[ -z "$publish_registry_url" ]] + publish_access=$(node -pe "require('./package.json').publishConfig?.access || ''") + if [[ -z "$publish_registry_url" ]] && [[ "$publish_access" != "public" ]] then - log_info "No publish registry url found in your package.json file" + log_info "No publish registry url found in your package.json file, and publish access is not set to public" log_info "Publish will only work if you're using GitLab project-level registry (use scope \\e[33;1m@${CI_PROJECT_ROOT_NAMESPACE}\\e[0m)" - log_info "Otherwise, declare the target registry url under \\e[33;1m'publishConfig' > '$publish_registry_key'\\e[0m key in your package.json file..." + log_info "Otherwise, declare the target registry url under \\e[33;1m'publishConfig' > '$publish_registry_key'\\e[0m key in your package.json file, or set 'public' access under \\e[33;1m'publishConfig' > 'access'\\e[0m to publish on default registry https://registry.npmjs.org/..." else + publish_registry_url="${publish_registry_url:-https://registry.npmjs.org/}" log_info "Publish to \\e[33;1m$publish_registry_url\\e[0m..." # maybe configure token if [[ "$NODE_PUBLISH_TOKEN" ]] @@ -818,7 +820,7 @@ node-sbom: paths: - $NODE_PROJECT_DIR/reports/node-sbom.cyclonedx.json reports: - cyclonedx: + cyclonedx: - $NODE_PROJECT_DIR/reports/node-sbom.cyclonedx.json rules: # exclude if disabled -- GitLab