@konomanoasa/tree-sitter-npmrc 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/Cargo.toml ADDED
@@ -0,0 +1,37 @@
1
+ [package]
2
+ name = "konomanoasa-tree-sitter-npmrc"
3
+ version = "0.2.0"
4
+ description = "Tree-sitter grammar for npm CLI configuration files."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ repository = "https://github.com/konomanoasa/tree-sitter-npmrc"
8
+ edition = "2024"
9
+ build = "bindings/rust/build.rs"
10
+ links = "tree-sitter-npmrc"
11
+ include = [
12
+ "/LICENSE",
13
+ "/README.md",
14
+ "/bindings/rust/*.rs",
15
+ "/queries/*.scm",
16
+ "/src/*.c",
17
+ "/src/*.h",
18
+ "/src/node-types.json",
19
+ "/src/tree_sitter/*.h",
20
+ "/test/bindings.test.rs",
21
+ ]
22
+
23
+ [lib]
24
+ path = "bindings/rust/lib.rs"
25
+
26
+ [[test]]
27
+ name = "bindings"
28
+ path = "test/bindings.test.rs"
29
+
30
+ [dependencies]
31
+ tree-sitter-language = "=0.1.9"
32
+
33
+ [dev-dependencies]
34
+ tree-sitter = "=0.27.2"
35
+
36
+ [build-dependencies]
37
+ cc = "=1.12.0"
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 konomanoasa
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/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
1
+ # tree-sitter-npmrc
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/konomanoasa/tree-sitter-npmrc/actions/workflows/ci.yaml/badge.svg)](https://github.com/konomanoasa/tree-sitter-npmrc/actions/workflows/ci.yaml)
4
+ [![crates.io](https://img.shields.io/crates/v/konomanoasa-tree-sitter-npmrc)](https://crates.io/crates/konomanoasa-tree-sitter-npmrc)
5
+ [![npm](https://img.shields.io/npm/v/@konomanoasa/tree-sitter-npmrc)](https://www.npmjs.com/package/@konomanoasa/tree-sitter-npmrc)
6
+ [![PyPI](https://img.shields.io/pypi/v/konomanoasa-tree-sitter-npmrc)](https://pypi.org/project/konomanoasa-tree-sitter-npmrc/)
7
+
8
+ [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for
9
+ npm CLI configuration files 12.2.3.
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ npm install @konomanoasa/tree-sitter-npmrc
15
+ ```
16
+
17
+ ## Development
18
+
19
+ ```sh
20
+ npm ci
21
+ npm test
22
+ ```
23
+
24
+ ## Specification
25
+
26
+ [npm CLI 12.2.3 configuration files](https://github.com/npm/cli/blob/v12.2.3/docs/lib/content/configuring-npm/npmrc.md)
27
+
28
+ ## License
29
+
30
+ [MIT](LICENSE)
package/binding.gyp ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "targets": [
3
+ {
4
+ "target_name": "tree_sitter_npmrc_binding",
5
+ "sources": ["bindings/node/binding.cc", "src/parser.c", "src/scanner.c"],
6
+ "include_dirs": ["src"],
7
+ "dependencies": [
8
+ "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except"
9
+ ],
10
+ "cflags_c": ["-std=c17"],
11
+ "cflags_cc": ["-std=c++17"],
12
+ "msvs_settings": {
13
+ "VCCLCompilerTool": {
14
+ "AdditionalOptions": ["/utf-8"],
15
+ "AdditionalOptions!": ["-std:c++20"],
16
+ "LanguageStandard": "stdcpp17",
17
+ "LanguageStandard_C": "stdc17"
18
+ }
19
+ },
20
+ "target_conditions": [
21
+ [
22
+ "OS==\"mac\"",
23
+ {
24
+ "xcode_settings": {
25
+ "CLANG_CXX_LANGUAGE_STANDARD": "c++17",
26
+ "GCC_C_LANGUAGE_STANDARD": "c17",
27
+ "MACOSX_DEPLOYMENT_TARGET": "14.0"
28
+ }
29
+ }
30
+ ]
31
+ ]
32
+ }
33
+ ]
34
+ }
@@ -0,0 +1,25 @@
1
+ #include <napi.h>
2
+
3
+ struct TSLanguage;
4
+ extern "C" const TSLanguage *tree_sitter_npmrc();
5
+
6
+ namespace {
7
+
8
+ constexpr napi_type_tag language_type_tag = {
9
+ 0x8AF2E5212AD58ABF,
10
+ 0xD5006CAD83ABBA16
11
+ };
12
+
13
+ Napi::Object Init(Napi::Env env, Napi::Object exports) {
14
+ auto language = Napi::External<TSLanguage>::New(
15
+ env,
16
+ const_cast<TSLanguage *>(tree_sitter_npmrc())
17
+ );
18
+ language.TypeTag(&language_type_tag);
19
+ exports["language"] = language;
20
+ return exports;
21
+ }
22
+
23
+ }
24
+
25
+ NODE_API_MODULE(tree_sitter_npmrc_binding, Init)
@@ -0,0 +1,5 @@
1
+ import type { Language } from "tree-sitter";
2
+
3
+ declare const binding: Language & { HIGHLIGHTS_QUERY: string };
4
+
5
+ export default binding;
@@ -0,0 +1,15 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import load from "node-gyp-build";
4
+
5
+ const binding = load(fileURLToPath(new URL("../..", import.meta.url)));
6
+ binding.nodeTypeInfo = JSON.parse(
7
+ readFileSync(new URL("../../src/node-types.json", import.meta.url), "utf8"),
8
+ );
9
+
10
+ binding.HIGHLIGHTS_QUERY = readFileSync(
11
+ new URL("../../queries/highlights.scm", import.meta.url),
12
+ "utf8",
13
+ );
14
+
15
+ export default binding;
@@ -0,0 +1,9 @@
1
+ from importlib.resources import files
2
+
3
+ from .binding import language
4
+
5
+ HIGHLIGHTS_QUERY: str = (
6
+ files(__package__).joinpath("queries/highlights.scm").read_text("utf-8")
7
+ )
8
+
9
+ __all__ = ["HIGHLIGHTS_QUERY", "language"]
@@ -0,0 +1,31 @@
1
+ #include <Python.h>
2
+
3
+ #include "../../src/tree_sitter/parser.h"
4
+
5
+ const TSLanguage *tree_sitter_npmrc(void);
6
+
7
+ static PyObject *language(PyObject *self, PyObject *args) {
8
+ (void)self;
9
+ (void)args;
10
+ return PyCapsule_New(
11
+ (void *)tree_sitter_npmrc(),
12
+ "tree_sitter.Language",
13
+ NULL
14
+ );
15
+ }
16
+
17
+ static PyMethodDef methods[] = {
18
+ {"language", language, METH_NOARGS, "Return the npmrc language capsule."},
19
+ {NULL, NULL, 0, NULL},
20
+ };
21
+
22
+ static struct PyModuleDef module = {
23
+ PyModuleDef_HEAD_INIT,
24
+ .m_name = "binding",
25
+ .m_size = -1,
26
+ .m_methods = methods,
27
+ };
28
+
29
+ PyMODINIT_FUNC PyInit_binding(void) {
30
+ return PyModule_Create(&module);
31
+ }
@@ -0,0 +1,3 @@
1
+ from types import CapsuleType
2
+
3
+ def language() -> CapsuleType: ...
File without changes
@@ -0,0 +1,23 @@
1
+ use std::{env, path::Path};
2
+
3
+ fn main() {
4
+ let mut build = cc::Build::new();
5
+ build.std("c17");
6
+ if build.get_compiler().is_like_msvc() {
7
+ build.flag("-utf-8");
8
+ }
9
+ if env::var("TARGET").expect("Cargo must provide TARGET")
10
+ == "wasm32-unknown-unknown"
11
+ {
12
+ let headers = env::var_os("DEP_TREE_SITTER_LANGUAGE_WASM_HEADERS")
13
+ .expect("tree-sitter-language must provide WebAssembly headers");
14
+ build.include(&headers);
15
+ println!("cargo::rerun-if-changed={}", Path::new(&headers).display());
16
+ }
17
+
18
+ println!("cargo::rerun-if-changed=src");
19
+ build
20
+ .include("src")
21
+ .files(["src/parser.c", "src/scanner.c"])
22
+ .compile("tree-sitter-npmrc");
23
+ }
@@ -0,0 +1,10 @@
1
+ use tree_sitter_language::LanguageFn;
2
+
3
+ unsafe extern "C" {
4
+ fn tree_sitter_npmrc() -> *const ();
5
+ }
6
+
7
+ pub const LANGUAGE: LanguageFn =
8
+ unsafe { LanguageFn::from_raw(tree_sitter_npmrc) };
9
+ pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
10
+ pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
package/grammar.js ADDED
@@ -0,0 +1,152 @@
1
+ const missing = [
2
+ "key_name",
3
+ "assignment_operator",
4
+ "variable_name",
5
+ "variable_close",
6
+ "quote",
7
+ ];
8
+
9
+ const problems = [
10
+ ["invalid_encoding", "invalid_syntax", "invalid_encoding"],
11
+ ["unexpected_tail", "invalid_syntax", "unexpected_value_text"],
12
+ ["absent_key", "invalid_syntax", "missing_key_name"],
13
+ ["invalid_array_name", "invalid_syntax", "missing_key_name"],
14
+ ["incomplete_array_name", "incomplete_syntax", "missing_key_name"],
15
+ ...missing.flatMap((name) => [
16
+ [`invalid_${name}`, "invalid_syntax", `missing_${name}`],
17
+ [`incomplete_${name}`, "incomplete_syntax", `missing_${name}`],
18
+ ]),
19
+ ];
20
+
21
+ function issue($, token) {
22
+ return field("issue", alias($[`_${token}_issue`], $.syntax_issue));
23
+ }
24
+
25
+ function missingAtBoundary($, name) {
26
+ return choice(issue($, `invalid_${name}`), issue($, `incomplete_${name}`));
27
+ }
28
+
29
+ export default grammar({
30
+ name: "npmrc",
31
+ extras: ($) => [$._padding],
32
+ externals: ($) => [
33
+ $.key_text,
34
+ $.package_scope,
35
+ $.registry_scope,
36
+ $.array_marker,
37
+ $._first_text,
38
+ $._bare_text,
39
+ $._quoted_text,
40
+ $.escape,
41
+ $.variable_name,
42
+ $._fallback,
43
+ $.comment_text,
44
+ $._padding,
45
+ ...problems.map(([token]) => $[`_${token}`]),
46
+ $._error_sentinel,
47
+ ],
48
+ rules: {
49
+ document: ($) =>
50
+ seq(repeat(seq(optional($._entry), $._newline)), optional($._entry)),
51
+ _newline: () => token(choice("\r\n", "\n", "\r")),
52
+ _entry: ($) => choice($.comment, $.pair),
53
+ comment: ($) =>
54
+ seq(
55
+ $.comment_marker,
56
+ repeat(choice($.comment_text, issue($, "invalid_encoding"))),
57
+ ),
58
+ comment_marker: () => /[#;]/,
59
+
60
+ pair: ($) =>
61
+ seq(
62
+ choice(field("key", $.key), issue($, "absent_key")),
63
+ choice(
64
+ seq(
65
+ "=",
66
+ optional(field("value", choice($.bare_value, $.quoted_value))),
67
+ ),
68
+ missingAtBoundary($, "assignment_operator"),
69
+ ),
70
+ ),
71
+ key: ($) =>
72
+ choice(
73
+ $._key_body,
74
+ seq(
75
+ field("scope", choice($.package_scope, $.registry_scope)),
76
+ ":",
77
+ choice(
78
+ $._key_body,
79
+ issue($, "absent_key"),
80
+ missingAtBoundary($, "key_name"),
81
+ ),
82
+ ),
83
+ ),
84
+ _key_body: ($) =>
85
+ choice(
86
+ seq(
87
+ repeat1(choice($.key_text, issue($, "invalid_encoding"))),
88
+ optional($.array_marker),
89
+ ),
90
+ seq(missingAtBoundary($, "array_name"), $.array_marker),
91
+ ),
92
+
93
+ bare_value: ($) =>
94
+ seq(
95
+ choice(
96
+ alias($._first_text, $.value_text),
97
+ $.variable_reference,
98
+ issue($, "invalid_encoding"),
99
+ ),
100
+ repeat(
101
+ choice(
102
+ alias($._bare_text, $.value_text),
103
+ $.variable_reference,
104
+ issue($, "invalid_encoding"),
105
+ ),
106
+ ),
107
+ ),
108
+ quoted_value: ($) =>
109
+ seq(
110
+ '"',
111
+ repeat(
112
+ choice(
113
+ alias($._quoted_text, $.value_text),
114
+ $.escape,
115
+ $.variable_reference,
116
+ issue($, "invalid_encoding"),
117
+ ),
118
+ ),
119
+ choice(
120
+ seq(
121
+ '"',
122
+ repeat(
123
+ choice(issue($, "unexpected_tail"), issue($, "invalid_encoding")),
124
+ ),
125
+ ),
126
+ missingAtBoundary($, "quote"),
127
+ ),
128
+ ),
129
+ variable_reference: ($) =>
130
+ seq(
131
+ "${",
132
+ choice(
133
+ repeat1(
134
+ choice(
135
+ field("name", $.variable_name),
136
+ issue($, "invalid_encoding"),
137
+ ),
138
+ ),
139
+ missingAtBoundary($, "variable_name"),
140
+ ),
141
+ optional(alias($._fallback, "?")),
142
+ choice("}", missingAtBoundary($, "variable_close")),
143
+ ),
144
+
145
+ ...Object.fromEntries(
146
+ problems.flatMap(([token, outcome, reason]) => [
147
+ [`_${token}_outcome`, ($) => alias($[`_${token}`], $[reason])],
148
+ [`_${token}_issue`, ($) => alias($[`_${token}_outcome`], $[outcome])],
149
+ ]),
150
+ ),
151
+ },
152
+ });
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@konomanoasa/tree-sitter-npmrc",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Tree-sitter grammar for npm CLI configuration files.",
5
+ "license": "MIT",
6
+ "repository": "git+https://github.com/konomanoasa/tree-sitter-npmrc.git",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./bindings/node/index.d.ts",
11
+ "default": "./bindings/node/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "Cargo.toml",
16
+ "binding.gyp",
17
+ "bindings/node/*.cc",
18
+ "bindings/node/*.js",
19
+ "bindings/node/*.ts",
20
+ "bindings/python/*.c",
21
+ "bindings/python/*.py",
22
+ "bindings/python/*.pyi",
23
+ "bindings/python/py.typed",
24
+ "bindings/rust/*.rs",
25
+ "grammar.js",
26
+ "pyproject.toml",
27
+ "queries/*.scm",
28
+ "scripts/tree-sitter.js",
29
+ "setup.py",
30
+ "src/*.c",
31
+ "src/*.h",
32
+ "src/*.json",
33
+ "src/tree_sitter/*.h",
34
+ "test/bindings.test.rs",
35
+ "tree-sitter.json"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "scripts": {
41
+ "build": "node-gyp rebuild && node-gyp configure -- -f compile_commands_json",
42
+ "build:parser": "npm run tree-sitter -- build-all",
43
+ "check": "biome check . && tsc",
44
+ "check:queries": "npm run tree-sitter -- check-queries",
45
+ "format": "biome format --write .",
46
+ "generate": "npm run tree-sitter -- generate-all",
47
+ "install": "node-gyp-build",
48
+ "test": "npm run tree-sitter -- test-corpus --rebuild && node --test --test-concurrency=1 test/bindings.test.js test/build.test.js test/cst.test.js test/highlight.test.js test/incremental.test.js && node scripts/check-c.js --test",
49
+ "test:fuzz": "npm run tree-sitter -- fuzz-all --iterations 100 --edits 5",
50
+ "test:sanitize": "node scripts/check-c.js --sanitize",
51
+ "tree-sitter": "node scripts/tree-sitter.js"
52
+ },
53
+ "dependencies": {
54
+ "node-addon-api": "8.9.2",
55
+ "node-gyp-build": "4.8.4"
56
+ },
57
+ "peerDependencies": {
58
+ "tree-sitter": "0.25.1"
59
+ },
60
+ "devDependencies": {
61
+ "@biomejs/biome": "2.6.9",
62
+ "@types/node": "26.6.11",
63
+ "node-gyp": "13.1.0",
64
+ "tree-sitter-cli": "0.27.2",
65
+ "typescript": "7.0.2"
66
+ },
67
+ "allowScripts": {
68
+ "tree-sitter": true,
69
+ "tree-sitter-cli": true
70
+ }
71
+ }
package/pyproject.toml ADDED
@@ -0,0 +1,74 @@
1
+ [project]
2
+ name = "konomanoasa-tree-sitter-npmrc"
3
+ version = "0.2.0"
4
+ description = "Tree-sitter grammar for npm CLI configuration files."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.13"
9
+
10
+ [project.urls]
11
+ Repository = "https://github.com/konomanoasa/tree-sitter-npmrc"
12
+
13
+ [dependency-groups]
14
+ dev = [
15
+ "poethepoet==0.49.0",
16
+ "ruff==0.17.6",
17
+ "setuptools==84.2.1",
18
+ "tree-sitter==0.27.0",
19
+ "twine==7.0.0",
20
+ "ty==0.0.112",
21
+ ]
22
+
23
+ [build-system]
24
+ requires = ["setuptools==84.2.1"]
25
+ build-backend = "setuptools.build_meta"
26
+
27
+ [tool.setuptools]
28
+ include-package-data = false
29
+ packages = ["tree_sitter_npmrc", "tree_sitter_npmrc.queries"]
30
+
31
+ [tool.setuptools.package-dir]
32
+ tree_sitter_npmrc = "bindings/python"
33
+ "tree_sitter_npmrc.queries" = "queries"
34
+
35
+ [tool.setuptools.package-data]
36
+ tree_sitter_npmrc = ["*.pyi", "py.typed"]
37
+ "tree_sitter_npmrc.queries" = ["*.scm"]
38
+
39
+ [tool.poe]
40
+ executor.type = "simple"
41
+
42
+ [tool.poe.tasks]
43
+ build = "uv build --no-sources"
44
+ check = [
45
+ { cmd = "ruff check setup.py bindings/python test/bindings.test.py" },
46
+ { cmd = "ty check setup.py bindings/python test/bindings.test.py" },
47
+ { cmd = "ruff format --check setup.py bindings/python test/bindings.test.py" },
48
+ ]
49
+ format = "ruff format setup.py bindings/python test/bindings.test.py"
50
+ test = "python test/bindings.test.py"
51
+
52
+ [tool.ruff]
53
+ indent-width = 4
54
+ line-length = 80
55
+
56
+ [tool.ruff.format]
57
+ indent-style = "space"
58
+ skip-magic-trailing-comma = true
59
+
60
+ [tool.ruff.lint.isort]
61
+ split-on-trailing-comma = false
62
+
63
+ [tool.uv]
64
+ cache-keys = [
65
+ { file = "LICENSE" },
66
+ { file = "README.md" },
67
+ { file = "bindings/python/*" },
68
+ { file = "pyproject.toml" },
69
+ { file = "queries/*.scm" },
70
+ { file = "setup.py" },
71
+ { file = "src/*.c" },
72
+ { file = "src/*.h" },
73
+ { file = "src/tree_sitter/*.h" },
74
+ ]
@@ -0,0 +1,33 @@
1
+ [
2
+ (comment_marker)
3
+ (comment_text)
4
+ ] @comment
5
+
6
+ (key_text) @property
7
+
8
+ (package_scope) @module
9
+
10
+ (registry_scope) @string.special.url
11
+
12
+ (array_marker) @punctuation.bracket
13
+
14
+ (value_text) @string
15
+
16
+ (escape) @string.escape
17
+
18
+ (variable_name) @variable
19
+
20
+ [
21
+ ":"
22
+ "\""
23
+ ] @punctuation.delimiter
24
+
25
+ [
26
+ "="
27
+ "?"
28
+ ] @operator
29
+
30
+ [
31
+ "${"
32
+ "}"
33
+ ] @punctuation.special