Skip to content

Commit

Permalink
feat: remove ownership changing features (#88)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this module will no longer attempt to alter file ownership
  • Loading branch information
nlf authored Oct 11, 2022
1 parent 4fc9a0a commit ef99e1c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
18 changes: 9 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
// Write a binroot/pkg.bin + ".cmd" file that has this line in it:
// @<prog> <args...> %dp0%<target> %*

const { promisify } = require('util')
const fs = require('fs')
const writeFile = promisify(fs.writeFile)
const readFile = promisify(fs.readFile)
const chmod = promisify(fs.chmod)
const stat = promisify(fs.stat)
const unlink = promisify(fs.unlink)
const {
chmod,
mkdir,
readFile,
stat,
unlink,
writeFile,
} = require('fs/promises')

const { dirname, relative } = require('path')
const mkdir = require('mkdirp-infer-owner')
const toBatchSyntax = require('./to-batch-syntax')
const shebangExpr = /^#!\s*(?:\/usr\/bin\/env\s*((?:[^ \t=]+=[^ \t=]+\s+)*))?([^ \t]+)(.*)$/

Expand All @@ -42,7 +42,7 @@ const writeShim = (from, to) =>
// First, check if the bin is a #! of some sort.
// If not, then assume it's something that'll be compiled, or some other
// sort of script, and just call it directly.
mkdir(dirname(to))
mkdir(dirname(to), { recursive: true })
.then(() => readFile(from, 'utf8'))
.then(data => {
const firstLine = data.trim().split(/\r*\n/)[0]
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
"url": "https://github.com/npm/cmd-shim.git"
},
"license": "ISC",
"dependencies": {
"mkdirp-infer-owner": "^2.0.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "4.5.1",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2",
"tap": "^16.0.1"
},
"files": [
Expand Down
11 changes: 7 additions & 4 deletions test/00-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const mkdirp = require('mkdirp')
const fs = require('fs')
const {
mkdirSync,
writeFileSync,
} = require('fs')

const fixtures = require('path').join(__dirname, '/fixtures')

const froms = {
Expand All @@ -12,7 +15,7 @@ const froms = {
'from.env.multiple.variables': '#!/usr/bin/env key=value key2=value2 node --flag-one --flag-two',
}

mkdirp.sync(fixtures)
mkdirSync(fixtures, { recursive: true })
for (const [f, content] of Object.entries(froms)) {
fs.writeFileSync(`${fixtures}/${f}`, content)
writeFileSync(`${fixtures}/${f}`, content)
}
6 changes: 3 additions & 3 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

var test = require('tap').test
var rimraf = require('rimraf')
var fs = require('fs')
var path = require('path')
var fixtures = path.resolve(__dirname, 'fixtures')
Expand Down Expand Up @@ -52,8 +53,7 @@ test('fails if to is a dir', async t => {
var from = path.resolve(fixtures, 'from.env')
var to = path.resolve(fixtures)
t.teardown(() => {
rimraf.sync(to + '.cmd')
rimraf.sync(to + '.ps1')
fs.rmSync(to + '.cmd', { recursive: true, force: true })
})
await t.rejects(cmdShim(from, to), { code: 'EISDIR' })
})
Expand Down
6 changes: 5 additions & 1 deletion test/zz-cleanup.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
require('rimraf').sync(require('path').join(__dirname, 'fixtures'))
const { join } = require('path')
const { rmSync } = require('fs')

rmSync(join(__dirname, 'fixtures'), { recursive: true, force: true })
rmSync(join(__dirname, 'fixtures.ps1'))

0 comments on commit ef99e1c

Please sign in to comment.