Skip to content

Commit

Permalink
feat: package is now ESM
Browse files Browse the repository at this point in the history
BREAKING CHANGE: package is now ESM
  • Loading branch information
wolfy1339 committed Mar 4, 2024
1 parent c6cc5fd commit 1f19786
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 100 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Node
Install with `npm install @octokit/core @octokit/plugin-paginate-graphql`. Optionally replace `@octokit/core` with a core-compatible module

```js
const { Octokit } = require("@octokit/core");
const { paginateGraphQL } = require("@octokit/plugin-paginate-graphql");
import { Octokit } from "@octokit/core";
import { paginateGraphQL } from "@octokit/plugin-paginate-graphql";
```

</td></tr>
Expand Down
104 changes: 48 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"publishConfig": {
"access": "public"
},
"type": "module",
"version": "0.0.0-development",
"description": "Octokit plugin to paginate GraphQL API endpoint responses",
"main": "index.js",
"scripts": {
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "jest --coverage",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict test/typescript-validate.ts",
"test:watch": "jest --watch",
"test:e2e": "jest --testRegex test/*.e2e.ts"
"test:watch": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --watch",
"test:e2e": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest --testRegex test/*.e2e.ts"
},
"repository": "github:octokit/plugin-paginate-graphql.js",
"keywords": [
Expand All @@ -25,12 +25,12 @@
],
"license": "MIT",
"peerDependencies": {
"@octokit/core": ">=5"
"@octokit/core": ">=6"
},
"devDependencies": {
"@octokit/core": "^5.0.0",
"@octokit/plugin-rest-endpoint-methods": "^10.0.0",
"@octokit/tsconfig": "^2.0.0",
"@octokit/core": "^6.0.0",
"@octokit/plugin-rest-endpoint-methods": "^11.0.0",
"@octokit/tsconfig": "^3.0.0",
"@types/fetch-mock": "^7.3.1",
"@types/jest": "^29.0.0",
"@types/node": "^20.0.0",
Expand All @@ -46,11 +46,15 @@
},
"jest": {
"preset": "ts-jest",
"extensionsToTreatAsEsm": [
".ts"
],
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
"tsconfig": "test/tsconfig.test.json",
"useESM": true
}
]
},
Expand All @@ -64,6 +68,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
8 changes: 6 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ async function main() {
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
browser: "dist-web/index.js",
types: "dist-types/index.d.ts",
module: "dist-src/index.js",
exports: {
".": {
types: "./dist-types/index.d.ts",
import: "./dist-node/index.js",
}
},
sideEffects: false,
},
null,
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CursorValue, PageInfoContext } from "./page-info";
import type { CursorValue, PageInfoContext } from "./page-info.js";

// Todo: Add link to explanation
const generateMessage = (path: string[], cursorValue: CursorValue): string =>
Expand Down
4 changes: 2 additions & 2 deletions src/extract-page-info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { PageInfoContext } from "./page-info";
import { findPaginatedResourcePath, get } from "./object-helpers";
import type { PageInfoContext } from "./page-info.js";
import { findPaginatedResourcePath, get } from "./object-helpers.js";

const extractPageInfos = (responseData: any): PageInfoContext => {
const pageInfoPath = findPaginatedResourcePath(responseData);
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Octokit } from "@octokit/core";
import { createIterator } from "./iterator";
import { createPaginate } from "./paginate";
export type { PageInfoForward, PageInfoBackward } from "./page-info";
import type { Octokit } from "@octokit/core";
import { createIterator } from "./iterator.js";
import { createPaginate } from "./paginate.js";
export type { PageInfoForward, PageInfoBackward } from "./page-info.js";

export function paginateGraphQL(octokit: Octokit) {

Check failure on line 6 in src/index.ts

View workflow job for this annotation

GitHub Actions / release

The inferred type of 'paginateGraphQL' cannot be named without a reference to '../node_modules/@octokit/graphql/dist-types/types.js'. This is likely not portable. A type annotation is necessary.

Check failure on line 6 in src/index.ts

View workflow job for this annotation

GitHub Actions / test

The inferred type of 'paginateGraphQL' cannot be named without a reference to '../node_modules/@octokit/graphql/dist-types/types.js'. This is likely not portable. A type annotation is necessary.
octokit.graphql;
Expand Down
8 changes: 4 additions & 4 deletions src/iterator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extractPageInfos } from "./extract-page-info";
import { Octokit } from "@octokit/core";
import { getCursorFrom, hasAnotherPage } from "./page-info";
import { MissingCursorChange } from "./errors";
import { extractPageInfos } from "./extract-page-info.js";
import type { Octokit } from "@octokit/core";
import { getCursorFrom, hasAnotherPage } from "./page-info.js";
import { MissingCursorChange } from "./errors.js";

const createIterator = (octokit: Octokit) => {
return <ResponseType = any>(
Expand Down
2 changes: 1 addition & 1 deletion src/merge-responses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findPaginatedResourcePath, get, set } from "./object-helpers";
import { findPaginatedResourcePath, get, set } from "./object-helpers.js";

const mergeResponses = <ResponseType extends object = any>(
response1: ResponseType,
Expand Down
2 changes: 1 addition & 1 deletion src/object-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MissingPageInfo } from "./errors";
import { MissingPageInfo } from "./errors.js";

const isObject = (value: any) =>
Object.prototype.toString.call(value) === "[object Object]";
Expand Down
6 changes: 3 additions & 3 deletions src/paginate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from "@octokit/core";
import { mergeResponses } from "./merge-responses";
import { createIterator } from "./iterator";
import type { Octokit } from "@octokit/core";
import { mergeResponses } from "./merge-responses.js";
import { createIterator } from "./iterator.js";

const createPaginate = (octokit: Octokit) => {
const iterator = createIterator(octokit);
Expand Down
4 changes: 2 additions & 2 deletions test/extract-page-infos.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extractPageInfos } from "../src/extract-page-info";
import { PageInfoContext } from "../src/page-info";
import { extractPageInfos } from "../src/extract-page-info.js";
import type { PageInfoContext } from "../src/page-info.js";

describe("extractPageInfos()", (): void => {
it("returns throws if no pageInfo object exists", async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/merge-responses.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeResponses } from "../src/merge-responses";
import { mergeResponses } from "../src/merge-responses.js";

describe(".mergeResponses()", (): void => {
it('merges the "nodes" array of a response if it exists.', async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion test/paginate-graphql.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Octokit } from "@octokit/core";
import { paginateGraphQL } from "../src";
import { paginateGraphQL } from "../src/index.js";

const PatchedOctokit = Octokit.plugin(paginateGraphQL);

Expand Down
10 changes: 5 additions & 5 deletions test/paginate.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fetchMock from "fetch-mock";
import { MissingCursorChange, MissingPageInfo } from "../src/errors";
import { PageInfo } from "../src/page-info";
import { MockOctokit, PatchedOctokit } from "./testHelpers/mock-octokit";
import { MissingCursorChange, MissingPageInfo } from "../src/errors.js";
import type { PageInfo } from "../src/page-info.js";
import { MockOctokit, PatchedOctokit } from "./testHelpers/mock-octokit.js";
import {
createResponsePages,
TestResponseType,
} from "./testHelpers/mock-response";
type TestResponseType,
} from "./testHelpers/mock-response.js";

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

0 comments on commit 1f19786

Please sign in to comment.