Is there an equivalent to package.json?

Asked by Brian Douglass

I noticed there isn't a package.json file anywhere in my JS Scope. Is there anything similar to that in use?
Also, it seems to be general practice to not check node_modules into version control, but without a package.json there isn't any way to re-create those depenecies. Should I just check my node_modules into version control so it can be easily picked up by someone else (that's what I've done for now)?

Question information

Language:
English Edit question
Status:
Solved
For:
unity-js-scopes Edit question
Assignee:
No assignee Edit question
Solved by:
Marcus Tomlinson
Solved:
Last query:
Last reply:
Revision history for this message
Best Marcus Tomlinson (marcustomlinson) said :
#1

Sorry that this is not obvious but yeah there is a way to define your dependancies in the CMake project such that they need not be committed to VCS.

At the top of your project's root CMakeLists.txt, you'll see the following line:

    execute_process(COMMAND unity-js-scopes-tool install ${CMAKE_SOURCE_DIR}/src/node_modules unity-js-scopes)

You can add other dependancies by inserting more of these execute_process commands directly underneath. So for example if I wanted to include the "pixl-xml" module into my project, I'd add:

    execute_process(COMMAND unity-js-scopes-tool install ${CMAKE_SOURCE_DIR}/src/node_modules pixl-xml)

And for the "node-gettext" module:

    execute_process(COMMAND unity-js-scopes-tool install ${CMAKE_SOURCE_DIR}/src/node_modules node-gettext)

And so on.

Revision history for this message
Brian Douglass (bhdouglass) said :
#2

Thanks Marcus Tomlinson, that solved my question.

Revision history for this message
Brian Douglass (bhdouglass) said :
#3

Ah I didn't think of that! That should work out nicely. Does the unity-js-scopes-tool accept a version in addition to the module name?

Also, out of curiosity, what's the difference between "unity-js-scopes-tool install" and "npm install"?

Revision history for this message
Marcus Tomlinson (marcustomlinson) said :
#4

If you run "unity-js-scopes-tool -h" you'll see what arguments it accepts. So no, we don't accept a version number. Do you think we should?

On the topic of how are they different: When you install a module using "unity-js-scopes-tool install", you'll see the output:

    Running 'node /node_modules/npm/cli.js --prefix=<modules_dir> --ignore-scripts install <module>' ...

This is the underlying command being executed. "node /node_modules/npm/cli.js" is really a fancy way of calling "npm". So that command is:

    'npm --prefix=<modules_dir> --ignore-scripts install <module>'

We use "--prefix" to ensure a module is install into a specified directory (i.e. the scope directory), and "--ignore-scripts" to skip any post-install build scripts from running during a CMake (this we do in a separate "unity-js-scopes-tool build" step during the actual build of your project).

We also do some other magic via unity-js-scopes-tool that handles cross-compilation, and some other stuff to avoid redundant re-installation / re-building when the module already exists or is already built (which can be overridden with "unity-js-scopes-tool reinstall / rebuild" btw).

I hope that answers your questions

Revision history for this message
Brian Douglass (bhdouglass) said :
#5

I think including an option to select the module version would be preferable. I've seen "beta" modules and breaking changes between major versions, so being able to select which version gets install would be nice.

Ah, thanks for the great explanation! So the important part is getting the modules cross complied correctly.

Revision history for this message
Marcus Tomlinson (marcustomlinson) said :
#6

Fair point. I've added a bug.

Revision history for this message
Marcus Tomlinson (marcustomlinson) said :
#7

Oops, looks like this actually is already possible. See my comment on the linked bug: https://bugs.launchpad.net/unity-js-scopes/+bug/1552661

Revision history for this message
Brian Douglass (bhdouglass) said :
#8

Haha, nice! More features for me and less work for you!