From d37829ef6acec8f3e3e4db260f57e92de2bbf0da Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 4 Mar 2024 20:16:05 +0700 Subject: [PATCH] build: build distribution files directly from TypeScript files (#221) * build: build dist directly from TypeScript sources * build(ts): adjust options in `tsconfig.json` * fix: import all instead of default in @actions modules --- .gitignore | 2 -- dist/index.js | 46 +++++++++++++++++++++++++++++++++++++++------- package.json | 2 +- src/index.ts | 20 ++++++++++---------- tsconfig.json | 10 ++++------ 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 55a7354..f58785f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ build/ node_modules/ - -src/**/*.js diff --git a/dist/index.js b/dist/index.js index 744e243..763ca7e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27685,6 +27685,35 @@ module.exports = parseParams /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __nccwpck_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __nccwpck_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __nccwpck_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; @@ -27694,8 +27723,11 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2340); +/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(4926); +/* harmony import */ var _actions_exec__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_exec__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _actions_io__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(1793); +/* harmony import */ var _actions_io__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_actions_io__WEBPACK_IMPORTED_MODULE_2__); @@ -27706,16 +27738,16 @@ async function main() { const generator = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput("generator"); if (generator) configureArgs.push(...["-G", generator]); - if (generator.match(/ninja/gi) && !(await _actions_io__WEBPACK_IMPORTED_MODULE_2__.which("ninja"))) { + if (generator.match(/ninja/gi) && !(await (0,_actions_io__WEBPACK_IMPORTED_MODULE_2__.which)("ninja"))) { switch (process.platform) { case "linux": - await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("sudo", ["apt", "install", "-y", "ninja-build"]); + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)("sudo", ["apt", "install", "-y", "ninja-build"]); break; case "darwin": - await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("brew", ["install", "ninja"]); + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)("brew", ["install", "ninja"]); break; case "win32": - await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("choco", ["install", "ninja"]); + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)("choco", ["install", "ninja"]); break; } } @@ -27738,19 +27770,19 @@ async function main() { const args = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getMultilineInput("args") .flatMap((args) => args.split(" ")); configureArgs.push(...args); - await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("cmake", configureArgs); + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)("cmake", configureArgs); _actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput("build-dir", buildDir || "build"); const runBuild = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getBooleanInput("run-build"); const runTest = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getBooleanInput("run-test"); if (runBuild || runTest) { const buildArgs = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getMultilineInput("build-args") .flatMap((args) => args.split(" ")); - await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("cmake", ["--build", buildDir || "build", ...buildArgs]); + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)("cmake", ["--build", buildDir || "build", ...buildArgs]); } if (runTest) { const testArgs = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getMultilineInput("test-args") .flatMap((args) => args.split(" ")); - await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec("ctest", [ + await (0,_actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec)("ctest", [ "--test-dir", buildDir || "build", "--output-on-failure", diff --git a/package.json b/package.json index 7b78296..333de86 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": true, "type": "module", "scripts": { - "build": "tsc && ncc build src/index.js -o dist", + "build": "ncc build src/index.ts -o dist", "format": "prettier --write --cache . !dist !README.md", "lint": "eslint --ignore-path .gitignore ." }, diff --git a/src/index.ts b/src/index.ts index b8219f4..6ea8735 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ -import core from "@actions/core"; -import exec from "@actions/exec"; -import io from "@actions/io"; +import * as core from "@actions/core"; +import { exec } from "@actions/exec"; +import { which } from "@actions/io"; async function main() { const sourceDir = core.getInput("source-dir"); @@ -11,16 +11,16 @@ async function main() { const generator = core.getInput("generator"); if (generator) configureArgs.push(...["-G", generator]); - if (generator.match(/ninja/gi) && !(await io.which("ninja"))) { + if (generator.match(/ninja/gi) && !(await which("ninja"))) { switch (process.platform) { case "linux": - await exec.exec("sudo", ["apt", "install", "-y", "ninja-build"]); + await exec("sudo", ["apt", "install", "-y", "ninja-build"]); break; case "darwin": - await exec.exec("brew", ["install", "ninja"]); + await exec("brew", ["install", "ninja"]); break; case "win32": - await exec.exec("choco", ["install", "ninja"]); + await exec("choco", ["install", "ninja"]); break; } } @@ -48,7 +48,7 @@ async function main() { .flatMap((args) => args.split(" ")); configureArgs.push(...args); - await exec.exec("cmake", configureArgs); + await exec("cmake", configureArgs); core.setOutput("build-dir", buildDir || "build"); const runBuild = core.getBooleanInput("run-build"); @@ -58,14 +58,14 @@ async function main() { const buildArgs = core .getMultilineInput("build-args") .flatMap((args) => args.split(" ")); - await exec.exec("cmake", ["--build", buildDir || "build", ...buildArgs]); + await exec("cmake", ["--build", buildDir || "build", ...buildArgs]); } if (runTest) { const testArgs = core .getMultilineInput("test-args") .flatMap((args) => args.split(" ")); - await exec.exec("ctest", [ + await exec("ctest", [ "--test-dir", buildDir || "build", "--output-on-failure", diff --git a/tsconfig.json b/tsconfig.json index e9de469..875ab45 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,8 @@ { "compilerOptions": { - "exactOptionalPropertyTypes": true, - "strict": true, "module": "node16", - "target": "es2022", - "skipLibCheck": true - }, - "include": ["src"] + "moduleResolution": "node16", + "esModuleInterop": true, + "target": "es2022" + } }