Skip to content

Commit 86228f6

Browse files
ci-botAniket-Engg
authored andcommitted
handle npm: prefix
1 parent b9139c4 commit 86228f6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

apps/remix-ide-e2e/src/tests/solidityImport.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ module.exports = {
147147
.verifyContracts(['test15', 'ERC20'], { wait: 30000 })
148148
},
149149

150+
'Test NPM Import (prefixed by `npm:` and remappings.txt), it should import from two different solidity version #group3': function (browser: NightwatchBrowser) {
151+
browser
152+
.setSolidityCompilerVersion('soljson-v0.8.30+commit.73712a01.js')
153+
.waitForElementPresent({
154+
selector: `//*[@data-id='compilerloaded' and @data-version='soljson-v0.8.30+commit.73712a01.js']`,
155+
locateStrategy: 'xpath',
156+
timeout: 120000
157+
})
158+
.clickLaunchIcon('filePanel')
159+
.click('li[data-id="treeViewLitreeViewItemREADME.txt"')
160+
.addFile('remappings.txt', sources[10]['remappings.txt'])
161+
.addFile('Untitled11.sol', sources[10]['Untitled11.sol'])
162+
.clickLaunchIcon('solidity')
163+
.click('[data-id="compilerContainerCompileBtn"]')
164+
.clickLaunchIcon('filePanel')
165+
.verifyContracts(['Address', 'Strings'], { wait: 30000 })
166+
},
167+
150168
'Test NPM Import (the version is specified in package.json) #group4': function (browser: NightwatchBrowser) {
151169
browser
152170
// clone https://github.com/yann300/remix-reward
@@ -208,5 +226,15 @@ const sources = [
208226
"@module_remapping": "npm:@openzeppelin/contracts@^4.9.0"
209227
}
210228
}` }
229+
},
230+
{
231+
'Untitled11.sol': { content: `import "@openzeppelin/contracts@5.0.2/utils/Strings.sol";
232+
import "@openzeppelin/contracts@4.7.3/utils/Address.sol";` },
233+
'remappings.txt': { content: `@openzeppelin/contracts@4.7.3/=npm:@openzeppelin/contracts@4.7.3/
234+
@openzeppelin/contracts@4.8.3/=npm:@openzeppelin/contracts@4.8.3/
235+
@openzeppelin/contracts@4.9.6/=npm:@openzeppelin/contracts@4.9.6/
236+
@openzeppelin/contracts@5.0.2/=npm:@openzeppelin/contracts@5.0.2/
237+
@openzeppelin/contracts@5.1.0/=npm:@openzeppelin/contracts@5.1.0/
238+
` }
211239
}
212240
]

libs/remix-url-resolver/src/resolve.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ export class RemixURLResolver {
255255
},
256256
handle: (match) => this.handleV4PeriphGithub(match[0])
257257
},
258+
{
259+
type: 'npm',
260+
match: (url) => {
261+
if (url && url.startsWith('npm:')) {
262+
return [url.replace('npm:', '')]
263+
}
264+
},
265+
handle: (match) => this.handleNpmImport(match[0])
266+
},
258267
{
259268
type: 'npm',
260269
match: (url) => { return /^[^/][^\n"?:*<>|]*$/g.exec(url) }, // match a typical relative path

0 commit comments

Comments
 (0)