tombi-lib 0.0.0-dev → 1.6.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/binding.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /** The content of a `tombi.toml` config file at a given path. */
5
+ export interface ConfigFile {
6
+ content: string
7
+ path: string
8
+ }
9
+
10
+ /** A diagnostic reported by Tombi. */
11
+ export interface Diagnostic {
12
+ level: "error" | "warning"
13
+ code: string
14
+ message: string
15
+ range: Range
16
+ sourceFile: string | null
17
+ }
18
+
19
+ /** Format a TOML document. */
20
+ export declare function format(source: string, sourcePath: string, options?: Options | undefined | null): Promise<FormatResult>
21
+
22
+ /** The result of formatting a TOML document. */
23
+ export interface FormatResult {
24
+ /** The formatted source, or `undefined` if formatting failed. */
25
+ formatted?: string
26
+ diagnostics: Array<Diagnostic>
27
+ }
28
+
29
+ /** Format a TOML document synchronously, blocking the calling thread. */
30
+ export declare function formatSync(source: string, sourcePath: string, options?: Options | undefined | null): FormatResult
31
+
32
+ /** Lint a TOML document. */
33
+ export declare function lint(source: string, sourcePath: string, options?: Options | undefined | null): Promise<LintResult>
34
+
35
+ /** The result of linting a TOML document. */
36
+ export interface LintResult {
37
+ diagnostics: Array<Diagnostic>
38
+ }
39
+
40
+ /** Lint a TOML document synchronously, blocking the calling thread. */
41
+ export declare function lintSync(source: string, sourcePath: string, options?: Options | undefined | null): LintResult
42
+
43
+ /** Options shared by the formatter and linter. */
44
+ export interface Options {
45
+ /**
46
+ * An in-memory `tombi.toml` configuration.
47
+ * When a string is provided, it is treated as the content of a virtual
48
+ * `tombi.toml`. When omitted, `tombi.toml` is searched from the current
49
+ * working directory.
50
+ */
51
+ config?: string | ConfigFile
52
+ }
53
+
54
+ /** A zero-based position in a TOML document. */
55
+ export interface Position {
56
+ line: number
57
+ column: number
58
+ }
59
+
60
+ /** A range in a TOML document. */
61
+ export interface Range {
62
+ start: Position
63
+ end: Position
64
+ }
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from "./binding";
2
+
3
+ /**
4
+ * The error `format`/`lint` reject with (and `formatSync`/`lintSync` throw) when
5
+ * the configuration, a schema, or an I/O operation fails. Malformed `options`
6
+ * reject (or throw) with a `TypeError` instead.
7
+ */
8
+ export interface TombiError extends Error {
9
+ readonly name: "TombiError";
10
+ }
package/index.js CHANGED
@@ -1,3 +1,73 @@
1
- function hello() {
2
- console.log("Hello, world!");
1
+ const { existsSync } = require("node:fs");
2
+ const { join } = require("node:path");
3
+ const { platform, arch, env } = process;
4
+ // Published as both `@tombi-toml/lib` and `tombi-lib` (the release
5
+ // workflow only rewrites `name`), so read it rather than hard-coding one.
6
+ const { name: packageName } = require("./package.json");
7
+
8
+ function isMusl() {
9
+ // `glibcVersionRuntime` is only reported by glibc-based Node.js builds.
10
+ const report = process.report?.getReport();
11
+ const header = typeof report === "string" ? JSON.parse(report).header : report?.header;
12
+ return !header?.glibcVersionRuntime;
3
13
  }
14
+
15
+ const PLATFORMS = {
16
+ win32: {
17
+ x64: "@tombi-toml/lib-win32-x64",
18
+ arm64: "@tombi-toml/lib-win32-arm64",
19
+ },
20
+ darwin: {
21
+ x64: "@tombi-toml/lib-darwin-x64",
22
+ arm64: "@tombi-toml/lib-darwin-arm64",
23
+ },
24
+ linux: {
25
+ x64: "@tombi-toml/lib-linux-x64",
26
+ arm64: "@tombi-toml/lib-linux-arm64",
27
+ },
28
+ "linux-musl": {
29
+ x64: "@tombi-toml/lib-linux-x64-musl",
30
+ arm64: "@tombi-toml/lib-linux-arm64-musl",
31
+ },
32
+ };
33
+
34
+ function loadBinding() {
35
+ if (env.TOMBI_LIB_BINARY) {
36
+ return require(env.TOMBI_LIB_BINARY);
37
+ }
38
+
39
+ // A local `pnpm build` output, for development within this repository.
40
+ const localBinary = join(__dirname, "tombi-lib.node");
41
+ if (existsSync(localBinary)) {
42
+ return require(localBinary);
43
+ }
44
+
45
+ const bindingPackageName =
46
+ platform === "linux" && isMusl()
47
+ ? PLATFORMS["linux-musl"][arch]
48
+ : PLATFORMS[platform]?.[arch];
49
+
50
+ if (!bindingPackageName) {
51
+ throw new Error(
52
+ `${packageName} doesn't ship with a prebuilt binary for ${platform}-${arch} yet.`,
53
+ );
54
+ }
55
+
56
+ try {
57
+ return require(`${bindingPackageName}/tombi-lib.node`);
58
+ } catch (error) {
59
+ throw new Error(
60
+ `The Tombi native binding "${bindingPackageName}" could not be loaded. ` +
61
+ "The platform-specific optional package may not be installed. " +
62
+ `Please reinstall ${packageName} with optional dependencies enabled.`,
63
+ { cause: error },
64
+ );
65
+ }
66
+ }
67
+
68
+ const binding = loadBinding();
69
+
70
+ module.exports.format = binding.format;
71
+ module.exports.lint = binding.lint;
72
+ module.exports.formatSync = binding.formatSync;
73
+ module.exports.lintSync = binding.lintSync;
package/package.json CHANGED
@@ -1,13 +1,57 @@
1
1
  {
2
2
  "name": "tombi-lib",
3
- "version": "0.0.0-dev",
4
- "description": "",
3
+ "version": "1.6.0",
4
+ "description": "Tombi formatter and linter library for Node.js",
5
+ "keywords": [
6
+ "toml",
7
+ "formatter",
8
+ "linter"
9
+ ],
10
+ "author": "tombi-toml",
11
+ "license": "MIT",
12
+ "private": false,
13
+ "homepage": "https://tombi-toml.github.io/tombi/",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/tombi-toml/tombi.git",
17
+ "directory": "typescript/@tombi-toml/lib"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/tombi-toml/tombi/issues"
21
+ },
22
+ "engines": {
23
+ "node": ">=20.0.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "provenance": true
28
+ },
5
29
  "main": "index.js",
6
- "keywords": [],
7
- "author": "",
8
- "license": "ISC",
9
- "type": "module",
30
+ "types": "index.d.ts",
31
+ "files": [
32
+ "index.js",
33
+ "index.d.ts",
34
+ "binding.d.ts",
35
+ "LICENSE"
36
+ ],
37
+ "napi": {
38
+ "binaryName": "tombi-lib"
39
+ },
10
40
  "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1"
41
+ "build": "napi build --manifest-path ../../../rust/tombi-lib-node/Cargo.toml --release --output-dir . --dts binding.d.ts",
42
+ "test": "node --test tests/*.test.mjs"
43
+ },
44
+ "devDependencies": {
45
+ "@napi-rs/cli": "3.10.5"
46
+ },
47
+ "optionalDependencies": {
48
+ "@tombi-toml/lib-win32-x64": "1.6.0",
49
+ "@tombi-toml/lib-win32-arm64": "1.6.0",
50
+ "@tombi-toml/lib-darwin-x64": "1.6.0",
51
+ "@tombi-toml/lib-darwin-arm64": "1.6.0",
52
+ "@tombi-toml/lib-linux-x64": "1.6.0",
53
+ "@tombi-toml/lib-linux-arm64": "1.6.0",
54
+ "@tombi-toml/lib-linux-x64-musl": "1.6.0",
55
+ "@tombi-toml/lib-linux-arm64-musl": "1.6.0"
12
56
  }
13
- }
57
+ }