From 5c57c19b17ab046f6c314bb1f3e4851e9691f8ae Mon Sep 17 00:00:00 2001 From: zhongliang02 Date: Tue, 19 Nov 2024 16:29:04 +0800 Subject: [PATCH] fix: node path import (#32) * fix: replace node: imports --- apps/docs/.vitepress/utils.ts | 4 ++-- packages/eslint-config/index.js | 2 +- packages/safe-fs/src/__tests__/fs.test.ts | 5 ++--- packages/safe-fs/src/getter.ts | 2 +- packages/safe-fs/src/index.ts | 2 +- packages/safe-fs/src/sanitizers.ts | 4 ++-- packages/safe-fs/vitest.config.ts | 2 +- packages/safe-fs/vitest.setup.ts | 4 ++-- packages/validators/package.json | 2 +- packages/validators/src/__tests__/path.test.ts | 3 +-- packages/validators/src/path/options.ts | 3 +-- packages/validators/src/path/schema.ts | 3 +-- packages/validators/src/path/utils.ts | 2 +- packages/validators/vitest.config.ts | 2 +- 14 files changed, 18 insertions(+), 22 deletions(-) diff --git a/apps/docs/.vitepress/utils.ts b/apps/docs/.vitepress/utils.ts index 565a82a..6940e41 100644 --- a/apps/docs/.vitepress/utils.ts +++ b/apps/docs/.vitepress/utils.ts @@ -1,5 +1,5 @@ -import fs from 'node:fs' -import path from 'node:path' +import fs from 'fs' +import path from 'path' export const scanDir = (dir: string) => { let res = fs.readdirSync(path.resolve(__dirname, `../${dir}`)).filter(item => !item.startsWith('.')) as string[] diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index cfe18a2..dc53b40 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -1,4 +1,4 @@ -const { resolve } = require("node:path"); +const { resolve } = require("path"); const project = resolve(process.cwd(), "tsconfig.json"); diff --git a/packages/safe-fs/src/__tests__/fs.test.ts b/packages/safe-fs/src/__tests__/fs.test.ts index f17b73d..3fd5664 100644 --- a/packages/safe-fs/src/__tests__/fs.test.ts +++ b/packages/safe-fs/src/__tests__/fs.test.ts @@ -1,7 +1,6 @@ -import fs from 'node:fs' -import path from 'node:path' - +import fs from 'fs' import { vol } from 'memfs' +import path from 'path' import { beforeEach, describe, expect, it } from 'vitest' import { createGetter } from '@/getter' diff --git a/packages/safe-fs/src/getter.ts b/packages/safe-fs/src/getter.ts index be4071e..094cf93 100644 --- a/packages/safe-fs/src/getter.ts +++ b/packages/safe-fs/src/getter.ts @@ -1,4 +1,4 @@ -import fs from 'node:fs' +import fs from 'fs' import PARAMS_TO_SANITIZE from '@/params' import { sanitizePath } from '@/sanitizers' diff --git a/packages/safe-fs/src/index.ts b/packages/safe-fs/src/index.ts index e5e5779..58d46f5 100644 --- a/packages/safe-fs/src/index.ts +++ b/packages/safe-fs/src/index.ts @@ -4,7 +4,7 @@ * @packageDocumentation */ -import * as fs from 'node:fs' +import * as fs from 'fs' import { createGetter } from '@/getter' diff --git a/packages/safe-fs/src/sanitizers.ts b/packages/safe-fs/src/sanitizers.ts index 3dcd009..054f821 100644 --- a/packages/safe-fs/src/sanitizers.ts +++ b/packages/safe-fs/src/sanitizers.ts @@ -1,5 +1,5 @@ -import { PathLike } from 'node:fs' -import path from 'node:path' +import { PathLike } from 'fs' +import path from 'path' const LEADING_DOT_SLASH_REGEX = /^(\.\.(\/|\\|$))+/ diff --git a/packages/safe-fs/vitest.config.ts b/packages/safe-fs/vitest.config.ts index 9ff6101..fe822c3 100644 --- a/packages/safe-fs/vitest.config.ts +++ b/packages/safe-fs/vitest.config.ts @@ -1,4 +1,4 @@ -import path from 'node:path' +import path from 'path' export default { resolve: { diff --git a/packages/safe-fs/vitest.setup.ts b/packages/safe-fs/vitest.setup.ts index 6319d9d..6b12795 100644 --- a/packages/safe-fs/vitest.setup.ts +++ b/packages/safe-fs/vitest.setup.ts @@ -1,6 +1,6 @@ import { vi } from 'vitest' -vi.mock('node:fs', async () => { +vi.mock('fs', async () => { const memfs: { fs: typeof fs } = await vi.importActual('memfs') return { @@ -10,7 +10,7 @@ vi.mock('node:fs', async () => { } }) -vi.mock('node:fs/promises', async () => { +vi.mock('fs/promises', async () => { const memfs: { fs: typeof fs } = await vi.importActual('memfs') return { diff --git a/packages/validators/package.json b/packages/validators/package.json index 6a90fda..5975217 100644 --- a/packages/validators/package.json +++ b/packages/validators/package.json @@ -1,6 +1,6 @@ { "name": "@opengovsg/starter-kitty-validators", - "version": "1.2.7", + "version": "1.2.8", "main": "./dist/index.js", "types": "./dist/index.d.ts", "exports": { diff --git a/packages/validators/src/__tests__/path.test.ts b/packages/validators/src/__tests__/path.test.ts index dd4c6ba..c5c41ce 100644 --- a/packages/validators/src/__tests__/path.test.ts +++ b/packages/validators/src/__tests__/path.test.ts @@ -1,5 +1,4 @@ -import path from 'node:path' - +import path from 'path' import { describe, expect, it } from 'vitest' import { ZodError } from 'zod' diff --git a/packages/validators/src/path/options.ts b/packages/validators/src/path/options.ts index 2712c66..46d9bcc 100644 --- a/packages/validators/src/path/options.ts +++ b/packages/validators/src/path/options.ts @@ -1,5 +1,4 @@ -import path from 'node:path' - +import path from 'path' import { z } from 'zod' /** diff --git a/packages/validators/src/path/schema.ts b/packages/validators/src/path/schema.ts index a177074..1df1ab2 100644 --- a/packages/validators/src/path/schema.ts +++ b/packages/validators/src/path/schema.ts @@ -1,5 +1,4 @@ -import path from 'node:path' - +import path from 'path' import { z } from 'zod' import { ParsedPathValidatorOptions } from '@/path/options' diff --git a/packages/validators/src/path/utils.ts b/packages/validators/src/path/utils.ts index 4b21f18..5f48e04 100644 --- a/packages/validators/src/path/utils.ts +++ b/packages/validators/src/path/utils.ts @@ -1,4 +1,4 @@ -import path from 'node:path' +import path from 'path' export const isSafePath = (absPath: string, basePath: string): boolean => { // check for poison null bytes diff --git a/packages/validators/vitest.config.ts b/packages/validators/vitest.config.ts index 0733414..d7eb39e 100644 --- a/packages/validators/vitest.config.ts +++ b/packages/validators/vitest.config.ts @@ -1,4 +1,4 @@ -import path from 'node:path' +import path from 'path' export default { resolve: {