ESM-only with updated @octokit dependencies
This commit is contained in:
@@ -4,6 +4,9 @@ module.exports = {
|
|||||||
roots: ['<rootDir>/packages'],
|
roots: ['<rootDir>/packages'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/__tests__/*.test.ts'],
|
testMatch: ['**/__tests__/*.test.ts'],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^(\\.{1,2}/.*)\\.js$': '$1'
|
||||||
|
},
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.(ts|js)$': ['ts-jest', {
|
'^.+\\.(ts|js)$': ['ts-jest', {
|
||||||
isolatedModules: true,
|
isolatedModules: true,
|
||||||
|
|||||||
@@ -6,9 +6,20 @@
|
|||||||
|
|
||||||
Returns an authenticated Octokit client that follows the machine [proxy settings](https://help.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners) and correctly sets GHES base urls. See https://octokit.github.io/rest.js for the API.
|
Returns an authenticated Octokit client that follows the machine [proxy settings](https://help.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners) and correctly sets GHES base urls. See https://octokit.github.io/rest.js for the API.
|
||||||
|
|
||||||
|
**Note:** This package is ESM-only starting from v9.0.0. For CommonJS projects, use dynamic import:
|
||||||
```js
|
```js
|
||||||
const github = require('@actions/github');
|
async function main() {
|
||||||
const core = require('@actions/core');
|
const { getOctokit, context } = await import('@actions/github');
|
||||||
|
// ... your code here
|
||||||
|
}
|
||||||
|
main();
|
||||||
|
```
|
||||||
|
|
||||||
|
For bundled actions (recommended), most bundlers like esbuild, webpack, and rollup handle ESM imports automatically.
|
||||||
|
|
||||||
|
```js
|
||||||
|
import * as github from '@actions/github';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
// This should be a token with access to your repository scoped in as a secret.
|
// This should be a token with access to your repository scoped in as a secret.
|
||||||
@@ -46,7 +57,7 @@ const result = await octokit.graphql(query, variables);
|
|||||||
Finally, you can get the context of the current action:
|
Finally, you can get the context of the current action:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const github = require('@actions/github');
|
import * as github from '@actions/github';
|
||||||
|
|
||||||
const context = github.context;
|
const context = github.context;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# @actions/github Releases
|
# @actions/github Releases
|
||||||
|
|
||||||
|
### 9.0.0
|
||||||
|
|
||||||
|
- **Breaking change**: Package is now ESM-only
|
||||||
|
- CommonJS consumers must use dynamic `import()` instead of `require()`
|
||||||
|
- Example: `const { getOctokit, context } = await import('@actions/github')`
|
||||||
|
- Fix TypeScript compilation by migrating to ESM, enabling proper imports from `@octokit/core/types`
|
||||||
|
|
||||||
### 8.0.1
|
### 8.0.1
|
||||||
|
|
||||||
- Update `undici` to `6.23.0`
|
- Update `undici` to `6.23.0`
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {Context} from '../src/context'
|
import {readFileSync} from 'fs'
|
||||||
|
import {Context} from '../src/context.js'
|
||||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
||||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
||||||
|
|
||||||
describe('@actions/context', () => {
|
describe('@actions/context', () => {
|
||||||
let context: Context
|
let context: Context
|
||||||
@@ -14,7 +12,10 @@ describe('@actions/context', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns the payload object', () => {
|
it('returns the payload object', () => {
|
||||||
expect(context.payload).toEqual(require('./payload.json'))
|
const payload = JSON.parse(
|
||||||
|
readFileSync(path.join(__dirname, 'payload.json'), 'utf8')
|
||||||
|
)
|
||||||
|
expect(context.payload).toEqual(payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns an empty payload if the GITHUB_EVENT_PATH environment variable is falsey', () => {
|
it('returns an empty payload if the GITHUB_EVENT_PATH environment variable is falsey', () => {
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
|
/** @type {import('jest').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/*.test.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
|
moduleNameMapper: {
|
||||||
|
'^(\\.{1,2}/.*)\\.js$': '$1'
|
||||||
|
},
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.(ts|js)$': ['ts-jest', {
|
'^.+\\.(ts|js)$': ['ts-jest', {
|
||||||
useESM: false,
|
|
||||||
tsconfig: {
|
tsconfig: {
|
||||||
allowJs: true,
|
allowJs: true,
|
||||||
esModuleInterop: true
|
esModuleInterop: true,
|
||||||
|
module: 'node16',
|
||||||
|
moduleResolution: 'node16'
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/github",
|
"name": "@actions/github",
|
||||||
"version": "8.0.1",
|
"version": "9.0.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@actions/github",
|
"name": "@actions/github",
|
||||||
"version": "8.0.1",
|
"version": "9.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "^3.0.2",
|
"@actions/http-client": "^3.0.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/github",
|
"name": "@actions/github",
|
||||||
"version": "8.0.1",
|
"version": "9.0.0",
|
||||||
"description": "Actions github lib",
|
"description": "Actions github lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
@@ -8,8 +8,19 @@
|
|||||||
],
|
],
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/main/packages/github",
|
"homepage": "https://github.com/actions/toolkit/tree/main/packages/github",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"type": "module",
|
||||||
"main": "lib/github.js",
|
"main": "lib/github.js",
|
||||||
"types": "lib/github.d.ts",
|
"types": "lib/github.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./lib/github.d.ts",
|
||||||
|
"import": "./lib/github.js"
|
||||||
|
},
|
||||||
|
"./lib/utils": {
|
||||||
|
"types": "./lib/utils.d.ts",
|
||||||
|
"import": "./lib/utils.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
"test": "__tests__"
|
"test": "__tests__"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/main/src/context.ts
|
// Originally pulled from https://github.com/JasonEtco/actions-toolkit/blob/main/src/context.ts
|
||||||
import {WebhookPayload} from './interfaces'
|
import {WebhookPayload} from './interfaces.js'
|
||||||
import {readFileSync, existsSync} from 'fs'
|
import {readFileSync, existsSync} from 'fs'
|
||||||
import {EOL} from 'os'
|
import {EOL} from 'os'
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import * as Context from './context'
|
import * as Context from './context.js'
|
||||||
import {GitHub, getOctokitOptions} from './utils'
|
import {GitHub, getOctokitOptions} from './utils.js'
|
||||||
|
|
||||||
// octokit + plugins
|
// octokit + plugins
|
||||||
import {OctokitOptions, OctokitPlugin} from '@octokit/core/dist-types/types'
|
import type {OctokitOptions, OctokitPlugin} from '@octokit/core/types'
|
||||||
|
|
||||||
export const context = new Context.Context()
|
export const context = new Context.Context()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as http from 'http'
|
import * as http from 'http'
|
||||||
import * as httpClient from '@actions/http-client'
|
import * as httpClient from '@actions/http-client'
|
||||||
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
import type {OctokitOptions} from '@octokit/core/types'
|
||||||
import {ProxyAgent, fetch} from 'undici'
|
import {ProxyAgent, fetch} from 'undici'
|
||||||
|
|
||||||
export function getAuthString(
|
export function getAuthString(
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import * as Context from './context'
|
import * as Context from './context.js'
|
||||||
import * as Utils from './internal/utils'
|
import * as Utils from './internal/utils.js'
|
||||||
|
import type {OctokitOptions} from '@octokit/core/types'
|
||||||
|
|
||||||
// octokit + plugins
|
// octokit + plugins
|
||||||
import {Octokit} from '@octokit/core'
|
import {Octokit} from '@octokit/core'
|
||||||
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
|
||||||
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
|
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
|
||||||
import {paginateRest} from '@octokit/plugin-paginate-rest'
|
import {paginateRest} from '@octokit/plugin-paginate-rest'
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"outDir": "./lib",
|
"outDir": "./lib",
|
||||||
"rootDir": "./src"
|
"rootDir": "./src",
|
||||||
|
"module": "node16",
|
||||||
|
"moduleResolution": "node16"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src"
|
"./src"
|
||||||
|
|||||||
Reference in New Issue
Block a user