xpl / get-source Goto Github PK
View Code? Open in Web Editor NEWFetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.
Home Page: http://npmjs.com/package/get-source
License: MIT License
Fetch source-mapped sources. Peek by file, line, column. Node & browsers. Sync & async.
Home Page: http://npmjs.com/package/get-source
License: MIT License
Hello again,
i'd like to know if it would be possible to use and xhr request instead of fetch for fetchFileAsync
.
Fetch only supports the http
protocol, while xhr also supports file
for compiled apps on android & similar.
I tried to replace it with an xhr request, and the module seems to be working.
This would be the code (very similar to the synchronous function):
module.exports.async = impl (function fetchFileAsync (path) {
return new Promise ((resolve, reject) => {
if (isBrowser) {
let xhr = new XMLHttpRequest ()
xhr.open ('GET', path)
xhr.send (null)
xhr.onload = r => resolve(xhr.responseText)
} else {
module.require ('fs').readFile (path, { encoding: 'utf8' }, (e, x) => {
e ? reject (e) : resolve (x)
})
}
})
})
Is there any reason why fetch would be necessarily needed?
Have a nice day
Hello,
i'm using xpl/stacktracey in a framework7 project with webpack which targets web
or cordova
.
After npm install
ing stacktracey and running webpack dev server with target web
, the following error is reported:
ERROR in a:/projects/temp/node_modules/get-source/get-source.js
Module not found: Error: Can't resolve 'fs' in 'a:\projects\temp\node_modules\get-source'
@ a:/projects/temp/node_modules/get-source/get-source.js 144:41-62 156:40-61
@ a:/projects/temp/node_modules/stacktracey/stacktracey.js
@ a:/projects/temp/src/js/errorReporter.js
@ a:/projects/temp/src/js/app.js
@ multi ./src/js/app.js
i 「wdm」: Failed to compile.
Apparently isBrowser
is false so the if
s on lines 138 and 152 go into the non-browser branch... Is this correct?
Have a nice day
Hi, I ran into a possible bug: when I try to resolve a position in a file that isn't covered by an inline source map mapping, the .resolve()
method returns an object which points to the file itself instead of its source, and doesn't signal this "resolution failure" in any way.
I forked the repo and wrote some (failing) tests that demonstrate the problem: https://github.com/corvidism/get-source/pull/1/files
The TMP
tests show this on a file where I discovered it. It's compiled from typescript, and it looks like the typescript
compiler doesn't include the leading spaces in the mappings => when I try to resolve a line from column=1
(I don't have the column number), the resolution fails.
Obviously, the ideal would be if it resolved, but it should at least warn that the resolution failed. As it is, there's no way to detect it. (That, and perhaps the sourceFile
could be set anyway? I mean, the filename is there, even if the mapping failed...)
Hi, I noticed that I seem to be unable to resolve sourcemaps in Node. Here is a full repro with repro steps.
Notice that, in my repro web app, Chrome is able to parse the stacktrace for script.min.js
(source: script.js
), so the sourcemap seems to be configured correctly:
Yet, in Node.js, when I run:
const stacktrace = "Error\n at http://localhost:3000/script.min.js:1:29"
console.log(new Stacktracey(stacktrace).withSources().asTable())
The output is:
at script.min.js:1
Note that it says script.min.js
, not script.js
.
I believe I've tracked it down to these lines of code:
Line 146 in 02d7eec
Line 169 in 02d7eec
Note that, in the browser version of the code, it does an XHR to fetch the path
– i.e. it assumes it's a URL, not a filepath. But in Node, it assumes it's a filepath. So we get a "no such file or directory" error:
It seems to me that the Node code should be making an HTTP request rather than doing fs.readFile
/ fs.readFileSync
, similar to what it does in the browser.
node version: v19.8.1
node_modules/get-source/get-source.js:146
resolve (nodeRequire ('fs').readFileSync (path, { encoding: 'utf8' }))
BECOMES
resolve (nodeRequire ('fs').readFileSync (new URL(path), { encoding: 'utf8' }))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.