Skip to content

Conversation

@GeoffreyBooth
Copy link
Collaborator

Fixes #2870. If the input is a file, not a folder; and --output is a path to a file, like dist/file.js or build.js; save as the desired output path/filename.

Examples:

coffee -co dist/testing.js test.coffee # Saves as dist/testing.js
coffee -co testing.js test.coffee      # Saves as testing.js
coffee -co dist test.coffee            # Saves as dist/test.js (same as current)
coffee -co dist src                    # Saves as dist/* (same as current)

…s a file and not a path, save as the desired filename
opts.output = path.resolve opts.output if opts.output
if opts.output
outputBasename = path.basename opts.output
if '.' in outputBasename
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about --output dir/. and --output dir/sub/..? I guess those two are supposed to mean --output dir/ and --output dir/? Also, there's --output . and --output ...

Also, a question: Is it possible to add a trailing slash to force a directory? --output dir/script.js/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was afraid of testing this, since this part of the codebase has no tests.

All those cases are ones I didn’t consider. Let me cover them . . .

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, so now if path.basename (which is everything from the last separator, / or \, to the end of the string) returns only periods, I’m just treating the output argument as a path (folder). This conforms to the old behavior, though it doesn’t seem to make much sense.

If the output argument ends in a slash, I’m forcing it to be treated as a folder name, even if it contains periods. So coffee -co scripts.js/ test.coffee will save into scripts.js/test.js.

… even if that folder name would contain a period (e.g. /scripts.js/); if output filename is only periods, treat it as a path
@GeoffreyBooth
Copy link
Collaborator Author

I wonder if we should keep this unmerged until 2.0.1, or if we’ve merged in so many bugfixes that we should release a 2.0.0-beta5. I’m eager to release 2.0.0, but I don’t want it to have too much code that hasn’t been more widely tested.

outputBasename = path.basename opts.output
if '.' in outputBasename and
not helpers.ends(opts.output, path.sep) and
not /^\.+$/.test(outputBasename) # Not `.` or `..`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Three or more dots is a valid file name, though. We should only special case . and ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You gotta be kidding me.

@lydell
Copy link
Collaborator

lydell commented Aug 24, 2017

I vote for a 2.0.0-beta5 btw.

@GeoffreyBooth
Copy link
Collaborator Author

Yeah I’m thinking that too. Might as well merge this in then 😄

@GeoffreyBooth GeoffreyBooth merged commit 3dd4582 into jashkenas:2 Aug 24, 2017
@GeoffreyBooth GeoffreyBooth deleted the output-file branch August 24, 2017 17:27
@GeoffreyBooth GeoffreyBooth mentioned this pull request Sep 2, 2017
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.

2 participants