diff --git a/Makefile b/Makefile index c937345..5f908a2 100644 --- a/Makefile +++ b/Makefile @@ -28,17 +28,16 @@ deps: $(LUAROCKS) install inspect $(LUAROCKS) install net-url $(LUAROCKS) install jsonschema - $(LUAROCKS) install lua-cjson .PHONY: test test: deps json - ./scripts/packspec.lua examples/packspec.1.lua - ./scripts/packspec.lua examples/packspec.1.json + nvim -l ./scripts/packspec.lua examples/packspec.1.lua + nvim -l ./scripts/packspec.lua examples/packspec.1.json ./deps/bin/busted .PHONY: json json: deps - ./scripts/generate_json_schema.lua + nvim -l ./scripts/generate_json_schema.lua .PHONY: clean clean: diff --git a/lua/packspec/schema.lua b/lua/packspec/schema.lua index 0253674..2d53531 100644 --- a/lua/packspec/schema.lua +++ b/lua/packspec/schema.lua @@ -38,12 +38,12 @@ end return { title = "packspec", - description = "A package specification for Neovim", + description = "Package format for declaring decentralized, ad-hoc dependencies", type = 'object', additionalProperties = false, properties = { package = { - description = "The name of the package", + description = "Name of the package (optional)", type = "string", }, version = { diff --git a/lua/utils/format_cjson.lua b/lua/utils/format_cjson.lua index 3a0eec3..825a313 100644 --- a/lua/utils/format_cjson.lua +++ b/lua/utils/format_cjson.lua @@ -26,8 +26,7 @@ -- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -local ok, cjson = pcall(require, "cjson.safe") -local enc = ok and cjson.encode or function() return nil, "Lua cJSON encoder not found" end +local enc = vim.json.encode local cat = table.concat local sub = string.sub local rep = string.rep diff --git a/schema/packspec_schema.json b/schema/packspec_schema.json index 2a6065e..2f603c7 100644 --- a/schema/packspec_schema.json +++ b/schema/packspec_schema.json @@ -1,117 +1,117 @@ { - "type": "object", - "title": "packspec", - "required": [ - "package", - "source" - ], + "additionalProperties": false, "properties": { - "packspec": { - "type": "string", - "description": "The current specification version. (0.1.0) at this time.", - "pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$" - }, - "dependencies": { - "patternProperties": { - ".*": { - "type": "object", - "additionalProperties": false, - "properties": { - "releases_only": { - "description": "Whether the package manager should only resolve version\nconstraints to include tagged releases.", - "type": "boolean" - }, - "version": { - "type": "string", - "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", - "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]*))*)*$" - }, - "source": { - "type": "string", - "description": "Source of the dependency. See previous `source` description.", - "pattern": "^\\w+:\/\/" - } - } - } - } - }, - "version": { - "type": "string", - "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.", - "pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$" - }, "external_dependencies": { - "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.", "patternProperties": { ".*": { - "type": "object", "additionalProperties": false, "properties": { "version": { - "type": "string", "description": "Same as `dependencies`", - "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]*))*)*$" + "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]*))*)*$", + "type": "string" } - } + }, + "type": "object" } - } + }, + "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." }, - "package": { - "description": "The name of the package", + "packspec": { + "description": "The current specification version. (0.1.0) at this time.", + "pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$", "type": "string" }, + "package": { + "type": "string", + "description": "The name of the package" + }, "description": { + "additionalProperties": false, + "description": "Description of the package", "properties": { "summary": { - "description": "Short description of the package, typically less than 100 character\nlong.", - "type": "string" + "type": "string", + "description": "Short description of the package, typically less than 100 character\nlong." }, "homepage": { - "description": "Homepage of the package. In most cases this will be the GitHub URL.", - "type": "string" + "type": "string", + "description": "Homepage of the package. In most cases this will be the GitHub URL." + }, + "detailed": { + "type": "string", + "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." + }, + "license": { + "type": "string", + "description": "This is [SPDX](https:\/\/spdx.org\/licenses\/) license identifier. Dual\nlicensing is indicated via joining the relevant licenses via `\/`." }, "author": { + "additionalProperties": false, + "description": "Author of the package", "properties": { + "email": { + "type": "string", + "description": "Author email" + }, "name": { - "description": "Author name", + "type": "string", + "description": "Author name" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "version": { + "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.", + "pattern": "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*$", + "type": "string" + }, + "$schema": { + "type": "string", + "description": "The optional json schema URI for validation with json-language-server." + }, + "dependencies": { + "patternProperties": { + ".*": { + "additionalProperties": false, + "properties": { + "version": { + "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", + "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]*))*)*$", "type": "string" }, - "email": { - "description": "Author email", + "releases_only": { + "type": "boolean", + "description": "Whether the package manager should only resolve version\nconstraints to include tagged releases." + }, + "source": { + "description": "Source of the dependency. See previous `source` description.", + "pattern": "^\\w+:\/\/", "type": "string" } }, - "type": "object", - "description": "Author of the package", - "additionalProperties": false - }, - "license": { - "description": "This is [SPDX](https:\/\/spdx.org\/licenses\/) license identifier. Dual\nlicensing is indicated via joining the relevant licenses via `\/`.", - "type": "string" - }, - "detailed": { - "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.", - "type": "string" + "type": "object" } - }, - "type": "object", - "description": "Description of the package", - "additionalProperties": false + } }, "source": { "pattern": "^\\w+:\/\/", - "type": "string", - "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 git@example.com\/myrepo.\n * `http:\/\/` - for HTTP URLs\n * `https:\/\/` - for HTTPS URLs", "examples": [ "luarocks:\/\/argparse", "git:\/\/github.com\/nvim-lua\/plenary.nvim" - ] - }, - "$schema": { - "description": "The optional json schema URI for validation with json-language-server.", + ], + "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 git@example.com\/myrepo.\n * `http:\/\/` - for HTTP URLs\n * `https:\/\/` - for HTTPS URLs", "type": "string" } }, - "additionalProperties": false, - "description": "A package specification for Neovim" + "title": "packspec", + "description": "A package specification for Neovim", + "required": [ + "package", + "source" + ], + "type": "object" } diff --git a/scripts/generate_json_schema.lua b/scripts/generate_json_schema.lua index 484aac6..3452a89 100755 --- a/scripts/generate_json_schema.lua +++ b/scripts/generate_json_schema.lua @@ -1,12 +1,9 @@ -#! /usr/bin/env lua5.1 - --- local cjson = require('cjson') local schema = require('packspec.schema') +-- TODO(justinmk): could eliminate format_cjson if `vim.json.encode()` had formatting options. local format_json = require('utils.format_cjson') -local encoded_json = format_json(schema, "\n", " ") - -local file = io.open('schema/packspec_schema.json', 'w') +local encoded_json = format_json(schema, "\n", " ")..'\n' +local file = assert(io.open('schema/packspec_schema.json', 'w')) io.output(file) io.write(encoded_json) io.close(file) diff --git a/scripts/packspec.lua b/scripts/packspec.lua index d42d3d1..e69250c 100755 --- a/scripts/packspec.lua +++ b/scripts/packspec.lua @@ -1,5 +1,3 @@ -#! /usr/bin/env lua5.1 - local function fatal(s, ...) print(string.format(s, ...)) os.exit(1) @@ -10,7 +8,6 @@ if not arg[1] then end local jsonschema = require('jsonschema') -local cjson = require('cjson.safe') local schema = require('packspec.schema') local validator = jsonschema.generate_validator(schema) @@ -18,7 +15,7 @@ local validator = jsonschema.generate_validator(schema) for _, path in ipairs(arg) do local spec if path:match('%.lua$') then - local chunk, err = loadfile(path) + local chunk, err = assert(loadfile(path)) if err then fatal('%s: loading failed\n%s', path, err) end @@ -32,18 +29,18 @@ for _, path in ipairs(arg) do fatal('%s: evaluation failed\n%s', path, err) end elseif path:match('%.json$') then - local file, err = io.open(path, 'rb') + local file, err = assert(io.open(path, 'rb')) if err then fatal('%s: failed to open file\n%s', path, err) end - local json = file:read('*a') + local json = (file:read('*a')) file:close() if not json then fatal('%s: could not read the file', path) end - spec, err = cjson.decode(json) + spec, err = vim.json.decode(json) if err then fatal('%s: decoding json failed\n%s', path, err) end diff --git a/test-npm/.gitignore b/test-npm/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/test-npm/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/test-npm/README.md b/test-npm/README.md new file mode 100644 index 0000000..a56232d --- /dev/null +++ b/test-npm/README.md @@ -0,0 +1,10 @@ +# Test pkg.json against NPM's read-package-json library + +`pkg.json` tries to be a subset of NPM's `package.json` format. The tests in +this directory test `pkg.json` samples using NPM's `read-package-json` library. + +To run the tests: + + cd test-npm/ + npm ci + npm run test diff --git a/test-npm/package-lock.json b/test-npm/package-lock.json new file mode 100644 index 0000000..212e6cd --- /dev/null +++ b/test-npm/package-lock.json @@ -0,0 +1,664 @@ +{ + "name": "packspec-npm-test", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "packspec-npm-test", + "version": "1.0.0", + "license": "Apache-2.0", + "devDependencies": { + "read-package-json": "^6.0.4" + } + }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, + "node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "node_modules/foreground-child": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", + "dev": true + }, + "node_modules/glob": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.1.tgz", + "integrity": "sha512-9BKYcEeIs7QwlCYs+Y3GBvqAMISufUS0i2ELd11zpZjxI5V9iyRj0HgzB5/cLf2NY4vcYBTYzJ7GIui7j/4DOw==", + "dev": true, + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^2.0.3", + "minimatch": "^9.0.1", + "minipass": "^5.0.0 || ^6.0.2", + "path-scurry": "^1.10.0" + }, + "bin": { + "glob": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/hosted-git-info": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-6.1.1.tgz", + "integrity": "sha512-r0EI+HBMcXadMrugk0GCQ+6BQV39PiWAZVfq7oIckeGiN7sjRGyQxPdft3nQekFTCQbYxLBH+/axZMeH8UX6+w==", + "dev": true, + "dependencies": { + "lru-cache": "^7.5.1" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/is-core-module": { + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz", + "integrity": "sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==", + "dev": true, + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, + "node_modules/jackspeak": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.2.1.tgz", + "integrity": "sha512-MXbxovZ/Pm42f6cDIDkl3xpwv1AGwObKwfmjs2nQePiy85tP3fatofl3FC1aBsOtP/6fq5SbtgHwWcMsLP+bDw==", + "dev": true, + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, + "node_modules/json-parse-even-better-errors": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-3.0.0.tgz", + "integrity": "sha512-iZbGHafX/59r39gPwVPRBGw0QQKnA7tte5pSMrhWOW7swGsVvVTjmfyAV9pNqk8YGT7tRCdxRu8uzcgZwoDooA==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "dev": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/minimatch": { + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/minipass": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-6.0.2.tgz", + "integrity": "sha512-MzWSV5nYVT7mVyWCwn2o7JH13w2TBRmmSqSRCKzTw+lmft9X4z+3wjvs06Tzijo5z4W/kahUCDpRXTF+ZrmF/w==", + "dev": true, + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/normalize-package-data": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-5.0.0.tgz", + "integrity": "sha512-h9iPVIfrVZ9wVYQnxFgtw1ugSvGEMOlyPWWtm8BMJhnwyEL/FLbYbTY3V3PpjI/BUK67n9PEWDu6eHzu1fB15Q==", + "dev": true, + "dependencies": { + "hosted-git-info": "^6.0.0", + "is-core-module": "^2.8.1", + "semver": "^7.3.5", + "validate-npm-package-license": "^3.0.4" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/npm-normalize-package-bin": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-3.0.1.tgz", + "integrity": "sha512-dMxCf+zZ+3zeQZXKxmyuCKlIDPGuv8EF940xbkC4kQVDTtqoh6rJFO+JTKSA6/Rwi0getWmtuy4Itup0AMcaDQ==", + "dev": true, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-scurry": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.0.tgz", + "integrity": "sha512-tZFEaRQbMLjwrsmidsGJ6wDMv0iazJWk6SfIKnY4Xru8auXgmJkOBa5DUbYFcFD2Rzk2+KDlIiF0GVXNCbgC7g==", + "dev": true, + "dependencies": { + "lru-cache": "^9.1.1 || ^10.0.0", + "minipass": "^5.0.0 || ^6.0.2" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.0.0.tgz", + "integrity": "sha512-svTf/fzsKHffP42sujkO/Rjs37BCIsQVRCeNYIm9WN8rgT7ffoUnRtZCqU+6BqcSBdv8gwJeTz8knJpgACeQMw==", + "dev": true, + "engines": { + "node": "14 || >=16.14" + } + }, + "node_modules/read-package-json": { + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-6.0.4.tgz", + "integrity": "sha512-AEtWXYfopBj2z5N5PbkAOeNHRPUg5q+Nen7QLxV8M2zJq1ym6/lCz3fYNTCXe19puu2d06jfHhrP7v/S2PtMMw==", + "dev": true, + "dependencies": { + "glob": "^10.2.2", + "json-parse-even-better-errors": "^3.0.0", + "normalize-package-data": "^5.0.0", + "npm-normalize-package-bin": "^3.0.0" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/signal-exit": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.0.2.tgz", + "integrity": "sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/spdx-correct": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", + "integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==", + "dev": true, + "dependencies": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-exceptions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==", + "dev": true + }, + "node_modules/spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dev": true, + "dependencies": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-license-ids": { + "version": "3.0.13", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.13.tgz", + "integrity": "sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==", + "dev": true + }, + "node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/string-width-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "dependencies": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/wrap-ansi-cjs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + } + } +} diff --git a/test-npm/package.json b/test-npm/package.json new file mode 100644 index 0000000..8b5b149 --- /dev/null +++ b/test-npm/package.json @@ -0,0 +1,14 @@ +{ + "name": "packspec-npm-test", + "version": "1.0.0", + "description": "Test pkg.json against NPM's read-package-json library", + "main": "npm.test.js", + "scripts": { + "test": "node test.js " + }, + "author": "packspec team", + "license": "Apache-2.0", + "devDependencies": { + "read-package-json": "^6.0.4" + } +} diff --git a/test-npm/test.js b/test-npm/test.js new file mode 100644 index 0000000..ffefe75 --- /dev/null +++ b/test-npm/test.js @@ -0,0 +1,71 @@ +// NODE_PATH=$(npm root -g) node scripts/npm.js + +var fs = require('fs') +var assert = require('assert') +var path = require('path') +var readJson = require('read-package-json') + +const fname = 'pkg.json' + +function runTest(inputFile, expectedFile) { + const expected = require('./'+expectedFile).expected + + // readJson(filename, [logFunction=noop], [strict=false], cb) + readJson(inputFile, console.error, false, function (e, data) { + if (e) { + console.error(`failed to parse "${inputFile}": ${e}`); + throw Error(`failed to parse "${inputFile}"`) + } + + // Remove unwanted fields auto-filled by read-package-json. + for (const field of ['gitHead']) { + delete data[field] + } + for (const field of Object.getOwnPropertySymbols(data)) { + // Symbol('indent'), Symbol('newline'), … + delete data[field] + } + + // assert.deepStrictEqual(data.engines, expected.engines); + // assert.deepStrictEqual(data.dependencies, expected.dependencies); + assert.deepStrictEqual(data, expected); + }); +} + +function runTests() { + const failures = []; + const tests = {}; // input:output map. { "test1.pkg.json" : "test1.expected.js", … } + const testDir = 'test/'; + const testFilenames = fs.readdirSync(testDir); + + // Find the tests. + for (const fname of testFilenames) { + const testName = fname.match(/[^.]+/).toString() // Remove ".pkg.json" suffix. + const suffix = fname.match(/\..+/)?.toString() // Get ".pkg.json" suffix. + const fullpath = path.join(testDir, fname); + if (suffix !== '.expected.js' && suffix !== '.pkg.json') { + throw Error(`unexpected test file (does not end with ".expected.js" or "pkg.json"): ${fullpath}`) + } + if (suffix === '.pkg.json') { + tests[fname] = `${testName}.expected.js`; + const expectedFile = path.join(testDir, tests[fname]); + if (!fs.existsSync(expectedFile)) { + throw Error(`found "${fname}", but missing "${tests[fname]}"`) + } + } + } + + // sanity check + assert(Object.keys(tests).length > 0, `no tests found in: ${testDir}`); + + // Run the tests. + for (const test of Object.keys(tests)) { + const inputFile = path.join(testDir, test); + const expectedFile = path.join(testDir, tests[test]); + runTest(inputFile, expectedFile); + } + + console.log(`test result: ${Object.keys(tests).length} passed, ${failures.length} failed`); +} + +runTests(); diff --git a/test-npm/test/test1.expected.js b/test-npm/test/test1.expected.js new file mode 100644 index 0000000..3e9b474 --- /dev/null +++ b/test-npm/test/test1.expected.js @@ -0,0 +1,22 @@ +// vim: set nomodeline + +module.exports.expected = { + name: 'lspconfig', + description: 'Quickstart configurations for the Nvim-lsp client', + randomClientDefinedField: 'foo', + readme: 'readme content', + engines: { nvim: '^0.10.0', vim: '^9.1.0' }, + repository: { + type: 'git', + url: 'git+https://github.com/neovim/nvim-lspconfig.git' + }, + dependencies: { + 'https://github.com/neovim/neovim': '0.6.1', + 'https://github.com/lewis6991/gitsigns.nvim': '0.3' + }, + version: '', + bugs: { url: 'https://github.com/neovim/nvim-lspconfig/issues' }, + homepage: 'https://github.com/neovim/nvim-lspconfig#readme', + _id: 'lspconfig@', + license: 'Apache-2.0', +} diff --git a/test-npm/test/test1.pkg.json b/test-npm/test/test1.pkg.json new file mode 100644 index 0000000..f8b3857 --- /dev/null +++ b/test-npm/test/test1.pkg.json @@ -0,0 +1,19 @@ +{ + "name": "lspconfig", + "randomClientDefinedField": "foo", + "description": "Quickstart configurations for the Nvim-lsp client", + "license": "Apache-2.0", + "readme": "readme content", + "engines": { + "nvim": "^0.10.0", + "vim": "^9.1.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/neovim/nvim-lspconfig" + }, + "dependencies" : { + "https://github.com/neovim/neovim" : "0.6.1", + "https://github.com/lewis6991/gitsigns.nvim" : "0.3" + } +} diff --git a/test-npm/test/test2.expected.js b/test-npm/test/test2.expected.js new file mode 100644 index 0000000..fd6c215 --- /dev/null +++ b/test-npm/test/test2.expected.js @@ -0,0 +1,20 @@ +// vim: set nomodeline + +module.exports.expected = { + name: 'lspconfig', + description: 'Quickstart configurations for the Nvim-lsp client', + readme: 'readme content', + engines: { nvim: '^0.10.0', vim: '^9.1.0' }, + repository: { + url: 'https://git.sr.ht/~example/foo.git', + }, + dependencies: { + 'https://github.com/neovim/neovim': '0.6.1', + 'https://github.com/lewis6991/gitsigns.nvim': '0.3' + }, + version: '', + bugs: { url: 'https://todo.sr.ht/~example/foo' }, + homepage: 'https://git.sr.ht/~example/foo#readme', + _id: 'lspconfig@', + license: 'Apache-2.0', +} diff --git a/test-npm/test/test2.pkg.json b/test-npm/test/test2.pkg.json new file mode 100644 index 0000000..284a771 --- /dev/null +++ b/test-npm/test/test2.pkg.json @@ -0,0 +1,17 @@ +{ + "name": "lspconfig", + "description": "Quickstart configurations for the Nvim-lsp client", + "readme": "readme content", + "license": "Apache-2.0", + "engines": { + "nvim": "^0.10.0", + "vim": "^9.1.0" + }, + "repository": { + "url": "https://git.sr.ht/~example/foo" + }, + "dependencies" : { + "https://github.com/neovim/neovim" : "0.6.1", + "https://github.com/lewis6991/gitsigns.nvim" : "0.3" + } +}