-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fdb4cc
commit 641b1cf
Showing
3 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 [email protected]'.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 |