Skip to content

Commit 4d05e28

Browse files
committed
fix(core): eliminate import cycles
This change eliminates two import cycles found in `@actions/core`. These import cycles would prevent rollupjs from removing unused code within `@actions/core`, bloating the resultant packaged js. Anecdotally, with these changes, a project I work on that only uses core's `info` and `setState` was reduced in size from 1.0MiB to approximately 244KiB. - `core.ts` <-> `oidc-utils.ts`: - `core.ts` importing from `oidc-utils.ts` for the purpose of forming and exporting `getIDToken()`. - `oidc-utils.ts` was importing `debug()` and `setSecret` from `core.ts`. - Resolved by: - Moving `getIDToken` into `oidc-utils.ts`. - Moving all package exports into `index.ts`, including the export of `getIDToken`. - `core.ts` <-> `utils.ts`: - `core.ts` importing `toCommandProperties` and `toCommandValue` from `utils.ts`. - `utils.ts` importing `AnnotationProperties` from `core.ts`. - Resolved by moving the definition of `AnnotationProperties` into `core-type.ts`, and having `utils.ts` import from there. Partially fixes #1436, where one of the import cycles were first described.
1 parent f58042f commit 4d05e28

File tree

8 files changed

+76
-69
lines changed

8 files changed

+76
-69
lines changed

packages/core/__tests__/core.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs'
22
import * as os from 'os'
33
import * as path from 'path'
4-
import * as core from '../src/core'
4+
import * as core from '../src/index'
55
import {HttpClient} from '@actions/http-client'
66
import {toCommandProperties} from '../src/utils'
77

packages/core/__tests__/platform.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os from 'os'
2-
import {platform} from '../src/core'
2+
import {platform} from '../src/index'
33

44
describe('getInfo', () => {
55
it('returns the platform info', async () => {

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
],
1010
"homepage": "https://github.com/actions/toolkit/tree/main/packages/core",
1111
"license": "MIT",
12-
"main": "lib/core.js",
13-
"types": "lib/core.d.ts",
12+
"main": "lib/index.js",
13+
"types": "lib/index.d.ts",
1414
"directories": {
1515
"lib": "lib",
1616
"test": "__tests__"

packages/core/src/core-types.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Optional properties that can be sent with annotation commands (notice, error, and warning)
3+
* See: https://docs.github.com/en/rest/reference/checks#create-a-check-run for more information about annotations.
4+
*/
5+
export interface AnnotationProperties {
6+
/**
7+
* A title for the annotation.
8+
*/
9+
title?: string
10+
11+
/**
12+
* The path of the file for which the annotation should be created.
13+
*/
14+
file?: string
15+
16+
/**
17+
* The start line for the annotation.
18+
*/
19+
startLine?: number
20+
21+
/**
22+
* The end line for the annotation. Defaults to `startLine` when `startLine` is provided.
23+
*/
24+
endLine?: number
25+
26+
/**
27+
* The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values.
28+
*/
29+
startColumn?: number
30+
31+
/**
32+
* The end column for the annotation. Cannot be sent when `startLine` and `endLine` are different values.
33+
* Defaults to `startColumn` when `startColumn` is provided.
34+
*/
35+
endColumn?: number
36+
}

packages/core/src/core.ts

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {issue, issueCommand} from './command'
22
import {issueFileCommand, prepareKeyValueMessage} from './file-command'
33
import {toCommandProperties, toCommandValue} from './utils'
4+
import {AnnotationProperties} from './core-types'
45

56
import * as os from 'os'
67
import * as path from 'path'
78

8-
import {OidcClient} from './oidc-utils'
9-
109
/**
1110
* Interface for getInput options
1211
*/
@@ -33,43 +32,6 @@ export enum ExitCode {
3332
Failure = 1
3433
}
3534

36-
/**
37-
* Optional properties that can be sent with annotation commands (notice, error, and warning)
38-
* See: https://docs.github.com/en/rest/reference/checks#create-a-check-run for more information about annotations.
39-
*/
40-
export interface AnnotationProperties {
41-
/**
42-
* A title for the annotation.
43-
*/
44-
title?: string
45-
46-
/**
47-
* The path of the file for which the annotation should be created.
48-
*/
49-
file?: string
50-
51-
/**
52-
* The start line for the annotation.
53-
*/
54-
startLine?: number
55-
56-
/**
57-
* The end line for the annotation. Defaults to `startLine` when `startLine` is provided.
58-
*/
59-
endLine?: number
60-
61-
/**
62-
* The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values.
63-
*/
64-
startColumn?: number
65-
66-
/**
67-
* The end column for the annotation. Cannot be sent when `startLine` and `endLine` are different values.
68-
* Defaults to `startColumn` when `startColumn` is provided.
69-
*/
70-
endColumn?: number
71-
}
72-
7335
//-----------------------------------------------------------------------
7436
// Variables
7537
//-----------------------------------------------------------------------
@@ -392,27 +354,3 @@ export function saveState(name: string, value: any): void {
392354
export function getState(name: string): string {
393355
return process.env[`STATE_${name}`] || ''
394356
}
395-
396-
export async function getIDToken(aud?: string): Promise<string> {
397-
return await OidcClient.getIDToken(aud)
398-
}
399-
400-
/**
401-
* Summary exports
402-
*/
403-
export {summary} from './summary'
404-
405-
/**
406-
* @deprecated use core.summary
407-
*/
408-
export {markdownSummary} from './summary'
409-
410-
/**
411-
* Path exports
412-
*/
413-
export {toPosixPath, toWin32Path, toPlatformPath} from './path-utils'
414-
415-
/**
416-
* Platform utilities exports
417-
*/
418-
export * as platform from './platform'

packages/core/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Core exports
3+
*/
4+
export * from './core'
5+
6+
/**
7+
* Summary exports
8+
*/
9+
export {summary} from './summary'
10+
11+
/**
12+
* @deprecated use core.summary
13+
*/
14+
export {markdownSummary} from './summary'
15+
16+
/**
17+
* Path exports
18+
*/
19+
export {toPosixPath, toWin32Path, toPlatformPath} from './path-utils'
20+
21+
/**
22+
* Platform utilities exports
23+
*/
24+
export * as platform from './platform'
25+
26+
/**
27+
* OIDC utilities exports
28+
*/
29+
export {getIDToken} from './oidc-utils'

packages/core/src/oidc-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface TokenResponse {
88
value?: string
99
}
1010

11-
export class OidcClient {
11+
class OidcClient {
1212
private static createHttpClient(
1313
allowRetry = true,
1414
maxRetry = 10
@@ -82,3 +82,7 @@ export class OidcClient {
8282
}
8383
}
8484
}
85+
86+
export async function getIDToken(aud?: string): Promise<string> {
87+
return await OidcClient.getIDToken(aud)
88+
}

packages/core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// We use any as a valid input type
22
/* eslint-disable @typescript-eslint/no-explicit-any */
33

4-
import {AnnotationProperties} from './core'
4+
import {AnnotationProperties} from './core-types'
55
import {CommandProperties} from './command'
66

77
/**

0 commit comments

Comments
 (0)