diff --git a/configurations/tsconfig.json b/configurations/tsconfig.json index d9f19af433a..456af0c28c5 100644 --- a/configurations/tsconfig.json +++ b/configurations/tsconfig.json @@ -19,6 +19,7 @@ "noUncheckedIndexedAccess": true, "jsx": "react", "paths": { + "@shopify/cli-kit": ["../packages/cli-kit/src/index"], "@shopify/cli-kit/*": ["../packages/cli-kit/src/public/*"], "@shopify/theme/*": ["../packages/theme/src/*"], "@shopify/cli-kit/typing/*": ["../packages/cli-kit/src/typing/*"], diff --git a/docs/cli/testing-strategy.md b/docs/cli/testing-strategy.md index 6244f7a2a9a..2db6f850741 100644 --- a/docs/cli/testing-strategy.md +++ b/docs/cli/testing-strategy.md @@ -40,19 +40,19 @@ pnpm test path/to/my.test.ts If the subject under testing does a filesystem I/O operation, we recommend not stubbing that behavior instead of hitting the filesystem. Create a temporary directory whose lifecycle is tied to the lifecycle of the test: ```ts -import {file, path} from "@shopify/cli-kit" +import {exists, inTemporaryDirectory, writeFile} from "@shopify/cli-kit/node/fs" +import {joinPath} from "@shopify/cli-kit/node/path" test("writes", async () => { - await file.inTemporaryDirectory(async (tmpDir: string) => { + await inTemporaryDirectory(async (tmpDir: string) => { // Given - const outputPath = path.join(tmpDir, "output") + const outputPath = joinPath(tmpDir, "output") // When - await file.write(outputPath, "content") + await writeFile(outputPath, "content") // Then - const exists = await file.exists(outputPath) - expect(exists).toBe(true) + expect(await exists(outputPath)).toBe(true) }) }) ``` diff --git a/packages/cli-kit/src/index.test.ts b/packages/cli-kit/src/index.test.ts new file mode 100644 index 00000000000..dba38017100 --- /dev/null +++ b/packages/cli-kit/src/index.test.ts @@ -0,0 +1,9 @@ +import {file, path} from './index.js' +import {describe, expect, test} from 'vitest' + +describe('root exports', () => { + test('exposes documented filesystem and path helpers', () => { + expect(file.inTemporaryDirectory).toBeTypeOf('function') + expect(path.joinPath).toBeTypeOf('function') + }) +}) diff --git a/packages/cli-kit/src/index.ts b/packages/cli-kit/src/index.ts new file mode 100644 index 00000000000..cb5a357d16f --- /dev/null +++ b/packages/cli-kit/src/index.ts @@ -0,0 +1,2 @@ +export * as file from './public/node/fs.js' +export * as path from './public/node/path.js'