如何在不实际发布到 NPM 的情况下测试“npm publish"结果? [英] How to test an `npm publish` result, without actually publishing to NPM?

查看:53
本文介绍了如何在不实际发布到 NPM 的情况下测试“npm publish"结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的一个常见问题是,有时我的 .npmignore 文件过于激进,而我忽略了我实际上想要包含在 NPM tarball 中的文件.

One common problem I have, is that sometimes my .npmignore file is too aggressive, and I ignore files that I actually will to include in the NPM tarball.

我的问题是 - 有没有办法测试 NPM 发布的结果,而无需实际发布到 NPM?

My question is - is there a way to test the results of NPM publish, without actually publishing to NPM?

我在想这样的事情.假设我有一个包名为foo"的本地 NPM 包

I am thinking something like this. Assuming I have a local NPM package with package name "foo"

set -e;
local proj="bar";
local path_to_foo="."
mkdir -p "$HOME/.local.npm"
npm --tarball -o "$HOME/.local.npm"  # made up command, but you get the idea
(
  cd "$HOME/.temp_projects"
  rm -rf "$proj"
  mkdir "$proj"
  cd "$proj"
  npm init -f
  npm install "$path_to_foo"
)
copy_test_stuff -o "$HOME/.temp_projects/bar"

cd "$HOME/.temp_projects/bar"
npm test

我认为这行不通.因为我们在 NPM 发布的 tarball 中包含的任何内容可能都不足以进行完整的测试.但也许如果我们在执行 copy_test_stuff 时复制所有测试文件(包括装置等),它可能会起作用吗?

I don't think this will work. Because whatever we include in the NPM publish tarball, might not have enough to do the full test. But maybe if we copy all the test files (including fixtures, etc) when we do copy_test_stuff, it might work?

推荐答案

(2019 答案)

只需运行

npm pack

npm 6 及更高版本中,这将显示将要上传的文件并在当前目录中创建一个 tar 球.

In npm 6 and up, this will display what files are going to be uploaded and create a tar ball in the current directory.

这篇关于如何在不实际发布到 NPM 的情况下测试“npm publish"结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