Skip to content

Commit 208acf5

Browse files
committed
build: eliminate "lua-cjson" dependency
1 parent 4e493c8 commit 208acf5

File tree

5 files changed

+84
-87
lines changed

5 files changed

+84
-87
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ deps:
2828
$(LUAROCKS) install inspect
2929
$(LUAROCKS) install net-url
3030
$(LUAROCKS) install jsonschema
31-
$(LUAROCKS) install lua-cjson
3231

3332
.PHONY: test
3433
test: deps json

lua/utils/format_cjson.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
-- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

29-
local ok, cjson = pcall(require, "cjson.safe")
30-
local enc = ok and cjson.encode or function() return nil, "Lua cJSON encoder not found" end
29+
local enc = vim.json.encode
3130
local cat = table.concat
3231
local sub = string.sub
3332
local rep = string.rep

schema/packspec_schema.json

+78-78
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,117 @@
11
{
2-
"type": "object",
3-
"title": "packspec",
4-
"required": [
5-
"package",
6-
"source"
7-
],
2+
"additionalProperties": false,
83
"properties": {
9-
"packspec": {
10-
"type": "string",
11-
"description": "The current specification version. (0.1.0) at this time.",
12-
"pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$"
13-
},
14-
"dependencies": {
15-
"patternProperties": {
16-
".*": {
17-
"type": "object",
18-
"additionalProperties": false,
19-
"properties": {
20-
"releases_only": {
21-
"description": "Whether the package manager should only resolve version\nconstraints to include tagged releases.",
22-
"type": "boolean"
23-
},
24-
"version": {
25-
"type": "string",
26-
"description": "Version constraints on the package.\n * Accepted operators are the relational operators of Lua:\n == \\~= < > <= >= , as well as a special operator, \\~>,\n inspired by the \"pessimistic operator\" of RubyGems\n (\"\\~> 2\" means \">= 2, < 3\"; \"~> 2.4\" means \">= 2.4, < 2.5\").\n No operator means an implicit == (i.e., \"lfs 1.0\" is the\n same as \"lfs == 1.0\"). \"lua\" is an special dependency name;\n it matches not a rock, but the version of Lua in use.\n Multiple version constraints can be joined with a `comma`,\n e.g. `\"neovim >= 5.0, < 7.0\"`.\n * If no version is specified, then HEAD is assumed valid.\n * If no upper bound is specified, then any commit after the\n tag corresponding to the lower bound is assumed valid. The\n commit chosen is up to the plugin manager's discretion, but\n implementers are strongly encouraged to always use the\n latest valid commit.\n * If an upper bound is specified, then the the tag\n corresponding to that upper bound is the latest commit that\n is valid",
27-
"pattern": "^((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*(\\s*,\\s*((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*)*$"
28-
},
29-
"source": {
30-
"type": "string",
31-
"description": "Source of the dependency. See previous `source` description.",
32-
"pattern": "^\\w+:\/\/"
33-
}
34-
}
35-
}
36-
}
37-
},
38-
"version": {
39-
"type": "string",
40-
"description": "The version of the package. Should obey semantic versioning\nconventions, for example `0.1.0`. Plugins should have a git commit\nwith a `tag` matching this version. For all version identifiers,\nimplementation should check for a `version` prefixed with `v` in the\ngit repository, as this is a common convention.",
41-
"pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$"
42-
},
434
"external_dependencies": {
44-
"description": "Like dependencies, this specifies packages which are required for the\npackage but should *not* be managed by the Neovim package manager, such\nas `gcc` or `cmake`. Package managers are encouraged to provide a\nnotification to the user if the dependency is not available.",
455
"patternProperties": {
466
".*": {
47-
"type": "object",
487
"additionalProperties": false,
498
"properties": {
509
"version": {
51-
"type": "string",
5210
"description": "Same as `dependencies`",
53-
"pattern": "^((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*(\\s*,\\s*((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*)*$"
11+
"pattern": "^((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*(\\s*,\\s*((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*)*$",
12+
"type": "string"
5413
}
55-
}
14+
},
15+
"type": "object"
5616
}
57-
}
17+
},
18+
"description": "Like dependencies, this specifies packages which are required for the\npackage but should *not* be managed by the Neovim package manager, such\nas `gcc` or `cmake`. Package managers are encouraged to provide a\nnotification to the user if the dependency is not available."
5819
},
59-
"package": {
60-
"description": "The name of the package",
20+
"packspec": {
21+
"description": "The current specification version. (0.1.0) at this time.",
22+
"pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$",
6123
"type": "string"
6224
},
25+
"package": {
26+
"type": "string",
27+
"description": "The name of the package"
28+
},
6329
"description": {
30+
"additionalProperties": false,
31+
"description": "Description of the package",
6432
"properties": {
6533
"summary": {
66-
"description": "Short description of the package, typically less than 100 character\nlong.",
67-
"type": "string"
34+
"type": "string",
35+
"description": "Short description of the package, typically less than 100 character\nlong."
6836
},
6937
"homepage": {
70-
"description": "Homepage of the package. In most cases this will be the GitHub URL.",
71-
"type": "string"
38+
"type": "string",
39+
"description": "Homepage of the package. In most cases this will be the GitHub URL."
40+
},
41+
"detailed": {
42+
"type": "string",
43+
"description": "Long-form description of the package, this should convey the\npackage's principal functionality to the user without being as\ndetailed as the package readme."
44+
},
45+
"license": {
46+
"type": "string",
47+
"description": "This is [SPDX](https:\/\/spdx.org\/licenses\/) license identifier. Dual\nlicensing is indicated via joining the relevant licenses via `\/`."
7248
},
7349
"author": {
50+
"additionalProperties": false,
51+
"description": "Author of the package",
7452
"properties": {
53+
"email": {
54+
"type": "string",
55+
"description": "Author email"
56+
},
7557
"name": {
76-
"description": "Author name",
58+
"type": "string",
59+
"description": "Author name"
60+
}
61+
},
62+
"type": "object"
63+
}
64+
},
65+
"type": "object"
66+
},
67+
"version": {
68+
"description": "The version of the package. Should obey semantic versioning\nconventions, for example `0.1.0`. Plugins should have a git commit\nwith a `tag` matching this version. For all version identifiers,\nimplementation should check for a `version` prefixed with `v` in the\ngit repository, as this is a common convention.",
69+
"pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$",
70+
"type": "string"
71+
},
72+
"$schema": {
73+
"type": "string",
74+
"description": "The optional json schema URI for validation with json-language-server."
75+
},
76+
"dependencies": {
77+
"patternProperties": {
78+
".*": {
79+
"additionalProperties": false,
80+
"properties": {
81+
"version": {
82+
"description": "Version constraints on the package.\n * Accepted operators are the relational operators of Lua:\n == \\~= < > <= >= , as well as a special operator, \\~>,\n inspired by the \"pessimistic operator\" of RubyGems\n (\"\\~> 2\" means \">= 2, < 3\"; \"~> 2.4\" means \">= 2.4, < 2.5\").\n No operator means an implicit == (i.e., \"lfs 1.0\" is the\n same as \"lfs == 1.0\"). \"lua\" is an special dependency name;\n it matches not a rock, but the version of Lua in use.\n Multiple version constraints can be joined with a `comma`,\n e.g. `\"neovim >= 5.0, < 7.0\"`.\n * If no version is specified, then HEAD is assumed valid.\n * If no upper bound is specified, then any commit after the\n tag corresponding to the lower bound is assumed valid. The\n commit chosen is up to the plugin manager's discretion, but\n implementers are strongly encouraged to always use the\n latest valid commit.\n * If an upper bound is specified, then the the tag\n corresponding to that upper bound is the latest commit that\n is valid",
83+
"pattern": "^((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*(\\s*,\\s*((==|~=|<|>|<=|>=|~>)\\s*)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*)*$",
7784
"type": "string"
7885
},
79-
"email": {
80-
"description": "Author email",
86+
"releases_only": {
87+
"type": "boolean",
88+
"description": "Whether the package manager should only resolve version\nconstraints to include tagged releases."
89+
},
90+
"source": {
91+
"description": "Source of the dependency. See previous `source` description.",
92+
"pattern": "^\\w+:\/\/",
8193
"type": "string"
8294
}
8395
},
84-
"type": "object",
85-
"description": "Author of the package",
86-
"additionalProperties": false
87-
},
88-
"license": {
89-
"description": "This is [SPDX](https:\/\/spdx.org\/licenses\/) license identifier. Dual\nlicensing is indicated via joining the relevant licenses via `\/`.",
90-
"type": "string"
91-
},
92-
"detailed": {
93-
"description": "Long-form description of the package, this should convey the\npackage's principal functionality to the user without being as\ndetailed as the package readme.",
94-
"type": "string"
96+
"type": "object"
9597
}
96-
},
97-
"type": "object",
98-
"description": "Description of the package",
99-
"additionalProperties": false
98+
}
10099
},
101100
"source": {
102101
"pattern": "^\\w+:\/\/",
103-
"type": "string",
104-
"description": "The URL of the package source archive. Examples:\n\"http:\/\/github.com\/downloads\/keplerproject\/wsapi\/wsapi-1.3.4.tar.gz\",\n\"git:\/\/github.com\/keplerproject\/wsapi.git\". Different protocols are\nsupported:\n\n * `luarocks:\/\/` - for luarocks packages\n * `file:\/\/` - for URLs in the local filesystem (note that for Unix\n paths, the root slash is the third slash, resulting in paths like\n \"file:\/\/\/full\/path\/filename\"\n * `git:\/\/` - for the Git source control manager\n * `git+https:\/\/` - for the Git source control manager when using\n repositories that need https:\/\/ URLs.\n * `git+ssh:\/\/` - for the Git source control manager when using\n repositories that need SSH login, such as [email protected]\/myrepo.\n * `http:\/\/` - for HTTP URLs\n * `https:\/\/` - for HTTPS URLs",
105102
"examples": [
106103
"luarocks:\/\/argparse",
107104
"git:\/\/github.com\/nvim-lua\/plenary.nvim"
108-
]
109-
},
110-
"$schema": {
111-
"description": "The optional json schema URI for validation with json-language-server.",
105+
],
106+
"description": "The URL of the package source archive. Examples:\n\"http:\/\/github.com\/downloads\/keplerproject\/wsapi\/wsapi-1.3.4.tar.gz\",\n\"git:\/\/github.com\/keplerproject\/wsapi.git\". Different protocols are\nsupported:\n\n * `luarocks:\/\/` - for luarocks packages\n * `file:\/\/` - for URLs in the local filesystem (note that for Unix\n paths, the root slash is the third slash, resulting in paths like\n \"file:\/\/\/full\/path\/filename\"\n * `git:\/\/` - for the Git source control manager\n * `git+https:\/\/` - for the Git source control manager when using\n repositories that need https:\/\/ URLs.\n * `git+ssh:\/\/` - for the Git source control manager when using\n repositories that need SSH login, such as [email protected]\/myrepo.\n * `http:\/\/` - for HTTP URLs\n * `https:\/\/` - for HTTPS URLs",
112107
"type": "string"
113108
}
114109
},
115-
"additionalProperties": false,
116-
"description": "A package specification for Neovim"
110+
"title": "packspec",
111+
"description": "A package specification for Neovim",
112+
"required": [
113+
"package",
114+
"source"
115+
],
116+
"type": "object"
117117
}

