@nx-devkit/cspell 0.0.0 → 0.0.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,3 +1,53 @@
1
1
  # @nx-devkit/cspell
2
2
 
3
- Placeholder for @nx-devkit/cspell published by @nx-devkit/prepare-for-release.
3
+ Zero-config Nx plugin: a [cspell](https://cspell.org/) config file in your workspace automatically produces a `spell` target — no `project.json` needed.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ nx add @nx-devkit/cspell
9
+ ```
10
+
11
+ The init generator registers the plugin in `nx.json` and installs the missing peer dependency (`cspell`) into devDependencies.
12
+
13
+ ## Usage
14
+
15
+ Any directory containing a cspell config gets a target on the owning project. When several config forms coexist in one directory, the first match in cspell's documented search order wins:
16
+
17
+ | Config file | Inferred target |
18
+ |---|---|
19
+ | `cspell` key in `package.json`, `cspell.json`, `.cspell.json`, `cspell.config.{json,js,cjs,mjs,ts}`, `cspell.{yaml,yml}`, `.cspell.{yaml,yml}` | `spell` |
20
+
21
+ ```bash
22
+ nx run my-app:spell # npx cspell lint .
23
+ nx run-many -t spell # every project with a config
24
+ ```
25
+
26
+ The target is **cached** — its verdict depends only on project file contents and the config.
27
+
28
+ ## Options
29
+
30
+ Register with options in `nx.json`:
31
+
32
+ ```jsonc
33
+ {
34
+ "plugins": [
35
+ {
36
+ "plugin": "@nx-devkit/cspell",
37
+ "options": {
38
+ "targetName": "spell", // default "spell"
39
+ "args": "." // default "."
40
+ }
41
+ }
42
+ ]
43
+ }
44
+ ```
45
+
46
+ | Option | Default | Description |
47
+ |---|---|---|
48
+ | `targetName` | `spell` | Target name. |
49
+ | `args` | `.` | Arguments passed to `cspell lint`, e.g. `"src/**/*.md"` or `"--words-only ."`. |
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,10 @@
1
+ import { GeneratorCallback, Tree } from "@nx/devkit";
2
+
3
+ //#region src/generators/init/generator.d.ts
4
+ interface NxCspellInitOptions {
5
+ pluginPath?: string;
6
+ }
7
+ declare function initGenerator(tree: Tree, options?: NxCspellInitOptions): Promise<GeneratorCallback>;
8
+ //#endregion
9
+ export { NxCspellInitOptions, initGenerator as default, initGenerator };
10
+ //# sourceMappingURL=generator.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.mts","names":[],"sources":["../../../src/generators/init/generator.ts"],"mappings":";;;UAGiB,mBAAA;EACf,UAAU;AAAA;AAAA,iBAOU,aAAA,CACpB,IAAA,EAAM,IAAA,EACN,OAAA,GAAS,mBAAA,GACR,OAAA,CAAQ,iBAAA"}
@@ -0,0 +1,301 @@
1
+ import { createRequire } from "node:module";
2
+ import { addDependenciesToPackageJson, formatFiles } from "@nx/devkit";
3
+ //#region \0rolldown/runtime.js
4
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
5
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
6
+ //#endregion
7
+ //#region ../internal/src/jsonc.ts
8
+ var import_main = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
9
+ (function(factory) {
10
+ if (typeof module === "object" && typeof module.exports === "object") {
11
+ var v = factory(__require, exports);
12
+ if (v !== void 0) module.exports = v;
13
+ } else if (typeof define === "function" && define.amd) define([
14
+ "require",
15
+ "exports",
16
+ "./impl/format",
17
+ "./impl/edit",
18
+ "./impl/scanner",
19
+ "./impl/parser"
20
+ ], factory);
21
+ })(function(require, exports$1) {
22
+ "use strict";
23
+ Object.defineProperty(exports$1, "__esModule", { value: true });
24
+ exports$1.applyEdits = exports$1.modify = exports$1.format = exports$1.printParseErrorCode = exports$1.ParseErrorCode = exports$1.stripComments = exports$1.visit = exports$1.getNodeValue = exports$1.getNodePath = exports$1.findNodeAtOffset = exports$1.findNodeAtLocation = exports$1.parseTree = exports$1.parse = exports$1.getLocation = exports$1.SyntaxKind = exports$1.ScanError = exports$1.createScanner = void 0;
25
+ const formatter = require("./impl/format");
26
+ const edit = require("./impl/edit");
27
+ const scanner = require("./impl/scanner");
28
+ const parser = require("./impl/parser");
29
+ /**
30
+ * Creates a JSON scanner on the given text.
31
+ * If ignoreTrivia is set, whitespaces or comments are ignored.
32
+ */
33
+ exports$1.createScanner = scanner.createScanner;
34
+ var ScanError;
35
+ (function(ScanError) {
36
+ ScanError[ScanError["None"] = 0] = "None";
37
+ ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
38
+ ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
39
+ ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
40
+ ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
41
+ ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
42
+ ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
43
+ })(ScanError || (exports$1.ScanError = ScanError = {}));
44
+ var SyntaxKind;
45
+ (function(SyntaxKind) {
46
+ SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
47
+ SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
48
+ SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
49
+ SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
50
+ SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
51
+ SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
52
+ SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
53
+ SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
54
+ SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
55
+ SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
56
+ SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
57
+ SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
58
+ SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
59
+ SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
60
+ SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
61
+ SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
62
+ SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
63
+ })(SyntaxKind || (exports$1.SyntaxKind = SyntaxKind = {}));
64
+ /**
65
+ * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
66
+ */
67
+ exports$1.getLocation = parser.getLocation;
68
+ /**
69
+ * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
70
+ * Therefore, always check the errors list to find out if the input was valid.
71
+ */
72
+ exports$1.parse = parser.parse;
73
+ /**
74
+ * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
75
+ */
76
+ exports$1.parseTree = parser.parseTree;
77
+ /**
78
+ * Finds the node at the given path in a JSON DOM.
79
+ */
80
+ exports$1.findNodeAtLocation = parser.findNodeAtLocation;
81
+ /**
82
+ * Finds the innermost node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
83
+ */
84
+ exports$1.findNodeAtOffset = parser.findNodeAtOffset;
85
+ /**
86
+ * Gets the JSON path of the given JSON DOM node
87
+ */
88
+ exports$1.getNodePath = parser.getNodePath;
89
+ /**
90
+ * Evaluates the JavaScript object of the given JSON DOM node
91
+ */
92
+ exports$1.getNodeValue = parser.getNodeValue;
93
+ /**
94
+ * Parses the given text and invokes the visitor functions for each object, array and literal reached.
95
+ */
96
+ exports$1.visit = parser.visit;
97
+ /**
98
+ * Takes JSON with JavaScript-style comments and remove
99
+ * them. Optionally replaces every none-newline character
100
+ * of comments with a replaceCharacter
101
+ */
102
+ exports$1.stripComments = parser.stripComments;
103
+ var ParseErrorCode;
104
+ (function(ParseErrorCode) {
105
+ ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
106
+ ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
107
+ ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
108
+ ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
109
+ ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
110
+ ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
111
+ ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
112
+ ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
113
+ ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
114
+ ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
115
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
116
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
117
+ ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
118
+ ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
119
+ ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
120
+ ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
121
+ })(ParseErrorCode || (exports$1.ParseErrorCode = ParseErrorCode = {}));
122
+ function printParseErrorCode(code) {
123
+ switch (code) {
124
+ case 1: return "InvalidSymbol";
125
+ case 2: return "InvalidNumberFormat";
126
+ case 3: return "PropertyNameExpected";
127
+ case 4: return "ValueExpected";
128
+ case 5: return "ColonExpected";
129
+ case 6: return "CommaExpected";
130
+ case 7: return "CloseBraceExpected";
131
+ case 8: return "CloseBracketExpected";
132
+ case 9: return "EndOfFileExpected";
133
+ case 10: return "InvalidCommentToken";
134
+ case 11: return "UnexpectedEndOfComment";
135
+ case 12: return "UnexpectedEndOfString";
136
+ case 13: return "UnexpectedEndOfNumber";
137
+ case 14: return "InvalidUnicode";
138
+ case 15: return "InvalidEscapeCharacter";
139
+ case 16: return "InvalidCharacter";
140
+ }
141
+ return "<unknown ParseErrorCode>";
142
+ }
143
+ exports$1.printParseErrorCode = printParseErrorCode;
144
+ /**
145
+ * Computes the edit operations needed to format a JSON document.
146
+ *
147
+ * @param documentText The input text
148
+ * @param range The range to format or `undefined` to format the full content
149
+ * @param options The formatting options
150
+ * @returns The edit operations describing the formatting changes to the original document following the format described in {@linkcode EditResult}.
151
+ * To apply the edit operations to the input, use {@linkcode applyEdits}.
152
+ */
153
+ function format(documentText, range, options) {
154
+ return formatter.format(documentText, range, options);
155
+ }
156
+ exports$1.format = format;
157
+ /**
158
+ * Computes the edit operations needed to modify a value in the JSON document.
159
+ *
160
+ * @param documentText The input text
161
+ * @param path The path of the value to change. The path represents either to the document root, a property or an array item.
162
+ * If the path points to an non-existing property or item, it will be created.
163
+ * @param value The new value for the specified property or item. If the value is undefined,
164
+ * the property or item will be removed.
165
+ * @param options Options
166
+ * @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.
167
+ * To apply the edit operations to the input, use {@linkcode applyEdits}.
168
+ */
169
+ function modify(text, path, value, options) {
170
+ return edit.setProperty(text, path, value, options);
171
+ }
172
+ exports$1.modify = modify;
173
+ /**
174
+ * Applies edits to an input string.
175
+ * @param text The input text
176
+ * @param edits Edit operations following the format described in {@linkcode EditResult}.
177
+ * @returns The text with the applied edits.
178
+ * @throws An error if the edit operations are not well-formed as described in {@linkcode EditResult}.
179
+ */
180
+ function applyEdits(text, edits) {
181
+ let sortedEdits = edits.slice(0).sort((a, b) => {
182
+ const diff = a.offset - b.offset;
183
+ if (diff === 0) return a.length - b.length;
184
+ return diff;
185
+ });
186
+ let lastModifiedOffset = text.length;
187
+ for (let i = sortedEdits.length - 1; i >= 0; i--) {
188
+ let e = sortedEdits[i];
189
+ if (e.offset + e.length <= lastModifiedOffset) text = edit.applyEdit(text, e);
190
+ else throw new Error("Overlapping edit");
191
+ lastModifiedOffset = e.offset;
192
+ }
193
+ return text;
194
+ }
195
+ exports$1.applyEdits = applyEdits;
196
+ });
197
+ })))();
198
+ function parseJsonObject(text, path) {
199
+ const errors = [];
200
+ const data = (0, import_main.parse)(text, errors, { allowTrailingComma: true });
201
+ if (errors.length > 0) {
202
+ const details = errors.map((e) => `${(0, import_main.printParseErrorCode)(e.error)} at offset ${e.offset}`).join("; ");
203
+ throw new Error(`Cannot parse ${path}: ${details}`);
204
+ }
205
+ if (typeof data !== "object" || data === null || Array.isArray(data)) throw new Error(`Cannot parse ${path}: expected a JSON object`);
206
+ return data;
207
+ }
208
+ function detectIndent(text) {
209
+ const firstProp = (0, import_main.parseTree)(text)?.children?.[0]?.children?.[0];
210
+ const lineStart = firstProp ? text.lastIndexOf("\n", firstProp.offset) + 1 : -1;
211
+ const leading = firstProp ? text.slice(lineStart, firstProp.offset) : "";
212
+ const indent = /^[ \t]+$/.test(leading) ? leading : " ";
213
+ return {
214
+ eol: text.includes("\r\n") ? "\r\n" : "\n",
215
+ insertSpaces: !indent.startsWith(" "),
216
+ tabSize: indent.startsWith(" ") ? 1 : indent.length
217
+ };
218
+ }
219
+ //#endregion
220
+ //#region ../internal/src/init-generator.ts
221
+ function readJson(tree, path) {
222
+ if (!tree.exists(path)) return null;
223
+ const text = tree.read(path, "utf8");
224
+ if (text == null) return null;
225
+ return parseJsonObject(text, path);
226
+ }
227
+ /**
228
+ * Registers `plugin` in nx.json as `{ plugin, options: {} }`, preserving
229
+ * JSONC comments and the file's own indentation. Dedupes string, tuple,
230
+ * and object plugin forms; creates nx.json when missing.
231
+ */
232
+ function registerPlugin(tree, pluginPath) {
233
+ const text = tree.exists("nx.json") ? tree.read("nx.json", "utf8") : null;
234
+ const nxJson = text == null ? {} : parseJsonObject(text, "nx.json");
235
+ const plugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
236
+ if (plugins.some((entry) => typeof entry === "string" && entry === pluginPath || Array.isArray(entry) && entry[0] === pluginPath || typeof entry === "object" && entry !== null && !Array.isArray(entry) && entry.plugin === pluginPath)) return;
237
+ const entry = {
238
+ options: {},
239
+ plugin: pluginPath
240
+ };
241
+ if (text == null) {
242
+ tree.write("nx.json", `${JSON.stringify({ plugins: [entry] }, null, 2)}\n`);
243
+ return;
244
+ }
245
+ const formattingOptions = detectIndent(text);
246
+ const updated = (0, import_main.applyEdits)(text, (0, import_main.modify)(text, Array.isArray(nxJson.plugins) ? ["plugins", plugins.length] : ["plugins"], Array.isArray(nxJson.plugins) ? entry : [entry], {
247
+ formattingOptions,
248
+ isArrayInsertion: true
249
+ }));
250
+ tree.write("nx.json", updated);
251
+ }
252
+ /** Nx names the root project from project.json, then nx.json, then package.json. */
253
+ function resolveRootProjectName(tree) {
254
+ for (const path of [
255
+ "project.json",
256
+ "nx.json",
257
+ "package.json"
258
+ ]) {
259
+ const name = readJson(tree, path)?.name;
260
+ if (typeof name === "string" && name) return name;
261
+ }
262
+ }
263
+ /**
264
+ * Returns a GeneratorCallback that installs `deps` as devDependencies in the
265
+ * consumer's package.json, skipping deps already declared in dependencies or
266
+ * devDependencies. Returns a no-op callback when nothing is missing.
267
+ */
268
+ function installPeerDeps(tree, deps) {
269
+ const pkg = readJson(tree, "package.json") ?? {};
270
+ const existing = {
271
+ ...pkg.dependencies,
272
+ ...pkg.devDependencies
273
+ };
274
+ const missing = {};
275
+ for (const [name, range] of Object.entries(deps)) if (!(name in existing)) missing[name] = range;
276
+ if (Object.keys(missing).length === 0) return () => {};
277
+ return addDependenciesToPackageJson(tree, {}, missing);
278
+ }
279
+ //#endregion
280
+ //#region src/generators/init/generator.ts
281
+ const PEER_DEPS = { cspell: "^9.0.0" };
282
+ const DEFAULT_PLUGIN_PATH = "@nx-devkit/cspell";
283
+ async function initGenerator(tree, options = {}) {
284
+ const pluginPath = options.pluginPath || DEFAULT_PLUGIN_PATH;
285
+ const projectName = resolveRootProjectName(tree) ?? "{root-project}";
286
+ registerPlugin(tree, pluginPath);
287
+ const installDeps = installPeerDeps(tree, PEER_DEPS);
288
+ const checklist = [
289
+ `1. The plugin is registered (${pluginPath}) — projects containing a cspell config now have spell targets.`,
290
+ "2. Inspect inferred targets:",
291
+ " bunx nx show projects",
292
+ `3. Run a target: bunx nx run ${projectName}:spell`
293
+ ];
294
+ for (const line of checklist) console.log(line);
295
+ await formatFiles(tree);
296
+ return () => installDeps();
297
+ }
298
+ //#endregion
299
+ export { initGenerator as default, initGenerator };
300
+
301
+ //# sourceMappingURL=generator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.mjs","names":["exports"],"sources":["../../../../../node_modules/.bun/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/umd/main.js","../../../../internal/src/jsonc.ts","../../../../internal/src/init-generator.ts","../../../src/generators/init/generator.ts"],"sourcesContent":["(function (factory) {\n if (typeof module === \"object\" && typeof module.exports === \"object\") {\n var v = factory(require, exports);\n if (v !== undefined) module.exports = v;\n }\n else if (typeof define === \"function\" && define.amd) {\n define([\"require\", \"exports\", \"./impl/format\", \"./impl/edit\", \"./impl/scanner\", \"./impl/parser\"], factory);\n }\n})(function (require, exports) {\n /*---------------------------------------------------------------------------------------------\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License. See License.txt in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n 'use strict';\n Object.defineProperty(exports, \"__esModule\", { value: true });\n exports.applyEdits = exports.modify = exports.format = exports.printParseErrorCode = exports.ParseErrorCode = exports.stripComments = exports.visit = exports.getNodeValue = exports.getNodePath = exports.findNodeAtOffset = exports.findNodeAtLocation = exports.parseTree = exports.parse = exports.getLocation = exports.SyntaxKind = exports.ScanError = exports.createScanner = void 0;\n const formatter = require(\"./impl/format\");\n const edit = require(\"./impl/edit\");\n const scanner = require(\"./impl/scanner\");\n const parser = require(\"./impl/parser\");\n /**\n * Creates a JSON scanner on the given text.\n * If ignoreTrivia is set, whitespaces or comments are ignored.\n */\n exports.createScanner = scanner.createScanner;\n var ScanError;\n (function (ScanError) {\n ScanError[ScanError[\"None\"] = 0] = \"None\";\n ScanError[ScanError[\"UnexpectedEndOfComment\"] = 1] = \"UnexpectedEndOfComment\";\n ScanError[ScanError[\"UnexpectedEndOfString\"] = 2] = \"UnexpectedEndOfString\";\n ScanError[ScanError[\"UnexpectedEndOfNumber\"] = 3] = \"UnexpectedEndOfNumber\";\n ScanError[ScanError[\"InvalidUnicode\"] = 4] = \"InvalidUnicode\";\n ScanError[ScanError[\"InvalidEscapeCharacter\"] = 5] = \"InvalidEscapeCharacter\";\n ScanError[ScanError[\"InvalidCharacter\"] = 6] = \"InvalidCharacter\";\n })(ScanError || (exports.ScanError = ScanError = {}));\n var SyntaxKind;\n (function (SyntaxKind) {\n SyntaxKind[SyntaxKind[\"OpenBraceToken\"] = 1] = \"OpenBraceToken\";\n SyntaxKind[SyntaxKind[\"CloseBraceToken\"] = 2] = \"CloseBraceToken\";\n SyntaxKind[SyntaxKind[\"OpenBracketToken\"] = 3] = \"OpenBracketToken\";\n SyntaxKind[SyntaxKind[\"CloseBracketToken\"] = 4] = \"CloseBracketToken\";\n SyntaxKind[SyntaxKind[\"CommaToken\"] = 5] = \"CommaToken\";\n SyntaxKind[SyntaxKind[\"ColonToken\"] = 6] = \"ColonToken\";\n SyntaxKind[SyntaxKind[\"NullKeyword\"] = 7] = \"NullKeyword\";\n SyntaxKind[SyntaxKind[\"TrueKeyword\"] = 8] = \"TrueKeyword\";\n SyntaxKind[SyntaxKind[\"FalseKeyword\"] = 9] = \"FalseKeyword\";\n SyntaxKind[SyntaxKind[\"StringLiteral\"] = 10] = \"StringLiteral\";\n SyntaxKind[SyntaxKind[\"NumericLiteral\"] = 11] = \"NumericLiteral\";\n SyntaxKind[SyntaxKind[\"LineCommentTrivia\"] = 12] = \"LineCommentTrivia\";\n SyntaxKind[SyntaxKind[\"BlockCommentTrivia\"] = 13] = \"BlockCommentTrivia\";\n SyntaxKind[SyntaxKind[\"LineBreakTrivia\"] = 14] = \"LineBreakTrivia\";\n SyntaxKind[SyntaxKind[\"Trivia\"] = 15] = \"Trivia\";\n SyntaxKind[SyntaxKind[\"Unknown\"] = 16] = \"Unknown\";\n SyntaxKind[SyntaxKind[\"EOF\"] = 17] = \"EOF\";\n })(SyntaxKind || (exports.SyntaxKind = SyntaxKind = {}));\n /**\n * For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.\n */\n exports.getLocation = parser.getLocation;\n /**\n * Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.\n * Therefore, always check the errors list to find out if the input was valid.\n */\n exports.parse = parser.parse;\n /**\n * Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.\n */\n exports.parseTree = parser.parseTree;\n /**\n * Finds the node at the given path in a JSON DOM.\n */\n exports.findNodeAtLocation = parser.findNodeAtLocation;\n /**\n * Finds the innermost node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.\n */\n exports.findNodeAtOffset = parser.findNodeAtOffset;\n /**\n * Gets the JSON path of the given JSON DOM node\n */\n exports.getNodePath = parser.getNodePath;\n /**\n * Evaluates the JavaScript object of the given JSON DOM node\n */\n exports.getNodeValue = parser.getNodeValue;\n /**\n * Parses the given text and invokes the visitor functions for each object, array and literal reached.\n */\n exports.visit = parser.visit;\n /**\n * Takes JSON with JavaScript-style comments and remove\n * them. Optionally replaces every none-newline character\n * of comments with a replaceCharacter\n */\n exports.stripComments = parser.stripComments;\n var ParseErrorCode;\n (function (ParseErrorCode) {\n ParseErrorCode[ParseErrorCode[\"InvalidSymbol\"] = 1] = \"InvalidSymbol\";\n ParseErrorCode[ParseErrorCode[\"InvalidNumberFormat\"] = 2] = \"InvalidNumberFormat\";\n ParseErrorCode[ParseErrorCode[\"PropertyNameExpected\"] = 3] = \"PropertyNameExpected\";\n ParseErrorCode[ParseErrorCode[\"ValueExpected\"] = 4] = \"ValueExpected\";\n ParseErrorCode[ParseErrorCode[\"ColonExpected\"] = 5] = \"ColonExpected\";\n ParseErrorCode[ParseErrorCode[\"CommaExpected\"] = 6] = \"CommaExpected\";\n ParseErrorCode[ParseErrorCode[\"CloseBraceExpected\"] = 7] = \"CloseBraceExpected\";\n ParseErrorCode[ParseErrorCode[\"CloseBracketExpected\"] = 8] = \"CloseBracketExpected\";\n ParseErrorCode[ParseErrorCode[\"EndOfFileExpected\"] = 9] = \"EndOfFileExpected\";\n ParseErrorCode[ParseErrorCode[\"InvalidCommentToken\"] = 10] = \"InvalidCommentToken\";\n ParseErrorCode[ParseErrorCode[\"UnexpectedEndOfComment\"] = 11] = \"UnexpectedEndOfComment\";\n ParseErrorCode[ParseErrorCode[\"UnexpectedEndOfString\"] = 12] = \"UnexpectedEndOfString\";\n ParseErrorCode[ParseErrorCode[\"UnexpectedEndOfNumber\"] = 13] = \"UnexpectedEndOfNumber\";\n ParseErrorCode[ParseErrorCode[\"InvalidUnicode\"] = 14] = \"InvalidUnicode\";\n ParseErrorCode[ParseErrorCode[\"InvalidEscapeCharacter\"] = 15] = \"InvalidEscapeCharacter\";\n ParseErrorCode[ParseErrorCode[\"InvalidCharacter\"] = 16] = \"InvalidCharacter\";\n })(ParseErrorCode || (exports.ParseErrorCode = ParseErrorCode = {}));\n function printParseErrorCode(code) {\n switch (code) {\n case 1 /* ParseErrorCode.InvalidSymbol */: return 'InvalidSymbol';\n case 2 /* ParseErrorCode.InvalidNumberFormat */: return 'InvalidNumberFormat';\n case 3 /* ParseErrorCode.PropertyNameExpected */: return 'PropertyNameExpected';\n case 4 /* ParseErrorCode.ValueExpected */: return 'ValueExpected';\n case 5 /* ParseErrorCode.ColonExpected */: return 'ColonExpected';\n case 6 /* ParseErrorCode.CommaExpected */: return 'CommaExpected';\n case 7 /* ParseErrorCode.CloseBraceExpected */: return 'CloseBraceExpected';\n case 8 /* ParseErrorCode.CloseBracketExpected */: return 'CloseBracketExpected';\n case 9 /* ParseErrorCode.EndOfFileExpected */: return 'EndOfFileExpected';\n case 10 /* ParseErrorCode.InvalidCommentToken */: return 'InvalidCommentToken';\n case 11 /* ParseErrorCode.UnexpectedEndOfComment */: return 'UnexpectedEndOfComment';\n case 12 /* ParseErrorCode.UnexpectedEndOfString */: return 'UnexpectedEndOfString';\n case 13 /* ParseErrorCode.UnexpectedEndOfNumber */: return 'UnexpectedEndOfNumber';\n case 14 /* ParseErrorCode.InvalidUnicode */: return 'InvalidUnicode';\n case 15 /* ParseErrorCode.InvalidEscapeCharacter */: return 'InvalidEscapeCharacter';\n case 16 /* ParseErrorCode.InvalidCharacter */: return 'InvalidCharacter';\n }\n return '<unknown ParseErrorCode>';\n }\n exports.printParseErrorCode = printParseErrorCode;\n /**\n * Computes the edit operations needed to format a JSON document.\n *\n * @param documentText The input text\n * @param range The range to format or `undefined` to format the full content\n * @param options The formatting options\n * @returns The edit operations describing the formatting changes to the original document following the format described in {@linkcode EditResult}.\n * To apply the edit operations to the input, use {@linkcode applyEdits}.\n */\n function format(documentText, range, options) {\n return formatter.format(documentText, range, options);\n }\n exports.format = format;\n /**\n * Computes the edit operations needed to modify a value in the JSON document.\n *\n * @param documentText The input text\n * @param path The path of the value to change. The path represents either to the document root, a property or an array item.\n * If the path points to an non-existing property or item, it will be created.\n * @param value The new value for the specified property or item. If the value is undefined,\n * the property or item will be removed.\n * @param options Options\n * @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.\n * To apply the edit operations to the input, use {@linkcode applyEdits}.\n */\n function modify(text, path, value, options) {\n return edit.setProperty(text, path, value, options);\n }\n exports.modify = modify;\n /**\n * Applies edits to an input string.\n * @param text The input text\n * @param edits Edit operations following the format described in {@linkcode EditResult}.\n * @returns The text with the applied edits.\n * @throws An error if the edit operations are not well-formed as described in {@linkcode EditResult}.\n */\n function applyEdits(text, edits) {\n let sortedEdits = edits.slice(0).sort((a, b) => {\n const diff = a.offset - b.offset;\n if (diff === 0) {\n return a.length - b.length;\n }\n return diff;\n });\n let lastModifiedOffset = text.length;\n for (let i = sortedEdits.length - 1; i >= 0; i--) {\n let e = sortedEdits[i];\n if (e.offset + e.length <= lastModifiedOffset) {\n text = edit.applyEdit(text, e);\n }\n else {\n throw new Error('Overlapping edit');\n }\n lastModifiedOffset = e.offset;\n }\n return text;\n }\n exports.applyEdits = applyEdits;\n});\n","import { parse, type ParseError, parseTree, printParseErrorCode } from 'jsonc-parser'\n\nexport function parseJsonObject(text: string, path: string): Record<string, unknown> {\n const errors: ParseError[] = []\n const data = parse(text, errors, { allowTrailingComma: true }) as unknown\n if (errors.length > 0) {\n const details = errors\n .map((e) => `${printParseErrorCode(e.error)} at offset ${e.offset}`)\n .join('; ')\n throw new Error(`Cannot parse ${path}: ${details}`)\n }\n if (typeof data !== 'object' || data === null || Array.isArray(data)) {\n throw new Error(`Cannot parse ${path}: expected a JSON object`)\n }\n return data as Record<string, unknown>\n}\n\nexport function detectIndent(text: string): {\n eol: string\n insertSpaces: boolean\n tabSize: number\n} {\n // Anchor on the first real property of the root object so quoted lines\n // Inside comments cannot skew the detected indentation.\n const root = parseTree(text)\n const firstProp = root?.children?.[0]?.children?.[0]\n const lineStart = firstProp ? text.lastIndexOf('\\n', firstProp.offset) + 1 : -1\n const leading = firstProp ? text.slice(lineStart, firstProp.offset) : ''\n const indent = /^[ \\t]+$/.test(leading) ? leading : ' '\n return {\n eol: text.includes('\\r\\n') ? '\\r\\n' : '\\n',\n insertSpaces: !indent.startsWith('\\t'),\n tabSize: indent.startsWith('\\t') ? 1 : indent.length,\n }\n}\n","import { addDependenciesToPackageJson, type GeneratorCallback, type Tree } from '@nx/devkit'\nimport { applyEdits, modify } from 'jsonc-parser'\nimport { detectIndent, parseJsonObject } from './jsonc.ts'\n\nexport function readJson(tree: Tree, path: string): Record<string, unknown> | null {\n if (!tree.exists(path)) {\n return null\n }\n const text = tree.read(path, 'utf8')\n if (text == null) {\n return null\n }\n return parseJsonObject(text, path)\n}\n\n/**\n * Registers `plugin` in nx.json as `{ plugin, options: {} }`, preserving\n * JSONC comments and the file's own indentation. Dedupes string, tuple,\n * and object plugin forms; creates nx.json when missing.\n */\nexport function registerPlugin(tree: Tree, pluginPath: string): void {\n const text = tree.exists('nx.json') ? tree.read('nx.json', 'utf8') : null\n const nxJson = text == null ? {} : parseJsonObject(text, 'nx.json')\n const plugins = Array.isArray(nxJson.plugins) ? (nxJson.plugins as unknown[]) : []\n const alreadyRegistered = plugins.some(\n (entry) =>\n (typeof entry === 'string' && entry === pluginPath) ||\n (Array.isArray(entry) && entry[0] === pluginPath) ||\n (typeof entry === 'object' &&\n entry !== null &&\n !Array.isArray(entry) &&\n (entry as { plugin?: string }).plugin === pluginPath),\n )\n if (alreadyRegistered) {\n return\n }\n\n const entry = { options: {}, plugin: pluginPath }\n if (text == null) {\n tree.write('nx.json', `${JSON.stringify({ plugins: [entry] }, null, 2)}\\n`)\n return\n }\n const formattingOptions = detectIndent(text)\n const updated = applyEdits(\n text,\n modify(\n text,\n Array.isArray(nxJson.plugins) ? ['plugins', plugins.length] : ['plugins'],\n Array.isArray(nxJson.plugins) ? entry : [entry],\n { formattingOptions, isArrayInsertion: true },\n ),\n )\n tree.write('nx.json', updated)\n}\n\n/** Nx names the root project from project.json, then nx.json, then package.json. */\nexport function resolveRootProjectName(tree: Tree): string | undefined {\n for (const path of ['project.json', 'nx.json', 'package.json']) {\n const name = readJson(tree, path)?.name\n if (typeof name === 'string' && name) {\n return name\n }\n }\n return undefined\n}\n\n/**\n * Returns a GeneratorCallback that installs `deps` as devDependencies in the\n * consumer's package.json, skipping deps already declared in dependencies or\n * devDependencies. Returns a no-op callback when nothing is missing.\n */\nexport function installPeerDeps(tree: Tree, deps: Record<string, string>): GeneratorCallback {\n const pkg = readJson(tree, 'package.json') ?? {}\n const existing = {\n ...(pkg.dependencies as Record<string, string> | undefined),\n ...(pkg.devDependencies as Record<string, string> | undefined),\n }\n const missing: Record<string, string> = {}\n for (const [name, range] of Object.entries(deps)) {\n if (!(name in existing)) missing[name] = range\n }\n if (Object.keys(missing).length === 0) {\n return () => {}\n }\n return addDependenciesToPackageJson(tree, {}, missing)\n}\n","import { formatFiles, type GeneratorCallback, type Tree } from '@nx/devkit'\nimport { installPeerDeps, registerPlugin, resolveRootProjectName } from '@nx-devkit/internal'\n\nexport interface NxCspellInitOptions {\n pluginPath?: string\n}\n\nconst PEER_DEPS: Record<string, string> = { cspell: '^9.0.0' }\n\nconst DEFAULT_PLUGIN_PATH = '@nx-devkit/cspell'\n\nexport async function initGenerator(\n tree: Tree,\n options: NxCspellInitOptions = {},\n): Promise<GeneratorCallback> {\n const pluginPath = options.pluginPath || DEFAULT_PLUGIN_PATH\n const projectName = resolveRootProjectName(tree) ?? '{root-project}'\n\n registerPlugin(tree, pluginPath)\n const installDeps = installPeerDeps(tree, PEER_DEPS)\n\n const checklist = [\n `1. The plugin is registered (${pluginPath}) — projects containing a cspell config now have spell targets.`,\n '2. Inspect inferred targets:',\n ' bunx nx show projects',\n `3. Run a target: bunx nx run ${projectName}:spell`,\n ]\n for (const line of checklist) {\n console.log(line)\n }\n await formatFiles(tree)\n\n return () => installDeps()\n}\n\nexport default initGenerator\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;CAAA,CAAC,SAAU,SAAS;EAChB,IAAI,OAAO,WAAW,YAAY,OAAO,OAAO,YAAY,UAAU;GAClE,IAAI,IAAI,QAAA,WAAiB,OAAO;GAChC,IAAI,MAAM,KAAA,GAAW,OAAO,UAAU;EAC1C,OACK,IAAI,OAAO,WAAW,cAAc,OAAO,KAC5C,OAAO;GAAC;GAAW;GAAW;GAAiB;GAAe;GAAkB;EAAe,GAAG,OAAO;CAEjH,EAAA,CAAG,SAAU,SAAS,WAAS;EAK3B;EACA,OAAO,eAAeA,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AAC,WAAW,GAClC,aAAa,CAAC;CAEhB,OAAO,6BAA6B,MAAM,CAAC,GAAG,OAAO;AACvD;;;AC9EA,MAAM,YAAoC,EAAE,QAAQ,SAAS;AAE7D,MAAM,sBAAsB;AAE5B,eAAsB,cACpB,MACA,UAA+B,CAAC,GACJ;CAC5B,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,cAAc,uBAAuB,IAAI,KAAK;CAEpD,eAAe,MAAM,UAAU;CAC/B,MAAM,cAAc,gBAAgB,MAAM,SAAS;CAEnD,MAAM,YAAY;EAChB,gCAAgC,WAAW;EAC3C;EACA;EACA,iCAAiC,YAAY;CAC/C;CACA,KAAK,MAAM,QAAQ,WACjB,QAAQ,IAAI,IAAI;CAElB,MAAM,YAAY,IAAI;CAEtB,aAAa,YAAY;AAC3B"}
@@ -0,0 +1,20 @@
1
+ import { CreateNodesV2 } from "@nx/devkit";
2
+
3
+ //#region src/plugin.d.ts
4
+ interface NxCspellPluginOptions {
5
+ /** Name of the spell-check target. Default: "spell". */
6
+ targetName?: string;
7
+ /** Arguments passed to `cspell lint`. Default: ".". */
8
+ args?: string;
9
+ }
10
+ declare function configRank(fileName: string): number;
11
+ declare function hasCspellKey(absPath: string): boolean;
12
+ declare const createNodesV2: CreateNodesV2<NxCspellPluginOptions>;
13
+ declare const __testing: {
14
+ CSPELL_GLOB: string;
15
+ configRank: typeof configRank;
16
+ hasCspellKey: typeof hasCspellKey;
17
+ };
18
+ //#endregion
19
+ export { NxCspellPluginOptions, __testing, createNodesV2, createNodesV2 as default };
20
+ //# sourceMappingURL=plugin.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;UAIiB,qBAAA;;EAEf,UAAA;EAFoC;EAIpC,IAAI;AAAA;AAAA,iBAuBG,UAAA,CAAW,QAAgB;AAAA,iBAK3B,YAAA,CAAa,OAAe;AAAA,cAgBxB,aAAA,EAAe,aAAa,CAAC,qBAAA;AAAA,cAsD7B,SAAA;;qBAAqD,UAAA;uBAAA,YAAA;AAAA"}
@@ -0,0 +1,82 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, relative, resolve } from "node:path";
3
+ //#region src/plugin.ts
4
+ const CSPELL_GLOB = "**/{cspell.json,cspell.config.js,cspell.config.cjs,cspell.config.mjs,cspell.config.ts,cspell.config.json,.cspell.json,cspell.yaml,cspell.yml,.cspell.yaml,.cspell.yml,package.json}";
5
+ const PRECEDENCE = [
6
+ "package.json",
7
+ "cspell.json",
8
+ ".cspell.json",
9
+ "cspell.config.json",
10
+ "cspell.config.js",
11
+ "cspell.config.cjs",
12
+ "cspell.config.mjs",
13
+ "cspell.config.ts",
14
+ "cspell.yaml",
15
+ "cspell.yml",
16
+ ".cspell.yaml",
17
+ ".cspell.yml"
18
+ ];
19
+ function configRank(fileName) {
20
+ const idx = PRECEDENCE.indexOf(fileName);
21
+ return idx === -1 ? PRECEDENCE.length : idx;
22
+ }
23
+ function hasCspellKey(absPath) {
24
+ try {
25
+ const pkg = JSON.parse(readFileSync(absPath, "utf8"));
26
+ return typeof pkg === "object" && pkg !== null && "cspell" in pkg;
27
+ } catch {
28
+ return false;
29
+ }
30
+ }
31
+ function shouldSkipDir(projectRoot, workspaceRoot) {
32
+ const rel = relative(workspaceRoot, resolve(workspaceRoot, projectRoot || "."));
33
+ if (rel === "") return false;
34
+ const segments = rel.split(/[\\/]/);
35
+ return segments.includes("..") || segments.includes("node_modules");
36
+ }
37
+ const createNodesV2 = [CSPELL_GLOB, (configFiles, options = {}, context) => {
38
+ const workspaceRoot = context.workspaceRoot;
39
+ const targetName = options.targetName ?? "spell";
40
+ const args = options.args ?? ".";
41
+ const byDir = /* @__PURE__ */ new Map();
42
+ for (const configFile of [...configFiles].sort()) {
43
+ const dir = dirname(configFile).replace(/\\/g, "/");
44
+ const key = dir === "." ? "" : dir;
45
+ const list = byDir.get(key) ?? [];
46
+ list.push(configFile);
47
+ byDir.set(key, list);
48
+ }
49
+ const results = [];
50
+ for (const [dir, files] of [...byDir.entries()].sort(([a], [b]) => a.localeCompare(b))) {
51
+ if (shouldSkipDir(dir, workspaceRoot)) continue;
52
+ const sorted = files.toSorted((a, b) => configRank(a.split("/").pop() ?? "") - configRank(b.split("/").pop() ?? ""));
53
+ const winner = sorted.at(0);
54
+ if (winner === void 0) continue;
55
+ if (winner.split("/").pop() === "package.json" && !hasCspellKey(resolve(workspaceRoot, winner))) continue;
56
+ const prefix = dir ? "{projectRoot}" : "{workspaceRoot}";
57
+ const configInputs = sorted.map((f) => `${prefix}/${dir ? f.slice(dir.length + 1) : f}`);
58
+ const targets = { [targetName]: {
59
+ executor: "nx:run-commands",
60
+ cache: true,
61
+ inputs: [`${prefix}/**/*`, ...configInputs],
62
+ options: {
63
+ command: `npx cspell lint ${args}`,
64
+ cwd: "{projectRoot}"
65
+ }
66
+ } };
67
+ results.push([winner, { projects: { [dir]: {
68
+ root: dir,
69
+ targets
70
+ } } }]);
71
+ }
72
+ return results;
73
+ }];
74
+ const __testing = {
75
+ CSPELL_GLOB,
76
+ configRank,
77
+ hasCspellKey
78
+ };
79
+ //#endregion
80
+ export { __testing, createNodesV2, createNodesV2 as default };
81
+
82
+ //# sourceMappingURL=plugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import { readFileSync } from 'node:fs'\nimport { dirname, relative, resolve } from 'node:path'\nimport type { CreateNodesV2, ProjectConfiguration, TargetConfiguration } from '@nx/devkit'\n\nexport interface NxCspellPluginOptions {\n /** Name of the spell-check target. Default: \"spell\". */\n targetName?: string\n /** Arguments passed to `cspell lint`. Default: \".\". */\n args?: string\n}\n\n// Cspell config search places — cspell auto-discovers all of them when run from the owning directory.\nconst CSPELL_GLOB =\n '**/{cspell.json,cspell.config.js,cspell.config.cjs,cspell.config.mjs,cspell.config.ts,cspell.config.json,.cspell.json,cspell.yaml,cspell.yml,.cspell.yaml,.cspell.yml,package.json}'\n\n// Deterministic precedence when several config forms live in one directory — mirrors cspell's documented search order.\nconst PRECEDENCE = [\n 'package.json',\n 'cspell.json',\n '.cspell.json',\n 'cspell.config.json',\n 'cspell.config.js',\n 'cspell.config.cjs',\n 'cspell.config.mjs',\n 'cspell.config.ts',\n 'cspell.yaml',\n 'cspell.yml',\n '.cspell.yaml',\n '.cspell.yml',\n]\n\nfunction configRank(fileName: string): number {\n const idx = PRECEDENCE.indexOf(fileName)\n return idx === -1 ? PRECEDENCE.length : idx\n}\n\nfunction hasCspellKey(absPath: string): boolean {\n try {\n const pkg = JSON.parse(readFileSync(absPath, 'utf8'))\n return typeof pkg === 'object' && pkg !== null && 'cspell' in pkg\n } catch {\n return false\n }\n}\n\nfunction shouldSkipDir(projectRoot: string, workspaceRoot: string): boolean {\n const rel = relative(workspaceRoot, resolve(workspaceRoot, projectRoot || '.'))\n if (rel === '') return false\n const segments = rel.split(/[\\\\/]/)\n return segments.includes('..') || segments.includes('node_modules')\n}\n\nexport const createNodesV2: CreateNodesV2<NxCspellPluginOptions> = [\n CSPELL_GLOB,\n (configFiles, options = {}, context) => {\n const workspaceRoot = context.workspaceRoot\n const targetName = options.targetName ?? 'spell'\n const args = options.args ?? '.'\n\n // One target per owning directory — the highest-precedence config wins.\n const byDir = new Map<string, string[]>()\n for (const configFile of [...configFiles].sort()) {\n const dir = dirname(configFile).replace(/\\\\/g, '/')\n const key = dir === '.' ? '' : dir\n const list = byDir.get(key) ?? []\n list.push(configFile)\n byDir.set(key, list)\n }\n\n const results: Array<readonly [string, { projects: Record<string, ProjectConfiguration> }]> = []\n for (const [dir, files] of [...byDir.entries()].sort(([a], [b]) => a.localeCompare(b))) {\n if (shouldSkipDir(dir, workspaceRoot)) continue\n\n const sorted = files.toSorted(\n (a, b) => configRank(a.split('/').pop() ?? '') - configRank(b.split('/').pop() ?? ''),\n )\n const winner = sorted.at(0)\n if (winner === undefined) continue\n if (\n winner.split('/').pop() === 'package.json' &&\n !hasCspellKey(resolve(workspaceRoot, winner))\n )\n continue\n\n const prefix = dir ? '{projectRoot}' : '{workspaceRoot}'\n // Every cspell-bearing file in the dir is an input — paths are relative to the project root (\"\" for the root project).\n const configInputs = sorted.map((f) => `${prefix}/${dir ? f.slice(dir.length + 1) : f}`)\n\n // The verdict depends on project file contents — cacheable.\n const targets: Record<string, TargetConfiguration> = {\n [targetName]: {\n executor: 'nx:run-commands',\n cache: true,\n inputs: [`${prefix}/**/*`, ...configInputs],\n options: { command: `npx cspell lint ${args}`, cwd: '{projectRoot}' },\n },\n }\n\n results.push([winner, { projects: { [dir]: { root: dir, targets } } }])\n }\n return results\n },\n]\n\nexport default createNodesV2\n\nexport const __testing = { CSPELL_GLOB, configRank, hasCspellKey }\n"],"mappings":";;;AAYA,MAAM,cACJ;AAGF,MAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,WAAW,UAA0B;CAC5C,MAAM,MAAM,WAAW,QAAQ,QAAQ;CACvC,OAAO,QAAQ,KAAK,WAAW,SAAS;AAC1C;AAEA,SAAS,aAAa,SAA0B;CAC9C,IAAI;EACF,MAAM,MAAM,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC;EACpD,OAAO,OAAO,QAAQ,YAAY,QAAQ,QAAQ,YAAY;CAChE,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,cAAc,aAAqB,eAAgC;CAC1E,MAAM,MAAM,SAAS,eAAe,QAAQ,eAAe,eAAe,GAAG,CAAC;CAC9E,IAAI,QAAQ,IAAI,OAAO;CACvB,MAAM,WAAW,IAAI,MAAM,OAAO;CAClC,OAAO,SAAS,SAAS,IAAI,KAAK,SAAS,SAAS,cAAc;AACpE;AAEA,MAAa,gBAAsD,CACjE,cACC,aAAa,UAAU,CAAC,GAAG,YAAY;CACtC,MAAM,gBAAgB,QAAQ;CAC9B,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,OAAO,QAAQ,Q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AK;EAAQ,EAAE,EAAE,CAAC,CAAC;CACxE;CACA,OAAO;AACT,CACF;AAIA,MAAa,YAAY;CAAE;CAAa;CAAY;AAAa"}
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "generators": {
4
+ "init": {
5
+ "factory": "./dist/generators/init/generator.mjs",
6
+ "schema": "./src/generators/init/schema.json",
7
+ "description": "Registers @nx-devkit/cspell in nx.json plugins."
8
+ }
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
- "bugs": {
3
- "url": "https://github.com/nx-devkit/nx.ts/issues"
4
- },
5
- "description": "Placeholder for @nx-devkit/cspell published by @nx-devkit/prepare-for-release.",
6
- "homepage": "https://github.com/nx-devkit/nx.ts/tree/main/packages/cspell",
2
+ "name": "@nx-devkit/cspell",
3
+ "version": "0.0.1",
7
4
  "license": "MIT",
5
+ "description": "Nx plugin: cspell config files infer a cached spell-check target — zero-config spelling lint without project.json.",
8
6
  "keywords": [
9
7
  "nx",
10
8
  "nx-plugin",
@@ -13,16 +11,53 @@
13
11
  "lint",
14
12
  "zero-config"
15
13
  ],
16
- "name": "@nx-devkit/cspell",
17
- "publishConfig": {
18
- "access": "public",
19
- "registry": "https://registry.npmjs.org/"
14
+ "private": false,
15
+ "type": "module",
16
+ "main": "./dist/plugin.mjs",
17
+ "module": "./dist/plugin.mjs",
18
+ "types": "./dist/plugin.d.mts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/plugin.d.mts",
22
+ "default": "./dist/plugin.mjs"
23
+ },
24
+ "./package.json": "./package.json",
25
+ "./generators/init": {
26
+ "types": "./dist/generators/init/generator.d.mts",
27
+ "default": "./dist/generators/init/generator.mjs"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "generators.json",
33
+ "src/generators/init/schema.json",
34
+ "README.md"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsdown",
38
+ "test": "vitest run"
39
+ },
40
+ "peerDependencies": {
41
+ "cspell": "^9.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@nx-devkit/internal": "0.0.0",
45
+ "@types/node": "^26.0.0",
46
+ "tsdown": "^0.22.3",
47
+ "typescript": "^6.0.3",
48
+ "vitest": "^4.1.11"
20
49
  },
21
50
  "repository": {
22
51
  "type": "git",
23
52
  "url": "https://github.com/nx-devkit/nx.ts",
24
53
  "directory": "packages/cspell"
25
54
  },
26
- "type": "module",
27
- "version": "0.0.0"
28
- }
55
+ "bugs": {
56
+ "url": "https://github.com/nx-devkit/nx.ts/issues"
57
+ },
58
+ "homepage": "https://github.com/nx-devkit/nx.ts/tree/main/packages/cspell",
59
+ "dependencies": {
60
+ "@nx/devkit": "^22.0.0 || ^23.0.0"
61
+ },
62
+ "generators": "./generators.json"
63
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "type": "object",
4
+ "title": "Init generator",
5
+ "description": "Registers @nx-devkit/cspell in nx.json plugins.",
6
+ "properties": {
7
+ "pluginPath": {
8
+ "type": "string",
9
+ "default": "@nx-devkit/cspell",
10
+ "minLength": 1,
11
+ "description": "Plugin specifier to register (e.g. a local path during development)."
12
+ }
13
+ },
14
+ "additionalProperties": false
15
+ }