diff --git a/app/server/declarations/tmp.d.ts b/app/server/declarations/tmp.d.ts deleted file mode 100644 index 039ec371ffb..00000000000 --- a/app/server/declarations/tmp.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import {Options, SimpleOptions} from "tmp"; - -// Add declarations of the promisifies methods of tmp. -declare module "tmp" { - function dirAsync(config?: Options): Promise; - function fileAsync(config?: Options): Promise; - function tmpNameAsync(config?: SimpleOptions): Promise; -} diff --git a/app/server/lib/ActiveDoc.ts b/app/server/lib/ActiveDoc.ts index 447b10d8474..1bddad9b70c 100644 --- a/app/server/lib/ActiveDoc.ts +++ b/app/server/lib/ActiveDoc.ts @@ -148,7 +148,6 @@ import * as moment from 'moment-timezone'; import fetch from 'node-fetch'; import stream from 'node:stream'; import path from 'path'; -import tmp from 'tmp'; import {ActionHistory} from './ActionHistory'; import {ActionHistoryImpl} from './ActionHistoryImpl'; @@ -172,8 +171,6 @@ import sum = require('lodash/sum'); import throttle = require('lodash/throttle'); import without = require('lodash/without'); -bluebird.promisifyAll(tmp); - const MAX_RECENT_ACTIONS = 100; const DEFAULT_TIMEZONE = (process.versions as any).electron ? moment.tz.guess() : "UTC"; diff --git a/app/server/lib/DocPluginManager.ts b/app/server/lib/DocPluginManager.ts index ba778cc58c2..9d0da667f99 100644 --- a/app/server/lib/DocPluginManager.ts +++ b/app/server/lib/DocPluginManager.ts @@ -16,13 +16,9 @@ import { GristServer } from 'app/server/lib/GristServer'; import log from 'app/server/lib/log'; import { SafePythonComponent } from 'app/server/lib/SafePythonComponent'; import { UnsafeNodeComponent } from 'app/server/lib/UnsafeNodeComponent'; -import { promisifyAll } from 'bluebird'; import * as fse from 'fs-extra'; import * as path from 'path'; -import tmp from 'tmp'; - - -promisifyAll(tmp); +import * as tmp from 'tmp-promise'; /** * Implements GristDocAPI interface. @@ -196,7 +192,7 @@ export class DocPluginManager { } private async _initialize(): Promise { - this._tmpDir = await tmp.dirAsync({ prefix: 'grist-tmp-', unsafeCleanup: true }); + this._tmpDir = (await tmp.dir({ prefix: 'grist-tmp-', unsafeCleanup: true })).path; for (const plugin of this._localPlugins) { try { // todo: once Comm has been replaced by grain-rpc, pluginInstance.rpc should forward '*' to client diff --git a/app/server/lib/Requests.ts b/app/server/lib/Requests.ts index 2c12c947cc9..e37138d6ec8 100644 --- a/app/server/lib/Requests.ts +++ b/app/server/lib/Requests.ts @@ -16,7 +16,7 @@ export class DocRequests { // and only as long as needed to finish calculating all formulas. // When _numPending reaches 0 again, _cacheDir is deleted. private _numPending: number = 0; - private _cacheDir: tmp.SynchrounousResult | null = null; + private _cacheDir: tmp.DirResult | null = null; constructor(private readonly _activeDoc: ActiveDoc) {} diff --git a/app/server/lib/uploads.ts b/app/server/lib/uploads.ts index e76791b0582..8e8ce3b0982 100644 --- a/app/server/lib/uploads.ts +++ b/app/server/lib/uploads.ts @@ -401,7 +401,7 @@ interface TmpDirResult { * Helper to create a temporary directory. It's a simple wrapper around tmp.dir, but replaces the * cleanup callback with an asynchronous version. */ -export async function createTmpDir(options: tmp.Options): Promise { +export async function createTmpDir(options: tmp.DirOptions): Promise { const fullOptions = {prefix: 'grist-upload-', unsafeCleanup: true, ...options}; const [tmpDir, tmpCleanup]: [string, CleanupCB] = await fromCallback( diff --git a/package.json b/package.json index ce0b604aca5..9951d262438 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,7 @@ "@types/sinon": "17.0.3", "@types/sqlite3": "3.1.6", "@types/swagger-ui": "3.52.4", - "@types/tmp": "0.0.33", + "@types/tmp": "0.2.6", "@types/uuid": "10.0.0", "@types/webpack-dev-server": "4.7.2", "@types/which": "2.0.1", @@ -213,7 +213,7 @@ "slugify": "1.6.6", "swagger-ui-dist": "5.11.0", "tar-stream": "^3.1.7", - "tmp": "0.0.33", + "tmp": "0.2.5", "tmp-promise": "1.0.5", "ts-interface-checker": "1.0.2", "typeorm": "0.3.17", diff --git a/stubs/app/server/tmp.d.ts b/stubs/app/server/tmp.d.ts deleted file mode 100644 index ef0768e0f2d..00000000000 --- a/stubs/app/server/tmp.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Add declarations of the promisifies methods of tmp. -import {Options, SimpleOptions} from "tmp"; -declare module "tmp" { - function dirAsync(config?: Options): Promise; - function fileAsync(config?: Options): Promise; - function tmpNameAsync(config?: SimpleOptions): Promise; -} diff --git a/test/server/docTools.ts b/test/server/docTools.ts index 92ccc9a4bcd..c5a2a1ee16e 100644 --- a/test/server/docTools.ts +++ b/test/server/docTools.ts @@ -17,7 +17,7 @@ import {assert} from 'chai'; import * as fse from 'fs-extra'; import {tmpdir} from 'os'; import * as path from 'path'; -import * as tmp from 'tmp'; +import * as tmp from 'tmp-promise'; tmp.setGracefulCleanup(); @@ -168,12 +168,12 @@ export async function createDocManager( export async function createTmpDir(): Promise { const tmpRootDir = process.env.TESTDIR || tmpdir(); await fse.mkdirs(tmpRootDir); - return fse.realpath(await tmp.dirAsync({ + return (await tmp.dir({ dir: tmpRootDir, prefix: 'grist_test_', unsafeCleanup: true, keep: noCleanup, - })); + })).path; } /** diff --git a/test/server/lib/DocStorage.js b/test/server/lib/DocStorage.js index 875b193c628..269d7624e35 100644 --- a/test/server/lib/DocStorage.js +++ b/test/server/lib/DocStorage.js @@ -1,12 +1,10 @@ const assert = require('chai').assert; const child_process = require('child_process'); const fs = require('fs'); -const tmp = require('tmp'); const Promise = require('bluebird'); Promise.promisifyAll(child_process); Promise.promisifyAll(fs); -Promise.promisifyAll(tmp); const {ActionHistoryImpl} = require('app/server/lib/ActionHistoryImpl'); const {DocStorage} = require('app/server/lib/DocStorage'); @@ -15,8 +13,6 @@ const marshal = require('app/common/marshal'); const {createDocTools} = require('test/server/docTools'); const testUtils = require('test/server/testUtils'); -tmp.setGracefulCleanup(); - describe('DocStorage', function() { var docStorageManager; diff --git a/test/server/lib/DocStorageManager.ts b/test/server/lib/DocStorageManager.ts index 2dda2325286..f7481cde377 100644 --- a/test/server/lib/DocStorageManager.ts +++ b/test/server/lib/DocStorageManager.ts @@ -3,7 +3,7 @@ import {assert} from 'chai'; import * as fse from 'fs-extra'; import * as path from 'path'; -import * as tmp from 'tmp'; +import * as tmp from 'tmp-promise'; import {DocStorageManager} from 'app/server/lib/DocStorageManager'; import * as docUtils from 'app/server/lib/docUtils'; @@ -16,12 +16,10 @@ describe('DocStorageManager', function() { // Set Grist home to a temporary directory, and wipe it out on exit. let docsRoot: string; let docStorageManager: DocStorageManager; - before(function() { - return tmp.dirAsync({ prefix: 'grist_test_', unsafeCleanup: true }) - .then(tmpDir => { - docsRoot = fse.realpathSync(tmpDir); - docStorageManager = new DocStorageManager(docsRoot); - }); + before(async function() { + const tmpDir = (await tmp.dir({ prefix: 'grist_test_', unsafeCleanup: true })).path; + docsRoot = fse.realpathSync(tmpDir); + docStorageManager = new DocStorageManager(docsRoot); }); describe('getPath', function() { @@ -81,7 +79,7 @@ describe('DocStorageManager', function() { // First create a doc, one under docsRoot, one outside; and include an attachment. fse.writeFileSync(doc1, "this is a test"); const doc2 = tmp.fileSync({ - prefix: 'DeleteTest2', postfix: '.grist', unsafeCleanup: true, + prefix: 'DeleteTest2', postfix: '.grist', discardDescriptor: true }).name; // Check that items got created as we expect. diff --git a/test/server/lib/DocStorageMigrations.ts b/test/server/lib/DocStorageMigrations.ts index 68f887ca23a..9ff4985e9e8 100644 --- a/test/server/lib/DocStorageMigrations.ts +++ b/test/server/lib/DocStorageMigrations.ts @@ -7,7 +7,7 @@ import * as fse from 'fs-extra'; import * as path from 'path'; import * as testUtils from 'test/server/testUtils'; import {assert} from 'test/server/testUtils'; -import * as tmp from 'tmp'; +import * as tmp from 'tmp-promise'; tmp.setGracefulCleanup(); const execFileAsync = promisify(child_process.execFile); @@ -20,7 +20,7 @@ describe('DocStorageMigrations', function() { before(async function() { // Set Grist home to a temporary directory, and wipe it out on exit. - let tmpDir = await tmp.dirAsync({ prefix: 'grist_test_', unsafeCleanup: true }); + let tmpDir = (await tmp.dir({ prefix: 'grist_test_', unsafeCleanup: true })).path; tmpDir = await fse.realpath(tmpDir); docStorageManager = new DocStorageManager(tmpDir); }); diff --git a/test/server/lib/SQLiteDB.ts b/test/server/lib/SQLiteDB.ts index 629f8070495..e19d3a23f39 100644 --- a/test/server/lib/SQLiteDB.ts +++ b/test/server/lib/SQLiteDB.ts @@ -2,7 +2,7 @@ import {assert} from 'chai'; import * as fse from 'fs-extra'; import {map, noop} from 'lodash'; import {join as pathJoin} from 'path'; -import * as tmp from 'tmp'; +import * as tmp from 'tmp-promise'; import {delay} from 'app/common/delay'; import {OpenMode, SchemaInfo, SQLiteDB} from 'app/server/lib/SQLiteDB'; @@ -13,17 +13,18 @@ tmp.setGracefulCleanup(); describe('SQLiteDB', function() { let tmpDir: string; + let cleanup: () => void; // Turn off logging for this test, and restore afterwards. testUtils.setTmpLogLevel('warn'); before(async function() { // Create a temporary directory, and wipe it out on exit. - tmpDir = await tmp.dirAsync({ prefix: 'grist_test_SQLiteDB_', unsafeCleanup: true }); + ({path: tmpDir, cleanup} = await tmp.dir({ prefix: 'grist_test_SQLiteDB_', unsafeCleanup: true })); }); - after(async function() { - await fse.remove(tmpDir); + after(function() { + cleanup(); }); // Convenience helpers to make tests more concise and readable. diff --git a/test/server/lib/TestingHooks.ts b/test/server/lib/TestingHooks.ts index 5a4c39cd647..732d53fb7d8 100644 --- a/test/server/lib/TestingHooks.ts +++ b/test/server/lib/TestingHooks.ts @@ -1,14 +1,14 @@ import {connectTestingHooks, startTestingHooks, TestingHooksClient} from 'app/server/lib/TestingHooks'; import {assert, setTmpLogLevel} from 'test/server/testUtils'; -import * as tmp from 'tmp'; +import * as tmp from 'tmp-promise'; tmp.setGracefulCleanup(); describe('TestingHooks', function() { setTmpLogLevel('warn'); it('should start server and accept basic calls', async function() { - const tmpName: string = await tmp.tmpNameAsync({prefix: 'gristtest-'}); + const tmpName: string = await tmp.tmpName({prefix: 'gristtest-'}); const server = await startTestingHooks(tmpName, 192348, null as any, null as any, []); const stub: TestingHooksClient = await connectTestingHooks(tmpName); try { diff --git a/test/server/testUtils.ts b/test/server/testUtils.ts index a28a8da216b..6b87e6f09d1 100644 --- a/test/server/testUtils.ts +++ b/test/server/testUtils.ts @@ -17,7 +17,7 @@ import * as path from 'path'; import * as fse from 'fs-extra'; import clone = require('lodash/clone'); import * as tmp from 'tmp-promise'; -import {Options as TmpOptions} from 'tmp'; +import {FileOptions as TmpOptions} from 'tmp'; import * as winston from 'winston'; import { serialize } from 'winston/lib/winston/common'; diff --git a/test/upgradeDocumentImpl.ts b/test/upgradeDocumentImpl.ts index f4cb037e4df..c7b6644c318 100644 --- a/test/upgradeDocumentImpl.ts +++ b/test/upgradeDocumentImpl.ts @@ -12,7 +12,7 @@ import log from 'app/server/lib/log'; import * as fs from "fs"; import * as fse from "fs-extra"; import * as path from "path"; -import * as tmp from "tmp"; +import * as tmp from "tmp-promise"; export async function upgradeDocuments(docPaths: string[]): Promise { const docTools = createDocTools(); @@ -31,7 +31,7 @@ export async function upgradeDocuments(docPaths: string[]): Promise { } export async function upgradeDocumentsDocStorageOnly(paths: string[]): Promise { - let tmpDir = await tmp.dirAsync({ prefix: 'grist_migrate_', unsafeCleanup: true }); + let tmpDir = (await tmp.dir({ prefix: 'grist_migrate_', unsafeCleanup: true })).path; tmpDir = await fse.realpath(tmpDir); const docStorageManager = new DocStorageManager(tmpDir); diff --git a/yarn.lock b/yarn.lock index 1f582d720b7..608f9592d09 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1484,10 +1484,10 @@ dependencies: "@types/node" "*" -"@types/tmp@0.0.33": - version "0.0.33" - resolved "https://registry.npmjs.org/@types/tmp/-/tmp-0.0.33.tgz" - integrity sha1-EHPEvIJHVK49EM+riKsCN7qWTk0= +"@types/tmp@0.2.6": + version "0.2.6" + resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.2.6.tgz#d785ee90c52d7cc020e249c948c36f7b32d1e217" + integrity sha512-chhaNf2oKHlRkDGt+tiKE2Z5aJ6qalm7Z9rlLdBwmOiAAf09YQvvoLXjWK4HWPF1xU/fqvMgfNfpVoBscA/tKA== "@types/tough-cookie@*": version "4.0.2" @@ -7059,8 +7059,8 @@ os-browserify@~0.3.0: os-tmpdir@~1.0.2: version "1.0.2" - resolved "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz" - integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g== otplib@12.0.1: version "12.0.1" @@ -7950,7 +7950,7 @@ rimraf@2: dependencies: glob "^7.1.3" -rimraf@^3.0.0, rimraf@^3.0.2: +rimraf@^3.0.2: version "3.0.2" resolved "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz" integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== @@ -8911,7 +8911,7 @@ tldts@^6.1.32: tmp-promise@1.0.5: version "1.0.5" - resolved "https://registry.npmjs.org/tmp-promise/-/tmp-promise-1.0.5.tgz" + resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-1.0.5.tgz#3208d7fa44758f86a2a4c4060f3c33fea30e8038" integrity sha512-hOabTz9Tp49wCozFwuJe5ISrOqkECm6kzw66XTP23DuzNU7QS/KiZq5LC9Y7QSy8f1rPSLy4bKaViP0OwGI1cA== dependencies: bluebird "^3.5.0" @@ -8919,22 +8919,20 @@ tmp-promise@1.0.5: tmp@0.0.33: version "0.0.33" - resolved "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== dependencies: os-tmpdir "~1.0.2" -tmp@^0.2.0: - version "0.2.1" - resolved "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz" - integrity sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ== - dependencies: - rimraf "^3.0.0" +tmp@0.2.5: + version "0.2.5" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.5.tgz#b06bcd23f0f3c8357b426891726d16015abfd8f8" + integrity sha512-voyz6MApa1rQGUxT3E+BK7/ROe8itEx7vD8/HEvt4xwXucvQ5G5oeEiHkmHZJuBO21RpOf+YYm9MOivj709jow== -tmp@^0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.3.tgz#eb783cc22bc1e8bebd0671476d46ea4eb32a79ae" - integrity sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w== +tmp@^0.2.0, tmp@^0.2.3: + version "0.2.4" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.2.4.tgz#c6db987a2ccc97f812f17137b36af2b6521b0d13" + integrity sha512-UdiSoX6ypifLmrfQ/XfiawN6hkjSBpCjhKxxZcWlUUmoXLaCKQU0bx4HF/tdDK2uzRuchf1txGvrWBzYREssoQ== to-arraybuffer@^1.0.0: version "1.0.1"