Skip to content

Commit ebc683a

Browse files
authored
chore: update tmp (#25404)
1 parent 3df36ec commit ebc683a

File tree

4 files changed

+28
-72
lines changed

4 files changed

+28
-72
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@
17131713
"semver": "^7.5.2",
17141714
"stack-trace": "0.0.10",
17151715
"sudo-prompt": "^9.2.1",
1716-
"tmp": "^0.0.33",
1716+
"tmp": "^0.2.5",
17171717
"uint64be": "^3.0.0",
17181718
"unicode": "^14.0.0",
17191719
"vscode-debugprotocol": "^1.28.0",

src/client/common/platform/fs-temp.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import * as tmp from 'tmp';
55
import { ITempFileSystem, TemporaryFile } from './types';
66

77
interface IRawTempFS {
8-
// TODO (https://github.com/microsoft/vscode/issues/84517)
9-
// This functionality has been requested for the
10-
// VS Code FS API (vscode.workspace.fs.*).
11-
file(
12-
config: tmp.Options,
13-
14-
callback?: (err: any, path: string, fd: number, cleanupCallback: () => void) => void,
15-
): void;
8+
fileSync(config?: tmp.Options): tmp.SynchrounousResult;
169
}
1710

1811
// Operations related to temporary files and directories.
@@ -35,14 +28,13 @@ export class TemporaryFileSystem implements ITempFileSystem {
3528
mode,
3629
};
3730
return new Promise<TemporaryFile>((resolve, reject) => {
38-
this.raw.file(opts, (err, filename, _fd, cleanUp) => {
39-
if (err) {
40-
return reject(err);
41-
}
42-
resolve({
43-
filePath: filename,
44-
dispose: cleanUp,
45-
});
31+
const { name, removeCallback } = this.raw.fileSync(opts);
32+
if (!name) {
33+
return reject(new Error('Failed to create temp file'));
34+
}
35+
resolve({
36+
filePath: name,
37+
dispose: removeCallback,
4638
});
4739
});
4840
}

src/test/common/platform/fs-temp.unit.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ import { TemporaryFileSystem } from '../../../client/common/platform/fs-temp';
77

88
interface IDeps {
99
// tmp module
10-
file(
11-
config: { postfix?: string; mode?: number },
12-
13-
callback?: (err: any, path: string, fd: number, cleanupCallback: () => void) => void,
14-
): void;
10+
fileSync(config: {
11+
postfix?: string;
12+
mode?: number;
13+
}): {
14+
name: string;
15+
fd: number;
16+
removeCallback(): void;
17+
};
1518
}
1619

1720
suite('FileSystem - temp files', () => {
@@ -28,7 +31,7 @@ suite('FileSystem - temp files', () => {
2831
suite('createFile', () => {
2932
test(`fails if the raw call fails`, async () => {
3033
const failure = new Error('oops');
31-
deps.setup((d) => d.file({ postfix: '.tmp', mode: undefined }, TypeMoq.It.isAny()))
34+
deps.setup((d) => d.fileSync({ postfix: '.tmp', mode: undefined }))
3235
// fail with an arbitrary error
3336
.throws(failure);
3437

@@ -40,7 +43,7 @@ suite('FileSystem - temp files', () => {
4043

4144
test(`fails if the raw call "returns" an error`, async () => {
4245
const failure = new Error('oops');
43-
deps.setup((d) => d.file({ postfix: '.tmp', mode: undefined }, TypeMoq.It.isAny())).callback((_cfg, cb) =>
46+
deps.setup((d) => d.fileSync({ postfix: '.tmp', mode: undefined })).callback((_cfg, cb) =>
4447
cb(failure, '...', -1, () => {}),
4548
);
4649

0 commit comments

Comments
 (0)