Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function unlink (manifest: ImporterManifest, opts: any) { // tslint:disable-line:no-any
return mutateModules(
[
{
manifest,
mutation: 'unlink',
rootDir: opts.dir,
},
],
opts,
)
}
async function unlinkPkgs (dependencyNames: string[], manifest: ImporterManifest, opts: any) { // tslint:disable-line:no-any
return mutateModules(
[
{
dependencyNames,
manifest,
mutation: 'unlinkSome',
rootDir: opts.dir,
},
],
opts,
)
}
async function unlink (manifest: ImporterManifest, opts: any) { // tslint:disable-line:no-any
return mutateModules(
[
{
manifest,
mutation: 'unlink',
rootDir: opts.dir,
},
],
opts,
)
}
export async function handler (input: string[], opts: CreateStoreControllerOptions & Pick) {
const store = await createOrConnectStoreController(opts)
const unlinkOpts = Object.assign(opts, {
storeController: store.ctrl,
storeDir: store.dir,
})
if (!input || !input.length) {
return mutateModules([
{
dependencyNames: input,
manifest: await readImporterManifestOnly(opts.dir, opts),
mutation: 'unlinkSome',
rootDir: opts.dir,
},
], unlinkOpts)
}
return mutateModules([
{
manifest: await readImporterManifestOnly(opts.dir, opts),
mutation: 'unlink',
rootDir: opts.dir,
},
], unlinkOpts)
}
}),
rootDir,
targetDependenciesField: getSaveType(opts),
} as MutatedImporter)
return
case 'install':
mutatedImporters.push({
buildIndex,
manifest,
mutation,
rootDir,
} as MutatedImporter)
return
}
}))
const mutatedPkgs = await mutateModules(mutatedImporters, {
...installOpts,
hooks,
storeController: store.ctrl,
})
if (opts.save !== false) {
await Promise.all(
mutatedPkgs
.map(({ manifest }, index) => writeImporterManifests[index](manifest))
)
}
return true
}
let pkgPaths = chunks.length === 0
? chunks[0]
: Object.keys(opts.selectedWsPkgsGraph).sort()
if (!input || !input.length) {
input = updateToWorkspacePackagesFromManifest(manifest, opts.include, workspacePackages!)
} else {
input = createWorkspaceSpecs(input, workspacePackages!)
}
}
if (!input || !input.length) {
if (invocation === 'add') {
throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm add` requires the package name')
}
const updatedManifest = await install(manifest, installOpts)
if (opts.update === true && opts.save !== false) {
await writeImporterManifest(updatedManifest)
}
} else {
const [updatedImporter] = await mutateModules([
{
allowNew: opts.allowNew,
binsDir: installOpts.bin,
dependencySelectors: input,
manifest,
mutation: 'installSome',
peer: opts.savePeer,
pinnedVersion: getPinnedVersion(opts),
rootDir: installOpts.dir,
targetDependenciesField: getSaveType(installOpts),
},
], installOpts)
if (opts.save !== false) {
await writeImporterManifest(updatedImporter.manifest)
}
}
export async function handler (input: string[], opts: Pick & CreateStoreControllerOptions) {
const store = await createOrConnectStoreController(opts)
return mutateModules([
{
buildIndex: 0,
manifest: await readImporterManifestOnly(process.cwd(), opts),
mutation: 'install',
pruneDirectDependencies: true,
rootDir: process.cwd(),
},
], {
...opts,
pruneStore: true,
storeController: store.ctrl,
storeDir: store.dir,
} as InstallOptions)
}
}),
rootDir,
targetDependenciesField: getSaveType(opts),
} as MutatedImporter)
return
case 'install':
mutatedImporters.push({
buildIndex,
manifest,
mutation,
rootDir,
} as MutatedImporter)
return
}
}))
const mutatedPkgs = await mutateModules(mutatedImporters, {
...installOpts,
hooks,
storeController: store.ctrl,
})
if (opts.save !== false) {
await Promise.all(
mutatedPkgs
.map(({ manifest }, index) => writeImporterManifests[index](manifest))
)
}
return true
}
let pkgPaths = chunks.length === 0
? chunks[0]
: Object.keys(opts.selectedWsPkgsGraph).sort()
input: string[],
opts: CreateStoreControllerOptions & Pick,
) {
const store = await createOrConnectStoreController(opts)
const removeOpts = Object.assign(opts, {
storeController: store.ctrl,
storeDir: store.dir,
})
if (!opts.ignorePnpmfile) {
removeOpts['hooks'] = requireHooks(opts.lockfileDir || opts.dir, opts)
}
removeOpts['workspacePackages'] = opts.workspaceDir
? arrayOfWorkspacePackagesToMap(await findWorkspacePackages(opts.workspaceDir, opts))
: undefined
const currentManifest = await readImporterManifest(opts.dir, opts)
const [mutationResult] = await mutateModules(
[
{
binsDir: opts.bin,
dependencyNames: input,
manifest: currentManifest.manifest,
mutation: 'uninstallSome',
rootDir: opts.dir,
},
],
removeOpts,
)
await currentManifest.writeImporterManifest(mutationResult.manifest)
}