Skip to content

Commit 4c315e2

Browse files
committed
feat: switch to typescript
1 parent 0564eaf commit 4c315e2

File tree

9 files changed

+92
-95
lines changed

9 files changed

+92
-95
lines changed

.circleci/config.yml

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
version: 2.1
2+
13
orbs:
24
node: circleci/[email protected]
35

6+
parameters:
7+
node_version:
8+
type: string
9+
default: '14'
10+
411
commands:
512
install_deps:
613
steps:
@@ -10,49 +17,17 @@ commands:
1017
dir: ~/repo/node_modules
1118
use-strict-cache: true
1219
steps:
13-
- run: yarn install --pure-lockfile --ignore-scripts --no-progress
14-
15-
version: 2.1
20+
- run: yarn install --pure-lockfile --no-progress
1621

1722
jobs:
18-
tests_10:
19-
executor:
20-
name: node/default
21-
tag: '10'
22-
working_directory: ~/repo
23-
environment:
24-
- JEST_JUNIT_OUTPUT_DIR: './test-results/jest'
25-
- JEST_JUNIT_OUTPUT_NAME: 'results.xml'
26-
steps:
27-
- checkout
28-
- install_deps
29-
30-
- run: yarn test:internal
31-
32-
- store_test_results:
33-
path: test-results
34-
tests_12:
23+
build:
3524
executor:
3625
name: node/default
37-
tag: '12'
26+
tag: << pipeline.parameters.node_version >>
3827
working_directory: ~/repo
39-
environment:
40-
- JEST_JUNIT_OUTPUT_DIR: './test-results/jest'
41-
- JEST_JUNIT_OUTPUT_NAME: 'results.xml'
4228
steps:
4329
- checkout
4430
- install_deps
45-
46-
- run: yarn test:internal
47-
48-
- store_test_results:
49-
path: test-results
50-
51-
workflows:
52-
version: 2
53-
54-
run_tests:
55-
jobs:
56-
- tests_10
57-
58-
- tests_12
31+
- run: yarn test
32+
- run: yarn type-check
33+
- run: yarn lint:ci

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
coverage/
2+
lib/
3+
renovate.json
4+
tsconfig.json

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
33
"extends": [
4-
"@shelf/eslint-config/backend"
4+
"@shelf/eslint-config/typescript"
55
]
66
}

.prettierignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.prettierrc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,68 @@
22
"name": "@shelf/aws-lambda-brotli-unpacker",
33
"version": "1.0.1",
44
"description": "Unpacks large Lambda binaries to /tmp",
5-
"license": "MIT",
5+
"keywords": [
6+
"lambda",
7+
"brotli"
8+
],
69
"repository": "shelfio/aws-lambda-brotli-unpacker",
10+
"license": "MIT",
711
"author": {
812
"name": "Vlad Holubiev",
913
"email": "[email protected]",
1014
"url": "shelf.io"
1115
},
12-
"engines": {
13-
"node": ">=10.16.0"
14-
},
16+
"main": "lib",
17+
"files": [
18+
"lib"
19+
],
1520
"scripts": {
16-
"lint": "eslint . --fix",
21+
"build": "rm -rf lib/ && yarn build:types && yarn build:code",
22+
"build:code": "babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts' && find ./lib -name '*.test.d.ts' -delete",
23+
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
24+
"coverage": "yarn test --coverage",
25+
"lint": "yarn lint:ci --fix",
26+
"lint:ci": "eslint . --ext .js,.ts,.json",
27+
"prepack": "yarn build",
28+
"test": "bin/test",
1729
"test:internal": "rm -rf .test && mkdir .test && jest",
18-
"test": "bin/test"
30+
"type-check": "tsc --noEmit",
31+
"type-check:watch": "npm run type-check -- --watch"
1932
},
20-
"files": [
21-
"src"
22-
],
23-
"main": "src/index.js",
24-
"keywords": [
25-
"lambda",
26-
"brotli"
27-
],
33+
"lint-staged": {
34+
"*.{html,md,yml}": [
35+
"prettier --write"
36+
],
37+
"*.{js,ts,json}": [
38+
"eslint --fix"
39+
]
40+
},
41+
"babel": {
42+
"extends": "@shelf/babel-config/backend"
43+
},
44+
"prettier": "@shelf/prettier-config",
2845
"dependencies": {
29-
"tar-fs": "2.1.0"
46+
"tar-fs": "2.1.1"
3047
},
3148
"devDependencies": {
32-
"@shelf/eslint-config": "0.19.0",
33-
"eslint": "7.6.0",
49+
"@babel/cli": "7.17.6",
50+
"@babel/core": "7.17.5",
51+
"@shelf/babel-config": "0.1.8",
52+
"@shelf/eslint-config": "2.13.0",
53+
"@shelf/prettier-config": "1.0.0",
54+
"@shelf/tsconfig": "0.0.6",
55+
"@types/jest": "27.4.0",
56+
"@types/node": "14",
57+
"@types/tar-fs": "2.0.1",
58+
"eslint": "8.9.0",
3459
"husky": "7.0.4",
35-
"jest": "26.2.2",
36-
"lint-staged": "10.2.11",
37-
"prettier": "2.0.5"
60+
"jest": "27.5.1",
61+
"lint-staged": "12.3.4",
62+
"prettier": "2.5.1",
63+
"typescript": "4.5.5"
3864
},
39-
"lint-staged": {
40-
"*.js": [
41-
"eslint --fix",
42-
"git add"
43-
],
44-
"*.{html,json,md,yml}": [
45-
"prettier --write",
46-
"git add"
47-
]
65+
"engines": {
66+
"node": ">=14"
4867
},
4968
"publishConfig": {
5069
"access": "public"

src/index.test.js renamed to src/index.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
const fs = require('fs');
2-
3-
const index = require('./index');
1+
import fs from 'fs';
2+
import {unpack} from './index';
43

54
const outputBaseDir = './.test';
65
const testPackageDir = './etc/test/packages';
76

87
it('should unpack test-extract.tar.br package only once', async () => {
98
const inputPath = `${testPackageDir}/test-extract.tar.br`;
109
const outputPath = `${outputBaseDir}/test-extract/test-file.txt`;
11-
await index.unpack({inputPath, outputBaseDir, outputPath});
10+
await unpack({inputPath, outputBaseDir, outputPath});
1211

1312
const expectedOutputPath = `${outputBaseDir}/test-extract/test-file.txt`;
1413

1514
expect(fs.existsSync(expectedOutputPath)).toBe(true);
1615
expect(fs.readFileSync(expectedOutputPath, {encoding: 'utf-8'})).toBe('success\n');
1716

1817
// Try again with the same output binary but a bogus package. It should ignore the package
19-
await index.unpack({
18+
await unpack({
2019
inputPath: `${outputBaseDir}/does-not-exist`,
2120
outputBaseDir,
22-
outputPath
21+
outputPath,
2322
});
2423

2524
expect(fs.existsSync(expectedOutputPath)).toBe(true);
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
const fs = require('fs');
2-
const path = require('path');
3-
const tar = require('tar-fs');
4-
const zlib = require('zlib');
1+
import fs from 'fs';
2+
import path from 'path';
3+
import tar from 'tar-fs';
4+
import zlib from 'zlib';
5+
6+
type UnpackParams = {inputPath: string; outputBaseDir: string; outputPath: string};
57

68
/**
79
* Unpacks brotli archive of a .tar file to /tmp folder
@@ -10,27 +12,23 @@ const zlib = require('zlib');
1012
* @return {Promise<String>} Path to unpacked binary, equals to outputBin
1113
* @see https://github.com/alixaxel/chrome-aws-lambda
1214
*/
13-
module.exports.unpack = function({inputPath, outputBaseDir, outputPath}) {
15+
export function unpack({inputPath, outputBaseDir, outputPath}: UnpackParams) {
1416
outputBaseDir = outputBaseDir || '/tmp';
1517

1618
return new Promise((resolve, reject) => {
17-
let input = path.resolve(inputPath);
18-
let output = outputPath;
19+
const input = path.resolve(inputPath);
20+
const output = outputPath;
1921

20-
if (fs.existsSync(output) === true) {
22+
if (fs.existsSync(output)) {
2123
return resolve(output);
2224
}
2325

2426
const source = fs.createReadStream(input);
2527
const target = tar.extract(outputBaseDir);
2628

27-
source.on('error', error => {
28-
return reject(error);
29-
});
29+
source.on('error', error => reject(error));
3030

31-
target.on('error', error => {
32-
return reject(error);
33-
});
31+
target.on('error', error => reject(error));
3432

3533
target.on('finish', () => {
3634
fs.chmod(output, '0755', error => {
@@ -44,4 +42,4 @@ module.exports.unpack = function({inputPath, outputBaseDir, outputPath}) {
4442

4543
source.pipe(zlib.createBrotliDecompress()).pipe(target);
4644
});
47-
};
45+
}

tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "@shelf/tsconfig/backend",
3+
"compilerOptions": {
4+
"strict": true
5+
},
6+
"exclude": ["node_modules"],
7+
"include": ["src"]
8+
}

0 commit comments

Comments
 (0)