@mdsvex/typescript-plugin 0.0.0 → 0.1.0-next.1
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.
- package/CHANGELOG.md +34 -0
- package/LICENSE +21 -0
- package/lib/index.cjs +77969 -0
- package/package.json +13 -7
- package/src/index.ts +44 -0
- package/vite.config.build.ts +26 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdsvex/typescript-plugin",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Placeholder release so npm trusted publishing can be configured.",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"homepage": "https://mdsvex.pngwn.io",
|
|
3
|
+
"version": "0.1.0-next.1",
|
|
7
4
|
"repository": {
|
|
8
5
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/pngwn/MDsveX",
|
|
6
|
+
"url": "git+https://github.com/pngwn/MDsveX.git",
|
|
10
7
|
"directory": "language-tools/typescript-plugin"
|
|
11
8
|
},
|
|
12
|
-
"
|
|
13
|
-
|
|
9
|
+
"description": "TypeScript plugin that teaches tsserver how to resolve .pfm imports",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./lib/index.cjs",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@volar/typescript": "^2.4.28",
|
|
14
|
+
"@mdsvex/language-core": "0.1.0-next.1"
|
|
15
|
+
},
|
|
16
|
+
"author": "pngwn <hello@pngwn.io>",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "vite build --config vite.config.build.ts"
|
|
14
20
|
}
|
|
15
21
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PFM TypeScript Plugin.
|
|
3
|
+
*
|
|
4
|
+
* Teaches tsserver how to resolve .pfm imports by running them through
|
|
5
|
+
* the PFM LanguagePlugin. This enables type-checking of .pfm imports
|
|
6
|
+
* in .ts and .svelte files.
|
|
7
|
+
*
|
|
8
|
+
* Usage in tsconfig.json:
|
|
9
|
+
* { "compilerOptions": { "plugins": [{ "name": "@mdsvex/typescript-plugin" }] } }
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createLanguageServicePlugin } from "@volar/typescript/lib/quickstart/createLanguageServicePlugin.js";
|
|
13
|
+
import { create_pfm_language_plugin, create_svelte_language_plugin } from "@mdsvex/language-core";
|
|
14
|
+
|
|
15
|
+
// TS plugins must export a factory function via module.exports
|
|
16
|
+
// (CJS convention that tsserver expects)
|
|
17
|
+
module.exports = createLanguageServicePlugin((ts, info) => {
|
|
18
|
+
console.log("[PFM TS Plugin] Loaded! Project:", info.project.getProjectName());
|
|
19
|
+
return {
|
|
20
|
+
languagePlugins: [
|
|
21
|
+
// typescript reads the exports of templates a mdsvex.config.json names
|
|
22
|
+
create_pfm_language_plugin({ typescript: ts as any }),
|
|
23
|
+
// two plugins claiming .svelte break its imports from .ts files
|
|
24
|
+
...(svelte_plugin_loaded(info) ? [] : [create_svelte_language_plugin()]),
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const SVELTE_PLUGIN = "typescript-svelte-plugin";
|
|
30
|
+
|
|
31
|
+
/** the svelte extension or the tsconfig loads the svelte typescript plugin */
|
|
32
|
+
function svelte_plugin_loaded(info: {
|
|
33
|
+
project: {
|
|
34
|
+
projectService: { globalPlugins?: readonly string[] };
|
|
35
|
+
getCompilerOptions(): { plugins?: unknown };
|
|
36
|
+
};
|
|
37
|
+
}): boolean {
|
|
38
|
+
if (info.project.projectService.globalPlugins?.includes(SVELTE_PLUGIN)) return true;
|
|
39
|
+
const plugins = info.project.getCompilerOptions().plugins;
|
|
40
|
+
return (
|
|
41
|
+
Array.isArray(plugins) &&
|
|
42
|
+
plugins.some((p) => (p as { name?: unknown })?.name === SVELTE_PLUGIN)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
build: {
|
|
6
|
+
lib: {
|
|
7
|
+
entry: resolve(__dirname, "src/index.ts"),
|
|
8
|
+
formats: ["cjs"],
|
|
9
|
+
fileName: "index",
|
|
10
|
+
},
|
|
11
|
+
outDir: "lib",
|
|
12
|
+
target: "node20",
|
|
13
|
+
ssr: true,
|
|
14
|
+
minify: false,
|
|
15
|
+
rollupOptions: {
|
|
16
|
+
// the vite plugin half of mdsvex loads vite lazily, the editor never reaches it
|
|
17
|
+
external: ["typescript", "vite"],
|
|
18
|
+
output: {
|
|
19
|
+
entryFileNames: "index.cjs",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
ssr: {
|
|
24
|
+
noExternal: true,
|
|
25
|
+
},
|
|
26
|
+
});
|
package/README.md
DELETED