Skip to content

Commit aec327b

Browse files
authored
feat(batch): add esmodule support (#1737)
1 parent d9a62ea commit aec327b

21 files changed

+230
-86
lines changed

packages/batch/jest.config.js renamed to packages/batch/jest.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module.exports = {
55
},
66
runner: 'groups',
77
preset: 'ts-jest',
8+
moduleNameMapper: {
9+
'^(\\.{1,2}/.*)\\.js$': '$1',
10+
},
811
transform: {
912
'^.+\\.ts?$': 'ts-jest',
1013
},

packages/batch/package.json

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,46 @@
1616
"test:e2e:nodejs18x": "echo 'Not Implemented'",
1717
"test:e2e": "echo 'Not Implemented'",
1818
"watch": "jest --watch",
19-
"build": "tsc --build --force",
19+
"build:cjs": "tsc --build --force && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
20+
"build:esm": "tsc --project tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
21+
"build": "npm run build:esm & npm run build:cjs",
2022
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
2123
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
2224
"prebuild": "rimraf ./lib",
23-
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
25+
"prepack": "rimraf ./lib/*.tsbuildinfo && node ../../.github/scripts/release_patch_package_json.js ."
2426
},
2527
"lint-staged": {
2628
"*.{js,ts}": "npm run lint-fix"
2729
},
2830
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/batch#readme",
2931
"license": "MIT-0",
30-
"main": "./lib/index.js",
31-
"types": "./lib/index.d.ts",
32+
"type": "module",
33+
"exports": {
34+
".": {
35+
"require": {
36+
"types": "./lib/cjs/index.d.ts",
37+
"default": "./lib/cjs/index.js"
38+
},
39+
"import": {
40+
"types": "./lib/esm/index.d.ts",
41+
"default": "./lib/esm/index.js"
42+
}
43+
},
44+
"./types": {
45+
"import": "./lib/esm/types.js",
46+
"require": "./lib/cjs/types.js"
47+
}
48+
},
49+
"typesVersions": {
50+
"*": {
51+
"types": [
52+
"lib/cjs/types.d.ts",
53+
"lib/esm/types.d.ts"
54+
]
55+
}
56+
},
57+
"types": "./lib/cjs/index.d.ts",
58+
"main": "./lib/cjs/index.js",
3259
"files": [
3360
"lib"
3461
],

packages/batch/src/BasePartialBatchProcessor.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import type {
33
KinesisStreamRecord,
44
SQSRecord,
55
} from 'aws-lambda';
6-
import { BasePartialProcessor } from './BasePartialProcessor';
7-
import { DATA_CLASS_MAPPING, DEFAULT_RESPONSE, EventType } from './constants';
8-
import { FullBatchFailureError } from './errors';
6+
import { BasePartialProcessor } from './BasePartialProcessor.js';
7+
import {
8+
DATA_CLASS_MAPPING,
9+
DEFAULT_RESPONSE,
10+
EventType,
11+
} from './constants.js';
12+
import { FullBatchFailureError } from './errors.js';
913
import type {
1014
EventSourceDataClassTypes,
1115
PartialItemFailureResponse,
1216
PartialItemFailures,
13-
} from './types';
17+
} from './types.js';
1418

1519
/**
1620
* Process batch and partially report failed items

packages/batch/src/BasePartialProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
FailureResponse,
66
ResultType,
77
SuccessResponse,
8-
} from './types';
8+
} from './types.js';
99

1010
/**
1111
* Abstract class for batch processors.

packages/batch/src/BatchProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor';
2-
import { BatchProcessingError } from './errors';
3-
import type { BaseRecord, FailureResponse, SuccessResponse } from './types';
1+
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
2+
import { BatchProcessingError } from './errors.js';
3+
import type { BaseRecord, FailureResponse, SuccessResponse } from './types.js';
44

55
/**
66
* Process native partial responses from SQS, Kinesis Data Streams, and DynamoDB

packages/batch/src/BatchProcessorSync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor';
2-
import { BatchProcessingError } from './errors';
3-
import type { BaseRecord, FailureResponse, SuccessResponse } from './types';
1+
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
2+
import { BatchProcessingError } from './errors.js';
3+
import type { BaseRecord, FailureResponse, SuccessResponse } from './types.js';
44

55
/**
66
* Process native partial responses from SQS, Kinesis Data Streams, and DynamoDB

packages/batch/src/SqsFifoPartialProcessor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { BatchProcessorSync } from './BatchProcessorSync';
2-
import { EventType } from './constants';
3-
import { SqsFifoShortCircuitError } from './errors';
4-
import type { FailureResponse, SuccessResponse } from './types';
1+
import { BatchProcessorSync } from './BatchProcessorSync.js';
2+
import { EventType } from './constants.js';
3+
import { SqsFifoShortCircuitError } from './errors.js';
4+
import type { FailureResponse, SuccessResponse } from './types.js';
55

66
/**
77
* Process native partial responses from SQS FIFO queues

packages/batch/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
import type {
77
PartialItemFailureResponse,
88
EventSourceDataClassTypes,
9-
} from './types';
9+
} from './types.js';
1010

1111
const EventType = {
1212
SQS: 'SQS',

packages/batch/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventType } from './constants';
1+
import { EventType } from './constants.js';
22

33
/**
44
* Base error thrown by the Batch Processing utility

packages/batch/src/index.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
export * from './constants';
2-
export * from './errors';
3-
export * from './types';
4-
export * from './BasePartialProcessor';
5-
export * from './BasePartialBatchProcessor';
6-
export * from './BatchProcessorSync';
7-
export * from './BatchProcessor';
8-
export * from './processPartialResponseSync';
9-
export * from './processPartialResponse';
10-
export * from './SqsFifoPartialProcessor';
1+
export { EventType } from './constants.js';
2+
export {
3+
BatchProcessingError,
4+
FullBatchFailureError,
5+
SqsFifoShortCircuitError,
6+
UnexpectedBatchTypeError,
7+
} from './errors.js';
8+
export { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
9+
export { BatchProcessorSync } from './BatchProcessorSync.js';
10+
export { BatchProcessor } from './BatchProcessor.js';
11+
export { processPartialResponseSync } from './processPartialResponseSync.js';
12+
export { processPartialResponse } from './processPartialResponse.js';
13+
export { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js';

0 commit comments

Comments
 (0)