eclipse-agail / agile-sdk

JavaScript Agile IoT SDK
Eclipse Public License 2.0
2 stars 4 forks source link

Inclusion with npm #12

Closed nopbyte closed 7 years ago

nopbyte commented 7 years ago

Hi @craig-mulligan I tried to include this project with npm by executing this. npm install --save git+https://github.com/Agile-IoT/agile-sdk.git

Afterwards, I created an index.js file that imports the dist file like this because I thought the issue was that npm was not recognizing the entry point or something...

module.exports = require('./dist/index.js');

Now, the require('agile-sdk;) inside the project including agile-sdk didn't fail, but once I actually try to instantiate the API, I get an error saying that ./dist/index.js is not there (inside the agile-sdk).

So, I was checking... and even when I have installed agile-sdk, there is no src folder inside the module located in node_modules. Maybe the package json needs to be updated so people can use it with npm transparently?

As a workaround, I checkout agile-sdk, execute npm install inside and then use npm link.

craigmulligan commented 7 years ago

It's because we ignore the dist folder in git. See .gitignore. This means the entry path won't be there when installing from github. There are multiple ways around this, does the npm-link suffice?

nopbyte commented 7 years ago

I think it may be that babel is not really executing when you do the npm install, and therefore there is no dist folder after npm install is executed (when agile-sdk has been installed as a dependency as I mentioned before). My point is that when you include agile-sdk from github, you get something that doesn't work inside your node_modules.

I was checking if we could do npm link in our docker files but we have an issue there too.

We have the following chain of dependencies agile-sdk -> node-red-contrib-security-nodes -> node-red (installed as a dependency) -> secure-node-red.

So, I was expecting to link agile-sdk inside node-red-contrib-security-nodes and then link node-red-contrib-security-nodes and node-red inside secure-node-red. However, this is what I get:

npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! path /opt/node-red-contrib-security-nodes/node_modules/agile-sdk/node_modules/ansi-regex
npm ERR! code EXDEV
npm ERR! errno -18
npm ERR! syscall rename

npm ERR! EXDEV: cross-device link not permitted, rename '/opt/node-red-contrib-security-nodes/node_modules/agile-sdk/node_modules/ansi-regex' -> '/opt/node-red-contrib-security-nodes/node_modules/ansi-regex'
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /opt/node-red-contrib-security-nodes/npm-debug.log

Before this was done with npm install -g to make everything global inside the container, but this also doesn't work when I try to install agile-sdk globally. I am guessing it relates to the npm commands that expect to execute babel... This is the error then:

sh: 1: babel: not found

npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! agile-sdk@0.4.0 build: `babel src --out-dir dist --copy-files && npm run build-browser`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the agile-sdk@0.4.0 build script 'babel src --out-dir dist --copy-files && npm run build-browser'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the agile-sdk package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     babel src --out-dir dist --copy-files && npm run build-browser
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs agile-sdk
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls agile-sdk
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /opt/agile-sdk/npm-debug.log

npm ERR! addLocal Could not install /opt/agile-sdk
npm ERR! Linux 3.16.0-4-amd64
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g"
npm ERR! node v7.5.0
npm ERR! npm  v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! agile-sdk@0.4.0 prepublish: `npm run build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the agile-sdk@0.4.0 prepublish script 'npm run build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the agile-sdk package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs agile-sdk
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls agile-sdk
npm ERR! There is likely additional logging output above.

And, I know that an idea would be to install babel globally, but... if I install babel-cli globally then I get this:

Error: Couldn't find preset "es2015" relative to directory "/opt/agile-sdk"
    at /usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
    at Array.map (native)
    at OptionManager.resolvePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
    at OptionManager.mergePresets (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
    at OptionManager.mergeOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
    at OptionManager.init (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
    at File.initOptions (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:212:65)
    at new File (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:135:24)
    at Pipeline.transform (/usr/local/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    at transform (/usr/local/lib/node_modules/babel-cli/lib/babel/util.js:50:22)
craigmulligan commented 7 years ago

@nopbyte, can you share the bit in the Dockerfile that's doing this?

nopbyte commented 7 years ago

hi @craig-mulligan, the issue seems to be that I was doing a link before install... I will address your comments on the agile-sdk and then include it in the node-red projects with npm link in the dockerfile. I would have liked if we can include the sdk transparently from github in a way that npm can actually install the agile-sdk. Otherwise we have to ask our developers to always rely on some additional scripting (or docker files) that do the npm link... Don't you think?

craigmulligan commented 7 years ago

@nopbyte the simplest way to do this is add a npm post install script to your branch that runs the npm prepublish script. This will build the dist folder on install.

However npm 5 has a prepare script that is only run for github installs which will solve our problem (see here: https://github.com/npm/npm/issues/3055).

nopbyte commented 7 years ago

Ok. I will give it a try when I get a chance. Thanks