Implements Phases 1-8 of the TFTSR implementation plan. Rust backend (Tauri 2.x, src-tauri/): - Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama - PII detection engine: 11 regex patterns with overlap resolution - SQLCipher AES-256 encrypted database with 10 versioned migrations - 28 Tauri IPC commands for triage, analysis, document, and system ops - Ollama: hardware probe, model recommendations, pull/delete with events - RCA and blameless post-mortem Markdown document generators - PDF export via printpdf - Audit log: SHA-256 hash of every external data send - Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2) Frontend (React 18 + TypeScript + Vite, src/): - 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings - 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives - 3 Zustand stores: session, settings (persisted), history - Type-safe tauriCommands.ts matching Rust backend types exactly - 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs) DevOps: - .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push - .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload Verified: - cargo check: zero errors - tsc --noEmit: zero errors - vitest run: 13/13 unit tests passing Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
111 lines
3.0 KiB
Markdown
111 lines
3.0 KiB
Markdown
# package-json-from-dist
|
|
|
|
Sometimes you want to load the `package.json` into your
|
|
TypeScript program, and it's tempting to just `import
|
|
'../package.json'`, since that seems to work.
|
|
|
|
However, this requires `tsc` to make an entire copy of your
|
|
`package.json` file into the `dist` folder, which is a problem if
|
|
you're using something like
|
|
[tshy](https://github.com/isaacs/tshy), which uses the
|
|
`package.json` file in dist for another purpose. Even when that
|
|
does work, it's asking the module system to do a bunch of extra
|
|
fs system calls, just to load a version number or something. (See
|
|
[this issue](https://github.com/isaacs/tshy/issues/61).)
|
|
|
|
This module helps by just finding the package.json file
|
|
appropriately, and reading and parsing it in the most normal
|
|
fashion.
|
|
|
|
## Caveats
|
|
|
|
This _only_ works if your code builds into a target folder called
|
|
`dist`, which is in the root of the package. It also requires
|
|
that you do not have a folder named `node_modules` anywhere
|
|
within your dev environment, or else it'll get the wrong answers
|
|
there. (But, at least, that'll be in dev, so you're pretty likely
|
|
to notice.)
|
|
|
|
If you build to some other location, then you'll need a different
|
|
approach. (Feel free to fork this module and make it your own, or
|
|
just put the code right inline, there's not much of it.)
|
|
|
|
## USAGE
|
|
|
|
```js
|
|
// src/index.ts
|
|
import {
|
|
findPackageJson,
|
|
loadPackageJson,
|
|
} from 'package-json-from-dist'
|
|
|
|
const pj = findPackageJson(import.meta.url)
|
|
console.log(`package.json found at ${pj}`)
|
|
|
|
const pkg = loadPackageJson(import.meta.url)
|
|
console.log(`Hello from ${pkg.name}@${pkg.version}`)
|
|
```
|
|
|
|
If your module is not directly in the `./src` folder, then you need
|
|
to specify the path that you would expect to find the
|
|
`package.json` when it's _not_ built to the `dist` folder.
|
|
|
|
```js
|
|
// src/components/something.ts
|
|
import {
|
|
findPackageJson,
|
|
loadPackageJson,
|
|
} from 'package-json-from-dist'
|
|
|
|
const pj = findPackageJson(import.meta.url, '../../package.json')
|
|
console.log(`package.json found at ${pj}`)
|
|
|
|
const pkg = loadPackageJson(import.meta.url, '../../package.json')
|
|
console.log(`Hello from ${pkg.name}@${pkg.version}`)
|
|
```
|
|
|
|
When running from CommmonJS, use `__filename` instead of
|
|
`import.meta.url`.
|
|
|
|
```js
|
|
// src/index.cts
|
|
import {
|
|
findPackageJson,
|
|
loadPackageJson,
|
|
} from 'package-json-from-dist'
|
|
|
|
const pj = findPackageJson(__filename)
|
|
console.log(`package.json found at ${pj}`)
|
|
|
|
const pkg = loadPackageJson(__filename)
|
|
console.log(`Hello from ${pkg.name}@${pkg.version}`)
|
|
```
|
|
|
|
Since [tshy](https://github.com/isaacs/tshy) builds _both_
|
|
CommonJS and ESM by default, you may find that you need a
|
|
CommonJS override and some `//@ts-ignore` magic to make it work.
|
|
|
|
`src/pkg.ts`:
|
|
|
|
```js
|
|
import {
|
|
findPackageJson,
|
|
loadPackageJson,
|
|
} from 'package-json-from-dist'
|
|
//@ts-ignore
|
|
export const pkg = loadPackageJson(import.meta.url)
|
|
//@ts-ignore
|
|
export const pj = findPackageJson(import.meta.url)
|
|
```
|
|
|
|
`src/pkg-cjs.cts`:
|
|
|
|
```js
|
|
import {
|
|
findPackageJson,
|
|
loadPackageJson,
|
|
} from 'package-json-from-dist'
|
|
export const pkg = loadPackageJson(__filename)
|
|
export const pj = findPackageJson(__filename)
|
|
```
|