@hublo/sentinel 1.7.0-alpha.1 → 1.7.0-alpha.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.
- package/dist/bin/sentinel.js +74 -13
- package/dist/chunk-4UUL4SEW.js +50 -0
- package/dist/{chunk-XGMMTX2N.js → chunk-DLGBRLUU.js} +2 -2
- package/dist/{chunk-7CRRGBHI.js → chunk-EETHWJBF.js} +78 -21
- package/dist/{chunk-ZVHUG6CA.js → chunk-H4HAFJFZ.js} +4 -13
- package/dist/chunk-H4HAFJFZ.js.map +1 -0
- package/dist/{chunk-POZDYETY.js → chunk-LNFGVGLE.js} +5 -3
- package/dist/{chunk-POZDYETY.js.map → chunk-LNFGVGLE.js.map} +1 -1
- package/dist/chunk-QXFCZON7.js +16 -0
- package/dist/chunk-QXFCZON7.js.map +1 -0
- package/dist/{chunk-7E6YTTAK.js → chunk-THTXP2QU.js} +1 -1
- package/dist/chunk-THTXP2QU.js.map +1 -0
- package/dist/{chunk-4HYOGCOX.js → chunk-Z3JI7ZWX.js} +158 -199
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/migrate-NI33SXZD.js +517 -0
- package/dist/roles/build/nest/toolchain.js +3 -2
- package/dist/roles/build/nest/toolchain.js.map +1 -1
- package/dist/roles/static-analysis/config.js +1 -1
- package/dist/roles/test/nest/toolchain.js +4 -3
- package/dist/roles/test/nest/toolchain.js.map +1 -1
- package/dist/roles/test/react/toolchain.js +4 -3
- package/dist/roles/test/react/toolchain.js.map +1 -1
- package/dist/roles/test/shared-test-config.js +4 -3
- package/dist/tsconfig/legacy.json +21 -0
- package/dist/tsconfig/nest.json +10 -1
- package/dist/tsconfig/node.json +11 -1
- package/dist/tsconfig/react.json +3 -0
- package/dist/{validate-LMGBKN6L.js → validate-LRHF63AW.js} +4 -2
- package/docs/typescript-adoption.md +52 -13
- package/docs/typescript-traces.md +1 -1
- package/package.json +4 -1
- package/dist/chunk-7E6YTTAK.js.map +0 -1
- package/dist/chunk-ZVHUG6CA.js.map +0 -1
- /package/dist/{chunk-XGMMTX2N.js.map → chunk-DLGBRLUU.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shared/jsonc.ts","../src/shared/tsconfig-paths.ts"],"sourcesContent":["/**\n * JSONC (JSON with comments + trailing commas) helpers. tsconfig files are JSONC,\n * so reading them with plain `JSON.parse` throws on real projects (e.g.\n * host-admin's tsconfig.app.json has comments). Backed by jsonc-parser (the VS\n * Code library), which also underpins content-preserving edits (added with the\n * `--init` merge).\n */\nimport { parse, printParseErrorCode, type ParseError } from 'jsonc-parser'\n\n/**\n * Parse JSONC text into a value. Throws with a clear message listing the parse\n * errors, so a malformed config fails loudly rather than silently mis-reading.\n */\nexport function parseJsonc<T = unknown>(text: string, source = 'config'): T {\n const errors: ParseError[] = []\n const value = parse(text, errors, { allowTrailingComma: true }) as T\n if (errors.length > 0) {\n const details = errors.map((error) => printParseErrorCode(error.error)).join(', ')\n throw new Error(`${source}: malformed JSONC (${details}).`)\n }\n return value\n}\n","/**\n * The `paths` a module's tsconfig chain resolves to, the way tsc reads them.\n *\n * ## Why one reader, and why it follows the chain\n *\n * Three readers in this package used to parse `tsconfig.base.json` at the workspace root, each on\n * its own: the runtime aliases of `build/nest` and of the test presets, the consumer index of\n * static analysis, and the workspace specifier of the `--init --test` codemod. tsc does not read\n * it that way. It reads the `paths` of the MODULE's tsconfig, following `extends`. The two agree\n * while a module extends the base, and they part silently the day a module declares its own\n * `paths` and stops extending it: it type-checks with its aliases while its build, its tests and\n * the consumer index resolve through the base. Measured on the monorepo when this was written:\n * 112 sentinel tsconfigs extend the base, and the plan is for each to stop.\n *\n * ## tsc's rules, reproduced rather than guessed\n *\n * - `extends` is a relative file or a package specifier, resolved like Node. In an array, the\n * RIGHTMOST entry wins, so the search runs from the last entry to the first.\n * - The first `paths` found REPLACES the inherited ones; tsc never merges two `paths` objects. A\n * module that declares one entry and extends the base keeps that one entry, not the base's 372.\n * - Targets are relative to `baseUrl` when the chain declares one, and otherwise to the file that\n * declares `paths`. ts-jest, Vite and the TypeScript 5 and 6 still in the repository read\n * `baseUrl`, and this reader serves the build and the tests, so it follows them. ⚠️ tsc 7 no\n * longer reads it: for a chain whose `baseUrl` is NOT the directory of the file declaring\n * `paths`, the typecheck and the runtime resolve differently. No such chain exists in the\n * monorepo today (the only `baseUrl`, in `libs/front/analytics`, is `./`, its own directory), and\n * a test pins this choice so that changing it is a decision, not an accident.\n * - `${configDir}` is the directory of the leaf tsconfig, the one the module was asked for.\n *\n * ## The fallback, and why it is a transition\n *\n * When the chain declares no `paths` at all, this reads `tsconfig.base.json` at the workspace\n * root, which is what every reader did before. That keeps a module that still extends the base\n * exactly where it was, and it is what makes this a minor. It is not where this ends: once no\n * module extends the base, a module without `paths` has no aliases, as in tsc.\n */\nimport { existsSync, readFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { dirname, isAbsolute, join, resolve } from 'node:path'\n\nimport { parseJsonc } from './jsonc.js'\n\n/** The workspace file every reader used before it followed the module's chain. */\nexport const WORKSPACE_TSCONFIG = 'tsconfig.base.json'\n\nexport interface EffectivePaths {\n /** The `paths` object, as declared: keys and targets untouched, `${configDir}` substituted. */\n paths: Record<string, string[]>\n /** The absolute directory the targets are relative to: `baseUrl`, or the declaring file's. */\n baseDirectory: string\n /** The absolute file that declared `paths`, which is what a report should name. */\n declaredIn: string\n /** True when the chain declared none and the workspace base answered instead. */\n fromWorkspaceFallback: boolean\n}\n\nexport interface RawTsconfig {\n extends?: string | string[]\n compilerOptions?: { paths?: Record<string, string[]>; baseUrl?: string }\n}\n\ninterface Found<T> {\n value: T\n file: string\n}\n\n/**\n * Parsed tsconfig files, shared by the reads of one caller.\n *\n * Optional, and owned by the CALLER rather than kept here, because the right lifetime is the\n * caller's: the consumer index reads the chains of 444 modules in one pass, and most of them end\n * in the same base of more than a thousand lines, while a dev server must see an edited tsconfig\n * on its next read.\n */\nexport type TsconfigReadCache = Map<string, RawTsconfig>\n\nfunction readTsconfig(file: string, cache?: TsconfigReadCache): RawTsconfig {\n const known = cache?.get(file)\n if (known !== undefined) return known\n const parsed = parseJsonc<RawTsconfig>(readFileSync(file, 'utf8'), file)\n cache?.set(file, parsed)\n return parsed\n}\n\n/**\n * Where an `extends` entry points, or undefined when it resolves to nothing tsc could read.\n *\n * ⚠️ A package specifier is resolved from the EXTENDING file's directory, like Node and like tsc,\n * not from this package: `@hublo/sentinel/typescript/nest` is the module's own pinned copy.\n */\nfunction resolveExtends(specifier: string, fromFile: string): string | undefined {\n const directory = dirname(fromFile)\n if (specifier.startsWith('.') || isAbsolute(specifier)) {\n const target = resolve(directory, specifier)\n if (existsSync(target) && target.endsWith('.json')) return target\n if (existsSync(`${target}.json`)) return `${target}.json`\n return existsSync(target) ? target : undefined\n }\n const require = createRequire(join(directory, 'noop.js'))\n for (const candidate of [specifier, `${specifier}.json`, `${specifier}/tsconfig.json`]) {\n try {\n return require.resolve(candidate)\n } catch {\n // Try the next spelling, which is the order tsc tries them in.\n }\n }\n return undefined\n}\n\n/**\n * The nearest definition of one compiler option along the chain, rightmost `extends` first.\n *\n * `seen` guards a cycle: tsc reports one and stops, and a reader that recursed would never return.\n */\nfunction nearest<T>(\n file: string,\n pick: (config: RawTsconfig) => T | undefined,\n cache: TsconfigReadCache | undefined,\n seen: Set<string> = new Set(),\n): Found<T> | undefined {\n if (seen.has(file)) return undefined\n seen.add(file)\n\n const config = readTsconfig(file, cache)\n const own = pick(config)\n if (own !== undefined) return { value: own, file }\n\n const parents = config.extends === undefined ? [] : [config.extends].flat()\n for (const specifier of [...parents].reverse()) {\n const parent = resolveExtends(specifier, file)\n if (parent === undefined) continue\n const found = nearest(parent, pick, cache, seen)\n if (found !== undefined) return found\n }\n return undefined\n}\n\nconst substituteConfigDirectory = (value: string, leafDirectory: string): string =>\n value.replaceAll('${configDir}', leafDirectory)\n\n/** The `paths` of one tsconfig file's chain, without the workspace fallback. */\nexport function chainPaths(\n tsconfigFile: string,\n cache?: TsconfigReadCache,\n): Omit<EffectivePaths, 'fromWorkspaceFallback'> | undefined {\n const leafDirectory = dirname(tsconfigFile)\n const paths = nearest(tsconfigFile, (config) => config.compilerOptions?.paths, cache)\n if (paths === undefined) return undefined\n\n const baseUrl = nearest(tsconfigFile, (config) => config.compilerOptions?.baseUrl, cache)\n const baseDirectory =\n baseUrl === undefined\n ? dirname(paths.file)\n : resolve(dirname(baseUrl.file), substituteConfigDirectory(baseUrl.value, leafDirectory))\n\n const substituted = Object.fromEntries(\n Object.entries(paths.value).map(([key, targets]) => [\n key,\n targets.map((target) => substituteConfigDirectory(target, leafDirectory)),\n ]),\n )\n return { paths: substituted, baseDirectory, declaredIn: paths.file }\n}\n\n/**\n * The `paths` a module resolves through: its own chain, or the workspace base when it has none.\n *\n * @param candidates the module's tsconfig names to try, most specific first, relative to\n * `moduleRoot`. The first that exists is the one read, which is what tsc is pointed at.\n * @returns undefined only when neither the module nor the workspace declares any `paths`.\n */\nexport function effectivePaths(\n moduleRoot: string,\n workspaceRoot: string,\n candidates: readonly string[] = ['tsconfig.json'],\n cache?: TsconfigReadCache,\n): EffectivePaths | undefined {\n const leaf = candidates.map((name) => join(moduleRoot, name)).find((file) => existsSync(file))\n const own = leaf === undefined ? undefined : chainPaths(leaf, cache)\n if (own !== undefined) return { ...own, fromWorkspaceFallback: false }\n\n const workspaceFile = join(workspaceRoot, WORKSPACE_TSCONFIG)\n if (!existsSync(workspaceFile)) return undefined\n const fallback = chainPaths(workspaceFile, cache)\n return fallback === undefined ? undefined : { ...fallback, fromWorkspaceFallback: true }\n}\n"],"mappings":";AAOA,SAAS,OAAO,2BAA4C;AAMrD,SAAS,WAAwB,MAAc,SAAS,UAAa;AAC1E,QAAM,SAAuB,CAAC;AAC9B,QAAM,QAAQ,MAAM,MAAM,QAAQ,EAAE,oBAAoB,KAAK,CAAC;AAC9D,MAAI,OAAO,SAAS,GAAG;AACrB,UAAM,UAAU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