Files
leaflet/spec/karma-version-preprocessor.cjs
2025-03-24 11:17:03 +01:00

19 lines
828 B
JavaScript

// Replace version import from package.json with static version for Firefox which currently not supports Import Attributes.
// TODO: After Firefox supports Import Attributes, remove this preprocessor and update the karma.conf.cjs file.
function replaceVersionPreprocessor(config) {
const replaceVersionImport = config.browsers.some(browser => browser.includes('Firefox'));
return function (content, file, done) {
if (replaceVersionImport) {
content = content.replace(
/import pkg from '\.\.\/package\.json' with \{ type: 'json' \};/,
'const pkg = {version: "0.0.0"};'
);
// we use error to make it visible in the console
console.error('Version import replaced with static variable', file.originalPath, config.browsers.join(', '));
}
done(content);
};
}
module.exports = replaceVersionPreprocessor;