trzsz / trzsz.js

trzsz.js is the js version of trzsz, makes terminal built with electron and webshell to support trzsz ( trz / tsz ).
https://trzsz.github.io/js
MIT License
189 stars 12 forks source link

In browser mode, seems download(tsz) may not work #10

Closed zxdong262 closed 12 months ago

zxdong262 commented 1 year ago

Any clue how to fix it?

lonnywong commented 1 year ago

Try to use the absolute path of Downloads?

lonnywong commented 1 year ago

Oh, do you change it to browser mode? Chrome does not allow writing to system directories. The Downloads is one of the system directories. Try to make a subdirectory in Downloads, and save to that subdirectory should work.

lonnywong commented 1 year ago

Using trzsz in the browser is very limited, and the user experience will be poor. It would be much better if there is a way to provide fs api to trzsz.

zxdong262 commented 1 year ago

Oh, do you change it to browser mode? Chrome does not allow writing to system directories. The Downloads is one of the system directories. Try to make a subdirectory in Downloads, and save to that subdirectory should work.

Tried different folder, same result, since in newer electron, can not expose fs directly in preload.js, wondering if we can expose fs api in brower mode through ipc, I am doing some experiments.

lonnywong commented 1 year ago

trzsz just need a few functions in fs. check https://github.com/trzsz/trzsz.js/blob/main/src/nodefs.ts. I want to change all of them to async, and make it replaceable.

lonnywong commented 1 year ago

Tried different folder, same result.

Maybe some error in window.showDirectoryPicker with mode readwrite.

https://github.com/trzsz/trzsz.js/blob/9320e1ccc6663bb628821ae871c5897f986680e2/src/browser.ts#L188

zxdong262 commented 1 year ago

I tried, after provide all fs/path functions in ipc mode and provide a proper window.require function, it would work, just need replace fs. to a runtime require('fs').

lonnywong commented 1 year ago

I tried, after provide all fs/path functions in ipc mode and provide a proper window.require function, it would work, just need replace fs. to a runtime require('fs').

Try this:

window.require = (module) => {
    if (module == "fs") {
        return {}
    }
}
zxdong262 commented 1 year ago

Deployed, since it is not a generic solution, publised a temp module https://github.com/electerm/electerm/commit/c064b6a581c7c28103d8784437b9492a4f619ee1 https://github.com/electerm/trzsz.js/commit/52446ecc24f84e8a2a75b8989575c5ffc1e96c50

lonnywong commented 1 year ago

Since you set window.require to a function, you should be able to use trzsz.js directly, no need to make a copy.

https://github.com/electerm/electerm/blob/c064b6a581c7c28103d8784437b9492a4f619ee1/src/client/common/pre.js#L165

zxdong262 commented 1 year ago

Since you set window.require to a function, you should be able to use trzsz.js directly, no need to make a copy.

https://github.com/electerm/electerm/blob/c064b6a581c7c28103d8784437b9492a4f619ee1/src/client/common/pre.js#L165

I tried, not working some how, have to use runtime require

lonnywong commented 1 year ago

electerm npm install fails for me.

~/workspace/electerm$ npm i
npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /opt/homebrew/Cellar/node/20.5.1/bin/node /opt/homebrew/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/lonnywong/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! > vscode-icons@12.5.0 prepare
npm ERR! > husky install
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm ERR! .git can't be found (see https://git.io/Jc3F9)
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /Users/lonnywong/.npm/_cacache/tmp/git-clonevhihTl
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c husky install
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in: /Users/lonnywong/.npm/_logs/2023-08-29T07_30_41_496Z-debug-0.log
zxdong262 commented 1 year ago

electerm npm install fails for me.

~/workspace/electerm$ npm i
npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /opt/homebrew/Cellar/node/20.5.1/bin/node /opt/homebrew/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/lonnywong/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! > vscode-icons@12.5.0 prepare
npm ERR! > husky install
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm ERR! .git can't be found (see https://git.io/Jc3F9)
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /Users/lonnywong/.npm/_cacache/tmp/git-clonevhihTl
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c husky install
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in: /Users/lonnywong/.npm/_logs/2023-08-29T07_30_41_496Z-debug-0.log

nodejs 16?

lonnywong commented 1 year ago

Both 16 and 20 are the same error. Haven't found a solution that works for me yet.

zxdong262 commented 1 year ago

Can you try uninstall your nodejs, install with nvm, then nvm install 16

lonnywong commented 1 year ago
brew uninstall node
brew install node@16
export PATH="/opt/homebrew/opt/node@16/bin:$PATH"

node -v
v16.20.2

npm -v
8.19.4

Same error for me.

zxdong262 commented 1 year ago

I mean use nvm

brew uninstall node
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
nvm install 16

Also, could try npm cache clean --force

lonnywong commented 1 year ago
brew uninstall --force node
brew uninstall --force node@16
brew install nvm

mkdir ~/.nvm
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"

nvm install 16
npm cache clean --force

node -v
v16.20.2

npm -v
8.19.4

npm i

Same error.

zxdong262 commented 1 year ago

did you clone the electem repo or download as https?

gpt4 gives this:

The error message indicates that there's an issue with Husky, a tool used for managing git hooks. The error message .git can't be found suggests that Husky is unable to find the .git directory in your project.

Here are some things you can try:

Ensure you're in a Git repository: Husky requires your project to be a Git repository. You can initialize it as a Git repository by running git init in the root of your project if it's not already one.
Try reinstalling Node modules: Sometimes, deleting node_modules and reinstalling can help resolve issues related to dependencies:
bash
rm -rf node_modules
npm install
Try updating Husky: It's possible that the version of Husky being used is outdated or has known issues. Try updating it:
bash
npm uninstall husky
npm install --save-dev husky@latest
Manually run husky install: Try manually running the command that seems to be causing the error:
bash
npx husky install
Check global npm cache: There might be some corruption or issues with your global npm cache, you could try clearing it with npm cache clean --force.
Check Node and npm versions: Ensure you're using up-to-date versions of Node.js and npm, as older versions may have compatibility issues with current packages.
If none of these suggestions work, please provide additional information about your development environment such as operating system, Node.js version, npm version etc., so I could provide more specific advice.
lonnywong commented 1 year ago

git clone https://github.com/electerm/electerm.git

zxdong262 commented 1 year ago

Check that your version of Git, is it greater than 2.9?

lonnywong commented 1 year ago

git version 2.39.2 (Apple Git-143)

lonnywong commented 1 year ago

Maybe related to apple m1.

lonnywong commented 1 year ago

I figured it out. There is a .git in my home directory, which leads to no .git in ~/.npm/_cacache/tmp/git-clonevhihTl.

lonnywong commented 1 year ago

I tried, not working some how, have to use runtime require

The reason is the code runs before window.require is set. https://github.com/trzsz/trzsz.js/blob/9320e1ccc6663bb628821ae871c5897f986680e2/src/comm.ts#L25-L34

Try move window.require = require; to another source file, and import it before import { TrzszFilter } from "trzsz";.

And add window.require.resolve = (name) => name; after window.require = require;.

zxdong262 commented 1 year ago

I tried, not working some how, have to use runtime require

The reason is the code runs before window.require is set.

https://github.com/trzsz/trzsz.js/blob/9320e1ccc6663bb628821ae871c5897f986680e2/src/comm.ts#L25-L34

Try move window.require = require; to another source file, and import it before import { TrzszFilter } from "trzsz";.

And add window.require.resolve = (name) => name; after window.require = require;.

Works!