Skip to content

Commit

Permalink
chore: extract nodejs file manager
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant committed Dec 19, 2023
1 parent 6ffda68 commit 06d9e08
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { existsSync } from 'node:fs';
import * as fs from 'node:fs/promises';

import { FileManager } from './file-manager.js';

/**
* Creates a new FileManager instance based on nodejs fs
* @param dataDir - where to store files
*/
export function createNodejsFileManager(dataDir: string): FileManager {
return new FileManager(
{
...fs,
...{
// ExistsSync is not available in the fs/promises module
existsSync,
// This is added here because the node types are not compatible with the FileSystem type for mkdir
// Typescripts tries to use a different variant of the function that is not the one that has the optional options.
mkdir: async (
dir: string,
opts?: {
/**
* Traverse child directories
*/
recursive: boolean;
},
) => {
await fs.mkdir(dir, opts);
},
},
},
dataDir,
);
}
25 changes: 2 additions & 23 deletions yarn-project/noir-compiler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { ContractArtifact } from '@aztec/foundation/abi';

import { existsSync } from 'node:fs';
import * as fs from 'node:fs/promises';
import { join, resolve } from 'path';

import { CompileOpts, NargoContractCompiler } from './compile/nargo.js';
import { FileManager } from './compile/noir/file-manager/file-manager.js';
import { createNodejsFileManager } from './compile/noir/file-manager/nodejs-file-manager.js';
import { NoirWasmCompileOptions, NoirWasmContractCompiler } from './compile/noir/noir-wasm-compiler.js';
import { generateArtifact, generateContractArtifact } from './contract-interface-gen/abi.js';
import { ProgramArtifact } from './noir_artifact.js';
Expand Down Expand Up @@ -42,26 +40,7 @@ export async function compileUsingNoirWasm(
opts: NoirWasmCompileOptions,
): Promise<(ContractArtifact | ProgramArtifact)[]> {
const cacheRoot = process.env.XDG_CACHE_HOME ?? join(process.env.HOME ?? '', '.cache');
const fileManager = new FileManager(
{
...fs,
...{
existsSync,
mkdir: async (
dir: string,
opts?: {
/**
* Traverse child directories
*/
recursive: boolean;
},
) => {
await fs.mkdir(dir, opts);
},
},
},
join(cacheRoot, 'aztec-noir-compiler'),
);
const fileManager = createNodejsFileManager(join(cacheRoot, 'aztec-noir-compiler'));
const compiler = await NoirWasmContractCompiler.new(fileManager, resolve(projectPath), opts);
const artifacts = await compiler.compile();
return artifacts.map(artifact => {
Expand Down

0 comments on commit 06d9e08

Please sign in to comment.