Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/app/src/cli/services/init/template/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {inTemporaryDirectory, mkdir, readFile, writeFile} from '@shopify/cli-kit
import {joinPath, moduleDirectory, normalizePath} from '@shopify/cli-kit/node/path'
import {platform} from 'os'

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

Expand Down
1 change: 0 additions & 1 deletion packages/cli-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@
"stacktracey": "2.1.8",
"strip-ansi": "7.1.0",
"supports-hyperlinks": "3.1.0",
"tempy": "3.1.0",
"terminal-link": "3.0.0",
"ts-error": "1.0.6",
"which": "4.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/cli-kit/src/private/node/temp-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {realpath} from 'fs/promises'
import {tmpdir} from 'os'

// Captured at module load time, before test mocks can interfere.
// Async realpath resolves symlinks (e.g. /var -> /private/var on macOS)
// and 8.3 short names on Windows (e.g. RUNNER~1 -> runneradmin),
// matching tempy's temp-dir behavior.
export const systemTempDir = await realpath(tmpdir())
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {beforeEach, describe, expect, test, vi} from 'vitest'
import {hostname} from 'os'
import {randomBytes} from 'crypto'

vi.mock('os')
vi.mock('os', async (importOriginal) => {
const actual = await importOriginal<typeof import('os')>()
return {...actual, hostname: vi.fn()}
})
vi.mock('crypto')

describe('generateThemeName', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/cli-kit/src/public/node/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import * as os from 'os'

vi.mock('../common/array.js')
vi.mock('fast-glob')
vi.mock('os')
vi.mock('os', async (importOriginal) => {
const actual = await importOriginal<typeof import('os')>()
return {...actual, EOL: actual.EOL}
})

describe('inTemporaryDirectory', () => {
test('ties the lifecycle of the temporary directory to the lifecycle of the callback', async () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/cli-kit/src/public/node/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {outputContent, outputToken, outputDebug} from './output.js'
import {joinPath, normalizePath} from './path.js'
import {OverloadParameters} from '../../private/common/ts/overloaded-parameters.js'
import {getRandomName, RandomNameFamily} from '../common/string.js'
import {systemTempDir} from '../../private/node/temp-dir.js'
import {
copy as fsCopy,
ensureFile as fsEnsureFile,
Expand All @@ -13,7 +14,6 @@ import {
// @ts-ignore
} from 'fs-extra/esm'

import {temporaryDirectory, temporaryDirectoryTask} from 'tempy'
import {sep, join} from 'pathe'
import {findUp as internalFindUp, findUpSync as internalFindUpSync} from 'find-up'
import {minimatch} from 'minimatch'
Expand All @@ -29,6 +29,7 @@ import {
constants as fsConstants,
existsSync as fsFileExistsSync,
unlinkSync as fsUnlinkSync,
mkdtempSync as fsMkdtempSync,
accessSync,
ReadStream,
WriteStream,
Expand Down Expand Up @@ -75,15 +76,20 @@ export function stripUpPath(path: string, strip: number): string {
* @param callback - The callback that receives the temporary directory.
*/
export async function inTemporaryDirectory<T>(callback: (tmpDir: string) => T | Promise<T>): Promise<T> {
return temporaryDirectoryTask(callback)
const tmpDir = await fsMkdtemp(join(systemTempDir, 'tmp-'))
try {
return await callback(tmpDir)
} finally {
await fsRm(tmpDir, {recursive: true, force: true, maxRetries: 2})
}
}

/**
* Return a temporary directory
* @returns - The path to the temporary directory.
*/
export function tempDirectory(): string {
return temporaryDirectory()
return fsMkdtempSync(join(systemTempDir, 'tmp-'))
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"@types/node": "18.19.70",
"execa": "^7.2.0",
"node-pty": "^1.0.0",
"strip-ansi": "^7.1.0",
"tempy": "^1.0.1"
"strip-ansi": "^7.1.0"
},
"engines": {
"node": ">=20.10.0"
Expand Down
117 changes: 0 additions & 117 deletions pnpm-lock.yaml

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

Loading
Loading