From 0507d0b5b139d1558d9917cb29bfce12d4c1ac26 Mon Sep 17 00:00:00 2001 From: Maxxxz <236820310@qq.com> Date: Mon, 14 Oct 2024 23:25:20 +0800 Subject: [PATCH] fix: dlopen relative part problem in mac system --- src/index.js | 4 ++-- test/__snapshots__/loader.test.js.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index f20df80..5440a38 100644 --- a/src/index.js +++ b/src/index.js @@ -23,9 +23,9 @@ export default function loader(content) { return ` try { - process.dlopen(module, __dirname + require("path").sep + __webpack_public_path__ + ${JSON.stringify( + process.dlopen(module, require("path").join(__dirname, __webpack_public_path__, ${JSON.stringify( name - )}${ + )})${ typeof options.flags !== "undefined" ? `, ${JSON.stringify(options.flags)}` : "" diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 3ce6d4b..78dfd50 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -5,7 +5,7 @@ exports[`loader should throw an error on broken "node" addon: errors 1`] = `Arra exports[`loader should throw an error on broken "node" addon: module 1`] = ` " try { - process.dlopen(module, __dirname + require(\\"path\\").sep + __webpack_public_path__ + \\"broken.node\\"); + process.dlopen(module, require(\\"path\\").join(__dirname, __webpack_public_path__, \\"broken.node\\")); } catch (error) { throw new Error('node-loader:\\\\n' + error); } @@ -19,7 +19,7 @@ exports[`loader should work: errors 1`] = `Array []`; exports[`loader should work: module 1`] = ` " try { - process.dlopen(module, __dirname + require(\\"path\\").sep + __webpack_public_path__ + \\"hello.node\\", 1); + process.dlopen(module, require(\\"path\\").join(__dirname, __webpack_public_path__, \\"hello.node\\"), 1); } catch (error) { throw new Error('node-loader:\\\\n' + error); }