-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: source maps to work correctly #51
Changes from 3 commits
28b6c1d
98e5256
2ed3438
a23245b
8b76b1a
03f293c
4a9e515
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,57 @@ | ||
import path from 'path'; | ||
import { createFsFromVolume, Volume } from 'memfs'; | ||
import { createFsRequire } from 'fs-require'; | ||
import sourceMapSupport from 'source-map-support'; | ||
import sourceMapSupport from '@cspotcode/source-map-support'; | ||
import sourceMappingURL from 'source-map-url'; | ||
|
||
export const mfs = createFsFromVolume(new Volume()); | ||
|
||
// @ts-expect-error To support Webpack 4. No longer needed in WP5 | ||
mfs.join = path.join; | ||
|
||
function removeFsRequirePrefix(filePath: string) { | ||
const fsRequirePrefix = 'fs-require://1'; | ||
|
||
if (filePath.startsWith(fsRequirePrefix)) { | ||
return filePath.slice(fsRequirePrefix.length); | ||
} | ||
|
||
return filePath; | ||
} | ||
|
||
sourceMapSupport.install({ | ||
environment: 'node', | ||
retrieveFile(filePath: string) { | ||
if (mfs.existsSync(filePath)) { | ||
return mfs.readFileSync(filePath).toString(); | ||
const filteredFilePath = removeFsRequirePrefix(filePath); | ||
|
||
if (mfs.existsSync(filteredFilePath)) { | ||
return mfs.readFileSync(filteredFilePath).toString(); | ||
} | ||
}, | ||
retrieveSourceMap(sourceFilePath: string) { | ||
const filteredSourceFilePath = removeFsRequirePrefix(sourceFilePath); | ||
|
||
if (mfs.existsSync(filteredSourceFilePath)) { | ||
const sourceFileContent = mfs.readFileSync(filteredSourceFilePath).toString(); | ||
const sourceMapFilePath = sourceMappingURL.getFrom(sourceFileContent); | ||
|
||
if (sourceMapFilePath === null) { | ||
return null; | ||
} | ||
|
||
const parentDirectory = path.dirname(filteredSourceFilePath); | ||
const sourceMapFileFullPath = `${parentDirectory}/${sourceMapFilePath}`; | ||
|
||
if (mfs.existsSync(sourceMapFileFullPath)) { | ||
return { | ||
url: sourceFilePath, | ||
map: mfs.readFileSync(sourceMapFileFullPath).toString(), | ||
}; | ||
} | ||
} | ||
|
||
return null; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests seem to pass when removing this entire There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch :) |
||
}); | ||
|
||
export const mRequire = (modulePath: string): any => ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear to me how this fork is different from the originalsource-map-support
so I'm going to revert this.NVM just saw the issue you linked!