@wordpress-flow/cli 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1835,7 +1835,7 @@ import { parentPort, workerData } from "worker_threads";
1835
1835
  import * as path from "path";
1836
1836
  import * as fs from "fs";
1837
1837
  import * as esbuild from "esbuild";
1838
- import { execSync } from "child_process";
1838
+ import { spawnSync } from "child_process";
1839
1839
  async function buildBlock() {
1840
1840
  const { block, outputDir, webpackConfigPath, scriptsPath, tempDir } = workerData;
1841
1841
  try {
@@ -2027,26 +2027,43 @@ function parseBlockJsonFromSource(block) {
2027
2027
  };
2028
2028
  }
2029
2029
  async function runWebpackBuild(entryPoint, outputDir, webpackConfigPath) {
2030
- const webpackBinary = findWebpackBinary();
2031
- const envString = `--env entry="${entryPoint}" --env output="${outputDir}"`;
2032
- const command = `${webpackBinary} --config "${webpackConfigPath}" ${envString} --mode production`;
2033
- execSync(command, {
2030
+ const webpackCliPath = findWebpackCliPath();
2031
+ const args = [
2032
+ webpackCliPath,
2033
+ "--config",
2034
+ webpackConfigPath,
2035
+ "--env",
2036
+ `entry=${entryPoint}`,
2037
+ "--env",
2038
+ `output=${outputDir}`,
2039
+ "--mode",
2040
+ "production"
2041
+ ];
2042
+ const result = spawnSync(process.execPath, args, {
2034
2043
  cwd: path.dirname(webpackConfigPath),
2035
2044
  stdio: "pipe",
2036
2045
  env: { ...process.env }
2037
2046
  });
2047
+ if (result.error) {
2048
+ throw result.error;
2049
+ }
2050
+ if (result.status !== 0) {
2051
+ const stderr = result.stderr?.toString() || "";
2052
+ const stdout = result.stdout?.toString() || "";
2053
+ throw new Error(`Webpack build failed (exit code ${result.status}): ${stderr || stdout}`);
2054
+ }
2038
2055
  }
2039
- function findWebpackBinary() {
2056
+ function findWebpackCliPath() {
2040
2057
  const possiblePaths = [
2041
- path.join(process.cwd(), "packages", "block", "node_modules", ".bin", "webpack"),
2042
- path.join(process.cwd(), "node_modules", ".bin", "webpack")
2058
+ path.join(process.cwd(), "packages", "block", "node_modules", "webpack-cli", "bin", "cli.js"),
2059
+ path.join(process.cwd(), "node_modules", "webpack-cli", "bin", "cli.js")
2043
2060
  ];
2044
- for (const webpackPath of possiblePaths) {
2045
- if (fs.existsSync(webpackPath)) {
2046
- return webpackPath;
2061
+ for (const cliPath of possiblePaths) {
2062
+ if (fs.existsSync(cliPath)) {
2063
+ return cliPath;
2047
2064
  }
2048
2065
  }
2049
- return "npx webpack";
2066
+ throw new Error("webpack-cli not found. Please install webpack-cli in your project.");
2050
2067
  }
2051
2068
  function verifyBuildOutput(outputDir) {
2052
2069
  const requiredFiles = ["block.json", "index.js", "ssr.js"];
package/dist/index.js CHANGED
@@ -115884,7 +115884,7 @@ add_action('enqueue_block_assets', 'wordpress_flow_enqueue_block_scripts');
115884
115884
  // package.json
115885
115885
  var package_default = {
115886
115886
  name: "@wordpress-flow/cli",
115887
- version: "1.0.9",
115887
+ version: "1.0.11",
115888
115888
  type: "module",
115889
115889
  description: "TypeScript-based WordPress block creation system",
115890
115890
  main: "dist/index.js",
@@ -116408,7 +116408,7 @@ import * as path19 from "path";
116408
116408
  // src/build/webpack-runner.ts
116409
116409
  import * as path17 from "path";
116410
116410
  import * as fs15 from "fs";
116411
- import { execSync } from "child_process";
116411
+ import { spawnSync } from "child_process";
116412
116412
  var import_chalk3 = __toESM(require_source(), 1);
116413
116413
 
116414
116414
  class WebpackRunner {
@@ -116429,73 +116429,85 @@ class WebpackRunner {
116429
116429
  throw new Error(error);
116430
116430
  }
116431
116431
  fs15.mkdirSync(outputDir, { recursive: true });
116432
- const webpackBinary = this.findWebpackBinary();
116433
- logger.debug(`Using webpack binary: ${webpackBinary}`);
116434
- const envVars = {
116435
- entry: entryPoint,
116436
- output: outputDir
116437
- };
116438
- const envString = Object.entries(envVars).map(([key, value]) => `--env ${key}="${value}"`).join(" ");
116439
- const command = `${webpackBinary} --config "${webpackConfigPath}" ${envString} --mode production`;
116440
- logger.debug(`Full command: ${command}`);
116441
- try {
116442
- const workingDir = path17.dirname(webpackConfigPath);
116443
- logger.debug(`Running webpack from directory: ${workingDir}`);
116444
- const output2 = execSync(command, {
116445
- cwd: workingDir,
116446
- encoding: "utf8",
116447
- stdio: "pipe",
116448
- env: { ...process.env }
116449
- });
116450
- logger.debug("Webpack build completed successfully");
116451
- logger.debug(`Output: ${output2}`);
116452
- } catch (error) {
116432
+ const webpackCliPath = this.findWebpackCliPath();
116433
+ logger.debug(`Using webpack-cli at: ${webpackCliPath}`);
116434
+ const args = [
116435
+ webpackCliPath,
116436
+ "--config",
116437
+ webpackConfigPath,
116438
+ "--env",
116439
+ `entry=${entryPoint}`,
116440
+ "--env",
116441
+ `output=${outputDir}`,
116442
+ "--mode",
116443
+ "production"
116444
+ ];
116445
+ logger.debug(`Full command: node ${args.join(" ")}`);
116446
+ const workingDir = path17.dirname(webpackConfigPath);
116447
+ logger.debug(`Running webpack from directory: ${workingDir}`);
116448
+ const result2 = spawnSync(process.execPath, args, {
116449
+ cwd: workingDir,
116450
+ stdio: "pipe",
116451
+ env: { ...process.env }
116452
+ });
116453
+ if (result2.error) {
116454
+ console.error("");
116455
+ console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
116456
+ console.error(import_chalk3.default.red.bold(" WEBPACK BUILD FAILED"));
116457
+ console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
116458
+ console.error("");
116459
+ console.error(import_chalk3.default.yellow("Error:"));
116460
+ console.error(import_chalk3.default.gray(result2.error.message));
116461
+ console.error("");
116462
+ console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
116463
+ console.error("");
116464
+ throw result2.error;
116465
+ }
116466
+ if (result2.status !== 0) {
116467
+ const stderr = result2.stderr?.toString() || "";
116468
+ const stdout = result2.stdout?.toString() || "";
116453
116469
  console.error("");
116454
116470
  console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
116455
116471
  console.error(import_chalk3.default.red.bold(" WEBPACK BUILD FAILED"));
116456
116472
  console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
116457
116473
  console.error("");
116458
116474
  console.error(import_chalk3.default.yellow("Command that failed:"));
116459
- console.error(import_chalk3.default.gray(command));
116475
+ console.error(import_chalk3.default.gray(`node ${args.join(" ")}`));
116460
116476
  console.error("");
116461
116477
  console.error(import_chalk3.default.yellow("Working directory:"));
116462
- console.error(import_chalk3.default.gray(path17.dirname(webpackConfigPath)));
116478
+ console.error(import_chalk3.default.gray(workingDir));
116463
116479
  console.error("");
116464
- if (error.stdout && error.stdout.trim()) {
116480
+ if (stdout.trim()) {
116465
116481
  console.error(import_chalk3.default.yellow("Standard output:"));
116466
- console.error(error.stdout);
116482
+ console.error(stdout);
116467
116483
  console.error("");
116468
116484
  }
116469
- if (error.stderr && error.stderr.trim()) {
116485
+ if (stderr.trim()) {
116470
116486
  console.error(import_chalk3.default.yellow("Error output:"));
116471
- console.error(error.stderr);
116472
- console.error("");
116473
- }
116474
- if (!error.stdout && !error.stderr) {
116475
- console.error(import_chalk3.default.yellow("Error message:"));
116476
- console.error(error.message);
116487
+ console.error(stderr);
116477
116488
  console.error("");
116478
116489
  }
116479
116490
  console.error(import_chalk3.default.red("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"));
116480
116491
  console.error("");
116481
- throw new Error(`Webpack build failed`);
116492
+ throw new Error(`Webpack build failed (exit code ${result2.status})`);
116482
116493
  }
116494
+ logger.debug("Webpack build completed successfully");
116495
+ logger.debug(`Output: ${result2.stdout?.toString() || ""}`);
116483
116496
  }
116484
- findWebpackBinary() {
116497
+ findWebpackCliPath() {
116485
116498
  const possiblePaths = [
116486
- path17.join(process.cwd(), "packages", "block", "node_modules", ".bin", "webpack"),
116487
- path17.join(process.cwd(), "node_modules", ".bin", "webpack"),
116488
- path17.join(import.meta.dirname, "..", "..", "..", "node_modules", ".bin", "webpack"),
116489
- path17.join(process.cwd(), "..", "node_modules", ".bin", "webpack")
116499
+ path17.join(process.cwd(), "packages", "block", "node_modules", "webpack-cli", "bin", "cli.js"),
116500
+ path17.join(process.cwd(), "node_modules", "webpack-cli", "bin", "cli.js"),
116501
+ path17.join(import.meta.dirname, "..", "..", "..", "node_modules", "webpack-cli", "bin", "cli.js"),
116502
+ path17.join(process.cwd(), "..", "node_modules", "webpack-cli", "bin", "cli.js")
116490
116503
  ];
116491
- for (const webpackPath of possiblePaths) {
116492
- if (fs15.existsSync(webpackPath)) {
116493
- logger.debug(`Found webpack at: ${webpackPath}`);
116494
- return webpackPath;
116504
+ for (const cliPath of possiblePaths) {
116505
+ if (fs15.existsSync(cliPath)) {
116506
+ logger.debug(`Found webpack-cli at: ${cliPath}`);
116507
+ return cliPath;
116495
116508
  }
116496
116509
  }
116497
- logger.debug("Using npx webpack as fallback");
116498
- return "npx webpack";
116510
+ throw new Error("webpack-cli not found. Please install webpack-cli in your project.");
116499
116511
  }
116500
116512
  }
116501
116513
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress-flow/cli",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "description": "TypeScript-based WordPress block creation system",
6
6
  "main": "dist/index.js",