Ocelot-Social/webapp/scripts/fix-vue2-jest.js

31 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
/**
* This script prevents vue2-jest from using Vue 3's compiler-sfc
* when Vue 3 is installed in parent node_modules (e.g., from vuepress).
*
* It creates a mock module at node_modules/vue/compiler-sfc that throws
* an error, forcing vue2-jest to fall back to @vue/component-compiler-utils.
*/
const fs = require('fs')
const path = require('path')
const vueDir = path.join(__dirname, '..', 'node_modules', 'vue')
const compilerSfcDir = path.join(vueDir, 'compiler-sfc')
const indexFile = path.join(compilerSfcDir, 'index.js')
// Only create if vue exists but compiler-sfc doesn't
if (fs.existsSync(vueDir) && !fs.existsSync(path.join(vueDir, 'compiler-sfc.js'))) {
if (!fs.existsSync(compilerSfcDir)) {
fs.mkdirSync(compilerSfcDir, { recursive: true })
}
const content = `// Auto-generated by scripts/fix-vue2-jest.js
// Prevents vue2-jest from using Vue 3's compiler-sfc from parent node_modules
throw new Error('vue/compiler-sfc is not available in Vue 2.6')
`
fs.writeFileSync(indexFile, content)
// eslint-disable-next-line no-console
console.log('Created vue/compiler-sfc mock for vue2-jest compatibility')
}