Skip to content

Commit

Permalink
Add support for MDX3 and Prettier v3 (#15)
Browse files Browse the repository at this point in the history
* Upgrade to Yarn 4

* Update `package.json` and dependencies

* Update CI

* Add `tsup.config.ts`

* Fix `tsconfig.json`

* Fix all imports

* Add support for MDX3 and Prettier v3 and copy changes from #14

* Format files

* Fix issues related to renaming imports and exports

* Update `@types/node` to version 22.2.0

* Update lockfile

* Bump `@types/node` to version 22.5.0

* Bump `@types/react` to version 18.3.4

* Bump `@types/unist` to version 3.0.3

* Bump `husky` to version 9.1.5

* Bump `tslib` to version 2.7.0

* Upgrade Yarn to version 4.4.1

* Update dependencies

* add node:test for linkDocblocks

* CI

---------

Co-authored-by: Lenz Weber-Tronic <[email protected]>
  • Loading branch information
aryaemami59 and phryneas authored Sep 8, 2024
1 parent 99f56e2 commit aa3d36d
Show file tree
Hide file tree
Showing 16 changed files with 6,685 additions and 8,734 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ jobs:

steps:
- name: Begin CI...
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Node 16
uses: actions/setup-node@v1
- name: Use Node 20
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x

- name: Use cached node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: nodeModules-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -32,7 +32,7 @@ jobs:
CI: true

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
run: yarn test
env:
CI: true

Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
.DS_Store
node_modules
dist

.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
*.tgz
925 changes: 925 additions & 0 deletions .yarn/releases/yarn-4.4.1.cjs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
compressionLevel: mixed

enableGlobalCache: false

enableTransparentWorkspaces: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.4.1.cjs
79 changes: 53 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,22 @@
"author": "Lenz Weber-Tronic",
"version": "1.1.0",
"license": "MIT",
"type": "module",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"files": [
"dist",
"src"
Expand All @@ -17,16 +31,13 @@
"node": ">=10"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build"
"start": "tsup --watch",
"build": "tsup",
"test": "yarn tsx --test test/linkDocblocks.test.ts",
"lint": "true",
"prepare": "yarn build"
},
"peerDependencies": {
"typescript": ">=4.0"
},
"husky": {
"_husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
Expand All @@ -37,24 +48,40 @@
"singleQuote": true,
"trailingComma": "es5"
},
"module": "dist/remark-typescript-tools.esm.js",
"module": "dist/index.js",
"devDependencies": {
"@types/prettier": "^2.1.0",
"@types/react": "^17.0.11",
"eslint-plugin-prettier": "3.1.4",
"husky": "^4.2.5",
"release-it": "^15.1.1",
"remark-mdx": "^1.6.16",
"remark-parse": "^8.0.3",
"remark-stringify": "^8.1.1",
"tsdx": "^0.13.3",
"tslib": "^2.0.1",
"unified": "^9.2.0"
"@types/node": "^22.5.4",
"@types/react": "^18.3.5",
"husky": "^9.1.5",
"release-it": "^17.6.0",
"remark-mdx": "^3.0.1",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"tslib": "^2.7.0",
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"unified": "^11.0.5"
},
"dependencies": {
"@microsoft/tsdoc": "^0.12.21",
"prettier": "^2.1.1",
"@microsoft/tsdoc": "^0.15.0",
"@types/estree": "^1.0.5",
"@types/unist": "^3.0.3",
"mdast-util-mdx-jsx": "^3.1.3",
"mdast-util-mdxjs-esm": "^2.0.1",
"prettier": "^3.3.3",
"tsx": "^4.19.0",
"unist-util-flatmap": "^1.0.0",
"unist-util-visit": "^2.0.3"
}
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.3"
},
"packageManager": "[email protected]",
"peerDependencies": {
"typescript": "*"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
},
"sideEffects": false
}
19 changes: 9 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export {
attacher as linkDocblocks,
Settings as LinkDocblocksSettings,
} from './linkDocblocks/plugin';
export { linkDocblocks } from './linkDocblocks/plugin.js';
export type { LinkDocblocksSettings } from './linkDocblocks/plugin.js';

