Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove shell-quote and switch to spawn #23

Merged
merged 6 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import { existsSync, statSync, readFileSync, openSync, writeSync, unlinkSync } from 'node:fs';
import { join } from 'node:path';
import { parse as urlParse } from 'node:url';
import { spawnSync } from 'node:child_process';
import { spawn } from 'node:child_process';
import { setTimeout } from 'node:timers/promises';
import { createRequire } from 'node:module';
import { performance } from 'node:perf_hooks';
import { tmpdir } from 'node:os';

import shellQuote from 'shell-quote';
import { once } from 'node:events';

class HarperDBNextJSExtensionError extends Error {}

Expand Down Expand Up @@ -273,27 +272,45 @@ async function build(config, componentPath, server) {
}

// Build
const [command, ...args] = shellQuote.parse(config.buildCommand);
try {
logger.info(`Building Next.js application at ${componentPath}`);

const timerStart = performance.now();

const stdout = [];
const stderr = [];

const timerStart = performance.now();
const buildProcess = spawn(config.buildCommand, [], {
shell: true,
cwd: componentPath,
stdio: ['ignore', 'pipe', 'pipe'],
});

const { stdout, stderr, status, error } = spawnSync(command, args, {
cwd: componentPath,
encoding: 'utf-8',
});
buildProcess.stdout.on('data', c => stdout.push(c));
buildProcess.stderr.on('data', c => stderr.push(c));

const [code, signal] = await once(buildProcess, 'close');

if (status === 0) {
if (stdout) logger.info(stdout);
const duration = performance.now() - timerStart;

logger.info(`Build command \`${config.buildCommand}\` exited with code ${code} and signal ${signal}`);

if (stdout.length > 0) {
logger.info(Buffer.concat(stdout).toString());
}

if (stderr.length > 0) {
logger.error(Buffer.concat(stderr).toString());
}

logger.info(`The Next.js build took ${((duration % 60000) / 1000).toFixed(2)} seconds`);
server.recordAnalytics(
duration,
'nextjs_build_time_in_milliseconds',
componentPath.toString().slice(0, -1).split('/').pop()
);
} else {
if (stderr) logger.error(stderr);
if (error) logger.error(error);
} catch (error) {
logger.error(error);
}

// Release lock and exit
Expand Down
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
"format:fix": "npm run format -- --write",
"lint": "eslint ."
},
"dependencies": {
"shell-quote": "^1.8.1"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@harperdb/code-guidelines": "^0.0.2",
Expand Down