Skip to content

Commit 13f7bdc

Browse files
authored
Merge pull request #456 from dev-five-git/turbo-files-issue
Fix symlink issue
2 parents 0275d0c + 6bfbe3a commit 13f7bdc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

packages/next-plugin/src/__tests__/preload.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { writeFileSync } from 'node:fs'
1+
import { realpathSync, writeFileSync } from 'node:fs'
22
import { readFileSync } from 'node:fs'
33
import { existsSync } from 'node:fs'
44
import { join } from 'node:path'
@@ -19,6 +19,7 @@ vi.mock('node:fs', () => ({
1919
writeFileSync: vi.fn(),
2020
mkdirSync: vi.fn(),
2121
existsSync: vi.fn(),
22+
realpathSync: vi.fn().mockReturnValue('src/App.tsx'),
2223
}))
2324

2425
vi.mock('glob', () => ({
@@ -68,6 +69,7 @@ describe('preload', () => {
6869
['**/*.tsx', '**/*.ts', '**/*.js', '**/*.mjs'],
6970
{
7071
follow: true,
72+
absolute: true,
7173
},
7274
)
7375
})
@@ -83,7 +85,10 @@ describe('preload', () => {
8385
it('should process each collected file', () => {
8486
const files = ['src/App.tsx', 'src/components/Button.tsx', '.next/page.tsx']
8587
vi.mocked(globSync).mockReturnValue(files)
86-
88+
vi.mocked(realpathSync)
89+
.mockReturnValueOnce('src/App.tsx')
90+
.mockReturnValueOnce('src/components/Button.tsx')
91+
.mockReturnValueOnce('.next/page.tsx')
8792
preload(/node_modules/, '@devup-ui/react', false, {}, '/output/css')
8893

8994
expect(codeExtract).toHaveBeenCalledTimes(2)

packages/next-plugin/src/preload.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync, writeFileSync } from 'node:fs'
1+
import { readFileSync, realpathSync, writeFileSync } from 'node:fs'
22
import { basename, join, relative } from 'node:path'
33

44
import { codeExtract, registerTheme } from '@devup-ui/wasm'
@@ -11,20 +11,19 @@ export function preload(
1111
theme: object,
1212
cssDir: string,
1313
) {
14-
const projectRoot = process.cwd()
15-
1614
const collected = globSync(['**/*.tsx', '**/*.ts', '**/*.js', '**/*.mjs'], {
1715
follow: true,
16+
absolute: true,
1817
})
1918
registerTheme(theme)
2019
for (const file of collected) {
20+
const filePath = relative(process.cwd(), realpathSync(file))
2121
if (
22-
/\.(test(-d)?|d|spec)\.(tsx|ts|js|mjs)$/.test(file) ||
23-
/^(out|.next)[/\\]/.test(file) ||
24-
excludeRegex.test(file)
22+
/\.(test(-d)?|d|spec)\.(tsx|ts|js|mjs)$/.test(filePath) ||
23+
/^(out|.next)[/\\]/.test(filePath) ||
24+
excludeRegex.test(filePath)
2525
)
2626
continue
27-
const filePath = relative(process.cwd(), join(projectRoot, file))
2827
const { cssFile, css } = codeExtract(
2928
filePath,
3029
readFileSync(filePath, 'utf-8'),

0 commit comments

Comments
 (0)