export {
attacher as transpileCodeblocks,
Settings as TranspileCodeblocksSettings,
defaultAssembleReplacementNodes,
} from './transpileCodeblocks/plugin';
transpileCodeblocks,
} from './transpileCodeblocks/plugin.js';

export type { TranspileCodeblocksSettings } from './transpileCodeblocks/plugin.js';

export {
postProcessTranspiledJs as defaultPostProcessTranspiledJs,
postProcessTs as defaultPostProcessTs,
} from './transpileCodeblocks/postProcessing';
defaultPostProcessTranspiledJs,
defaultPostProcessTs,
} from './transpileCodeblocks/postProcessing.js';
4 changes: 2 additions & 2 deletions src/linkDocblocks/extract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ts from 'typescript';
import path from 'path';
import * as path from 'node:path';
import * as tsdoc from '@microsoft/tsdoc';

import { getJSDocCommentRanges } from './utils';
import { getJSDocCommentRanges } from './utils.js';

export interface ExtractorSettings {
tsconfig: string;
Expand Down
27 changes: 16 additions & 11 deletions src/linkDocblocks/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-ignore
import flatMap from 'unist-util-flatmap';
import { Extractor, ExtractorSettings } from './extract';
import { renderDocNode } from './utils';
import { URL } from 'url';
import { Extractor } from './extract.js';
import type { ExtractorSettings } from './extract.js';
import { renderDocNode } from './utils.js';
import { URL } from 'node:url';
import type { Node, Parent } from 'unist';
import visit from 'unist-util-visit';
import { visit } from 'unist-util-visit';

import type { Plugin } from 'unified';
import type { DocNode } from '@microsoft/tsdoc';
Expand All @@ -18,13 +19,15 @@ type RenderableKey = {
: never;
}[keyof Comment];

export interface Settings {
export interface LinkDocblocksSettings {
extractorSettings: ExtractorSettings;
}

const extractors = new WeakMap<ExtractorSettings, Extractor>();

export const attacher: Plugin<[Settings]> = function ({ extractorSettings }) {
export const linkDocblocks: Plugin<[LinkDocblocksSettings]> = function ({
extractorSettings,
}) {
if (!extractors.has(extractorSettings)) {
extractors.set(extractorSettings, new Extractor(extractorSettings));
}
Expand Down Expand Up @@ -118,11 +121,13 @@ export const attacher: Plugin<[Settings]> = function ({ extractorSettings }) {
return acc;
}, []);

visit<
Node & { value: string }
>({ type: 'fakeRoot', children: retVal }, 'code', (node) => {
node.value = node.value.trimEnd();
});
visit(
{ type: 'fakeRoot', children: retVal },
'code',
(node: Node & { value: string }) => {
node.value = node.value.trimEnd();
}
);

return retVal;
});
Expand Down
1 change: 0 additions & 1 deletion src/linkDocblocks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as tsdoc from '@microsoft/tsdoc';
* https://github.com/Microsoft/TypeScript/blob/v3.0.3/src/compiler/utilities.ts#L924
*/
export function getJSDocCommentRanges(node: ts.Node, text: string) {
/** @type {import('typescript').CommentRange[]} */
const commentRanges: ts.CommentRange[] = [];

switch (node.kind) {
Expand Down
16 changes: 6 additions & 10 deletions src/transpileCodeblocks/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ts from 'typescript';
import { normalize } from 'path';
import { normalize } from 'node:path';

import { VirtualFiles, VirtualFile } from './plugin';
import type { VirtualFiles, VirtualFile } from './plugin.js';

export type Diagnostic =
| { line: number; character: number; message: string }
Expand Down Expand Up @@ -84,10 +84,8 @@ export class Compiler {
'\n'
);
if (diagnostic.file && diagnostic.start) {
const {
line,
character,
} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
const { line, character } =
diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
return { line, character, message };
}
return { message };
Expand All @@ -111,10 +109,8 @@ function createCompilerHost(
Required<Pick<ts.LanguageServiceHost, 'writeFile'>> & {
setScriptFileNames(files: string[]): void;
} {
const virtualFiles: Record<
string,
{ contents: string; version: number }
> = {};
const virtualFiles: Record<string, { contents: string; version: number }> =
{};
let scriptFileNames: string[] = [];

return {
Expand Down
Loading

0 comments on commit aa3d36d

Please sign in to comment.