-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tsc): fix tsc build process and file importing
- Loading branch information
Showing
29 changed files
with
336 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#! /usr/bin/env node | ||
import { CLI } from '../dist' | ||
import { CLI } from '../dist/index.js' | ||
CLI(process.argv.slice(2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Environment } from './types.ts'; | ||
/** | ||
* Executes env - cmd using command line arguments | ||
* @export | ||
* @param {string[]} args Command line argument to pass in ['-f', './.env'] | ||
* @returns {Promise<Environment>} | ||
*/ | ||
export declare function CLI(args: string[]): Promise<Environment>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as processLib from 'node:process'; | ||
import { EnvCmd } from './env-cmd.js'; | ||
import { parseArgs } from './parse-args.js'; | ||
/** | ||
* Executes env - cmd using command line arguments | ||
* @export | ||
* @param {string[]} args Command line argument to pass in ['-f', './.env'] | ||
* @returns {Promise<Environment>} | ||
*/ | ||
export async function CLI(args) { | ||
// Parse the args from the command line | ||
const parsedArgs = parseArgs(args); | ||
// Run EnvCmd | ||
try { | ||
return await EnvCmd(parsedArgs); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return processLib.exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import { EnvCmdOptions } from './types'; | ||
/** | ||
* Executes env - cmd using command line arguments | ||
* @export | ||
* @param {string[]} args Command line argument to pass in ['-f', './.env'] | ||
* @returns {Promise<{ [key: string]: any }>} | ||
*/ | ||
export declare function CLI(args: string[]): Promise<Record<string, any>>; | ||
import type { EnvCmdOptions, Environment } from './types.ts'; | ||
/** | ||
* The main env-cmd program. This will spawn a new process and run the given command using | ||
* various environment file solutions. | ||
* | ||
* @export | ||
* @param {EnvCmdOptions} { command, commandArgs, envFile, rc, options } | ||
* @returns {Promise<{ [key: string]: any }>} Returns an object containing [environment variable name]: value | ||
* @returns {Promise<Environment>} Returns an object containing [environment variable name]: value | ||
*/ | ||
export declare function EnvCmd({ command, commandArgs, envFile, rc, options }: EnvCmdOptions): Promise<Record<string, any>>; | ||
export declare function EnvCmd({ command, commandArgs, envFile, rc, options, }: EnvCmdOptions): Promise<Environment>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,47 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const spawn_1 = require("./spawn"); | ||
const signal_termination_1 = require("./signal-termination"); | ||
const parse_args_1 = require("./parse-args"); | ||
const get_env_vars_1 = require("./get-env-vars"); | ||
const expand_envs_1 = require("./expand-envs"); | ||
/** | ||
* Executes env - cmd using command line arguments | ||
* @export | ||
* @param {string[]} args Command line argument to pass in ['-f', './.env'] | ||
* @returns {Promise<{ [key: string]: any }>} | ||
*/ | ||
async function CLI(args) { | ||
// Parse the args from the command line | ||
const parsedArgs = parse_args_1.parseArgs(args); | ||
// Run EnvCmd | ||
try { | ||
return await exports.EnvCmd(parsedArgs); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
return process.exit(1); | ||
} | ||
} | ||
exports.CLI = CLI; | ||
import { default as spawn } from 'cross-spawn'; | ||
import { TermSignals } from './signal-termination.js'; | ||
import { getEnvVars } from './get-env-vars.js'; | ||
import { expandEnvs } from './expand-envs.js'; | ||
import * as processLib from 'node:process'; | ||
/** | ||
* The main env-cmd program. This will spawn a new process and run the given command using | ||
* various environment file solutions. | ||
* | ||
* @export | ||
* @param {EnvCmdOptions} { command, commandArgs, envFile, rc, options } | ||
* @returns {Promise<{ [key: string]: any }>} Returns an object containing [environment variable name]: value | ||
* @returns {Promise<Environment>} Returns an object containing [environment variable name]: value | ||
*/ | ||
async function EnvCmd({ command, commandArgs, envFile, rc, options = {} }) { | ||
var _a; | ||
export async function EnvCmd({ command, commandArgs, envFile, rc, options = {}, }) { | ||
let env = {}; | ||
try { | ||
env = await get_env_vars_1.getEnvVars({ envFile, rc, verbose: options.verbose }); | ||
env = await getEnvVars({ envFile, rc, verbose: options.verbose }); | ||
} | ||
catch (e) { | ||
if (!((_a = options.silent) !== null && _a !== void 0 ? _a : false)) { | ||
if (!(options.silent ?? false)) { | ||
throw e; | ||
} | ||
} | ||
// Override the merge order if --no-override flag set | ||
if (options.noOverride === true) { | ||
env = Object.assign({}, env, process.env); | ||
env = Object.assign({}, env, processLib.env); | ||
} | ||
else { | ||
// Add in the system environment variables to our environment list | ||
env = Object.assign({}, process.env, env); | ||
env = Object.assign({}, processLib.env, env); | ||
} | ||
if (options.expandEnvs === true) { | ||
command = expand_envs_1.expandEnvs(command, env); | ||
commandArgs = commandArgs.map(arg => expand_envs_1.expandEnvs(arg, env)); | ||
command = expandEnvs(command, env); | ||
commandArgs = commandArgs.map(arg => expandEnvs(arg, env)); | ||
} | ||
// Execute the command with the given environment variables | ||
const proc = spawn_1.spawn(command, commandArgs, { | ||
const proc = spawn(command, commandArgs, { | ||
stdio: 'inherit', | ||
shell: options.useShell, | ||
env | ||
env: env, | ||
}); | ||
// Handle any termination signals for parent and child proceses | ||
const signals = new signal_termination_1.TermSignals({ verbose: options.verbose }); | ||
const signals = new TermSignals({ verbose: options.verbose }); | ||
signals.handleUncaughtExceptions(); | ||
signals.handleTermSignals(proc); | ||
return env; | ||
} | ||
exports.EnvCmd = EnvCmd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import type { Environment } from './types.ts'; | ||
/** | ||
* expandEnvs Replaces $var in args and command with environment variables | ||
* the environment variable doesn't exist, it leaves it as is. | ||
* if the environment variable doesn't exist, it leaves it as is. | ||
*/ | ||
export declare function expandEnvs(str: string, envs: Record<string, any>): string; | ||
export declare function expandEnvs(str: string, envs: Environment): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* expandEnvs Replaces $var in args and command with environment variables | ||
* the environment variable doesn't exist, it leaves it as is. | ||
* if the environment variable doesn't exist, it leaves it as is. | ||
*/ | ||
function expandEnvs(str, envs) { | ||
return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, varName => { | ||
export function expandEnvs(str, envs) { | ||
return str.replace(/(?<!\\)\$[a-zA-Z0-9_]+/g, (varName) => { | ||
const varValue = envs[varName.slice(1)]; | ||
return varValue === undefined ? varName : varValue; | ||
// const test = 42; | ||
return varValue === undefined ? varName : varValue.toString(); | ||
}); | ||
} | ||
exports.expandEnvs = expandEnvs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { GetEnvVarOptions } from './types'; | ||
export declare function getEnvVars(options?: GetEnvVarOptions): Promise<Record<string, any>>; | ||
import type { GetEnvVarOptions, Environment } from './types.ts'; | ||
export declare function getEnvVars(options?: GetEnvVarOptions): Promise<Environment>; | ||
export declare function getEnvFile({ filePath, fallback, verbose }: { | ||
filePath?: string; | ||
fallback?: boolean; | ||
verbose?: boolean; | ||
}): Promise<Record<string, any>>; | ||
}): Promise<Environment>; | ||
export declare function getRCFile({ environments, filePath, verbose }: { | ||
environments: string[]; | ||
filePath?: string; | ||
verbose?: boolean; | ||
}): Promise<Record<string, any>>; | ||
}): Promise<Environment>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { getEnvVars } from './get-env-vars'; | ||
export * from './types'; | ||
export * from './env-cmd'; | ||
import { getEnvVars } from './get-env-vars.js'; | ||
export * from './types.js'; | ||
export * from './cli.js'; | ||
export * from './env-cmd.js'; | ||
export declare const GetEnvVars: typeof getEnvVars; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const get_env_vars_1 = require("./get-env-vars"); | ||
__export(require("./env-cmd")); | ||
exports.GetEnvVars = get_env_vars_1.getEnvVars; | ||
import { getEnvVars } from './get-env-vars.js'; | ||
// Export the core env-cmd API | ||
export * from './types.js'; | ||
export * from './cli.js'; | ||
export * from './env-cmd.js'; | ||
export const GetEnvVars = getEnvVars; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import * as commander from 'commander'; | ||
import { EnvCmdOptions } from './types'; | ||
import type { EnvCmdOptions, CommanderOptions } from './types.ts'; | ||
/** | ||
* Parses the arguments passed into the cli | ||
*/ | ||
export declare function parseArgs(args: string[]): EnvCmdOptions; | ||
export declare function parseArgsUsingCommander(args: string[]): commander.Command; | ||
export declare function parseArgsUsingCommander(args: string[]): CommanderOptions; |
Oops, something went wrong.