Merge pull request #3622 from ethereum/fix_version_import

Fix version import
pull/3623/head^2
yann300 2 years ago committed by GitHub
commit 6276cb5353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      apps/remix-ide-e2e/src/tests/solidityImport.test.ts
  2. 18
      libs/remix-url-resolver/src/resolve.ts
  3. 2
      package.json
  4. 7
      yarn.lock

@ -112,7 +112,31 @@ module.exports = {
timeout: 120000, timeout: 120000,
}) })
.verifyContracts(['test13', 'ERC20'], { wait: 30000 }) .verifyContracts(['test13', 'ERC20'], { wait: 30000 })
.end() },
'Test NPM Import (the version is specified in package.json) #group4': function (browser: NightwatchBrowser) {
browser
// clone https://github.com/yann300/remix-reward
.clickLaunchIcon('filePanel')
.waitForElementVisible('[data-id="workspaceMenuDropdown"]')
.click('[data-id="workspaceMenuDropdown"]')
.waitForElementVisible('[data-id="workspaceclone"]')
.click('[data-id="workspaceclone"]')
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
.click('[data-id="fileSystemModalDialogModalBody-react"]')
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/yann300/remix-reward')
.click('[data-id="fileSystem-modal-footer-ok-react"]')
.waitForElementPresent('.fa-spinner')
.pause(5000)
.waitForElementNotPresent('.fa-spinner')
.waitForElementVisible('*[data-id="treeViewLitreeViewItem.git"]')
.waitForElementContainsText('[data-id="workspacesSelect"]', 'remix-reward')
.clickLaunchIcon('solidity')
// compile (this will be using the version specified in the package.json)
.openFile('contracts')
.openFile('contracts/RemixRewardUpgradable.sol')
.verifyContracts(['Remix'])
} }
} }

@ -1,5 +1,6 @@
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
import axios, { AxiosResponse } from 'axios' import axios, { AxiosResponse } from 'axios'
import semver from 'semver'
import { BzzNode as Bzz } from '@erebos/bzz-node' import { BzzNode as Bzz } from '@erebos/bzz-node'
export interface Imported { export interface Imported {
@ -137,14 +138,16 @@ export class RemixURLResolver {
*/ */
async handleNpmImport(url: string): Promise<HandlerResponse> { async handleNpmImport(url: string): Promise<HandlerResponse> {
if (this.getDependencies) { if (!url) throw new Error('url is empty')
const isVersionned = semverRegex().exec(url.replace(/@/g, '@ ').replace(/\//g, ' /'))
if (this.getDependencies && !isVersionned) {
try { try {
const { deps, yarnLock, packageLock } = await this.getDependencies() const { deps, yarnLock, packageLock } = await this.getDependencies()
let matchLength = 0 let matchLength = 0
let pkg let pkg
if (deps) { if (deps) {
Object.keys(deps).map((dep) => { Object.keys(deps).map((dep) => {
const reg = new RegExp(dep, 'g') const reg = new RegExp(dep + '/', 'g')
const match = url.match(reg) const match = url.match(reg)
if (match && match.length > 0 && matchLength < match[0].length) { if (match && match.length > 0 && matchLength < match[0].length) {
matchLength = match[0].length matchLength = match[0].length
@ -169,7 +172,10 @@ export class RemixURLResolver {
// package.json // package.json
version = deps[pkg] version = deps[pkg]
} }
if (version) url = url.replace(pkg, `${pkg}@${version}`) if (version) {
const versionSemver = semver.minVersion(version)
url = url.replace(pkg, `${pkg}@${versionSemver.version}`)
}
} }
} }
} catch (e) { } catch (e) {
@ -177,7 +183,6 @@ export class RemixURLResolver {
} }
} }
const npm_urls = ["https://cdn.jsdelivr.net/npm/", "https://unpkg.com/"] const npm_urls = ["https://cdn.jsdelivr.net/npm/", "https://unpkg.com/"]
process && process.env && process.env['NPM_URL'] && npm_urls.unshift(process.env['NPM_URL']) process && process.env && process.env['NPM_URL'] && npm_urls.unshift(process.env['NPM_URL'])
let content = null let content = null
@ -253,3 +258,8 @@ export class RemixURLResolver {
return imported return imported
} }
} }
// see npm semver-regex
function semverRegex() {
return /(?<=^v?|\sv?)(?:(?:0|[1-9]\d{0,9}?)\.){2}(?:0|[1-9]\d{0,9})(?:-(?:--+)?(?:0|[1-9]\d*|\d*[a-z]+\d*)){0,100}(?=$| |\+|\.)(?:(?<=-\S+)(?:\.(?:--?|[\da-z-]*[a-z-]\d*|0|[1-9]\d*)){1,100}?)?(?!\.)(?:\+(?:[\da-z]\.?-?){1,100}?(?!\w))?(?!\+)/gi;
}

@ -342,7 +342,7 @@
"request": "^2.83.0", "request": "^2.83.0",
"rimraf": "^2.6.1", "rimraf": "^2.6.1",
"selenium-standalone": "^8.2.3", "selenium-standalone": "^8.2.3",
"semver": "^6.3.0", "semver": "^7.4.0",
"solc": "0.7.4", "solc": "0.7.4",
"stream-browserify": "^3.0.0", "stream-browserify": "^3.0.0",
"stream-http": "^3.2.0", "stream-http": "^3.2.0",

@ -23663,6 +23663,13 @@ semver@^7.3.7:
dependencies: dependencies:
lru-cache "^6.0.0" lru-cache "^6.0.0"
semver@^7.4.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.4.0.tgz#8481c92feffc531ab1e012a8ffc15bdd3a0f4318"
integrity sha512-RgOxM8Mw+7Zus0+zcLEUn8+JfoLpj/huFTItQy2hsM4khuC1HYRDp0cU482Ewn/Fcy6bCjufD8vAj7voC66KQw==
dependencies:
lru-cache "^6.0.0"
semver@~7.0.0: semver@~7.0.0:
version "7.0.0" version "7.0.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e" resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"

Loading…
Cancel
Save