Skip to content

Commit

Permalink
Migrate to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Feb 26, 2024
1 parent 3ed92c8 commit ea107a3
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 139 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
],
"license": "MIT",
"private": true,
"type": "module",
"exports": {
".": "./dist/index.js"
},
"engines": {
"node": ">=20"
},
"scripts": {
"start": "ts-node src/index.ts",
"start": "tsx src/index.ts",
"build": "ncc build src/index.ts --license LICENSE.txt --minify",
"lint": "eslint --max-warnings 0 .",
"pretty": "prettier --check .",
Expand All @@ -42,7 +43,7 @@
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vitest": "^1.3.1",
"vitest-mock-extended": "^1.3.1"
Expand Down
106 changes: 20 additions & 86 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { group, info, warning } from "@actions/core"
import { processPackages } from "./process/process"
import { DeleteStrategy, Input, QueryStrategy } from "./types"
import { processPackages } from "./process/process.js"
import { DeleteStrategy, Input, QueryStrategy } from "./types.js"

export async function executeAction(input: Input, queryStrategy: QueryStrategy, deleteStrategy: DeleteStrategy) {
if (input.dryRun) {
Expand Down
5 changes: 2 additions & 3 deletions src/clients/packages.client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { info, warning } from "@actions/core"
import { getOctokit } from "@actions/github"
import { GitHub } from "@actions/github/lib/utils"
import { Octokit } from "@octokit/core"
import { throttling } from "@octokit/plugin-throttling"
import { RequestOptions } from "@octokit/types"
import { Input } from "../types"
import { Input } from "../types.js"

export function createPackagesClient(input: Input): InstanceType<typeof GitHub> {
export function createPackagesClient(input: Input): ReturnType<typeof getOctokit> {
const customClient = Octokit.plugin(throttling)

const customOctokit = new customClient({
Expand Down
8 changes: 4 additions & 4 deletions src/delete/delete.strategy.factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createPackagesClient } from "../clients/packages.client"
import { DeleteStrategy, Input } from "../types"
import OrganizationDeleteStrategy from "./strategies/organization.delete.strategy"
import UserDeleteStrategy from "./strategies/user.delete.strategy"
import { createPackagesClient } from "../clients/packages.client.js"
import { DeleteStrategy, Input } from "../types.js"
import OrganizationDeleteStrategy from "./strategies/organization.delete.strategy.js"
import UserDeleteStrategy from "./strategies/user.delete.strategy.js"

export function decideDeleteStrategy(input: Input): DeleteStrategy {
const packagesClient = createPackagesClient(input)
Expand Down
6 changes: 3 additions & 3 deletions src/delete/strategies/organization.delete.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GitHub } from "@actions/github/lib/utils"
import { DeleteStrategy, Input } from "../../types"
import { getOctokit } from "@actions/github"
import { DeleteStrategy, Input } from "../../types.js"

export default class OrganizationDeleteStrategy implements DeleteStrategy {
constructor(private readonly octokit: InstanceType<typeof GitHub>) {}
constructor(private readonly octokit: ReturnType<typeof getOctokit>) {}

async deletePackageVersion(input: Input, name: string, id: string): Promise<void> {
await this.octokit.rest.packages.deletePackageVersionForOrg({
Expand Down
6 changes: 3 additions & 3 deletions src/delete/strategies/user.delete.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GitHub } from "@actions/github/lib/utils"
import { DeleteStrategy, Input } from "../../types"
import { getOctokit } from "@actions/github"
import { DeleteStrategy, Input } from "../../types.js"

export default class UserDeleteStrategy implements DeleteStrategy {
constructor(private readonly octokit: InstanceType<typeof GitHub>) {}
constructor(private readonly octokit: ReturnType<typeof getOctokit>) {}

async deletePackageVersion(input: Input, name: string, id: string): Promise<void> {
await this.octokit.rest.packages.deletePackageVersionForUser({
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { setFailed } from "@actions/core"
import { executeAction } from "./action"
import { decideDeleteStrategy } from "./delete/delete.strategy.factory"
import { getActionInput, validateInput } from "./input"
import { decideQueryStrategy } from "./query/query.strategy.factory"
import { executeAction } from "./action.js"
import { decideDeleteStrategy } from "./delete/delete.strategy.factory.js"
import { getActionInput, validateInput } from "./input.js"
import { decideQueryStrategy } from "./query/query.strategy.factory.js"

async function run() {
const input = validateInput(getActionInput())
Expand Down
2 changes: 1 addition & 1 deletion src/input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getBooleanInput, getInput, getMultilineInput } from "@actions/core"
import { Range } from "semver"
import { Input, PackageType } from "./types"
import { Input, PackageType } from "./types.js"

const DEFAULT_KEEP = 2

Expand Down
5 changes: 2 additions & 3 deletions src/process/process.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Endpoints } from "@octokit/types"
import semverCoerce from "semver/functions/coerce"
import semverSatisfies from "semver/functions/satisfies"
import { Input, Package, PackageType, PackageVersion } from "../types"
import { coerce as semverCoerce, satisfies as semverSatisfies } from "semver"
import { Input, Package, PackageType, PackageVersion } from "../types.js"

type OctokitPackageResponse =
Endpoints["GET /users/{username}/packages/{package_type}/{package_name}/versions"]["response"]
Expand Down
8 changes: 4 additions & 4 deletions src/query/query.strategy.factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createPackagesClient } from "../clients/packages.client"
import { Input, QueryStrategy } from "../types"
import OrganizationQueryStrategy from "./strategies/organization.query.strategy"
import UserQueryStrategy from "./strategies/user.query.strategy"
import { createPackagesClient } from "../clients/packages.client.js"
import { Input, QueryStrategy } from "../types.js"
import OrganizationQueryStrategy from "./strategies/organization.query.strategy.js"
import UserQueryStrategy from "./strategies/user.query.strategy.js"

export function decideQueryStrategy(input: Input): QueryStrategy {
const packagesClient = createPackagesClient(input)
Expand Down
8 changes: 4 additions & 4 deletions src/query/strategies/organization.query.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GitHub } from "@actions/github/lib/utils"
import { processResponse } from "../../process/process"
import { Input, Package, QueryStrategy } from "../../types"
import { getOctokit } from "@actions/github"
import { processResponse } from "../../process/process.js"
import { Input, Package, QueryStrategy } from "../../types.js"

export default class OrganizationQueryStrategy implements QueryStrategy {
constructor(private readonly octokit: InstanceType<typeof GitHub>) {}
constructor(private readonly octokit: ReturnType<typeof getOctokit>) {}

async queryPackages(input: Input): Promise<Package[]> {
return await Promise.all(
Expand Down
8 changes: 4 additions & 4 deletions src/query/strategies/user.query.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { GitHub } from "@actions/github/lib/utils"
import { processResponse } from "../../process/process"
import { Input, Package, QueryStrategy } from "../../types"
import { getOctokit } from "@actions/github"
import { processResponse } from "../../process/process.js"
import { Input, Package, QueryStrategy } from "../../types.js"

export default class UserQueryStrategy implements QueryStrategy {
constructor(private readonly octokit: InstanceType<typeof GitHub>) {}
constructor(private readonly octokit: ReturnType<typeof getOctokit>) {}

async queryPackages(input: Input): Promise<Package[]> {
return await Promise.all(
Expand Down
4 changes: 2 additions & 2 deletions test/action.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Range } from "semver"
import { expect, test } from "vitest"
import { mock } from "vitest-mock-extended"
import { executeAction } from "../src/action"
import { DeleteStrategy, Input, PackageType, QueryStrategy } from "../src/types"
import { executeAction } from "../src/action.js"
import { DeleteStrategy, Input, PackageType, QueryStrategy } from "../src/types.js"

const packages = [
{
Expand Down
8 changes: 4 additions & 4 deletions test/delete/delete.strategy.factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect, test } from "vitest"
import { decideDeleteStrategy } from "../../src/delete/delete.strategy.factory"
import OrganizationDeleteStrategy from "../../src/delete/strategies/organization.delete.strategy"
import UserDeleteStrategy from "../../src/delete/strategies/user.delete.strategy"
import { Input, PackageType } from "../../src/types"
import { decideDeleteStrategy } from "../../src/delete/delete.strategy.factory.js"
import OrganizationDeleteStrategy from "../../src/delete/strategies/organization.delete.strategy.js"
import UserDeleteStrategy from "../../src/delete/strategies/user.delete.strategy.js"
import { Input, PackageType } from "../../src/types.js"

test("decide default delete strategy", () => {
const input: Input = {
Expand Down
4 changes: 2 additions & 2 deletions test/input.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Range } from "semver"
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"
import { getActionInput, validateInput } from "../src/input"
import { Input, PackageType } from "../src/types"
import { getActionInput, validateInput } from "../src/input.js"
import { Input, PackageType } from "../src/types.js"

describe("getActionInput", () => {
const env = process.env
Expand Down
Loading

0 comments on commit ea107a3

Please sign in to comment.