Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Support installed npm modules and relative require #135

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

Merged
merged 25 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use concat for paths
  • Loading branch information
jclem committed Apr 21, 2021
commit ade5cea98518854348345e2003402434d703b4ca
4 changes: 3 additions & 1 deletion 4 dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2467,7 +2467,9 @@ const wrapRequire = new Proxy(require, {
return target.apply(thisArg, [moduleID]);
}
catch (err) {
return target.resolve(moduleID, { paths: [...module.paths, process.cwd()] });
return target.resolve(moduleID, {
paths: module.paths.concat(process.cwd())
});
}
},
get: (target, prop, receiver) => {
Expand Down
4 changes: 3 additions & 1 deletion 4 src/wrap-require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const wrapRequire = new Proxy(__non_webpack_require__, {
try {
return target.apply(thisArg, [moduleID])

Choose a reason for hiding this comment

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

Concern: I feel like the order here of the try vs. catch block is backwards.

When using a require('lodash') from my github-script block now, that may end up requiring an incompatible version of the module if it exists as a dependency somewhere "near" to where the github-script code is executed rather than relying on the CWD's package.json file. 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah this is a good point. Instead, we should perhaps remove this entire try/catch construct and just do this:

const modulePath = target.resolve.apply(thisArg, [
  moduleID,
  {
    // Webpack does not have an escape hatch for getting the actual
    // module, other than `eval`.
    paths: [process.cwd(), ...eval('module').paths]
  }
])

return target.apply(thisArg, [modulePath])

Copy link
Contributor Author

@jclem jclem Apr 21, 2021

Choose a reason for hiding this comment

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

Fixing in #136

Choose a reason for hiding this comment

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

Thanks!

} catch (err) {
return target.resolve(moduleID, {paths: [...module.paths, process.cwd()]})
return target.resolve(moduleID, {
paths: module.paths.concat(process.cwd())
})
}
},

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.