Skip to content

Commit f558976

Browse files
authored
chore: update tooling (#241)
BREAKING CHANGE: support for node 8 was dropped
1 parent 4f05353 commit f558976

17 files changed

+12594
-235
lines changed

.eslintrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
env: {
3+
commonjs: true,
4+
es6: true,
5+
node: true,
6+
jest: true,
7+
},
8+
extends: 'eslint:recommended',
9+
globals: {
10+
Atomics: 'readonly',
11+
SharedArrayBuffer: 'readonly',
12+
},
13+
parserOptions: {
14+
ecmaVersion: 11,
15+
},
16+
};

.github/workflows/test.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Node CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- '*'
9+
10+
pull_request:
11+
types: [opened, synchronize, reopened]
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
os: [macos-latest, ubuntu-latest, windows-latest]
19+
node-version: [10.x, 12.x, 13.x]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
- name: Get npm cache directory
28+
id: npm-cache
29+
run: |
30+
echo "::set-output name=dir::$(npm config get cache)"
31+
- uses: actions/cache@v2
32+
with:
33+
path: ${{ steps.npm-cache.outputs.dir }}
34+
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
35+
restore-keys: |
36+
${{ runner.os }}-node-${{ matrix.node-version }}-
37+
- name: log versions
38+
run: node --version && npm --version
39+
- name: install dependencies
40+
run: npm ci
41+
- name: run linter
42+
run: npm run lint
43+
- name: check formatting
44+
run: npm run format:ci
45+
- name: run tests
46+
run: npm test

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules/
22
.vscode/
33
*.swp
4-
package-lock.json
54
.temp

.prettierrc

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
{}
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"trailingComma": "all",
7+
"useTabs": false,
8+
"overrides": [
9+
{
10+
"files": "*.json",
11+
"options": { "printWidth": 200 }
12+
}
13+
]
14+
}
15+

bin/cmd.js

+40-40
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,61 @@
44
* Module dependencies.
55
*/
66

7-
var program = require("commander");
8-
var fs = require("fs");
9-
var path = require("path");
7+
var program = require('commander');
8+
var fs = require('fs');
9+
var path = require('path');
1010
var pkg = JSON.parse(
11-
fs.readFileSync(path.join(__dirname, "..", "package.json"))
11+
fs.readFileSync(path.join(__dirname, '..', 'package.json')),
1212
);
13-
var build = require("../lib/build");
14-
var serve = require("../lib/serve");
15-
var install = require("../lib/install");
13+
var build = require('../lib/build');
14+
var serve = require('../lib/serve');
15+
var install = require('../lib/install');
1616

1717
program.version(pkg.version);
1818

19-
const stringBooleanToBoolean = val => {
19+
const stringBooleanToBoolean = (val) => {
2020
console.log({ val });
21-
if (typeof val !== "string" && (val !== "true" || val !== "false")) {
21+
if (typeof val !== 'string' && (val !== 'true' || val !== 'false')) {
2222
throw Error(`Incorrect string value: ${val}`);
2323
}
2424

25-
return val === "true";
25+
return val === 'true';
2626
};
2727

2828
program
29-
.option("-c --config <webpack-config>", "additional webpack configuration")
30-
.option("-p --port <port>", "port to serve from (default: 9000)")
29+
.option('-c --config <webpack-config>', 'additional webpack configuration')
30+
.option('-p --port <port>', 'port to serve from (default: 9000)')
3131
.option(
32-
"-b --babelrc <babelrc>",
33-
"use .babelrc in root (default: true)",
34-
stringBooleanToBoolean
32+
'-b --babelrc <babelrc>',
33+
'use .babelrc in root (default: true)',
34+
stringBooleanToBoolean,
3535
)
3636
.option(
37-
"-t --timeout <timeout>",
38-
"function invocation timeout in seconds (default: 10)"
37+
'-t --timeout <timeout>',
38+
'function invocation timeout in seconds (default: 10)',
3939
)
40-
.option("-s --static", "serve pre-built lambda files");
40+
.option('-s --static', 'serve pre-built lambda files');
4141

4242
program
43-
.command("serve <dir>")
44-
.description("serve and watch functions")
45-
.action(function(cmd, options) {
46-
console.log("netlify-lambda: Starting server");
43+
.command('serve <dir>')
44+
.description('serve and watch functions')
45+
.action(function (cmd) {
46+
console.log('netlify-lambda: Starting server');
4747
var static = Boolean(program.static);
4848
var server;
49-
var startServer = function() {
49+
var startServer = function () {
5050
server = serve.listen(
5151
program.port || 9000,
5252
static,
53-
Number(program.timeout) || 10
53+
Number(program.timeout) || 10,
5454
);
5555
};
5656
if (static) {
5757
startServer();
5858
return; // early terminate, don't build
5959
}
6060
const { config: userWebpackConfig, babelrc: useBabelrc = true } = program;
61-
build.watch(cmd, { userWebpackConfig, useBabelrc }, function(err, stats) {
61+
build.watch(cmd, { userWebpackConfig, useBabelrc }, function (err, stats) {
6262
if (err) {
6363
console.error(err);
6464
return;
@@ -67,47 +67,47 @@ program
6767
if (!server) {
6868
startServer();
6969
}
70-
stats.compilation.chunks.forEach(function(chunk) {
70+
stats.compilation.chunks.forEach(function (chunk) {
7171
server.clearCache(chunk.name || chunk.id.toString());
7272
});
7373
});
7474
});
7575

7676
program
77-
.command("build <dir>")
78-
.description("build functions")
79-
.action(function(cmd, options) {
80-
console.log("netlify-lambda: Building functions");
77+
.command('build <dir>')
78+
.description('build functions')
79+
.action(function (cmd) {
80+
console.log('netlify-lambda: Building functions');
8181

8282
const { config: userWebpackConfig, babelrc: useBabelrc = true } = program;
8383
build
8484
.run(cmd, { userWebpackConfig, useBabelrc })
85-
.then(function(stats) {
85+
.then(function (stats) {
8686
console.log(stats.toString(stats.compilation.options.stats));
8787
})
88-
.catch(function(err) {
88+
.catch(function (err) {
8989
console.error(err);
9090
process.exit(1);
9191
});
9292
});
9393

9494
program
95-
.command("install [dir]")
96-
.description("install functions")
97-
.action(function(cmd, options) {
98-
console.log("netlify-lambda: installing function dependencies");
99-
install.run(cmd).catch(function(err) {
95+
.command('install [dir]')
96+
.description('install functions')
97+
.action(function (cmd) {
98+
console.log('netlify-lambda: installing function dependencies');
99+
install.run(cmd).catch(function (err) {
100100
console.error(err);
101101
process.exit(1);
102102
});
103103
});
104104

105105
// error on unknown commands
106106
// ref: https://github.com/tj/commander.js#custom-event-listeners
107-
program.on("command:*", function() {
107+
program.on('command:*', function () {
108108
console.error(
109-
"Invalid command: %s\nSee --help for a list of available commands.",
110-
program.args.join(" ")
109+
'Invalid command: %s\nSee --help for a list of available commands.',
110+
program.args.join(' '),
111111
);
112112
process.exit(1);
113113
});

commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

0 commit comments

Comments
 (0)