Skip to content
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 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 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])
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown

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