Skip to content

Commit 83885ec

Browse files
committed
use ncc to build single file dist
Rather than including node_modules in the repository, build a single file containing everything needed using @vercel/ncc. The file can be rebuilt using npm run build.
1 parent 1bc54da commit 83885ec

File tree

2 files changed

+264
-1
lines changed

2 files changed

+264
-1
lines changed

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ inputs:
5353

5454
runs:
5555
using: "node20"
56-
main: "index.js"
56+
main: "dist/index.js"

dist/index.js

+263
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
/******/ (() => { // webpackBootstrap
2+
/******/ var __webpack_modules__ = ({
3+
4+
/***/ 396:
5+
/***/ ((module) => {
6+
7+
module.exports = eval("require")("@actions/core");
8+
9+
10+
/***/ }),
11+
12+
/***/ 526:
13+
/***/ ((module) => {
14+
15+
module.exports = eval("require")("@actions/exec");
16+
17+
18+
/***/ }),
19+
20+
/***/ 27:
21+
/***/ ((module) => {
22+
23+
module.exports = eval("require")("@actions/io");
24+
25+
26+
/***/ }),
27+
28+
/***/ 617:
29+
/***/ ((module) => {
30+
31+
module.exports = eval("require")("@actions/tool-cache");
32+
33+
34+
/***/ }),
35+
36+
/***/ 37:
37+
/***/ ((module) => {
38+
39+
"use strict";
40+
module.exports = require("os");
41+
42+
/***/ }),
43+
44+
/***/ 17:
45+
/***/ ((module) => {
46+
47+
"use strict";
48+
module.exports = require("path");
49+
50+
/***/ })
51+
52+
/******/ });
53+
/************************************************************************/
54+
/******/ // The module cache
55+
/******/ var __webpack_module_cache__ = {};
56+
/******/
57+
/******/ // The require function
58+
/******/ function __nccwpck_require__(moduleId) {
59+
/******/ // Check if module is in cache
60+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
61+
/******/ if (cachedModule !== undefined) {
62+
/******/ return cachedModule.exports;
63+
/******/ }
64+
/******/ // Create a new module (and put it into the cache)
65+
/******/ var module = __webpack_module_cache__[moduleId] = {
66+
/******/ // no module.id needed
67+
/******/ // no module.loaded needed
68+
/******/ exports: {}
69+
/******/ };
70+
/******/
71+
/******/ // Execute the module function
72+
/******/ var threw = true;
73+
/******/ try {
74+
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
75+
/******/ threw = false;
76+
/******/ } finally {
77+
/******/ if(threw) delete __webpack_module_cache__[moduleId];
78+
/******/ }
79+
/******/
80+
/******/ // Return the exports of the module
81+
/******/ return module.exports;
82+
/******/ }
83+
/******/
84+
/************************************************************************/
85+
/******/ /* webpack/runtime/compat */
86+
/******/
87+
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
88+
/******/
89+
/************************************************************************/
90+
var __webpack_exports__ = {};
91+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
92+
(() => {
93+
const core = __nccwpck_require__(396);
94+
const tc = __nccwpck_require__(617);
95+
const exec = __nccwpck_require__(526);
96+
const io = __nccwpck_require__(27);
97+
98+
const path = __nccwpck_require__(17);
99+
const os = __nccwpck_require__(37);
100+
101+
let PERL;
102+
103+
async function install_cpm_location() {
104+
let out = "";
105+
106+
const options = {};
107+
options.listeners = {
108+
stdout: (data) => {
109+
out += data.toString();
110+
},
111+
};
112+
113+
let p = core.getInput("path");
114+
p.replace("\\", "\\\\");
115+
await exec.exec(PERL, ["-MConfig", "-e", `print "${p}"`], options);
116+
117+
return path.resolve(out);
118+
}
119+
120+
async function install_cpm(install_to) {
121+
const version = core.getInput("version");
122+
const url = `https://raw.githubusercontent.com/skaji/cpm/${version}/cpm`;
123+
124+
core.info(`Get cpm from URL: ${url}`);
125+
126+
const cpmScript = await tc.downloadTool(url);
127+
128+
core.info(`Install cpm to: ${install_to}`);
129+
130+
const platform = os.platform();
131+
132+
if (platform == "win32") {
133+
await io.cp(cpmScript, install_to);
134+
} else {
135+
await do_exec([
136+
PERL,
137+
"-MFile::Copy=cp",
138+
"-e",
139+
`cp("${cpmScript}", "${install_to}"); chmod(0755, "${install_to}")`,
140+
]);
141+
}
142+
143+
return install_to;
144+
}
145+
146+
async function which_perl() {
147+
const perl = core.getInput("perl");
148+
if (perl == "perl") {
149+
return await io.which("perl", true);
150+
}
151+
return perl;
152+
}
153+
154+
function is_true(b) {
155+
if (b !== null && (b === true || b == "true" || b == "1" || b == "ok")) {
156+
return true;
157+
}
158+
159+
return false;
160+
}
161+
162+
async function do_exec(cmd) {
163+
const sudo = is_true(core.getInput("sudo"));
164+
const platform = os.platform();
165+
const bin = sudo && platform != "win32" ? "sudo" : cmd.shift();
166+
167+
core.info(`do_exec: ${bin}`);
168+
169+
await exec.exec(bin, cmd);
170+
}
171+
172+
async function run() {
173+
PERL = await which_perl();
174+
175+
const cpm_location = await install_cpm_location();
176+
177+
await install_cpm(cpm_location);
178+
179+
// input arguments
180+
const install = core.getInput("install");
181+
const cpanfile = core.getInput("cpanfile");
182+
const tests = core.getInput("tests");
183+
const dash_g = core.getInput("global");
184+
const args = core.getInput("args");
185+
const verbose = core.getInput("verbose");
186+
187+
const w_tests = is_true(tests) ? "--test" : "--no-test";
188+
let w_args = [];
189+
190+
if (args !== null && args.length) {
191+
w_args = args.split(/\s+/);
192+
}
193+
194+
/* base CMD_install command */
195+
let CMD_install = [
196+
PERL,
197+
cpm_location,
198+
"install",
199+
"--show-build-log-on-failure",
200+
w_tests,
201+
];
202+
203+
if (is_true(verbose)) {
204+
CMD_install.push("-v");
205+
}
206+
if (is_true(dash_g)) {
207+
CMD_install.push("-g");
208+
}
209+
if (w_args.length) {
210+
CMD_install = CMD_install.concat(w_args);
211+
}
212+
213+
let has_run = false;
214+
215+
/* install one ore more modules */
216+
if (install !== null && install.length) {
217+
// install one or more modules
218+
core.info(`install: ${install}!`);
219+
const list = install.split("\n");
220+
221+
let cmd = [...CMD_install]; /* clone array */
222+
cmd = cmd.concat(list);
223+
224+
has_run = true;
225+
await do_exec(cmd);
226+
}
227+
228+
/* install from cpanfile */
229+
if (cpanfile !== null && cpanfile.length) {
230+
// install one or more modules
231+
core.info(`cpanfile: ${cpanfile}!`);
232+
const cpanfile_full_path = path.resolve(cpanfile);
233+
core.info(`cpanfile: ${cpanfile_full_path}! [resolved]`);
234+
235+
let cmd = [...CMD_install];
236+
cmd.push("--cpanfile", cpanfile_full_path);
237+
238+
has_run = true;
239+
await do_exec(cmd);
240+
}
241+
242+
/* custom run with args */
243+
if (has_run === false && w_args.length) {
244+
core.info(`custom run with args`);
245+
let cmd = [...CMD_install];
246+
has_run = true;
247+
await do_exec(cmd);
248+
}
249+
}
250+
251+
// Call run
252+
(async () => {
253+
try {
254+
await run();
255+
} catch (error) {
256+
core.setFailed(error.message);
257+
}
258+
})();
259+
})();
260+
261+
module.exports = __webpack_exports__;
262+
/******/ })()
263+
;

0 commit comments

Comments
 (0)