Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the deployment procedure of zkApps that use o1js of version < v1.0.1 and that use local imports without the .js extension. #654

Merged
merged 5 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
14 changes: 12 additions & 2 deletions src/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,25 @@ 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) && !modulePath.endsWith('.js')) {
modulePath += '.js';
}
return 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
// https://github.com/o1-labs/o1js/commit/0a56798210e9e6678a2b18ca0cecd683b05ba6e5
if (moduleName === 'o1js') {
delete packageJson['main'];
}
let mainFile =
packageJson.main || packageJson?.exports?.node?.import || 'index.js';
return path.join(packagePath, mainFile);
Expand Down
Loading