loadwise 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Loadwise
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/loadwise) [](https://github.com/IbrahimHafez1/loadwise/actions/workflows/check.yml) [](LICENSE)
|
|
3
|
+
[](https://www.npmjs.com/package/loadwise) [](https://github.com/IbrahimHafez1/loadwise/actions/workflows/check.yml) [](https://scorecard.dev/viewer/?uri=github.com/IbrahimHafez1/loadwise) [](LICENSE)
|
|
4
4
|
|
|
5
5
|
Loadwise checks a backend project before it ships. One CLI runs five checkers:
|
|
6
6
|
|
package/bin/loadwise.js
CHANGED
|
@@ -79,7 +79,7 @@ const inProcessCheckers = new Set(['perf', 'rel', 'maint', 'sec', 'a11y']);
|
|
|
79
79
|
function respawnIfHeapTooSmall(commandArgs) {
|
|
80
80
|
if (!inProcessCheckers.has(commandArgs[0]) || !shouldRespawnWithLargerHeap())
|
|
81
81
|
return false;
|
|
82
|
-
|
|
82
|
+
respawnWithLargerHeap(import.meta.filename, commandArgs);
|
|
83
83
|
return true;
|
|
84
84
|
}
|
|
85
85
|
function runMain(commandArgs) {
|
|
@@ -16,10 +16,12 @@ function hasInterpolation(dialect, value) {
|
|
|
16
16
|
}
|
|
17
17
|
// `@click.stop`, `(click)="$event.stopPropagation()"` or `on:click={(e) => e.stopPropagation()}` keeps a click inside
|
|
18
18
|
// a panel from reaching a backdrop; it is not a way to activate the element, so it is left out like a missing handler.
|
|
19
|
-
|
|
19
|
+
// Each whitespace run has one place to match, so a long run of spaces cannot make the test backtrack. The arrow
|
|
20
|
+
// parameter starts with a name or a parenthesis, never a space, for the same reason.
|
|
21
|
+
const propagationOnlyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?(?:\{\s*)?(?:[\w$]+\.(?:stopPropagation|preventDefault)\(\)\s*(?:;\s*)?)+(?:\}\s*)?$/;
|
|
20
22
|
// `@click="() => {}"` does nothing, so it is no more a way to activate the element than a propagation-only handler. A
|
|
21
23
|
// Svelte `on:click={…}` value keeps its closing brace, hence the optional second one.
|
|
22
|
-
const emptyHandler = /^\s*(?:\(
|
|
24
|
+
const emptyHandler = /^\s*(?:(?:\([\w$]*\)|[\w$]+)\s*=>\s*)?\{\s*\}\}?\s*$/;
|
|
23
25
|
function eventAttribute(event, rawValue, isBareAllowed) {
|
|
24
26
|
const isBare = rawValue === undefined || rawValue.trim() === '';
|
|
25
27
|
if (isBare && isBareAllowed)
|
package/lib/shared/check.js
CHANGED
|
@@ -12,6 +12,10 @@ import { writeReviewHandoff } from './review-delivery.js';
|
|
|
12
12
|
const invalidInputCode = 2;
|
|
13
13
|
const thresholdMetCode = 1;
|
|
14
14
|
function parseCheckArgs(args) {
|
|
15
|
+
// Each checker takes --fix, so `loadwise --fix` is a natural guess; point it to the fix command instead of a parser error.
|
|
16
|
+
if (args.includes('--fix')) {
|
|
17
|
+
throw new Error('check never changes files. From the project folder, run `loadwise fix --yes` for automatic edits or `loadwise fix --all` to also apply edits marked for review; add checker names to limit either, as in `loadwise fix --all performance`.');
|
|
18
|
+
}
|
|
15
19
|
const { args: checkArgs, ...baselineOptions } = extractBaselineFlags(args);
|
|
16
20
|
const { values, positionals } = parseArgs({
|
|
17
21
|
args: checkArgs,
|
|
@@ -190,6 +194,9 @@ async function scanForFixes(checkers) {
|
|
|
190
194
|
return options.selected.flatMap((pillar, index) => {
|
|
191
195
|
if (!runs[index] && pillar.optional)
|
|
192
196
|
return [];
|
|
197
|
+
if (!runs[index] && !projectConfig(options.directory)) {
|
|
198
|
+
throw new Error(`No tsconfig.json or jsconfig.json in ${options.directory}, so the ${pillar.title} checker cannot run. Run loadwise fix from the project folder, or add a tsconfig.json or jsconfig.json there. No fixes applied.`);
|
|
199
|
+
}
|
|
193
200
|
const report = parsedReport(runs[index]);
|
|
194
201
|
if (!report || !Array.isArray(report.findings) || ![0, 1].includes(runs[index]?.code ?? invalidInputCode)) {
|
|
195
202
|
throw new Error(`The ${pillar.title} scan did not complete. No fixes applied.`);
|
package/lib/shared/heap-limit.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// The checkers get a larger limit derived from the machine unless the user already chose one.
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import v8 from 'node:v8';
|
|
5
|
-
import {
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
6
|
const bytesPerMegabyte = 1024 * 1024;
|
|
7
7
|
const heapFractionOfMemory = 0.6;
|
|
8
8
|
const minHeapMegabytes = 4096;
|
|
@@ -45,12 +45,23 @@ function shouldRespawnWithLargerHeap(env = process.env) {
|
|
|
45
45
|
return false;
|
|
46
46
|
return recommendedHeapMegabytes() > defaultHeapMegabytes();
|
|
47
47
|
}
|
|
48
|
+
// Editors and process managers signal only the process they started. Without forwarding, stopping a
|
|
49
|
+
// `--watch` run would leave the re-spawned watcher running, holding its output pipes open forever.
|
|
50
|
+
const forwardedSignals = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
51
|
+
// Sets process.exitCode once the child exits.
|
|
48
52
|
function respawnWithLargerHeap(scriptPath, args) {
|
|
49
53
|
// The child inherits process.env; copying it here would read every variable, connection strings
|
|
50
54
|
// included.
|
|
51
55
|
process.env[respawnMarker] = '1';
|
|
52
|
-
const
|
|
53
|
-
|
|
56
|
+
const child = spawn(process.execPath, [`${heapFlagName}=${recommendedHeapMegabytes()}`, ...process.execArgv, scriptPath, ...args], { stdio: 'inherit', windowsHide: true });
|
|
57
|
+
const forward = (signal) => child.kill(signal);
|
|
58
|
+
for (const signal of forwardedSignals)
|
|
59
|
+
process.on(signal, forward);
|
|
60
|
+
child.on('exit', (code) => {
|
|
61
|
+
for (const signal of forwardedSignals)
|
|
62
|
+
process.off(signal, forward);
|
|
63
|
+
process.exitCode = code ?? 2;
|
|
64
|
+
});
|
|
54
65
|
}
|
|
55
66
|
const heapExhaustionPattern = /(heap|javascript) out of memory/i;
|
|
56
67
|
function isHeapExhaustion({ code, signal, stderr }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loadwise",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Find performance, reliability, maintainability, security and accessibility issues, review suggested fixes, and check changed code locally or in CI.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"vscode"
|
|
40
40
|
],
|
|
41
41
|
"bin": {
|
|
42
|
-
"loadwise": "
|
|
42
|
+
"loadwise": "bin/loadwise.js"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
45
|
"bin/",
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
"format": "prettier --cache --write .",
|
|
76
76
|
"format:check": "prettier --cache --check .",
|
|
77
77
|
"lint": "oxlint --deny-warnings .",
|
|
78
|
-
"check": "npm run format:check && npm run lint && npm
|
|
78
|
+
"check": "npm run format:check && npm run lint && npm test",
|
|
79
79
|
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
80
|
-
"test": "npm run build && node
|
|
80
|
+
"test": "npm run build && node scripts/run-tests.js",
|
|
81
81
|
"selfscan:baseline": "node bin/loadwise.js check . --config scripts/self-scan/loadwise.config.json --write-baseline scripts/self-scan/loadwise-baseline.json",
|
|
82
82
|
"bench:corpus": "node scripts/score-corpus.js",
|
|
83
83
|
"bench:scorecard": "node scripts/score-corpus.js --scorecard",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "loadwise",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Runs the project's local loadwise checkers on each file Claude edits and sends findings back with their fix commands.",
|
|
5
5
|
"author": { "name": "Ibrahim Hafez" },
|
|
6
6
|
"homepage": "https://github.com/IbrahimHafez1/loadwise#readme",
|