@torpor/check 1.0.14 → 1.0.15
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/dist/bin/index.js +43 -1
- package/dist/bin/index.js.map +1 -1
- package/package.json +2 -2
package/dist/bin/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
import { n as check, t as check$1 } from "../checkFile-BvvjrnaS.mjs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
3
4
|
import chalk from "chalk";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
+
import fs, { existsSync, readdirSync, statSync } from "node:fs";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
//#region src/printErrors.ts
|
|
7
8
|
function printErrors(folder, errors) {
|
|
@@ -20,7 +21,48 @@ function printErrors(folder, errors) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
//#endregion
|
|
24
|
+
//#region src/warnStaleView.ts
|
|
25
|
+
/**
|
|
26
|
+
* Warns when the `@torpor/view` dist that the compiler resolves to is older
|
|
27
|
+
* than its src tree. The check pipeline compiles `.torp` files through
|
|
28
|
+
* `@torpor/view/compile`, which resolves to the packed `dist` — so after
|
|
29
|
+
* changing `packages/view/src` without rebuilding, reported errors describe
|
|
30
|
+
* stale compiler output that no longer matches the current compiler (this has
|
|
31
|
+
* produced batches of phantom errors before). Only fires inside the monorepo,
|
|
32
|
+
* where a `src` sibling exists to compare against; a one-line warning is
|
|
33
|
+
* cheaper than the rebuild it saves.
|
|
34
|
+
*/
|
|
35
|
+
function warnStaleView() {
|
|
36
|
+
const require = createRequire(import.meta.url);
|
|
37
|
+
let viewDir;
|
|
38
|
+
try {
|
|
39
|
+
viewDir = path.dirname(require.resolve("@torpor/view/package.json"));
|
|
40
|
+
} catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const srcDir = path.join(viewDir, "src");
|
|
44
|
+
const distDir = path.join(viewDir, "dist");
|
|
45
|
+
if (!existsSync(srcDir) || !existsSync(distDir)) return;
|
|
46
|
+
const newestMtime = (folder) => {
|
|
47
|
+
let newest = 0;
|
|
48
|
+
const walk = (dir) => {
|
|
49
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
50
|
+
const full = path.join(dir, entry.name);
|
|
51
|
+
if (entry.isDirectory()) walk(full);
|
|
52
|
+
else {
|
|
53
|
+
const mtime = statSync(full).mtimeMs;
|
|
54
|
+
if (mtime > newest) newest = mtime;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
walk(folder);
|
|
59
|
+
return newest;
|
|
60
|
+
};
|
|
61
|
+
if (newestMtime(srcDir) > newestMtime(distDir)) console.warn("NOTE: @torpor/view/dist is older than its src — check results may not match the current compiler. Run `pnpm build` in packages/view to refresh.");
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
23
64
|
//#region src/bin/index.ts
|
|
65
|
+
warnStaleView();
|
|
24
66
|
let errors = [];
|
|
25
67
|
let pathArg = process.argv[2];
|
|
26
68
|
if (!pathArg) {
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["checkFile"],"sources":["../../src/printErrors.ts","../../src/bin/index.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function printErrors(folder: string, errors: Diagnostic[]): void {\n\terrors.sort((a, b) => a.path.localeCompare(b.path));\n\n\tfor (let error of errors) {\n\t\tconsole.log(\n\t\t\t`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red(\"error\")}${error.code ? chalk.gray(` TS${error.code}`) : \"\"}: ${error.message}`,\n\t\t);\n\t\tif (error.lineText) {\n\t\t\t// HACK: If I were less lazy I'd replace tabs with 4 spaces and adjust positions\n\t\t\terror.lineText = error.lineText.replaceAll(\"\\t\", \" \");\n\t\t\tconsole.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);\n\t\t\tlet numberLength = error.range.start.line.toString().length;\n\t\t\tlet spacerLength = error.range.start.character;\n\t\t\tlet squiggleLength =\n\t\t\t\terror.range.start.line === error.range.end.line\n\t\t\t\t\t? error.range.end.character - error.range.start.character\n\t\t\t\t\t: error.lineText.length - error.range.start.character;\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.black.bgWhite(\" \".repeat(numberLength))} ${\" \".repeat(spacerLength)}${chalk.red(\"~\").repeat(squiggleLength)}`,\n\t\t\t);\n\t\t}\n\t\tconsole.log();\n\t}\n}\n","#! /usr/bin/env node\nimport chalk from \"chalk\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport check from \"../check\";\nimport checkFile from \"../checkFile\";\nimport printErrors from \"../printErrors\";\nimport type Diagnostic from \"../types/Diagnostic\";\n\nlet errors: Diagnostic[] = [];\n\nlet pathArg = process.argv[2];\nif (!pathArg) {\n\tpathArg = process.cwd();\n\terrors = check(pathArg);\n} else {\n\tif (!fs.existsSync(pathArg)) {\n\t\tpathArg = path.join(process.cwd(), pathArg);\n\t}\n\tif (!fs.existsSync(pathArg)) {\n\t\tconsole.log(\"Path not found\", process.argv[2]);\n\t} else if (fs.lstatSync(pathArg).isDirectory()) {\n\t\terrors = check(pathArg);\n\t} else {\n\t\terrors = checkFile(pathArg);\n\t}\n}\n\nif (errors.length > 0) {\n\tconsole.log();\n\tprintErrors(path.dirname(pathArg), errors);\n\tconsole.log(`Found ${chalk.red(errors.length)} error${errors.length === 1 ? \"\" : \"s\"}`);\n} else {\n\tconsole.log(\"No errors found\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["checkFile"],"sources":["../../src/printErrors.ts","../../src/warnStaleView.ts","../../src/bin/index.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function printErrors(folder: string, errors: Diagnostic[]): void {\n\terrors.sort((a, b) => a.path.localeCompare(b.path));\n\n\tfor (let error of errors) {\n\t\tconsole.log(\n\t\t\t`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red(\"error\")}${error.code ? chalk.gray(` TS${error.code}`) : \"\"}: ${error.message}`,\n\t\t);\n\t\tif (error.lineText) {\n\t\t\t// HACK: If I were less lazy I'd replace tabs with 4 spaces and adjust positions\n\t\t\terror.lineText = error.lineText.replaceAll(\"\\t\", \" \");\n\t\t\tconsole.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);\n\t\t\tlet numberLength = error.range.start.line.toString().length;\n\t\t\tlet spacerLength = error.range.start.character;\n\t\t\tlet squiggleLength =\n\t\t\t\terror.range.start.line === error.range.end.line\n\t\t\t\t\t? error.range.end.character - error.range.start.character\n\t\t\t\t\t: error.lineText.length - error.range.start.character;\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.black.bgWhite(\" \".repeat(numberLength))} ${\" \".repeat(spacerLength)}${chalk.red(\"~\").repeat(squiggleLength)}`,\n\t\t\t);\n\t\t}\n\t\tconsole.log();\n\t}\n}\n","import { existsSync, readdirSync, statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { createRequire } from \"node:module\";\n\n/**\n * Warns when the `@torpor/view` dist that the compiler resolves to is older\n * than its src tree. The check pipeline compiles `.torp` files through\n * `@torpor/view/compile`, which resolves to the packed `dist` — so after\n * changing `packages/view/src` without rebuilding, reported errors describe\n * stale compiler output that no longer matches the current compiler (this has\n * produced batches of phantom errors before). Only fires inside the monorepo,\n * where a `src` sibling exists to compare against; a one-line warning is\n * cheaper than the rebuild it saves.\n */\nexport default function warnStaleView(): void {\n\tconst require = createRequire(import.meta.url);\n\tlet viewDir: string;\n\ttry {\n\t\tviewDir = path.dirname(require.resolve(\"@torpor/view/package.json\"));\n\t} catch {\n\t\treturn;\n\t}\n\tconst srcDir = path.join(viewDir, \"src\");\n\tconst distDir = path.join(viewDir, \"dist\");\n\tif (!existsSync(srcDir) || !existsSync(distDir)) {\n\t\t// An installed copy in a user project — nothing to compare\n\t\treturn;\n\t}\n\n\tconst newestMtime = (folder: string): number => {\n\t\tlet newest = 0;\n\t\tconst walk = (dir: string): void => {\n\t\t\tfor (const entry of readdirSync(dir, { withFileTypes: true })) {\n\t\t\t\tconst full = path.join(dir, entry.name);\n\t\t\t\tif (entry.isDirectory()) {\n\t\t\t\t\twalk(full);\n\t\t\t\t} else {\n\t\t\t\t\tconst mtime = statSync(full).mtimeMs;\n\t\t\t\t\tif (mtime > newest) newest = mtime;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\twalk(folder);\n\t\treturn newest;\n\t};\n\n\tif (newestMtime(srcDir) > newestMtime(distDir)) {\n\t\tconsole.warn(\n\t\t\t\"NOTE: @torpor/view/dist is older than its src — check results may not match the current compiler. Run `pnpm build` in packages/view to refresh.\",\n\t\t);\n\t}\n}\n","#! /usr/bin/env node\nimport chalk from \"chalk\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport check from \"../check\";\nimport checkFile from \"../checkFile\";\nimport printErrors from \"../printErrors\";\nimport type Diagnostic from \"../types/Diagnostic\";\nimport warnStaleView from \"../warnStaleView\";\n\n// Warn before checking when the compiler dist is older than its src (results\n// would describe stale compiler output)\nwarnStaleView();\n\nlet errors: Diagnostic[] = [];\n\nlet pathArg = process.argv[2];\nif (!pathArg) {\n\tpathArg = process.cwd();\n\terrors = check(pathArg);\n} else {\n\tif (!fs.existsSync(pathArg)) {\n\t\tpathArg = path.join(process.cwd(), pathArg);\n\t}\n\tif (!fs.existsSync(pathArg)) {\n\t\tconsole.log(\"Path not found\", process.argv[2]);\n\t} else if (fs.lstatSync(pathArg).isDirectory()) {\n\t\terrors = check(pathArg);\n\t} else {\n\t\terrors = checkFile(pathArg);\n\t}\n}\n\nif (errors.length > 0) {\n\tconsole.log();\n\tprintErrors(path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EAAE,QAAQ,OAAO,WAAW,IAAI,KAAK,KAAK;AACvF,OACC,QAAQ,IAAI,iBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/check",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
4
4
|
"description": "Checks Torpor files for errors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@torpor/view": "^1.
|
|
25
|
+
"@torpor/view": "^1.3.0",
|
|
26
26
|
"@typescript/vfs": "^1.6.5",
|
|
27
27
|
"chalk": "^6.0.1",
|
|
28
28
|
"fast-glob": "^3.3.3"
|