Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to esbuild, upgrade is-image package #287

Merged
merged 4 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ lib/
*.log
.DS_Store
yarn.lock
test.js
!.husky/_/husky.sh
7 changes: 7 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('esbuild').buildSync({
entryPoints: ['src/index.ts'],
bundle: true,
platform: 'node',
outfile: 'lib/index.js',
});
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ES_PACKAGES_TO_TRANSFORM = ['is-image'];

/** @type {import("jest").Config} */
const config = {
transform: {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
parser: {
syntax: 'typescript',
},
},
},
],
},
transformIgnorePatterns: [
`node_modules/(?!(${ES_PACKAGES_TO_TRANSFORM.join('|')}))/node_modules/.+\\.js`,
],
};

module.exports = config;
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shelf/aws-lambda-tesseract",
"version": "5.0.0",
"version": "5.1.0",
"description": "6 MB Tesseract 4.1 (with English training data) to fit inside AWS Lambda",
"keywords": [
"aws",
Expand All @@ -22,7 +22,7 @@
"bin/tt.tar.gz"
],
"scripts": {
"build": "rm -rf lib/ && yarn build:types && babel src --out-dir lib --ignore '**/*.test.ts' --extensions '.ts'",
"build": "rm -rf lib/ && yarn build:types && node esbuild.js",
"build:types": "tsc --emitDeclarationOnly --declaration --isolatedModules false --declarationDir lib",
"coverage": "jest --coverage",
"lint": "yarn lint:ci --fix",
Expand All @@ -40,25 +40,20 @@
"eslint --fix"
]
},
"babel": {
"extends": "@shelf/babel-config/backend"
},
"prettier": "@shelf/prettier-config",
"dependencies": {
"is-image": "3.1.0",
"is-image": "4.0.0",
"tar": "6.2.0"
},
"devDependencies": {
"@babel/cli": "7.23.0",
"@babel/core": "7.23.2",
"@babel/preset-env": "7.23.2",
"@babel/preset-typescript": "7.22.15",
"@shelf/babel-config": "2.0.2",
"@shelf/eslint-config": "3.10.0",
"@shelf/prettier-config": "1.0.0",
"@swc/core": "1.3.96",
"@swc/jest": "0.2.29",
"@types/jest": "29.5.8",
"@types/node": "18",
"@types/tar": "6.1.7",
"esbuild": "0.19.5",
"eslint": "8.48.0",
"husky": "8.0.3",
"jest": "29.7.0",
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const {execSync} = require('child_process');
const {getTextFromImage} = require('./lib/index.js');

module.exports = {
handler() {
execSync(`cp ./test.png /tmp/test.png`);

return getTextFromImage('/tmp/test.png');
}
}
2 changes: 0 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ cd bin
tar -xvzf tt.tar.gz
cd ..

yarn babel test.ts --out-file test.js

(sleep 5; curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}') &


Expand Down
9 changes: 0 additions & 9 deletions test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"target": "esnext"
},
"exclude": ["node_modules"],
"include": ["src", "test.ts"]
"include": ["src/index.ts"]
}