@toruslabs/torus-scripts
Advanced tools
Comparing version 0.0.12 to 0.0.13
{ | ||
"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(); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
48056
16
647
0
24
19
+ Addedchalk@^4.1.2
+ Addedlistr@^0.14.3
+ Added@samverschueren/stream-to-observable@0.3.1(transitive)
+ Addedansi-escapes@3.2.0(transitive)
+ Addedansi-regex@2.1.13.0.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedany-observable@0.3.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-cursor@2.1.0(transitive)
+ Addedcli-truncate@0.2.1(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addeddate-fns@1.30.1(transitive)
+ Addedelegant-spinner@1.0.1(transitive)
+ Addedfigures@1.7.02.0.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedindent-string@3.2.0(transitive)
+ Addedis-fullwidth-code-point@1.0.02.0.0(transitive)
+ Addedis-observable@1.1.0(transitive)
+ Addedis-promise@2.2.2(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedlistr@0.14.3(transitive)
+ Addedlistr-silent-renderer@1.1.1(transitive)
+ Addedlistr-update-renderer@0.5.0(transitive)
+ Addedlistr-verbose-renderer@0.5.0(transitive)
+ Addedlog-symbols@1.0.2(transitive)
+ Addedlog-update@2.3.0(transitive)
+ Addedmimic-fn@1.2.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonetime@2.0.1(transitive)
+ Addedp-map@2.1.0(transitive)
+ Addedrestore-cursor@2.0.0(transitive)
+ Addedrxjs@6.6.7(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedslice-ansi@0.0.4(transitive)
+ Addedstring-width@1.0.22.1.1(transitive)
+ Addedstrip-ansi@3.0.14.0.0(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedsymbol-observable@1.2.0(transitive)
+ Addedtslib@1.14.1(transitive)
+ Addedwrap-ansi@3.0.1(transitive)
Updated@babel/core@^7.16.0
Updated@babel/preset-env@^7.16.0
Updated@babel/runtime@^7.16.3
Updatedrollup@^2.60.0