mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Fixing bug that was causing file deletes to be ignored, debouncing compileJoin
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(function() {
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, usage, version, watch, watchDir, watchers, writeJs, _ref;
|
||||
var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, helpers, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, watch, watchDir, watchers, writeJs, _ref;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
@@ -168,12 +168,17 @@
|
||||
});
|
||||
};
|
||||
|
||||
joinTimeout = null;
|
||||
|
||||
compileJoin = function() {
|
||||
if (!opts.join) return;
|
||||
if (!sourceCode.some(function(code) {
|
||||
return code === null;
|
||||
})) {
|
||||
return compileScript(opts.join, sourceCode.join('\n'), opts.join);
|
||||
clearTimeout(joinTimeout);
|
||||
return joinTimeout = setTimeout(function() {
|
||||
return compileScript(opts.join, sourceCode.join('\n'), opts.join);
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -195,7 +200,7 @@
|
||||
compileTimeout = null;
|
||||
watchErr = function(e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
if (sources.indexOf(source === -1)) return;
|
||||
if (sources.indexOf(source) === -1) return;
|
||||
removeSource(source, base, true);
|
||||
return compileJoin();
|
||||
} else {
|
||||
@@ -240,45 +245,25 @@
|
||||
};
|
||||
|
||||
watchDir = function(source, base) {
|
||||
var watcher;
|
||||
var readdirTimeout, watcher;
|
||||
readdirTimeout = null;
|
||||
try {
|
||||
return watcher = fs.watch(source, function() {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, i, prevSources, toRemove, _i, _j, _len, _len2, _results;
|
||||
if (err) {
|
||||
if (err.code !== 'ENOENT') throw err;
|
||||
prevSources = sources.slice();
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) _results.push(file);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
clearTimeout(readdirTimeout);
|
||||
return readdirTimeout = setTimeout(function() {
|
||||
return fs.readdir(source, function(err, files) {
|
||||
var file, _i, _len, _results;
|
||||
if (err) {
|
||||
if (err.code !== 'ENOENT') throw err;
|
||||
watcher.close();
|
||||
return unwatchDir(source, base);
|
||||
}
|
||||
if ((function() {
|
||||
var _ref2, _results;
|
||||
_results = [];
|
||||
for (i = 0, _ref2 = sources.length; 0 <= _ref2 ? i < _ref2 : i > _ref2; 0 <= _ref2 ? i++ : i--) {
|
||||
_results.push(sources[i] === prevSources[i]);
|
||||
}
|
||||
return _results;
|
||||
})()) {
|
||||
return;
|
||||
}
|
||||
return compileJoin();
|
||||
} else {
|
||||
files = files.map(function(file) {
|
||||
return path.join(source, file);
|
||||
});
|
||||
_results = [];
|
||||
for (_j = 0, _len2 = files.length; _j < _len2; _j++) {
|
||||
file = files[_j];
|
||||
for (_i = 0, _len = files.length; _i < _len; _i++) {
|
||||
file = files[_i];
|
||||
if (!(!notSources[file])) continue;
|
||||
if (sources.some(function(s) {
|
||||
return s.indexOf(file) >= 0;
|
||||
@@ -290,14 +275,43 @@
|
||||
_results.push(compilePath(file, false, base));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 25);
|
||||
});
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') throw e;
|
||||
}
|
||||
};
|
||||
|
||||
unwatchDir = function(source, base) {
|
||||
var file, i, prevSources, toRemove, _i, _len;
|
||||
prevSources = sources.slice();
|
||||
toRemove = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = sources.length; _i < _len; _i++) {
|
||||
file = sources[_i];
|
||||
if (file.indexOf(source) >= 0) _results.push(file);
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
for (_i = 0, _len = toRemove.length; _i < _len; _i++) {
|
||||
file = toRemove[_i];
|
||||
removeSource(file, base, true);
|
||||
}
|
||||
if ((function() {
|
||||
var _ref2, _results;
|
||||
_results = [];
|
||||
for (i = 0, _ref2 = sources.length; 0 <= _ref2 ? i < _ref2 : i > _ref2; 0 <= _ref2 ? i++ : i--) {
|
||||
_results.push(sources[i] === prevSources[i]);
|
||||
}
|
||||
return _results;
|
||||
})()) {
|
||||
return;
|
||||
}
|
||||
return compileJoin();
|
||||
};
|
||||
|
||||
removeSource = function(source, base, removeJs) {
|
||||
var index, jsPath;
|
||||
index = sources.indexOf(source);
|
||||
|
||||
@@ -152,10 +152,14 @@ compileStdio = ->
|
||||
|
||||
# If all of the source files are done being read, concatenate and compile
|
||||
# them together.
|
||||
joinTimeout = null
|
||||
compileJoin = ->
|
||||
return unless opts.join
|
||||
unless sourceCode.some((code) -> code is null)
|
||||
compileScript opts.join, sourceCode.join('\n'), opts.join
|
||||
clearTimeout joinTimeout
|
||||
joinTimeout = setTimeout ->
|
||||
compileScript opts.join, sourceCode.join('\n'), opts.join
|
||||
, 100
|
||||
|
||||
# Load files that are to-be-required before compilation occurs.
|
||||
loadRequires = ->
|
||||
@@ -174,7 +178,7 @@ watch = (source, base) ->
|
||||
|
||||
watchErr = (e) ->
|
||||
if e.code is 'ENOENT'
|
||||
return if sources.indexOf source is -1
|
||||
return if sources.indexOf(source) is -1
|
||||
removeSource source, base, yes
|
||||
compileJoin()
|
||||
else throw e
|
||||
@@ -209,26 +213,33 @@ watch = (source, base) ->
|
||||
|
||||
# Watch a directory of files for new additions.
|
||||
watchDir = (source, base) ->
|
||||
readdirTimeout = null
|
||||
try
|
||||
watcher = fs.watch source, ->
|
||||
fs.readdir source, (err, files) ->
|
||||
if err
|
||||
throw err unless err.code is 'ENOENT'
|
||||
prevSources = sources.slice()
|
||||
toRemove = (file for file in sources when file.indexOf(source) >= 0)
|
||||
removeSource file, base, yes for file in toRemove
|
||||
return if sources[i] is prevSources[i] for i in [0...sources.length]
|
||||
compileJoin()
|
||||
else
|
||||
clearTimeout readdirTimeout
|
||||
readdirTimeout = setTimeout ->
|
||||
fs.readdir source, (err, files) ->
|
||||
if err
|
||||
throw err unless err.code is 'ENOENT'
|
||||
watcher.close()
|
||||
return unwatchDir source, base
|
||||
files = files.map (file) -> path.join source, file
|
||||
for file in files when not notSources[file]
|
||||
continue if sources.some (s) -> s.indexOf(file) >= 0
|
||||
sources.push file
|
||||
sourceCode.push null
|
||||
compilePath file, no, base
|
||||
, 25
|
||||
catch e
|
||||
throw e unless e.code is 'ENOENT'
|
||||
|
||||
unwatchDir = (source, base) ->
|
||||
prevSources = sources.slice()
|
||||
toRemove = (file for file in sources when file.indexOf(source) >= 0)
|
||||
removeSource file, base, yes for file in toRemove
|
||||
return if sources[i] is prevSources[i] for i in [0...sources.length]
|
||||
compileJoin()
|
||||
|
||||
# Remove a file from our source list, and source code cache. Optionally remove
|
||||
# the compiled JS version as well.
|
||||
removeSource = (source, base, removeJs) ->
|
||||
|
||||
Reference in New Issue
Block a user