我会详细说明我之前发布的评论(感谢 Alexander Mills)。
我是verdaccio 的贡献者,因此,我密切关注谁在实施以及如何实施 verdaccio。我将描述我发现并且可能很有趣或作为有效答案的夫妻或示例(主要是 e2e)。
创建反应应用程序
到目前为止,最流行的集成。让我给你一些背景信息,他们正在使用lerna,并且有多个包需要在发布到主注册表之前进行测试(npmjs)。我会 quote here Dan Abramov 解释他们使用自定义注册表的原因。
script is self-explanatory 但让我强调一些部分。
+nohup npx verdaccio@2.7.2 &>$tmp_registry_log &
+# Wait for `verdaccio` to boot
+grep -q 'http address' <(tail -f $tmp_registry_log)
+
+# Set registry to local registry
+npm set registry http://localhost:4873
+yarn config set registry http://localhost:4873
+
+# Login so we can publish packages
+npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r http://localhost:4873 --quotes
# Test local start command
yarn start --smoke-test
+./tasks/release.sh --yes --force-publish=* --skip-git --cd-version=prerelease --exact --npm-tag=latest
如您所见,他们正在运行verdaccio,而不是他们决定使用npm-cli-login 的自定义配置文件,然后他们针对verdaccio 运行测试。一切准备就绪后,他们会在 verdaccio 上发布。作为最后一步,稍后在同一个文件中,他们使用自己的应用程序获取包。
pnpm
他们创建了一个名为 pnpm-registry-mock 的项目,这是一个抽象,允许他们在运行测试之前运行 verdaccio。
"pretest:e2e": "rimraf ../.tmp/ && rimraf node_modules/.bin/pnpm && pnpm-registry-mock prepare",
"test:e2e": "preview --skip-prepublishOnly && npm-run-all -p -r pnpm-registry-mock test:tap",
"test": "npm run lint && npm run tsc && npm run test:e2e",
基本上,他们使用 npm 脚本准备 verdaccio 并在最后一步运行测试。我不能说太多细节,因为我看到的只是肤浅的。但我知道它的作用。
Mozilla 中微子
我是work in progress,但是,在这里提一下也很有趣。
+if [ "$PROJECT" == "all" ]; then
+ yarn link:all;
+ yarn validate:eslintrc;
+ yarn lint;
+ yarn build;
+ yarn test;
+else
+ yarn verdaccio --config verdaccio.yml & sleep 10;
+ yarn config set registry "http://localhost:4873";
+ npm config set registry "http://localhost:4873";
+ .scripts/npm-adduser.js;
+ yarn lerna publish \
+ --force-publish=* \
+ --skip-git \
+ --skip-npm \
+ --registry http://localhost:4873/ \
+ --yes \
+ --repo-version $(node_modules/.bin/semver -i patch $(npm view neutrino version));
+ yarn lerna exec npm publish --registry http://localhost:4873/;
+ PROJECT="$PROJECT" TEST_RUNNER="$TEST_RUNNER" LINTER="$LINTER" yarn test:create-project;
+fi
同样的方法,正在构建项目,然后正在执行 verdaccio 并发布所有包。
Babel.js
我知道 Babel.js 一直在对 Babel 6 进行冒烟测试,并且拥有 plans to integrate a registry with Babel 7。我quote Henry Zhu early this year talking about babel-smoke-tests 在create-react-app 的同一线程中。
实验名为babel-smoke-tests,babel-smoke-tests/scripts/test.sh 是您的密钥文件。
在这里,我看到了与其他项目相同的模式。他们正在启动verdaccio,然后他们会做他们的事情。
START=$(cd scripts; pwd)/section-start.sh
END=$(cd scripts; pwd)/section-end.sh
$START 'Setting up local npm registry' setup.npm.registry
node_modules/.bin/verdaccio -l localhost:4873 -c verdaccio.yml &
export NPM_CONFIG_REGISTRY=http://localhost:4873/
NPM_LOGIN=$(pwd)/scripts/npm-login.sh
$NPM_LOGIN
$END 'Done setting up local npm registry' setup.npm.registry
scripts/bootstrap.sh
export THEM=$(cd them; pwd)
if [[ $SPECIFIC_TEST ]]; then
scripts/tests/$SPECIFIC_TEST.sh
else
scripts/tests/jquery.sh
scripts/tests/react.sh
fi
总结
首先,我希望我的小型研究能够为您提供解决问题的新思路。我认为npm pack 解决了一些问题,但是使用verdaccio 模拟注册表,这对您来说非常轻巧且易于使用,这可能是一个真正的选择。一些大型项目正在(或开始)使用它,它们或多或少遵循相同的方法。那么,为什么不试试呢? :)
https://www.verdaccio.org/