chore: update @actions/core to v3 and migrate to ESM (#73)
This PR updates the `@actions/core` dependency from v2 to v3.0.0.
### Major Changes:
- **Dependency Update**: Updated `@actions/core` to `v3.0.0` in `package.json`.
- **ESM Migration**: Converted the entire project to ECMAScript Modules (ESM). This was necessary because `@actions/core` v3 is an ESM-only package and does not provide CommonJS exports.
- **`package.json` updates**: Added `"type": "module"` and updated the dependency version.
- **Code Refactor**:
- Converted `index.js` to use `import` and `export`.
- Updated the main execution check to use `import.meta.url` for ESM compatibility.
- Converted `__tests__/index.test.js` to use ESM imports for compatibility with the updated source code.
- **Production Build**: Re-generated the `dist/index.js` bundle using `ncc` to reflect the changes.
- **Node.js Version**: The project continues to use Node 20 (`node20` in `action.yaml`), which is fully compatible with these changes.
### Why these changes are needed:
- `@actions/core` v3 brings latest improvements and fixes from the GitHub Actions toolkit.
- Migrating to ESM is the modern standard for Node.js development and is required to consume ESM-only packages like the new `@actions/core` v3.
Verified with `npm test` and `npm run build`.
Reviewed-on: #73
This commit was merged in pull request #73.
This commit is contained in:
32
index.js
32
index.js
@@ -1,8 +1,9 @@
|
||||
const { ScreepsAPI } = require("screeps-api");
|
||||
const core = require("@actions/core");
|
||||
const fs = require("fs");
|
||||
const { glob } = require("glob");
|
||||
const path = require("path");
|
||||
import { ScreepsAPI } from "screeps-api";
|
||||
import * as core from "@actions/core";
|
||||
import fs from "fs";
|
||||
import { glob } from "glob";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
/**
|
||||
* Replaces specific placeholder strings within the provided content with corresponding dynamic values.
|
||||
@@ -17,7 +18,7 @@ const path = require("path");
|
||||
* @param {string} content - The string content in which placeholders are to be replaced.
|
||||
* @returns {string} The content with placeholders replaced by their respective dynamic values.
|
||||
*/
|
||||
function replacePlaceholders(content, hostname) {
|
||||
export function replacePlaceholders(content, hostname) {
|
||||
const deployTime = new Date().toISOString();
|
||||
return content
|
||||
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
|
||||
@@ -37,7 +38,7 @@ function replacePlaceholders(content, hostname) {
|
||||
* @param {string} [prefix] - An optional directory prefix to prepend to the glob pattern. This allows searching within a specific directory.
|
||||
* @returns {Promise<string[]>} A promise that resolves with an array of file paths that were processed, or rejects with an error if the process fails.
|
||||
*/
|
||||
async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
||||
export async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
||||
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||
const files = await glob(globPattern);
|
||||
|
||||
@@ -58,7 +59,7 @@ async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
||||
* @param {string} prefix - Directory prefix for file paths.
|
||||
* @returns {Promise<Object>} - Promise resolving to a dictionary of file contents keyed by filenames.
|
||||
*/
|
||||
async function readFilesIntoDict(pattern, prefix) {
|
||||
export async function readFilesIntoDict(pattern, prefix) {
|
||||
// Prepend the prefix to the glob pattern
|
||||
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||
const files = await glob(globPattern);
|
||||
@@ -88,7 +89,7 @@ async function readFilesIntoDict(pattern, prefix) {
|
||||
* @param {string} password - The password.
|
||||
* @returns {string|null} - Returns an error message if validation fails, otherwise null.
|
||||
*/
|
||||
function validateAuthentication(token, username, password) {
|
||||
export function validateAuthentication(token, username, password) {
|
||||
if (token) {
|
||||
if (username || password) {
|
||||
return "Token is defined along with username and/or password.";
|
||||
@@ -110,7 +111,7 @@ function validateAuthentication(token, username, password) {
|
||||
/**
|
||||
* Posts code to Screeps server.
|
||||
*/
|
||||
async function postCode() {
|
||||
export async function postCode() {
|
||||
const protocol = core.getInput("protocol") || "https";
|
||||
const hostname = core.getInput("hostname") || "screeps.com";
|
||||
const port = core.getInput("port") || "443";
|
||||
@@ -175,14 +176,7 @@ async function postCode() {
|
||||
}
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
if (process.argv[1] === __filename) {
|
||||
postCode();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
validateAuthentication,
|
||||
replacePlaceholders,
|
||||
postCode,
|
||||
readReplaceAndWriteFiles,
|
||||
readFilesIntoDict,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user