Skip to content

Commit 1f19786

Browse files
committed
feat: package is now ESM
BREAKING CHANGE: package is now ESM
1 parent c6cc5fd commit 1f19786

19 files changed

+106
-100
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ Node
3030
Install with `npm install @octokit/core @octokit/plugin-paginate-graphql`. Optionally replace `@octokit/core` with a core-compatible module
3131

3232
```js
33-
const { Octokit } = require("@octokit/core");
34-
const { paginateGraphQL } = require("@octokit/plugin-paginate-graphql");
33+
import { Octokit } from "@octokit/core";
34+
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
3535
```
3636

3737
</td></tr>

package-lock.json

Lines changed: 48 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"publishConfig": {
44
"access": "public"
55
},
6+
"type": "module",
67
"version": "0.0.0-development",
78
"description": "Octokit plugin to paginate GraphQL API endpoint responses",
8-
"main": "index.js",
99
"scripts": {
1010
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1111
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1212
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
1313
"pretest": "npm run -s lint",
14-
"test": "jest --coverage",
14+
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
1515
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict test/typescript-validate.ts",
16-
"test:watch": "jest --watch",
17-
"test:e2e": "jest --testRegex test/*.e2e.ts"
16+
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch",
17+
"test:e2e": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --testRegex test/*.e2e.ts"
1818
},
1919
"repository": "github:octokit/plugin-paginate-graphql.js",
2020
"keywords": [
@@ -25,12 +25,12 @@
2525
],
2626
"license": "MIT",
2727
"peerDependencies": {
28-
"@octokit/core": ">=5"
28+
"@octokit/core": ">=6"
2929
},
3030
"devDependencies": {
31-
"@octokit/core": "^5.0.0",
32-
"@octokit/plugin-rest-endpoint-methods": "^10.0.0",
33-
"@octokit/tsconfig": "^2.0.0",
31+
"@octokit/core": "^6.0.0",
32+
"@octokit/plugin-rest-endpoint-methods": "^11.0.0",
33+
"@octokit/tsconfig": "^3.0.0",
3434
"@types/fetch-mock": "^7.3.1",
3535
"@types/jest": "^29.0.0",
3636
"@types/node": "^20.0.0",
@@ -46,11 +46,15 @@
4646
},
4747
"jest": {
4848
"preset": "ts-jest",
49+
"extensionsToTreatAsEsm": [
50+
".ts"
51+
],
4952
"transform": {
5053
"^.+\\.(ts|tsx)$": [
5154
"ts-jest",
5255
{
53-
"tsconfig": "test/tsconfig.test.json"
56+
"tsconfig": "test/tsconfig.test.json",
57+
"useESM": true
5458
}
5559
]
5660
},
@@ -64,6 +68,9 @@
6468
"functions": 100,
6569
"lines": 100
6670
}
71+
},
72+
"moduleNameMapper": {
73+
"^(.+)\\.jsx?$": "$1"
6774
}
6875
},
6976
"release": {

scripts/build.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ async function main() {
7575
...pkg,
7676
files: ["dist-*/**", "bin/**"],
7777
main: "dist-node/index.js",
78-
browser: "dist-web/index.js",
7978
types: "dist-types/index.d.ts",
80-
module: "dist-src/index.js",
79+
exports: {
80+
".": {
81+
types: "./dist-types/index.d.ts",
82+
import: "./dist-node/index.js",
83+
}
84+
},
8185
sideEffects: false,
8286
},
8387
null,

src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CursorValue, PageInfoContext } from "./page-info";
1+
import type { CursorValue, PageInfoContext } from "./page-info.js";
22

33
// Todo: Add link to explanation
44
const generateMessage = (path: string[], cursorValue: CursorValue): string =>

src/extract-page-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { PageInfoContext } from "./page-info";
2-
import { findPaginatedResourcePath, get } from "./object-helpers";
1+
import type { PageInfoContext } from "./page-info.js";
2+
import { findPaginatedResourcePath, get } from "./object-helpers.js";
33

44
const extractPageInfos = (responseData: any): PageInfoContext => {
55
const pageInfoPath = findPaginatedResourcePath(responseData);

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Octokit } from "@octokit/core";
2-
import { createIterator } from "./iterator";
3-
import { createPaginate } from "./paginate";
4-
export type { PageInfoForward, PageInfoBackward } from "./page-info";
1+
import type { Octokit } from "@octokit/core";
2+
import { createIterator } from "./iterator.js";
3+
import { createPaginate } from "./paginate.js";
4+
export type { PageInfoForward, PageInfoBackward } from "./page-info.js";
55

66
export function paginateGraphQL(octokit: Octokit) {
77
octokit.graphql;

src/iterator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { extractPageInfos } from "./extract-page-info";
2-
import { Octokit } from "@octokit/core";
3-
import { getCursorFrom, hasAnotherPage } from "./page-info";
4-
import { MissingCursorChange } from "./errors";
1+
import { extractPageInfos } from "./extract-page-info.js";
2+
import type { Octokit } from "@octokit/core";
3+
import { getCursorFrom, hasAnotherPage } from "./page-info.js";
4+
import { MissingCursorChange } from "./errors.js";
55

66
const createIterator = (octokit: Octokit) => {
77
return <ResponseType = any>(

src/merge-responses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { findPaginatedResourcePath, get, set } from "./object-helpers";
1+
import { findPaginatedResourcePath, get, set } from "./object-helpers.js";
22

33
const mergeResponses = <ResponseType extends object = any>(
44
response1: ResponseType,

src/object-helpers.ts

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

33
const isObject = (value: any) =>
44
Object.prototype.toString.call(value) === "[object Object]";

src/paginate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Octokit } from "@octokit/core";
2-
import { mergeResponses } from "./merge-responses";
3-
import { createIterator } from "./iterator";
1+
import type { Octokit } from "@octokit/core";
2+
import { mergeResponses } from "./merge-responses.js";
3+
import { createIterator } from "./iterator.js";
44

55
const createPaginate = (octokit: Octokit) => {
66
const iterator = createIterator(octokit);

test/extract-page-infos.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { extractPageInfos } from "../src/extract-page-info";
2-
import { PageInfoContext } from "../src/page-info";
1+
import { extractPageInfos } from "../src/extract-page-info.js";
2+
import type { PageInfoContext } from "../src/page-info.js";
33

44
describe("extractPageInfos()", (): void => {
55
it("returns throws if no pageInfo object exists", async (): Promise<void> => {

test/merge-responses.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mergeResponses } from "../src/merge-responses";
1+
import { mergeResponses } from "../src/merge-responses.js";
22

33
describe(".mergeResponses()", (): void => {
44
it('merges the "nodes" array of a response if it exists.', async (): Promise<void> => {

test/paginate-graphql.e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Octokit } from "@octokit/core";
2-
import { paginateGraphQL } from "../src";
2+
import { paginateGraphQL } from "../src/index.js";
33

44
const PatchedOctokit = Octokit.plugin(paginateGraphQL);
55

test/paginate.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import fetchMock from "fetch-mock";
2-
import { MissingCursorChange, MissingPageInfo } from "../src/errors";
3-
import { PageInfo } from "../src/page-info";
4-
import { MockOctokit, PatchedOctokit } from "./testHelpers/mock-octokit";
2+
import { MissingCursorChange, MissingPageInfo } from "../src/errors.js";
3+
import type { PageInfo } from "../src/page-info.js";
4+
import { MockOctokit, PatchedOctokit } from "./testHelpers/mock-octokit.js";
55
import {
66
createResponsePages,
7-
TestResponseType,
8-
} from "./testHelpers/mock-response";
7+
type TestResponseType,
8+
} from "./testHelpers/mock-response.js";
99

1010
describe("pagination", () => {
1111
it(".paginate() returns the response data if only one page exists.", async (): Promise<void> => {

0 commit comments

Comments
 (0)