async readPackage(dir) { let file = path.join(dir, "package.json"); if (this.packageCache.has(file)) { return this.packageCache.get(file); } let json = await fs.readFile(file, "utf8"); let pkg = JSON.parse(json); pkg.pkgfile = file; pkg.pkgdir = dir; // If the package has a `source` field, check if it is behind a symlink. // If so, we treat the module as source code rather than a pre-compiled module. if (pkg.source) { let realpath = await fs.realpath(file); if (realpath === file) { delete pkg.source; } } this.packageCache.set(file, pkg); return pkg; }
function tryFilename(filename, isMain) { let rc = -1 if (isExtJS(filename) || isExtMJS(filename)) { let stat = statSync(filename) if (stat !== null) { rc = Reflect.apply(isFile, stat, []) ? 0 : 1 } } else { rc = statFast(filename) } if (rc) { return "" } const useRealpath = isMain ? resolveSymlinksMain : resolveSymlinks return useRealpath ? realpath(filename) : filename }
const filename = realpath(argv[1]) const nodeModulesIndex = filename.lastIndexOf(sep + "node_modules" + sep)
if (isOwnPath(realpath(thePath))) { return true
children.forEach(function (child) { if (child.fromBundle === bundler) return reset(child) child.fromBundle = bundler child.isInLink = bundler.isLink child.parent = parent child.path = childPath(parent.path, child) child.realpath = bundler.isLink ? child.realpath : childPath(parent.realpath, child) child.isLink = child.isLink || parent.isLink || parent.target inflateBundled(bundler, child, child.children) })
function moveOldDestinationAway () { return rimraf(delpath).then(() => { return move(pkg.realpath, delpath, moveOpts) }).then(() => { movedDestAway = true }) }
async function choice(file) { const value = await realpath( resolve('.', 'node_modules', '.bin', file), ); return { name: file.yellow.bold, value, }; }
function childIsEquivalent (sw, requested, child) { if (!child) return false if (child.fromShrinkwrap) return true if (sw.integrity && child.package._integrity === sw.integrity) return true if (child.isLink && requested.type === 'directory') return path.relative(child.realpath, requested.fetchSpec) === '' if (sw.resolved) return child.package._resolved === sw.resolved if (!isRegistry(requested) && sw.from) return child.package._from === sw.from if (!isRegistry(requested) && child.package._resolved) return sw.version === child.package._resolved return child.package.version === sw.version }
function packageRelativePath (tree) { if (!tree) return '' var requested = tree.package._requested || {} var isLocal = requested.type === 'directory' || requested.type === 'file' return isLocal ? requested.fetchSpec : (tree.isLink || tree.isInLink) && !preserveSymlinks() ? tree.realpath : tree.path }
// Build our tentative remove list. We don't add remove actions yet // because we might resuse them as part of a move. Object.keys(flatOldTree).forEach(function (flatname) { if (flatname === '/') return if (flatNewTree[flatname]) return var pkg = flatOldTree[flatname] if (pkg.isInLink && /^[.][.][/\\]/.test(path.relative(newTree.realpath, pkg.realpath))) return toRemove[flatname] = pkg var name = moduleName(pkg) if (!toRemoveByName[name]) toRemoveByName[name] = [] toRemoveByName[name].push({flatname: flatname, pkg: pkg}) })
chain([ [asyncMap, modules, function (mod, done) { chain([ mod.parent && !mod.isLink && [checkGit, mod.realpath], [checkErrors, mod, idealTree] ], done) }], [thenValidateAllPeerDeps, idealTree], [thenCheckTop, idealTree], [thenCheckDuplicateDeps, idealTree] ], andFinishTracker(log, next))
function restoreOldNodeModules () { if (!movedDestAway) return return readdir(path.join(delpath, 'node_modules')).catch(() => []).then((modules) => { if (!modules.length) return return mkdirp(path.join(pkg.realpath, 'node_modules')).then(() => Bluebird.map(modules, (file) => { const from = path.join(delpath, 'node_modules', file) const to = path.join(pkg.realpath, 'node_modules', file) return move(from, to, moveOpts) })) }) }
async readPackage(dir) { let file = path.join(dir, "package.json"); if (this.packageCache.has(file)) { return this.packageCache.get(file); } let json = await fs.readFile(file, "utf8"); let pkg = JSON.parse(json); pkg.pkgfile = file; pkg.pkgdir = dir; // If the package has a `source` field, check if it is behind a symlink. // If so, we treat the module as source code rather than a pre-compiled module. if (pkg.source) { let realpath = await fs.realpath(file); if (realpath === file) { delete pkg.source; } } this.packageCache.set(file, pkg); return pkg; }