scripts/generate_json_schema.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-- local cjson = require('cjson')
21
local schema = require('packspec.schema')
2+
-- TODO(justinmk): could eliminate format_cjson if `vim.json.encode()` had formatting options.
33
local format_json = require('utils.format_cjson')
44

55
local encoded_json = format_json(schema, "\n", " ")..'\n'

scripts/packspec.lua

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ if not arg[1] then
88
end
99

1010
local jsonschema = require('jsonschema')
11-
local cjson = require('cjson.safe')
1211
local schema = require('packspec.schema')
1312

1413
local validator = jsonschema.generate_validator(schema)
1514

1615
for _, path in ipairs(arg) do
1716
local spec
1817
if path:match('%.lua$') then
19-
local chunk, err = loadfile(path)
18+
local chunk, err = assert(loadfile(path))
2019
if err then
2120
fatal('%s: loading failed\n%s', path, err)
2221
end
@@ -30,18 +29,18 @@ for _, path in ipairs(arg) do
3029
fatal('%s: evaluation failed\n%s', path, err)
3130
end
3231
elseif path:match('%.json$') then
33-
local file, err = io.open(path, 'rb')
32+
local file, err = assert(io.open(path, 'rb'))
3433
if err then
3534
fatal('%s: failed to open file\n%s', path, err)
3635
end
3736

38-
local json = file:read('*a')
37+
local json = (file:read('*a'))
3938
file:close()
4039
if not json then
4140
fatal('%s: could not read the file', path)
4241
end
4342

44-
spec, err = cjson.decode(json)
43+
spec, err = vim.json.decode(json)
4544
if err then
4645
fatal('%s: decoding json failed\n%s', path, err)
4746
end

0 commit comments

Comments
 (0)