chore(wallaby.js): prevent double imports
This commit is contained in:
parent
60a8830ff4
commit
f0046ef1d7
1 changed files with 20 additions and 0 deletions
20
wallaby.js
20
wallaby.js
|
|
@ -3,6 +3,23 @@ const wallabyWebpack = require('wallaby-webpack'); // eslint-disable-line import
|
||||||
// filter packages, e.g. 'core' / '{radio,radio-button}' / '{form,input*}'
|
// filter packages, e.g. 'core' / '{radio,radio-button}' / '{form,input*}'
|
||||||
const packagePattern = '*';
|
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 = () => ({
|
module.exports = () => ({
|
||||||
files: [
|
files: [
|
||||||
{ pattern: `packages/${packagePattern}/*.js`, load: false },
|
{ pattern: `packages/${packagePattern}/*.js`, load: false },
|
||||||
|
|
@ -18,6 +35,9 @@ module.exports = () => ({
|
||||||
env: {
|
env: {
|
||||||
kind: 'chrome',
|
kind: 'chrome',
|
||||||
},
|
},
|
||||||
|
preprocessors: {
|
||||||
|
'**/*.js': makeLionImportsRelative,
|
||||||
|
},
|
||||||
postprocessor: wallabyWebpack(),
|
postprocessor: wallabyWebpack(),
|
||||||
setup: () => {
|
setup: () => {
|
||||||
// required to trigger test loading
|
// required to trigger test loading
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue