Skip to content

Commit

Permalink
[Runtime] fix: fixed execution on older node.js versions
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Nov 10, 2023
1 parent 3111adf commit 7ebe505
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ try {
}
}

const nullish = (value, cond) => ((undefined === value) || (null === value)) ? cond() : value;
const awsLambdaTaskRoot = process.env.LAMBDA_TASK_ROOT;
const awsHandler = process.env._HANDLER;
const FUNCTION_EXPR = /^([^.]*)\.(.*)$/;
Expand Down Expand Up @@ -52,12 +53,15 @@ if (awsLambdaTaskRoot && awsHandler) {
}

delete require.cache[file];
const mainExports = __jymfony.autoload.classLoader.loadFile(file, null);
const mainExports = __jymfony.autoload.classLoader.loadFile(file);
if (mainExports.__esModule) {
exportName = 'default';
}

let runtime = process.env.APP_RUNTIME ?? Jymfony.Component.Runtime.JymfonyRuntime;
let runtime = nullish(process.env.APP_RUNTIME, () => Jymfony.Component.Runtime.JymfonyRuntime);
const reflection = new ReflectionClass(runtime);

runtime = reflection.newInstance(Object.assign({ project_dir: dirname(file) }, globalThis.APP_RUNTIME_OPTIONS ?? {}));
runtime = reflection.newInstance(Object.assign({ project_dir: dirname(file) }, nullish(globalThis.APP_RUNTIME_OPTIONS, () => ({}))));

let [ app, args ] = runtime.getResolver(null === exportName ? mainExports : mainExports[exportName]).resolve();
(async function () {
Expand Down
30 changes: 15 additions & 15 deletions src/JymfonyRuntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ const ConsoleOutput = Jymfony.Component.Console.Output.ConsoleOutput;
const GenericRuntime = Jymfony.Component.Runtime.GenericRuntime;
const JymfonyErrorHandler = Jymfony.Component.Runtime.Internal.JymfonyErrorHandler;

function getInput(options) {
const input = new ArgvInput();
const env = input.getParameterOption([ '--env', '-e' ], null, true);
if (null !== env) {
process.env[options.env_var_name] = env;
}

if (input.hasParameterOption('--no-debug', true)) {
process.env[options.debug_var_name] = '0';
}

return input;
}

/**
* Knows the basic conventions to run Jymfony apps.
*
Expand Down Expand Up @@ -65,7 +79,7 @@ export default class JymfonyRuntime extends GenericRuntime {
}

const prodEnvs = options.prod_envs ?? [ 'prod' ];
const input = JymfonyRuntime.#getInput(options);
const input = getInput(options);
if (
!(options.disable_dotenv ?? !ReflectionClass.exists('Jymfony.Component.Dotenv.Dotenv')) &&
!!options.project_dir
Expand Down Expand Up @@ -151,18 +165,4 @@ export default class JymfonyRuntime extends GenericRuntime {

return self;
}

static #getInput(options) {
const input = new ArgvInput();
const env = input.getParameterOption([ '--env', '-e' ], null, true);
if (null !== env) {
process.env[options.env_var_name] = env;
}

if (input.hasParameterOption('--no-debug', true)) {
process.env[options.debug_var_name] = '0';
}

return input;
}
}

0 comments on commit 7ebe505

Please sign in to comment.