Merge pull request #431 from akv-platform/allow-json-comments

Allow json comments
This commit is contained in:
Nikolai Laevskii 2023-06-06 13:17:59 +02:00 committed by GitHub
commit 70fa3206c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1539 additions and 7 deletions

View File

@ -229,6 +229,31 @@ jobs:
shell: pwsh shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2" run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"
test-global-json-with-comments:
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Clear toolcache
shell: pwsh
run: __tests__/clear-toolcache.ps1 ${{ runner.os }}
- name: Write global.json
shell: bash
run: |
mkdir subdirectory
echo '/* should support comments */ {"sdk":{"version": "2.2.207","rollForward": "latestFeature"}} // should support comments' > ./subdirectory/global.json
- name: Setup dotnet
uses: ./
with:
global-json-file: ./subdirectory/global.json
- name: Verify dotnet
shell: pwsh
run: __tests__/verify-dotnet.ps1 -Patterns "^2.2"
test-setup-with-dotnet-quality: test-setup-with-dotnet-quality:
runs-on: ${{ matrix.operating-system }} runs-on: ${{ matrix.operating-system }}
strategy: strategy:

36
.licenses/npm/json5.dep.yml generated Normal file
View File

@ -0,0 +1,36 @@
---
name: json5
version: 2.2.3
type: npm
summary: JSON for Humans
homepage: http://json5.org/
license: mit
licenses:
- sources: LICENSE.md
text: |
MIT License
Copyright (c) 2012-2018 Aseem Kishore, and [others].
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[others]: https://github.com/json5/json5/contributors
- sources: README.md
text: MIT. See [LICENSE.md](./LICENSE.md) for details.
notices: []

1469
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

5
package-lock.json generated
View File

@ -17,6 +17,7 @@
"@actions/http-client": "^2.0.1", "@actions/http-client": "^2.0.1",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",
"fast-xml-parser": "^4.0.10", "fast-xml-parser": "^4.0.10",
"json5": "^2.2.3",
"semver": "^6.3.0" "semver": "^6.3.0"
}, },
"devDependencies": { "devDependencies": {
@ -4902,7 +4903,6 @@
"version": "2.2.3", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
"dev": true,
"bin": { "bin": {
"json5": "lib/cli.js" "json5": "lib/cli.js"
}, },
@ -10204,8 +10204,7 @@
"json5": { "json5": {
"version": "2.2.3", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg=="
"dev": true
}, },
"kleur": { "kleur": {
"version": "3.0.3", "version": "3.0.3",

View File

@ -34,6 +34,7 @@
"@actions/http-client": "^2.0.1", "@actions/http-client": "^2.0.1",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",
"fast-xml-parser": "^4.0.10", "fast-xml-parser": "^4.0.10",
"json5": "^2.2.3",
"semver": "^6.3.0" "semver": "^6.3.0"
}, },
"devDependencies": { "devDependencies": {

View File

@ -7,6 +7,7 @@ import * as auth from './authutil';
import {isCacheFeatureAvailable} from './cache-utils'; import {isCacheFeatureAvailable} from './cache-utils';
import {restoreCache} from './cache-restore'; import {restoreCache} from './cache-restore';
import {Outputs} from './constants'; import {Outputs} from './constants';
import JSON5 from 'json5';
const qualityOptions = [ const qualityOptions = [
'daily', 'daily',
@ -97,9 +98,14 @@ export async function run() {
function getVersionFromGlobalJson(globalJsonPath: string): string { function getVersionFromGlobalJson(globalJsonPath: string): string {
let version = ''; let version = '';
const globalJson = JSON.parse( const globalJson = JSON5.parse(
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim() fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim(),
// is necessary as JSON5 supports wider variety of options for numbers: https://www.npmjs.com/package/json5#numbers
(key, value) => {
if (key === 'version' || key === 'rollForward') return String(value);
return value;
}
); );
if (globalJson.sdk && globalJson.sdk.version) { if (globalJson.sdk && globalJson.sdk.version) {
version = globalJson.sdk.version; version = globalJson.sdk.version;