@flint.fyi/volar-language 0.0.1 → 0.1.0
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.md +20 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/language.d.ts +35 -0
- package/lib/language.js +220 -0
- package/lib/package.js +7 -0
- package/package.json +45 -8
- package/README.md +0 -45
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FileAboutData, FileReport, Language, Language as Language$2, LanguageFileCacheImpacts, LanguageReports, RuleContext, RuleReport } from "@flint.fyi/core";
|
|
2
|
+
import { AST, ExtractedDirective, TypeScriptFileServices, TypeScriptNodesByName } from "@flint.fyi/typescript-language";
|
|
3
|
+
import * as typescript from "typescript";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { Language as Language$1, LanguagePlugin, SourceScript } from "@volar/language-core";
|
|
6
|
+
import { TypeScriptServiceScript } from "@volar/typescript";
|
|
7
|
+
|
|
8
|
+
//#region src/language.d.ts
|
|
9
|
+
type VolarLanguagePluginInitializer<FileServices extends object> = (ts: typeof typescript, options: ts.CreateProgramOptions) => {
|
|
10
|
+
createFile: VolarBasedLanguageCreateFile<FileServices>;
|
|
11
|
+
languagePlugins: LanguagePlugin<string>[];
|
|
12
|
+
};
|
|
13
|
+
interface VolarBasedLanguageCreateFileContext {
|
|
14
|
+
data: FileAboutData;
|
|
15
|
+
program: ts.Program;
|
|
16
|
+
serviceScript: TypeScriptServiceScript;
|
|
17
|
+
sourceFile: AST.SourceFile;
|
|
18
|
+
sourceScript: SourceScript<string> & {
|
|
19
|
+
generated: NonNullable<SourceScript<string>["generated"]>;
|
|
20
|
+
};
|
|
21
|
+
volarLanguage: Language$1;
|
|
22
|
+
}
|
|
23
|
+
type VolarBasedLanguageCreateFile<FileServices extends object> = (ctx: VolarBasedLanguageCreateFileContext) => {
|
|
24
|
+
cache?: LanguageFileCacheImpacts;
|
|
25
|
+
directives?: ExtractedDirective[];
|
|
26
|
+
extraContext?: FileServices;
|
|
27
|
+
firstStatementPosition: number;
|
|
28
|
+
getLanguageReports?: () => LanguageReports;
|
|
29
|
+
reports?: FileReport[];
|
|
30
|
+
};
|
|
31
|
+
declare function createVolarBasedLanguage<FileServices extends object>(initializer: VolarLanguagePluginInitializer<FileServices>): Language<TypeScriptNodesByName, Partial<FileServices> & TypeScriptFileServices>;
|
|
32
|
+
declare function reportSourceCode<T extends string>(context: RuleContext<T>, report: RuleReport<T>): void;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { type Language$2 as Language, createVolarBasedLanguage, reportSourceCode };
|
|
35
|
+
//# sourceMappingURL=language.d.ts.map
|
package/lib/language.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { name, version } from "./package.js";
|
|
2
|
+
import { DirectivesCollector, createLanguage, getColumnAndLineOfPosition, isSuggestionForFiles } from "@flint.fyi/core";
|
|
3
|
+
import { setTSProgramCreationProxy } from "@flint.fyi/ts-patch";
|
|
4
|
+
import { NodeSyntaxKinds, convertTypeScriptDiagnosticToLanguageReport, extractDirectivesFromTypeScriptFile, setVolarCreateFile, throwUnknownLanguageExtension, typescriptLanguage } from "@flint.fyi/typescript-language";
|
|
5
|
+
import { FlintAssertionError, assert, nullThrows } from "@flint.fyi/utils";
|
|
6
|
+
import { proxyCreateProgram } from "@volar/typescript/lib/node/proxyCreateProgram.js";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
//#region src/language.ts
|
|
9
|
+
const stateSymbol = Symbol.for("@flint.fyi/volar-language/state");
|
|
10
|
+
const globalTyped = globalThis;
|
|
11
|
+
assert(globalTyped[stateSymbol] == null, `Two different versions of ${name} are imported: ${version} and ${globalTyped[stateSymbol]?.packageVersion}`);
|
|
12
|
+
const { pluginInitializers } = globalTyped[stateSymbol] = {
|
|
13
|
+
packageVersion: version,
|
|
14
|
+
pluginInitializers: /* @__PURE__ */ new Set()
|
|
15
|
+
};
|
|
16
|
+
setTSProgramCreationProxy((ts, createProgram) => new Proxy(function() {}, { apply(_, thisArg, args) {
|
|
17
|
+
let volarLanguage = null;
|
|
18
|
+
const proxied = proxyCreateProgram(ts, new Proxy(createProgram, { apply(target, thisArg, [options]) {
|
|
19
|
+
assert(options.host != null, "Expected options.host to be defined");
|
|
20
|
+
const patchedGetSourceFile = options.host.getSourceFile.bind(options.host);
|
|
21
|
+
options.host.getSourceFile = (...args) => {
|
|
22
|
+
try {
|
|
23
|
+
return patchedGetSourceFile(...args);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (error instanceof Error && error.message === "!!sourceScript") throwUnknownLanguageExtension(args[0]);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return Reflect.apply(target, thisArg, args);
|
|
30
|
+
} }), (ts, options) => {
|
|
31
|
+
return {
|
|
32
|
+
languagePlugins: Array.from(pluginInitializers).map((initializer) => initializer(ts, options)).flatMap(({ createFile, languagePlugins }) => languagePlugins.map((plugin) => {
|
|
33
|
+
if (plugin.typescript == null) return plugin;
|
|
34
|
+
plugin[stateSymbol] = { createFile };
|
|
35
|
+
const getServiceScript = plugin.typescript.getServiceScript.bind(plugin.typescript);
|
|
36
|
+
plugin.typescript.getServiceScript = (root) => {
|
|
37
|
+
const script = getServiceScript(root);
|
|
38
|
+
if (script == null) return script;
|
|
39
|
+
return {
|
|
40
|
+
...script,
|
|
41
|
+
preventLeadingOffset: true
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
return plugin;
|
|
45
|
+
})),
|
|
46
|
+
setup: (lang) => {
|
|
47
|
+
volarLanguage = lang;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const program = Reflect.apply(proxied, thisArg, args);
|
|
52
|
+
assert(volarLanguage != null, "Expected volarLanguage to be set");
|
|
53
|
+
program[stateSymbol] ??= { volarLanguage };
|
|
54
|
+
return program;
|
|
55
|
+
} }));
|
|
56
|
+
setVolarCreateFile((data, program, sourceFile) => {
|
|
57
|
+
const volarLanguage = nullThrows(program[stateSymbol]?.volarLanguage, "TypeScript wasn't proxied with Volar.js");
|
|
58
|
+
const sourceScript = volarLanguage.scripts.get(sourceFile.fileName);
|
|
59
|
+
assert(sourceScript != null, `Volar.js source script for ${sourceFile.fileName} is undefined`);
|
|
60
|
+
assert(sourceScript.generated != null, `Volar.js sourceScript.generated for ${sourceFile.fileName} is undefined`);
|
|
61
|
+
assert(sourceScript.generated.languagePlugin.typescript != null, `Volar.js sourceScript.generated.languagePlugin.typescript for ${sourceFile.fileName} is undefined`);
|
|
62
|
+
const createFile = nullThrows(sourceScript.generated.languagePlugin[stateSymbol]?.createFile, `Volar.js language plugin for script (${sourceFile.fileName}) with language id ${sourceScript.generated.root.languageId} doesn't have __flintCreateFile property`);
|
|
63
|
+
const sourceText = sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength());
|
|
64
|
+
const sourceTextWithLineMap = { text: sourceText };
|
|
65
|
+
function normalizeSourceRange(range) {
|
|
66
|
+
return {
|
|
67
|
+
begin: getColumnAndLineOfPosition(sourceTextWithLineMap, range.begin),
|
|
68
|
+
end: getColumnAndLineOfPosition(sourceTextWithLineMap, range.end)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const serviceScript = nullThrows(sourceScript.generated.languagePlugin.typescript.getServiceScript(sourceScript.generated.root), `Volar.js service script for ${sourceFile.fileName} is undefined`);
|
|
72
|
+
const map = volarLanguage.maps.get(serviceScript.code, sourceScript);
|
|
73
|
+
const sortedMappings = map.mappings.toSorted(({ generatedOffsets: [a] }, { generatedOffsets: [b] }) => {
|
|
74
|
+
assert(a != null, "Expected generatedOffsets to have at least one element");
|
|
75
|
+
assert(b != null, "Expected generatedOffsets to have at least one element");
|
|
76
|
+
return a - b;
|
|
77
|
+
});
|
|
78
|
+
const { directives, extraContext, firstStatementPosition, getLanguageReports, reports } = createFile({
|
|
79
|
+
data,
|
|
80
|
+
program,
|
|
81
|
+
serviceScript,
|
|
82
|
+
sourceFile,
|
|
83
|
+
sourceScript,
|
|
84
|
+
volarLanguage
|
|
85
|
+
});
|
|
86
|
+
const translatedDirectives = [...directives ?? []];
|
|
87
|
+
for (const directive of extractDirectivesFromTypeScriptFile(sourceFile)) {
|
|
88
|
+
const range = translateRange(map, directive.range.begin.raw, directive.range.end.raw);
|
|
89
|
+
if (range != null) translatedDirectives.push({
|
|
90
|
+
...directive,
|
|
91
|
+
range: normalizeSourceRange(range)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const directivesCollector = new DirectivesCollector(firstStatementPosition);
|
|
95
|
+
translatedDirectives.sort((a, b) => a.range.begin.raw - b.range.begin.raw);
|
|
96
|
+
for (const { range, selection, type } of translatedDirectives) directivesCollector.add(range, selection, type);
|
|
97
|
+
const collected = directivesCollector.collect();
|
|
98
|
+
return {
|
|
99
|
+
__volarServices: {
|
|
100
|
+
runVisitors(file, options, runtime) {
|
|
101
|
+
const { visitors } = runtime;
|
|
102
|
+
if (!visitors) return;
|
|
103
|
+
const visitorServices = {
|
|
104
|
+
options,
|
|
105
|
+
...file.services
|
|
106
|
+
};
|
|
107
|
+
let lastMappingIdx = 0;
|
|
108
|
+
const visit = (node) => {
|
|
109
|
+
const key = NodeSyntaxKinds[node.kind];
|
|
110
|
+
visitors[key]?.(node, visitorServices);
|
|
111
|
+
node.forEachChild(visit);
|
|
112
|
+
visitors[`${key}:exit`]?.(node, visitorServices);
|
|
113
|
+
};
|
|
114
|
+
visitors.SourceFile?.(sourceFile, visitorServices);
|
|
115
|
+
Statements: for (const statement of sourceFile.statements) {
|
|
116
|
+
while (true) {
|
|
117
|
+
const currentMapping = sortedMappings[lastMappingIdx];
|
|
118
|
+
if (currentMapping == null) break Statements;
|
|
119
|
+
const currentMappingOffset = nullThrows(currentMapping.generatedOffsets[0], "Expected mapping to have at least one generated offset");
|
|
120
|
+
const currentMappingLength = nullThrows(currentMapping.generatedLengths?.[0] ?? currentMapping.lengths[0], "Expected mapping to have at least one length");
|
|
121
|
+
if (currentMappingLength === 0 || statement.pos >= currentMappingOffset + currentMappingLength) {
|
|
122
|
+
lastMappingIdx++;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (statement.end <= currentMappingOffset) continue Statements;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
visit(statement);
|
|
129
|
+
}
|
|
130
|
+
visit(sourceFile.endOfFileToken);
|
|
131
|
+
},
|
|
132
|
+
getLanguageReports() {
|
|
133
|
+
return [...ts.getPreEmitDiagnostics(program, sourceFile).map((diagnostic) => convertTypeScriptDiagnosticToLanguageReport({
|
|
134
|
+
...diagnostic,
|
|
135
|
+
file: diagnostic.file ? {
|
|
136
|
+
fileName: diagnostic.file.fileName,
|
|
137
|
+
text: sourceText
|
|
138
|
+
} : diagnostic.file
|
|
139
|
+
})), ...getLanguageReports?.() ?? []];
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
about: {
|
|
143
|
+
...data,
|
|
144
|
+
sourceText
|
|
145
|
+
},
|
|
146
|
+
adjustReportRange(range) {
|
|
147
|
+
if (range.begin < 0) return {
|
|
148
|
+
begin: -range.begin,
|
|
149
|
+
end: range.end
|
|
150
|
+
};
|
|
151
|
+
return translateRange(map, range.begin, range.end);
|
|
152
|
+
},
|
|
153
|
+
directives: collected.directives,
|
|
154
|
+
language: typescriptLanguage,
|
|
155
|
+
reports: [...collected.reports, ...reports ?? []],
|
|
156
|
+
services: {
|
|
157
|
+
program,
|
|
158
|
+
sourceFile,
|
|
159
|
+
typeChecker: program.getTypeChecker(),
|
|
160
|
+
...extraContext
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
function createVolarBasedLanguage(initializer) {
|
|
165
|
+
pluginInitializers.add(initializer);
|
|
166
|
+
return {
|
|
167
|
+
...createLanguage({
|
|
168
|
+
about: { name: "Volar.js-based language" },
|
|
169
|
+
createFileFactory() {
|
|
170
|
+
throw new FlintAssertionError("Volar.js based language should never be called directly");
|
|
171
|
+
},
|
|
172
|
+
runFileVisitors() {
|
|
173
|
+
throw new FlintAssertionError("Volar.js based language should never be called directly");
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
createRule: (ruleDefinition) => {
|
|
177
|
+
return {
|
|
178
|
+
...ruleDefinition,
|
|
179
|
+
language: typescriptLanguage
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function reportSourceCode(context, report) {
|
|
185
|
+
context.report({
|
|
186
|
+
...report,
|
|
187
|
+
fix: (report.fix && !Array.isArray(report.fix) ? [report.fix] : report.fix)?.map((change) => ({
|
|
188
|
+
...change,
|
|
189
|
+
range: sourceCodeRange(change.range)
|
|
190
|
+
})),
|
|
191
|
+
range: sourceCodeRange(report.range),
|
|
192
|
+
suggestions: report.suggestions?.map((suggestion) => {
|
|
193
|
+
if (isSuggestionForFiles(suggestion)) return null;
|
|
194
|
+
return {
|
|
195
|
+
...suggestion,
|
|
196
|
+
range: sourceCodeRange(suggestion.range)
|
|
197
|
+
};
|
|
198
|
+
}).filter((s) => s != null)
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function sourceCodeRange(range) {
|
|
202
|
+
return {
|
|
203
|
+
begin: -range.begin,
|
|
204
|
+
end: range.end
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function translateRange(map, serviceBegin, serviceEnd) {
|
|
208
|
+
for (const [begin, end] of map.toSourceRange(serviceBegin, serviceEnd, true)) {
|
|
209
|
+
if (begin === end) continue;
|
|
210
|
+
return {
|
|
211
|
+
begin,
|
|
212
|
+
end
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
export { createVolarBasedLanguage, reportSourceCode };
|
|
219
|
+
|
|
220
|
+
//# sourceMappingURL=language.js.map
|
package/lib/package.js
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flint.fyi/volar-language",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
}
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "[Experimental] Volar.js language for Flint.",
|
|
5
|
+
"homepage": "https://flint.fyi",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/flint-fyi/flint.git",
|
|
9
|
+
"directory": "packages/volar-language"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "JoshuaKGoldberg",
|
|
14
|
+
"email": "npm@joshuakgoldberg.com"
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": true,
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"lib/",
|
|
23
|
+
"!lib/**/*.map"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@volar/language-core": "2.4.28",
|
|
27
|
+
"@volar/typescript": "2.4.28",
|
|
28
|
+
"typescript": "^5.9.0 || ^6.0.0",
|
|
29
|
+
"@flint.fyi/core": "^0.21.0",
|
|
30
|
+
"@flint.fyi/ts-patch": "^0.13.5",
|
|
31
|
+
"@flint.fyi/typescript-language": "^0.18.0",
|
|
32
|
+
"@flint.fyi/utils": "^0.14.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsdown": "0.21.0",
|
|
36
|
+
"vitest": "4.1.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=24.0.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"test": "vitest --project volar-language"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/README.md
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# @flint.fyi/volar-language
|
|
2
|
-
|
|
3
|
-
## ⚠️ IMPORTANT NOTICE ⚠️
|
|
4
|
-
|
|
5
|
-
**This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
|
|
6
|
-
|
|
7
|
-
This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
|
|
8
|
-
|
|
9
|
-
## Purpose
|
|
10
|
-
|
|
11
|
-
This package exists to:
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@flint.fyi/volar-language`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
15
|
-
|
|
16
|
-
## What is OIDC Trusted Publishing?
|
|
17
|
-
|
|
18
|
-
OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
|
|
19
|
-
|
|
20
|
-
## Setup Instructions
|
|
21
|
-
|
|
22
|
-
To properly configure OIDC trusted publishing for this package:
|
|
23
|
-
|
|
24
|
-
1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
|
|
25
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
28
|
-
|
|
29
|
-
## DO NOT USE THIS PACKAGE
|
|
30
|
-
|
|
31
|
-
This package is a placeholder for OIDC configuration only. It:
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
36
|
-
|
|
37
|
-
## More Information
|
|
38
|
-
|
|
39
|
-
For more details about npm's trusted publishing feature, see:
|
|
40
|
-
- [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
|
|
41
|
-
- [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
|
|
42
|
-
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
**Maintained for OIDC setup purposes only**
|