Skip to content

Commit 3cc05bf

Browse files
authored
Merge pull request #7180 from Shopify/04-02-remove-tempy
Remove tempy dependency, use Node builtins for temp directories
2 parents 685faef + 73a9304 commit 3cc05bf

10 files changed

Lines changed: 38 additions & 131 deletions

File tree

packages/app/src/cli/services/init/template/npm.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {inTemporaryDirectory, mkdir, readFile, writeFile} from '@shopify/cli-kit
55
import {joinPath, moduleDirectory, normalizePath} from '@shopify/cli-kit/node/path'
66
import {platform} from 'os'
77

8-
vi.mock('os')
8+
vi.mock('os', async (importOriginal) => {
9+
const actual = await importOriginal<typeof import('os')>()
10+
return {...actual, platform: vi.fn()}
11+
})
912
vi.mock('@shopify/cli-kit/node/node-package-manager')
1013
vi.mock('@shopify/cli-kit/common/version', () => ({CLI_KIT_VERSION: '1.2.3'}))
1114

packages/cli-kit/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
"stacktracey": "2.1.8",
157157
"strip-ansi": "7.1.0",
158158
"supports-hyperlinks": "3.1.0",
159-
"tempy": "3.1.0",
160159
"terminal-link": "3.0.0",
161160
"ts-error": "1.0.6",
162161
"which": "4.0.0",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {realpath} from 'fs/promises'
2+
import {tmpdir} from 'os'
3+
4+
// Captured at module load time, before test mocks can interfere.
5+
// Async realpath resolves symlinks (e.g. /var -> /private/var on macOS)
6+
// and 8.3 short names on Windows (e.g. RUNNER~1 -> runneradmin),
7+
// matching tempy's temp-dir behavior.
8+
export const systemTempDir = await realpath(tmpdir())

packages/cli-kit/src/private/node/themes/generate-theme-name.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import {beforeEach, describe, expect, test, vi} from 'vitest'
33
import {hostname} from 'os'
44
import {randomBytes} from 'crypto'
55

6-
vi.mock('os')
6+
vi.mock('os', async (importOriginal) => {
7+
const actual = await importOriginal<typeof import('os')>()
8+
return {...actual, hostname: vi.fn()}
9+
})
710
vi.mock('crypto')
811

912
describe('generateThemeName', () => {

packages/cli-kit/src/public/node/fs.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import * as os from 'os'
3232

3333
vi.mock('../common/array.js')
3434
vi.mock('fast-glob')
35-
vi.mock('os')
35+
vi.mock('os', async (importOriginal) => {
36+
const actual = await importOriginal<typeof import('os')>()
37+
return {...actual, EOL: actual.EOL}
38+
})
3639

3740
describe('inTemporaryDirectory', () => {
3841
test('ties the lifecycle of the temporary directory to the lifecycle of the callback', async () => {

packages/cli-kit/src/public/node/fs.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {outputContent, outputToken, outputDebug} from './output.js'
22
import {joinPath, normalizePath} from './path.js'
33
import {OverloadParameters} from '../../private/common/ts/overloaded-parameters.js'
44
import {getRandomName, RandomNameFamily} from '../common/string.js'
5+
import {systemTempDir} from '../../private/node/temp-dir.js'
56
import {
67
copy as fsCopy,
78
ensureFile as fsEnsureFile,
@@ -13,7 +14,6 @@ import {
1314
// @ts-ignore
1415
} from 'fs-extra/esm'
1516

16-
import {temporaryDirectory, temporaryDirectoryTask} from 'tempy'
1717
import {sep, join} from 'pathe'
1818
import {findUp as internalFindUp, findUpSync as internalFindUpSync} from 'find-up'
1919
import {minimatch} from 'minimatch'
@@ -29,6 +29,7 @@ import {
2929
constants as fsConstants,
3030
existsSync as fsFileExistsSync,
3131
unlinkSync as fsUnlinkSync,
32+
mkdtempSync as fsMkdtempSync,
3233
accessSync,
3334
ReadStream,
3435
WriteStream,
@@ -75,15 +76,20 @@ export function stripUpPath(path: string, strip: number): string {
7576
* @param callback - The callback that receives the temporary directory.
7677
*/
7778
export async function inTemporaryDirectory<T>(callback: (tmpDir: string) => T | Promise<T>): Promise<T> {
78-
return temporaryDirectoryTask(callback)
79+
const tmpDir = await fsMkdtemp(join(systemTempDir, 'tmp-'))
80+
try {
81+
return await callback(tmpDir)
82+
} finally {
83+
await fsRm(tmpDir, {recursive: true, force: true, maxRetries: 2})
84+
}
7985
}
8086

8187
/**
8288
* Return a temporary directory
8389
* @returns - The path to the temporary directory.
8490
*/
8591
export function tempDirectory(): string {
86-
return temporaryDirectory()
92+
return fsMkdtempSync(join(systemTempDir, 'tmp-'))
8793
}
8894

8995
/**

packages/e2e/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
"@types/node": "18.19.70",
3434
"execa": "^7.2.0",
3535
"node-pty": "^1.0.0",
36-
"strip-ansi": "^7.1.0",
37-
"tempy": "^1.0.1"
36+
"strip-ansi": "^7.1.0"
3837
},
3938
"engines": {
4039
"node": ">=20.10.0"

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)