mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge pull request #2869 from marchaefner/master
Fix Windows path separator issue in `baseFileName`.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.6.2
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, exists, forkNode, fs, helpers, hidden, joinTimeout, lint, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, useWinPathSep, version, wait, watch, watchDir, watchers, writeJs, _ref;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
exists = fs.exists || path.exists;
|
||||
|
||||
useWinPathSep = path.sep === '\\';
|
||||
|
||||
helpers.extend(CoffeeScript, new EventEmitter);
|
||||
|
||||
printLine = function(line) {
|
||||
@@ -387,7 +389,7 @@
|
||||
if (extension == null) {
|
||||
extension = ".js";
|
||||
}
|
||||
basename = helpers.baseFileName(source, true, path.sep);
|
||||
basename = helpers.baseFileName(source, true, useWinPathSep);
|
||||
srcDir = path.dirname(source);
|
||||
baseDir = base === '.' ? srcDir : srcDir.substring(base.length);
|
||||
dir = opts.output ? path.join(opts.output, baseDir) : srcDir;
|
||||
@@ -407,7 +409,7 @@
|
||||
js = ' ';
|
||||
}
|
||||
if (generatedSourceMap) {
|
||||
js = "" + js + "\n/*\n//@ sourceMappingURL=" + (helpers.baseFileName(sourceMapPath, false, path.sep)) + "\n*/\n";
|
||||
js = "" + js + "\n/*\n//@ sourceMappingURL=" + (helpers.baseFileName(sourceMapPath, false, useWinPathSep)) + "\n*/\n";
|
||||
}
|
||||
fs.writeFile(jsPath, js, function(err) {
|
||||
if (err) {
|
||||
@@ -503,13 +505,13 @@
|
||||
jsPath: jsPath,
|
||||
sourceRoot: path.relative(jsDir, cwd),
|
||||
sourceFiles: [path.relative(cwd, filename)],
|
||||
generatedFile: helpers.baseFileName(jsPath, false, path.sep)
|
||||
generatedFile: helpers.baseFileName(jsPath, false, useWinPathSep)
|
||||
});
|
||||
} else {
|
||||
answer = helpers.merge(answer, {
|
||||
sourceRoot: "",
|
||||
sourceFiles: [helpers.baseFileName(filename, false, path.sep)],
|
||||
generatedFile: helpers.baseFileName(filename, true, path.sep) + ".js"
|
||||
sourceFiles: [helpers.baseFileName(filename, false, useWinPathSep)],
|
||||
generatedFile: helpers.baseFileName(filename, true, useWinPathSep) + ".js"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,14 +156,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
exports.baseFileName = function(file, stripExt, pathSep) {
|
||||
var parts;
|
||||
exports.baseFileName = function(file, stripExt, useWinPathSep) {
|
||||
var parts, pathSep;
|
||||
if (stripExt == null) {
|
||||
stripExt = false;
|
||||
}
|
||||
if (pathSep == null) {
|
||||
pathSep = '/';
|
||||
if (useWinPathSep == null) {
|
||||
useWinPathSep = false;
|
||||
}
|
||||
pathSep = useWinPathSep ? /\\|\// : /\//;
|
||||
parts = file.split(pathSep);
|
||||
file = parts[parts.length - 1];
|
||||
if (!stripExt) {
|
||||
|
||||
@@ -14,6 +14,7 @@ CoffeeScript = require './coffee-script'
|
||||
{EventEmitter} = require 'events'
|
||||
|
||||
exists = fs.exists or path.exists
|
||||
useWinPathSep = path.sep is '\\'
|
||||
|
||||
# Allow CoffeeScript to emit Node.js events.
|
||||
helpers.extend CoffeeScript, new EventEmitter
|
||||
@@ -256,7 +257,7 @@ removeSource = (source, base, removeJs) ->
|
||||
|
||||
# Get the corresponding output JavaScript path for a source file.
|
||||
outputPath = (source, base, extension=".js") ->
|
||||
basename = helpers.baseFileName source, yes, path.sep
|
||||
basename = helpers.baseFileName source, yes, useWinPathSep
|
||||
srcDir = path.dirname source
|
||||
baseDir = if base is '.' then srcDir else srcDir.substring base.length
|
||||
dir = if opts.output then path.join opts.output, baseDir else srcDir
|
||||
@@ -274,7 +275,7 @@ writeJs = (base, sourcePath, js, jsPath, generatedSourceMap = null) ->
|
||||
compile = ->
|
||||
if opts.compile
|
||||
js = ' ' if js.length <= 0
|
||||
if generatedSourceMap then js = "#{js}\n/*\n//@ sourceMappingURL=#{helpers.baseFileName sourceMapPath, no, path.sep}\n*/\n"
|
||||
if generatedSourceMap then js = "#{js}\n/*\n//@ sourceMappingURL=#{helpers.baseFileName sourceMapPath, no, useWinPathSep}\n*/\n"
|
||||
fs.writeFile jsPath, js, (err) ->
|
||||
if err
|
||||
printLine err.message
|
||||
@@ -343,13 +344,13 @@ compileOptions = (filename, base) ->
|
||||
jsPath
|
||||
sourceRoot: path.relative jsDir, cwd
|
||||
sourceFiles: [path.relative cwd, filename]
|
||||
generatedFile: helpers.baseFileName(jsPath, no, path.sep)
|
||||
generatedFile: helpers.baseFileName(jsPath, no, useWinPathSep)
|
||||
}
|
||||
else
|
||||
answer = helpers.merge answer,
|
||||
sourceRoot: ""
|
||||
sourceFiles: [helpers.baseFileName filename, no, path.sep]
|
||||
generatedFile: helpers.baseFileName(filename, yes, path.sep) + ".js"
|
||||
sourceFiles: [helpers.baseFileName filename, no, useWinPathSep]
|
||||
generatedFile: helpers.baseFileName(filename, yes, useWinPathSep) + ".js"
|
||||
answer
|
||||
|
||||
# Start up a new Node.js instance with the arguments in `--nodejs` passed to
|
||||
|
||||
@@ -118,7 +118,8 @@ exports.locationDataToString = (obj) ->
|
||||
"No location data"
|
||||
|
||||
# A `.coffee.md` compatible version of `basename`, that returns the file sans-extension.
|
||||
exports.baseFileName = (file, stripExt = no, pathSep = '/') ->
|
||||
exports.baseFileName = (file, stripExt = no, useWinPathSep = no) ->
|
||||
pathSep = if useWinPathSep then /\\|\// else /\//
|
||||
parts = file.split(pathSep)
|
||||
file = parts[parts.length - 1]
|
||||
return file unless stripExt
|
||||
|
||||
Reference in New Issue
Block a user