{"action":"opened","issue":{"url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2545","repository_url":"https://api.github.com/repos/BuckleScript/bucklescript","labels_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2545/labels{/name}","comments_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2545/comments","events_url":"https://api.github.com/repos/BuckleScript/bucklescript/issues/2545/events","html_url":"https://github.com/BuckleScript/bucklescript/issues/2545","id":300048978,"number":2545,"title":"Example: Is the current file being run from the shell?","user":{"login":"rauschma","id":526114,"avatar_url":"https://avatars3.githubusercontent.com/u/526114?v=4","gravatar_id":"","url":"https://api.github.com/users/rauschma","html_url":"https://github.com/rauschma","followers_url":"https://api.github.com/users/rauschma/followers","following_url":"https://api.github.com/users/rauschma/following{/other_user}","gists_url":"https://api.github.com/users/rauschma/gists{/gist_id}","starred_url":"https://api.github.com/users/rauschma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rauschma/subscriptions","organizations_url":"https://api.github.com/users/rauschma/orgs","repos_url":"https://api.github.com/users/rauschma/repos","events_url":"https://api.github.com/users/rauschma/events{/privacy}","received_events_url":"https://api.github.com/users/rauschma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-25T18:29:07Z","updated_at":"2018-02-25T18:29:07Z","closed_at":null,"author_association":"NONE","body":"Suggestion: On the page https://bucklescript.github.io/docs/en/nodejs-special-variables.html , add the following example:\r\n\r\n```\r\n/**\r\n * Is the current file being run from the shell?\r\n * @param _module Call with [%bs.node _module]\r\n */\r\nlet isMain = (_module: option(Node.node_module)) => {\r\n  let require: option(Node.node_require) = [%bs.node require];\r\n  \r\n  switch (require, _module) {\r\n  | (Some(require'), Some(_module')) =>\r\n    switch (Js.undefinedToOption(require'##main)) {\r\n    | Some(main') =>\r\n      main' === _module'\r\n    | None => Js.Exn.raiseError(\"Illegal state\")\r\n    };\r\n  | _ => Js.Exn.raiseError(\"Illegal state\")\r\n  };\r\n};\r\n```\r\n\r\nCreated with help from Glenn Slotte. https://reasonml.chat/t/where-are-node-module-and-node-require/191\r\n"}}
{"actor":{"display_login":"rauschma"}}