diff --git a/extension.js b/extension.js index d80c6ba..2fe6a38 100644 --- a/extension.js +++ b/extension.js @@ -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 {} @@ -273,27 +272,47 @@ 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; + + if (code !== 0) { + logger.warn(`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 diff --git a/package-lock.json b/package-lock.json index 937ece8..5f51af4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "@harperdb/nextjs", "version": "1.1.0", "license": "MIT", - "dependencies": { - "shell-quote": "^1.8.1" - }, "bin": { "harperdb-nextjs": "cli.js" }, @@ -1045,15 +1042,6 @@ "node": ">=8" } }, - "node_modules/shell-quote": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", - "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", diff --git a/package.json b/package.json index 0fe694d..e7b34ee 100644 --- a/package.json +++ b/package.json @@ -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",