Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove chownr and mkdirp-infer-owner #5710

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 3 additions & 29 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ graph LR;
bin-links-->read-cmd-shim;
bin-links-->write-file-atomic;
cacache-->fs-minipass;
cacache-->infer-owner;
cacache-->npmcli-fs["@npmcli/fs"];
cacache-->npmcli-move-file["@npmcli/move-file"];
cacache-->ssri;
Expand Down Expand Up @@ -37,7 +36,6 @@ graph LR;
libnpmexec-->npmcli-arborist["@npmcli/arborist"];
libnpmexec-->npmcli-ci-detect["@npmcli/ci-detect"];
libnpmexec-->npmcli-eslint-config["@npmcli/eslint-config"];
libnpmexec-->npmcli-fs["@npmcli/fs"];
libnpmexec-->npmcli-run-script["@npmcli/run-script"];
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
libnpmexec-->npmlog;
Expand Down Expand Up @@ -121,7 +119,6 @@ graph LR;
npm-->npmcli-config["@npmcli/config"];
npm-->npmcli-docs["@npmcli/docs"];
npm-->npmcli-eslint-config["@npmcli/eslint-config"];
npm-->npmcli-fs["@npmcli/fs"];
npm-->npmcli-git["@npmcli/git"];
npm-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npm-->npmcli-package-json["@npmcli/package-json"];
Expand Down Expand Up @@ -195,7 +192,6 @@ graph LR;
npmcli-config-->semver;
npmcli-docs-->ignore-walk;
npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-docs-->npmcli-fs["@npmcli/fs"];
npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-fs-->semver;
npmcli-git-->npm-pick-manifest;
Expand All @@ -212,16 +208,13 @@ graph LR;
npmcli-metavuln-calculator-->semver;
npmcli-package-json-->json-parse-even-better-errors;
npmcli-promise-spawn-->infer-owner;
npmcli-query-->npm-package-arg;
npmcli-query-->semver;
npmcli-run-script-->npmcli-node-gyp["@npmcli/node-gyp"];
npmcli-run-script-->npmcli-promise-spawn["@npmcli/promise-spawn"];
npmcli-run-script-->read-package-json-fast;
npmlog-->are-we-there-yet;
npmlog-->gauge;
pacote-->cacache;
pacote-->fs-minipass;
pacote-->infer-owner;
pacote-->npm-package-arg;
pacote-->npm-packlist;
pacote-->npm-pick-manifest;
Expand Down Expand Up @@ -341,10 +334,8 @@ graph LR;
babel-types-->babel-helper-validator-identifier["@babel/helper-validator-identifier"];
babel-types-->to-fast-properties;
bin-links-->cmd-shim;
bin-links-->mkdirp-infer-owner;
bin-links-->npm-normalize-package-bin;
bin-links-->read-cmd-shim;
bin-links-->rimraf;
bin-links-->write-file-atomic;
bindings-->file-uri-to-path;
bl-->buffer;
Expand Down Expand Up @@ -387,7 +378,6 @@ graph LR;
cmark-gfm-->bindings;
cmark-gfm-->node-addon-api;
cmark-gfm-->prebuild-install;
cmd-shim-->mkdirp-infer-owner;
color-convert-->color-name;
columnify-->strip-ansi;
columnify-->wcwidth;
Expand Down Expand Up @@ -549,7 +539,6 @@ graph LR;
libnpmexec-->npmcli-arborist["@npmcli/arborist"];
libnpmexec-->npmcli-ci-detect["@npmcli/ci-detect"];
libnpmexec-->npmcli-eslint-config["@npmcli/eslint-config"];
libnpmexec-->npmcli-fs["@npmcli/fs"];
libnpmexec-->npmcli-run-script["@npmcli/run-script"];
libnpmexec-->npmcli-template-oss["@npmcli/template-oss"];
libnpmexec-->npmlog;
Expand Down Expand Up @@ -679,9 +668,6 @@ graph LR;
minipass-sized-->minipass;
minizlib-->minipass;
minizlib-->yallist;
mkdirp-infer-owner-->chownr;
mkdirp-infer-owner-->infer-owner;
mkdirp-infer-owner-->mkdirp;
node-abi-->semver;
node-gyp-->env-paths;
node-gyp-->glob;
Expand All @@ -702,7 +688,6 @@ graph LR;
npm-->archy;
npm-->cacache;
npm-->chalk;
npm-->chownr;
npm-->cli-columns;
npm-->cli-table3;
npm-->columnify;
Expand Down Expand Up @@ -732,7 +717,6 @@ graph LR;
npm-->minimatch;
npm-->minipass-pipeline;
npm-->minipass;
npm-->mkdirp-infer-owner;
npm-->mkdirp;
npm-->ms;
npm-->nock;
Expand All @@ -751,7 +735,6 @@ graph LR;
npm-->npmcli-config["@npmcli/config"];
npm-->npmcli-docs["@npmcli/docs"];
npm-->npmcli-eslint-config["@npmcli/eslint-config"];
npm-->npmcli-fs["@npmcli/fs"];
npm-->npmcli-git["@npmcli/git"];
npm-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npm-->npmcli-package-json["@npmcli/package-json"];
Expand Down Expand Up @@ -845,7 +828,6 @@ graph LR;
npmcli-arborist-->treeverse;
npmcli-arborist-->walk-up-path;
npmcli-config-->ini;
npmcli-config-->mkdirp-infer-owner;
npmcli-config-->nopt;
npmcli-config-->npmcli-map-workspaces["@npmcli/map-workspaces"];
npmcli-config-->proc-log;
Expand All @@ -862,11 +844,9 @@ graph LR;
npmcli-docs-->mdx-js-mdx["@mdx-js/mdx"];
npmcli-docs-->mkdirp;
npmcli-docs-->npmcli-eslint-config["@npmcli/eslint-config"];
npmcli-docs-->npmcli-fs["@npmcli/fs"];
npmcli-docs-->npmcli-template-oss["@npmcli/template-oss"];
npmcli-docs-->tap;
npmcli-docs-->yaml;
npmcli-fs-->gar-promisify["@gar/promisify"];
npmcli-fs-->semver;
npmcli-git-->lru-cache;
npmcli-git-->mkdirp;
Expand All @@ -891,9 +871,7 @@ graph LR;
npmcli-move-file-->rimraf;
npmcli-package-json-->json-parse-even-better-errors;
npmcli-promise-spawn-->infer-owner;
npmcli-query-->npm-package-arg;
npmcli-query-->postcss-selector-parser;
npmcli-query-->semver;
npmcli-run-script-->node-gyp;
npmcli-run-script-->npmcli-node-gyp["@npmcli/node-gyp"];
npmcli-run-script-->npmcli-promise-spawn["@npmcli/promise-spawn"];
Expand All @@ -912,11 +890,8 @@ graph LR;
optionator-->word-wrap;
p-map-->aggregate-error;
pacote-->cacache;
pacote-->chownr;
pacote-->fs-minipass;
pacote-->infer-owner;
pacote-->minipass;
pacote-->mkdirp;
pacote-->npm-package-arg;
pacote-->npm-packlist;
pacote-->npm-pick-manifest;
Expand All @@ -929,7 +904,6 @@ graph LR;
pacote-->promise-retry;
pacote-->read-package-json-fast;
pacote-->read-package-json;
pacote-->rimraf;
pacote-->ssri;
pacote-->tar;
parse-conflict-json-->json-parse-even-better-errors;
Expand Down Expand Up @@ -1127,6 +1101,6 @@ packages higher up the chain.
- pacote, libnpmaccess, libnpmhook, libnpmorg, libnpmsearch, libnpmteam, npm-profile
- npm-registry-fetch, libnpmversion
- @npmcli/git, make-fetch-happen, @npmcli/config, init-package-json
- @npmcli/docs, @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, @npmcli/run-script, read-package-json, @npmcli/query, readdir-scoped-modules, promzard
- @npmcli/fs, npm-bundled, read-package-json-fast, unique-filename, @npmcli/promise-spawn, npm-install-checks, npm-package-arg, npm-packlist, normalize-package-data, @npmcli/package-json, bin-links, nopt, npmlog, parse-conflict-json, dezalgo, read
- semver, ignore-walk, @npmcli/eslint-config, @npmcli/template-oss, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, @npmcli/move-file, fs-minipass, infer-owner, ssri, unique-slug, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, minipass-fetch, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, wrappy, treeverse, minify-registry-metadata, @npmcli/disparity-colors, @npmcli/ci-detect, mute-stream, ini, npm-audit-report, npm-user-validate
- @npmcli/installed-package-contents, @npmcli/map-workspaces, cacache, npm-pick-manifest, @npmcli/run-script, read-package-json, readdir-scoped-modules, promzard
- @npmcli/docs, npm-bundled, read-package-json-fast, @npmcli/fs, unique-filename, @npmcli/promise-spawn, npm-install-checks, npm-package-arg, npm-packlist, normalize-package-data, @npmcli/package-json, bin-links, nopt, npmlog, parse-conflict-json, dezalgo, read
- ignore-walk, @npmcli/eslint-config, @npmcli/template-oss, npm-normalize-package-bin, @npmcli/name-from-folder, json-parse-even-better-errors, semver, @npmcli/move-file, fs-minipass, ssri, unique-slug, infer-owner, hosted-git-info, proc-log, validate-npm-package-name, @npmcli/node-gyp, minipass-fetch, @npmcli/query, cmd-shim, read-cmd-shim, write-file-atomic, abbrev, are-we-there-yet, gauge, wrappy, treeverse, minify-registry-metadata, @npmcli/disparity-colors, @npmcli/ci-detect, mute-stream, ini, npm-audit-report, npm-user-validate
2 changes: 1 addition & 1 deletion docs/lib/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { join, dirname, basename, extname, sep, posix } = require('path')
const fs = require('@npmcli/fs')
const fs = require('fs/promises')
const ignoreWalk = require('ignore-walk')
const yaml = require('yaml')
const parseFrontMatter = require('front-matter')
Expand Down
3 changes: 1 addition & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"dependencies": {
"@isaacs/string-locale-compare": "^1.1.0",
"@mdx-js/mdx": "^1.6.22",
"@npmcli/fs": "^2.1.0",
"cmark-gfm": "^0.9.0",
"front-matter": "^4.0.2",
"ignore-walk": "^5.0.1",
"ignore-walk": "^6.0.0",
"jsdom": "^20.0.1",
"marked-man": "^0.7.0",
"mkdirp": "^1.0.4",
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// as an array.
//

const fs = require('@npmcli/fs')
const fs = require('fs/promises')
const nopt = require('nopt')

const { definitions, shorthands } = require('../utils/config/index.js')
Expand Down
8 changes: 2 additions & 6 deletions lib/commands/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// don't expand so that we only assemble the set of defaults when needed
const configDefs = require('../utils/config/index.js')

const mkdirp = require('mkdirp-infer-owner')
const { mkdir, readFile, writeFile } = require('fs/promises')
const { dirname, resolve } = require('path')
const { promisify } = require('util')
const fs = require('fs')
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)
const { spawn } = require('child_process')
const { EOL } = require('os')
const ini = require('ini')
Expand Down Expand Up @@ -231,7 +227,7 @@ ${data.split('\n').sort(localeCompare).join('\n').trim()}

