Skip to content

Commit 421827a

Browse files
fix: support modern TypeScript module imports (#3)
1 parent 0b3156b commit 421827a

File tree

16 files changed

+300
-76
lines changed

16 files changed

+300
-76
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Release Canary
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [18.x, 20.x, 22.x]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- run: yarn install --frozen-lockfile
23+
- run: yarn build
24+
- run: yarn lint
25+
- run: yarn prettier:check
26+
- run: yarn test
27+
- run: node test/test-import.cjs
28+
29+
publish:
30+
runs-on: ubuntu-latest
31+
needs: test
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: 20.x
37+
registry-url: 'https://registry.npmjs.org'
38+
- run: yarn install --forzen-lockfile
39+
- run: yarn build
40+
- run: npx rollingversions publish --canary $GITHUB_RUN_NUMBER
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/rollingversions.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,20 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [10.x, 12.x, 14.x]
12+
node-version: [18.x, 20.x, 22.x]
1313

1414
steps:
1515
- uses: actions/checkout@v2
16-
with:
17-
path: 'repo'
1816
- name: Use Node.js ${{ matrix.node-version }}
1917
uses: actions/setup-node@v1
2018
with:
2119
node-version: ${{ matrix.node-version }}
22-
- run: cd repo && yarn install --forzen-lockfile
23-
- run: cd repo && yarn build
24-
- run: cd repo && yarn lint
25-
- run: cd repo && yarn prettier:check
26-
- run: cd repo && yarn test
27-
- run: cd repo && npm pack
28-
- run: cp -r repo/test test
29-
- run: cd test && npm i ../repo/then-retry-0.0.0.tgz
30-
- run: cd test && node index
20+
- run: yarn install --frozen-lockfile
21+
- run: yarn build
22+
- run: yarn lint
23+
- run: yarn prettier:check
24+
- run: yarn test
25+
- run: node test/test-import.cjs
3126

3227
publish:
3328
runs-on: ubuntu-latest
@@ -36,8 +31,11 @@ jobs:
3631
- uses: actions/checkout@v2
3732
- uses: actions/setup-node@v1
3833
with:
39-
node-version: 12.x
34+
node-version: 20.x
35+
registry-url: 'https://registry.npmjs.org'
4036
- run: yarn install --forzen-lockfile
4137
- run: yarn build
42-
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
43-
- run: npx rollingversions publish --github-token ${{ secrets.GITHUB_TOKEN }}
38+
- run: npx rollingversions publish
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,17 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [10.x, 12.x, 14.x]
17+
node-version: [18.x, 20.x, 22.x]
1818

1919
steps:
2020
- uses: actions/checkout@v2
21-
with:
22-
path: 'repo'
2321
- name: Use Node.js ${{ matrix.node-version }}
2422
uses: actions/setup-node@v1
2523
with:
2624
node-version: ${{ matrix.node-version }}
27-
- run: cd repo && yarn install --forzen-lockfile
28-
- run: cd repo && yarn build
29-
- run: cd repo && yarn lint
30-
- run: cd repo && yarn prettier:check
31-
- run: cd repo && yarn test
32-
- run: cd repo && npm pack
33-
- run: cp -r repo/test test
34-
- run: cd test && npm i ../repo/then-retry-0.0.0.tgz
35-
- run: cd test && node index
25+
- run: yarn install --frozen-lockfile
26+
- run: yarn build
27+
- run: yarn lint
28+
- run: yarn prettier:check
29+
- run: yarn test
30+
- run: node test/test-import.cjs

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@ dist
103103
# TernJS port file
104104
.tern-port
105105

106-
lib/
106+
lib/
107+
test-output/

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ yarn add then-retry
1313
## Usage
1414

1515
```js
16-
import retry, {withRetry} from 'then-retry';
16+
import retry, { withRetry } from "then-retry";
1717

1818
// to retry a one of operation
19-
await retry(() => someAsyncOp('hello world'));
19+
await retry(() => someAsyncOp("hello world"));
2020

2121
// to retry every call of a given function
2222
const someRetriedOp = withRetry(someAsyncOp);
23-
await someRetriedOp('hello world');
23+
await someRetriedOp("hello world");
2424
```
2525

2626
The following options can be passed as a second arg to either `retry` or `withRetry`:

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
"name": "then-retry",
33
"version": "0.0.0",
44
"description": "Retry a function that returns a promise",
5-
"main": "./lib/commonjs/index.js",
5+
"main": "./lib/commonjs/index.cjs",
66
"types": "./lib/es/index.d.ts",
7+
"type": "module",
78
"scripts": {
8-
"build": "tsc && (echo \";module.exports = exports.default;Object.assign(module.exports, exports);\" >> lib/commonjs/index.js) && tsc -p tsconfig.es.json && mv lib/es/index.js lib/es/index.mjs",
9+
"build": "yarn build:commonjs && yarn build:esm",
10+
"build:commonjs": "tsc && mv lib/commonjs/index.js lib/commonjs/index.cjs && (echo \";module.exports = exports.default;Object.assign(module.exports, exports);\" >> lib/commonjs/index.cjs)",
11+
"build:esm": "tsc -p tsconfig.es.json && mv lib/es/index.js lib/es/index.mjs",
912
"lint": "tslint './src/**/*.{ts,tsx}' -t verbose -p .",
1013
"prettier:write": "prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
1114
"prettier:check": "prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
12-
"test": "node test/local"
15+
"test": "node test/test.cjs && node test/test.mjs"
1316
},
1417
"files": [
15-
"lib/commonjs/index.js",
18+
"lib/commonjs/index.cjs",
1619
"lib/es/index.mjs",
1720
"lib/es/index.d.ts"
1821
],
1922
"exports": {
20-
".": [
21-
{
22-
"import": "./lib/es/index.mjs",
23-
"require": "./lib/commonjs/index.js",
24-
"default": "./lib/commonjs/index.js"
25-
},
26-
"./lib/commonjs/index.js"
27-
]
23+
".": {
24+
"types": "./lib/es/index.d.ts",
25+
"import": "./lib/es/index.mjs",
26+
"default": "./lib/commonjs/index.cjs"
27+
}
2828
},
2929
"repository": {
3030
"type": "git",
@@ -38,5 +38,6 @@
3838
"prettier": "^2.0.5",
3939
"tslint": "^6.1.2",
4040
"typescript": "^3.8.3"
41-
}
41+
},
42+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
4243
}

prettier.config.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async function retry<T>(
1717
{
1818
shouldRetry = defaultShouldRetry,
1919
retryDelay = defaultRetryDelay,
20-
}: Options = {},
20+
}: Options = {}
2121
): Promise<T> {
2222
let failedAttempts = 0;
2323
while (true) {
@@ -38,7 +38,7 @@ export default async function retry<T>(
3838

3939
export function withRetry<TArgs extends any[], TResult>(
4040
fn: (...args: TArgs) => Promise<TResult>,
41-
options: Options = {},
41+
options: Options = {}
4242
): (...args: TArgs) => Promise<TResult> {
4343
return async (...args) => {
4444
return retry(() => fn(...args), options);

test/commonjs.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/esm.mjs

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)