Skip to content

Commit

Permalink
ci: ensure ci runs lint and make lint pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanitskiy committed Jul 17, 2023
1 parent 83904af commit 8a9afc2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 45 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"ignorePatterns": ["**/node_modules/", "/dist/", "/lib/"],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"warn",
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ jobs:
strategy:
matrix:
nginx-version:
- 1.18.x
- 1.20.x
- 1.21.x
- 1.22.x
- 1.25.x
env:
NGINX_VERSION: ${{ matrix.nginx-version }}
runs-on: ubuntu-latest
Expand All @@ -21,7 +18,7 @@ jobs:
- name: Install dependencies
run: sudo apt-get install -y ca-certificates
- uses: actions/setup-node@v3
- run: npm install
- run: npm ci
- run: npm run lint
- run: npm run build
- run: npm run test
# - run: npm run lint
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// @ts-check

/** @type {babel.ConfigFunction} */
// eslint-disable-next-line no-undef
module.exports = (api) => ({
presets: [
// Transpile modern JavaScript into code compatible with njs.
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"build": "rollup -c --environment NODE_ENV:dev",
"clean": "rimraf dist/* lib/* node_modules/.cache/*",
"lint": "run-p lint:*",
"lint:eslint": "eslint --cache --cache-location node_modules/.cache/eslint --ext .ts,.js .",
"lint:types": "tsc -b",
"lint:eslint": "npx eslint .",
"prepublishOnly": "run-s build && asciidoctor -b docbook -a npm-readme -a gh-branch=v$npm_package_version -o - README.adoc | pandoc -f docbook -t gfm --base-header-level 2 -o README.md",
"start": "run-p watch start-nginx",
"start-nginx": "start-nginx --version 1.24.x --port 8090 --watch dist/ integration-tests/nginx.conf",
Expand Down
72 changes: 37 additions & 35 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import addGitMsg from 'rollup-plugin-add-git-msg'
import babel from '@rollup/plugin-babel'
import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import json from "@rollup/plugin-json";
import json from '@rollup/plugin-json'
import pkg from './package.json'


// List of njs built-in modules.
const njsExternals = ['crypto', 'fs', 'querystring']
// eslint-disable-next-line no-undef
const isEnvProd = process.env.NODE_ENV === 'production'

/**
Expand All @@ -18,44 +18,46 @@ const isEnvProd = process.env.NODE_ENV === 'production'
* @return {import('rollup').OutputPlugin}
*/
const fixExportDefault = () => ({
name: 'fix-export-default',
renderChunk: (code) => ({
code: code.replace(/\bexport { (\S+) as default };/, 'export default $1;'),
map: null,
}),
name: 'fix-export-default',
renderChunk: (code) => ({
code: code.replace(/\bexport { (\S+) as default };/, 'export default $1;'),
map: null,
}),
})

/**
* @type {import('rollup').RollupOptions}
*/
const options = {
input: 'src/index.ts',
external: njsExternals,
plugins: [
// Transpile TypeScript sources to JS.
babel({
babelHelpers: 'bundled',
envName: 'njs',
extensions: ['.ts', '.mjs', '.js'],
}),
// Resolve node modules.
resolve({
extensions: ['.mjs', '.js', '.json', '.ts'],
}),
json(),
// Convert CommonJS modules to ES6 modules.
commonjs(),
// Fix syntax of the default export.
fixExportDefault(),
// Plugins to use in production mode only.
...isEnvProd ? [
// Add git tag, commit SHA, build date and copyright at top of the file.
addGitMsg(),
] : [],
],
output: {
file: pkg.main,
format: 'es',
},
input: 'src/index.ts',
external: njsExternals,
plugins: [
// Transpile TypeScript sources to JS.
babel({
babelHelpers: 'bundled',
envName: 'njs',
extensions: ['.ts', '.mjs', '.js'],
}),
// Resolve node modules.
resolve({
extensions: ['.mjs', '.js', '.json', '.ts'],
}),
json(),
// Convert CommonJS modules to ES6 modules.
commonjs(),
// Fix syntax of the default export.
fixExportDefault(),
// Plugins to use in production mode only.
...(isEnvProd
? [
// Add git tag, commit SHA, build date and copyright at top of the file.
addGitMsg(),
]
: []),
],
output: {
file: pkg.main,
format: 'es',
},
}
export default options
3 changes: 3 additions & 0 deletions src/x509.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-fallthrough */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/**
* this is from https://github.com/nginx/njs-examples/blob/master/njs/http/certs/js/x509.js
*
Expand Down Expand Up @@ -370,6 +372,7 @@ function parse_pem_cert(pem) {
der = der.slice(1, -2)
}

// eslint-disable-next-line no-undef
return asn1_read(Buffer.from(der.join(''), 'base64'))
}

Expand Down
11 changes: 9 additions & 2 deletions unit-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["node", "njs-types"]
}
"types": ["njs-types", "node"]
},
"files": [
"../node_modules/njs-types/ngx_http_js_module.d.ts",
"../node_modules/njs-types/njs_webcrypto.d.ts",
"../node_modules/njs-types/njs_core.d.ts",
"../node_modules/njs-types/njs_modules/crypto.d.ts",
"../node_modules/njs-types/njs_modules/fs.d.ts"
]
}

0 comments on commit 8a9afc2

Please sign in to comment.