Skip to content

Commit

Permalink
internal: Only use custom resolver in test environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed May 9, 2024
1 parent 588575d commit 1cb07d9
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ const { resolvePath } = require('babel-plugin-module-resolver');

module.exports = function (api) {
api.cache.using(() => process.env.NODE_ENV + process.env.BROWSERSLIST_ENV);
const options = { loose: true };
if (process.env.NODE_ENV === 'test') {
options.resolver = {
resolvePath(sourcePath, currentFile, opts) {
if (
sourcePath.startsWith('.') &&
(sourcePath.endsWith('.js') || sourcePath.endsWith('.cjs'))
) {
const removedExt = sourcePath.substring(
0,
sourcePath.lastIndexOf('.'),
);
return resolvePath(removedExt, currentFile, opts);
}
},
root: [],
};
}
return {
presets: [
[
'@anansi',
{
loose: true,
resolver: {
resolvePath(sourcePath, currentFile, opts) {
if (
process.env.NODE_ENV === 'test' &&
sourcePath.startsWith('.') &&
(sourcePath.endsWith('.js') || sourcePath.endsWith('.cjs'))
) {
const removedExt = sourcePath.substring(
0,
sourcePath.lastIndexOf('.'),
);
return resolvePath(removedExt, currentFile, opts);
}
},
root: [],
},
},
],
],
presets: [['@anansi', options]],
assumptions: {
noDocumentAll: true,
noClassCalls: true,
Expand All @@ -35,6 +30,6 @@ module.exports = function (api) {
pureGetters: true,
},
// allows us to load .babelrc in addition to this
babelrcRoots: ['packages/*'],
babelrcRoots: ['packages/*', 'examples/*'],
};
};

0 comments on commit 1cb07d9

Please sign in to comment.