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

artoolkitX.js as a npm package #28

Open
kalwalt opened this issue Jan 5, 2020 · 34 comments
Open

artoolkitX.js as a npm package #28

kalwalt opened this issue Jan 5, 2020 · 34 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers Medium priority medium priority issue

Comments

@kalwalt
Copy link
Collaborator

kalwalt commented Jan 5, 2020

It seems that recently Github let you deploy a npm package with zero effort, at least this seems to me.
I will investigate on this.

@kalwalt kalwalt added enhancement New feature or request good first issue Good for newcomers Medium priority medium priority issue labels Jan 5, 2020
@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 6, 2020

@ThorstenBux it should be sufficient to add this line/option in package.json:

"publishConfig": { "registry": "https://npm.pkg.github.com/" }

and then authenticate:

npm login --registry=https://npm.pkg.github.com/

final step:

npm publish

@kalwalt kalwalt self-assigned this Jan 6, 2020
@ThorstenBux
Copy link

if it is that easy I'd say we already add it to jsartoolkit5 and publish it directly from artoolkitx/jsartoolkit5 what do you think?

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 7, 2020

@ThorstenBux i was refering to this project, but refering to jsartoolkit5 i found the old package https://www.npmjs.com/package/jsartoolkit5 but it is linked by https://github.com/artoolkit/jsartoolkit5, it is outdated (4 years old) trying to run on Runkit it fails.
It would be nice to host instead the https://github.com/augmentmy-world/artoolkitX.js/ and https://github.com/artoolkitx/jsartoolkit5 when this last my PR will be merged.

@kalwalt kalwalt closed this as completed Jan 7, 2020
@kalwalt kalwalt reopened this Jan 7, 2020
@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 7, 2020

about artoolkitx/jsartoolkit5 i found this issue artoolkitx/jsartoolkit5#26 but the npm artoolkitx/jsartoolkit5 was not updated after this.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 7, 2020

It would be also interesting to test them in a node environment. I'd like to do if i have time.

@ThorstenBux
Copy link

ThorstenBux commented Jan 7, 2020 via email

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 7, 2020

Yes you are right. I recall this project.
That is the trouble with NPM that everyone can publish packages with a name. I can’t update them.
Don’t know how to contact the author either.

I could publish it as artoolkitx/jsartoolkit5 I guess.

Maybe we can contact the authot of that issue/PR @hakandilek and let us know if he can add us as collaborators.

@ThorstenBux
Copy link

Let us see if he responds

@hakandilek
Copy link

👋
Hi here I am,

Yes sure, I can re-publish it or give access to any of you guys.

I cannot find the original project (github.com/artoolkit/jsartoolkit5) on Github. One I could find and associate with the published code is the https://github.com/artoolkitx/jsartoolkit5 but this one seems to be outdated as well. I'd be nice if you could pull me in the context with some history lecture. ;-)

Also, README.md in this repo is not much npmjs.org friendly. It documents how to build the library within the shell quite well but misses the installation instructions for npm install.

@ThorstenBux
Copy link

ThorstenBux commented Jan 8, 2020 via email

@ThorstenBux
Copy link

ThorstenBux commented Jan 8, 2020 via email

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 8, 2020

Thank you @hakandilek for the answer and the help!

@hakandilek
Copy link

History lesson in short as I’m on the phone. DAQRI the owner of artoolkit org deleted the account today.

😒

ArtoolkitX is the follow up repo. Would be good if you could give me access to the npm project. I’m one of the main contributors to artoolkit(x). And kalwalt as well as he is the one that does the most of the jsartoolkit5 work right now.

Sure thing. Do you use the same alias for npmjs?

If you could help us with a proper npm friendly readme that would be awesome. Can reply in detail later if you have more questions I’m happy to answer those.

Can you please provide instructions for npm integration? I'm not actively developing AR applications anymore. But I can test and provide feedback later.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 8, 2020

@hakandilek do you made the typescript porting of jsartoolkit5 ? I would to know if we should make some updates in the code (i did but not sure of). Sorry for the off topic, I'm sure that is related in some way, i will open other issue on my repo.

@ThorstenBux
Copy link

