File tree Expand file tree Collapse file tree 10 files changed +68
-23
lines changed Expand file tree Collapse file tree 10 files changed +68
-23
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,10 @@ yarn.lock
2626.idea /.gitignore
2727! .husky /_ /husky.sh
2828
29- . /test /cid
30- . /test /lib
31- . /test /node_modules
29+ test /cid
30+ test /lib
31+ test /node_modules
32+ test /dist /
33+ test /test-bundled.js
3234
3335.DS_Store
Original file line number Diff line number Diff line change 22 * @type {import('jest').Config }
33 */
44const config = {
5+ extensionsToTreatAsEsm : [ '.ts' ] ,
56 transform : {
67 '^.+\\.(t|j)sx?$' : '@swc/jest' ,
78 } ,
8- transformIgnorePatterns : [ 'node_modules/(?!(is-video|@shelf/is-audio-filepath)/)' ] ,
9+ transformIgnorePatterns : [ 'node_modules/(?!(is-video|@shelf/is-audio-filepath|is-image )/)' ] ,
910 resetMocks : true ,
1011 coverageThreshold : {
1112 global : {
Original file line number Diff line number Diff line change 1515 "email" : " vlad@shelf.io" ,
1616 "url" : " https://shelf.io"
1717 },
18- "main" : " lib" ,
18+ "type" : " module" ,
19+ "main" : " lib/index.js" ,
1920 "types" : " lib/index.d.ts" ,
21+ "exports" : {
22+ "." : {
23+ "import" : " ./lib/index.js" ,
24+ "types" : " ./lib/index.d.ts"
25+ }
26+ },
2027 "files" : [
2128 " lib"
2229 ],
4047 },
4148 "prettier" : " @shelf/prettier-config" ,
4249 "dependencies" : {
43- "@shelf/is-audio-filepath" : " 2 .0.0 " ,
44- "del" : " 6 .0.0" ,
45- "is-image" : " 3.1 .0" ,
50+ "@shelf/is-audio-filepath" : " 3 .0.1 " ,
51+ "del" : " 8 .0.0" ,
52+ "is-image" : " 4.0 .0" ,
4653 "is-video" : " 2.0.0"
4754 },
4855 "devDependencies" : {
5259 "@swc/jest" : " 0.2.39" ,
5360 "@types/jest" : " 30.0.0" ,
5461 "@types/node" : " ^24.2.1" ,
62+ "esbuild" : " 0.25.9" ,
5563 "eslint" : " 9.33.0" ,
56- "husky" : " 8.0.3 " ,
64+ "husky" : " 9.1.7 " ,
5765 "jest" : " 30.0.5" ,
58- "lint-staged" : " 13.3.0 " ,
66+ "lint-staged" : " 16.1.5 " ,
5967 "prettier" : " 3.6.2" ,
6068 "typescript" : " 5.9.2"
6169 },
Original file line number Diff line number Diff line change 11import fs from 'fs/promises' ;
2- import del from 'del' ;
2+ import { deleteAsync } from 'del' ;
33
44// Removes temp files generated by LibreOffice
55export async function cleanupTempFiles ( ) : Promise < void > {
66 const files = await fs . readdir ( `/tmp` ) ;
77 for ( const file of files ) {
88 if ( file . endsWith ( '.tmp' ) === true || file . startsWith ( 'OSL_PIPE' ) ) {
99 try {
10- await del ( [ `/tmp/${ file } ` , `/tmp/${ file } /*` ] , { force : true } ) ;
10+ await deleteAsync ( [ `/tmp/${ file } ` , `/tmp/${ file } /*` ] , { force : true } ) ;
1111 } catch { }
1212 }
1313 }
Original file line number Diff line number Diff line change 11import childProcess from 'child_process' ;
22import util from 'util' ;
33import path from 'node:path' ;
4- import { cleanupTempFiles } from './cleanup' ;
5- import { getConvertedFilePath } from './logs' ;
4+ import { cleanupTempFiles } from './cleanup.js ' ;
5+ import { getConvertedFilePath } from './logs.js ' ;
66
77const exec = util . promisify ( childProcess . exec ) ;
88
Original file line number Diff line number Diff line change 1- export * from './convert' ;
2- export * from './validations' ;
1+ export * from './convert.js ' ;
2+ export * from './validations.js ' ;
Original file line number Diff line number Diff line change 1- FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.6-node18 -x86_64
1+ FROM public.ecr.aws/shelf/lambda-libreoffice-base:7.6-node20 -x86_64
22
3- COPY . ${LAMBDA_TASK_ROOT}/
3+ COPY test-bundled.js ${LAMBDA_TASK_ROOT}/test.js
44CMD [ "test.handler" ]
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env node
2+ import { existsSync , mkdirSync } from 'fs' ;
3+ import * as esbuild from 'esbuild' ;
4+
5+ if ( ! existsSync ( './dist' ) ) {
6+ mkdirSync ( './dist' ) ;
7+ }
8+
9+ await esbuild . build ( {
10+ entryPoints : [ './test.js' ] ,
11+ bundle : true ,
12+ outfile : './dist/test.js' ,
13+ platform : 'node' ,
14+ target : 'node20' ,
15+ format : 'cjs' ,
16+ external : [
17+ // Keep native modules external
18+ 'child_process' ,
19+ 'fs' ,
20+ 'fs/promises' ,
21+ 'path' ,
22+ 'util' ,
23+ 'node:path' ,
24+ ] ,
25+ logLevel : 'info' ,
26+ } ) ;
27+
28+ console . log ( 'Lambda handler built successfully to ./dist/test.js' ) ;
Original file line number Diff line number Diff line change 11import { writeFileSync } from 'fs' ;
2- import { convertTo } from './lib' ;
2+ import { convertTo } from './lib/index.js ' ;
33
44export const handler = async ( ) => {
55 writeFileSync ( '/tmp/test.txt' , Buffer . from ( 'Hello World!' ) ) ;
Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3+ # Build the ESM code to CommonJS for Lambda compatibility
4+ echo " Building Lambda handler with esbuild..."
35cp -r ../lib ./
4- cp -r ../node_modules ./
5- docker build -t lo-lambda-test .
6+ node build-for-lambda.js
7+
8+ # Copy the transpiled file to the root for the Dockerfile
9+ cp ./dist/test.js ./test-bundled.js
10+
11+ podman build --platform linux/amd64 -t lo-lambda-test .
612
713(sleep 7; curl -XPOST " http://localhost:9000/2015-03-31/functions/function/invocations" -d ' {"payload":"hello world!"}' ) &
8- (sleep 30; CID=$( cat ./cid) && docker stop $CID && rm ./cid) &
14+ (sleep 30; CID=$( cat ./cid) && podman stop $CID && rm ./cid) &
915
10- docker run -p 9000:8080 --rm --cidfile ./cid lo-lambda-test
16+ podman run --platform linux/amd64 -p 9000:8080 --rm --cidfile ./cid lo-lambda-test
You can’t perform that action at this time.
0 commit comments