Files
pnpm/src/api/extendStoreStatusOptions.ts
Emanuele Tamponi fdad157392 feat: --shamefully-flatten (#42)
* feat: this is a best attempt at flattening the dependency tree, similar to what npm does

* test: shamefullyFlatten option

* feat: when uninstalling, if shamefully-flatten is true, we need to re-flatten

* fix: use new shrinkwrap, not the old one

* fix: changes suggested in PR

* test: remove test.only

* fix: various bugs in uninstall and general install, added tests

* test: fix test

* test: use project.has and project.hasNot correctly

* test: remove test.only

* test: added tsconfig.json, added lint-test script, lint fixes

* test: use correct message

* fix: check should work on windows too
2018-02-22 01:04:44 +02:00

76 lines
2.0 KiB
TypeScript

import path = require('path')
import logger from '@pnpm/logger'
import pnpmPkgJson from '../pnpmPkgJson'
import {LAYOUT_VERSION} from '../fs/modulesController'
import normalizeRegistryUrl = require('normalize-registry-url')
import {StoreController} from 'package-store'
import { ReporterFunction } from '../types'
import { ReadPackageHook } from '@pnpm/types'
export type StoreStatusOptions = {
prefix?: string,
store: string,
independentLeaves?: boolean,
force?: boolean,
global?: boolean,
registry?: string,
shrinkwrap?: boolean,
reporter?: ReporterFunction,
production?: boolean,
development?: boolean,
optional?: boolean,
bin?: string,
shamefullyFlatten?: boolean,
}
export type StrictStoreStatusOptions = StoreStatusOptions & {
prefix: string,
store: string,
independentLeaves: boolean,
force: boolean,
global: boolean,
registry: string,
bin: string,
shrinkwrap: boolean,
shamefullyFlatten: boolean,
}
const defaults = async (opts: StoreStatusOptions) => {
const prefix = opts.prefix || process.cwd()
return <StrictStoreStatusOptions>{
global: false,
store: opts.store,
bin: path.join(prefix, 'node_modules', '.bin'),
prefix,
force: false,
registry: 'https://registry.npmjs.org/',
independentLeaves: false,
shrinkwrap: true,
shamefullyFlatten: false,
}
}
export default async (
opts: StoreStatusOptions,
): Promise<StrictStoreStatusOptions> => {
if (opts) {
for (const key in opts) {
if (opts[key] === undefined) {
delete opts[key]
}
}
}
const defaultOpts = await defaults(opts)
const extendedOpts = {...defaultOpts, ...opts, store: defaultOpts.store}
if (extendedOpts.force) {
logger.warn('using --force I sure hope you know what you are doing')
}
extendedOpts.registry = normalizeRegistryUrl(extendedOpts.registry)
if (extendedOpts.global) {
const subfolder = LAYOUT_VERSION.toString() + (extendedOpts.independentLeaves ? '_independent_leaves' : '')
extendedOpts.prefix = path.join(extendedOpts.prefix, subfolder)
}
return extendedOpts
}