✨ Added dockerfile、lua prettier plugin
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
*.tgz
|
||||
*.unopt.wasm
|
||||
jsr.jsonc
|
||||
32
frontend/src/common/prettier/plugins/dart/extra/dart_fmt.d.ts
vendored
Normal file
32
frontend/src/common/prettier/plugins/dart/extra/dart_fmt.d.ts
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
export function format(input: string, filename: string, config?: LayoutConfig): string;
|
||||
|
||||
interface LayoutConfig {
|
||||
line_width?: number;
|
||||
line_ending?: "lf" | "crlf";
|
||||
language_version?: string;
|
||||
}
|
||||
|
||||
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
||||
|
||||
export type InitOutput = unknown;
|
||||
|
||||
// export type SyncInitInput = BufferSource | WebAssembly.Module;
|
||||
// /**
|
||||
// * Instantiates the given `module`, which can either be bytes or
|
||||
// * a precompiled `WebAssembly.Module`.
|
||||
// *
|
||||
// * @param {SyncInitInput} module
|
||||
// *
|
||||
// * @returns {InitOutput}
|
||||
// */
|
||||
// export function initSync(module: SyncInitInput): InitOutput;
|
||||
|
||||
/**
|
||||
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
||||
* for everything else, calls `WebAssembly.instantiate` directly.
|
||||
*
|
||||
* @param {InitInput | Promise<InitInput>} module_or_path
|
||||
*
|
||||
* @returns {Promise<InitOutput>}
|
||||
*/
|
||||
export default function init(module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
||||
84
frontend/src/common/prettier/plugins/dart/extra/dart_fmt.js
Normal file
84
frontend/src/common/prettier/plugins/dart/extra/dart_fmt.js
Normal file
@@ -0,0 +1,84 @@
|
||||
import { format as dart_fmt, instantiate, invoke } from "./dart_fmt.mjs";
|
||||
|
||||
let wasm;
|
||||
|
||||
function get_imports() {}
|
||||
function init_memory() {}
|
||||
|
||||
function normalize(module) {
|
||||
if (!(module instanceof WebAssembly.Module)) {
|
||||
return new WebAssembly.Module(module);
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
export default async function (input) {
|
||||
if (wasm !== undefined) return wasm;
|
||||
|
||||
if (typeof input === "undefined") {
|
||||
input = new URL("dart_fmt.wasm", import.meta.url);
|
||||
}
|
||||
const imports = get_imports();
|
||||
|
||||
if (
|
||||
typeof input === "string" ||
|
||||
(typeof Request === "function" && input instanceof Request) ||
|
||||
(typeof URL === "function" && input instanceof URL)
|
||||
) {
|
||||
input = fetch(input);
|
||||
}
|
||||
|
||||
init_memory(imports);
|
||||
|
||||
wasm = await load(await input)
|
||||
.then(normalize)
|
||||
.then(instantiate);
|
||||
|
||||
invoke(wasm);
|
||||
|
||||
return wasm;
|
||||
}
|
||||
|
||||
async function load(module) {
|
||||
if (typeof Response === "function" && module instanceof Response) {
|
||||
if ("compileStreaming" in WebAssembly) {
|
||||
try {
|
||||
return await WebAssembly.compileStreaming(module);
|
||||
} catch (e) {
|
||||
if (module.headers.get("Content-Type") != "application/wasm") {
|
||||
console.warn(
|
||||
"`WebAssembly.compileStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
|
||||
e,
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return module.arrayBuffer();
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
export function format(source, filename = "stdin.dart", config = {}) {
|
||||
const options = { lineEnding: "\n" };
|
||||
if (config.line_width) {
|
||||
options.pageWidth = config.line_width;
|
||||
}
|
||||
if (options.line_ending === "crlf") {
|
||||
options.lineEnding = "\r\n";
|
||||
}
|
||||
if(options.language_version) {
|
||||
options.languageVersion = options.language_version;
|
||||
}
|
||||
|
||||
const result = dart_fmt(source, filename, JSON.stringify(options));
|
||||
const err = result[0] === "x";
|
||||
const output = result.slice(1);
|
||||
if (err) {
|
||||
throw new Error(output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import fs from "node:fs/promises";
|
||||
import initAsync from "./dart_fmt.js";
|
||||
|
||||
const wasm = new URL("./dart_fmt.wasm", import.meta.url);
|
||||
|
||||
export default function __wbg_init(init = fs.readFile(wasm)) {
|
||||
return initAsync(init);
|
||||
}
|
||||
|
||||
export * from "./dart_fmt.js";
|
||||
@@ -0,0 +1,8 @@
|
||||
import initAsync from "./dart_fmt.js";
|
||||
import wasm from "./dart_fmt.wasm?url";
|
||||
|
||||
export default function __wbg_init(input = wasm) {
|
||||
return initAsync(input);
|
||||
}
|
||||
|
||||
export * from "./dart_fmt.js";
|
||||
31
frontend/src/common/prettier/plugins/dart/lib/binding.dart
Normal file
31
frontend/src/common/prettier/plugins/dart/lib/binding.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:js_interop';
|
||||
import 'package:dart_fmt/dart_fmt.dart';
|
||||
|
||||
class Options {
|
||||
final int? pageWidth;
|
||||
final String? lineEnding;
|
||||
final String? languageVersion;
|
||||
|
||||
Options.fromJson(Map<String, dynamic> json)
|
||||
: pageWidth = json['pageWidth'] as int?,
|
||||
lineEnding = json['lineEnding'] as String?,
|
||||
languageVersion = json['languageVersion'] as String?;
|
||||
}
|
||||
|
||||
String formatWrapper(String source, String filename, String options) {
|
||||
final config = Options.fromJson(jsonDecode(options));
|
||||
|
||||
try {
|
||||
return "o${format(source, filename, pageWidth: config.pageWidth, lineEnding: config.lineEnding, version: config.languageVersion)}";
|
||||
} catch (e) {
|
||||
return "x$e";
|
||||
}
|
||||
}
|
||||
|
||||
@JS('format')
|
||||
external set formatExport(JSFunction handler);
|
||||
|
||||
void main(List<String> arguments) {
|
||||
formatExport = formatWrapper.toJS;
|
||||
}
|
||||
14
frontend/src/common/prettier/plugins/dart/lib/dart_fmt.dart
Normal file
14
frontend/src/common/prettier/plugins/dart/lib/dart_fmt.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:dart_style/dart_style.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
|
||||
String format(String source, String filename,
|
||||
{int? pageWidth, String? lineEnding, String? version}) {
|
||||
final languageVersion = version != null
|
||||
? Version.parse(version)
|
||||
: DartFormatter.latestLanguageVersion;
|
||||
final formatter = DartFormatter(
|
||||
pageWidth: pageWidth,
|
||||
lineEnding: lineEnding,
|
||||
languageVersion: languageVersion);
|
||||
return formatter.format(source, uri: filename);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
cd $(dirname $0)/..
|
||||
|
||||
dart compile wasm ./lib/binding.dart -o ./build/dart_fmt.wasm
|
||||
cp -LR ./extra/. ./build/
|
||||
|
||||
./scripts/patch.mjs ./build/dart_fmt.mjs
|
||||
./scripts/package.mjs ./package.json
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
import process from "node:process";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
const pkg_path = path.resolve(process.cwd(), process.argv[2]);
|
||||
const pkg_text = fs.readFileSync(pkg_path, { encoding: "utf-8" });
|
||||
const pkg_json = JSON.parse(pkg_text);
|
||||
|
||||
// JSR
|
||||
|
||||
const jsr_path = path.resolve(pkg_path, "..", "build", "jsr.jsonc");
|
||||
pkg_json.name = "@fmt/dart-fmt";
|
||||
pkg_json.exports = "./dart_fmt.js";
|
||||
pkg_json.exclude = ["!../build", "*.tgz", ".npmignore"];
|
||||
fs.writeFileSync(jsr_path, JSON.stringify(pkg_json, null, 4));
|
||||
13
frontend/src/common/prettier/plugins/dart/scripts/patch.mjs
Normal file
13
frontend/src/common/prettier/plugins/dart/scripts/patch.mjs
Normal file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
import process from "node:process";
|
||||
import path from "node:path";
|
||||
import fs from "node:fs";
|
||||
|
||||
const file_path = path.resolve(process.cwd(), process.argv[2]);
|
||||
let file_text = fs.readFileSync(file_path, { encoding: "utf-8" });
|
||||
|
||||
file_text = file_text.replace(`"length": (s) => s.length`, '"length": (s) => s?.length||0');
|
||||
file_text = file_text.replace('globalThis.format', 'format');
|
||||
file_text += "\nexport let format;";
|
||||
|
||||
fs.writeFileSync(file_path, file_text);
|
||||
Reference in New Issue
Block a user