mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-29 12:31:52 -04:00
refactor: normalize the structure of store.json on Windows
BREAKING CHANGE: Paths used in store.json is normalized on Windows. Paths in store.json don't have the redundant package.json specified.
This commit is contained in:
@@ -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 <rico@ricostacruz.com>",
|
||||
"bin": {
|
||||
"pnpm": "lib/bin/pnpm.js"
|
||||
|
||||
@@ -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<CommandNamespace> {
|
||||
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<CommandNamespac
|
||||
failIfNotCompatible(storeJson.pnpm)
|
||||
}
|
||||
const cmd: CommandNamespace = {
|
||||
pkg,
|
||||
pkg: pkg.pkg,
|
||||
root,
|
||||
store,
|
||||
storeJson: storeJson || {
|
||||
@@ -74,6 +70,12 @@ function failIfNotCompatible (storeVersion: string) {
|
||||
`)
|
||||
throw new Error(msg)
|
||||
}
|
||||
if (!semver.satisfies(storeVersion, '>=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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export async function prune(maybeOpts?: PnpmOptions): Promise<void> {
|
||||
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)
|
||||
|
||||
|
||||
@@ -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 = <string[]>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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user