Skip to content

Commit

Permalink
feat: replace lib similarly to what we do for node_modules
Browse files Browse the repository at this point in the history
  • Loading branch information
0xteddybear committed Nov 26, 2024
1 parent 632efe8 commit 6993ff6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/transformRemappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const transformRemappings = (file: string): string => {
line = line.replace(remappingOrigin, remappingDestination);
}

line = line.replace(/(['""]).*node_modules\//, `$1`);
line = line.replace(/(['""]).*(?:node_modules|lib)\//, `$1`);

return line;
})
Expand Down
31 changes: 31 additions & 0 deletions test/unit/transformRemappings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ describe('transformRemappings', () => {
});
});

describe('with remapping for path inside lib/', function () {
before(() => {
mock({
'remappings.txt': `
solmate/=lib/solmate/src/`,
});
});

it('should apply remapping and then remove lib from path', () => {
const fileContent = `
import {FixedPointMathLib} from 'solmate/utils/FixedPointMathLib.sol';
import 'solmate/utils/FixedPointMathLib.sol';
import "solmate/utils/FixedPointMathLib.sol";
import {FixedPointMathLib as FPL} from 'solmate/utils/FixedPointMathLib.sol';
import * as FPL from "solmate/utils/FixedPointMathLib.sol";
`;

const transformedContent = transformRemappings(fileContent);

expect(transformedContent).to.include(
`import {FixedPointMathLib} from 'solmate/src/utils/FixedPointMathLib.sol';`,
);
expect(transformedContent).to.include(`import 'solmate/src/utils/FixedPointMathLib.sol';`);
expect(transformedContent).to.include(`import "solmate/src/utils/FixedPointMathLib.sol";`);
expect(transformedContent).to.include(
`import {FixedPointMathLib as FPL} from 'solmate/src/utils/FixedPointMathLib.sol';`,
);
expect(transformedContent).to.include(`import * as FPL from "solmate/src/utils/FixedPointMathLib.sol";`);
});
});

it('should leave unrelated imports alone', () => {
const fileContent = `
import './Contract.sol';
Expand Down

0 comments on commit 6993ff6

Please sign in to comment.