Skip to content
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

Merged
merged 7 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
"webpack": "4 || 5"
},
"dependencies": {
"@cspotcode/source-map-support": "^0.8.1",
Copy link
Owner

@privatenumber privatenumber Aug 1, 2023

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 original source-map-support so I'm going to revert this.

NVM just saw the issue you linked!

"fs-require": "^1.6.0",
"memfs": "^3.5.0",
"source-map-support": "^0.5.21",
"yargs": "^16.2.0"
},
"devDependencies": {
Expand Down
77 changes: 53 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions src/lib/memfs.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
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';

export const mfs = createFsFromVolume(new Volume());

// @ts-expect-error To support Webpack 4. No longer needed in WP5
mfs.join = path.join;

let id: number;

export const mRequire = (modulePath: string): any => {

Check warning on line 13 in src/lib/memfs.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 13 in src/lib/memfs.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unexpected any. Specify a different type

Check warning on line 13 in src/lib/memfs.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected any. Specify a different type

Check warning on line 13 in src/lib/memfs.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest)

Unexpected any. Specify a different type
const require = createFsRequire(mfs, {
fs: true,
});

id = require.id;

return require(modulePath);
};

sourceMapSupport.install({
environment: 'node',
retrieveFile(filePath: string) {
const fsRequirePrefix = `fs-require://${id}/`;

if (filePath.startsWith(fsRequirePrefix)) {
filePath = filePath.slice(fsRequirePrefix.length - 1);
}

if (mfs.existsSync(filePath)) {
return mfs.readFileSync(filePath).toString();
}
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests seem to pass when removing this entire retrieveSourceMap function. Is it necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch :)
Indeed, tests are OK without it.
It might have been useful at some point in the development process but its no longer the case so it should be removed.
We can also remove direct dependency to source-map-url.

});

export const mRequire = (modulePath: string): any => (
createFsRequire(mfs, {
fs: true,
})(modulePath)
);
Loading
Loading