From f207db24759b15a9a148744786164359ddc02586 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 31 Jan 2020 15:30:51 -0800 Subject: [PATCH] [Dev Deps] update `@ljharb/eslint-config`, `tape`; add `safe-publish-latest` --- bin.js | 4 ++-- getLockfile.js | 8 ++++---- getProjectTempDir.js | 6 +++--- package.json | 6 ++++-- test.js => test/index.js | 13 ++++++++----- 5 files changed, 21 insertions(+), 16 deletions(-) rename test.js => test/index.js (51%) diff --git a/bin.js b/bin.js index cdaa458..a72c3d2 100755 --- a/bin.js +++ b/bin.js @@ -47,6 +47,6 @@ const { }); getLockfile(pkg, date === 'now' ? undefined : date, { logger: console.log.bind(console), npmNeeded: '^6.9.0-0' }) - .then(lockfile => writeFile(output, lockfile)) + .then((lockfile) => writeFile(output, lockfile)) .then(() => { console.log(chalk.green('Lockfile contents written!')); }) - .catch(err => console.error(err)); + .catch((err) => console.error(err)); diff --git a/getLockfile.js b/getLockfile.js index bf0ecf5..6520f05 100644 --- a/getLockfile.js +++ b/getLockfile.js @@ -21,11 +21,11 @@ module.exports = function getLockfile(packageFile, date, { npmNeeded, logger = ( } const tmpDirP = getProjectTempDir({ npmNeeded, logger }); const npmRC = path.join(path.dirname(packageFile), '.npmrc'); - const copyPkg = tmpDirP.then(tmpDir => { + const copyPkg = tmpDirP.then((tmpDir) => { logger(chalk.blue(`Creating \`package.json\` in temp dir for ${date || '“now”'} lockfile`)); return Promise.all([ copyFile(packageFile, path.join(tmpDir, 'package.json')), - copyFile(npmRC, path.join(tmpDir, '.npmrc')).catch(err => { + copyFile(npmRC, path.join(tmpDir, '.npmrc')).catch((err) => { if (!err || !(/^ENOENT: no such file or directory/).test(err.message)) { throw err; } @@ -35,14 +35,14 @@ module.exports = function getLockfile(packageFile, date, { npmNeeded, logger = ( return Promise.all([tmpDirP, copyPkg]).then(([tmpDir]) => new Promise((resolve, reject) => { const PATH = path.join(tmpDir, '../node_modules/.bin'); logger(chalk.blue(`Running npm install to create lockfile for ${date || '“now”'}...`)); - exec(`npm install --package-lock --package-lock-only${date ? ` --before=${date}` : ''}`, { cwd: tmpDir, env: { PATH: `${PATH}:${process.env.PATH}` } }, err => { + exec(`npm install --package-lock --package-lock-only${date ? ` --before=${date}` : ''}`, { cwd: tmpDir, env: { PATH: `${PATH}:${process.env.PATH}` } }, (err) => { if (err) { reject(err); } else { resolve(tmpDir); } }); - })).then(tmpDir => { + })).then((tmpDir) => { logger(chalk.blue(`Reading lockfile contents for ${date || '“now”'}...`)); const lockfile = path.join(tmpDir, 'package-lock.json'); return readFile(lockfile, { encoding: 'utf-8' }); diff --git a/getProjectTempDir.js b/getProjectTempDir.js index 7ecef67..2c78681 100644 --- a/getProjectTempDir.js +++ b/getProjectTempDir.js @@ -29,7 +29,7 @@ const getRootTempDir = function getRootTempDir(npmNeeded, logger = () => {}) { resolve(tmpDir); cleanupHandlers.push(cleanup); nodeCleanup(finalCleanup); - })).then(tmpDir => { + })).then((tmpDir) => { const npmV = execSync('npm --version', { encoding: 'utf-8', cwd: tmpDir }).trim(); logger(`${chalk.blue('Checking npm version:')} \`npm --version\` -> v${npmV}`); if (!semver.satisfies(npmV, npmNeeded)) { @@ -47,7 +47,7 @@ const getRootTempDir = function getRootTempDir(npmNeeded, logger = () => {}) { cleanupHandlers.unshift(() => { rimraf.sync(path.join(tmpDir, '*')); }); - exec('npm install --no-package-lock --silent >/dev/null', { cwd: tmpDir }, err => { + exec('npm install --no-package-lock --silent >/dev/null', { cwd: tmpDir }, (err) => { if (err) { return reject(err); } @@ -62,7 +62,7 @@ const getRootTempDir = function getRootTempDir(npmNeeded, logger = () => {}) { }; module.exports = function getProjectTempDir({ npmNeeded = '^6.9.0-0', logger = undefined } = {}) { - return getRootTempDir(npmNeeded, logger).then(rootDir => { + return getRootTempDir(npmNeeded, logger).then((rootDir) => { const projectDir = path.join(rootDir, 'XXXXXX'); return new Promise((resolve, reject) => tmp.dir({ template: projectDir }, (err, tmpDir, cleanup) => { if (err) { diff --git a/package.json b/package.json index 5d80c62..9237a49 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Safely generate an npm lockfile and output it to the filename of your choice.", "bin": "./bin.js", "scripts": { + "prepublish": "safe-publish-latest", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"", "lint": "eslint .", @@ -48,10 +49,11 @@ "node": ">= 6" }, "devDependencies": { - "@ljharb/eslint-config": "^15.1.0", + "@ljharb/eslint-config": "^16.0.0", "auto-changelog": "^1.16.2", "eslint": "^6.8.0", - "tape": "^5.0.0-next.3" + "safe-publish-latest": "^1.1.4", + "tape": "^5.0.0-next.4" }, "auto-changelog": { "output": "CHANGELOG.md", diff --git a/test.js b/test/index.js similarity index 51% rename from test.js rename to test/index.js index 3b53f41..d6e527d 100644 --- a/test.js +++ b/test/index.js @@ -1,18 +1,21 @@ 'use strict'; const { execSync } = require('child_process'); +const path = require('path'); const { readFileSync, unlinkSync } = require('fs'); const test = require('tape'); -test('simple test', t => { - execSync('./bin.js -o package-lock.json --date=now'); - const lockPackage = readFileSync('./package-lock.json', { encoding: 'utf-8' }); +const lockPath = path.join(__dirname, '../package-lock.json'); + +test('simple test', (t) => { + execSync('"' + path.join(__dirname, '../bin.js') + '" -o package-lock.json --date=now'); + const lockPackage = readFileSync(lockPath, { encoding: 'utf-8' }); t.ok(lockPackage, 'lockfile produced by package'); execSync('npm install --package-lock --package-lock-only', { encoding: 'utf-8' }); - const lockActual = readFileSync('./package-lock.json', { encoding: 'utf-8' }); + const lockActual = readFileSync(lockPath, { encoding: 'utf-8' }); t.ok(lockActual, 'lockfile produced by npm'); - unlinkSync('./package-lock.json'); + unlinkSync(lockPath); t.equal(lockActual, lockPackage, 'actual === package'); t.end(); });