Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[question]could this package be used to wrap local files? #78

Open
radiorz opened this issue Aug 8, 2023 · 3 comments
Open

[question]could this package be used to wrap local files? #78

radiorz opened this issue Aug 8, 2023 · 3 comments

Comments

@radiorz
Copy link

radiorz commented Aug 8, 2023

Like I have a Test.js file,
could i change it like this:

const path = require("path");
const { Hook } = require("require-in-the-middle");

// Hook into the Test module
new Hook(["./Test.js"], function (exports, name, basedir) {
  // 在这里对Test模块进行修改或扩展
  console.log("Hooked into Test module:", name);

  // 返回你想要的修改后的exports对象
  return exports;
});

const Test = require("./Test.js");
console.log(`Test`, Test);
@radiorz
Copy link
Author

radiorz commented Aug 8, 2023

I find absolute path is work:

const Hook = require("require-in-the-middle");
// Hook into the Test module
const hook = new Hook(["G:\\xxx\\math\\require_hack\\Test.js"], function (
  exports,
  name,
  basedir
) {
  // 在这里对Test模块进行修改或扩展
  console.log("Hooked into module:", name);
  // 返回你想要的修改后的exports对象
  return exports;
});

const Test = require("./Test");

but it doesnt work when using null or ['./Test.js']

@radiorz
Copy link
Author

radiorz commented Aug 8, 2023

#56

This pr is work for local files, but still not merged into master branch

@radiorz radiorz changed the title [question] could this package be used to wrap a simple file? could this package be used to wrap local files? Aug 8, 2023
@radiorz radiorz changed the title could this package be used to wrap local files? [question]could this package be used to wrap local files? Aug 8, 2023
@radiorz
Copy link
Author

radiorz commented Aug 16, 2023

#duplicate #37

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant