Skip to content

Commit

Permalink
chore(wallaby.js): prevent double imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Bashkirov authored and daKmoR committed May 8, 2019
1 parent 60a8830 commit f0046ef
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions wallaby.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@ const wallabyWebpack = require('wallaby-webpack'); // eslint-disable-line import
// filter packages, e.g. 'core' / '{radio,radio-button}' / '{form,input*}'
const packagePattern = '*';

const replaceAll = (str, oldValue, newValue) => {
return str.split(oldValue).join(newValue);
};

const countOccurences = (str, subbstr) => {
return str.split(subbstr).length - 1;
};

const makeLionImportsRelative = file => {
// example:
// file.path: 'packages/package-name/src/my-element.js'
// old imports: '@lion/package-name'
// new imports: '../../package-name'
const nestLevel = countOccurences(file.path, '/') - 1; // 3 - 1 = 2
return replaceAll(file.content, '@lion/', '../'.repeat(nestLevel)); // '@lion/' => '../../'
};

module.exports = () => ({
files: [
{ pattern: `packages/${packagePattern}/*.js`, load: false },
Expand All @@ -18,6 +35,9 @@ module.exports = () => ({
env: {
kind: 'chrome',
},
preprocessors: {
'**/*.js': makeLionImportsRelative,
},
postprocessor: wallabyWebpack(),
setup: () => {
// required to trigger test loading
Expand Down

0 comments on commit f0046ef

Please sign in to comment.