Use local version of circomlib deps

pull/4430/head^2
ioedeveloper 11 months ago committed by Aniket
parent 974d3bd5b1
commit 535207fde0
  1. 22
      apps/circuit-compiler/src/app/services/circomPluginClient.ts

@ -254,10 +254,20 @@ export class CircomPluginClient extends PluginClient {
dependencyContent = await this.call('fileManager', 'readFile', relativePath)
} else {
if (include.startsWith('circomlib')) {
// try to resolve include import from github if it is a circomlib dependency
const splitInclude = include.split('/')
const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g)
try {
// try to resolve include import from .deps folder
if (version && version[0]) {
path = `.deps/https/raw.githubusercontent.com/iden3/circomlib/${version[0]}/${splitInclude.slice(2).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
} else {
path = `.deps/https/raw.githubusercontent.com/iden3/circomlib/master/${splitInclude.slice(1).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
}
} catch (e) {
// try to resolve include import from github if it is a circomlib dependency
if (version && version[0]) {
path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/${splitInclude.slice(2).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
@ -265,6 +275,7 @@ export class CircomPluginClient extends PluginClient {
path = `https://raw.githubusercontent.com/iden3/circomlib/master/${splitInclude.slice(1).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
}
}
} else {
if (depPath) {
// resolves relative dependecies for .deps folder
@ -281,10 +292,10 @@ export class CircomPluginClient extends PluginClient {
}
if (path.indexOf('https://') === 0) {
// Regular expression to match include statements and make deps imports uniform
const includeRegex = /include "(.+?)";/g;
const replacement = 'include "circomlib/circuits/$1";';
const includeRegex = /include "(.+?)";/g
const replacement = 'include "circomlib/circuits/$1";'
dependencyContent = dependencyContent.replace(includeRegex, replacement);
dependencyContent = dependencyContent.replace(includeRegex, replacement)
} else {
if (!include.startsWith('circomlib') && !pathModule.isAbsolute(filePath) && !pathModule.isAbsolute(path)) {
// if include is not absolute, resolve it using the parent path of the current file opened in editor
@ -300,7 +311,8 @@ export class CircomPluginClient extends PluginClient {
if (!blackPath.includes(includeName)) {
if(!includeName.startsWith('circomlib')) {
const absFilePath = pathModule.resolve(include.slice(0, include.lastIndexOf('/')), includeName)
let absFilePath = pathModule.resolve(include.slice(0, include.lastIndexOf('/')), includeName)
absFilePath = include.startsWith('circomlib') ? absFilePath.substring(1) : absFilePath
dependencyContent = dependencyContent.replace(`${includeName}`, `${absFilePath}`)
return absFilePath

Loading…
Cancel
Save