From 6a04067a76d4635875b85598394fb92b5eefd712 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 27 Feb 2016 20:19:12 +0100 Subject: [PATCH] bin/pegjs: Do not overwrite extension-less files Running bin/pegjs with one argument which was an extension-less file name caused the file to be overwritten. This was because internal extension rewriting logic didn't handle this case corectly. This commit changes the logic from regexp-based to path.extname-based, fixing the problem. The new code generates file names like this: Input file name Output file name ------------------------------------ grammar.ext grammar.js grammar.ext1.ext2 grammar.ext1.js grammar. grammar.js grammar grammar.js Fixes #405. --- bin/pegjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/pegjs b/bin/pegjs index 57d2b76..f2f4799 100755 --- a/bin/pegjs +++ b/bin/pegjs @@ -240,7 +240,7 @@ switch (args.length) { }); var outputFile = args.length === 1 - ? args[0].replace(/\.[^.]*$/, ".js") + ? args[0].substr(0, args[0].length - path.extname(args[0]).length) + ".js" : args[1]; outputStream = fs.createWriteStream(outputFile); outputStream.on("error", function() {