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

cli-task

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-task - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

index.d.ts

12

.vscode/launch.json

@@ -7,6 +7,7 @@ {

"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"name": "Launch dep-tree",
"program": "${workspaceFolder}/src/cli.js",

@@ -22,2 +23,11 @@ "args": [

"request": "launch",
"name": "Launch dummy",
"program": "${workspaceFolder}/src/cli.js",
"args": [
"dummy",
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",

@@ -24,0 +34,0 @@ "program": "${workspaceFolder}/tasks/dep-tree.ts",

1

index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Task_1 = require("./src/Task");
module.exports = () => new Task_1.default();
//# sourceMappingURL=index.js.map
{
"name": "cli-task",
"version": "0.4.0",
"version": "0.5.0",
"repository": "https://github.com/astoilkov/cli-task",

@@ -5,0 +5,0 @@ "description": "",

@@ -12,6 +12,6 @@ "use strict";

let handleError = (err) => {
if (this.getCurrentTask()) {
this.getCurrentTask().failure(err);
if (this.getCurrentStep()) {
this.getCurrentStep().failure(err);
}
else {
else if (err instanceof Error) {
throw err;

@@ -47,12 +47,12 @@ }

}
getCurrentTask() {
getCurrentStep() {
let queue = this.steps.slice();
while (queue.length) {
let task = queue.pop();
if (task.status == Step_1.StepStatus.Running) {
if (task.child) {
queue.push(...task.child.steps);
let step = queue.pop();
if (step.status == Step_1.StepStatus.Running) {
if (step.child) {
queue.push(...step.child.steps);
}
else {
return task;
return step;
}

@@ -86,6 +86,6 @@ }

}
if (step.concurrent && step.status != Step_1.StepStatus.Failure) {
else if (step.concurrent) {
resolve();
}
if (result && result.then instanceof Function && result.catch instanceof Function) {
else if (result && result.then instanceof Function && result.catch instanceof Function) {
result.then(done).catch((err) => step.failure(err));

@@ -116,6 +116,6 @@ }

info: (message) => {
this.getCurrentTask().info = message;
this.getCurrentStep().info = message;
},
fail: (message) => {
this.getCurrentTask().failure(message);
this.getCurrentStep().failure(message);
}

@@ -122,0 +122,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const os_1 = require("os");
const child_process_1 = require("child_process");
const execa = require("execa");
const task = require("../index");
const semver = require("semver");
const jetpack = require("fs-jetpack");
const prettyBytes = require("pretty-bytes");
exports.default = task()
.add({
name: 'init npm repository',
exec: (state) => {
let dirPath = path_1.join(os_1.tmpdir(), 'dep-tree');
jetpack.remove(dirPath);
state.global.set('dirPath', dirPath);
jetpack.dir(dirPath);
return execa('npm', [
'init',
'--force'
], {
cwd: dirPath
});
}
})
.add({
name: 'install dependency',
exec: (state) => {
return execa('npm', [
'install',
state.global.argv._[0]
], {
cwd: state.global.get('dirPath')
});
}
})
.add({
name: 'do stuff',
exec: async (state) => {
let dirPath = state.global.get('dirPath');
let tree = await generateTree(dirPath);
let html = renderTree(tree.nodes[0]);
let filePath = path_1.join(os_1.tmpdir(), '98sb938a0q.html');
let entireSize = (await jetpack.inspectTree(dirPath)).size;
let missing = entireSize - tree.totalSize;
if (missing > 0) {
html += `<div>Missing: ${prettyBytes(missing)}</div>`;
}
jetpack.write(filePath, html);
child_process_1.spawn('open', [filePath]);
}
});
async function generateTree(dirPath) {
let packages = jetpack.find(dirPath, {
matching: ['**/package.json']
});
let dependencies = [];
for (let i = 0; i < packages.length; i++) {
let packageJSON = await jetpack.readAsync(packages[i], 'json');
let inspectTree = await jetpack.inspectTree(path_1.dirname(packages[i]));
let nodeModules = inspectTree.children.find(child => child.name == 'node_modules' && child.type == 'dir');
let size = inspectTree.size;
if (nodeModules) {
size -= nodeModules.size;
}
if (packageJSON.name) {
dependencies.push({
size: size,
name: packageJSON.name,
version: packageJSON.version,
dependencies: Object.entries(packageJSON.dependencies || {}).map(value => {
return {
name: value[0],
range: value[1]
};
}),
});
}
}
let rootPackageJSON = jetpack.read(path_1.join(dirPath, 'package.json'), 'json');
let dependency = dependencies.find(dep => dep.name == rootPackageJSON.name);
let root = {
nodes: [],
parent: null,
dependency: dependency,
totalSize: dependency.size,
};
fillTree(root, dependencies, []);
return root;
}
function fillTree(node, dependencies, visited) {
let nodes = node.dependency.dependencies.map(value => {
let dependency = dependencies.find(dep => dep.name == value.name && semver.satisfies(dep.version, value.range));
return {
nodes: [],
parent: node,
dependency: dependency,
totalSize: dependency.size,
};
});
for (let i = 0; i < nodes.length; i++) {
if (visited.includes(nodes[i].dependency)) {
continue;
}
node.nodes.push(nodes[i]);
visited.push(nodes[i].dependency);
fillTree(nodes[i], dependencies, visited);
node.totalSize += nodes[i].totalSize;
}
node.nodes.sort((nodeA, nodeB) => nodeB.totalSize - nodeA.totalSize);
}
function renderTree(tree) {
return `
<style>
:root {
font-family: -apple-system, BlinkMacSystemFont, segoe ui, Roboto, Helvetica, Arial, sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
font-size: 14px;
font-weight: 400;
letter-spacing: 1px;
line-height: 2em;
margin: 0;
padding: 0;
color: hsla(0, 0%, 70%, 1);
background: rgb(40, 40, 40);
}
ul {
list-style-type: none;
}
li {
position: relative;
padding-left: 20px;
}
li::before {
display: inline-block;
content: '›';
transform: rotate(90deg);
position: absolute;
top: 1px;
left: 0;
}
li > span {
margin-right: 10px;
}
li .total-size,
li .local-size {
background: rgb(30, 30, 30);
padding: 2px 4px;
}
</style>
<ul class="list list--root">
${renderNode(tree)}
</ul>
`;
}
function renderNode(node) {
let html = '';
let expanded = true;
let oneKB = 1024;
if (node.totalSize < oneKB * 100 && node.nodes.length > 0) {
expanded = false;
}
if (node.dependency.size < node.totalSize * 0.9 && node.nodes.length > 0) {
expanded = false;
}
html += `
<li class="list__item ${expanded ? 'list__item--expanded' : 'list__item--collapsed'}">
<span class="icon"></span>
<span class="name">${node.dependency.name}</span>
<span class="version">${node.dependency.version.toString()}</span>
<span class="total-size">${prettyBytes(node.totalSize)}</span>
<span class="local-size">${prettyBytes(node.dependency.size)}</span>
<ul class="list">
${node.nodes.map(node => renderNode(node)).join('')}
</ul>
</li>
`;
return html;
}
//# sourceMappingURL=dep-tree.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
exports.default = index_1.default().add({
name: 'value',
exec: async () => {
let a = 4;
const task = require("../index");
exports.default = task()
.add({
name: 'asdf',
exec: (state) => {
state.fail('asdf');
}
});
//# sourceMappingURL=dummy.js.map
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