clang-format
Advanced tools
Comparing version 1.0.0 to 1.0.1
#! /usr/bin/env node | ||
// polyfill for node < 0.12 | ||
var spawnSync = require('spawn-sync'); | ||
var os = require('os'); | ||
var fs = require('fs'); | ||
var clangFormat = require('../index').spawnClangFormat; | ||
var nativeBinary = __dirname + '/' + os.platform() + "_" + os.arch() + '/clang-format'; | ||
if (!fs.existsSync(nativeBinary)) { | ||
process.stdout.write("FATAL: This module doesn't bundle the clang-format executable for your platform. "); | ||
process.stdout.write("(" + os.platform() + "_" + os.arch() + ")\n"); | ||
process.stdout.write("Consider installing it with your native package manager instead.\n"); | ||
process.exit(1); | ||
try { | ||
clangFormat(process.argv.slice(2), process.exit, 'inherit'); | ||
} catch (e) { | ||
process.stdout.write(e.message); | ||
process.exit(1); | ||
} | ||
var result = spawnSync(nativeBinary, process.argv.slice(2)); | ||
process.stderr.write(result.stderr); | ||
// Note, status code will always equal 0 if using busy waiting fallback | ||
if (result.status !== 0) { | ||
process.exit(result.status); | ||
} else { | ||
process.stdout.write(result.stdout); | ||
} |
41
index.js
var spawn = require('child_process').spawn; | ||
var os = require('os'); | ||
var fs = require('fs'); | ||
@@ -12,20 +13,32 @@ /** | ||
*/ | ||
function spawnClangFormat(file, enc, style, done) { | ||
var child_process = | ||
spawn('bin/' + os.platform() + "_" + os.arch() + '/clang-format', | ||
['-style=' + style, file.path], { | ||
stdio: ['ignore', 'pipe', process.stderr], | ||
cwd: __dirname, | ||
encoding: enc | ||
}); | ||
function clangFormat(file, enc, style, done) { | ||
return spawnClangFormat(['-style=' + style, file.path], done, | ||
['ignore', 'pipe', process.stderr]) | ||
.stdout; | ||
} | ||
child_process.on('close', function(code) { | ||
if (code) { | ||
done(code); | ||
/** | ||
* Spawn the clang-format binary with given arguments | ||
*/ | ||
function spawnClangFormat(args, done, stdio) { | ||
var nativeBinary = __dirname + '/bin/' + os.platform() + "_" + os.arch() + '/clang-format'; | ||
if (!fs.existsSync(nativeBinary)) { | ||
message = "FATAL: This module doesn't bundle the clang-format executable for your platform. " + | ||
"(" + os.platform() + "_" + os.arch() + ")\n" + | ||
"Consider installing it with your native package manager instead.\n"; | ||
throw new Error(message); | ||
} | ||
var child_process = spawn(nativeBinary, args, { | ||
stdio: stdio, | ||
cwd: __dirname, | ||
}); | ||
child_process.on('close', function(exit) { | ||
if (exit) { | ||
done(exit); | ||
} | ||
}); | ||
return child_process.stdout; | ||
return child_process; | ||
} | ||
module.exports = spawnClangFormat; | ||
module.exports = clangFormat; | ||
module.exports.spawnClangFormat = spawnClangFormat; |
{ | ||
"name": "clang-format", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "node wrapper around clang-format", | ||
@@ -10,3 +10,2 @@ "repository": { | ||
"main": "index.js", | ||
"preferGlobal": "true", | ||
"bin": { | ||
@@ -16,6 +15,3 @@ "clang-format": "bin/wrapper.js" | ||
"author": "Alex Eagle <alexeagle@google.com>", | ||
"license": "Apache 2", | ||
"dependencies": { | ||
"spawn-sync": "^1.0.5" | ||
} | ||
"license": "Apache 2" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
0
48
1
1441152
- Removedspawn-sync@^1.0.5
- Removedbuffer-from@1.1.2(transitive)
- Removedconcat-stream@1.6.2(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedos-shim@0.1.3(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedspawn-sync@1.0.15(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtypedarray@0.0.6(transitive)
- Removedutil-deprecate@1.0.2(transitive)