ThorstenBux commented Jan 8, 2020 via email

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 8, 2020

History lesson in short as I’m on the phone. DAQRI the owner of artoolkit org deleted the account today.

oh nooo! why this? this is a nonsense...

@ThorstenBux
Copy link

DAQRI is bankrupt and is winding down.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 10, 2020

Artoolkitx.js could not be used as a node package at the moment as it is.

  1. it lacks of the libs in the repo ( must be downloaded with the build script and placed in the SDK/lib folder) so a npm package will fails.

  2. it lacks of an index.js file ( but you can configure another file as entry point in the package.json file

  3. it use the window object in some part of the code. And this is not nodejs friendly.

with this in mind i try to adequate to this three points the code in a locale repo for testing.

this the folder structure:

test-npm-artoolkitxjs

  • index.js
  • package.json
  • node_modules
    • artoolkitX.js

inside the artoolkitX.js folder SDK/lib folder with all the libs, and index.js:

// index.js
module.exports = function() {
require( './SDK/lib/artoolkitX.api.js');
};

and test-npm-artoolkitxjs/index.js:

const artoolkitxjs = require("artoolkitX.js");

console.log('Hello ArtoolkitX.js!');
console.log(artoolkitxjs);

var cameraParam = new artoolkitxjs.ARCameraParam();
console.log(cameraParam);

and test-npm-artoolkitxjs/package.json:

{
  "name": "test-npm-artoolkitxjs",
  "version": "1.0.0",
  "description": "testing artoolkitxjs",
  "main": "index.js",
  "devDependencies": {
    "artoolkitX.js": "^0.0.0"
  },
  "scripts": {
    "test": "",
    "build": "node index.js"
  },
  "keywords": [
    "artoolkitX.js"
  ],
  "author": "@kalwalt",
  "license": "GPL-3.0-or-later"
}

i run the command:

npm run build

result:

walter@walter-RC530-RC730:~/kalwalt-github/test/test-npm-artoolkitxjs$ npm run build

> test-npm-artoolkitxjs@1.0.0 build /home/walter/kalwalt-github/test/test-npm-artoolkitxjs
> node index.js

Hello ArtoolkitX.js!
[Function (anonymous)]
/home/walter/kalwalt-github/test/test-npm-artoolkitxjs/index.js:7
var cameraParam = new artoolkitxjs.ARCameraParam();
                  ^

TypeError: artoolkitxjs.ARCameraParam is not a constructor
    at Object.<anonymous> (/home/walter/kalwalt-github/test/test-npm-artoolkitxjs/index.js:7:19)
    at Module._compile (internal/modules/cjs/loader.js:1121:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1160:10)
    at Module.load (internal/modules/cjs/loader.js:976:32)
    at Function.Module._load (internal/modules/cjs/loader.js:884:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:67:12)
    at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-npm-artoolkitxjs@1.0.0 build: `node index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test-npm-artoolkitxjs@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/walter/.npm/_logs/2020-01-10T13_30_49_701Z-debug.log

what i have done wrong?

@le0m
Copy link

le0m commented Jan 24, 2020

The problem is that you're exporting a function:

const artoolkitxjs = require("artoolkitX.js");

console.log('Hello ArtoolkitX.js!');
console.log(artoolkitxjs); // <--- note that this logs [Function (anonymous)]

So you should call it before using it:

const artoolkitxjs = require("artoolkitX.js")(); // <--- call the required function

After the change, the require will work and here's the real problem:

import artoolkitXjs from 'artoolkitX.js/SDK/lib/artoolkitx.js'
^^^^^^

SyntaxError: Cannot use import statement outside a module

The artoolkitX you're using as a library has import/export syntax, which won't work in nodejs.

EDIT:

Nodejs 13 has experimental support for ECMAScript modules.
You can enable this by adding "type": "module" to both test-npm-artoolkitxjs/package.json and test-npm-artoolkitxjs/node_modules/artoolkitX.js/package.json

If you do this and try to import:

import artoolkitxjs from './node_modules/artoolkitX.js/SDK/lib/artoolkitX.api.js';

it will "work" with this error:

ReferenceError: window is not defined

which is a step forward :D

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 24, 2020

Thank you @le0m i will think about this. At the moment i have other priority about this project, but i think it would be interesting to make it nodejs compatible.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 24, 2020

thanks @le0m for the steps you added!
I think the error:
ReferenceError: window is not defined
is caused because at the beginning there is the wasm section with some window call should be changed as i did for the jsartoolkit5 lib in this test https://github.com/kalwalt/jsartoolkit5-nodejs https://github.com/kalwalt/jsartoolkit5/blob/e574e54ee0afc345d022549a2d06373dcd06b7a0/js/artoolkit.api.js#L4-L22
Probably needs to be changed also other parts but for the wasm section it is needed to modify the ARX_wasmLoader.js and the rebuild the libs.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 24, 2020

For anyone else interested i created this repository https://github.com/kalwalt/artoolkitxjs-nodejs

@le0m
Copy link

le0m commented Jan 25, 2020

Glad to help, I may have more time to look into this next week!

Taking a step back for a moment: does Nodejs compatibility have an usecase?
Since we're not in the browser there is no default video input/output, only console. I see https://www.npmjs.com/package/node-webcam is a thing, which could mean that some usecase may exist.

Just throwing this out there, what you think?

@kalwalt
Copy link
Collaborator Author

kalwalt commented Jan 25, 2020

Glad to help, I may have more time to look into this next week!

Thank you! It will be awesome!

Taking a step back for a moment: does Nodejs compatibility have an usecase?
Since we're not in the browser there is no default video input/output, only console. I see https://www.npmjs.com/package/node-webcam is a thing, which could mean that some usecase may exist.

Just throwing this out there, what you think?

I have no idea. i will look into the node-webcam package you posted. Maybe we can found some infos on Emscripten site.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Feb 8, 2020

@le0m have you tried again with node? I did some little steps ahead but still can't use it with node.
I tried also to import it as a module in a simple react app but it fails. The reason is does not parse the WASM code correctly. Maybe i will open another issue on this topic.

@le0m
Copy link

le0m commented Feb 10, 2020

I'm sorry but I was busy with other personal projects, I'll try to have a look at your nodejs repo this week.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Feb 10, 2020

Ok, no problem, just to know what do you think, thank you! 😄

@andypotato
Copy link

I fixed this issue in my own ES6 build of ARToolkit, see the related issue.

The root cause is Emscripten injecting some code that doesn't play nice with Node.js. My solution was to:

  1. Build the WASM module as single file (SINGLE_FILE=1)
  2. Disable the use of import.meta (USE_ES6_IMPORT_META=0) as this will cause Webpack to choke
  3. Add a workaround for this Webpack bug

This will make ARToolkit itself run in all environments without issues.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Feb 19, 2020

@andypotato thank you 🙂, sure I will try to build as a single file, it will solve the wasm issue, i will see if it is affected by other problems.

@kalwalt
Copy link
Collaborator Author

kalwalt commented Feb 19, 2020

As a single file is better: the wasm issue disappear. Pr here augmentmy-world/artoolkitx#5

EDIT: that PR is closed go to the new one: augmentmy-world/artoolkitx#6

@kalwalt
Copy link
Collaborator Author

kalwalt commented Apr 12, 2020

@le0m I created a npm scoped package https://www.npmjs.com/package/@kalwalt/artoolkitx.js to test ArtoolkitX.js with react try this little project https://github.com/kalwalt/artoolkitxjs-react , Although it is not finished yet, at least it loads correctly ArtoolkitX.js... 😄

@le0m
Copy link

le0m commented Apr 15, 2020

Great work @kalwalt!
I'm sorry I didn't come back to this, It's been some really busy weeks (I thought the pandemic was going to give me more free time...quite the opposite <.<")

@kalwalt
Copy link
Collaborator Author

kalwalt commented Apr 15, 2020

Great work @kalwalt!
I'm sorry I didn't come back to this, It's been some really busy weeks (I thought the pandemic was going to give me more free time...quite the opposite <.<")

No worries @leom, just to inform you. But I haven't tested with node, I think i have to apply the modify @andypotato suggested. More to come stay tuned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers Medium priority medium priority issue
Projects
None yet
Development

No branches or pull requests

5 participants