Skip to content

Commit

Permalink
πŸ“Ÿ Make --globals available in cli via JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Sep 12, 2024
1 parent d6c30df commit dbd8910
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions kdjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ Parameters:
--define : Values for @define annotated variables
--isolateDir : Directory name to write the isolated and preprocessed input files
--emit_shebang : Whether to place bun shebang sequence at the beginning of the output
--globals : A JSON encoded object to be used as globals
```
9 changes: 8 additions & 1 deletion kdjs/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { preprocessAndIsolate } from "./preprocess";
/** @typedef {!Object<string, *>} */
const Params = {};

/**
* @param {*} globals
* @return {!Object<string, *>}
*/
const getGlobals = (globals) => /** @type {!Object<string, *>} */(typeof globals == "string"
? JSON.parse(globals) : (globals || {}));

/**
* @param {!Params} params
* @param {function(!Array<string>):!Promise<boolean>=} checkFreshFn
Expand All @@ -27,7 +34,7 @@ const compile = async (params, checkFreshFn) => {
/** @type {string} */(params["entry"]),
isolateDir,
[].concat(params["externs"] || []),
/** @type {!Object<string, *>} */(params["globals"] || {})
getGlobals(params["globals"])
);
/** @const {!Array<string>} */
const allFilesArray = Array.from(allFiles).sort();
Expand Down
1 change: 1 addition & 0 deletions kdjs/kdjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Parameters:
--define : Values for @define annotated variables
--isolateDir : Directory name to write the isolated and preprocessed input files
--emit_shebang : Whether to place bun shebang sequence at the beginning of the output
--globals : A JSON encoded object to be used as globals
`);
process.exit(0);
}
Expand Down

0 comments on commit dbd8910

Please sign in to comment.