Skip to content

Commit 1659f3f

Browse files
committedNov 30, 2022
chore: support both es-module and commonjs
1 parent e31fa6f commit 1659f3f

12 files changed

+2328
-6323
lines changed
 

‎.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
node-version:
15-
- '18'
15+
- "18"
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v3
@@ -21,4 +21,4 @@ jobs:
2121
with:
2222
node-version: ${{ matrix.node-version }}
2323
- run: npm ci
24-
- run: npm test
24+
- run: npm test run

‎.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
node-version: 18
1818
registry-url: "https://registry.npmjs.org"
1919
- run: npm ci
20-
- run: npm test
20+
- run: npm test run
2121
- run: npm publish
2222
env:
2323
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ node_modules/
88

99
lib/*.js
1010
test/*.js
11+
12+
dist

‎index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { AthenaQuery } from "./lib/athena-query";
2+
3+
export default AthenaQuery;

‎jest.config.js

-192
This file was deleted.

‎lib/helper.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { setTimeout } from "node:timers/promises";
21
import {
32
Athena,
43
Datum,
@@ -16,9 +15,9 @@ async function startQueryExecution(params: {
1615
const output = await params.athena.startQueryExecution({
1716
QueryString: params.sql,
1817
ExecutionParameters: params.executionParameters,
19-
WorkGroup: params.workgroup,
18+
WorkGroup: params.workgroup || "primary",
2019
QueryExecutionContext: {
21-
Database: params.db,
20+
Database: params.db || "default",
2221
Catalog: params.catalog,
2322
},
2423
});
@@ -46,7 +45,7 @@ async function waitExecutionCompleted(params: {
4645
} else if (state === "FAILED") {
4746
throw new Error(reason);
4847
} else {
49-
await setTimeout(200);
48+
await wait(200);
5049
await waitExecutionCompleted(params);
5150
}
5251
}
@@ -147,4 +146,6 @@ async function getDataTypes(
147146
return columnInfoObject;
148147
}
149148

149+
const wait = (ms: number) => new Promise((res) => setTimeout(res, ms));
150+
150151
export { startQueryExecution, waitExecutionCompleted, getQueryResults };

‎lib/index.ts

-3
This file was deleted.

‎package-lock.json

+2,281-6,108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "@classmethod/athena-query",
33
"version": "0.2.1",
44
"description": "Athena-Query makes it easier to execute SQL queries on Amazon Athena by consolidating & abstracting several methods in the AWS SDK",
5-
"main": "./lib/index.js",
6-
"types": "./lib/index.ts",
5+
"main": "./dist/index.cjs.js",
6+
"module": "./dist/index.esm.mjs",
7+
"types": "./dist/index.d.ts",
78
"author": "Classmethod, Inc.",
89
"license": "MIT",
910
"repository": {
@@ -27,18 +28,19 @@
2728
"lib"
2829
],
2930
"scripts": {
30-
"build": "tsc",
31-
"pretest": "npm run build",
32-
"test": "jest"
31+
"build": "rm -rf dist && rollup -c",
32+
"test": "vitest"
3333
},
3434
"devDependencies": {
3535
"@aws-sdk/client-athena": "^3.218.0",
36-
"@types/jest": "^29.2.3",
36+
"@rollup/plugin-commonjs": "^23.0.3",
3737
"@types/node": "^18.11.9",
3838
"aws-sdk-client-mock": "^2.0.1",
39-
"jest": "^29.3.1",
4039
"prettier": "^2.8.0",
41-
"typescript": "^4.9.3"
40+
"rollup": "^3.5.0",
41+
"rollup-plugin-typescript2": "^0.34.1",
42+
"typescript": "^4.9.3",
43+
"vitest": "^0.25.3"
4244
},
4345
"peerDependencies": {
4446
"@aws-sdk/client-athena": "^3.218.0"

‎rollup.config.mjs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import commonjs from "@rollup/plugin-commonjs";
2+
import typescript from "rollup-plugin-typescript2";
3+
4+
export default {
5+
input: "index.ts",
6+
output: [
7+
{
8+
file: "dist/index.esm.mjs",
9+
},
10+
{
11+
file: "dist/index.cjs.js",
12+
format: "cjs",
13+
exports: "default",
14+
},
15+
],
16+
plugins: [typescript({ exclude: ["test/**"] }), commonjs()],
17+
};

‎test/index.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { beforeEach, test, expect } from "vitest";
12
import {
23
Athena,
34
AthenaClient,

‎tsconfig.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"exclude": ["dist", "examples"],
23
"compilerOptions": {
34
/* Visit https://aka.ms/tsconfig to read more about this file */
45

@@ -25,9 +26,9 @@
2526
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2627

2728
/* Modules */
28-
"module": "commonjs" /* Specify what module code is generated. */,
29+
"module": "esnext" /* Specify what module code is generated. */,
2930
// "rootDir": "./", /* Specify the root folder within your source files. */
30-
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31+
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
3132
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3233
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3334
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -44,12 +45,12 @@
4445
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
4546

4647
/* Emit */
47-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48+
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
4849
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
4950
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
5051
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5152
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
52-
// "outDir": "./", /* Specify an output folder for all emitted files. */
53+
"outDir": "dist" /* Specify an output folder for all emitted files. */,
5354
// "removeComments": true, /* Disable emitting comments. */
5455
// "noEmit": true, /* Disable emitting files from a compilation. */
5556
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@@ -65,7 +66,7 @@
6566
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
6667
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
6768
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69+
// "declarationDir": "." /* Specify the output directory for generated declaration files. */,
6970
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7071

7172
/* Interop Constraints */

0 commit comments

Comments
 (0)
Please sign in to comment.