diff --git a/lib/svgo-node.js b/lib/svgo-node.js index ee019ed8..fc3ba8ab 100644 --- a/lib/svgo-node.js +++ b/lib/svgo-node.js @@ -14,24 +14,10 @@ const importConfig = async (configFile) => { 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 - const { default: imported } = await import(pathToFileURL(configFile)); - config = imported; - } catch (importError) { - // TODO remove require in v3 - try { - config = require(configFile); - } catch (requireError) { - // throw original error if es module is detected - if (requireError.code === 'ERR_REQUIRE_ESM') { - throw importError; - } else { - throw requireError; - } - } - } + // dynamic import expects file url instead of path and may fail + // when windows path is provided + const { default: imported } = await import(pathToFileURL(configFile)); + config = imported; } if (config == null || typeof config !== 'object' || Array.isArray(config)) { throw Error(`Invalid config file "${configFile}"`); diff --git a/lib/svgo-node.test.js b/lib/svgo-node.test.js index fe21e085..453d17b1 100644 --- a/lib/svgo-node.test.js +++ b/lib/svgo-node.test.js @@ -147,12 +147,9 @@ describe('loadConfig', () => { expect( await loadConfig(null, path.join(cwd, './test/fixtures/missing')) ).toEqual(null); - // TODO remove check in v3 - if (process.version.startsWith('v10.') === false) { - expect(await loadConfig(null, path.join(fixtures, 'mjs'))).toEqual({ - plugins: ['mjs'], - }); - } + expect(await loadConfig(null, path.join(fixtures, 'mjs'))).toEqual({ + plugins: ['mjs'], + }); expect(await loadConfig(null, path.join(fixtures, 'cjs'))).toEqual({ plugins: ['cjs'], }); @@ -195,14 +192,11 @@ describe('loadConfig', () => { } catch (error) { expect(error.message).toMatch(/plugins is not defined/); } - // TODO remove check in v3 - if (process.version.startsWith('v10.') === false) { - try { - await loadConfig(path.join(fixtures, 'invalid-runtime.mjs')); - expect.fail('Config is loaded successfully'); - } catch (error) { - expect(error.message).toMatch(/plugins is not defined/); - } + try { + await loadConfig(path.join(fixtures, 'invalid-runtime.mjs')); + expect.fail('Config is loaded successfully'); + } catch (error) { + expect(error.message).toMatch(/plugins is not defined/); } });