Skip to content

Commit

Permalink
chore(import-export): remove production dependency on temp COMPASS-7975
Browse files Browse the repository at this point in the history
… (#5826)

chore(import-export): remove production dependency on temp
  • Loading branch information
mcasimir authored Jun 5, 2024
1 parent fcdb908 commit 1a91160
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/compass-import-export/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
"redux": "^4.2.1",
"redux-thunk": "^2.4.2",
"stream-json": "^1.7.5",
"strip-bom-stream": "^4.0.0",
"temp": "^0.9.4"
"strip-bom-stream": "^4.0.0"
},
"devDependencies": {
"@mongodb-js/compass-test-server": "^0.1.16",
Expand Down Expand Up @@ -106,6 +105,7 @@
"react-dom": "^17.0.2",
"sinon": "^9.2.3",
"sinon-chai": "^3.7.0",
"temp": "^0.9.4",
"typescript": "^5.0.4",
"xvfb-maybe": "^0.2.1"
},
Expand Down
11 changes: 9 additions & 2 deletions packages/compass-import-export/src/export/export-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs';
import { EJSON } from 'bson';
import type { Document } from 'bson';
import { pipeline } from 'stream/promises';
import temp from 'temp';
import { Transform } from 'stream';
import type { Readable, Writable } from 'stream';
import toNS from 'mongodb-ns';
Expand All @@ -11,6 +10,8 @@ import type { PreferencesAccess } from 'compass-preferences-model/provider';
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provider';
import Parser from 'stream-json/Parser';
import StreamValues from 'stream-json/streamers/StreamValues';
import path from 'path';
import os from 'os';

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

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

const generateTempFilename = (suffix: string) => {
const randomString = Math.random().toString(36).substring(2, 15);
const filename = `temp-${randomString}${suffix}`;
return path.join(os.tmpdir(), filename);
};

// First we download all the docs for the query/aggregation to a temporary file
// while determining the unique set of columns we'll need and their order
// (DOWNLOAD), then we write the header row, then process that temp file in
Expand Down Expand Up @@ -223,7 +230,7 @@ async function loadEJSONFileAndColumns({
// while simultaneously determining the unique set of columns in the order
// we'll have to write to the file.
const inputStream = cursor.stream();
const filename = temp.path({ suffix: '.jsonl' });
const filename = generateTempFilename('.jsonl');
const output = fs.createWriteStream(filename);

const columnStream = new ColumnStream(progressCallback);
Expand Down
3 changes: 0 additions & 3 deletions packages/compass-import-export/src/modules/export.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import os from 'os';
import { expect } from 'chai';
import temp from 'temp';
import fs from 'fs';
import path from 'path';
import Sinon from 'sinon';
import type { DataService } from 'mongodb-data-service';
import { connect } from 'mongodb-data-service';
import AppRegistry from 'hadron-app-registry';

temp.track();

import {
openExport,
addFieldToExport,
Expand Down

0 comments on commit 1a91160

Please sign in to comment.