Skip to content

Commit 1a91160

Browse files
authored
chore(import-export): remove production dependency on temp COMPASS-7975 (#5826)
chore(import-export): remove production dependency on temp
1 parent fcdb908 commit 1a91160

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

package-lock.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-import-export/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@
7474
"redux": "^4.2.1",
7575
"redux-thunk": "^2.4.2",
7676
"stream-json": "^1.7.5",
77-
"strip-bom-stream": "^4.0.0",
78-
"temp": "^0.9.4"
77+
"strip-bom-stream": "^4.0.0"
7978
},
8079
"devDependencies": {
8180
"@mongodb-js/compass-test-server": "^0.1.16",
@@ -106,6 +105,7 @@
106105
"react-dom": "^17.0.2",
107106
"sinon": "^9.2.3",
108107
"sinon-chai": "^3.7.0",
108+
"temp": "^0.9.4",
109109
"typescript": "^5.0.4",
110110
"xvfb-maybe": "^0.2.1"
111111
},

packages/compass-import-export/src/export/export-csv.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fs from 'fs';
22
import { EJSON } from 'bson';
33
import type { Document } from 'bson';
44
import { pipeline } from 'stream/promises';
5-
import temp from 'temp';
65
import { Transform } from 'stream';
76
import type { Readable, Writable } from 'stream';
87
import toNS from 'mongodb-ns';
@@ -11,6 +10,8 @@ import type { PreferencesAccess } from 'compass-preferences-model/provider';
1110
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provider';
1211
import Parser from 'stream-json/Parser';
1312
import StreamValues from 'stream-json/streamers/StreamValues';
13+
import path from 'path';
14+
import os from 'os';
1415

1516
import { lookupValueForPath, ColumnRecorder } from './export-utils';
1617
import {
@@ -31,6 +32,12 @@ import type { AggregationCursor, FindCursor } from 'mongodb';
3132

3233
const debug = createDebug('export-csv');
3334

35+
const generateTempFilename = (suffix: string) => {
36+
const randomString = Math.random().toString(36).substring(2, 15);
37+
const filename = `temp-${randomString}${suffix}`;
38+
return path.join(os.tmpdir(), filename);
39+
};
40+
3441
// First we download all the docs for the query/aggregation to a temporary file
3542
// while determining the unique set of columns we'll need and their order
3643
// (DOWNLOAD), then we write the header row, then process that temp file in
@@ -223,7 +230,7 @@ async function loadEJSONFileAndColumns({
223230
// while simultaneously determining the unique set of columns in the order
224231
// we'll have to write to the file.
225232
const inputStream = cursor.stream();
226-
const filename = temp.path({ suffix: '.jsonl' });
233+
const filename = generateTempFilename('.jsonl');
227234
const output = fs.createWriteStream(filename);
228235

229236
const columnStream = new ColumnStream(progressCallback);

packages/compass-import-export/src/modules/export.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import os from 'os';
22
import { expect } from 'chai';
3-
import temp from 'temp';
43
import fs from 'fs';
54
import path from 'path';
65
import Sinon from 'sinon';
76
import type { DataService } from 'mongodb-data-service';
87
import { connect } from 'mongodb-data-service';
98
import AppRegistry from 'hadron-app-registry';
109

11-
temp.track();
12-
1310
import {
1411
openExport,
1512
addFieldToExport,

0 commit comments

Comments
 (0)