From 7f880654aeaa57d8fb7bdb8312f32b3f58ebbb7b Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Sat, 28 Sep 2024 00:21:29 +0200 Subject: [PATCH] use tmp library instead of temp --- bin/__tests__/jscodeshift-test.js | 2 -- package.json | 2 +- src/Runner.js | 10 +++++----- utils/testUtils.js | 8 ++++---- yarn.lock | 32 +++++-------------------------- 5 files changed, 15 insertions(+), 39 deletions(-) diff --git a/bin/__tests__/jscodeshift-test.js b/bin/__tests__/jscodeshift-test.js index 1255d214..07562b02 100644 --- a/bin/__tests__/jscodeshift-test.js +++ b/bin/__tests__/jscodeshift-test.js @@ -17,9 +17,7 @@ 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'); const createTransformWith = testUtils.createTransformWith; const createTempFileWith = testUtils.createTempFileWith; diff --git a/package.json b/package.json index ca05c864..0d930ab6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "neo-async": "^2.5.0", "picocolors": "^1.0.1", "recast": "^0.23.9", - "temp": "^0.9.4", + "tmp": "^0.2.3", "write-file-atomic": "^5.0.1" }, "peerDependencies": { diff --git a/src/Runner.js b/src/Runner.js index f503bdf7..dd3b803b 100644 --- a/src/Runner.js +++ b/src/Runner.js @@ -14,7 +14,7 @@ const fs = require('graceful-fs'); const path = require('path'); const http = require('http'); const https = require('https'); -const temp = require('temp'); +const tmp = require('tmp'); const ignores = require('./ignoreFiles'); const availableCpus = Math.max(require('os').cpus().length - 1, 1); @@ -190,13 +190,13 @@ function run(transformFile, paths, options) { }) .on('end', () => { const ext = path.extname(transformFile); - temp.open({ prefix: 'jscodeshift', suffix: ext }, (err, info) => { + tmp.file({ prefix: 'jscodeshift', postfix: ext }, (err, path, fd) => { if (err) return reject(err); - fs.write(info.fd, contents, function (err) { + fs.write(fd, contents, function (err) { if (err) return reject(err); - fs.close(info.fd, function(err) { + fs.close(fd, function(err) { if (err) return reject(err); - transform(info.path).then(resolve, reject); + transform(path).then(resolve, reject); }); }); }); diff --git a/utils/testUtils.js b/utils/testUtils.js index 3d5d44d4..e271f822 100644 --- a/utils/testUtils.js +++ b/utils/testUtils.js @@ -10,7 +10,7 @@ const fs = require('fs'); const path = require('path'); -const temp = require('temp'); +const tmp = require('tmp'); function renameFileTo(oldPath, newFilename, extension = '') { const projectPath = path.dirname(oldPath); @@ -21,12 +21,12 @@ function renameFileTo(oldPath, newFilename, extension = '') { } function createTempFileWith(content, filename, extension) { - const info = temp.openSync({ suffix: extension }); - let filePath = info.path; + const info = tmp.fileSync({ postfix: extension }); + let filePath = info.name; fs.writeSync(info.fd, content); fs.closeSync(info.fd); if (filename) { - filePath = renameFileTo(filePath, filename, extension); + filePath = renameFileTo(info.name, filename, extension); } return filePath; } diff --git a/yarn.lock b/yarn.lock index d02bebd7..9a7911dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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" @@ -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" @@ -2931,6 +2904,11 @@ tiny-invariant@^1.3.3: resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.3.3.tgz#46680b7a873a0d5d10005995eb90a70d74d60127" integrity sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg== +tmp@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.3.tgz#eb783cc22bc1e8bebd0671476d46ea4eb32a79ae" + integrity sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w== + tmpl@1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"