feat: init

This commit is contained in:
Zoltan Kochan
2018-02-19 01:35:53 +02:00
commit 7cdcd48715
15 changed files with 3345 additions and 0 deletions

11
.editorconfig Normal file
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
.gitattributes vendored Normal file
View File

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

21
.gitignore vendored Normal file
View File

@@ -0,0 +1,21 @@
# 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/
.store

2
.npmrc Normal file
View File

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

15
.travis.yml Normal file
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
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
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'
const pnpmConfigs = getConfigs()
```
## License
[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io/)

57
package.json Normal file
View File

@@ -0,0 +1,57 @@
{
"name": "@pnpm/config",
"version": "0.0.0",
"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",
"camelcase": "^4.1.0",
"npm-conf": "^1.1.3"
},
"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": "^4.0.0",
"tslint": "^5.8.0",
"typescript": "^2.6.2"
},
"mos": {
"plugins": [
"readme"
],
"installation": {
"useShortAlias": true
}
}
}

6
renovate.json Normal file
View File

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

3015
shrinkwrap.yaml Normal file
View File

File diff suppressed because it is too large Load Diff

85
src/index.ts Normal file
View File

@@ -0,0 +1,85 @@
import camelcase = require('camelcase')
import loadNpmConf = require('npm-conf')
import npmTypes = require('npm-conf/lib/types')
import path = require('path')
export const types = Object.assign({
'background': Boolean,
'child-concurrency': Number,
'fetching-concurrency': Number,
'global-path': path,
'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,
'port': Number,
'prefer-offline': Boolean,
'protocol': ['auto', 'tcp', 'ipc'],
'reporter': String,
'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 (
opts: {
cliArgs: object,
packageManager: {
name: string,
version: string,
},
},
) => {
const packageManager = opts && opts.packageManager || {name: 'pnpm', version: 'undefined'}
const cliArgs = opts && opts.cliArgs || {}
const npmConfig = loadNpmConf()
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 : npmConfig.prefix
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
}

7
test/index.ts Normal file
View File

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

24
tsconfig.json Normal file
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
}
}

44
tslint.json Normal file
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
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;
}