1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-31 07:44:22 +03:00

Load .cjs with require only (#1605)

Ref https://github.com/svg/svgo/issues/1596

At the moment dynamic import may randomly fail with segfault.
To workaround this for some users .cjs extension is loaded
exclusively with require.
This commit is contained in:
Bogdan Chadkin
2021-10-30 01:31:36 +03:00
committed by GitHub
parent 4b4391fbe3
commit c7995035ef

View File

@ -15,6 +15,12 @@ exports.createContentItem = createContentItem;
const importConfig = async (configFile) => {
let config;
// at the moment dynamic import may randomly fail with segfault
// to workaround this for some users .cjs extension is loaded
// exclusively with require
if (configFile.endsWith('.cjs')) {
config = require(configFile);
} else {
try {
// dynamic import expects file url instead of path and may fail
// when windows path is provided
@ -33,6 +39,7 @@ const importConfig = async (configFile) => {
}
}
}
}
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
throw Error(`Invalid config file "${configFile}"`);
}