How to use the supi.mutateModules function in supi

To help you get started, we’ve selected a few supi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pnpm / pnpm / packages / plugin-commands-installation / src / recursive.ts View on Github external
async function unlink (manifest: ImporterManifest, opts: any) { // tslint:disable-line:no-any
  return mutateModules(
    [
      {
        manifest,
        mutation: 'unlink',
        rootDir: opts.dir,
      },
    ],
    opts,
  )
}
github pnpm / pnpm / packages / plugin-commands-recursive / src / recursive.ts View on Github external
async function unlinkPkgs (dependencyNames: string[], manifest: ImporterManifest, opts: any) { // tslint:disable-line:no-any
  return mutateModules(
    [
      {
        dependencyNames,
        manifest,
        mutation: 'unlinkSome',
        rootDir: opts.dir,
      },
    ],
    opts,
  )
}
github pnpm / pnpm / packages / plugin-commands-recursive / src / recursive.ts View on Github external
async function unlink (manifest: ImporterManifest, opts: any) { // tslint:disable-line:no-any
  return mutateModules(
    [
      {
        manifest,
        mutation: 'unlink',
        rootDir: opts.dir,
      },
    ],
    opts,
  )
}
github pnpm / pnpm / packages / plugin-commands-installation / src / unlink.ts View on Github external
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)
}
github pnpm / pnpm / packages / plugin-commands-recursive / src / recursive.ts View on Github external
}),
              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()
github pnpm / pnpm / packages / plugin-commands-installation / src / install.ts View on Github external
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)
    }
  }
github pnpm / pnpm / packages / plugin-commands-installation / src / prune.ts View on Github external
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)
}
github pnpm / pnpm / packages / plugin-commands-installation / src / recursive.ts View on Github external
}),
            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()
github pnpm / pnpm / packages / plugin-commands-installation / src / remove.ts View on Github external
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)
}