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: TypeError when using --inject with comma-separated file paths #927

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kittizz
Copy link

@kittizz kittizz commented Mar 4, 2025

This PR fixes an issue where using the --inject option with comma-separated file paths (e.g. --inject file1.js,file2.css) causes a TypeError.

Root Cause
The problem occurs because the inject parameter is received as a string, but the code attempts to call Array.every() on it, resulting in a TypeError.

Solution
This PR adds a custom option processor for the --inject option that automatically splits the comma-separated string into an array. This ensures that when the option value reaches the validation code, it's already in the expected array format.

Related Issues

fixed #914

Problem

When using the --inject option with comma-separated file paths, the application throws a TypeError because Commander.js passes the option value as a string, but the code expects an array when calling the .every() method.

➜  workspace pake https://chat.kittizz.com --name ChatKT --icon /Users/kittizz/workspace/pake/chat-kt/chatkt.ico --hide-title-bar --inject "/Users/kittizz/workspace/pake/chat-kt/style.css,/Users/kittizz/workspace/pake/chat-kt/script.js" --debug
PakeAppOptions {
 icon: '/Users/kittizz/workspace/pake/chat-kt/chatkt.ico',
 width: 1200,
 height: 780,
 useLocalFile: false,
 fullscreen: false,
 hideTitleBar: true,
 multiArch: false,
 inject: '/Users/kittizz/workspace/pake/chat-kt/style.css,/Users/kittizz/workspace/pake/chat-kt/script.js',
 debug: true,
 proxyUrl: '',
 userAgent: '',
 targets: 'deb',
 appVersion: '1.0.0',
 alwaysOnTop: false,
 darkMode: false,
 disabledWebShortcuts: false,
 activationShortcut: '',
 showSystemTray: false,
 systemTrayIcon: '',
 installerLanguage: 'en-US',
 name: 'ChatKT',
 identifier: 'com.pake.61f97b'
}
www.npmjs.com latency is 8 ms
✶ Installing package...

up to date, audited 223 packages in 570ms

73 packages are looking for funding
 run `npm fund` for details

✔ Package installed!
✼ macOS icon must be .icns type., but you give .ico
✼ Icon will remain as default.
file:///Users/kittizz/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/pake-cli/dist/cli.js:572
       if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) {
                   ^

TypeError: inject.every is not a function
   at mergeConfig (file:///Users/kittizz/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/pake-cli/dist/cli.js:572:21)
   at async MacBuilder.buildAndCopy (file:///Users/kittizz/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/pake-cli/dist/cli.js:656:9)
   at async MacBuilder.build (file:///Users/kittizz/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/pake-cli/dist/cli.js:649:9)
   at async Command.<anonymous> (file:///Users/kittizz/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/pake-cli/dist/cli.js:1013:5)

Node.js v22.14.0

Testing

test css,js path

➜  Pake git:(fix-cli-inject) ✗ node cli.js https://chat.kittizz.com --name ChatKT --icon /Users/kittizz/workspace/pake/chat-kt/chatkt.ico --hide-title-bar --inject "/Users/kittizz/workspace/pake/chat-kt/style.css,/Users/kittizz/workspace/pake/chat-kt/script.js" --debug
PakeAppOptions {
  icon: '/Users/kittizz/workspace/pake/chat-kt/chatkt.ico',
  width: 1200,
  height: 780,
  useLocalFile: false,
  fullscreen: false,
  hideTitleBar: true,
  multiArch: false,
  inject: [
    '/Users/kittizz/workspace/pake/chat-kt/style.css',
    '/Users/kittizz/workspace/pake/chat-kt/script.js'
  ],

test only js

➜  Pake git:(fix-cli-inject) ✗ node cli.js https://chat.kittizz.com --name ChatKT --icon /Users/kittizz/workspace/pake/chat-kt/chatkt.ico --hide-title-bar --inject "/Users/kittizz/workspace/pake/chat-kt/style.js" --debug        
PakeAppOptions {
  icon: '/Users/kittizz/workspace/pake/chat-kt/chatkt.ico',
  width: 1200,
  height: 780,
  useLocalFile: false,
  fullscreen: false,
  hideTitleBar: true,
  multiArch: false,
  inject: [ '/Users/kittizz/workspace/pake/chat-kt/style.js' ],

test no inject

➜  Pake git:(fix-cli-inject) ✗ node cli.js https://chat.kittizz.com --name ChatKT --icon /Users/kittizz/workspace/pake/chat-kt/chatkt.ico --hide-title-bar  --debug                                                                                                          
PakeAppOptions {
  icon: '/Users/kittizz/workspace/pake/chat-kt/chatkt.ico',
  width: 1200,
  height: 780,
  useLocalFile: false,
  fullscreen: false,
  hideTitleBar: true,
  multiArch: false,
  inject: [],

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.

[Bug] --inject not work on macos
1 participant