Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@RaisinTen
Copy link
Member

@RaisinTen RaisinTen commented Oct 17, 2022

Compile a JavaScript file into a single executable application:

$ echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js

$ cp $(command -v node) hello

# On systems other than macOS:
$ npx postject hello NODE_JS_CODE hello.js \
    --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2

# On macOS:
$ npx postject hello NODE_JS_CODE hello.js \
    --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
    --macho-segment-name NODE_JS

$ ./hello world
Hello, world!

Signed-off-by: Darshan Sen [email protected]


It was decided in the Node.js Collaborator Summit that we want to come up with an MVP that is capable of compiling a single JavaScript file into a single executable application. More features will be added incrementally.

Meeting notes for reference: https://github.com/nodejs/single-executable/blob/c7008ecd67a395c7c902d602f2f116e2c5744bc9/meetings/2022-10-01.md


cc @nodejs/single-executable

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/actions
  • @nodejs/gyp
  • @nodejs/startup
  • @nodejs/tsc

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Oct 17, 2022
RaisinTen added a commit to nodejs/single-executable that referenced this pull request Oct 17, 2022
@aduh95 aduh95 added semver-minor PRs that contain new features and should be released in the next minor version. notable-change PRs with changes that should be highlighted in changelogs. labels Oct 17, 2022
@jviotti
Copy link
Member

jviotti commented Oct 17, 2022

@RaisinTen Don't forget to list this PR in https://github.com/nodejs/single-executable's README, for the record :)

@kapv89
Copy link

kapv89 commented Oct 17, 2022

Question: does the executable require node to be installed?

@jasnell
Copy link
Member

jasnell commented Oct 17, 2022

Adding postject really should be done in a separate commit. Also, are we sure it's actually needed here at all? It's a rather sizeable addition on its own.

@GeoffreyBooth
Copy link
Member

Please make it print the experimental warning if that isn’t happening already.

RaisinTen added a commit to nodejs/postject that referenced this pull request Oct 19, 2022
Fixes the following error I came across while integrating Postject in
Node.js:
```console
../deps/postject/src/dist/postject-api.h:30:13: error: unused function 'postject_options_init' [-Werror,-Wunused-function]
static void postject_options_init(struct postject_options* options) {
            ^
1 error generated.
```

Refs: nodejs/node#45038
Signed-off-by: Darshan Sen <[email protected]>
@ovflowd
Copy link
Member

ovflowd commented Oct 19, 2022

Is it just me or the deps/postject/postject.js is obfuscated, or at least very unreadable? Is this intended? Is this the source of the project or a compiled version? (I believe the later one)

@ovflowd
Copy link
Member

ovflowd commented Oct 19, 2022

Off-topic: Having the source of postject here means that this is a full copy of the original repository? What would happen with the original repository? Or is this intended to be a snapshot of the project at a given point in time?

Copy link
Member

@ovflowd ovflowd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool stuff! Super mega hyper excited for this!

@RaisinTen RaisinTen mentioned this pull request Oct 19, 2022
@RaisinTen
Copy link
Member Author

Question: does the executable require node to be installed?

@kapv89 no it does not. That's one of the main use cases for the single executables applications - so that it is possible to distribute a Node.js application to a user who does not already have Node.js installed on their system.

@RaisinTen
Copy link
Member Author

Adding postject really should be done in a separate commit. Also, are we sure it's actually needed here at all? It's a rather sizeable addition on its own.

@jasnell sure, moved it to its own PR - #45066. And yes, it is needed for the resource injection part.

@RaisinTen
Copy link
Member Author

Is it just me or the deps/postject/postject.js is obfuscated, or at least very unreadable? Is this intended? Is this the source of the project or a compiled version? (I believe the later one)

@ovflowd it is the compiled version :)

@ovflowd
Copy link
Member

ovflowd commented Oct 19, 2022

@ovflowd it is the compiled version :)

Do we need the compiled version? As node-gyp seems to actually build the source?

@RaisinTen
Copy link
Member Author

@ovflowd as mentioned in #45066 (comment), that is the webassembly code which is precompiled in postject. It's built using the emsdk, not node-gyp.

@RaisinTen
Copy link
Member Author

@danielleadams done - #47495!

@danielleadams
Copy link
Contributor

@RaisinTen If you have some time, would you mind putting together a small summary for the v18.16.0 release notes? Thanks!

@RaisinTen
Copy link
Member Author

@danielleadams sure! Does this work?


Add initial support for single executable applications

Compile a JavaScript file into a single executable application:

$ echo 'console.log(`Hello, ${process.argv[2]}!`);' > hello.js

$ cp $(command -v node) hello

# On systems other than macOS:
$ npx postject hello NODE_JS_CODE hello.js \
    --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2

# On macOS:
$ npx postject hello NODE_JS_CODE hello.js \
    --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2 \
    --macho-segment-name NODE_JS

$ ./hello world
Hello, world!

Contributed by Darshan Sen in #45038

@danielleadams
Copy link
Contributor

@RaisinTen perfect - thanks!

@waitingsong
Copy link

waitingsong commented Apr 13, 2023

something wrong?

[admin tmp]$ npx postject hello NODE_JS_CODE hello.js \
>     --sentinel-fuse NODE_JS_FUSE_fce680ab2cc467b6e072b8b5df1996b2

Need to install the following packages:
  [email protected]
Ok to proceed? (y)
Start injection of NODE_JS_CODE in hello...
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'
warning: Can't find string offset for section name '.note.100'

CentOS 8

[admin tmp]$ uname -a
Linux git 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

@RaisinTen
Copy link
Member Author

@waitingsong which version of Node.js are you using? Does running ./hello work for you? Also, if you don't mind could you open an issue in https://github.com/nodejs/postject/issues to further discuss this?

@waitingsong
Copy link

waitingsong commented Apr 13, 2023

which version of Node.js are you using? Does running ./hello work for you? Also, if you don't mind could you open an issue in https://github.com/nodejs/postject/issues to further discuss this?


[admin tmp]$ node -v
v18.16.0
[admins tmp]$ npm -v
9.5.1
[admin tmp]$ node hello.js
Hello, undefined!

issue: nodejs/postject#83

EDIT:
It works.

@RaisinTen RaisinTen added the single-executable Issues and PRs related to single-executable applications label May 5, 2023
@RezaErfani67
Copy link

it give me error
Error [ERR_UNKNOWN_BUILTIN_MODULE]: No such built-in module: express
at embedderRequire (node:internal/util/embedding:48:11)
at hello.js:1:17
at embedderRunCjs (node:internal/util/embedding:37:10)
at node:internal/main/embedding:18:8 {
code: 'ERR_UNKNOWN_BUILTIN_MODULE'
}
@RaisinTen

@RaisinTen
Copy link
Member Author

@RezaErfani67 could you create an issue in https://github.com/nodejs/single-executable/issues?

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. notable-change PRs with changes that should be highlighted in changelogs. semver-minor PRs that contain new features and should be released in the next minor version. single-executable Issues and PRs related to single-executable applications

Projects

None yet

Development

Successfully merging this pull request may close these issues.