我正在使用的脚本部分package.json来强制解决方案:
"preinstall": "npx npm-force-resolutions"
Run Code Online (Sandbox Code Playgroud)
在分辨率部分,我输入graceful-fs了指定的版本:
"resolutions": {
"graceful-fs": "^4.2.4",
},
Run Code Online (Sandbox Code Playgroud)
当我运行npm i一切都正确安装时,会考虑设置版本。但是后来当我安装一个额外的模块时,例如npm i random-package,我的设置版本被扔掉了,我最终得到graceful-fs@1.2.3了一些依赖项中的其他低版本。
如果我清除 node_modules 文件夹并npm i再次运行,一切都会再次正常。
我还尝试将分辨率设置得更具体,例如
"resolutions": {
"glob/**/graceful-fs": "^4.2.4",
},
Run Code Online (Sandbox Code Playgroud)
但这无济于事。
我也试过:
但没有运气。
我错过了什么?
我在使用 Visual Studio Code for Windows 10 时遇到了这个问题:我在资源管理器侧栏中再也看不到 NPM 脚本了。
我删除了所有扩展,卸载了 VS Code,同时取消了它的文件夹和扩展文件夹,再次安装了最新版本的 VS Code,没有自定义选项和扩展,但它没有解决我的问题;NPM 脚本菜单不会出现。
我该如何解决这个问题,以便再次显示 NPM 脚本菜单选项?
有没有办法将命令行参数传递给npm'pre'脚本或运行多个命令的脚本?
假设一个简单的脚本mySexyScript.js只是注销process.argv:
console.log(process.argv);
Run Code Online (Sandbox Code Playgroud)
这有效
使用npm脚本:
...
"scripts": {
....
"sexyscript": "node mySexyScript.js"
....
}
...
Run Code Online (Sandbox Code Playgroud)
运行:
npm run sexyscript -- --foo=bar
Run Code Online (Sandbox Code Playgroud)
参数按预期记录到控制台.
'pre'脚本 - 这不起作用
使用npm脚本:
...
"scripts": {
....
"presexyscript": "node mySexyScript.js"
"sexyscript": "node mySuperSexyScript.js"
....
}
...
Run Code Online (Sandbox Code Playgroud)
运行:
npm run sexyscript -- --foo=bar
Run Code Online (Sandbox Code Playgroud)
参数不会传递给mySexyScript,也不会记录它们
多个命令 - 这也不起作用
使用npm脚本:
...
"scripts": {
....
"sexyscript": "node mySexyScript.js && node mySuperSexyScript.js"
....
}
...
Run Code Online (Sandbox Code Playgroud)
运行:
npm run sexyscript -- --foo=bar
Run Code Online (Sandbox Code Playgroud)
参数不会传递给mySexyScript,也不会记录它们
在 package.json 文件中:
"scripts": {
"dev": "./scripts/dev_parallel.sh",
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试通过输入以下内容来运行 shell 脚本:
npm run dev
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:-
$ npm run dev
./scripts/dev_parallel.sh
'.' is not recognized as an internal or external command, operable program or batch file.
Run Code Online (Sandbox Code Playgroud) 在npm中,如何运行两个或多个并行任务,但是等待第一个任务将创建的资源可供第二个任务使用,等等?
例子(概念):
npm run task1 & waitfor task1 then task2 & waitFor task3 then task4 ...
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
编辑
作为一个例子:让我们说我的第一个任务是启动一个网络服务器,而我的第二个任务是每次事件发生时都从该网络服务器中消耗数据.另一个例子:我的第一个任务可能是启动webdriver-manager,我的第二个任务,启动一个网络服务器,以及我的第三个任务,运行e2e测试我的文件被更改的时间.因此,我需要所有这些任务保持并发运行,但它们需要按特定的顺序和时间进行初始化.
我正在尝试为我的项目测试 npm 包,这样每次我尝试安装模块时,即运行npm install <module> 脚本时,必须在安装该模块之前运行。预安装脚本仅适用于npm install而不适用于npm install <module>.
例如:- 如果运行npm install request。它应该运行一个脚本,在安装模块之前向我显示请求模块的所有依赖项。提前致谢。
我已将所有linting配置和相关的包/插件/预设(用于更漂亮,stylelint,eslint,commitlint)移到npm包中.然后,我在多个项目中使用此包,并将配置扩展或合并到项目的本地配置文件中,以确保一致性,并且无需安装和保持我的开发依赖项是最新的.
除了配置,我还有许多有用的npm脚本,它们运行连接并执行各种其他与开发相关的功能,例如:
"lint:prettier": "prettier 'src/**/*.{js,json}' --write",
"lint:eslint": "eslint 'src/**/*.js'",
"lint:compatibilityCheck": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
"lint": "npm run lint:compatibilityCheck && npm run lint:prettier && npm run lint:eslint"
Run Code Online (Sandbox Code Playgroud)
这些目前在我的所有项目中都是重复的,但我想将这些脚本与我的共享包一起分发,以便在一个位置定义它们.我该怎么做?
我有一个 bash 脚本,可以启动服务器,然后运行一些功能测试。它必须在一个脚本中发生,所以我在后台运行服务器。这一切都通过 2 个 npm 命令发生:start:nolog和test:functional.
都好。但是输出中有很多我不关心的问题:
? ./functional-tests/runInPipeline.sh
(... "good" output here)
> @co/foo@2.2.10 pretest:functional /Users/jcol53/Documents/work/foo
> curl 'http://localhost:3000/foo' -s -f -o /dev/null || (echo 'Website must be running locally for functional tests.' && exit 1)
> @co/foo@2.2.10 test:functional /Users/jcol53/Documents/work/foo
> npm run --prefix functional-tests test:dev:chromeff
> @co/foo-functional-tests@1.0.0 test:dev:chromeff /Users/jcol53/Documents/work/foo/functional-tests
> testcafe chrome:headless,firefox:headless ./tests/**.test.js -r junit:reports/functional-test.junit.xml -r html:reports/functional-test.html --skip-js-errors
Run Code Online (Sandbox Code Playgroud)
那里有很多我不需要的行。我可以抑制@co/foo-functional-tests等行吗?他们没有告诉我任何值得...
npm run -s 杀死命令的所有输出,这不是我要找的。
这可能是不可能的,但这没关系,我很好奇,也许我错过了什么......
既然没有必要package.json用 deno来拥有文件,那么作为开发人员,我怎么能像npm scripts在 in 中一样拥有类似的体验package.json呢?
使用npm或yarn,npm脚本指定的脚本是否可以知道npm脚本本身的名称?例如:
"scripts": {
"foo": "echo Original command: $0",
"bar": "echo Original command: $0"
}
Run Code Online (Sandbox Code Playgroud)
我希望这两个脚本的结果类似于:
Original command: yarn run foo
Original command: yarn run bar
Run Code Online (Sandbox Code Playgroud)
但我实际得到的是:Original command: /bin/sh。
如果它有所不同,它只是我需要的脚本的名称,而不是部分yarn run,所以像这样的输出Original command: foo就可以了。
npm-scripts ×10
npm ×7
node.js ×6
javascript ×2
package.json ×2
deno ×1
dependencies ×1
nodes ×1
npm-install ×1
scripting ×1
yarnpkg ×1