From c47ee9accc8e5814f56585dc711c974b2ca8f709 Mon Sep 17 00:00:00 2001 From: klu909 <55161078+klu909@users.noreply.github.com> Date: Thu, 1 Dec 2022 16:03:04 -0800 Subject: [PATCH] feat(2683): nodejs upgrade (#36) BREAKING CHANGE: Node 18 upgrade && eslint upgrade --- bin/main.js | 6 +----- commands.js | 5 +---- index.js | 4 +++- package.json | 22 +++++++++++----------- screwdriver.yaml | 2 +- test/index.test.js | 11 ++++++----- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/bin/main.js b/bin/main.js index 5082ab1..b795b1e 100755 --- a/bin/main.js +++ b/bin/main.js @@ -10,11 +10,7 @@ const nomnom = require('nomnom'); const { operations } = require('../commands'); Object.keys(operations).forEach(key => { - nomnom - .command(key) - .options(operations[key].opts) - .callback(operations[key].exec) - .help(operations[key].help); + nomnom.command(key).options(operations[key].opts).callback(operations[key].exec).help(operations[key].help); }); nomnom.parse(); diff --git a/commands.js b/commands.js index a8df663..6354fcb 100644 --- a/commands.js +++ b/commands.js @@ -182,10 +182,7 @@ const operations = { * @return {Object} result of command, if any */ function run(name) { - const opts = nomnom - .options(operations[name].opts) - .help(operations[name].help) - .parse(); + const opts = nomnom.options(operations[name].opts).help(operations[name].help).parse(); return operations[name].exec(opts); } diff --git a/index.js b/index.js index 5857be7..5ad9951 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,9 @@ const Yaml = require('js-yaml'); * @return {Promise} Promise that resolves to the template as a config object */ function loadYaml(path) { - return new Promise(resolve => resolve(Yaml.safeLoad(fs.readFileSync(path, 'utf8')))); + return new Promise(resolve => { + resolve(Yaml.load(fs.readFileSync(path, 'utf8'))); + }); } /** diff --git a/package.json b/package.json index bfa3a38..797ae6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "screwdriver-template-main", - "version": "1.0.0", + "version": "2.0.0", "description": "Validates, publishes, and tags templates", "main": "index.js", "scripts": { @@ -41,25 +41,25 @@ "Tiffany Kyi " ], "devDependencies": { - "chai": "^4.3.4", - "eslint": "^7.31.0", - "eslint-config-screwdriver": "^5.0.1", - "mocha": "^8.2.1", + "chai": "^4.3.7", + "eslint": "^8.28.0", + "eslint-config-screwdriver": "^7.0.0", + "mocha": "^10.1.0", "mocha-multi-reporters": "^1.5.1", "mocha-sonarqube-reporter": "^1.0.2", - "mockery": "^2.0.0", - "nyc": "^15.0.0", - "sinon": "^9.0.0" + "mockery": "^2.1.0", + "nyc": "^15.1.0", + "sinon": "^15.0.0" }, "dependencies": { - "js-yaml": "^3.14.1", + "js-yaml": "^4.1.0", "nomnom": "^1.8.1", - "screwdriver-request": "^1.0.1" + "screwdriver-request": "^2.0.1" }, "release": { "debug": false }, "engines": { - "node": ">=12.0.0" + "node": ">=18.0.0" } } diff --git a/screwdriver.yaml b/screwdriver.yaml index 60fc1e0..ec9095b 100644 --- a/screwdriver.yaml +++ b/screwdriver.yaml @@ -1,5 +1,5 @@ shared: - image: node:12 + image: node:18 jobs: main: diff --git a/test/index.test.js b/test/index.test.js index 2bbd968..6dbd3d7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -23,7 +23,7 @@ describe('index', () => { beforeEach(() => { requestMock = sinon.stub(); YamlMock = { - safeLoad: sinon.stub() + load: sinon.stub() }; fsMock = { readFileSync: sinon.stub() @@ -39,7 +39,7 @@ describe('index', () => { } }; - YamlMock.safeLoad.returns(templateConfig); + YamlMock.load.returns(templateConfig); mockery.registerMock('fs', fsMock); mockery.registerMock('js-yaml', YamlMock); @@ -61,7 +61,7 @@ describe('index', () => { describe('Load Yaml', () => { it('resolves if loads successfully', () => { - YamlMock.safeLoad.resolves('yamlcontent'); + YamlMock.load.resolves('yamlcontent'); return index.loadYaml(config => assert.equal(config, 'yamlcontent')); }); @@ -263,8 +263,9 @@ describe('index', () => { }); }); describe('Template Tag', () => { - const url = `${process.env.SD_API_URL || - 'https://api.screwdriver.cd/v4/'}templates/template%2Ftest/tags/stable`; + const url = `${ + process.env.SD_API_URL || 'https://api.screwdriver.cd/v4/' + }templates/template%2Ftest/tags/stable`; describe('Create/Update a tag', () => { const config = {