From 3ec245d22b45ab6abe0f870de0627b053687875e Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Thu, 6 Mar 2025 16:40:51 -0700 Subject: [PATCH 1/5] remove shell-quote and switch to execsync --- extension.js | 29 ++++++++++++++--------------- package-lock.json | 12 ------------ package.json | 3 --- 3 files changed, 14 insertions(+), 30 deletions(-) diff --git a/extension.js b/extension.js index 5526a73..513c8ef 100644 --- a/extension.js +++ b/extension.js @@ -4,14 +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 { execSync } 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'; - class HarperDBNextJSExtensionError extends Error {} /** @@ -270,27 +268,28 @@ async function build(config, componentPath, server) { } // Build - const [command, ...args] = shellQuote.parse(config.buildCommand); - - const timerStart = performance.now(); + try { + const timerStart = performance.now(); - const { stdout, stderr, status, error } = spawnSync(command, args, { - cwd: componentPath, - encoding: 'utf-8', - }); + const stdout = execSync(config.buildCommand, { + cwd: componentPath, + encoding: 'utf-8', + }); - if (status === 0) { - if (stdout) logger.info(stdout); const duration = performance.now() - timerStart; + + if (stdout) { + logger.info(stdout); + } + 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 1e3f9b3..a366032 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "@harperdb/nextjs", "version": "1.0.2", "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 96e0f07..65ca690 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", From 7277ccef3ba8999f80a74aac87bd91bc6c76c60a Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Wed, 12 Mar 2025 08:59:29 -0600 Subject: [PATCH 2/5] update to be async --- extension.js | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/extension.js b/extension.js index 92b6c70..6e8e48f 100644 --- a/extension.js +++ b/extension.js @@ -4,11 +4,13 @@ import { existsSync, statSync, readFileSync, openSync, writeSync, unlinkSync } from 'node:fs'; import { join } from 'node:path'; import { parse as urlParse } from 'node:url'; -import { execSync } 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 { Writable } from 'node:stream'; +import { once } from 'node:events'; class HarperDBNextJSExtensionError extends Error {} @@ -272,17 +274,49 @@ async function build(config, componentPath, server) { // Build try { + logger.info(`Building Next.js application at ${componentPath}`); + const timerStart = performance.now(); - const stdout = execSync(config.buildCommand, { + const stdout = []; + const stderr = []; + + const buildProcess = spawn(config.buildCommand, [], { + shell: true, cwd: componentPath, - encoding: 'utf-8', + stdio: ['ignore', 'pipe', 'pipe'], }); + buildProcess.stdout.pipe( + new Writable({ + write(chunk, encoding, callback) { + stdout.push(chunk); + callback(); + }, + }) + ); + + buildProcess.stderr.pipe( + new Writable({ + write(chunk, encoding, callback) { + stderr.push(chunk); + callback(); + }, + }) + ); + + const [code, signal] = await once(buildProcess, 'exit'); + const duration = performance.now() - timerStart; - if (stdout) { - logger.info(stdout); + 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`); From 0001cc5b6428e6394253a4127caf0b6350f9858c Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Wed, 12 Mar 2025 09:34:15 -0600 Subject: [PATCH 3/5] ditch unecessary writable --- extension.js | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/extension.js b/extension.js index 6e8e48f..1c116e4 100644 --- a/extension.js +++ b/extension.js @@ -9,7 +9,6 @@ import { setTimeout } from 'node:timers/promises'; import { createRequire } from 'node:module'; import { performance } from 'node:perf_hooks'; import { tmpdir } from 'node:os'; -import { Writable } from 'node:stream'; import { once } from 'node:events'; class HarperDBNextJSExtensionError extends Error {} @@ -287,23 +286,8 @@ async function build(config, componentPath, server) { stdio: ['ignore', 'pipe', 'pipe'], }); - buildProcess.stdout.pipe( - new Writable({ - write(chunk, encoding, callback) { - stdout.push(chunk); - callback(); - }, - }) - ); - - buildProcess.stderr.pipe( - new Writable({ - write(chunk, encoding, callback) { - stderr.push(chunk); - callback(); - }, - }) - ); + buildProcess.stdout.on('data', c => stdout.push(c)); + buildProcess.stderr.on('data', c => stderr.push(c)); const [code, signal] = await once(buildProcess, 'exit'); From 7937cdf07ab512fe90dddd9903f7c06c960dc0a3 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Wed, 12 Mar 2025 09:47:59 -0600 Subject: [PATCH 4/5] Update extension.js Co-authored-by: Chris Barber --- extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension.js b/extension.js index 1c116e4..bca17b8 100644 --- a/extension.js +++ b/extension.js @@ -289,7 +289,7 @@ async function build(config, componentPath, server) { buildProcess.stdout.on('data', c => stdout.push(c)); buildProcess.stderr.on('data', c => stderr.push(c)); - const [code, signal] = await once(buildProcess, 'exit'); + const [code, signal] = await once(buildProcess, 'close'); const duration = performance.now() - timerStart; From 7e5ad9874ecdbfbe22e9ce91809f9173bfe1f156 Mon Sep 17 00:00:00 2001 From: Ethan Arrowood Date: Wed, 12 Mar 2025 10:50:57 -0600 Subject: [PATCH 5/5] fix up warn --- extension.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/extension.js b/extension.js index bca17b8..2fe6a38 100644 --- a/extension.js +++ b/extension.js @@ -286,14 +286,16 @@ async function build(config, componentPath, server) { stdio: ['ignore', 'pipe', 'pipe'], }); - buildProcess.stdout.on('data', c => stdout.push(c)); - buildProcess.stderr.on('data', c => stderr.push(c)); + buildProcess.stdout.on('data', (c) => stdout.push(c)); + buildProcess.stderr.on('data', (c) => stderr.push(c)); const [code, signal] = await once(buildProcess, 'close'); const duration = performance.now() - timerStart; - logger.info(`Build command \`${config.buildCommand}\` exited with code ${code} and signal ${signal}`); + 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());