upgrade NodeJS from 14 LTS to 16 LTS (#1924)

* update from node 14 to node 16

* update package.json

Notice that the package-lock.json have a new format due to nodejs 16

* remove grunt task validate_links

undo PR #1297
Fetch github tags as versions for urls

* add travis-ci: osx_image xcode13.1
This commit is contained in:
Gerry Ferdinandus
2021-11-09 18:41:06 +01:00
committed by GitHub
parent 233939e550
commit 55661bbc6d
5 changed files with 4799 additions and 1013 deletions

View File

@@ -11,9 +11,9 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: '14.x'
node-version: '16'
- name: Run test
run: |
cd src

View File

@@ -1038,167 +1038,6 @@ module.exports = function (grunt) {
grunt.log.ok('OK')
})
function hasBOM (buf) {
return buf.length > 2 && buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf
}
function parseJSON (text) {
try {
return {
json: JSON.parse(text)
}
} catch (err) {
return {
error: err.message
}
}
}
const rawGithubPrefix = 'https://raw.githubusercontent.com/'
function isRawGithubURL (url) {
return url.startsWith(rawGithubPrefix)
}
// extract repo, branch and path from a raw GitHub url
// returns false if not a raw GitHub url
function parseRawGithubURL (url) {
if (isRawGithubURL(url)) {
const [project, repo, branch, ...path] =
url
.substr(rawGithubPrefix.length)
.split('/')
return {
repo: `https://github.com/${project}/${repo}`,
base: `${project}/${repo}`,
branch,
path: path.join('/')
}
}
return false
}
const util = require('util')
const exec = util.promisify(require('child_process').exec)
// heuristic to find valid version tag
// disregard versions that are marked as special
// require at least a number
function validVersion (version) {
const invalid =
/alpha|beta|next|rc|tag|pre|\^/i.test(version) ||
!/\d+/.test(version)
return !invalid
}
// extract tags that might represent versions and return most recent
// returns false none found
async function githubNewestRelease (githubRepo) {
const cmd = `git ls-remote --tags ${githubRepo}`
const result = await exec(cmd)
const stdout = result.stdout.trim()
if (stdout === '') {
return false
}
const refs =
stdout
.split('\n')
.map(line =>
line
.split('\t')[1]
.split('/')[2]
)
// sort refs using "natural" ordering (so that it works with versions)
const collator = new Intl.Collator(undefined, {
numeric: true,
sensitivity: 'base'
})
refs.sort(collator.compare)
const refsDescending =
refs
.reverse()
.filter(version => validVersion(version))
if (refsDescending.length > 0) {
return refsDescending[0]
}
return false
}
// git default branch (master/main)
async function githubDefaultBranch (githubRepo) {
const cmd = `git ls-remote --symref ${githubRepo} HEAD`
const prefix = 'ref: refs/heads/'
const result = await exec(cmd)
const stdout = result.stdout.trim()
const rows =
stdout
.split('\n')
.map(line => line.split('\t'))
for (const row of rows) {
if (row[0].startsWith(prefix)) {
return row[0].substr(prefix.length)
}
}
throwWithErrorText(['unable to determine default branch'])
}
// construct raw GitHub url to the newest version
async function rawGithubVersionedURL (url) {
const urlParts = parseRawGithubURL(url)
let branch = await githubNewestRelease(urlParts.repo)
if (branch === false) {
branch = await githubDefaultBranch(urlParts.repo)
}
return {
repo: urlParts.repo,
branch,
rawURL: `${rawGithubPrefix}${urlParts.base}/${branch}/${urlParts.path}`
}
}
// Async task structure: https://gruntjs.com/creating-tasks
grunt.registerTask('validate_links', 'Check if links return 200 and valid json', async function () {
// Force task into async mode and grab a handle to the "done" function.
const done = this.async()
const catalogFileName = 'api/json/catalog.json'
const catalog = grunt.file.readJSON(catalogFileName)
const got = require('got')
for (let { url } of catalog.schemas) {
if (isRawGithubURL(url)) {
const { repo, branch, rawURL } = await rawGithubVersionedURL(url)
if (url !== rawURL) {
grunt.log.error('repo', repo, 'branch', branch, 'url should be', rawURL)
// test if the advised url works
url = rawURL
}
}
try {
const body = await got(url)
if (body.statusCode !== 200) {
grunt.log.error(url, body.statusCode)
continue
}
if (hasBOM(body.rawBody)) {
grunt.log.error(url, 'contains UTF-8 BOM')
}
const result = parseJSON(body.rawBody.toString('utf8'))
if (result.error) {
grunt.log.error(url, result.error)
}
} catch (err) {
grunt.log.error(url, err.message)
}
}
done()
})
grunt.registerTask('local_test',
[
'local_check_duplicate_list_in_schema-validation.json',

5635
src/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,23 +17,22 @@
"build": "npm run eslint_check && grunt",
"eslint_check": "eslint Gruntfile.js",
"eslint_fix": "eslint --fix Gruntfile.js",
"validate_links": "grunt validate_links",
"remote": "grunt remote_test",
"maintenance": "grunt local_maintenance"
},
"devDependencies": {
"ajv": "^8.6.3",
"ajv": "^8.7.1",
"ajv-draft-04": "^0.1.0",
"ajv-formats": "^2.1.1",
"ajv-formats-draft2019": "^1.6.1",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-promise": "^5.1.1",
"find-duplicated-property-keys": "^1.2.7",
"got": "^11.8.2",
"grunt": "^1.4.1",
"grunt-tv4": "^2.1.0"
"grunt-tv4": "^5.0.1"
}
}

View File

@@ -224,7 +224,8 @@
"xcode12.2",
"xcode12.3",
"xcode12.4",
"xcode12.5"
"xcode12.5",
"xcode13.1"
]
},
"envVars": {