Skip to content

Commit 67914eb

Browse files
authored
feat: dual module export (dynamodb-toolbox#607)
1 parent d0bb431 commit 67914eb

File tree

68 files changed

+228
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+228
-178
lines changed

jest.config.js renamed to jest.config.cjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ module.exports = {
33
testMatch: ['**/?(*.)+(unit.test).+(ts|tsx|js)'],
44
testPathIgnorePatterns: ['/__tests__/entities/*', '/__tests__/tables/*'],
55
coveragePathIgnorePatterns: ['/__tests__/*'],
6+
extensionsToTreatAsEsm: ['.ts'],
7+
moduleNameMapper: {
8+
'^(\\.{1,2}/.*)\\.js$': '$1',
9+
},
610
transform: {
7-
'^.+\\.(ts|tsx)$': 'ts-jest'
8-
}
11+
'^.+\\.[tj]sx?$': [
12+
'ts-jest',
13+
{
14+
useESM: true,
15+
},
16+
],
17+
},
918
}

package.json

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,32 @@
22
"name": "dynamodb-toolbox",
33
"description": "A simple set of tools for working with Amazon DynamoDB and the DocumentClient.",
44
"author": "Jeremy Daly <jeremy@jeremydaly.com>",
5-
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
5+
"main": "dist/cjs/index.js",
6+
"types": "dist/cjs/index.d.ts",
7+
"exports": {
8+
".": {
9+
"import": {
10+
"default": "./dist/esm/index.js",
11+
"types": "./dist/esm/index.d.ts"
12+
},
13+
"require": {
14+
"default": "./dist/cjs/index.js",
15+
"types": "./dist/cjs/index.d.ts"
16+
}
17+
}
18+
},
19+
"type": "module",
720
"scripts": {
821
"test": "jest unit",
922
"test-cov": "jest unit --coverage",
1023
"test-ci": "eslint . && jest unit --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
1124
"test-types": "tsd",
1225
"check-types": "tsc --noEmit",
1326
"lint": "eslint .",
14-
"build": "rm -rf dist && tsc -p tsconfig.build.json",
27+
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{ \"type\": \"commonjs\" }' > dist/cjs/package.json",
28+
"build:esm": "tsc -p tsconfig.esm.json && echo '{ \"type\": \"module\" }' > dist/esm/package.json",
29+
"build": "npm run build:cjs & npm run build:esm",
30+
"prebuild": "rm -rf dist",
1531
"prepublishOnly": "npm test && npm run lint && npm run test-types",
1632
"changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline"
1733
},
@@ -62,9 +78,13 @@
6278
"typescript": "^4.1.3"
6379
},
6480
"files": [
65-
"dist/index.*",
66-
"dist/constants.*",
67-
"dist/classes/",
68-
"dist/lib/"
81+
"dist/cjs/index.*",
82+
"dist/cjs/constants.*",
83+
"dist/cjs/classes/",
84+
"dist/cjs/lib/",
85+
"dist/esm/index.*",
86+
"dist/esm/constants.*",
87+
"dist/esm/classes/",
88+
"dist/esm/lib/"
6989
]
7090
}

src/__tests__/checkAttribute.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import checkAttribute from '../lib/checkAttribute'
1+
import checkAttribute from '../lib/checkAttribute.js'
22

33
// Require Table and Entity classes
4-
import Table from '../classes/Table'
5-
import Entity from '../classes/Entity'
4+
import Table from '../classes/Table/Table.js'
5+
import Entity from '../classes/Entity/Entity.js'
66

77
// Create basic table
88
const DefaultTable = new Table({

src/__tests__/entity-creation.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Table from '../classes/Table'
2-
import Entity from '../classes/Entity'
3-
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test'
1+
import Table from '../classes/Table/Table.js'
2+
import Entity from '../classes/Entity/Entity.js'
3+
import { DocumentClient, DocumentClientWithWrappedNumbers } from './bootstrap.test.js'
44

55
const tableAddEntity = jest.spyOn(Table.prototype, 'addEntity').mockReturnValue()
66

src/__tests__/entity-properties.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Table from '../classes/Table'
2-
import Entity from '../classes/Entity'
1+
import Table from '../classes/Table/Table.js'
2+
import Entity from '../classes/Entity/Entity.js'
33

44
describe('Entity properties', () => {
55
describe('table', () => {

src/__tests__/entity.delete.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Entity, Table } from '..'
2-
import { DocumentClient } from './bootstrap.test'
1+
import { Entity, Table } from '../index.js'
2+
import { DocumentClient } from './bootstrap.test.js'
33

44
const TestTable = new Table({
55
name: 'test-table',

src/__tests__/entity.get.int.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-nocheck
2-
import { Table, Entity } from '../index'
3-
import { DocumentClient } from './bootstrap.test'
2+
import { Table, Entity } from '../index.js'
3+
import { DocumentClient } from './bootstrap.test.js'
44

55
const TestTable = new Table({
66
name: 'test-table',

src/__tests__/entity.get.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Table, Entity } from '..'
2-
import { DocumentClient } from './bootstrap.test'
1+
import { Table, Entity } from '../index.js'
2+
import { DocumentClient } from './bootstrap.test.js'
33

44
const TestTable = new Table({
55
name: 'test-table',

src/__tests__/entity.parse.unit.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { DocumentClientWithWrappedNumbers } from './bootstrap.test'
1+
import { DocumentClientWithWrappedNumbers } from './bootstrap.test.js'
22

3-
import Table from '../classes/Table'
4-
import Entity from '../classes/Entity'
3+
import Table from '../classes/Table/Table.js'
4+
import Entity from '../classes/Entity/Entity.js'
55
import { unmarshall } from '@aws-sdk/util-dynamodb'
66

77
const TestTable = new Table({

src/__tests__/entity.put.unit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Table, Entity } from '../index'
2-
import { DocumentClient } from './bootstrap.test'
1+
import { Table, Entity } from '../index.js'
2+
import { DocumentClient } from './bootstrap.test.js'
33
import assert from 'assert'
44

55
const TestTable = new Table({

0 commit comments

Comments
 (0)