|
| 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