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

[API Feature Request] Installing native node add-ons using node-gyp #135

Open
loris opened this issue Oct 20, 2021 · 5 comments
Open

[API Feature Request] Installing native node add-ons using node-gyp #135

loris opened this issue Oct 20, 2021 · 5 comments
Labels
api Issues related to API feature request New feature or improvement

Comments

@loris
Copy link
Contributor

loris commented Oct 20, 2021

Description

Right now, it looks like we cannot use any native node add-ons which are built using node-gyp. For instance, I tried various npm package to access sqlite database but failed: sqlite, sqlite3, better-sqlite3, etc

Steps To Reproduce

  1. npm install and try to import in your extension any package relying on node-gyp (for instance: https://github.com/JoshuaWise/better-sqlite3)

The current behavior

You will get a nodejs error (such as Error: Could not find module root given file: "node:internal/modules/cjs/loader". Do you have a package.json file?)

The expected behavior

No error

@loris loris added api Issues related to API bug Something isn't working labels Oct 20, 2021
@bromanko
Copy link
Contributor

sqlite3 also does not work because it tries to read package.json in the module and that file isn't found when running in Raycast.

Error: package.json does not exist at /Users/bromanko/.config/raycast/extensions/package.json

        throw new Error("package.json does not exist at " + package_json_path);
              ^

Object.exports.find:pre-binding.js:18:15

---
15: 
16: exports.find = function(package_json_path,opts) {
17:    if (!existsSync(package_json_path)) {
18:         throw new Error("package.json does not exist at " + package_json_path);
19:    }
20:    var package_json = require(package_json_path);
21:    versioning.validate_config(package_json,opts);
---

node_modules/sqlite3/lib/sqlite3-binding.js:sqlite3-binding.js:3:27
__require:searchChrome.js:9:44
node_modules/sqlite3/lib/sqlite3.js:sqlite3.js:2:15
__require:searchChrome.js:9:44
Object.<anonymous>:browserHistory.tsx:4:21
Module._compile:loader:1101:14
Object.Module._extensions..js:loader:1153:10
Module.load:loader:981:32
Function.Module._load:loader:822:12

bromanko added a commit to bromanko/raycast-extensions that referenced this issue Oct 22, 2021
This uses the WASM compiled version of sqlite since [native modules are
not supported](raycast#135).

The query for matching is a rudimenary `title LIKE '%query%'` where
clause. I intend to make this a bit more sophisticated to handle
multiple terms.

It is only using the native throttle support to debounce access to
the database. It's possible that this will need more tuning or better
resource management.

It also does not yet support choosing a specific profile for history.
This would be possible by setting that string in preferences. For now it
defaults to "Default".
@bromanko
Copy link
Contributor

FWIW I was able to use the WASM-based sql.js in #172

@hmarr hmarr mentioned this issue Oct 23, 2021
3 tasks
@fe9lix
Copy link
Contributor

fe9lix commented Oct 25, 2021

Hey guys, I'm flagging this as "feature" instead of bug because this is more like a known JS bundler limitation (in our case esbuild) and something that could be argued is "missing" rather than being buggy.

For now, there a workarounds such as marking certain modules as external via package.json and using other alternatives such as the mentioned wasm-based package above.

@fe9lix fe9lix added feature request New feature or improvement and removed bug Something isn't working labels Oct 25, 2021
@fe9lix fe9lix changed the title [API Bug] Installing native node add-ons using node-gyp fails [API Feature Request] Installing native node add-ons using node-gyp Oct 25, 2021
@fe9lix fe9lix removed their assignment Oct 25, 2021
mattisssa pushed a commit that referenced this issue Oct 26, 2021
* Support for searching Google Chrome history

This uses the WASM compiled version of sqlite since [native modules are
not supported](#135).

The query for matching is a rudimenary `title LIKE '%query%'` where
clause. I intend to make this a bit more sophisticated to handle
multiple terms.

It is only using the native throttle support to debounce access to
the database. It's possible that this will need more tuning or better
resource management.

It also does not yet support choosing a specific profile for history.
This would be possible by setting that string in preferences. For now it
defaults to "Default".

* Fix missing type annotation

* Fix command titles

It should use the name of the app as the Subtitle

* Add title to OpenInBrowserAction

* Move bromanko to contributors

* Improve database lifecycle management

This improves the database lifecycle management. Now, the db is loaded
once when the component is mounted and disposed when the component is
unmounted.

Note that I have not been able to see the disposal logic get called. I
suspect that this is either due to the way that Raycast handles
extension component lifecycles or the dev environment operating differently.

* Change copy to clipboard shortcut

CMD+C is reserved for global use

* Share the favicon code between commands

* Always stringify the error message

* Improve search query

This commit changes the search from comparing the entire string as a
single pattern to tokenizing the words and matching each independently.
All terms must be found for it to match.

* Load the last visit date from database

Chrome stores dates as the number of microseconds since 01/01/1601.

* Group entries by date
FezVrasta pushed a commit to FezVrasta/extensions that referenced this issue Nov 24, 2021
* Support for searching Google Chrome history

This uses the WASM compiled version of sqlite since [native modules are
not supported](raycast#135).

The query for matching is a rudimenary `title LIKE '%query%'` where
clause. I intend to make this a bit more sophisticated to handle
multiple terms.

It is only using the native throttle support to debounce access to
the database. It's possible that this will need more tuning or better
resource management.

It also does not yet support choosing a specific profile for history.
This would be possible by setting that string in preferences. For now it
defaults to "Default".

* Fix missing type annotation

* Fix command titles

It should use the name of the app as the Subtitle

* Add title to OpenInBrowserAction

* Move bromanko to contributors

* Improve database lifecycle management

This improves the database lifecycle management. Now, the db is loaded
once when the component is mounted and disposed when the component is
unmounted.

Note that I have not been able to see the disposal logic get called. I
suspect that this is either due to the way that Raycast handles
extension component lifecycles or the dev environment operating differently.

* Change copy to clipboard shortcut

CMD+C is reserved for global use

* Share the favicon code between commands

* Always stringify the error message

* Improve search query

This commit changes the search from comparing the entire string as a
single pattern to tokenizing the words and matching each independently.
All terms must be found for it to match.

* Load the last visit date from database

Chrome stores dates as the number of microseconds since 01/01/1601.

* Group entries by date
@ayroblu
Copy link

ayroblu commented Dec 28, 2022

👋 Hey, based on this issue: evanw/esbuild#1051 is there still anything that can't be done here? My understanding is that esbuild simply grabs all the .node files and bundles them along? Though sqlite3 fails for weird reasons, better-sqlite3 looks like it could work with this native node modules plugin approach?

I get a list of errors like:

Error: Could not locate the bindings file. Tried:
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/build/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/build/Debug/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/build/Release/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/out/Debug/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/Debug/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/out/Release/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/Release/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/build/default/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/compiled/18.10.0/darwin/arm64/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/addon-build/release/install-root/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/addon-build/debug/install-root/better_sqlite3.node
 → /Applications/Raycast.app/Contents/Resources/RaycastCommands_RaycastCommands.bundle/Contents/Resources/api/addon-build/default/install-root/better_sqlite3.node

@gutenye
Copy link
Contributor

gutenye commented Jan 21, 2024

For now, there a workarounds such as marking certain modules as external via package.json and using other alternatives such as the mentioned wasm-based package above.

@fe9lix How to make it as external via package.json? Can you give an example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to API feature request New feature or improvement
Projects
None yet
Development

No branches or pull requests

5 participants