feat: add @pnpm/config

This commit is contained in:
Zoltan Kochan
2018-05-13 16:39:36 +03:00
15 changed files with 3339 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
root = true
[*]
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
[*.{ts,js,json}]
indent_style = space
indent_size = 2

3
packages/config/.gitattributes vendored Normal file
View File

@@ -0,0 +1,3 @@
* text eol=lf
*.tgz binary

23
packages/config/.gitignore vendored Normal file
View File

@@ -0,0 +1,23 @@
# Logs
logs
*.log
npm-debug.log*
# Dependency directory
node_modules
# Coverage directory used by tools like istanbul
coverage
fixtures
.tmp
_docpress
lib
# Visual Studio Code configs
.vscode/
# JetBrains IDEs
.idea/
.store

2
packages/config/.npmrc Normal file
View File

@@ -0,0 +1,2 @@
tag-version-prefix =
message = chore(release): %s

View File

@@ -0,0 +1,15 @@
language: node_js
node_js:
- 4
- 6
- 8
- 9
sudo: false
before_install:
- curl -L https://unpkg.com/@pnpm/self-installer | node
install:
- pnpm install
script:
- npm test
notifications:
email: false

21
packages/config/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 Zoltan Kochan <z@kochan.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

25
packages/config/README.md Normal file
View File

@@ -0,0 +1,25 @@
# @pnpm/config
> Gets configs for pnpm
<!--@shields('npm', 'travis')-->
[![npm version](https://img.shields.io/npm/v/@pnpm/config.svg)](https://www.npmjs.com/package/@pnpm/config) [![Build Status](https://img.shields.io/travis/pnpm/config/master.svg)](https://travis-ci.org/pnpm/config)
<!--/@-->
## Installation
```sh
npm i -S @pnpm/config
```
## Usage
```ts
import getConfigs from '@pnpm/config'
getConfigs().then(pnpmConfigs => console.log(pnpmConfigs))
```
## License
[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io/)

View File

@@ -0,0 +1,59 @@
{
"name": "@pnpm/config",
"version": "0.3.1",
"description": "Gets configs for pnpm",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
"lib"
],
"scripts": {
"prepublishOnly": "npm run tsc",
"tsc": "rimraf lib && tsc",
"lint": "tslint -c tslint.json --project .",
"test": "npm run lint && preview && ts-node test && mos t"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pnpm/config.git"
},
"keywords": [
"pnpm",
"config"
],
"engines": {
"node": ">=4"
},
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/pnpm/config/issues"
},
"homepage": "https://github.com/pnpm/config#readme",
"dependencies": {
"@types/camelcase": "^4.1.0",
"@types/node": "^9.4.6",
"@types/which": "^1.3.1",
"camelcase": "^4.1.0",
"npm-conf": "^1.1.3",
"which": "^1.3.0"
},
"devDependencies": {
"mos": "^2.0.0-alpha.3",
"mos-plugin-readme": "^1.0.4",
"package-preview": "^1.0.1",
"rimraf": "^2.6.2",
"tape": "^4.8.0",
"ts-node": "^5.0.0",
"tslint": "^5.8.0",
"typescript": "^2.6.2"
},
"mos": {
"plugins": [
"readme"
],
"installation": {
"useShortAlias": true
}
}
}

View File

