Open slackwareer opened 1 month ago
### Test Common Functions
{{
const test = require('./test.js')
console.log(test.TestFunc());
}}
You need to call your method
See https://github.com/httpyac/httpyac.github.io/blob/main/examples/script/scriptRequire.http
### Test Common Functions {{ const test = require('./test.js') console.log(test.TestFunc()); }}
You need to call your method
I called the method with following codes:
### Test Common Functions
{{
const test = require('./test.js')
test.TestFunc()
}}
Unfortunately I got nothing output...
It works, but not the way you expect it to. It works directly on the command line. In vscode it would also work, but the console output is not the output channel but really stdout.
For scripts that I execute directly, I overwrite the console output so that it appears in the OutputChannel. For require scripts I have not yet found a trick for this, so it writes directly to stdout. Pass the function the reference to the console then it would work.
### Test Common Functions
{{
const test = require('./test.js')
console.log(test.TestFunc(console));
}}
const TestFunc = (c) => {
c.log("test");
};
exports.TestFunc = TestFunc
It works, but not the way you expect it to. It works directly on the command line. In vscode it would also work, but the console output is not the output channel but really stdout.
For scripts that I execute directly, I overwrite the console output so that it appears in the OutputChannel. For require scripts I have not yet found a trick for this, so it writes directly to stdout. Pass the function the reference to the console then it would work.
### Test Common Functions {{ const test = require('./test.js') console.log(test.TestFunc(console)); }}
const TestFunc = (c) => { c.log("test"); }; exports.TestFunc = TestFunc
Yeah ,passing the outer console object to the required function works, it print to OutputChannel and the log can be read in the httpyac Console.
And if there is a way to overwrite the global console.log
method or overwrite the origin required script to override the console.log
method in the script ? Or maybe it's a problem that if it's worthy to do such stuff ......
And if there is a way to overwrite the global console.log method or overwrite the origin required script to override the console.log method in the script
PR is welcome. I've been looking into NodeJS vm for a while, but haven't found it. If you have an idea, please feel free.
@AnWeber Quote of the day: "It works, but not the way you expect it to." :-)
A js file which exports some functions is required by a http script, however the requiring result is only an empty object.
JS file: test.js
test.http file
Guess what is printed... It turns out to be just an empty object.![image](https://github.com/AnWeber/vscode-httpyac/assets/239952/187335f0-628c-458f-8cd8-57fa10f1e976)
So how can I write a js file which can be required by the http file?