Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Note that Babel ignores empty string values, even for NODE_ENV. Here
// default to 'test' unless NODE_ENV is defined, in which case fall back to
// Babel's default of 'development' if it's empty.
const envName = process.env.BABEL_ENV || ('NODE_ENV' in process.env ? process.env.NODE_ENV : 'test') || 'development';
// Prepare inputs for caching seeds. Compute a seed based on the Node.js
// version and the project directory. Dependency hashes may vary based on the
// Node.js version, e.g. with the @ava/stage-4 Babel preset. Certain plugins
// and presets are provided as absolute paths, which wouldn't necessarily
// be valid if the project directory changes. Also include `envName`, so
// options can be cached even if users change BABEL_ENV or NODE_ENV between
// runs.
const seedInputs = [
process.versions.node,
packageHash.sync(require.resolve('../package.json')),
projectDir,
envName,
concordance.serialize(concordance.describe(userOptions))
];
const partialCacheKey = md5Hex(seedInputs);
const pluginAndPresetHashes = new Map();
const ensureStage4 = wantsStage4(userOptions, projectDir, {experiments});
const containsStage4 = makeValueChecker('../stage-4');
const containsTransformTestFiles = makeValueChecker('@ava/babel-preset-transform-test-files');
const loadOptions = filename => {
const partialTestConfig = babel.loadPartialConfig({
babelrc: false,
babelrcRoots: [projectDir],
for (const item of [...plugins, ...presets]) {
if (!item.file) {
continue;
}
const {file: {resolved: filename}} = item;
if (pluginAndPresetHashes.has(filename)) {
inputs.push(pluginAndPresetHashes.get(filename));
continue;
}
const [firstComponent] = path.relative(projectDir, filename).split(path.sep);
let hash;
if (firstComponent === 'node_modules') {
hash = packageHash.sync(findUp.sync('package.json', {cwd: path.dirname(filename)}));
} else {
hash = md5Hex(stripBomBuf(fs.readFileSync(filename)));
}
pluginAndPresetHashes.set(filename, hash);
inputs.push(hash);
}
return md5Hex(inputs);
}
_createTransform() {
const salt = packageHash.sync([
require.resolve('../package.json'),
require.resolve('@babel/core/package.json')
], this.babelCacheKeys);
return cachingTransform({
factory: this._init,
cacheDir: this.cacheDirPath,
hash: this._generateHash,
salt,
ext: '.js'
});
}
function getOwnHash() {
ownHash = packageHash.sync(path.join(__dirname, 'package.json'));
return ownHash;
}