如何配置我的package.json,以便某些软件包只能在Windows上安装?

时间:2016-08-16 21:56:25

标签: node.js windows npm package.json

我正在使用“msnodesqlv8”:“0.2.3”npm包为我的应用程序在Windows上运行一些MSSQL脚本,但在Mac上由于此错误我无法安装所有其他包:

Macbook-Pro jeremy$ npm install
npm ERR! Darwin 15.5.0
npm ERR! argv "/Users/jeremy/.nvm/versions/node/v6.1.0/bin/node" "/Users/jeremy/.nvm/versions/node/v6.1.0/bin/npm" "i"
npm ERR! node v6.1.0
npm ERR! npm  v3.8.6
npm ERR! code EBADPLATFORM

npm ERR! notsup Not compatible with your operating system or architecture: msnodesqlv8@0.2.3
npm ERR! notsup Valid OS:    win32
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   darwin
npm ERR! notsup Actual Arch: x64

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/jeremy/code/lyfeboat/mitchell-sql-feathers/npm-debug.log

有没有办法配置我的package.json,以便在所有非Windows系统上忽略此包?

1 个答案:

答案 0 :(得分:1)

我不确定是否有更好的方法,但我能够使用package.json中的optionalDependencies属性获得所需的行为。

https://docs.npmjs.com/files/package.json#optionaldependencies

以下是我使用的格式:

Import-Module ActiveDirectory
$DaysInactive = 60
$time = (Get-Date).AddDays(-$DaysInactive)

# Get all AD computers with lastLogonTimestamp less than our time
Get-ADComputer -Filter { LastLogonTimeStamp -lt $time -and OperatingSystem -like 'Windows 7 *'} -Properties LastLogonTimeStamp |
    Where-Object { $_.DistinguishedName -notlike '*,OU=COMPUTERS,OU=Quarantine,DC=ad,DC=int,DC=com,*' }

# Output hostname and lastLogonTimestamp into CSV
Select-Object Name, @{ Name = "Stamp"; Expression = { [DateTime]::FromFileTime($_.lastLogonTimestamp) } } |
    Export-Csv OLD_Computer.csv -NoTypeInformation

按预期输出:

...
"optionalDependencies": {
  "msnodesqlv8": "0.2.3"
},
...