diff --git a/nullstack-adapt-babel/index.js b/nullstack-adapt-babel/index.js index f3d48ba..76998e9 100644 --- a/nullstack-adapt-babel/index.js +++ b/nullstack-adapt-babel/index.js @@ -2,6 +2,7 @@ const path = require('path') const { readdirSync } = require('fs') const getOptions = require('./utils/getOptions') +const fixDeps = require('./utils/fix-deps') function runtime(options) { return { @@ -233,6 +234,8 @@ function newConfig(options) { ] } +fixDeps() + /** * * @param {Array<(...[]) => {module: {rules: Array<{}>}}>} configs diff --git a/nullstack-adapt-babel/package.json b/nullstack-adapt-babel/package.json index 1755c42..2598156 100644 --- a/nullstack-adapt-babel/package.json +++ b/nullstack-adapt-babel/package.json @@ -1,6 +1,6 @@ { "name": "nullstack-adapt-babel", - "version": "0.0.5", + "version": "0.0.6", "description": "Adapt Nullstack to Babel", "author": "GuiDevloper", "license": "MIT", diff --git a/nullstack-adapt-babel/utils/fix-deps.js b/nullstack-adapt-babel/utils/fix-deps.js new file mode 100644 index 0000000..d1c0d00 --- /dev/null +++ b/nullstack-adapt-babel/utils/fix-deps.js @@ -0,0 +1,30 @@ +const fs = require('fs') +const path = require('path') +const atCWD = fullPath => path.join(process.cwd(), fullPath) + +/** + * Try to fix dependencies issues at virtual NPM environments (e.g: ajv) + * @see https://github.com/ajv-validator/ajv-keywords/issues/385 + **/ +function fixDeps() { + try { + const isVirtualNPM = + process.env.PKG_MANAGER === 'npm' && !process.env.npm_config_registry + if (isVirtualNPM && !process.env.DISABLE_AJV_FIX) { + const ajvJSON = require(atCWD('node_modules/ajv/package.json')) + if (ajvJSON.version !== '7.2.4') { + console.log('Fixing npm deps...') + const cprocess = require('child_process') + const npmCLI = process.platform === 'win32' ? 'npm.cmd' : 'npm' + cprocess.spawnSync(npmCLI, 'install ajv@7.2.4'.split(' ')) + const pkgJSON = fs.readFileSync(atCWD('package.json'), 'utf8') + fs.writeFileSync( + atCWD('package.json'), + pkgJSON.replace(/[ ]+"ajv": "(\^|)7.2.4"(,|)\n/, '') + ) + } + } + } catch {} +} + +module.exports = fixDeps