From bed71f910a6b2121749efff040962288634ef883 Mon Sep 17 00:00:00 2001 From: Brendan Nee Date: Mon, 17 Jun 2024 11:54:07 -0700 Subject: [PATCH] Use tempy for temporary directory creation --- CHANGELOG.md | 4 ++ lib/import.js | 10 ++--- package-lock.json | 99 ++++++++++++++++++++++++++++++++++++++++------- package.json | 2 +- 4 files changed, 95 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f607646e..0085ce72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for `service_id` in `getRoutes` +### Changed + +- Use tempy for temporary directory creation + ## [4.11.3] - 2024-06-13 ### Fixed diff --git a/lib/import.js b/lib/import.js index 4386a511..cebc8116 100644 --- a/lib/import.js +++ b/lib/import.js @@ -1,11 +1,11 @@ import path from 'node:path'; import { createReadStream, existsSync, lstatSync } from 'node:fs'; -import { cp, readdir, rename, readFile, writeFile } from 'node:fs/promises'; +import { cp, readdir, rename, readFile, rm, writeFile } from 'node:fs/promises'; import fetch from 'node-fetch'; import { parse } from 'csv-parse'; import pluralize from 'pluralize'; import stripBomStream from 'strip-bom-stream'; -import { dir } from 'tmp-promise'; +import { temporaryDirectory } from 'tempy'; import untildify from 'untildify'; import mapSeries from 'promise-map-series'; import GtfsRealtimeBindings from 'gtfs-realtime-bindings'; @@ -687,7 +687,7 @@ export async function importGtfs(initialConfig) { createTables(db); await mapSeries(config.agencies, async (agency) => { - const { path, cleanup } = await dir({ unsafeCleanup: true }); + const tempPath = temporaryDirectory(); const task = { exclude: agency.exclude, @@ -695,7 +695,7 @@ export async function importGtfs(initialConfig) { headers: agency.headers || false, realtime_headers: agency.realtimeHeaders || false, realtime_urls: agency.realtimeUrls || false, - downloadDir: path, + downloadDir: tempPath, downloadTimeout: config.downloadTimeout, path: agency.path, csvOptions: config.csvOptions || {}, @@ -719,7 +719,7 @@ export async function importGtfs(initialConfig) { await updateRealtimeData(task); } - cleanup(); + await rm(tempPath, { recursive: true }); } catch (error) { if (config.ignoreErrors) { logError(error.message); diff --git a/package-lock.json b/package-lock.json index 61828528..40a55b5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "sanitize-filename": "^1.6.3", "sqlstring-sqlite": "^0.1.1", "strip-bom-stream": "^5.0.0", - "tmp-promise": "^3.0.3", + "tempy": "^3.1.0", "untildify": "^5.0.0", "yargs": "^17.7.2", "yoctocolors": "^2.0.2" @@ -178,9 +178,9 @@ } }, "node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.12.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", + "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", "license": "MIT", "bin": { "acorn": "bin/acorn" @@ -703,6 +703,33 @@ "node": ">= 8" } }, + "node_modules/crypto-random-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-4.0.0.tgz", + "integrity": "sha512-x8dy3RnvYdlUcPOjkEHqozhiwzKNSq7GcPuXFbnyMOCHxX8V3OgIg/pYuabl2sbUPfIJaeAQB7PMOK8DFIdoRA==", + "license": "MIT", + "dependencies": { + "type-fest": "^1.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/crypto-random-string/node_modules/type-fest": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", + "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/css-select": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-4.3.0.tgz", @@ -1898,7 +1925,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", - "dev": true, "license": "MIT", "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" @@ -3745,6 +3771,33 @@ "node": ">=6" } }, + "node_modules/temp-dir": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-3.0.0.tgz", + "integrity": "sha512-nHc6S/bwIilKHNRgK/3jlhDoIHcp45YgyiwcAk46Tr0LfEqGBVpmiAyuiuxeVE44m3mXnEeVhaipLOEWmH+Njw==", + "license": "MIT", + "engines": { + "node": ">=14.16" + } + }, + "node_modules/tempy": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/tempy/-/tempy-3.1.0.tgz", + "integrity": "sha512-7jDLIdD2Zp0bDe5r3D2qtkd1QOCacylBuL7oa4udvN6v2pqr4+LcCr67C8DR1zkpaZ8XosF5m1yQSabKAW6f2g==", + "license": "MIT", + "dependencies": { + "is-stream": "^3.0.0", + "temp-dir": "^3.0.0", + "type-fest": "^2.12.2", + "unique-string": "^3.0.0" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/tmp": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", @@ -3754,15 +3807,6 @@ "node": ">=14.14" } }, - "node_modules/tmp-promise": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/tmp-promise/-/tmp-promise-3.0.3.tgz", - "integrity": "sha512-RwM7MoPojPxsOBYnyd2hy0bxtIlVrihNs9pj5SUvY8Zz1sQcQG2tG1hSr8PDxfgEB8RNKDhqbIlroIarSNDNsQ==", - "license": "MIT", - "dependencies": { - "tmp": "^0.2.0" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -3815,6 +3859,18 @@ "node": ">= 0.8.0" } }, + "node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/uc.micro": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz", @@ -3845,6 +3901,21 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "license": "MIT" }, + "node_modules/unique-string": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-3.0.0.tgz", + "integrity": "sha512-VGXBUVwxKMBUznyffQweQABPRRW1vHZAbadFZud4pLFAqRGvv/96vafgjWFqzourzr8YonlQiPgH0YCJfawoGQ==", + "license": "MIT", + "dependencies": { + "crypto-random-string": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/untildify": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/untildify/-/untildify-5.0.0.tgz", diff --git a/package.json b/package.json index e9d83f81..9fcad770 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "sanitize-filename": "^1.6.3", "sqlstring-sqlite": "^0.1.1", "strip-bom-stream": "^5.0.0", - "tmp-promise": "^3.0.3", + "tempy": "^3.1.0", "untildify": "^5.0.0", "yargs": "^17.7.2", "yoctocolors": "^2.0.2"