diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2033354d7..6650a377e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,8 +18,6 @@ jobs: cache: npm - run: npm ci - run: npm run build - - name: "Fix pkg.files file pattern" - run: node scripts/fix-package-json.js - run: npx semantic-release --debug env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/package-lock.json b/package-lock.json index 43dd709c8..9c1b7f80c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,15 +12,13 @@ "@octokit/types": "^12.0.0" }, "devDependencies": { - "@gimenete/type-writer": "^0.1.5", "@octokit/core": "^5.0.0", "@octokit/tsconfig": "^2.0.0", "@types/fetch-mock": "^7.3.1", "@types/jest": "^29.0.0", "@types/node": "^18.0.0", "esbuild": "^0.19.0", - "fetch-mock": "^9.0.0", - "fs-extra": "^11.0.0", + "fetch-mock": "npm:@gr2m/fetch-mock@^9.11.0-pull-request-644.1", "github-openapi-graphql-query": "^4.0.0", "glob": "^10.2.6", "jest": "^29.0.0", @@ -31,7 +29,7 @@ "npm-run-all": "^4.1.5", "prettier": "3.0.3", "semantic-release-plugin-update-version-in-files": "^1.0.0", - "sort-keys": "^4.2.0", + "sort-keys": "^5.0.0", "string-to-jsdoc-comment": "^1.0.0", "ts-jest": "^29.0.0", "typescript": "^5.0.0" @@ -919,26 +917,6 @@ "node": ">=12" } }, - "node_modules/@gimenete/type-writer": { - "version": "0.1.5", - "dev": true, - "license": "MIT", - "dependencies": { - "camelcase": "^5.0.0", - "prettier": "^1.19.1" - } - }, - "node_modules/@gimenete/type-writer/node_modules/prettier": { - "version": "1.19.1", - "dev": true, - "license": "MIT", - "bin": { - "prettier": "bin-prettier.js" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/@graphql-tools/merge": { "version": "9.0.0", "dev": true, @@ -2659,9 +2637,11 @@ } }, "node_modules/fetch-mock": { - "version": "9.11.0", + "name": "@gr2m/fetch-mock", + "version": "9.11.0-pull-request-644.1", + "resolved": "https://registry.npmjs.org/@gr2m/fetch-mock/-/fetch-mock-9.11.0-pull-request-644.1.tgz", + "integrity": "sha512-gTp6RCHzlOXS1qRb0APfuyz48Lw/JFPa4uiar+kEgL1STsDwth75HJZ4x30tBlXMJXV8XDTDzJ2Hz9w3RWiHJA==", "dev": true, - "license": "MIT", "dependencies": { "@babel/core": "^7.0.0", "@babel/runtime": "^7.0.0", @@ -2759,19 +2739,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/fs-extra": { - "version": "11.1.1", - "dev": true, - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "dev": true, @@ -2898,9 +2865,10 @@ } }, "node_modules/github-openapi-graphql-query/node_modules/semver": { - "version": "7.5.1", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, - "license": "ISC", "dependencies": { "lru-cache": "^6.0.0" }, @@ -3005,9 +2973,10 @@ "license": "ISC" }, "node_modules/graphql": { - "version": "16.6.0", + "version": "16.8.1", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.1.tgz", + "integrity": "sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==", "dev": true, - "license": "MIT", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } @@ -3304,11 +3273,15 @@ } }, "node_modules/is-plain-obj": { - "version": "2.1.0", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-4.1.0.tgz", + "integrity": "sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==", "dev": true, - "license": "MIT", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/is-plain-object": { @@ -4042,9 +4015,10 @@ } }, "node_modules/jest-snapshot/node_modules/semver": { - "version": "7.5.1", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, - "license": "ISC", "dependencies": { "lru-cache": "^6.0.0" }, @@ -4236,17 +4210,6 @@ "node": ">=6" } }, - "node_modules/jsonfile": { - "version": "6.1.0", - "dev": true, - "license": "MIT", - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, "node_modules/keyv": { "version": "4.5.2", "dev": true, @@ -4527,9 +4490,10 @@ } }, "node_modules/normalize-package-data/node_modules/semver": { - "version": "5.7.1", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, - "license": "ISC", "bin": { "semver": "bin/semver" } @@ -4666,9 +4630,10 @@ } }, "node_modules/npm-run-all/node_modules/semver": { - "version": "5.7.1", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, - "license": "ISC", "bin": { "semver": "bin/semver" } @@ -5230,9 +5195,10 @@ } }, "node_modules/semver": { - "version": "6.3.0", + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", "dev": true, - "license": "ISC", "bin": { "semver": "bin/semver.js" } @@ -5302,14 +5268,15 @@ } }, "node_modules/sort-keys": { - "version": "4.2.0", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/sort-keys/-/sort-keys-5.0.0.tgz", + "integrity": "sha512-Pdz01AvCAottHTPQGzndktFNdbRA75BgOfeT1hH+AMnJFv8lynkPi42rfeEhpx1saTEI3YNMWxfqu0sFD1G8pw==", "dev": true, - "license": "MIT", "dependencies": { - "is-plain-obj": "^2.0.0" + "is-plain-obj": "^4.0.0" }, "engines": { - "node": ">=8" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -5752,9 +5719,10 @@ } }, "node_modules/ts-jest/node_modules/semver": { - "version": "7.5.1", + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", + "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", "dev": true, - "license": "ISC", "dependencies": { "lru-cache": "^6.0.0" }, @@ -5839,14 +5807,6 @@ "integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==", "dev": true }, - "node_modules/universalify": { - "version": "2.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/update-browserslist-db": { "version": "1.0.11", "dev": true, diff --git a/package.json b/package.json index 4756fe19a..7ed481479 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,15 @@ "description": "Octokit plugin adding one method for all of api.github.com REST API endpoints", "scripts": { "build": "node scripts/build.mjs && tsc -p tsconfig.json", - "lint": "prettier --check '{src,test}/**/*' '!src/generated/**' README.md package.json", - "lint:fix": "prettier --write '{src,test}/**/*' '!src/generated/**' README.md package.json", + "lint": "prettier --check '{src,test,scripts}/**/*' '!scripts/update-endpoints/generated/**' '!src/generated/**' README.md package.json", + "lint:fix": "prettier --write '{src,test,scripts}/**/*' '!scripts/update-endpoints/generated/**' '!src/generated/**' README.md package.json", "pretest": "npm run -s lint", "test": "jest --coverage", "update-endpoints": "npm-run-all update-endpoints:*", - "update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json", - "update-endpoints:code": "node scripts/update-endpoints/code", - "update-endpoints:docs": "node scripts/update-endpoints/docs", - "update-endpoints:types": "node scripts/update-endpoints/types" + "update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json.mjs", + "update-endpoints:code": "node scripts/update-endpoints/code.mjs", + "update-endpoints:docs": "node scripts/update-endpoints/docs.mjs", + "update-endpoints:types": "node scripts/update-endpoints/types.mjs" }, "repository": "github:octokit/plugin-rest-endpoint-methods.js", "keywords": [ @@ -27,15 +27,13 @@ "@octokit/types": "^12.0.0" }, "devDependencies": { - "@gimenete/type-writer": "^0.1.5", "@octokit/core": "^5.0.0", "@octokit/tsconfig": "^2.0.0", "@types/fetch-mock": "^7.3.1", "@types/jest": "^29.0.0", "@types/node": "^18.0.0", "esbuild": "^0.19.0", - "fetch-mock": "^9.0.0", - "fs-extra": "^11.0.0", + "fetch-mock": "npm:@gr2m/fetch-mock@^9.11.0-pull-request-644.1", "github-openapi-graphql-query": "^4.0.0", "glob": "^10.2.6", "jest": "^29.0.0", @@ -46,7 +44,7 @@ "npm-run-all": "^4.1.5", "prettier": "3.0.3", "semantic-release-plugin-update-version-in-files": "^1.0.0", - "sort-keys": "^4.2.0", + "sort-keys": "^5.0.0", "string-to-jsdoc-comment": "^1.0.0", "ts-jest": "^29.0.0", "typescript": "^5.0.0" diff --git a/scripts/build.mjs b/scripts/build.mjs index 67f82f141..862e23a59 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -81,8 +81,8 @@ async function main() { sideEffects: false, }, null, - 2 - ) + 2, + ), ); } main(); diff --git a/scripts/fix-package-json.js b/scripts/fix-package-json.js deleted file mode 100644 index 76ab50ef6..000000000 --- a/scripts/fix-package-json.js +++ /dev/null @@ -1,15 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const { EOL } = require("os"); - -const pkgPath = path.join(__dirname, "../pkg/package.json"); -const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); - -pkg.files = pkg.files.map((file) => { - if (file.endsWith("/")) { - return file + "**"; - } - return file; -}); - -fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + EOL, "utf8"); diff --git a/scripts/update-endpoints/code.js b/scripts/update-endpoints/code.mjs similarity index 84% rename from scripts/update-endpoints/code.js rename to scripts/update-endpoints/code.mjs index 68968f500..7f5bd1123 100644 --- a/scripts/update-endpoints/code.js +++ b/scripts/update-endpoints/code.mjs @@ -1,19 +1,23 @@ -const { writeFileSync } = require("fs"); -const { join } = require("path"); +import { readFileSync, writeFileSync } from "fs"; +import { join } from "path"; +import { fileURLToPath } from "url"; -const prettier = require("prettier"); -const sortKeys = require("sort-keys"); +import { format } from "prettier"; +import sortKeys from "sort-keys"; -const ENDPOINTS = require("./generated/endpoints.json"); -const { isDeprecated } = require("./util"); +const parentDir = new URL(".", import.meta.url); +const ENDPOINTS = JSON.parse( + readFileSync(new URL("generated/endpoints.json", parentDir)).toString(), +); +import { isDeprecated } from "./util.mjs"; const ROUTES_PATH = join( - __dirname, + fileURLToPath(parentDir), "..", "..", "src", "generated", - "endpoints.ts" + "endpoints.ts", ); const newRoutes = {}; @@ -84,7 +88,7 @@ async function generateRoutes() { } const renamedParameters = endpoint.parameters.filter( - (parameter) => !!parameter.alias + (parameter) => !!parameter.alias, ); if (renamedParameters.length) { @@ -118,15 +122,15 @@ async function generateRoutes() { writeFileSync( ROUTES_PATH, - await prettier.format( + await format( `import type { EndpointsDefaultsAndDecorations } from "../types"; const Endpoints: EndpointsDefaultsAndDecorations = ${JSON.stringify( - sortKeys(newRoutes, { deep: true }) + sortKeys(newRoutes, { deep: true }), )} export default Endpoints`, - { parser: "typescript" } - ) + { parser: "typescript" }, + ), ); console.log(`${ROUTES_PATH} written.`); } diff --git a/scripts/update-endpoints/docs.js b/scripts/update-endpoints/docs.mjs similarity index 79% rename from scripts/update-endpoints/docs.js rename to scripts/update-endpoints/docs.mjs index 1ea67f94d..618de6ddc 100644 --- a/scripts/update-endpoints/docs.js +++ b/scripts/update-endpoints/docs.mjs @@ -1,8 +1,13 @@ -const { outputFileSync } = require("fs-extra"); -const prettier = require("prettier"); +import { format } from "prettier"; -const ENDPOINTS = require("./generated/endpoints.json"); -const { isDeprecated } = require("./util"); +import { isDeprecated } from "./util.mjs"; +import { readFileSync, mkdirSync, writeFileSync } from "fs"; + +const ENDPOINTS = JSON.parse( + readFileSync( + new URL("generated/endpoints.json", new URL(".", import.meta.url)), + ).toString(), +); generateRoutes(); @@ -14,8 +19,10 @@ async function generateRoutes() { }); for (const endpoint of endpoints) { - const path = `docs/${endpoint.scope}/${endpoint.id}.md`; - outputFileSync(path, await template(endpoint)); + const dirPath = `docs/${endpoint.scope}`; + const path = `${dirPath}/${endpoint.id}.md`; + mkdirSync(dirPath, { recursive: true }); + writeFileSync(path, await template(endpoint)); console.log(`${path} written`); } } @@ -34,7 +41,7 @@ async function template(endpoint) { ${param.description || ""} -` +`, ); const requiredParameterNames = endpoint.parameters @@ -96,7 +103,7 @@ ${parameters} See also: [GitHub Developer Guide documentation](${endpoint.documentationUrl}).`; - return await prettier.format(content, { + return await format(content, { parser: "markdown", }); } diff --git a/scripts/update-endpoints/fetch-json.js b/scripts/update-endpoints/fetch-json.mjs similarity index 79% rename from scripts/update-endpoints/fetch-json.js rename to scripts/update-endpoints/fetch-json.mjs index bd70318ad..62c851f2b 100644 --- a/scripts/update-endpoints/fetch-json.js +++ b/scripts/update-endpoints/fetch-json.mjs @@ -1,8 +1,9 @@ -const { writeFileSync } = require("fs"); -const path = require("path"); +import { writeFileSync } from "fs"; +import { resolve } from "path"; +import { fileURLToPath } from "url"; -const graphql = require("github-openapi-graphql-query"); -const prettier = require("prettier"); +import graphql from "github-openapi-graphql-query"; +import { format } from "prettier"; if (!process.env.VERSION) { throw new Error(`VERSION environment variable must be set`); @@ -77,9 +78,13 @@ async function main() { }); writeFileSync( - path.resolve(__dirname, "generated", "endpoints.json"), - await prettier.format(JSON.stringify(endpoints), { + resolve( + fileURLToPath(new URL(".", import.meta.url)), + "generated", + "endpoints.json", + ), + await format(JSON.stringify(endpoints), { parser: "json", - }) + }), ); } diff --git a/scripts/update-endpoints/types.js b/scripts/update-endpoints/types.mjs similarity index 87% rename from scripts/update-endpoints/types.js rename to scripts/update-endpoints/types.mjs index 70a0f834c..abbbdd42a 100644 --- a/scripts/update-endpoints/types.js +++ b/scripts/update-endpoints/types.mjs @@ -1,13 +1,17 @@ -const { writeFileSync } = require("fs"); -const { join: pathJoin } = require("path"); +import { writeFileSync, readFileSync } from "fs"; +import { join as pathJoin } from "path"; -const camelCase = require("lodash.camelcase"); -const prettier = require("prettier"); -const { stringToJsdocComment } = require("string-to-jsdoc-comment"); -const sortKeys = require("sort-keys"); +import camelCase from "lodash.camelcase"; +import { format } from "prettier"; +import { stringToJsdocComment } from "string-to-jsdoc-comment"; +import sortKeys from "sort-keys"; -const ENDPOINTS = require("./generated/endpoints.json"); -const { isDeprecated } = require("./util"); +const ENDPOINTS = JSON.parse( + readFileSync( + new URL("generated/endpoints.json", new URL(".", import.meta.url)), + ).toString(), +); +import { isDeprecated } from "./util.mjs"; generateTypes(); @@ -33,7 +37,7 @@ async function generateTypes() { jsdoc: stringToJsdocComment(description), }); }, - [] + [], ); return namespaces.concat({ @@ -50,7 +54,7 @@ async function generateTypes() { `${method.name}: { parameters: RequestParameters & Omit, response: Endpoints["${method.route}"]["response"] - }` + }`, ); } @@ -71,7 +75,7 @@ async function generateTypes() { defaults: RequestInterface["defaults"]; endpoint: EndpointInterface<{ url: string }>; }`, - ].join("\n") + ].join("\n"), ); } @@ -80,7 +84,7 @@ async function generateTypes() { }`); } - const methodTypesSource = await prettier.format( + const methodTypesSource = await format( [ `import type { EndpointInterface, RequestInterface } from "@octokit/types";`, `import type { RestEndpointMethodTypes } from "./parameters-and-response-types";`, @@ -91,9 +95,9 @@ async function generateTypes() { ].join("\n"), { parser: "typescript", - } + }, ); - const parametersAndResponsesTypes = await prettier.format( + const parametersAndResponsesTypes = await format( [ `import type { Endpoints, RequestParameters } from "@octokit/types";`, "", @@ -103,14 +107,14 @@ async function generateTypes() { ].join("\n"), { parser: "typescript", - } + }, ); const methodTypesFilePath = pathJoin( process.cwd(), "src", "generated", - "method-types.ts" + "method-types.ts", ); writeFileSync(methodTypesFilePath, methodTypesSource, "utf8"); @@ -120,13 +124,13 @@ async function generateTypes() { process.cwd(), "src", "generated", - "parameters-and-response-types.ts" + "parameters-and-response-types.ts", ); writeFileSync( parametersAndResponseFilePath, parametersAndResponsesTypes, - "utf8" + "utf8", ); console.log(`Types written to ${parametersAndResponseFilePath}`); } diff --git a/scripts/update-endpoints/util.js b/scripts/update-endpoints/util.mjs similarity index 89% rename from scripts/update-endpoints/util.js rename to scripts/update-endpoints/util.mjs index bda8a7a42..8d348585c 100644 --- a/scripts/update-endpoints/util.js +++ b/scripts/update-endpoints/util.mjs @@ -1,12 +1,8 @@ -module.exports = { - isDeprecated, -}; - /** * we ignore all legacy endpoints except the ones that were recently added * @param { Endpoint } endpoint */ -function isDeprecated(endpoint) { +export function isDeprecated(endpoint) { if ( endpoint.removalDate && endpoint.removalDate < new Date().toISOString().substr(0, 10)