chore!: move away from ESM

It turns out that Jest's ESM support still relies on experimental node
modules (as of node 18). Switch back to commonjs instead.
This commit is contained in:
Tom Keller
2022-10-15 18:09:41 -07:00
parent 239add3ff1
commit 921a07e77f
10 changed files with 174 additions and 82 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import fs from 'fs';
import path from 'path';
import * as core from '@actions/core';
import { AssumeRoleCommandInput, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts';
import { errorMessage, getStsClient, isDefined } from './helpers.js';
import { errorMessage, getStsClient, isDefined } from './helpers';
const SANITIZATION_CHARACTER = '_';
const MAX_TAG_VALUE_LENGTH = 256;
+7 -6
View File
@@ -1,6 +1,5 @@
import * as url from 'node:url';
import * as core from '@actions/core';
import { errorMessage } from '../helpers.js';
import { errorMessage } from '../helpers';
/**
* When the GitHub Actions job is done, clean up any environment variables that
@@ -28,8 +27,10 @@ export async function cleanup() {
core.setFailed(errorMessage(error));
}
}
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
await cleanup();
if (require.main === module) {
(async () => {
await cleanup();
})().catch((error) => {
core.setFailed(errorMessage(error));
});
}
+8 -6
View File
@@ -1,8 +1,7 @@
import * as url from 'node:url';
import * as core from '@actions/core';
import { Credentials, GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
import { assumeRole } from './assumeRole.js';
import { errorMessage, getStsClient, retryAndBackoff } from './helpers.js';
import { assumeRole } from './assumeRole';
import { errorMessage, getStsClient, retryAndBackoff } from './helpers';
// Use 1hr as role duration when using session token or OIDC
// Otherwise, use the max duration of GitHub action (6hr)
@@ -204,7 +203,10 @@ export async function run() {
}
}
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
await run();
if (require.main === module) {
(async () => {
await run();
})().catch((error) => {
core.setFailed(error.message);
});
}