Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ts-last-modified.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'markdown-magic-last-modified': minor
---

TypeScript: ship type declarations
8 changes: 4 additions & 4 deletions packages/last-modified/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./example.js) -->
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=./example.ts) -->

```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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
14 changes: 10 additions & 4 deletions packages/last-modified/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -32,15 +36,17 @@
"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",
"bugs": {
"url": "https://github.com/camacho/markdown-magic-plugins/issues"
},
"files": [
"index.js"
"dist"
]
}
18 changes: 18 additions & 0 deletions packages/last-modified/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -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"]
}
14 changes: 14 additions & 0 deletions packages/last-modified/types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading