Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ object JavaScriptBinding {
/** Module name of the profile kit: `require('msgbot')`. */
const val KIT = "msgbot"

/** Extensions of JavaScript sources besides the language's own `js`: ES modules and CommonJS files. */
val MODULE_EXTENSIONS: Set<String> = setOf("mjs", "cjs")

/**
* CommonJS loader source. Evaluates to `function (sources, compile, fallback)` returning
* `makeRequire(fromPath)`; `compile(path, text)` must return the module wrapper function and
* `fallback(specifier)` is the runtime's own `require` or null. Engines set the global `require`
* to `makeRequire(entry)` before running the profile.
* Module loader source. Evaluates to `function (sources, compile, fallback, java, esm)` returning
* `makeRequire(fromPath)`. Engines set the global `require` to `makeRequire(entry)` before running the profile.
*
* - `compile(path, text)` returns the CommonJS wrapper function `(exports, require, module, __filename, __dirname)`.
* - `fallback(specifier)` is the runtime's own `require`, or null.
* - `java(name, isClass)` returns the Java package or class for a `java:` module: null when the project may not use
* Java, undefined when there is no such class. Pass null instead of a function when the engine runs no Java.
* - `esm` is true when the engine runs ES modules itself. It then compiles every module that
* `makeRequire.esm.entry(path)` and `makeRequire.esm.moduleFor(specifier, fromPath)` hand it (`{ name, source, esm }`,
* one module per `name`; `makeRequire.esm.nameOf(specifier, fromPath)` gives that name without loading anything).
* When false, files with `#!support esm` on their first line are converted to CommonJS.
* - `makeRequire.script(path)` is the entry file as source for a global script: without its `#!` line, converted
* when needed. An ES module engine runs an entry whose `makeRequire.esm.kindOf(path)` is `"esm"` as a module instead.
*
* The rules are in `docs/bindings/javascript.md`.
*/
val MODULE_LOADER: String by lazy {
resource("modules.js").replace("/*BUILTINS*/null", jsonObject(mapOf(KIT to resource("kit.js"))))
Expand Down
Loading
Loading