@timvir/mdx 0.2.46 → 0.2.48

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/index.js +0 -70
  3. package/package.json +1 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @timvir/mdx
2
2
 
3
+ ## 0.2.48
4
+
5
+ ### Patch Changes
6
+
7
+ - **Drop dependency on Prettier** ([#3656](https://github.com/timvir/timvir/pull/3656)) - Prettier was used in the `@timvir/macro` and `@timvir/mdx` packages to format source code that's injected into MDX files. When Prettier released major version 3, they dropped the synchronous API so we were not able to keep up to date. Many projects are starting to adopt alternative formatters (oxc, biome). Using Prettier introduces divergence between code in files and code that appears in the documentation. Reformatting code makes line highlighting unpredictable. Lines of code that the developer sees in source files may not correspond to lines in the documentation. Due to those reasons, we're dropping dependency on Prettier. Along with that, the macro and MDX plugin `<Sample>` component no longer supports `as="source/component"` or `as="source/markup"`. If you rely on those features, inline the code into your MDX files.
8
+
9
+ ## 0.2.47
10
+
3
11
  ## 0.2.46
4
12
 
5
13
  ### Patch Changes
package/index.js CHANGED
@@ -1,6 +1,3 @@
1
- import generate from "@babel/generator";
2
- import { parse } from "@babel/parser";
3
- import * as t from "@babel/types";
4
1
  import * as crypto from "node:crypto";
5
2
  import * as espree from "espree";
6
3
  import * as fs from "node:fs";
@@ -8,7 +5,6 @@ import { fromMarkdown } from "mdast-util-from-markdown";
8
5
  import { mdxFromMarkdown } from "mdast-util-mdx";
9
6
  import { mdxjs } from "micromark-extension-mdxjs";
10
7
  import * as path from "node:path";
11
- import prettier from "prettier";
12
8
  import { visit } from "unist-util-visit";
13
9
 
14
10
  export function remarkPlugin() {
@@ -115,72 +111,6 @@ export function remarkPlugin() {
115
111
  delete node[k];
116
112
  }
117
113
 
118
- for (const [k, v] of Object.entries(children[0])) {
119
- node[k] = v;
120
- }
121
- },
122
- "source/component": () => {
123
- const source = (() => {
124
- const file = parse(loadSource(), {
125
- sourceType: "module",
126
- plugins: ["jsx", "typescript"],
127
- });
128
-
129
- const exportDefaultDeclaration = file.program.body.find((node) => t.isExportDefaultDeclaration(node));
130
- const { declaration } = exportDefaultDeclaration;
131
- const { code } = generate.default(declaration);
132
- return prettier
133
- .format(code, {
134
- parser: "typescript",
135
- printWidth: 80,
136
- })
137
- .trim()
138
- .slice(0, -1);
139
- })();
140
-
141
- const { children } = fromMarkdown(`{${JSON.stringify(source)}}`, {
142
- extensions: [mdxjs()],
143
- mdastExtensions: [mdxFromMarkdown()],
144
- });
145
-
146
- for (const [k] of Object.keys(node)) {
147
- delete node[k];
148
- }
149
-
150
- for (const [k, v] of Object.entries(children[0])) {
151
- node[k] = v;
152
- }
153
- },
154
- "source/markup": () => {
155
- const source = (() => {
156
- const file = parse(loadSource(), {
157
- sourceType: "module",
158
- plugins: ["jsx", "typescript"],
159
- });
160
-
161
- const exportDefaultDeclaration = file.program.body.find((node) => t.isExportDefaultDeclaration(node));
162
- const { declaration } = exportDefaultDeclaration;
163
- const body = declaration.body.body;
164
- const returnStatement = body.find((node) => t.isReturnStatement(node));
165
- const { code } = generate.default(returnStatement.argument);
166
- return prettier
167
- .format(code, {
168
- parser: "typescript",
169
- printWidth: 80,
170
- })
171
- .trim()
172
- .slice(0, -1);
173
- })();
174
-
175
- const { children } = fromMarkdown(`{${JSON.stringify(source)}}`, {
176
- extensions: [mdxjs()],
177
- mdastExtensions: [mdxFromMarkdown()],
178
- });
179
-
180
- for (const [k] of Object.keys(node)) {
181
- delete node[k];
182
- }
183
-
184
114
  for (const [k, v] of Object.entries(children[0])) {
185
115
  node[k] = v;
186
116
  }
package/package.json CHANGED
@@ -1,21 +1,17 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@timvir/mdx",
4
- "version": "0.2.46",
4
+ "version": "0.2.48",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
8
  ".": "./index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@babel/generator": "^7",
12
- "@babel/parser": "^7",
13
- "@babel/types": "^7",
14
11
  "espree": "^9 || ^10 || ^11",
15
12
  "mdast-util-from-markdown": "^1 || ^2",
16
13
  "mdast-util-mdx": "^2 || ^3",
17
14
  "micromark-extension-mdxjs": "^3",
18
- "prettier": "^2",
19
15
  "unist-util-visit": "^5"
20
16
  },
21
17
  "repository": {