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

Replace temp package with vendored code to avoid deprecated rimraf transitive dependency #618

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/__tests__/jscodeshift-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jest.setTimeout(600000); // 10 minutes
const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
const temp = require('temp');
const testUtils = require('../../utils/testUtils');
const {chdir} = require('process');

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"micromatch": "^4.0.7",
"neo-async": "^2.5.0",
"recast": "^0.23.9",
"temp": "^0.9.4",
"write-file-atomic": "^5.0.1"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const fs = require('graceful-fs');
const path = require('path');
const http = require('http');
const https = require('https');
const temp = require('temp');
const ignores = require('./ignoreFiles');
const temp = require('./utils/temp');

const availableCpus = Math.max(require('os').cpus().length - 1, 1);
const CHUNK_SIZE = 50;
Expand Down Expand Up @@ -190,7 +190,7 @@ function run(transformFile, paths, options) {
})
.on('end', () => {
const ext = path.extname(transformFile);
temp.open({ prefix: 'jscodeshift', suffix: ext }, (err, info) => {
temp.open({ suffix: ext }, (err, info) => {
if (err) return reject(err);
fs.write(info.fd, contents, function (err) {
if (err) return reject(err);
Expand Down
58 changes: 58 additions & 0 deletions src/utils/temp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
* Copyright (c) 2010-2014 Bruce Williams
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const fs = require('fs');
const path = require('path');
const os = require('os');
const constants = require('constants');

const RDWR_EXCL = constants.O_CREAT | constants.O_TRUNC | constants.O_RDWR | constants.O_EXCL;
const tempDir = path.resolve(os.tmpdir());

function generateName(suffix) {
const now = new Date();
return path.join(
tempDir,
[
'jscodeshift',
now.getFullYear(),
now.getMonth(),
now.getDate(),
'-',
process.pid,
'-',
(Math.random() * 0x100000000 + 1).toString(36),
suffix || '',
].join('')
);
}

exports.open = function open(opts, callback) {
if (!opts) opts = {};
const target = generateName(opts.suffix);
return new Promise((resolve, reject) => {
kitten marked this conversation as resolved.
Show resolved Hide resolved
fs.open(target, RDWR_EXCL, 0o600, (error, fd) => {
if (!error) {
deleteFileOnExit(target);
}
const result = { path: target, fd };
if (callback) callback(error, result);
if (error) return reject(error);
resolve(result);
});
});
};

exports.openSync = function open(opts) {
if (!opts) opts = {};
const target = generateName(opts.suffix);
const fd = fs.openSync(target, RDWR_EXCL, 0o600);
return { path: target, fd };
};
2 changes: 1 addition & 1 deletion utils/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const fs = require('fs');
const path = require('path');
const temp = require('temp');
const temp = require('../src/utils/temp');

function renameFileTo(oldPath, newFilename, extension = '') {
const projectPath = path.dirname(oldPath);
Expand Down
27 changes: 0 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2429,18 +2429,6 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2:
dependencies:
brace-expansion "^1.1.7"

minimist@^1.2.6:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==

mkdirp@^0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.6.tgz#7def03d2432dcae4ba1d611445c48396062255f6"
integrity sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==
dependencies:
minimist "^1.2.6"

mkdirp@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
Expand Down Expand Up @@ -2738,13 +2726,6 @@ rimraf@^3.0.2:
dependencies:
glob "^7.1.3"

rimraf@~2.6.2:
version "2.6.3"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"
integrity sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==
dependencies:
glob "^7.1.3"

run-parallel@^1.1.9:
version "1.2.0"
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
Expand Down Expand Up @@ -2904,14 +2885,6 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

temp@^0.9.4:
version "0.9.4"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.9.4.tgz#cd20a8580cb63635d0e4e9d4bd989d44286e7620"
integrity sha512-yYrrsWnrXMcdsnu/7YMYAofM1ktpL5By7vZhf15CrXijWWrEYZks5AXBudalfSWJLlnen/QUJUB5aoB0kqZUGA==
dependencies:
mkdirp "^0.5.1"
rimraf "~2.6.2"

test-exclude@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
Expand Down