Files
pnpm/src/fs/modulesController.ts
zkochan 765a139ede fix: store status doesn't fail on skipped optional deps
A new property called `skipped` added to
`node_modules/.modules.yaml`. The property is an array of
package IDs, of those packages that are optional an were
skipped during installation.

Close #681
2017-04-09 14:06:49 +03:00

31 lines
897 B
TypeScript

import path = require('path')
import loadYamlFile = require('load-yaml-file')
import writeYamlFile = require('write-yaml-file')
// The dot prefix is needed because otherwise `npm shrinkwrap`
// thinks that it is an extraneous package.
const modulesFileName = '.modules.yaml'
export type Modules = {
packageManager: string,
storePath: string,
skipped: string[],
}
export async function read (modulesPath: string): Promise<Modules | null> {
const modulesYamlPath = path.join(modulesPath, modulesFileName)
try {
return await loadYamlFile<Modules>(modulesYamlPath)
} catch (err) {
if ((<NodeJS.ErrnoException>err).code !== 'ENOENT') {
throw err
}
return null
}
}
export function save (modulesPath: string, modules: Modules) {
const modulesYamlPath = path.join(modulesPath, modulesFileName)
return writeYamlFile(modulesYamlPath, modules, {sortKeys: true})
}