From 6bfbe3a61c414f8a7708e98cd28cae3e5ed5955c Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Tue, 28 Oct 2025 23:44:23 +0900 Subject: [PATCH] Fix symlink issue --- packages/next-plugin/src/__tests__/preload.test.ts | 9 +++++++-- packages/next-plugin/src/preload.ts | 13 ++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/next-plugin/src/__tests__/preload.test.ts b/packages/next-plugin/src/__tests__/preload.test.ts index c8a035fe..049ffb6c 100644 --- a/packages/next-plugin/src/__tests__/preload.test.ts +++ b/packages/next-plugin/src/__tests__/preload.test.ts @@ -1,4 +1,4 @@ -import { writeFileSync } from 'node:fs' +import { realpathSync, writeFileSync } from 'node:fs' import { readFileSync } from 'node:fs' import { existsSync } from 'node:fs' import { join } from 'node:path' @@ -19,6 +19,7 @@ vi.mock('node:fs', () => ({ writeFileSync: vi.fn(), mkdirSync: vi.fn(), existsSync: vi.fn(), + realpathSync: vi.fn().mockReturnValue('src/App.tsx'), })) vi.mock('glob', () => ({ @@ -68,6 +69,7 @@ describe('preload', () => { ['**/*.tsx', '**/*.ts', '**/*.js', '**/*.mjs'], { follow: true, + absolute: true, }, ) }) @@ -83,7 +85,10 @@ describe('preload', () => { it('should process each collected file', () => { const files = ['src/App.tsx', 'src/components/Button.tsx', '.next/page.tsx'] vi.mocked(globSync).mockReturnValue(files) - + vi.mocked(realpathSync) + .mockReturnValueOnce('src/App.tsx') + .mockReturnValueOnce('src/components/Button.tsx') + .mockReturnValueOnce('.next/page.tsx') preload(/node_modules/, '@devup-ui/react', false, {}, '/output/css') expect(codeExtract).toHaveBeenCalledTimes(2) diff --git a/packages/next-plugin/src/preload.ts b/packages/next-plugin/src/preload.ts index 819f3ba4..78d888cf 100644 --- a/packages/next-plugin/src/preload.ts +++ b/packages/next-plugin/src/preload.ts @@ -1,4 +1,4 @@ -import { readFileSync, writeFileSync } from 'node:fs' +import { readFileSync, realpathSync, writeFileSync } from 'node:fs' import { basename, join, relative } from 'node:path' import { codeExtract, registerTheme } from '@devup-ui/wasm' @@ -11,20 +11,19 @@ export function preload( theme: object, cssDir: string, ) { - const projectRoot = process.cwd() - const collected = globSync(['**/*.tsx', '**/*.ts', '**/*.js', '**/*.mjs'], { follow: true, + absolute: true, }) registerTheme(theme) for (const file of collected) { + const filePath = relative(process.cwd(), realpathSync(file)) if ( - /\.(test(-d)?|d|spec)\.(tsx|ts|js|mjs)$/.test(file) || - /^(out|.next)[/\\]/.test(file) || - excludeRegex.test(file) + /\.(test(-d)?|d|spec)\.(tsx|ts|js|mjs)$/.test(filePath) || + /^(out|.next)[/\\]/.test(filePath) || + excludeRegex.test(filePath) ) continue - const filePath = relative(process.cwd(), join(projectRoot, file)) const { cssFile, css } = codeExtract( filePath, readFileSync(filePath, 'utf-8'),