From 24ca1f8366ac8fef624107019c41bdeead282046 Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Wed, 6 Dec 2023 16:08:45 +0000 Subject: [PATCH] fix: extract whole archive instead of subset --- .../dependencies/github-dependency-resolver.ts | 18 +++++++++--------- .../dependencies/local-dependency-resolver.ts | 8 +++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/yarn-project/noir-compiler/src/compile/noir/dependencies/github-dependency-resolver.ts b/yarn-project/noir-compiler/src/compile/noir/dependencies/github-dependency-resolver.ts index 356c891564d..8c9380b77ef 100644 --- a/yarn-project/noir-compiler/src/compile/noir/dependencies/github-dependency-resolver.ts +++ b/yarn-project/noir-compiler/src/compile/noir/dependencies/github-dependency-resolver.ts @@ -71,8 +71,11 @@ export class GithubDependencyResolver implements NoirDependencyResolver { async #extractZip(dependency: NoirGitDependencyConfig, archivePath: string): Promise { const gitUrl = new URL(dependency.git); + // extract the archive to this location const extractLocation = join('libs', safeFilename(gitUrl.pathname + '@' + (dependency.tag ?? 'HEAD'))); - const tmpExtractLocation = extractLocation + '.tmp'; + + // where we expect to find this package after extraction + // it might already exist if the archive got unzipped previously const packagePath = join(extractLocation, dependency.directory ?? ''); if (this.#fm.hasFileSync(packagePath)) { @@ -82,24 +85,21 @@ export class GithubDependencyResolver implements NoirDependencyResolver { const { entries } = await unzip(this.#fm.readFileSync(archivePath)); + // extract to a temporary directory, then move it to the final location + // TODO empty the temp directory first + const tmpExtractLocation = extractLocation + '.tmp'; for (const entry of Object.values(entries)) { if (entry.isDirectory) { continue; } + // remove the first path segment, because it'll be the archive name const name = stripSegments(entry.name, 1); - if (dependency.directory && !name.startsWith(dependency.directory)) { - continue; - } const path = join(tmpExtractLocation, name); await this.#fm.writeFile(path, (await entry.blob()).stream()); } - if (dependency.directory) { - this.#fm.moveFileSync(join(tmpExtractLocation, dependency.directory), packagePath); - } else { - this.#fm.moveFileSync(tmpExtractLocation, packagePath); - } + this.#fm.moveFileSync(tmpExtractLocation, extractLocation); return packagePath; } diff --git a/yarn-project/noir-compiler/src/compile/noir/dependencies/local-dependency-resolver.ts b/yarn-project/noir-compiler/src/compile/noir/dependencies/local-dependency-resolver.ts index 36e2e24893b..720b7fe942f 100644 --- a/yarn-project/noir-compiler/src/compile/noir/dependencies/local-dependency-resolver.ts +++ b/yarn-project/noir-compiler/src/compile/noir/dependencies/local-dependency-resolver.ts @@ -1,6 +1,6 @@ import { NoirDependencyConfig } from '@aztec/foundation/noir'; -import { resolve } from 'path'; +import { isAbsolute, join } from 'path'; import { FileManager } from '../file-manager/file-manager.js'; import { NoirPackage } from '../package.js'; @@ -16,12 +16,14 @@ export class LocalDependencyResolver implements NoirDependencyResolver { this.#fm = fm; } - resolveDependency(pkg: NoirPackage, config: NoirDependencyConfig): Promise { + resolveDependency(parent: NoirPackage, config: NoirDependencyConfig): Promise { if ('path' in config) { + const parentPath = parent.getPackagePath(); + const dependencyPath = isAbsolute(config.path) ? config.path : join(parentPath, config.path); return Promise.resolve({ // unknown version, Nargo.toml doesn't have a version field version: undefined, - package: NoirPackage.open(resolve(pkg.getPackagePath(), config.path), this.#fm), + package: NoirPackage.open(dependencyPath, this.#fm), }); } else { return Promise.resolve(null);