From 094707b49cdd129de524d710ed4e4cf098893093 Mon Sep 17 00:00:00 2001 From: Patrick Camacho Date: Sun, 5 Jul 2026 21:10:07 +0200 Subject: [PATCH 1/2] convert last-modified to TypeScript: dist packaging, changeset index.ts + types.ts + index.spec.ts + example.ts, tsconfig.build.json (rootDir/include root-relative for the flat plugin layout), dist packaging with prepack. Logic unchanged, types + syntax + .ts specifiers only. README stays JS-referencing for now (LASTMODIFIED output is non-idempotent; docs-gate carve-out already checks out this package's README in CI). --- .changeset/ts-last-modified.md | 5 +++++ .../last-modified/{example.js => example.ts} | 2 +- .../{index.spec.js => index.spec.ts} | 2 +- packages/last-modified/{index.js => index.ts} | 13 ++++++++++--- packages/last-modified/package.json | 14 ++++++++++---- packages/last-modified/tsconfig.build.json | 18 ++++++++++++++++++ packages/last-modified/types.ts | 14 ++++++++++++++ pnpm-lock.yaml | 6 ++++++ 8 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 .changeset/ts-last-modified.md rename packages/last-modified/{example.js => example.ts} (87%) rename packages/last-modified/{index.spec.js => index.spec.ts} (96%) rename packages/last-modified/{index.js => index.ts} (71%) create mode 100644 packages/last-modified/tsconfig.build.json create mode 100644 packages/last-modified/types.ts diff --git a/.changeset/ts-last-modified.md b/.changeset/ts-last-modified.md new file mode 100644 index 0000000..82a4091 --- /dev/null +++ b/.changeset/ts-last-modified.md @@ -0,0 +1,5 @@ +--- +'markdown-magic-last-modified': minor +--- + +TypeScript: ship type declarations diff --git a/packages/last-modified/example.js b/packages/last-modified/example.ts similarity index 87% rename from packages/last-modified/example.js rename to packages/last-modified/example.ts index 86e130a..2c7ad01 100644 --- a/packages/last-modified/example.js +++ b/packages/last-modified/example.ts @@ -1,6 +1,6 @@ import path from 'path'; import { markdownMagic } from 'markdown-magic'; -import LASTMODIFIED from './index.js'; +import LASTMODIFIED from './index.ts'; const config = { matchWord: 'AUTO-GENERATED-CONTENT', diff --git a/packages/last-modified/index.spec.js b/packages/last-modified/index.spec.ts similarity index 96% rename from packages/last-modified/index.spec.js rename to packages/last-modified/index.spec.ts index 7d41ab2..46bd709 100644 --- a/packages/last-modified/index.spec.js +++ b/packages/last-modified/index.spec.ts @@ -1,7 +1,7 @@ import { mkdirSync, rmSync, writeFileSync } from 'fs'; import path from 'path'; import { describe, expect, it } from 'vitest'; -import format from './index.js'; +import format from './index.ts'; const srcPath = path.join(import.meta.dirname, 'README.md'); diff --git a/packages/last-modified/index.js b/packages/last-modified/index.ts similarity index 71% rename from packages/last-modified/index.js rename to packages/last-modified/index.ts index 297d6f9..92b698d 100644 --- a/packages/last-modified/index.js +++ b/packages/last-modified/index.ts @@ -1,8 +1,15 @@ -import path from 'path'; import { execFileSync } from 'child_process'; +import path from 'path'; +import type { TransformArgs } from './types.ts'; + +export type { TransformArgs, TransformOptions } from './types.ts'; -export default function LASTMODIFIED({ content, options = {}, srcPath }) { - let filePath; +export default function LASTMODIFIED({ + content, + options = {}, + srcPath, +}: TransformArgs): string { + let filePath: string; if (options.file) { filePath = path.resolve(path.dirname(srcPath), options.file); diff --git a/packages/last-modified/package.json b/packages/last-modified/package.json index 5750a9f..cbeaba3 100644 --- a/packages/last-modified/package.json +++ b/packages/last-modified/package.json @@ -3,17 +3,21 @@ "version": "2.0.0", "description": "Print the last modified date using git for a given file", "type": "module", - "main": "index.js", + "main": "dist/index.js", + "types": "dist/index.d.ts", "exports": { - ".": "./index.js", + ".": "./dist/index.js", "./package.json": "./package.json" }, "engines": { "node": ">=22.18.0" }, "scripts": { + "prebuild": "rm -rf dist", + "build": "tsc --project tsconfig.build.json", + "prepack": "pnpm build", "test": "vitest run", - "docs": "node example.js && prettier --write README.md", + "docs": "node example.ts && prettier --write README.md", "format": "prettier --write ." }, "license": "MIT", @@ -32,8 +36,10 @@ "markdown-magic": "^4" }, "devDependencies": { + "@types/node": "^24.13.2", "markdown-magic": "catalog:", "prettier": "catalog:", + "typescript": "^6.0.3", "vitest": "catalog:" }, "homepage": "https://github.com/camacho/markdown-magic-plugins#readme", @@ -41,6 +47,6 @@ "url": "https://github.com/camacho/markdown-magic-plugins/issues" }, "files": [ - "index.js" + "dist" ] } diff --git a/packages/last-modified/tsconfig.build.json b/packages/last-modified/tsconfig.build.json new file mode 100644 index 0000000..d7ec333 --- /dev/null +++ b/packages/last-modified/tsconfig.build.json @@ -0,0 +1,18 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "dist", + "rootDir": ".", + "types": ["node"] + }, + "exclude": [ + "node_modules", + "dist", + "*.spec.ts", + "example.ts", + "__fixtures__", + "__snapshots__" + ], + "include": ["*.ts"] +} diff --git a/packages/last-modified/types.ts b/packages/last-modified/types.ts new file mode 100644 index 0000000..64c1458 --- /dev/null +++ b/packages/last-modified/types.ts @@ -0,0 +1,14 @@ +// Transform interface shared by markdown-magic plugins. Adapted from +// format-package's scripts/markdown-transformers.ts TransformArgs/TransformOptions +// (content: unknown -> content: string, the plugins' actual contract), plus +// this package's own `file` option. +export interface TransformOptions { + file?: string; + [key: string]: unknown; +} + +export interface TransformArgs { + content: string; + options: TransformOptions; + srcPath: string; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c1e0321..0006a7d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -151,12 +151,18 @@ importers: packages/last-modified: devDependencies: + '@types/node': + specifier: ^24.13.2 + version: 24.13.2 markdown-magic: specifier: 'catalog:' version: 4.10.5 prettier: specifier: 'catalog:' version: 3.9.1 + typescript: + specifier: ^6.0.3 + version: 6.0.3 vitest: specifier: 'catalog:' version: 4.1.9(@types/node@24.13.2)(vite@8.1.0(@types/node@24.13.2)) From 66e8a000c90b40d47f865b4b8265e17cdbab59be Mon Sep 17 00:00:00 2001 From: Patrick Camacho Date: Sun, 5 Jul 2026 21:13:08 +0200 Subject: [PATCH 2/2] point last-modified readme at example.ts --- packages/last-modified/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/last-modified/README.md b/packages/last-modified/README.md index b605c8a..d3d6f10 100644 --- a/packages/last-modified/README.md +++ b/packages/last-modified/README.md @@ -10,14 +10,14 @@ npm i markdown-magic markdown-magic-last-modified --save-dev ## Adding the plugin -See `example.js` for usage. +See `example.ts` for usage. - + -```js +```ts import path from 'path'; import { markdownMagic } from 'markdown-magic'; -import LASTMODIFIED from './index.js'; +import LASTMODIFIED from './index.ts'; const config = { matchWord: 'AUTO-GENERATED-CONTENT',