@flint.fyi/svelte-language 0.0.1 → 0.0.3
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/README.md +7 -43
- package/lib/extractDirectives.d.ts +5 -0
- package/lib/extractDirectives.js +27 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/language.d.ts +15 -0
- package/lib/language.js +65 -0
- package/lib/volarLanguagePlugin.d.ts +7 -0
- package/lib/volarLanguagePlugin.js +149 -0
- package/package.json +48 -8
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/README.md
CHANGED
|
@@ -1,45 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center"><code>@flint.fyi/svelte-language</code></h1>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
[Experimental] Svelte language for Flint.
|
|
5
|
+
❤️🔥
|
|
6
|
+
</p>
|
|
4
7
|
|
|
5
|
-
|
|
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/svelte-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**
|
|
8
|
+
This is an internal package for Flint.
|
|
9
|
+
Documentation will eventually be added.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type SourceFileWithLineMap } from "@flint.fyi/core";
|
|
2
|
+
import type { ExtractedDirective } from "@flint.fyi/typescript-language";
|
|
3
|
+
import type { AST } from "svelte/compiler";
|
|
4
|
+
export declare function extractDirectives(ast: AST.Root, source: SourceFileWithLineMap): ExtractedDirective[];
|
|
5
|
+
//# sourceMappingURL=extractDirectives.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getColumnAndLineOfPosition } from "@flint.fyi/core";
|
|
2
|
+
import { nullThrows } from "@flint.fyi/utils";
|
|
3
|
+
//#region src/extractDirectives.ts
|
|
4
|
+
function extractDirectives(ast, source) {
|
|
5
|
+
const directives = [];
|
|
6
|
+
function visit(node) {
|
|
7
|
+
if ("fragment" in node) for (const child of node.fragment.nodes) visit(child);
|
|
8
|
+
if (node.type !== "Comment") return;
|
|
9
|
+
const match = /\s*flint-(\S+)(?:\s+(.+))?/.exec(node.data);
|
|
10
|
+
if (match == null) return;
|
|
11
|
+
const [, type, selection] = match;
|
|
12
|
+
directives.push({
|
|
13
|
+
range: {
|
|
14
|
+
begin: getColumnAndLineOfPosition(source, node.start),
|
|
15
|
+
end: getColumnAndLineOfPosition(source, node.end)
|
|
16
|
+
},
|
|
17
|
+
selection: nullThrows(selection, "Expected RegExp to provide second capturing group"),
|
|
18
|
+
type: nullThrows(type, "Expected RegExp to provide first capturing group")
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
for (const child of ast.fragment.nodes) visit(child);
|
|
22
|
+
return directives;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { extractDirectives };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=extractDirectives.js.map
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AST } from "svelte/compiler";
|
|
2
|
+
import * as _flint_fyi_core0 from "@flint.fyi/core";
|
|
3
|
+
import * as _flint_fyi_typescript_language0 from "@flint.fyi/typescript-language";
|
|
4
|
+
|
|
5
|
+
//#region src/language.d.ts
|
|
6
|
+
interface SvelteServices {
|
|
7
|
+
svelte: {
|
|
8
|
+
ast: AST.Root;
|
|
9
|
+
sourceText: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
declare const svelteLanguage: _flint_fyi_core0.Language<_flint_fyi_typescript_language0.TypeScriptNodesByName, Partial<SvelteServices> & _flint_fyi_typescript_language0.TypeScriptFileServices>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { svelteLanguage };
|
|
15
|
+
//# sourceMappingURL=language.d.ts.map
|
package/lib/language.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { extractDirectives } from "./extractDirectives.js";
|
|
2
|
+
import { errorToLanguageReport, virtualCodeReports, volarLanguagePlugin } from "./volarLanguagePlugin.js";
|
|
3
|
+
import { setTSExtraSupportedExtensions } from "@flint.fyi/ts-patch";
|
|
4
|
+
import { createVolarBasedLanguage } from "@flint.fyi/volar-language";
|
|
5
|
+
import { parse } from "svelte/compiler";
|
|
6
|
+
//#region src/language.ts
|
|
7
|
+
setTSExtraSupportedExtensions([".svelte"]);
|
|
8
|
+
const svelteLanguage = createVolarBasedLanguage((ts, options) => {
|
|
9
|
+
return {
|
|
10
|
+
createFile({ sourceFile, sourceScript }) {
|
|
11
|
+
const sourceText = sourceScript.snapshot.getText(0, sourceScript.snapshot.getLength());
|
|
12
|
+
const source = { text: sourceText };
|
|
13
|
+
const virtualCode = sourceScript.generated.root;
|
|
14
|
+
let ast;
|
|
15
|
+
const reports = [];
|
|
16
|
+
try {
|
|
17
|
+
ast = parse(sourceText, {
|
|
18
|
+
loose: true,
|
|
19
|
+
modern: true
|
|
20
|
+
});
|
|
21
|
+
} catch (error) {
|
|
22
|
+
reports.push(errorToLanguageReport(sourceFile.fileName, error));
|
|
23
|
+
ast = {
|
|
24
|
+
comments: [],
|
|
25
|
+
css: null,
|
|
26
|
+
end: 0,
|
|
27
|
+
fragment: {
|
|
28
|
+
nodes: [],
|
|
29
|
+
type: "Fragment"
|
|
30
|
+
},
|
|
31
|
+
instance: null,
|
|
32
|
+
module: null,
|
|
33
|
+
options: null,
|
|
34
|
+
start: 0,
|
|
35
|
+
type: "Root"
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const codegenReport = virtualCodeReports.get(virtualCode);
|
|
39
|
+
if (codegenReport != null) reports.push(codegenReport);
|
|
40
|
+
return {
|
|
41
|
+
directives: extractDirectives(ast, source),
|
|
42
|
+
extraContext: { svelte: {
|
|
43
|
+
ast,
|
|
44
|
+
sourceText
|
|
45
|
+
} },
|
|
46
|
+
firstStatementPosition: Math.min(...[
|
|
47
|
+
ast.fragment.nodes.find((node) => node.type !== "Text" || !!node.data.trim().length)?.start,
|
|
48
|
+
ast.module?.start,
|
|
49
|
+
ast.instance?.start,
|
|
50
|
+
ast.css?.start,
|
|
51
|
+
ast.options?.start,
|
|
52
|
+
sourceText.length
|
|
53
|
+
].filter((pos) => typeof pos === "number")),
|
|
54
|
+
getLanguageReports() {
|
|
55
|
+
return reports;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
languagePlugins: [volarLanguagePlugin(ts, options)]
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
//#endregion
|
|
63
|
+
export { svelteLanguage };
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=language.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type LanguageReport } from "@flint.fyi/core";
|
|
2
|
+
import { type LanguagePlugin, type VirtualCode } from "@volar/language-core";
|
|
3
|
+
import type * as ts from "typescript";
|
|
4
|
+
export declare function volarLanguagePlugin(ts: typeof import("typescript"), options: ts.CreateProgramOptions): LanguagePlugin<string>;
|
|
5
|
+
export declare const virtualCodeReports: WeakMap<VirtualCode, LanguageReport>;
|
|
6
|
+
export declare function errorToLanguageReport(fileName: string, error: unknown): LanguageReport;
|
|
7
|
+
//# sourceMappingURL=volarLanguagePlugin.d.ts.map
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { getPositionOfColumnAndLine } from "@flint.fyi/core";
|
|
2
|
+
import { decode } from "@jridgewell/sourcemap-codec";
|
|
3
|
+
import { forEachEmbeddedCode } from "@volar/language-core";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import url from "node:url";
|
|
6
|
+
import { internalHelpers, svelte2tsx } from "svelte2tsx";
|
|
7
|
+
//#region src/volarLanguagePlugin.ts
|
|
8
|
+
const sveltePath = path.dirname(url.fileURLToPath(import.meta.resolve("svelte/package.json")));
|
|
9
|
+
const svelte2tsxPath = path.dirname(url.fileURLToPath(import.meta.resolve("svelte2tsx/package.json")));
|
|
10
|
+
function volarLanguagePlugin(ts, options) {
|
|
11
|
+
const cwd = typeof options.options.configFilePath === "string" ? path.dirname(options.options.configFilePath) : (options.host ?? ts.sys).getCurrentDirectory();
|
|
12
|
+
return {
|
|
13
|
+
createVirtualCode(fileName, languageId, snapshot) {
|
|
14
|
+
if (languageId !== "svelte") return;
|
|
15
|
+
return {
|
|
16
|
+
codegenStacks: [],
|
|
17
|
+
embeddedCodes: [getEmbeddedTsCode(ts, cwd, fileName, snapshot.getText(0, snapshot.getLength()))],
|
|
18
|
+
id: "root",
|
|
19
|
+
languageId,
|
|
20
|
+
mappings: [],
|
|
21
|
+
snapshot
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
getLanguageId(fileName) {
|
|
25
|
+
if (fileName.endsWith(".svelte")) return "svelte";
|
|
26
|
+
},
|
|
27
|
+
typescript: {
|
|
28
|
+
extraFileExtensions: [{
|
|
29
|
+
extension: "svelte",
|
|
30
|
+
isMixedContent: true,
|
|
31
|
+
scriptKind: 7
|
|
32
|
+
}],
|
|
33
|
+
getServiceScript(root) {
|
|
34
|
+
for (const code of forEachEmbeddedCode(root)) if (code.id === "tsx") return {
|
|
35
|
+
code,
|
|
36
|
+
extension: ".tsx",
|
|
37
|
+
scriptKind: 4
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
updateVirtualCode(fileName, virtualCode, snapshot) {
|
|
42
|
+
virtualCode.snapshot = snapshot;
|
|
43
|
+
virtualCode.embeddedCodes = [getEmbeddedTsCode(ts, cwd, fileName, snapshot.getText(0, snapshot.getLength()))];
|
|
44
|
+
return virtualCode;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const virtualCodeReports = /* @__PURE__ */ new WeakMap();
|
|
49
|
+
function errorToLanguageReport(fileName, error) {
|
|
50
|
+
if (typeof error !== "object" || error == null) return { text: `${fileName} - Unknown error` };
|
|
51
|
+
const res = { text: `${fileName}${"position" in error && Array.isArray(error.position) ? `:${error.position[0]}:${error.position[1]}` : ""} - ${"message" in error && typeof error.message === "string" ? error.message : "Codegen error"}` };
|
|
52
|
+
if ("code" in error && typeof error.code === "string") res.code = error.code;
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
function getEmbeddedTsCode(ts, cwd, fileName, text) {
|
|
56
|
+
const svelteTsxFiles = internalHelpers.get_global_types(ts.sys, false, sveltePath, svelte2tsxPath, cwd);
|
|
57
|
+
try {
|
|
58
|
+
const tsx = svelte2tsx(text, {
|
|
59
|
+
isTsFile: true,
|
|
60
|
+
mode: "ts"
|
|
61
|
+
});
|
|
62
|
+
const v3Mappings = decode(tsx.map.mappings);
|
|
63
|
+
const sourceTextWithLineMap = { text };
|
|
64
|
+
const serviceTextWithLineMap = { text: tsx.code };
|
|
65
|
+
const mappings = [];
|
|
66
|
+
let current = null;
|
|
67
|
+
for (const [genLine, segments] of v3Mappings.entries()) for (const segment of segments) {
|
|
68
|
+
const genCharacter = segment[0];
|
|
69
|
+
const genOffset = getPositionOfColumnAndLine(serviceTextWithLineMap, {
|
|
70
|
+
column: genCharacter,
|
|
71
|
+
line: genLine
|
|
72
|
+
});
|
|
73
|
+
if (current != null) {
|
|
74
|
+
let length = genOffset - current.genOffset;
|
|
75
|
+
const sourceText = text.substring(current.sourceOffset, current.sourceOffset + length);
|
|
76
|
+
const genText = tsx.code.substring(current.genOffset, current.genOffset + length);
|
|
77
|
+
if (sourceText !== genText) {
|
|
78
|
+
length = 0;
|
|
79
|
+
for (let i = 0; i < genOffset - current.genOffset; i++) if (sourceText[i] === genText[i]) length = i + 1;
|
|
80
|
+
else break;
|
|
81
|
+
}
|
|
82
|
+
if (length > 0) {
|
|
83
|
+
const lastMapping = mappings.at(-1);
|
|
84
|
+
if (lastMapping && current.genOffset === lastMapping.generatedOffsets[0] + lastMapping.lengths[0] && current.sourceOffset === lastMapping.sourceOffsets[0] + lastMapping.lengths[0]) lastMapping.lengths[0] += length;
|
|
85
|
+
else mappings.push({
|
|
86
|
+
data: {
|
|
87
|
+
completion: true,
|
|
88
|
+
format: false,
|
|
89
|
+
navigation: true,
|
|
90
|
+
semantic: true,
|
|
91
|
+
structure: false,
|
|
92
|
+
verification: true
|
|
93
|
+
},
|
|
94
|
+
generatedOffsets: [current.genOffset],
|
|
95
|
+
lengths: [length],
|
|
96
|
+
sourceOffsets: [current.sourceOffset]
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
current = null;
|
|
100
|
+
}
|
|
101
|
+
if (segment[2] != null && segment[3] != null) current = {
|
|
102
|
+
genOffset,
|
|
103
|
+
sourceOffset: getPositionOfColumnAndLine(sourceTextWithLineMap, {
|
|
104
|
+
column: segment[3],
|
|
105
|
+
line: segment[2]
|
|
106
|
+
})
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const codeWithTypes = tsx.code + "\n\n" + svelteTsxFiles.map((p) => `import ${JSON.stringify(p)}`).join("\n");
|
|
110
|
+
return {
|
|
111
|
+
embeddedCodes: [],
|
|
112
|
+
id: "tsx",
|
|
113
|
+
languageId: "typescriptreact",
|
|
114
|
+
mappings,
|
|
115
|
+
snapshot: {
|
|
116
|
+
getChangeRange() {},
|
|
117
|
+
getLength() {
|
|
118
|
+
return codeWithTypes.length;
|
|
119
|
+
},
|
|
120
|
+
getText(start, end) {
|
|
121
|
+
return codeWithTypes.substring(start, end);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const report = errorToLanguageReport(fileName, error);
|
|
127
|
+
const code = {
|
|
128
|
+
embeddedCodes: [],
|
|
129
|
+
id: "tsx",
|
|
130
|
+
languageId: "typescriptreact",
|
|
131
|
+
mappings: [],
|
|
132
|
+
snapshot: {
|
|
133
|
+
getChangeRange() {},
|
|
134
|
+
getLength() {
|
|
135
|
+
return 0;
|
|
136
|
+
},
|
|
137
|
+
getText() {
|
|
138
|
+
return "";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
virtualCodeReports.set(code, report);
|
|
143
|
+
return code;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
export { errorToLanguageReport, virtualCodeReports, volarLanguagePlugin };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=volarLanguagePlugin.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flint.fyi/svelte-language",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
}
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "[Experimental] Svelte 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/svelte-language"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Flint Team",
|
|
14
|
+
"url": "https://flint.fyi/team"
|
|
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
|
+
"@jridgewell/sourcemap-codec": "^1.5.5",
|
|
27
|
+
"@volar/language-core": "2.4.28",
|
|
28
|
+
"svelte": "^5.0.0",
|
|
29
|
+
"svelte2tsx": "^0.7.52",
|
|
30
|
+
"typescript": "^5.9.0 || ^6.0.0",
|
|
31
|
+
"@flint.fyi/typescript-language": "^0.18.2",
|
|
32
|
+
"@flint.fyi/core": "^0.22.0",
|
|
33
|
+
"@flint.fyi/ts-patch": "^0.13.5",
|
|
34
|
+
"@flint.fyi/utils": "^0.14.1",
|
|
35
|
+
"@flint.fyi/volar-language": "^0.1.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsdown": "0.21.0",
|
|
39
|
+
"vitest": "4.1.0"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=24.0.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"test": "vitest --project svelte-language"
|
|
49
|
+
}
|
|
50
|
+
}
|