Socket
Socket
Sign inDemoInstall

@toruslabs/torus-scripts

Package Overview
Dependencies
627
Maintainers
5
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.12 to 0.0.13

helpers/formatRollupStats.js

22

package.json
{
"name": "@toruslabs/torus-scripts",
"version": "0.0.12",
"version": "0.0.13",
"bin": {

@@ -8,18 +8,20 @@ "torus-scripts": "./bin/torus-scripts.js"

"dependencies": {
"@babel/core": "^7.15.8",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-object-rest-spread": "^7.15.6",
"@babel/core": "^7.16.0",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@babel/runtime": "^7.15.4",
"@babel/plugin-transform-runtime": "^7.16.0",
"@babel/preset-env": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@babel/runtime": "^7.16.3",
"@rollup/plugin-typescript": "^8.3.0",
"babel-loader": "^8.2.3",
"babel-merge": "^3.0.0",
"chalk": "^4.1.2",
"dotenv": "^10.0.0",
"eslint-webpack-plugin": "^2.5.4",
"listr": "^0.14.3",
"lodash.mergewith": "^4.6.2",
"require-from-string": "^2.0.2",
"rollup": "^2.58.3",
"rollup": "^2.60.0",
"rollup-plugin-sourcemaps": "^0.6.3",

@@ -35,3 +37,3 @@ "typescript": "^4.4.4",

},
"gitHead": "df2f0e897b98f2e796f09cef13596721ea9754b2"
"gitHead": "922270e960411c70c1ff7e6f83207a31296a5e51"
}

@@ -28,7 +28,13 @@ "use strict";

const webpack = require("webpack");
const chalk = require("chalk");
const Listr = require("listr");
const ui = require("cliui")({ width: process.stdout.columns || 80 });
const generateRollupConfig = require("../config/rollup.config");
const generateWebpackConfig = require("../config/webpack.config");
const torusConfig = require("../config/torus.config");
const paths = require("../config/paths");
const formatWebpackStats = require("../helpers/formatWebpackStats");
const formatWebpackMessages = require("../helpers/formatWebpackMessages");
const paths = require("../config/paths");
const formatRollupStats = require("../helpers/formatRollupStats");

@@ -41,67 +47,121 @@ finalArgs.name = finalArgs.name || torusConfig.name;

async function buildRollup() {
function addOutput({ ctx, filename, formattedStats, type, warnings }) {
if (!ctx.outputs) ctx.outputs = {};
ctx.outputs[filename] = {
type,
formattedStats,
warnings,
};
}
function getRollupTasks() {
const config = generateRollupConfig(finalArgs.name);
const outputOptions = Array.isArray(config.output) ? config.output : [config.output];
// console.log(bundle.watchFiles);
const bundle = await rollup.rollup(config);
await Promise.all(
outputOptions.map(async (outputOption) => {
await bundle.generate(outputOption);
// console.log(output);
await bundle.write(outputOption);
})
);
await bundle.close();
return outputOptions.map((outputOption) => {
const filenameChunks = outputOption.file.split("/");
const filename = filenameChunks[filenameChunks.length - 1];
return {
title: filename,
task: async (ctx) => {
const start = process.hrtime.bigint();
const bundle = await rollup.rollup(config);
await bundle.generate(outputOption);
const output = await bundle.write(outputOption);
await bundle.close();
const end = process.hrtime.bigint();
const time = ((end - start) / BigInt(1e6)).toString();
const formattedStats = formatRollupStats(output.output, paths.appBuild, time);
// time is in ms
addOutput({ ctx, filename, formattedStats, warnings: [], type: "rollup" });
},
};
});
}
async function buildWebpack() {
function getWebpackTasks() {
const configs = generateWebpackConfig(finalArgs.name);
const results = await Promise.all(
configs.map(async (x) => {
return new Promise((resolve, reject) => {
webpack(x, (err, stats) => {
let messages;
if (err) {
if (!err.message) {
return reject(err);
return configs.map((x) => {
return {
title: x.output.filename,
task: (ctx) => {
return new Promise((resolve, reject) => {
webpack(x, (err, stats) => {
let messages;
if (err) {
if (!err.message) {
return reject(err);
}
messages = formatWebpackMessages({
errors: [err.message],
warnings: [],
});
} else {
messages = formatWebpackMessages(stats.toJson({ all: false, warnings: true, errors: true }));
}
messages = formatWebpackMessages({
errors: [err.message],
warnings: [],
});
} else {
messages = formatWebpackMessages(stats.toJson({ all: false, warnings: true, errors: true }));
}
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1;
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1;
}
return reject(new Error(messages.errors.join("\n\n")));
}
return reject(new Error(messages.errors.join("\n\n")));
}
const resolveArgs = {
stats,
warnings: messages.warnings,
};
return resolve(resolveArgs);
const formattedStats = formatWebpackStats(stats, paths.appBuild);
addOutput({ ctx, filename: x.output.filename, warnings: messages.warnings, formattedStats, type: "webpack" });
return resolve();
});
});
});
})
);
console.log(
results.map((x) =>
x.stats?.toJson({
all: false,
assets: true,
})
)
);
},
};
});
}
if (torusConfig.esm) buildRollup();
async function main() {
const tasks = new Listr([], { concurrent: true });
console.log(chalk.yellow("Collating builds..."));
if (torusConfig.esm) {
tasks.add(getRollupTasks());
}
tasks.add(getWebpackTasks());
try {
const ctx = await tasks.run();
buildWebpack();
Object.keys(ctx.outputs).forEach((filename) => {
const outputObj = ctx.outputs[filename];
const warnings = outputObj.warnings;
if (warnings.length > 0) {
console.log(chalk.yellow("\nCompiled with warnings.\n"));
console.log(warnings.join("\n\n"));
console.log("\nSearch for the " + chalk.underline(chalk.yellow("keywords")) + " to learn more about each warning.");
console.log("To ignore, add " + chalk.cyan("// eslint-disable-next-line") + " to the line before.\n");
}
});
ui.div(chalk.cyan.bold(`File`), chalk.cyan.bold(`Size`), chalk.cyan.bold(`Gzipped`), chalk.cyan.bold(`Time`));
Object.keys(ctx.outputs).forEach((filename) => {
const outputObj = ctx.outputs[filename];
outputObj.formattedStats.map((x) => ui.div(...x));
});
ui.div(`\n ${chalk.gray(`Images and other types of assets omitted.`)}\n`);
console.log(ui.toString());
console.log(chalk.green("✔"), "Build complete");
} catch (error) {
console.error(chalk.red(error.message));
console.error(chalk.red(error.stack));
// Throw to exit with code 1
throw new Error("Build failed");
}
}
main();
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc