From 77870b9a50083b0af26f686517ce035a77219b2a Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Fri, 17 Jun 2022 23:53:55 +0300 Subject: [PATCH] test: fix ci tests --- .gitignore | 6 +++--- package.json | 2 +- src/main/js/publish.js | 10 +++++++--- src/test/js/test-utils.js | 7 ++----- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 4f600db..fdc8357 100644 --- a/.gitignore +++ b/.gitignore @@ -44,9 +44,9 @@ node_modules/ jspm_packages/ # npm creds -.npmrc -.yarnrc -.pnpmrc +**/.npmrc +**/.yarnrc +**/.pnpmrc # TypeScript v1 declaration files typings/ diff --git a/package.json b/package.json index cb8b5b8..2b76c92 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "exports": "./src/main/js/index.js", "type": "module", "scripts": { - "test": "c8 uvu ./src/test -i fixtures -i utils && c8 report -r lcov", + "test": "NPM_REGISTRY='http://localhost:4873' NPM_TOKEN='mRv6eIuiaggXGb9ZDFCtBA==' c8 uvu ./src/test -i fixtures -i utils && c8 report -r lcov", "docs": "mkdir -p docs && cp ./README.md ./docs/README.md" }, "dependencies": { diff --git a/src/main/js/publish.js b/src/main/js/publish.js index 65810a4..8238475 100644 --- a/src/main/js/publish.js +++ b/src/main/js/publish.js @@ -1,5 +1,5 @@ import {formatTag, getLatestTag} from './tag.js' -import {tempy, ctx, fs, path} from 'zx-extra' +import {tempy, ctx, fs, path, $} from 'zx-extra' import {copydir} from 'git-glob-cp' const branches = {} @@ -38,7 +38,7 @@ export const push = async ({cwd, from, to, branch, origin, msg, ignoreFiles}) => await $.raw`git push origin HEAD:refs/heads/${branch}` }) -export const publish = async (pkg, env, registry = 'http://localhost:4873/') => ctx(async ($) => { +export const publish = async (pkg, env) => ctx(async ($) => { const {name, version, files} = pkg.manifest const cwd = pkg.absPath $.cwd = cwd @@ -57,8 +57,12 @@ export const publish = async (pkg, env, registry = 'http://localhost:4873/') => console.log('push artifact to branch `meta`') await push({cwd, from, to, branch: 'meta', msg: `chore: publish artifact ${name} ${version}`, ignoreFiles: '.npmignore'}) + const registry = env.NPM_REGISTRY || 'https://registry.npmjs.org' + const npmrc = path.resolve(cwd, '.npmrc') console.log(`publish npm package to ${registry}`) - await $`npm publish --no-git-tag-version --registry=${registry}` + + await $.raw`echo ${registry.replace(/https?:/, '')}/:_authToken=${$.env.NPM_TOKEN} >> ${npmrc}` + await $`npm publish --no-git-tag-version --registry=${registry} --userconfig ${npmrc} --no-workspaces` }) export const getArtifactPath = (tag) => tag.toLowerCase().replace(/[^a-z0-9-]/g, '-') diff --git a/src/test/js/test-utils.js b/src/test/js/test-utils.js index 48ad253..a005f50 100644 --- a/src/test/js/test-utils.js +++ b/src/test/js/test-utils.js @@ -5,13 +5,10 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)) export const fixtures = path.resolve(__dirname, '../fixtures') export const createNpmRegistry = () => { - const VERDACCIO_TOKEN = 'mRv6eIuiaggXGb9ZDFCtBA==' - $.cwd = path.resolve(__dirname, '../../../') - $.raw`echo "//localhost:4873/:_authToken=${VERDACCIO_TOKEN}" >> .npmrc` - let p + return { - address: 'http://localhost:4873/', + address: $.env.NPM_REGISTRY, async start() { fs.removeSync(path.resolve(__dirname, '../../../storage')) const config = path.resolve(__dirname, '../../../verdaccio.config.yaml')