MCPcopy Create free account
hub / github.com/npm/cli / createPkg

Function createPkg

workspaces/libnpmexec/test/fixtures/setup.js:14–92  ·  view source on GitHub ↗
({
  name = '@npmcli/create-index',
  bin,
  files,
  versions = [],
  version,
  localVersion,
})

Source from the content-addressed store, hash-verified

12const DEFAULT_BIN_FILE = 'bin-file.js'
13
14const createPkg = ({
15 name = '@npmcli/create-index',
16 bin,
17 files,
18 versions = [],
19 version,
20 localVersion,
21}) => {
22 if (localVersion && !versions.includes(localVersion)) {
23 versions = [...versions, localVersion]
24 }
25 if (version && !versions.includes(version)) {
26 versions = [...versions, version]
27 }
28
29 const defaultBinName = name.includes('/') ? name.split('/')[1] : name
30
31 if (!bin) {
32 bin = {
33 [defaultBinName]: `./${DEFAULT_BIN_FILE}`,
34 }
35 }
36
37 const pkgsArr = versions.map((v) => ({
38 name,
39 version: v,
40 bin,
41 }))
42
43 const pkgs = {}
44 const tarballs = {}
45 const fixtures = {}
46
47 for (const pkg of pkgsArr) {
48 pkgs[pkg.version] = pkg
49 }
50
51 if (localVersion) {
52 set(fixtures, ['node_modules', ...name.split('/')], {
53 'package.json': pkgs[localVersion],
54 ...files || {
55 [DEFAULT_BIN_FILE]: { key: name, value: `local-${localVersion}` },
56 },
57 })
58 fixtures['package.json'] = {
59 name: 'pkg',
60 version: '9.9.9',
61 dependencies: {
62 [name]: `^${localVersion}`,
63 },
64 }
65 }
66
67 for (const pkg of pkgsArr) {
68 const fixturePath = `${pkg.name}-${pkg.version}`.replace('/', '-')
69 set(fixtures, ['packages', fixturePath], {
70 'package.json': pkg,
71 ...files || {

Callers 3

local.jsFile · 0.85
prompt.jsFile · 0.85
registry.jsFile · 0.85

Calls 5

setFunction · 0.85
resolveFunction · 0.85
replaceMethod · 0.80
manifestMethod · 0.80
packageMethod · 0.45

Tested by

no test coverage detected