Skip to content

Commit 1fbcd7b

Browse files
committed
fix(tailwindcss-patch): fallback to workspace source modules
1 parent 2a7f8b6 commit 1fbcd7b

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

packages/tailwindcss-patch/src/config/workspace.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,26 @@ function isNodeError(error: unknown): error is NodeJS.ErrnoException {
1919
return !!error && typeof error === 'object' && ('code' in error || 'message' in error)
2020
}
2121

22-
function isMissingConfigModuleError(error: unknown) {
23-
if (!isNodeError(error) || error.code !== 'MODULE_NOT_FOUND') {
22+
export function isMissingModuleError(error: unknown, pkgName: string) {
23+
if (!isNodeError(error)) {
2424
return false
2525
}
26-
const message = error.message ?? ''
27-
return message.includes('@tailwindcss-mangle/config')
28-
}
2926

30-
function isMissingSharedModuleError(error: unknown) {
31-
if (!isNodeError(error) || error.code !== 'MODULE_NOT_FOUND') {
27+
const code = error.code
28+
if (code !== 'MODULE_NOT_FOUND' && code !== 'ERR_MODULE_NOT_FOUND') {
3229
return false
3330
}
31+
3432
const message = error.message ?? ''
35-
return message.includes('@tailwindcss-mangle/shared')
33+
return message.includes(pkgName) || message.includes(`${pkgName}/dist/`)
34+
}
35+
36+
function isMissingConfigModuleError(error: unknown) {
37+
return isMissingModuleError(error, '@tailwindcss-mangle/config')
38+
}
39+
40+
function isMissingSharedModuleError(error: unknown) {
41+
return isMissingModuleError(error, '@tailwindcss-mangle/shared')
3642
}
3743

3844
export async function loadWorkspaceConfigModule() {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { isMissingModuleError } from '../src/config/workspace'
3+
4+
function createNodeError(code: string, message: string) {
5+
const error = new Error(message) as NodeJS.ErrnoException
6+
error.code = code
7+
return error
8+
}
9+
10+
describe('workspace module resolution guards', () => {
11+
it('treats ERR_MODULE_NOT_FOUND for workspace dist entries as fallback-worthy', () => {
12+
const error = createNodeError(
13+
'ERR_MODULE_NOT_FOUND',
14+
`Cannot find module '/repo/node_modules/@tailwindcss-mangle/shared/dist/index.js' imported from /repo/packages/tailwindcss-patch/src/config/workspace.ts`,
15+
)
16+
17+
expect(isMissingModuleError(error, '@tailwindcss-mangle/shared')).toBe(true)
18+
})
19+
20+
it('treats classic MODULE_NOT_FOUND package lookup errors as fallback-worthy', () => {
21+
const error = createNodeError(
22+
'MODULE_NOT_FOUND',
23+
`Cannot find module '@tailwindcss-mangle/config' imported from /repo/packages/tailwindcss-patch/src/config/workspace.ts`,
24+
)
25+
26+
expect(isMissingModuleError(error, '@tailwindcss-mangle/config')).toBe(true)
27+
})
28+
29+
it('ignores unrelated missing-module errors', () => {
30+
const error = createNodeError(
31+
'ERR_MODULE_NOT_FOUND',
32+
`Cannot find module '/repo/node_modules/other-package/dist/index.js' imported from /repo/packages/tailwindcss-patch/src/config/workspace.ts`,
33+
)
34+
35+
expect(isMissingModuleError(error, '@tailwindcss-mangle/shared')).toBe(false)
36+
})
37+
})

0 commit comments

Comments
 (0)