Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

neon-cli

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neon-cli - npm Package Compare versions

Comparing version 0.1.14 to 0.1.15

lib/artifacts.js

121

lib/cli.js

@@ -23,2 +23,6 @@ 'use strict';

var _neon_clean = require('./ops/neon_clean');
var _neon_clean2 = _interopRequireDefault(_neon_clean);
var _style = require('./ops/style');

@@ -40,2 +44,6 @@

var _log = require('./log');
var _log2 = _interopRequireDefault(_log);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

@@ -54,2 +62,9 @@

function profile(value) {
if (!['debug', 'release', 'all'].indexOf(value) > -1) {
throw new Error("Expected one of 'debug', 'release', or 'all', got '" + value + "'");
}
return value;
}
function commandUsage(command) {

@@ -65,2 +80,17 @@ if (!spec[command]) {

function logIf(multiple, action, cwd, module) {
if (multiple) {
(0, _log2.default)(action + " Neon package at " + (_path2.default.relative(cwd, module) || "."));
}
}
function parseModules(cwd, names, paths) {
let modules = names ? names.map(m => paths ? _path2.default.resolve(cwd, m) : _path2.default.resolve(cwd, 'node_modules', m)) : [cwd];
return {
modules: modules,
multiple: modules.length > 1
};
}
const spec = {

@@ -78,3 +108,3 @@

header: "Command List",
content: [{ name: "new", summary: "Create a new Neon project." }, { name: "build", summary: "(Re)build a Neon project." }, { name: "version", summary: "Display the Neon version." }, { name: "help", summary: "Display help information about Neon." }]
content: [{ name: "new", summary: "Create a new Neon project." }, { name: "build", summary: "(Re)build a Neon project." }, { name: "clean", summary: "Remove build artifacts from a Neon project." }, { name: "version", summary: "Display the Neon version." }, { name: "help", summary: "Display help information about Neon." }]
}],

@@ -113,3 +143,3 @@ action: function action(options, usage) {

new: {
args: [{ name: "rust", alias: "r", type: channel, defaultValue: "default" }, { name: "name", type: String, defaultOption: true }, { name: "help", alias: "h", type: Boolean }],
args: [{ name: "name", type: String, defaultOption: true }, { name: "help", alias: "h", type: Boolean }],
usage: [{

@@ -120,11 +150,3 @@ header: "neon new",

header: "Synopsis",
content: "$ neon new [options] [@<scope>/]<name>"
}, {
header: "Options",
optionList: [{
name: "rust",
alias: "r",
type: channel,
description: "Rust channel (default, nightly, beta, or stable). [default: default]"
}]
content: "$ neon new [@<scope>/]<name>"
}],

@@ -137,3 +159,3 @@ action: function action(options) {

return (0, _neon_new2.default)(this.cwd, options.name, options.rust);
return (0, _neon_new2.default)(this.cwd, options.name);
}

@@ -171,4 +193,2 @@ },

var _ref = _asyncToGenerator(function* (options) {
var _this = this;
if (options.help) {

@@ -179,14 +199,12 @@ commandUsage('build');

let modules = options.modules ? options.modules.map(function (m) {
return options.path ? _path2.default.resolve(_this.cwd, m) : _path2.default.resolve(_this.cwd, 'node_modules', m);
}) : [this.cwd];
var _parseModules = parseModules(this.cwd, options.modules, options.path);
let info = modules.length > 1;
let modules = _parseModules.modules,
multiple = _parseModules.multiple;
for (let mod of modules) {
if (info) {
console.log(style.info("building Neon package at " + (_path2.default.relative(this.cwd, mod) || ".")));
}
yield (0, _neon_build2.default)(mod, options.rust, options.debug ? 'debug' : 'release', options.node_module_version);
for (let module of modules) {
logIf(multiple, "building", this.cwd, module);
yield (0, _neon_build2.default)(module, options.rust, !options.debug, options.node_module_version);
}

@@ -203,2 +221,47 @@ });

clean: {
args: [{ name: "path", alias: "p", type: Boolean }, { name: "modules", type: String, multiple: true, defaultOption: true }, { name: "help", alias: "h", type: Boolean }],
usage: [{
header: "neon clean",
content: "Remove build artifacts from a Neon project."
}, {
header: "Synopsis",
content: ["$ neon clean [options]", "$ neon clean [options] [underline]{module} ..."]
}, {
header: "Options",
optionList: [{
name: "path",
alias: "p",
type: Boolean,
description: "Specify modules by path instead of name."
}]
}],
action: (() => {
var _ref2 = _asyncToGenerator(function* (options) {
if (options.help) {
commandUsage('clean');
return;
}
var _parseModules2 = parseModules(this.cwd, options.modules, options.path);
let modules = _parseModules2.modules,
multiple = _parseModules2.multiple;
for (let module of modules) {
logIf(multiple, "cleaning", this.cwd, module);
yield (0, _neon_clean2.default)(module);
}
});
function action(_x2) {
return _ref2.apply(this, arguments);
}
return action;
})()
},
version: {

@@ -232,7 +295,11 @@ args: [{ name: "help", alias: "h", type: Boolean }],

exec() {
var _this2 = this;
var _this = this;
return _asyncToGenerator(function* () {
(0, _log.setup)(function (msg) {
console.log(style.info(msg));
});
try {
var _parseCommands = (0, _commandLineCommands2.default)([null, 'help', 'new', 'build', 'version'], _this2.argv);
var _parseCommands = (0, _commandLineCommands2.default)([null, 'help', 'new', 'build', 'clean', 'version'], _this.argv);

@@ -243,5 +310,5 @@ let command = _parseCommands.command,

yield spec[command].action.call(_this2, (0, _commandLineArgs2.default)(spec[command].args, { argv: argv }), (0, _commandLineUsage2.default)(spec[command].usage));
yield spec[command].action.call(_this, (0, _commandLineArgs2.default)(spec[command].args, { argv: argv }), (0, _commandLineUsage2.default)(spec[command].usage));
} catch (e) {
spec.help.action.call(_this2);
spec.help.action.call(_this);

@@ -248,0 +315,0 @@ switch (e.name) {

@@ -7,50 +7,6 @@ 'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _project = require('../project');
let main = (() => {
var _ref3 = _asyncToGenerator(function* (root, name, configuration, target) {
let pp = process.platform;
let output_directory = target ? _path2.default.resolve(root, 'native', 'target', target, configuration) : _path2.default.resolve(root, 'native', 'target', configuration);
let dylib = _path2.default.resolve(output_directory, LIB_PREFIX[pp] + name + LIB_SUFFIX[pp]);
let index = _path2.default.resolve(root, 'native', 'index.node');
var _project2 = _interopRequireDefault(_project);
console.log(style.info("generating native" + _path2.default.sep + "index.node"));
yield (0, _fs.remove)(index);
yield (0, _fs.copy)(dylib, index);
});
return function main(_x, _x2, _x3, _x4) {
return _ref3.apply(this, arguments);
};
})();
var _fs = require('../async/fs');
var _child_process = require('../async/child_process');
var _path = require('path');
var _path2 = _interopRequireDefault(_path);
var _handlebars = require('handlebars');
var _handlebars2 = _interopRequireDefault(_handlebars);
var _style = require('./style');
var style = _interopRequireWildcard(_style);
var _fsExtra = require('fs-extra');
var _toml = require('toml');
var _toml2 = _interopRequireDefault(_toml);
var _shallowCopy = require('shallow-copy');
var _shallowCopy2 = _interopRequireDefault(_shallowCopy);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -60,80 +16,10 @@

const TEMPLATES_DIR = _path2.default.resolve(__dirname, '..', 'templates');
const LIB_PREFIX = {
'darwin': "lib",
'freebsd': "lib",
'linux': "lib",
'sunos': "lib",
'win32': ""
};
const LIB_SUFFIX = {
'darwin': ".dylib",
'freebsd': ".so",
'linux': ".so",
'sunos': ".so",
'win32': ".dll"
};
function explicit_cargo_target() {
if (process.platform === 'win32') {
let arch = process.env.npm_config_arch || process.arch;
if (arch === 'ia32') {
return 'i686-pc-windows-msvc';
} else {
return 'x86_64-pc-windows-msvc';
}
}
}
function cargo(root, toolchain, configuration, nodeModuleVersion, target) {
let macos = process.platform === 'darwin';
var _ref = toolchain === 'default' ? ["cargo", []] : ["multirust", ["run", toolchain]],
_ref2 = _slicedToArray(_ref, 2);
let command = _ref2[0],
prefix = _ref2[1];
let args = prefix.concat(macos ? 'rustc' : 'build', configuration === 'release' ? ["--release"] : [], macos ? ["--", "-C", "link-args=-Wl,-undefined,dynamic_lookup"] : []);
// Pass the Node modules ABI version to the build as an environment variable.
let env = (0, _shallowCopy2.default)(process.env);
env.NEON_NODE_ABI = nodeModuleVersion || process.versions.modules;
if (target) {
args.push("--target=" + target);
}
console.log(style.info([command].concat(args).join(" ")));
return (0, _child_process.spawn)(command, args, { cwd: _path2.default.resolve(root, 'native'), stdio: 'inherit', env: env });
}
exports.default = (() => {
var _ref4 = _asyncToGenerator(function* (root, toolchain, configuration, nodeModuleVersion) {
// 1. Read the Cargo metadata.
let metadata = _toml2.default.parse((yield (0, _fs.readFile)(_path2.default.resolve(root, 'native', 'Cargo.toml'), 'utf8')));
if (!metadata.lib.name) {
throw new Error("Cargo.toml does not contain a [lib] section with a 'name' field");
}
let target = explicit_cargo_target();
console.log(style.info("running cargo"));
// 2. Build the binary.
if ((yield cargo(root, toolchain, configuration, nodeModuleVersion, target)) !== 0) {
throw new Error("cargo build failed");
}
// 3. Copy the dylib into the main index.node file.
yield main(root, metadata.lib.name, configuration, target);
var _ref = _asyncToGenerator(function* (root, toolchain, release, abi) {
let project = new _project2.default(root);
yield project.build(toolchain, release, abi);
});
function neon_build(_x5, _x6, _x7, _x8) {
return _ref4.apply(this, arguments);
function neon_build(_x, _x2, _x3, _x4) {
return _ref.apply(this, arguments);
}

@@ -140,0 +26,0 @@

@@ -98,3 +98,3 @@ 'use strict';

exports.default = (() => {
var _ref4 = _asyncToGenerator(function* (pwd, name, toolchain) {
var _ref4 = _asyncToGenerator(function* (pwd, name) {
let its = (0, _validateNpmPackageName2.default)(name);

@@ -168,7 +168,2 @@ if (!its.validForNewPackages) {

patch: _semver2.default.patch(version)
},
build: {
cargo: {
cmd: toolchain === 'default' ? [] : ["multirust", "run", toolchain]
}
}

@@ -208,3 +203,3 @@ };

function wizard(_x2, _x3, _x4) {
function wizard(_x2, _x3) {
return _ref4.apply(this, arguments);

@@ -211,0 +206,0 @@ }

{
"name": "neon-cli",
"version": "0.1.14",
"version": "0.1.15",
"description": "Build and load native Rust/Neon modules.",

@@ -5,0 +5,0 @@ "author": "Dave Herman <dherman@mozilla.com>",

@@ -0,1 +1,5 @@

# Version 0.1.15
* Better support for Electron via the artifacts file (#52).
# Version 0.1.14

@@ -2,0 +6,0 @@

@@ -5,2 +5,3 @@ import path from 'path';

import neon_build from './ops/neon_build';
import neon_clean from './ops/neon_clean';
import * as style from './ops/style';

@@ -10,2 +11,4 @@ import parseCommands from 'command-line-commands';

import parseUsage from 'command-line-usage';
import log from './log';
import { setup as setupLogging } from './log';

@@ -19,2 +22,9 @@ function channel(value) {

function profile(value) {
if (!['debug', 'release', 'all'].indexOf(value) > -1) {
throw new Error("Expected one of 'debug', 'release', or 'all', got '" + value + "'");
}
return value;
}
function commandUsage(command) {

@@ -30,2 +40,20 @@ if (!spec[command]) {

function logIf(multiple, action, cwd, module) {
if (multiple) {
log(action + " Neon package at " + (path.relative(cwd, module) || "."));
}
}
function parseModules(cwd, names, paths) {
let modules = names
? names.map(m => paths ? path.resolve(cwd, m)
: path.resolve(cwd, 'node_modules', m))
: [cwd];
return {
modules,
multiple: modules.length > 1
};
}
const spec = {

@@ -46,2 +74,3 @@

{ name: "build", summary: "(Re)build a Neon project." },
{ name: "clean", summary: "Remove build artifacts from a Neon project." },
{ name: "version", summary: "Display the Neon version." },

@@ -83,4 +112,3 @@ { name: "help", summary: "Display help information about Neon." }]

new: {
args: [{ name: "rust", alias: "r", type: channel, defaultValue: "default" },
{ name: "name", type: String, defaultOption: true },
args: [{ name: "name", type: String, defaultOption: true },
{ name: "help", alias: "h", type: Boolean }],

@@ -92,11 +120,3 @@ usage: [{

header: "Synopsis",
content: "$ neon new [options] [@<scope>/]<name>"
}, {
header: "Options",
optionList: [{
name: "rust",
alias: "r",
type: channel,
description: "Rust channel (default, nightly, beta, or stable). [default: default]"
}]
content: "$ neon new [@<scope>/]<name>"
}],

@@ -109,3 +129,3 @@ action: function(options) {

return neon_new(this.cwd, options.name, options.rust);
return neon_new(this.cwd, options.name);
}

@@ -153,16 +173,45 @@ },

let modules = options.modules
? options.modules.map(m => options.path ? path.resolve(this.cwd, m)
: path.resolve(this.cwd, 'node_modules', m))
: [this.cwd];
let { modules, multiple } = parseModules(this.cwd, options.modules, options.path);
let info = modules.length > 1;
for (let module of modules) {
logIf(multiple, "building", this.cwd, module);
for (let mod of modules) {
if (info) {
console.log(style.info("building Neon package at " + (path.relative(this.cwd, mod) || ".")));
}
await neon_build(module, options.rust, !options.debug, options.node_module_version);
}
}
},
await neon_build(mod, options.rust, options.debug ? 'debug' : 'release', options.node_module_version);
clean: {
args: [{ name: "path", alias: "p", type: Boolean },
{ name: "modules", type: String, multiple: true, defaultOption: true },
{ name: "help", alias: "h", type: Boolean }],
usage: [{
header: "neon clean",
content: "Remove build artifacts from a Neon project."
}, {
header: "Synopsis",
content: ["$ neon clean [options]",
"$ neon clean [options] [underline]{module} ..."]
}, {
header: "Options",
optionList: [{
name: "path",
alias: "p",
type: Boolean,
description: "Specify modules by path instead of name."
}]
}],
action: async function(options) {
if (options.help) {
commandUsage('clean');
return;
}
let { modules, multiple } = parseModules(this.cwd, options.modules, options.path);
for (let module of modules) {
logIf(multiple, "cleaning", this.cwd, module);
await neon_clean(module);
}
}

@@ -199,4 +248,6 @@ },

async exec() {
setupLogging(msg => { console.log(style.info(msg)); });
try {
let { command, argv } = parseCommands([ null, 'help', 'new', 'build', 'version' ], this.argv);
let { command, argv } = parseCommands([ null, 'help', 'new', 'build', 'clean', 'version' ], this.argv);

@@ -203,0 +254,0 @@ await spec[command].action.call(this,

@@ -1,96 +0,6 @@

import { remove, copy, readFile } from '../async/fs';
import { spawn } from '../async/child_process';
import path from 'path';
import handlebars from 'handlebars';
import * as style from './style';
import { removeSync, copySync } from 'fs-extra';
import TOML from 'toml';
import clone from 'shallow-copy';
import Project from '../project';
const TEMPLATES_DIR = path.resolve(__dirname, '..', 'templates');
const LIB_PREFIX = {
'darwin': "lib",
'freebsd': "lib",
'linux': "lib",
'sunos': "lib",
'win32': ""
};
const LIB_SUFFIX = {
'darwin': ".dylib",
'freebsd': ".so",
'linux': ".so",
'sunos': ".so",
'win32': ".dll"
};
function explicit_cargo_target() {
if (process.platform === 'win32') {
let arch = process.env.npm_config_arch || process.arch;
if (arch === 'ia32') {
return 'i686-pc-windows-msvc';
} else {
return 'x86_64-pc-windows-msvc';
}
}
export default async function neon_build(root, toolchain, release, abi) {
let project = new Project(root);
await project.build(toolchain, release, abi);
}
function cargo(root, toolchain, configuration, nodeModuleVersion, target) {
let macos = process.platform === 'darwin';
let [command, prefix] = toolchain === 'default'
? ["cargo", []]
: ["multirust", ["run", toolchain]];
let args = prefix.concat(macos ? 'rustc' : 'build',
configuration === 'release' ? ["--release"] : [],
macos ? ["--", "-C", "link-args=-Wl,-undefined,dynamic_lookup"] : []);
// Pass the Node modules ABI version to the build as an environment variable.
let env = clone(process.env);
env.NEON_NODE_ABI = nodeModuleVersion || process.versions.modules;
if (target) {
args.push("--target=" + target);
}
console.log(style.info([command].concat(args).join(" ")));
return spawn(command, args, { cwd: path.resolve(root, 'native'), stdio: 'inherit', env: env });
}
async function main(root, name, configuration, target) {
let pp = process.platform;
let output_directory = target ?
path.resolve(root, 'native', 'target', target, configuration) :
path.resolve(root, 'native', 'target', configuration);
let dylib = path.resolve(output_directory, LIB_PREFIX[pp] + name + LIB_SUFFIX[pp]);
let index = path.resolve(root, 'native', 'index.node');
console.log(style.info("generating native" + path.sep + "index.node"));
await remove(index);
await copy(dylib, index);
}
export default async function neon_build(root, toolchain, configuration, nodeModuleVersion) {
// 1. Read the Cargo metadata.
let metadata = TOML.parse(await readFile(path.resolve(root, 'native', 'Cargo.toml'), 'utf8'));
if (!metadata.lib.name) {
throw new Error("Cargo.toml does not contain a [lib] section with a 'name' field");
}
let target = explicit_cargo_target();
console.log(style.info("running cargo"));
// 2. Build the binary.
if ((await cargo(root, toolchain, configuration, nodeModuleVersion, target)) !== 0) {
throw new Error("cargo build failed");
}
// 3. Copy the dylib into the main index.node file.
await main(root, metadata.lib.name, configuration, target);
}

@@ -49,3 +49,3 @@ import { readFile, writeFile, mkdirs } from '../async/fs';

export default async function wizard(pwd, name, toolchain) {
export default async function wizard(pwd, name) {
let its = validateName(name);

@@ -121,9 +121,2 @@ if (!its.validForNewPackages) {

patch: semver.patch(version)
},
build: {
cargo: {
cmd: toolchain === 'default'
? []
: ["multirust", "run", toolchain]
}
}

@@ -130,0 +123,0 @@ };

@@ -22,2 +22,3 @@ import { setup } from '../support/acceptance';

.wait("build")
.wait("clean")
.wait("version")

@@ -35,2 +36,23 @@ .wait("help")

function testHelpClean(proc, done) {
return proc
.wait("neon clean")
.wait("Remove build artifacts from a Neon project.")
.wait("Synopsis")
.wait("$ neon clean [options]")
.wait("$ neon clean [options] module ...")
.wait("Options")
.wait("-p, --path")
.run(err => {
if (err) throw err;
done();
});
}
describeHelp("neon help clean", "should print `neon clean` usage", testHelpClean, ['help', 'clean']);
describeHelp("neon clean --help", "should print `neon clean` usage", testHelpClean, ['clean', '--help']);
describeHelp("neon clean -h", "should print `neon clean` usage", testHelpClean, ['clean', '-h']);
describeHelp("neon --help clean", "should print `neon clean` usage", testHelpClean, ['--help', 'clean']);
describeHelp("neon -h clean", "should print `neon clean` usage", testHelpClean, ['-h', 'clean']);
function testHelpVersion(proc, done) {

@@ -59,5 +81,3 @@ return proc

.wait("Synopsis")
.wait("$ neon new [options] [@<scope>/]<name>")
.wait("Options")
.wait("-r, --rust")
.wait("$ neon new [@<scope>/]<name>")
.run(err => {

@@ -64,0 +84,0 @@ if (err) throw err;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc