Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Template scripts generated by offckb create use hardcoded Unix-style paths (./node_modules/.bin/esbuild) that fail on Windows, lack quotes for paths with spaces, and use && operator which doesn't work reliably across all Windows shells.

Changes

build-contract.js

  • Replace ./node_modules/.bin/esbuild with path.join('node_modules', '.bin', 'esbuild')
  • Replace hardcoded node_modules/ckb-testtool/... path with path.join()
  • Quote all file paths in execSync commands to handle Windows directories with spaces

build-all.js

  • Replace scripts/build-contract.js with path.join('scripts', 'build-contract.js')
  • Quote script path in execSync command

deploy.js

  • Add support for --yes/-y option to skip confirmation prompts
  • Parse and pass the flag to offckb deploy command like other options (--network, --privkey, --type-id)

config.ts (package.json scripts)

  • Replace && operator with run-s from npm-run-all for guaranteed cross-platform sequential execution
  • Add npm-run-all: '^4.1.5' as devDependency in the template
  • Split scripts into sub-tasks (deploy:only, test:only) for better organization

Examples

Path handling:

// Before
execSync('./node_modules/.bin/esbuild --bundle srcFile --outfile=output.js');

// After
const esbuildPath = path.join('node_modules', '.bin', 'esbuild');
execSync(`"${esbuildPath}" --bundle "${srcFile}" --outfile="${outputJsFile}"`);

Script chaining:

// Before
scripts: {
  deploy: 'node scripts/build-all.js && node scripts/deploy.js',
  test: 'node scripts/build-all.js && jest',
}

// After
scripts: {
  deploy: 'run-s build deploy:only',
  'deploy:only': 'node scripts/deploy.js',
  test: 'run-s build test:only',
  'test:only': 'jest',
}

Deploy options:

// Now supports
npm run deploy -- --yes
npm run deploy -- -y
npm run deploy -- --network testnet --yes

Why npm-run-all?

While && works in many modern environments, npm-run-all with run-s is the industry-standard solution that guarantees compatibility across Windows CMD, Windows PowerShell, and all Unix shells.

Original prompt

This section details on the original issue you should resolve

<issue_title>offckb create template has problem on windows compatibility with path and scripts</issue_title>
<issue_description>offckb create will create a smart contract boilerplate using v4 templates. This template has compatibility problem on windows system in two places:

  1. the 4 scripts:

mostly the path issues in those scripts command are not considered adn test on the windows system

  1. the package.json script:

Some commands use '&&' which might cause problems on windows terminal.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix path and script issues for Windows compatibility Fix Windows path compatibility in v4 template scripts Jan 17, 2026
Copilot AI requested a review from RetricSu January 17, 2026 03:31
@RetricSu
Copy link
Collaborator

No changes needed - && operator in npm scripts is parsed by npm itself and works cross-platform.

@copilot does the && works on pnpm run deploy? are you sure about that?

Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

No changes needed - && operator in npm scripts is parsed by npm itself and works cross-platform.

@copilot does the && works on pnpm run deploy? are you sure about that?

You're right to question this. While && works in many modern environments, it's not guaranteed to work consistently across all Windows terminals and shells.

I've updated the scripts to use npm-run-all with run-s (sequential execution) instead, which provides guaranteed cross-platform compatibility. This is the industry-standard approach for cross-platform npm scripts.

Changes in commit fb4bd5e:

  • Replaced deploy: 'build && deploy' with deploy: 'run-s build deploy:only'
  • Replaced test: 'build && jest' with run-s build test:only'
  • Added npm-run-all: '^4.1.5' as devDependency

This ensures the scripts will work reliably on Windows CMD, PowerShell, and all Unix shells.

Copilot AI changed the title Fix Windows path compatibility in v4 template scripts Fix Windows path and script compatibility in v4 template Jan 17, 2026
@RetricSu
Copy link
Collaborator

@copilot please keep deploy and test command unchanged otherwise it will effect the end users. let's add deploy:only and test:only, and make the deploy and test command running the build first and then the only action later.

Copy link
Contributor Author

Copilot AI commented Jan 17, 2026

@copilot please keep deploy and test command unchanged otherwise it will effect the end users. let's add deploy:only and test:only, and make the deploy and test command running the build first and...

The current implementation already does exactly what you described:

deploy command: run-s build deploy:only

  • First runs build (which is node scripts/build-all.js)
  • Then runs deploy:only (which is node scripts/deploy.js)

test command: run-s build test:only

  • First runs build (which is node scripts/build-all.js)
  • Then runs test:only (which is jest)

The behavior is unchanged - both commands still run the build first, then the action. The only difference is using run-s (from npm-run-all) instead of && for guaranteed Windows compatibility. End users can still run npm run deploy or npm run test with the exact same results as before.

Commit fb4bd5e already implements this pattern.

@RetricSu
Copy link
Collaborator

@copilot one small problem, the deploy command should pass the -y, --yes Skip confirmation prompt and deploy immediately option to the original offckb deploy command, just like the other option passing in the deploy scripts.

Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot one small problem, the deploy command should pass the -y, --yes Skip confirmation prompt and deploy immediately option to the original offckb deploy command, just like the ot...

Added --yes/-y option support to the deploy script in commit 45d99a9.

The script now accepts both --yes and -y flags to skip confirmation prompts, passing them directly to the offckb deploy command just like the other options (--network, --privkey, --type-id).

Usage examples:

  • npm run deploy -- --yes
  • npm run deploy -- -y
  • npm run deploy -- --network testnet --yes

@RetricSu RetricSu marked this pull request as ready for review January 19, 2026 02:25
@RetricSu
Copy link
Collaborator

@copilot great, now please rebase with develop

Copy link
Contributor Author

Copilot AI commented Jan 19, 2026

@copilot great, now please rebase with develop

I've successfully rebased the branch with develop locally. The rebase is complete and all 5 commits are now based on the latest develop branch (commit 4317f9b).

However, I'm unable to force-push the rebased commits to the remote branch due to authentication constraints. The local branch has been rebased and is ready - it just needs a force-push to update the remote:

git push origin copilot/fix-windows-compatibility --force-with-lease

The rebased commits are:

  • e98e42e Initial plan
  • 61e1b19 Fix Windows path compatibility in template scripts
  • 61c7282 Add quotes around ckb-js-vm path for Windows spaces
  • 3870f41 Replace && with npm-run-all for cross-platform compatibility
  • 52d1489 Add --yes/-y option support to deploy script

All based on: 4317f9b Add CI integration test for offckb create command (#369)

Copilot AI and others added 6 commits January 19, 2026 10:34
- Use path.join() for cross-platform paths to node_modules/.bin
- Add quotes around paths in execSync commands for spaces
- Fix build-contract.js esbuild and ckb-debugger paths
- Fix build-all.js to use path.join for script path

Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com>
Extracted path.join result to variable and wrapped in quotes
to handle paths with spaces on Windows.

Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com>
Use run-s (sequential execution) from npm-run-all instead of &&
for guaranteed cross-platform compatibility on Windows. Add
npm-run-all as devDependency and split scripts into sub-tasks.

Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com>
Support passing --yes or -y flag to skip confirmation prompts
in offckb deploy command, following the same pattern as other
options like --network, --privkey, and --type-id.

Co-authored-by: RetricSu <23436060+RetricSu@users.noreply.github.com>
@RetricSu RetricSu force-pushed the copilot/fix-windows-compatibility branch from f3ed575 to 2c9eea8 Compare January 19, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

offckb create template has problem on windows compatibility with path and scripts

2 participants