${defData}
`.split('\n').join(EOL)
await mkdirp(dirname(file))
await mkdir(dirname(file), { recursive: true })
await writeFile(file, tmpData, 'utf8')
await new Promise((resolve, reject) => {
const [bin, ...args] = e.split(/\s+/)
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const { relative, resolve } = require('path')
const mkdirp = require('mkdirp-infer-owner')
const { mkdir } = require('fs/promises')
const initJson = require('init-package-json')
const npa = require('npm-package-arg')
const rpj = require('read-package-json-fast')
Expand Down Expand Up @@ -59,7 +59,7 @@ class Init extends BaseCommand {
if (args.length) {
for (const filterArg of filters) {
const path = wPath(filterArg)
await mkdirp(path)
await mkdir(path, { recursive: true })
workspacesPaths.push(path)
await this.execCreate({ args, path })
await this.setWorkspace({ pkg, workspacePath: path })
Expand All @@ -70,7 +70,7 @@ class Init extends BaseCommand {
// no args, uses classic init-package-json boilerplate
for (const filterArg of filters) {
const path = wPath(filterArg)
await mkdirp(path)
await mkdir(path, { recursive: true })
workspacesPaths.push(path)
await this.template(path)
await this.setWorkspace({ pkg, workspacePath: path })
Expand Down
6 changes: 3 additions & 3 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { resolve, dirname, join } = require('path')
const Config = require('@npmcli/config')
const chalk = require('chalk')
const which = require('which')
const fs = require('@npmcli/fs')
const fs = require('fs/promises')

// Patch the global fs module here at the app level
require('graceful-fs').gracefulify(require('fs'))
Expand Down Expand Up @@ -246,13 +246,13 @@ class Npm extends EventEmitter {
// a cache dir, but we don't want to fail immediately since
// the command might not need a cache dir (like `npm --version`)
await this.time('npm:load:mkdirpcache', () =>
fs.mkdir(this.cache, { recursive: true, owner: 'inherit' })
fs.mkdir(this.cache, { recursive: true })
.catch((e) => log.verbose('cache', `could not create cache: ${e}`)))

// its ok if this fails. user might have specified an invalid dir
// which we will tell them about at the end
await this.time('npm:load:mkdirplogs', () =>
fs.mkdir(this.logsDir, { recursive: true, owner: 'inherit' })
fs.mkdir(this.logsDir, { recursive: true })
.catch((e) => log.verbose('logfile', `could not create logs-dir: ${e}`)))

// note: this MUST be shorter than the actual argv length, because it
Expand Down
8 changes: 2 additions & 6 deletions lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const os = require('os')
const fs = require('@npmcli/fs')
const fs = require('fs')

const log = require('./log-shim.js')
const errorMessage = require('./error-message.js')
Expand Down Expand Up @@ -186,11 +186,7 @@ const exitHandler = err => {
file = `${npm.logPath}${file}`
content = `'Log files:\n${npm.logFiles.join('\n')}\n\n${content.trim()}\n`
try {
fs.withOwnerSync(
file,
() => fs.writeFileSync(file, content),
{ owner: 'inherit' }
)
fs.writeFileSync(file, content)
detail.push(['', `\n\nFor a full report see:\n${file}`])
} catch (err) {
log.warn('', `Could not write error message to ${file} due to ${err}`)
Expand Down
7 changes: 1 addition & 6 deletions lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const rimraf = promisify(require('rimraf'))
const glob = promisify(require('glob'))
const MiniPass = require('minipass')
const fsMiniPass = require('fs-minipass')
const fs = require('@npmcli/fs')
const log = require('./log-shim')

const padZero = (n, length) => n.toString().padStart(length.toString().length, '0')
Expand Down Expand Up @@ -174,11 +173,7 @@ class LogFiles {
// during process.on('exit') which has to be synchronous. So in order
// to never drop log messages, it is easiest to make it sync all the time
// and this was measured to be about 1.5% slower for 40k lines of output
const logStream = fs.withOwnerSync(
f,
() => new fsMiniPass.WriteStreamSync(f, { flags: 'a' }),
{ owner: 'inherit' }
)
const logStream = new fsMiniPass.WriteStreamSync(f, { flags: 'a' })
if (count > 0) {
// Reset file log count if we are opening
// after our first file
Expand Down
8 changes: 2 additions & 6 deletions lib/utils/timers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const EE = require('events')
const fs = require('@npmcli/fs')
const fs = require('fs')
const log = require('./log-shim')

// This is an event emiiter but on/off
Expand Down Expand Up @@ -90,11 +90,7 @@ class Timers extends EE {
return acc
}, {}),
}
fs.withOwnerSync(
this.file,
() => fs.writeFileSync(this.file, JSON.stringify(content) + '\n'),
{ owner: 'inherit' }
)
fs.writeFileSync(this.file, JSON.stringify(content) + '\n')
} catch (e) {
this.file = null
log.warn('timing', `could not write timing file: ${e}`)
Expand Down