Skip to content

Commit

Permalink
feat: provide types
Browse files Browse the repository at this point in the history
BREAKING CHANGE: node 20+ is required now
  • Loading branch information
arlac77 committed Mar 20, 2024
1 parent 28653b4 commit 30807fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
18 changes: 17 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"access": "public",
"provenance": true
},
"types": "./types/expander.d.mts",
"exports": {
".": {
"default": "./src/expander.mjs"
"default": "./src/expander.mjs",
"types": "./types/expander.d.mts"
}
},
"description": "Expands expressions in config files",
Expand Down Expand Up @@ -39,14 +41,15 @@
"pratt-parser": "^9.0.2"
},
"devDependencies": {
"@types/node": "^20.11.30",
"ava": "^6.1.2",
"c8": "^9.1.0",
"documentation": "^14.0.3",
"semantic-release": "^23.0.5",
"typescript": "^5.4.2"
},
"engines": {
"node": ">=16.20.2"
"node": ">=20.11.1"
},
"repository": {
"type": "git",
Expand Down
10 changes: 5 additions & 5 deletions src/expander.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from "node:os";
import { readFile } from "node:fs/promises";
import { createCipheriv, createDecipheriv, scryptSync, randomBytes } from "node:crypto";
import { dirname, resolve } from "mode:path";
import { dirname, resolve } from "node:path";
import { spawn } from "node:child_process";
import { createContext } from "expression-expander";
import { ConfigParser } from "./grammar.mjs";
Expand All @@ -27,17 +27,17 @@ const IV = randomBytes(16);
* @param {Object} options.functions additional functions
* @returns {Promise} resolves to the expanded configuration
*/
export async function expand(config, options = {}) {
export async function expand(config, options) {
const context = {
constants: Object.assign(
{
basedir: process.cwd(),
env: process.env,
os
},
options.constants
options?.constants
),
functions: Object.assign({}, functions, options.functions)
functions: Object.assign({}, functions, options?.functions)
};

const parser = new ConfigParser();
Expand All @@ -50,7 +50,7 @@ export async function expand(config, options = {}) {
},...options
});

return options.default !== undefined
return options?.default !== undefined
? merge(await ee.expand(options.default), await ee.expand(config))
: ee.expand(config);
}
Expand Down

0 comments on commit 30807fd

Please sign in to comment.