@golar/vue 0.0.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/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.js +20 -0
- package/dist/bin.js +16 -0
- package/dist/language-plugin.js +61 -0
- package/dist/patch-language-tools.js +50 -0
- package/dist/typescript-lite.js +36113 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 auvred <https://github.com/auvred>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) {
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (!no_symbols) {
|
|
14
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { __exportAll };
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createVolarPlugin } from "@golar/volar";
|
|
3
|
+
|
|
4
|
+
//#region src/bin.ts
|
|
5
|
+
createVolarPlugin({
|
|
6
|
+
filename: import.meta.filename,
|
|
7
|
+
extraFileExtensions: [".vue"],
|
|
8
|
+
languagePlugins: async (cwd, configFileName) => {
|
|
9
|
+
await import("./patch-language-tools.js");
|
|
10
|
+
const { vueLanguagePlugin } = await import("./language-plugin.js");
|
|
11
|
+
return [await vueLanguagePlugin(cwd, configFileName)];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ScriptKind, sys, typescript_lite_exports } from "./typescript-lite.js";
|
|
2
|
+
import { createParsedCommandLine, createParsedCommandLineByJson, forEachEmbeddedCode } from "@vue/language-core";
|
|
3
|
+
import compilerDom from "@vue/compiler-dom";
|
|
4
|
+
import { VueVirtualCode } from "@vue/language-core/lib/virtualCode/index.js";
|
|
5
|
+
import PluginVueTsx from "@vue/language-core/lib/plugins/vue-tsx.js";
|
|
6
|
+
import PluginFileVue from "@vue/language-core/lib/plugins/file-vue.js";
|
|
7
|
+
import PluginVueScriptJs from "@vue/language-core/lib/plugins/vue-script-js.js";
|
|
8
|
+
import PluginVueTemplateHtml from "@vue/language-core/lib/plugins/vue-template-html.js";
|
|
9
|
+
|
|
10
|
+
//#region src/language-plugin.ts
|
|
11
|
+
async function vueLanguagePlugin(cwd, configFileName) {
|
|
12
|
+
const { options: compilerOptions, vueOptions: vueCompilerOptions } = configFileName == null ? createParsedCommandLineByJson(typescript_lite_exports, sys, cwd, {}) : createParsedCommandLine(typescript_lite_exports, sys, configFileName);
|
|
13
|
+
const plugins = (await Promise.all([
|
|
14
|
+
PluginVueTsx,
|
|
15
|
+
PluginFileVue,
|
|
16
|
+
PluginVueScriptJs,
|
|
17
|
+
PluginVueTemplateHtml
|
|
18
|
+
])).flatMap(({ default: ctor }) => ctor({
|
|
19
|
+
modules: {
|
|
20
|
+
typescript: typescript_lite_exports,
|
|
21
|
+
"@vue/compiler-dom": compilerDom
|
|
22
|
+
},
|
|
23
|
+
compilerOptions,
|
|
24
|
+
vueCompilerOptions
|
|
25
|
+
}));
|
|
26
|
+
return {
|
|
27
|
+
getLanguageId(scriptId) {
|
|
28
|
+
return scriptId.endsWith(".vue") ? "vue" : void 0;
|
|
29
|
+
},
|
|
30
|
+
createVirtualCode(scriptId, languageId, snapshot) {
|
|
31
|
+
return new VueVirtualCode(scriptId, languageId, snapshot, vueCompilerOptions, plugins, typescript_lite_exports);
|
|
32
|
+
},
|
|
33
|
+
getVirtualCodeErrors(root) {
|
|
34
|
+
return root.vueSfc.errors.filter((e) => "code" in e).map((e) => ({
|
|
35
|
+
start: e.loc?.start.offset ?? 0,
|
|
36
|
+
end: e.loc?.end.offset ?? 0,
|
|
37
|
+
message: e.message
|
|
38
|
+
}));
|
|
39
|
+
},
|
|
40
|
+
typescript: {
|
|
41
|
+
extraFileExtensions: [{
|
|
42
|
+
extension: "vue",
|
|
43
|
+
isMixedContent: true,
|
|
44
|
+
scriptKind: 7
|
|
45
|
+
}],
|
|
46
|
+
getServiceScript(root) {
|
|
47
|
+
for (const code of forEachEmbeddedCode(root)) if (/script_(js|jsx|ts|tsx)/.test(code.id)) {
|
|
48
|
+
const lang = code.id.slice(7);
|
|
49
|
+
return {
|
|
50
|
+
code,
|
|
51
|
+
extension: "." + lang,
|
|
52
|
+
scriptKind: lang === "js" ? ScriptKind.JS : lang === "jsx" ? ScriptKind.JSX : lang === "tsx" ? ScriptKind.TSX : ScriptKind.TS
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
export { vueLanguagePlugin };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region src/patch-language-tools.ts
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const originalReadFileSync = fs.readFileSync;
|
|
8
|
+
function patchFile(filePath, patch) {
|
|
9
|
+
let patched = false;
|
|
10
|
+
fs.readFileSync = (...args) => {
|
|
11
|
+
const src = originalReadFileSync(...args).toString();
|
|
12
|
+
fs.readFileSync = originalReadFileSync;
|
|
13
|
+
patched = true;
|
|
14
|
+
return patch(src);
|
|
15
|
+
};
|
|
16
|
+
require(filePath);
|
|
17
|
+
fs.readFileSync = originalReadFileSync;
|
|
18
|
+
assert.ok(patched, `Golar bug: File ${filePath} wasn't patched; most probably it has been already loaded`);
|
|
19
|
+
}
|
|
20
|
+
patchFile("@vue/language-core/lib/codegen/template/context.js", (src) => {
|
|
21
|
+
src = replaceOrThrow(src, "function createTemplateCodegenContext()", () => `function createTemplateCodegenContext(options)`);
|
|
22
|
+
src = replaceOrThrow(src, "function resolveCodeFeatures", (s) => `${s}(...args) {
|
|
23
|
+
const features = _resolveCodeFeatures(...args)
|
|
24
|
+
const data = stack.at(-1)
|
|
25
|
+
if (data?.expectError != null) {
|
|
26
|
+
features.__expectErrorCommentLoc = [
|
|
27
|
+
(options?.template?.startTagEnd ?? 0) + data.expectError.node.loc.start.offset,
|
|
28
|
+
(options?.template?.startTagEnd ?? 0) + data.expectError.node.loc.end.offset,
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
return features
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _resolveCodeFeatures`);
|
|
35
|
+
return src;
|
|
36
|
+
});
|
|
37
|
+
patchFile("@vue/language-core/lib/codegen/template/index.js", (src) => {
|
|
38
|
+
src = replaceOrThrow(src, "createTemplateCodegenContext)()", () => `createTemplateCodegenContext)(options)`);
|
|
39
|
+
return src;
|
|
40
|
+
});
|
|
41
|
+
function replaceOrThrow(source, search, replace) {
|
|
42
|
+
const before = source;
|
|
43
|
+
source = source.replace(search, replace);
|
|
44
|
+
const after = source;
|
|
45
|
+
if (after === before) throw new Error("Golar bug: failed to replace: " + search.toString());
|
|
46
|
+
return after;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { };
|