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

Better Local Library Support / Code Organisation #24

Open
K3TH3R opened this issue Jan 29, 2022 · 1 comment
Open

Better Local Library Support / Code Organisation #24

K3TH3R opened this issue Jan 29, 2022 · 1 comment

Comments

@K3TH3R
Copy link

K3TH3R commented Jan 29, 2022

Describe the bug

I'm working on a rather large generative art system that I would like to build out in several files that are separate from the Nodes I'm using to create individual art pieces. For example, I'm working on an extensible WebGLImageFilter node that has a ~dozen filter options to apply. The library I'm basing this on is ~600 lines by itself and it would be nice to not have to stuff all of that code into my node.

I've tried using require() with all of the following with no success:

require('./lib/WebGLImageFilter.js')
require('../lib/WebGLImageFilter.js')
require('WebGLImageFilter.js')
require('./WebGLImageFilter.js')

I've also tried adding a local dependency as per the instructions in this StackOverflow, but it crashed Nodes.io and required me to Force Quit the application.

Expected behavior

I would expect that Nodes.io would support the common require() syntaxes and allow us to include local dependencies without having to publish everything to NPM or include them in our package.json

Environment Information:

  • nodes: 1.0.0-beta.2
  • os: darwin
  • node: 12.18.3
  • electron: 11.1.0
  • chrome: 87.0.4280.88
@dmnsgn
Copy link
Member

dmnsgn commented Feb 11, 2022

Hi @K3TH3R,

require() calls in Nodes are currently not commonjs require (more info here: https://nodes.io/docs/api-reference/#:~:text=Note%20that%20they,chunk%20%7D%20from%20%27lodash%27.) but we've had success including local libraries anyway.

Suppose your project has the following structure:

$ tree -L 1
.
├── assets
├── custom
├── graphs
├── index.html
├── local_modules
│   ├── WebGLImageFilter
├── node_modules
├── nodes
├── package-lock.json
├── package.json
└── user.json

The package.json can include your external library like this:

{
  // ...
  "dependencies" : {
    // ...
    "webgl-image-filter": "file:local_modules/WebGLImageFilter"
  }
}

The local_modules/WebGLImageFilter folder needs to be a valid node modules so it needs to contain a package.json. It could be as simple as:

{
  "name": "webgl-image-filter",
  "version": "1.0.0",
  "main": "./WebGLImageFilter.js"
}

After that if you open your project and if they are no syntax errors in WebGLImageFilter, you should be able to require("webgl-image-filter") in your node to include whatever the package exports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants