@shikijs/vitepress-twoslash 1.1.0 → 1.1.2

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 (2) hide show
  1. package/dist/index.mjs +23 -0
  2. package/package.json +5 -4
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createTransformerFactory } from '@shikijs/twoslash/core';
2
2
  import { createTwoslasher } from 'twoslash-vue';
3
+ import { removeTwoslashNotations } from 'twoslash';
3
4
  import { rendererRich } from '@shikijs/twoslash';
4
5
  export { defaultHoverInfoProcessor } from '@shikijs/twoslash';
5
6
  import { gfmFromMarkdown } from 'mdast-util-gfm';
@@ -161,11 +162,33 @@ function transformerTwoslash(options = {}) {
161
162
  const {
162
163
  explicitTrigger = true
163
164
  } = options;
165
+ const onError = (error, code) => {
166
+ const isCI = typeof process !== "undefined" && process?.env?.CI;
167
+ const isDev = typeof process !== "undefined" && process?.env?.NODE_ENV === "development";
168
+ const shouldThrow = (options.throws || isCI || !isDev) && options.throws !== false;
169
+ console.error(`
170
+
171
+ --------
172
+ Twoslash error in code:
173
+ --------
174
+ ${code.split(/\n/g).slice(0, 15).join("\n").trim()}
175
+ --------
176
+ `);
177
+ if (shouldThrow)
178
+ throw error;
179
+ else
180
+ console.error(error);
181
+ if (typeof process !== "undefined")
182
+ process.exitCode = 1;
183
+ return removeTwoslashNotations(code);
184
+ };
164
185
  const twoslash = createTransformerFactory(
165
186
  createTwoslasher()
166
187
  )({
167
188
  langs: ["ts", "tsx", "js", "jsx", "json", "vue"],
168
189
  renderer: rendererFloatingVue(options),
190
+ onTwoslashError: onError,
191
+ onShikiError: onError,
169
192
  ...options,
170
193
  explicitTrigger
171
194
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/vitepress-twoslash",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "description": "Enable Twoslash support in VitePress",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -52,10 +52,11 @@
52
52
  "mdast-util-from-markdown": "^2.0.0",
53
53
  "mdast-util-gfm": "^3.0.0",
54
54
  "mdast-util-to-hast": "^13.1.0",
55
- "twoslash-vue": "^0.2.0",
55
+ "twoslash": "^0.2.1",
56
+ "twoslash-vue": "^0.2.1",
56
57
  "vue": "^3.4.18",
57
- "@shikijs/twoslash": "1.1.0",
58
- "shiki": "1.1.0"
58
+ "@shikijs/twoslash": "1.1.2",
59
+ "shiki": "1.1.2"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "unbuild",