@nx-devkit/knip 0.0.1 → 0.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"generator.d.mts","names":[],"sources":["../../../src/generators/init/generator.ts"],"mappings":";;;UAGiB,iBAAA;EACf,UAAU;AAAA;AAAA,iBAKU,aAAA,CACpB,IAAA,EAAM,IAAA,EACN,OAAA,GAAS,iBAAA,GACR,OAAA,CAAQ,iBAAA"}
1
+ {"version":3,"file":"generator.d.mts","names":[],"sources":["../../../src/generators/init/generator.ts"],"mappings":";;;UAGiB,iBAAA;EACf,UAAU;AAAA;AAAA,iBAOU,aAAA,CACpB,IAAA,EAAM,IAAA,EACN,OAAA,GAAS,iBAAA,GACR,OAAA,CAAQ,iBAAA"}
@@ -1,5 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
- import { formatFiles } from "@nx/devkit";
2
+ import { addDependenciesToPackageJson, formatFiles } from "@nx/devkit";
3
3
  //#region \0rolldown/runtime.js
4
4
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
5
5
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
@@ -260,13 +260,31 @@ function resolveRootProjectName(tree) {
260
260
  if (typeof name === "string" && name) return name;
261
261
  }
262
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
+ }
263
279
  //#endregion
264
280
  //#region src/generators/init/generator.ts
281
+ const PEER_DEPS = { knip: "^6.0.0" };
265
282
  const DEFAULT_PLUGIN_PATH = "@nx-devkit/knip";
266
283
  async function initGenerator(tree, options = {}) {
267
284
  const pluginPath = options.pluginPath || DEFAULT_PLUGIN_PATH;
268
285
  const projectName = resolveRootProjectName(tree) ?? "{root-project}";
269
286
  registerPlugin(tree, pluginPath);
287
+ const installDeps = installPeerDeps(tree, PEER_DEPS);
270
288
  const checklist = [
271
289
  `1. The plugin is registered (${pluginPath}) — projects containing a knip config now have knip targets.`,
272
290
  "2. Inspect inferred targets:",
@@ -275,7 +293,7 @@ async function initGenerator(tree, options = {}) {
275
293
  ];
276
294
  for (const line of checklist) console.log(line);
277
295
  await formatFiles(tree);
278
- return () => {};
296
+ return () => installDeps();
279
297
  }
280
298
  //#endregion
281
299
  export { initGenerator as default, initGenerator };
@@ -1 +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 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","import { formatFiles, type GeneratorCallback, type Tree } from '@nx/devkit'\nimport { registerPlugin, resolveRootProjectName } from '@nx-devkit/internal'\n\nexport interface NxKnipInitOptions {\n pluginPath?: string\n}\n\nconst DEFAULT_PLUGIN_PATH = '@nx-devkit/knip'\n\nexport async function initGenerator(\n tree: Tree,\n options: NxKnipInitOptions = {},\n): Promise<GeneratorCallback> {\n const pluginPath = options.pluginPath || DEFAULT_PLUGIN_PATH\n const projectName = resolveRootProjectName(tree) ?? '{root-project}'\n\n registerPlugin(tree, pluginPath)\n\n const checklist = [\n `1. The plugin is registered (${pluginPath}) — projects containing a knip config now have knip targets.`,\n '2. Inspect inferred targets:',\n ' bunx nx show projects',\n `3. Run a target: bunx nx run ${projectName}:knip`,\n ]\n for (const line of checklist) {\n console.log(line)\n }\n await formatFiles(tree)\n\n return () => {\n /* No-op */\n }\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,WAAS,cAAc,EAAE,OAAO,KAAK,CAAC;EAC5D,UAAQ,aAAa,UAAQ,SAAS,UAAQ,SAAS,UAAQ,sBAAsB,UAAQ,iBAAiB,UAAQ,gBAAgB,UAAQ,QAAQ,UAAQ,eAAe,UAAQ,cAAc,UAAQ,mBAAmB,UAAQ,qBAAqB,UAAQ,YAAY,UAAQ,QAAQ,UAAQ,cAAc,UAAQ,aAAa,UAAQ,YAAY,UAAQ,gBAAgB,KAAK;EAC3X,MAAM,YAAY,QAAQ,eAAe;EACzC,MAAM,OAAO,QAAQ,aAAa;EAClC,MAAM,UAAU,QAAQ,gBAAgB;EACxC,MAAM,SAAS,QAAQ,eAAe;;;;;EAKtC,UAAQ,gBAAgB,QAAQ;EAChC,IAAI;EACJ,CA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J,OAAA,GAAA,YAAA,OAAA,CAEE,MACA,MAAM,QAAQ,OAAO,OAAO,IAAI,CAAC,WAAW,QAAQ,MAAM,IAAI,CAAC,SAAS,GACxE,MAAM,QAAQ,OAAO,OAAO,IAAI,QAAQ,CAAC,KAAK,GAC9C;EAAE;EAAmB,kBAAkB;CAAK,CAC9C,CACF;CACA,KAAK,MAAM,WAAW,OAAO;AAC/B;;AAGA,SAAgB,uBAAuB,MAAgC;CACrE,KAAK,MAAM,QAAQ;EAAC;EAAgB;EAAW;CAAc,GAAG;EAC9D,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC,EAAE;EACnC,IAAI,OAAO,SAAS,YAAY,MAC9B,OAAO;CAEX;AAEF;;;ACzDA,MAAM,sBAAsB;AAE5B,eAAsB,cACpB,MACA,UAA6B,CAAC,GACF;CAC5B,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,cAAc,uBAAuB,IAAI,KAAK;CAEpD,eAAe,MAAM,UAAU;CAE/B,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,CAEb;AACF"}
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 NxKnipInitOptions {\n pluginPath?: string\n}\n\nconst PEER_DEPS: Record<string, string> = { knip: '^6.0.0' }\n\nconst DEFAULT_PLUGIN_PATH = '@nx-devkit/knip'\n\nexport async function initGenerator(\n tree: Tree,\n options: NxKnipInitOptions = {},\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 knip config now have knip targets.`,\n '2. Inspect inferred targets:',\n ' bunx nx show projects',\n `3. Run a target: bunx nx run ${projectName}:knip`,\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,UAA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AM,SAAS,MAAM,cAAc,KAAK,CAAC;CAC/C,MAAM,WAAW;EACf,GAAI,IAAI;EACR,GAAI,IAAI;CACV;CACA,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,IAAI,GAC7C,IAAI,EAAE,QAAQ,WAAW,QAAQ,QAAQ;CAE3C,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,WAAW,GAClC,aAAa,CAAC;CAEhB,OAAO,6BAA6B,MAAM,CAAC,GAAG,OAAO;AACvD;;;AC9EA,MAAM,YAAoC,EAAE,MAAM,SAAS;AAE3D,MAAM,sBAAsB;AAE5B,eAAsB,cACpB,MACA,UAA6B,CAAC,GACF;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx-devkit/knip",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "description": "Nx plugin: knip config files infer a cached knip target — dead exports/files/dependencies detection without project.json.",
6
6
  "keywords": [