Skip to content

Commit e019575

Browse files
committed
Merge pull request #3234 from marchaefner/issue3087
Fixes #3087 -- Use `fs.*Sync` for CLI compilation
2 parents efb9809 + 96ae98f commit e019575

File tree

2 files changed

+85
-79
lines changed

2 files changed

+85
-79
lines changed

lib/coffee-script/command.js

+58-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/command.coffee

+27-24
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ opts = {}
5858
sources = []
5959
sourceCode = []
6060
notSources = {}
61-
watchers = {}
6261
optionParser = null
6362

6463
# Run `coffee` by parsing passed options and determining what action to take.
@@ -89,31 +88,35 @@ exports.run = ->
8988
# is passed, recursively compile all '.coffee', '.litcoffee', and '.coffee.md'
9089
# extension source files in it and all subdirectories.
9190
compilePath = (source, topLevel, base) ->
92-
fs.stat source, (err, stats) ->
93-
throw err if err and err.code isnt 'ENOENT'
94-
if err?.code is 'ENOENT'
91+
try
92+
stats = fs.statSync source
93+
catch err
94+
if err.code is 'ENOENT'
9595
console.error "File not found: #{source}"
9696
process.exit 1
97-
if stats.isDirectory() and path.dirname(source) isnt 'node_modules'
98-
watchDir source, base if opts.watch
99-
fs.readdir source, (err, files) ->
100-
throw err if err and err.code isnt 'ENOENT'
101-
return if err?.code is 'ENOENT'
102-
index = sources.indexOf source
103-
files = files.filter (file) -> not hidden file
104-
sources[index..index] = (path.join source, file for file in files)
105-
sourceCode[index..index] = files.map -> null
106-
files.forEach (file) ->
107-
compilePath (path.join source, file), no, base
108-
else if topLevel or helpers.isCoffee source
109-
watch source, base if opts.watch
110-
fs.readFile source, (err, code) ->
111-
throw err if err and err.code isnt 'ENOENT'
112-
return if err?.code is 'ENOENT'
113-
compileScript(source, code.toString(), base)
114-
else
115-
notSources[source] = yes
116-
removeSource source, base
97+
throw err
98+
if stats.isDirectory() and path.dirname(source) isnt 'node_modules'
99+
watchDir source, base if opts.watch
100+
try
101+
files = fs.readdirSync source
102+
catch err
103+
if err.code is 'ENOENT' then return else throw err
104+
index = sources.indexOf source
105+
files = files.filter (file) -> not hidden file
106+
sources[index..index] = (path.join source, file for file in files)
107+
sourceCode[index..index] = files.map -> null
108+
files.forEach (file) ->
109+
compilePath (path.join source, file), no, base
110+
else if topLevel or helpers.isCoffee source
111+
watch source, base if opts.watch
112+
try
113+
code = fs.readFileSync source
114+
catch err
115+
if err.code is 'ENOENT' then return else throw err
116+
compileScript(source, code.toString(), base)
117+
else
118+
notSources[source] = yes
119+
removeSource source, base
117120

118121

119122
# Compile a single source script, containing the given code, according to the

0 commit comments

Comments
 (0)