@tombi-toml/lib 0.0.0-dev → 1.5.10
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/binding.d.ts +64 -0
- package/index.d.ts +10 -0
- package/index.js +73 -0
- package/package.json +49 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 tombi-toml
|
|
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/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
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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;
|
|
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,12 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tombi-toml/lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.5.10",
|
|
4
|
+
"description": "Tombi formatter and linter library for Node.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"toml",
|
|
7
|
+
"formatter",
|
|
8
|
+
"linter"
|
|
9
|
+
],
|
|
10
|
+
"author": "tombi-toml",
|
|
4
11
|
"license": "MIT",
|
|
12
|
+
"private": false,
|
|
13
|
+
"homepage": "https://tombi-toml.github.io/tombi/",
|
|
5
14
|
"repository": {
|
|
6
15
|
"type": "git",
|
|
7
16
|
"url": "git+https://github.com/tombi-toml/tombi.git",
|
|
8
17
|
"directory": "typescript/@tombi-toml/lib"
|
|
9
18
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
}
|
|
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
|
+
},
|
|
29
|
+
"main": "index.js",
|
|
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
|
+
},
|
|
40
|
+
"scripts": {
|
|
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.5.10",
|
|
49
|
+
"@tombi-toml/lib-win32-arm64": "1.5.10",
|
|
50
|
+
"@tombi-toml/lib-darwin-x64": "1.5.10",
|
|
51
|
+
"@tombi-toml/lib-darwin-arm64": "1.5.10",
|
|
52
|
+
"@tombi-toml/lib-linux-x64": "1.5.10",
|
|
53
|
+
"@tombi-toml/lib-linux-arm64": "1.5.10",
|
|
54
|
+
"@tombi-toml/lib-linux-x64-musl": "1.5.10",
|
|
55
|
+
"@tombi-toml/lib-linux-arm64-musl": "1.5.10"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/README.md
DELETED