Skip to content

Commit

Permalink
[Dev Deps] update @ljharb/eslint-config, tape; add `safe-publish-…
Browse files Browse the repository at this point in the history
…latest`
  • Loading branch information
ljharb committed Jan 31, 2020
1 parent 7256f27 commit f207db2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
8 changes: 4 additions & 4 deletions getLockfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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' });
Expand Down
6 changes: 3 additions & 3 deletions getProjectTempDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions test.js → test/index.js
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit f207db2

Please sign in to comment.