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

windows pathing fix #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

windows pathing fix #53

wants to merge 2 commits into from

Conversation

rokku-x
Copy link

@rokku-x rokku-x commented Dec 7, 2021

import will not universally work on all node.js use-cases like pkg for example. I made fix to handover the module loading to require in node.js for better compatibility.

when removing the 'file://' from path, in windows, it will leave a leading '/' in the path that will make the worker module loading fail.

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

Please add unit tests to cover new and changed code.

@@ -18,6 +18,14 @@ const data = Buffer.from(dataBuf)
async function start () {
let fn
try {
if(typeof process !== "undefined"){
Copy link
Member

Choose a reason for hiding this comment

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

Please apply the linting standard of the project. npm test will report an error here.

@@ -18,6 +18,14 @@ const data = Buffer.from(dataBuf)
async function start () {
let fn
try {
if(typeof process !== "undefined"){
//reused the error code.
Copy link
Member

Choose a reason for hiding this comment

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

What is this comment referencing?

@@ -18,6 +18,14 @@ const data = Buffer.from(dataBuf)
async function start () {
let fn
try {
if(typeof process !== "undefined"){
//reused the error code.
const err = new Error()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const err = new Error()
const err = Error()

Also, an appropriate message should be passed to the constructor.

if(typeof process !== "undefined"){
//reused the error code.
const err = new Error()
err.code = 'ERR_MODULE_NOT_FOUND';
Copy link
Member

Choose a reason for hiding this comment

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

This code does not seem appropriate for the condition.

Comment on lines +27 to +28
//this will not universally work on all node.js instances and use-cases.
//better to hand it over to require when using node.js
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this comment.

Copy link
Author

Choose a reason for hiding this comment

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

This is for pkg incompatibility.

@@ -30,7 +38,7 @@ async function start () {
// The error codes may change based on the node.js version (ENOTDIR > 12, ERR_MODULE_NOT_FOUND <= 12 )
if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND') &&
workerData.filename.startsWith('file://')) {
fn = realRequire(workerData.filename.replace('file://', ''))
fn = realRequire(workerData.filename.replace(workerData.filename[9] === ":" ? 'file:///' : 'file://', ''))
Copy link
Member

Choose a reason for hiding this comment

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

This seems very fragile. I think the new code is looking for file://c:/foo/bar. But there is no guarantee the provided path will be absolute. I think a proper process.platform check should be used instead.

Copy link
Author

Choose a reason for hiding this comment

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

I agree this is fragile. I agree to use process.platform

The old code removes the file:// from the path. in unix systems. file:///example/ex.js will be : /example/ex.js. But in windows file:///C:/example/ex.js will be : /C:/example.js and this will make the module loading fail to resolve the file.

@mcollina
Copy link
Member

mcollina commented Dec 7, 2021

@simoneb could you check this on Windows?

@simoneb
Copy link

simoneb commented Dec 8, 2021

@simoneb could you check this on Windows?

happy to check once there's a proper implementation and tests in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants