@amritk/mjst 0.27.1 → 0.27.3

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.
Files changed (2) hide show
  1. package/dist/lint/run.js +16 -5
  2. package/package.json +7 -7
package/dist/lint/run.js CHANGED
@@ -1,11 +1,9 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { readFile, stat } from "node:fs/promises";
2
2
  import { dirname, isAbsolute, resolve } from "node:path";
3
3
  import { lintDocument, validateRuleset } from "@amritk/lint";
4
4
  import { DiagnosticSeverity } from "@amritk/lint/types";
5
- import fg from "fast-glob";
6
5
  import yargs from "yargs";
7
6
  import { buildLoadedRuleset, buildPresetRuleset, PRESET_RULESET_NAMES } from "./preset-ruleset.js";
8
- import { createLintResolver } from "./resolver.js";
9
7
  import { discoverRuleset, loadRuleset } from "./ruleset-loader.js";
10
8
  const SEVERITY_BY_NAME = {
11
9
  error: DiagnosticSeverity.Error,
@@ -27,6 +25,19 @@ const formatReport = (findings) => {
27
25
  return `${lines.join("\n")}
28
26
  `;
29
27
  };
28
+ const GLOB_SYNTAX = /[*?[\]{}()!+@|\\]|\/\//;
29
+ const expandDocuments = async (documents) => {
30
+ if (documents.length === 0)
31
+ return [];
32
+ const [only] = documents;
33
+ if (documents.length === 1 && only && !GLOB_SYNTAX.test(only)) {
34
+ const isFile = await stat(only).then((stats) => stats.isFile(), () => false);
35
+ if (isFile)
36
+ return [only];
37
+ }
38
+ const { default: fg } = await import("fast-glob");
39
+ return fg(documents, { dot: true, onlyFiles: true });
40
+ };
30
41
  const readStdin = async () => {
31
42
  const chunks = [];
32
43
  for await (const chunk of process.stdin)
@@ -106,7 +117,7 @@ Run \`mjst lint --help\` for the supported flags.
106
117
  return { code: 0, stdout: "", stderr: "" };
107
118
  const failSeverity = SEVERITY_BY_NAME[parsed.failSeverity] ?? DiagnosticSeverity.Error;
108
119
  const allowRemote = parsed.resolveRemote || (parsed.allowedHosts?.length ?? 0) > 0;
109
- const resolver = parsed.resolve ? createLintResolver({
120
+ const resolver = parsed.resolve ? (await import("./resolver.js")).createLintResolver({
110
121
  remote: allowRemote,
111
122
  ...parsed.allowedHosts ? { allowedHosts: parsed.allowedHosts } : {},
112
123
  allowPrivateHosts: parsed.allowPrivateHosts,
@@ -144,7 +155,7 @@ Run \`mjst lint --help\` for the supported flags.
144
155
  }
145
156
  }
146
157
  const documents = parsed.documents ?? [];
147
- const targets = await fg(documents, { dot: true, onlyFiles: true });
158
+ const targets = await expandDocuments(documents);
148
159
  const allResults = [];
149
160
  if (targets.length === 0 && documents.length > 0) {
150
161
  return { code: 2, stdout: "", stderr: `No files matched: ${documents.join(", ")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/mjst",
3
- "version": "0.27.1",
3
+ "version": "0.27.3",
4
4
  "description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -49,14 +49,14 @@
49
49
  "./package.json": "./package.json"
50
50
  },
51
51
  "dependencies": {
52
- "@amritk/adapters": "^0.6.9",
52
+ "@amritk/adapters": "^0.6.10",
53
53
  "@amritk/api": "^0.16.7",
54
- "@amritk/asyncapi": "^0.3.7",
55
- "@amritk/generate-examples": "^0.8.11",
54
+ "@amritk/asyncapi": "^0.3.8",
55
+ "@amritk/generate-examples": "^0.8.12",
56
56
  "@amritk/generate-markdown": "^0.12.0",
57
- "@amritk/helpers": "^0.25.0",
58
- "@amritk/lint": "^0.8.0",
59
- "@amritk/validation": "^0.6.0",
57
+ "@amritk/helpers": "^0.26.0",
58
+ "@amritk/lint": "^0.9.0",
59
+ "@amritk/validation": "^0.6.1",
60
60
  "@amritk/resolve-refs": "^0.9.0",
61
61
  "@amritk/yaml": "^0.8.0",
62
62
  "fast-glob": "^3.3.2",