Skip to content

Commit d71a659

Browse files
committed
Add main module dependencies.
1 parent a379c08 commit d71a659

3 files changed

Lines changed: 127 additions & 9 deletions

File tree

action/dist/action.js

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

action/dist/index.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,50 @@ async function executeExport(args) {
113113
if (!(__nccwpck_require__(9896).existsSync)(cliPath)) {
114114
throw new Error(`CLI library not found at ${cliPath}. Please run 'npm run build' in the main directory first.`);
115115
}
116-
// We use a subprocess approach to call the CLI
116+
// Install CLI dependencies in the action's working directory
117+
core.info('Installing CLI dependencies...');
117118
const { spawn } = __nccwpck_require__(5317);
119+
// First, install the LiaScript exporter package globally to get all dependencies
120+
const installResult = await new Promise((resolve) => {
121+
const npmInstall = spawn('npm', ['install', '-g', '@liascript/exporter'], {
122+
stdio: ['pipe', 'pipe', 'pipe'],
123+
env: { ...process.env }
124+
});
125+
let installOutput = '';
126+
let installError = '';
127+
npmInstall.stdout.on('data', (data) => {
128+
installOutput += data.toString();
129+
core.info(`npm install: ${data.toString().trim()}`);
130+
});
131+
npmInstall.stderr.on('data', (data) => {
132+
installError += data.toString();
133+
core.warning(`npm install warning: ${data.toString().trim()}`);
134+
});
135+
npmInstall.on('close', (code) => {
136+
if (code === 0) {
137+
core.info('CLI dependencies installed successfully');
138+
resolve(true);
139+
}
140+
else {
141+
core.error(`Failed to install CLI dependencies: ${installError}`);
142+
resolve(false);
143+
}
144+
});
145+
npmInstall.on('error', (error) => {
146+
core.error(`Failed to start npm install: ${error.message}`);
147+
resolve(false);
148+
});
149+
});
150+
if (!installResult) {
151+
throw new Error('Failed to install CLI dependencies');
152+
}
153+
// Now use the globally installed CLI instead of the local one
154+
const globalCliCommand = 'liascript-exporter';
118155
// Build CLI arguments
119156
const cliArgs = buildCliArguments(args);
120157
core.info(`CLI arguments: ${cliArgs.join(' ')}`);
121158
return new Promise((resolve) => {
122-
const childProcess = spawn('node', [cliPath, ...cliArgs], {
159+
const childProcess = spawn(globalCliCommand, cliArgs, {
123160
cwd: args.path || path.dirname(args.input),
124161
stdio: ['pipe', 'pipe', 'pipe'],
125162
env: { ...process.env, NODE_ENV: 'production' }
@@ -199,7 +236,7 @@ async function executeExport(args) {
199236
childProcess.on('error', (error) => {
200237
clearTimeout(timeout);
201238
if (error.message.includes('ENOENT')) {
202-
core.error(`Failed to start export process: Node.js not found or CLI path incorrect (${error.message})`);
239+
core.error(`Failed to start export process: CLI command not found (${error.message})`);
203240
}
204241
else {
205242
core.error(`Failed to start export process: ${error.message}`);

action/src/action.ts

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,59 @@ async function executeExport(args: LiaScriptExporterArgs): Promise<boolean> {
100100
throw new Error(`CLI library not found at ${cliPath}. Please run 'npm run build' in the main directory first.`);
101101
}
102102

103-
// We use a subprocess approach to call the CLI
103+
// Install CLI dependencies in the action's working directory
104+
core.info('Installing CLI dependencies...');
104105
const { spawn } = require('child_process');
105106

107+
// First, install the LiaScript exporter package globally to get all dependencies
108+
const installResult = await new Promise<boolean>((resolve) => {
109+
const npmInstall = spawn('npm', ['install', '-g', '@liascript/exporter'], {
110+
stdio: ['pipe', 'pipe', 'pipe'],
111+
env: { ...process.env }
112+
});
113+
114+
let installOutput = '';
115+
let installError = '';
116+
117+
npmInstall.stdout.on('data', (data: Buffer) => {
118+
installOutput += data.toString();
119+
core.info(`npm install: ${data.toString().trim()}`);
120+
});
121+
122+
npmInstall.stderr.on('data', (data: Buffer) => {
123+
installError += data.toString();
124+
core.warning(`npm install warning: ${data.toString().trim()}`);
125+
});
126+
127+
npmInstall.on('close', (code: number | null) => {
128+
if (code === 0) {
129+
core.info('CLI dependencies installed successfully');
130+
resolve(true);
131+
} else {
132+
core.error(`Failed to install CLI dependencies: ${installError}`);
133+
resolve(false);
134+
}
135+
});
136+
137+
npmInstall.on('error', (error: Error) => {
138+
core.error(`Failed to start npm install: ${error.message}`);
139+
resolve(false);
140+
});
141+
});
142+
143+
if (!installResult) {
144+
throw new Error('Failed to install CLI dependencies');
145+
}
146+
147+
// Now use the globally installed CLI instead of the local one
148+
const globalCliCommand = 'liascript-exporter';
149+
106150
// Build CLI arguments
107151
const cliArgs = buildCliArguments(args);
108152
core.info(`CLI arguments: ${cliArgs.join(' ')}`);
109153

110154
return new Promise((resolve) => {
111-
const childProcess = spawn('node', [cliPath, ...cliArgs], {
155+
const childProcess = spawn(globalCliCommand, cliArgs, {
112156
cwd: args.path || path.dirname(args.input),
113157
stdio: ['pipe', 'pipe', 'pipe'],
114158
env: { ...process.env, NODE_ENV: 'production' }
@@ -191,7 +235,7 @@ async function executeExport(args: LiaScriptExporterArgs): Promise<boolean> {
191235
clearTimeout(timeout);
192236

193237
if (error.message.includes('ENOENT')) {
194-
core.error(`Failed to start export process: Node.js not found or CLI path incorrect (${error.message})`);
238+
core.error(`Failed to start export process: CLI command not found (${error.message})`);
195239
} else {
196240
core.error(`Failed to start export process: ${error.message}`);
197241
}

0 commit comments

Comments
 (0)