Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Windows separator fix #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

joeyespo
Copy link

Replaced the in-place separator string with a variable that gets set similar to the way Node does it.

When upgrading Node to a version that includes this commit, the declaration of sep can easily be replaced with the following change to line 5.

{extname, join, normalize, sep} = require 'path'

@robofish
Copy link

you'd have to adjust line 118 as well:

result += JSON.stringify name.replace /\\/g,'/'

plus: one could use the normalize function to get the separator:

sep = normalize '/'

@joeyespo
Copy link
Author

@robofish Just addressed your first concern. It's now part of this pull request.

As for normalize, yeah you could do that. I personally don't know what additional implications that would have, so I played it safe and just used the same method Node uses.

@robofish
Copy link

cool :)

Yeah, I'm wasn't too sure about normalize either, but if felt somewhat right to add some abstraction there - on the other hand path separators won't be subject of frequent changes ;)

@@ -113,7 +116,7 @@ exports.Package = class Package
index = 0
for name, {filename, source} of sources
result += if index++ is 0 then "" else ", "
result += JSON.stringify name
result += if isWindows then JSON.stringify(name.replace(/\\/g, '/')) else name

Choose a reason for hiding this comment

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

uh wait - you'll need another JSON.stringify for the posix case here

Copy link
Author

Choose a reason for hiding this comment

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

Is that really what we want to do here? When on Unix, the path separators will already correctly be '/'.

Choose a reason for hiding this comment

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

yeah, but the the point of this change is windows compatability, right? ;)
and I do have first hand knowledge that the packages will have \ in their path name, while the require statements use / as path separator => require won't find the package.
my point was that your latest change removes the 'JSON.stringify' from the name (which basically just adds the quotes) in case it's an unix system. you might want to do something like JSON.stringify( if isWindows then name.replace(/\/g, '/') else name )

Copy link
Author

Choose a reason for hiding this comment

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

and I do have first hand knowledge that the packages will have \ in their path name

Ah, ok. I actually think this is a mistake.

"Windows compatibility" means you should be able to run Node on Windows, install the Stitch module, and everything should still work. It does not mean, for example, require paths should suddenly start using '' in their paths. This would tie your code to the system it's developed on, making collaboration nearly impossible. Requiring that stitch uses Unix paths parallels the uniformity of URL paths.

That said, if Node accepts both forward and back slashes for require for paths, stitch should also. Though it should accept both forms from all operating systems like Node and not show different error messages that depend on what OS Node happens to be running on.

Copy link
Author

Choose a reason for hiding this comment

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

Just updated the pull request with better path normalization. Also, both path styles can now be used in require like with Node. See 2e4e6cd.

* Paths are now properly normalized upfront so both Windows-style and Unix-style paths are supported to behave like Node's require
* Module names are now always Unix-style, even when Windows-style names are used when calling "require"
* Consequently, error messages are always shown in Unix-style, which will encourage OS-independent code
  e.g. "require('lib\\missing')" displays "'lib/missing' not found" regardless of the underlying OS
@spikebrehm
Copy link

@sstephenson do you think you'll be able to merge this in soon?

@HenrikJoreteg
Copy link

+1

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

Successfully merging this pull request may close these issues.

4 participants