@@ -0,0 +1,6 @@
{
"extends": [
"config:base"
],
"pinVersions": false
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
import camelcase = require('camelcase')
import loadNpmConf = require('npm-conf')
import npmTypes = require('npm-conf/lib/types')
import path = require('path')
import whichcb = require('which')
function which (cmd: string) {
return new Promise<string>((resolve, reject) => {
whichcb(cmd, (err: Error, resolvedPath: string) => err ? reject(err) : resolve(resolvedPath))
})
}
export const types = Object.assign({
'background': Boolean,
'child-concurrency': Number,
'fetching-concurrency': Number,
'frozen-shrinkwrap': Boolean,
'global-path': path,
'global-pnpmfile': String,
'ignore-pnpmfile': Boolean,
'ignore-stop-requests': Boolean,
'ignore-upload-requests': Boolean,
'independent-leaves': Boolean,
'lock': Boolean,
'lock-stale-duration': Number,
'network-concurrency': Number,
'offline': Boolean,
'package-import-method': ['auto', 'hardlink', 'reflink', 'copy'],
'pending': Boolean,
'pnpmfile': String,
'port': Number,
'prefer-frozen-shrinkwrap': Boolean,
'prefer-offline': Boolean,
'protocol': ['auto', 'tcp', 'ipc'],
'reporter': String,
'shamefully-flatten': Boolean,
'shrinkwrap-only': Boolean,
'side-effects-cache': Boolean,
'side-effects-cache-readonly': Boolean,
'store': path,
'store-path': path, // DEPRECATE! store should be used
'use-store-server': Boolean,
'verify-store-integrity': Boolean,
}, npmTypes.types)
export default async (
opts: {
cliArgs: object,
packageManager: {
name: string,
version: string,
},
},
) => {
const packageManager = opts && opts.packageManager || {name: 'pnpm', version: 'undefined'}
const cliArgs = opts && opts.cliArgs || {}
// This is what npm does as well, overriding process.execPath with the resolved location of Node.
// The value of process.execPath is changed only for the duration of config initialization.
// Otherwise, npmConfig.globalPrefix would sometimes have the bad location.
//
// TODO: use this workaround only during global installation
const originalExecPath = process.execPath
try {
const node = await which(process.argv[0])
if (node.toUpperCase() !== process.execPath.toUpperCase()) {
process.execPath = node
}
} catch (err) {} // tslint:disable-line:no-empty
const npmConfig = loadNpmConf()
process.execPath = originalExecPath
if (!cliArgs['user-agent']) {
cliArgs['user-agent'] = `${packageManager.name}/${packageManager.version} npm/? node/${process.version} ${process.platform} ${process.arch}`
}
const pnpmConfig: any = Object.keys(types) // tslint:disable-line
.reduce((acc, configKey) => {
acc[camelcase(configKey)] = typeof cliArgs[configKey] !== 'undefined'
? cliArgs[configKey]
: npmConfig.get(configKey)
return acc
}, {})
pnpmConfig.rawNpmConfig = Object.assign.apply(Object, npmConfig.list.reverse().concat([cliArgs]))
pnpmConfig.globalBin = process.platform === 'win32'
? npmConfig.globalPrefix
: path.resolve(npmConfig.globalPrefix, 'bin')
pnpmConfig.bin = pnpmConfig.global
? pnpmConfig.globalBin
: path.join(npmConfig.localPrefix, 'node_modules', '.bin')
pnpmConfig.globalPrefix = path.join(npmConfig.globalPrefix, 'pnpm-global')
pnpmConfig.prefix = pnpmConfig.global
? pnpmConfig.globalPrefix
: (cliArgs['prefix'] ? path.resolve(cliArgs['prefix']) : npmConfig.localPrefix) // tslint:disable-line
pnpmConfig.packageManager = packageManager
if (pnpmConfig.only === 'prod' || pnpmConfig.only === 'production' || !pnpmConfig.only && pnpmConfig.production) {
pnpmConfig.production = true
pnpmConfig.development = false
} else if (pnpmConfig.only === 'dev' || pnpmConfig.only === 'development') {
pnpmConfig.production = false
pnpmConfig.development = true
pnpmConfig.optional = false
} else {
pnpmConfig.production = true
pnpmConfig.development = true
}
if (!pnpmConfig.packageLock && pnpmConfig.shrinkwrap) {
pnpmConfig.shrinkwrap = false
}
return pnpmConfig
}

View File

@@ -0,0 +1,7 @@
import getConfigs from '@pnpm/config'
import test = require('tape')
test('getConfigs()', async (t) => {
t.ok(await getConfigs())
t.end()
})

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"removeComments": false,
"preserveConstEnums": true,
"sourceMap": true,
"declaration": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"allowSyntheticDefaultImports": true,
"strictNullChecks": true,
"target": "es6",
"outDir": "lib",
"module": "commonjs",
"moduleResolution": "node"
},
"include": [
"src/**/*.ts",
"typings/**/*.d.ts"
],
"atom": {
"rewriteTsconfig": true
}
}

View File

@@ -0,0 +1,44 @@
{
"extends": "tslint:recommended",
"rules": {
"curly": false,
"eofline": false,
"align": [true, "parameters"],
"class-name": true,
"indent": [true, "spaces"],
"max-line-length": false,
"no-any": true,
"no-consecutive-blank-lines": true,
"no-trailing-whitespace": true,
"no-duplicate-variable": true,
"no-var-keyword": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-requires": true,
"no-require-imports": false,
"space-before-function-paren": [true, "always"],
"interface-name": [true, "never-prefix"],
"no-console": false,
"one-line": [true,
"check-else",
"check-whitespace",
"check-open-brace"],
"quotemark": [true,
"single",
"avoid-escape"],
"semicolon": false,
"typedef-whitespace": [true, {
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}],
"whitespace": [true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"]
}
}

9
packages/config/typings/index.d.ts vendored Normal file
View File

@@ -0,0 +1,9 @@
declare module 'npm-conf' {
const anything: any;
export = anything;
}
declare module 'npm-conf/lib/types' {
const anything: any;
export = anything;
}