@lumiose/prettier-plugin 0.0.0-stage → 0.2.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 +21 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +74 -0
- package/package.json +35 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Javi Aguilar
|
|
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Plugin } from "prettier";
|
|
2
|
+
/** The parsed file: already formatted, since the work happens in the (async) parser. */
|
|
3
|
+
interface StsxDocument {
|
|
4
|
+
type: "stsx";
|
|
5
|
+
formatted: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const languages: Plugin["languages"];
|
|
8
|
+
export declare const parsers: Plugin<StsxDocument>["parsers"];
|
|
9
|
+
export declare const printers: Plugin<StsxDocument>["printers"];
|
|
10
|
+
declare const plugin: Plugin<StsxDocument>;
|
|
11
|
+
export default plugin;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// `@lumiose/prettier-plugin` (TASK-41): Prettier formats `.stsx` files the way `lumiose fmt` does, with
|
|
2
|
+
// Prettier's own printers. `lumiose fmt`'s algorithm (@lumiose/cli/tooling `formatStsx`) does the work:
|
|
3
|
+
// the TSX with every style block replaced by a placeholder goes through Prettier's TypeScript
|
|
4
|
+
// printer, each block's CSS through its CSS printer (`$` references protected), and the blocks are
|
|
5
|
+
// re-indented at their placement. Files with scanner or syntax errors are reported, not changed.
|
|
6
|
+
//
|
|
7
|
+
// // .prettierrc.json
|
|
8
|
+
// { "plugins": ["@lumiose/prettier-plugin"] }
|
|
9
|
+
//
|
|
10
|
+
// oxfmt (which `lumiose fmt` uses) has no plugin API, so this is the way to keep Prettier for `.stsx`.
|
|
11
|
+
import { formatStsx } from "@lumiose/cli/tooling";
|
|
12
|
+
import { format } from "prettier";
|
|
13
|
+
/** The Prettier options that shape TSX and CSS output, passed on to both printers. */
|
|
14
|
+
const FORMAT_OPTIONS = [
|
|
15
|
+
"printWidth",
|
|
16
|
+
"tabWidth",
|
|
17
|
+
"useTabs",
|
|
18
|
+
"semi",
|
|
19
|
+
"singleQuote",
|
|
20
|
+
"jsxSingleQuote",
|
|
21
|
+
"quoteProps",
|
|
22
|
+
"trailingComma",
|
|
23
|
+
"bracketSpacing",
|
|
24
|
+
"bracketSameLine",
|
|
25
|
+
"objectWrap",
|
|
26
|
+
"arrowParens",
|
|
27
|
+
"singleAttributePerLine",
|
|
28
|
+
"endOfLine",
|
|
29
|
+
];
|
|
30
|
+
/** Formats TSX or CSS with Prettier, in the shape `formatStsx` expects from oxfmt. */
|
|
31
|
+
const prettierFormatter = async (fileName, source, options) => {
|
|
32
|
+
try {
|
|
33
|
+
const parser = fileName.endsWith(".css") ? "css" : "typescript";
|
|
34
|
+
return { code: await format(source, { ...options, parser }), errors: [] };
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return { code: source, errors: [{ message: error.message }] };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const languages = [
|
|
41
|
+
{
|
|
42
|
+
name: "Lumiose STSX",
|
|
43
|
+
parsers: ["stsx"],
|
|
44
|
+
extensions: [".stsx"],
|
|
45
|
+
vscodeLanguageIds: ["stsx"],
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
export const parsers = {
|
|
49
|
+
stsx: {
|
|
50
|
+
astFormat: "lumiose-stsx",
|
|
51
|
+
async parse(text, options) {
|
|
52
|
+
const config = {};
|
|
53
|
+
for (const key of FORMAT_OPTIONS) {
|
|
54
|
+
const value = options[key];
|
|
55
|
+
if (value !== undefined)
|
|
56
|
+
config[key] = value;
|
|
57
|
+
}
|
|
58
|
+
const file = typeof options.filepath === "string" ? options.filepath : "component.stsx";
|
|
59
|
+
const result = await formatStsx(text, file, prettierFormatter, config);
|
|
60
|
+
if (!result.ok)
|
|
61
|
+
throw new SyntaxError(`${file}: ${result.error}`);
|
|
62
|
+
return { type: "stsx", formatted: result.code };
|
|
63
|
+
},
|
|
64
|
+
locStart: () => 0,
|
|
65
|
+
locEnd: (node) => node.formatted.length,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
export const printers = {
|
|
69
|
+
"lumiose-stsx": {
|
|
70
|
+
print: (path) => path.node.formatted,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const plugin = { languages, parsers, printers };
|
|
74
|
+
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumiose/prettier-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Prettier support for Lumiose .stsx files: the TSX with Prettier's TypeScript printer, each <style> block with its CSS printer, re-indented at its placement (like lumiose fmt).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/itsjavi/lumiose.git",
|
|
9
|
+
"directory": "packages/prettier-plugin"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@lumiose/cli": "0.2.0",
|
|
24
|
+
"lumiose": "0.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@lumiose/compiler": "0.2.0",
|
|
28
|
+
"prettier": "^3.9.9"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"prettier": "^3.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"build": "node ../../scripts/build-package.ts"
|
|
37
|
+
}
|
|
6
38
|
}
|
package/README.md
DELETED