Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support modern TypeScript module imports #3

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/rollingversions-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release Canary

on:
push:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn lint
- run: yarn prettier:check
- run: yarn test
- run: node test/test-import.cjs

publish:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- run: yarn install --forzen-lockfile
- run: yarn build
- run: npx rollingversions publish --canary $GITHUB_RUN_NUMBER
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
28 changes: 13 additions & 15 deletions .github/workflows/rollingversions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,20 @@ jobs:

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

steps:
- uses: actions/checkout@v2
with:
path: 'repo'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: cd repo && yarn install --forzen-lockfile
- run: cd repo && yarn build
- run: cd repo && yarn lint
- run: cd repo && yarn prettier:check
- run: cd repo && yarn test
- run: cd repo && npm pack
- run: cp -r repo/test test
- run: cd test && npm i ../repo/then-retry-0.0.0.tgz
- run: cd test && node index
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn lint
- run: yarn prettier:check
- run: yarn test
- run: node test/test-import.cjs

publish:
runs-on: ubuntu-latest
Expand All @@ -36,8 +31,11 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- run: yarn install --forzen-lockfile
- run: yarn build
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- run: npx rollingversions publish --github-token ${{ secrets.GITHUB_TOKEN }}
- run: npx rollingversions publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
19 changes: 7 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@ jobs:

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

steps:
- uses: actions/checkout@v2
with:
path: 'repo'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: cd repo && yarn install --forzen-lockfile
- run: cd repo && yarn build
- run: cd repo && yarn lint
- run: cd repo && yarn prettier:check
- run: cd repo && yarn test
- run: cd repo && npm pack
- run: cp -r repo/test test
- run: cd test && npm i ../repo/then-retry-0.0.0.tgz
- run: cd test && node index
- run: yarn install --frozen-lockfile
- run: yarn build
- run: yarn lint
- run: yarn prettier:check
- run: yarn test
- run: node test/test-import.cjs
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ dist
# TernJS port file
.tern-port

lib/
lib/
test-output/
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ yarn add then-retry
## Usage

```js
import retry, {withRetry} from 'then-retry';
import retry, { withRetry } from "then-retry";

// to retry a one of operation
await retry(() => someAsyncOp('hello world'));
await retry(() => someAsyncOp("hello world"));

// to retry every call of a given function
const someRetriedOp = withRetry(someAsyncOp);
await someRetriedOp('hello world');
await someRetriedOp("hello world");
```

The following options can be passed as a second arg to either `retry` or `withRetry`:
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
"name": "then-retry",
"version": "0.0.0",
"description": "Retry a function that returns a promise",
"main": "./lib/commonjs/index.js",
"main": "./lib/commonjs/index.cjs",
"types": "./lib/es/index.d.ts",
"type": "module",
"scripts": {
"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",
"build": "yarn build:commonjs && yarn build:esm",
"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)",
"build:esm": "tsc -p tsconfig.es.json && mv lib/es/index.js lib/es/index.mjs",
"lint": "tslint './src/**/*.{ts,tsx}' -t verbose -p .",
"prettier:write": "prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
"prettier:check": "prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
"test": "node test/local"
"test": "node test/test.cjs && node test/test.mjs"
},
"files": [
"lib/commonjs/index.js",
"lib/commonjs/index.cjs",
"lib/es/index.mjs",
"lib/es/index.d.ts"
],
"exports": {
".": [
{
"import": "./lib/es/index.mjs",
"require": "./lib/commonjs/index.js",
"default": "./lib/commonjs/index.js"
},
"./lib/commonjs/index.js"
]
".": {
"types": "./lib/es/index.d.ts",
"import": "./lib/es/index.mjs",
"default": "./lib/commonjs/index.cjs"
}
},
"repository": {
"type": "git",
Expand All @@ -38,5 +38,6 @@
"prettier": "^2.0.5",
"tslint": "^6.1.2",
"typescript": "^3.8.3"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
1 change: 0 additions & 1 deletion prettier.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function retry<T>(
{
shouldRetry = defaultShouldRetry,
retryDelay = defaultRetryDelay,
}: Options = {},
}: Options = {}
): Promise<T> {
let failedAttempts = 0;
while (true) {
Expand All @@ -38,7 +38,7 @@ export default async function retry<T>(

export function withRetry<TArgs extends any[], TResult>(
fn: (...args: TArgs) => Promise<TResult>,
options: Options = {},
options: Options = {}
): (...args: TArgs) => Promise<TResult> {
return async (...args) => {
return retry(() => fn(...args), options);
Expand Down
1 change: 0 additions & 1 deletion test/commonjs.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/esm.mjs

This file was deleted.

14 changes: 0 additions & 14 deletions test/index.js

This file was deleted.

1 change: 0 additions & 1 deletion test/local.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/run.js

This file was deleted.

Loading
Loading