From a4d1af18deabe79caa959eb654ca1ebc2d9f6867 Mon Sep 17 00:00:00 2001 From: Ivan Zakharchanka <3axap4eHko@gmail.com> Date: Tue, 21 Mar 2023 04:04:55 -0400 Subject: [PATCH] fix(bindings/node): Fix loading of `spack.config.js` (#7105) --- node-swc/src/spack.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/node-swc/src/spack.ts b/node-swc/src/spack.ts index 3e3a3f5599b7..befd93d931bf 100644 --- a/node-swc/src/spack.ts +++ b/node-swc/src/spack.ts @@ -4,12 +4,15 @@ import { Options } from "./types"; export type BundleInput = BundleOptions | BundleOptions[]; +export const isLocalFile = /^\.{0,2}\//; // starts with '/' './' '../' + export async function compileBundleOptions(config: BundleInput | string | undefined): Promise { const f = config === undefined ? '.' : config; try { - const file = typeof f === 'string' ? f : path.resolve('spack.config.js'); - let configFromFile: BundleInput = require(file); + const filepath = typeof f === 'string' ? f : 'spack.config.js'; + const fileModule = isLocalFile.test(filepath) ? path.resolve(filepath) : filepath; + let configFromFile: BundleInput = require(fileModule); if ((configFromFile as any).default) { configFromFile = (configFromFile as any).default; }