From 5ae0b78b616b4776383ee6670353c88802a110c5 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Mon, 20 May 2024 19:55:18 +0300 Subject: [PATCH 1/4] Fix for the deployment procedure for zkApps that use of version < and that use local imports without '.js' extension. --- CHANGELOG.md | 6 ++++++ package-lock.json | 4 ++-- package.json | 2 +- src/lib/helpers.js | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40fd479c..9eb4f4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## Unreleased +## [0.21.3](https://github.com/o1-labs/zkapp-cli/compare/0.21.2...0.21.3) - 2024-05-20 + +### Fixed + +- Fixed the deployment procedure for zkApps that use `o1js` of version < `v1.0.1` and that use local imports without '.js' extension. [#654](https://github.com/o1-labs/zkapp-cli/pull/654) + ## [0.21.2](https://github.com/o1-labs/zkapp-cli/compare/0.21.0...0.21.2) - 2024-05-20 ### Changed diff --git a/package-lock.json b/package-lock.json index 8b81cda2..01c032d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zkapp-cli", - "version": "0.21.2", + "version": "0.21.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "zkapp-cli", - "version": "0.21.2", + "version": "0.21.3", "license": "Apache-2.0", "dependencies": { "acorn": "^8.11.3", diff --git a/package.json b/package.json index ad29957a..ff422e3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zkapp-cli", - "version": "0.21.2", + "version": "0.21.3", "description": "CLI to create zkApps (zero-knowledge apps) for Mina Protocol", "homepage": "https://github.com/o1-labs/zkapp-cli/", "keywords": [ diff --git a/src/lib/helpers.js b/src/lib/helpers.js index a0205f72..acf670b2 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -224,15 +224,27 @@ function resolveModulePath(moduleName, basePath) { // Resolve relative or absolute paths based on the current file's directory if (path.isAbsolute(moduleName) || moduleName.startsWith('.')) { - return path.resolve(basePath, moduleName); + let modulePath = path.resolve(basePath, moduleName); + if (!fs.existsSync(modulePath)) { + // If the modulePath doesn't exist and doesn't already end with '.js' + if (!modulePath.endsWith('.js')) { + modulePath += '.js'; + } + } + return path.resolve(modulePath); } else { // Module is a node_modules dependency const packagePath = path.join('node_modules', moduleName); const packageJsonPath = path.join(packagePath, 'package.json'); + // Try to resolve the main file using the package.json if (fs.existsSync(packageJsonPath)) { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); - // Try to resolve the main file using the package.json + // Skip the primary entry point for the 'o1js' module + // This is necessary if the 'o1js' module is of < v1.0.1 + if (moduleName === 'o1js') { + delete packageJson['main']; + } let mainFile = packageJson.main || packageJson?.exports?.node?.import || 'index.js'; return path.join(packagePath, mainFile); From 8822765ac46c217b05b3d5da1ab0a9ac244f1989 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Mon, 20 May 2024 19:58:38 +0300 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb4f4f4..8d5cf756 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed -- Fixed the deployment procedure for zkApps that use `o1js` of version < `v1.0.1` and that use local imports without '.js' extension. [#654](https://github.com/o1-labs/zkapp-cli/pull/654) +- Fixed the deployment procedure for zkApps that use `o1js` of version < `v1.0.1` and that use local imports without the `.js` extension. [#654](https://github.com/o1-labs/zkapp-cli/pull/654) ## [0.21.2](https://github.com/o1-labs/zkapp-cli/compare/0.21.0...0.21.2) - 2024-05-20 From de69bcede74b871432d1b791776f61c86ef83907 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Mon, 20 May 2024 20:14:26 +0300 Subject: [PATCH 3/4] Update helpers.js --- src/lib/helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/helpers.js b/src/lib/helpers.js index acf670b2..c22925c7 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -242,6 +242,7 @@ function resolveModulePath(moduleName, basePath) { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); // Skip the primary entry point for the 'o1js' module // This is necessary if the 'o1js' module is of < v1.0.1 + // https://github.com/o1-labs/o1js/commit/0a56798210e9e6678a2b18ca0cecd683b05ba6e5 if (moduleName === 'o1js') { delete packageJson['main']; } From 5cc8b37673a417e413963ed7d293068cfbac73cc Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Mon, 20 May 2024 20:18:36 +0300 Subject: [PATCH 4/4] Refactoring. --- src/lib/helpers.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/helpers.js b/src/lib/helpers.js index acf670b2..1d993b96 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -225,13 +225,10 @@ function resolveModulePath(moduleName, basePath) { // Resolve relative or absolute paths based on the current file's directory if (path.isAbsolute(moduleName) || moduleName.startsWith('.')) { let modulePath = path.resolve(basePath, moduleName); - if (!fs.existsSync(modulePath)) { - // If the modulePath doesn't exist and doesn't already end with '.js' - if (!modulePath.endsWith('.js')) { - modulePath += '.js'; - } + if (!fs.existsSync(modulePath) && !modulePath.endsWith('.js')) { + modulePath += '.js'; } - return path.resolve(modulePath); + return modulePath; } else { // Module is a node_modules dependency const packagePath = path.join('node_modules', moduleName);