diff --git a/package.json b/package.json index 931c437ed3..20b6921f1e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pnpm", "description": "A fast implementation of npm install", - "version": "0.37.0", + "version": "0.38.0", "author": "Rico Sta. Cruz ", "bin": { "pnpm": "lib/bin/pnpm.js" diff --git a/src/api/initCmd.ts b/src/api/initCmd.ts index d041cd164d..63161f186f 100644 --- a/src/api/initCmd.ts +++ b/src/api/initCmd.ts @@ -13,14 +13,10 @@ import mkdirp from '../fs/mkdirp' import {Package} from '../types' import {StoreJson} from '../fs/storeJsonController' import pnpmPkgJson from '../pnpmPkgJson' - -export type PackageAndPath = { - pkg: Package, - path: string -} +import normalizePath = require('normalize-path') export type CommandNamespace = { - pkg?: PackageAndPath, + pkg?: Package, storeJsonCtrl: StoreJsonCtrl, store: string, root: string, @@ -30,7 +26,7 @@ export type CommandNamespace = { export default async function (opts: StrictPnpmOptions): Promise { const cwd = opts.cwd || process.cwd() const pkg = await (opts.global ? readGlobalPkg(opts.globalPath) : readPkgUp({ cwd })) - const root = pkg.path ? path.dirname(pkg.path) : cwd + const root = normalizePath(pkg.path ? path.dirname(pkg.path) : cwd) const store = resolveStorePath(opts.storePath, root) const storeJsonCtrl = storeJsonController(store) const storeJson = storeJsonCtrl.read() @@ -38,7 +34,7 @@ export default async function (opts: StrictPnpmOptions): Promise=0.38')) { + const msg = structureChangeMsg(stripIndent` + The structure of store.json/dependencies was changed to not include the redundunt package.json at the end + `) + throw new Error(msg) + } } function structureChangeMsg (moreInfo: string): string { diff --git a/src/api/install.ts b/src/api/install.ts index d8c1b3404d..6e1094bfc9 100644 --- a/src/api/install.ts +++ b/src/api/install.ts @@ -49,9 +49,9 @@ export async function install (maybeOpts?: PnpmOptions) { const cmd = await initCmd(opts) const installCtx = await createInstallCmd(opts, cmd.storeJson) - if (!cmd.pkg || !cmd.pkg.pkg) throw runtimeError('No package.json found') - const packagesToInstall = Object.assign({}, cmd.pkg.pkg.dependencies || {}) - if (!opts.production) Object.assign(packagesToInstall, cmd.pkg.pkg.devDependencies || {}) + if (!cmd.pkg) throw runtimeError('No package.json found') + const packagesToInstall = Object.assign({}, cmd.pkg.dependencies || {}) + if (!opts.production) Object.assign(packagesToInstall, cmd.pkg.devDependencies || {}) return lock(cmd.store, () => installInContext('general', packagesToInstall, cmd, installCtx, opts)) } @@ -77,11 +77,11 @@ export async function installPkgs (fuzzyDeps: string[] | Dependencies, maybeOpts async function installInContext (installType: string, packagesToInstall: Dependencies, cmd: CommandNamespace, installCtx: InstallContext, opts: StrictPnpmOptions) { const pkgs: InstalledPackage[] = await installMultiple(installCtx, packagesToInstall, - cmd.pkg && cmd.pkg.pkg && cmd.pkg.pkg.optionalDependencies || {}, + cmd.pkg && cmd.pkg && cmd.pkg.optionalDependencies || {}, path.join(cmd.root, 'node_modules'), { linkLocal: opts.linkLocal, - dependent: cmd.pkg && cmd.pkg.path || cmd.root, + dependent: cmd.root, root: cmd.root, store: cmd.store } @@ -95,7 +95,8 @@ async function installInContext (installType: string, packagesToInstall: Depende } const inputNames = Object.keys(packagesToInstall) const savedPackages = pkgs.filter((pkg: InstalledPackage) => inputNames.indexOf(pkg.pkg.name) > -1) - await save(cmd.pkg.path, savedPackages, saveType, opts.saveExact) + const pkgJsonPath = path.join(cmd.root, 'package.json') + await save(pkgJsonPath, savedPackages, saveType, opts.saveExact) } } @@ -121,7 +122,7 @@ async function installInContext (installType: string, packagesToInstall: Depende } await linkBins(path.join(cmd.root, 'node_modules')) if (!opts.ignoreScripts && cmd.pkg) { - await mainPostInstall(cmd.pkg.pkg && cmd.pkg.pkg.scripts || {}, cmd.root, opts.production) + await mainPostInstall(cmd.pkg && cmd.pkg.scripts || {}, cmd.root, opts.production) } } diff --git a/src/api/prune.ts b/src/api/prune.ts index f03a524805..acc04f3906 100644 --- a/src/api/prune.ts +++ b/src/api/prune.ts @@ -17,7 +17,7 @@ export async function prune(maybeOpts?: PnpmOptions): Promise { throw new Error('No package.json found - cannot prune') } - const pkg = cmd.pkg.pkg + const pkg = cmd.pkg const extraneousPkgs = await getExtraneousPkgs(pkg, cmd.root, opts.production) @@ -34,7 +34,7 @@ export async function prunePkgs(pkgsToPrune: string[], maybeOpts?: PnpmOptions): if (!cmd.pkg) { throw new Error('No package.json found - cannot prune') } - const pkg = cmd.pkg.pkg + const pkg = cmd.pkg const extraneousPkgs = await getExtraneousPkgs(pkg, cmd.root, opts.production) diff --git a/src/api/uninstall.ts b/src/api/uninstall.ts index 395be92c03..a192a55144 100644 --- a/src/api/uninstall.ts +++ b/src/api/uninstall.ts @@ -1,13 +1,13 @@ import cbRimraf = require('rimraf') import path = require('path') -import initCmd, {CommandNamespace, PackageAndPath} from './initCmd' +import initCmd, {CommandNamespace} from './initCmd' import getSaveType from '../getSaveType' import removeDeps from '../removeDeps' import binify from '../binify' import extendOptions from './extendOptions' import requireJson from '../fs/requireJson' -import {PnpmOptions, StrictPnpmOptions} from '../types' +import {PnpmOptions, StrictPnpmOptions, Package} from '../types' import {StoreJson} from '../fs/storeJsonController' import lock from './lock' @@ -24,25 +24,25 @@ export default async function uninstallCmd (pkgsToUninstall: string[], maybeOpts return lock(cmd.store, () => uninstallInContext(pkgsToUninstall, pkg, cmd, opts)) } -export async function uninstallInContext (pkgsToUninstall: string[], pkg: PackageAndPath, cmd: CommandNamespace, opts: StrictPnpmOptions) { - pkg.pkg.dependencies = pkg.pkg.dependencies || {} +export async function uninstallInContext (pkgsToUninstall: string[], pkg: Package, cmd: CommandNamespace, opts: StrictPnpmOptions) { + pkg.dependencies = pkg.dependencies || {} // this is OK. The store might not have records for the package // maybe it was cloned, `pnpm install` was not executed // and remove is done on a package with no dependencies installed - cmd.storeJson.dependencies[pkg.path] = cmd.storeJson.dependencies[pkg.path] || {} + cmd.storeJson.dependencies[cmd.root] = cmd.storeJson.dependencies[cmd.root] || {} const pkgIds = pkgsToUninstall - .map(dep => cmd.storeJson.dependencies[pkg.path][dep]) + .map(dep => cmd.storeJson.dependencies[cmd.root][dep]) .filter(pkgId => !!pkgId) - const uninstalledPkgs = tryUninstall(pkgIds.slice(), cmd.storeJson, pkg.path) + const uninstalledPkgs = tryUninstall(pkgIds.slice(), cmd.storeJson, cmd.root) uninstalledPkgs.forEach(uninstalledPkg => removeBins(uninstalledPkg, cmd.store, cmd.root)) - if (cmd.storeJson.dependencies[pkg.path]) { + if (cmd.storeJson.dependencies[cmd.root]) { pkgsToUninstall.forEach(dep => { - delete cmd.storeJson.dependencies[pkg.path][dep] + delete cmd.storeJson.dependencies[cmd.root][dep] }) - if (!Object.keys(cmd.storeJson.dependencies[pkg.path]).length) { - delete cmd.storeJson.dependencies[pkg.path] + if (!Object.keys(cmd.storeJson.dependencies[cmd.root]).length) { + delete cmd.storeJson.dependencies[cmd.root] } } await Promise.all(uninstalledPkgs.map(pkgId => removePkgFromStore(pkgId, cmd.store))) @@ -52,7 +52,8 @@ export async function uninstallInContext (pkgsToUninstall: string[], pkg: Packag const saveType = getSaveType(opts) if (saveType) { - await removeDeps(pkg.path, pkgsToUninstall, saveType) + const pkgJsonPath = path.join(cmd.root, 'package.json') + await removeDeps(pkgJsonPath, pkgsToUninstall, saveType) } }