@wordpress-flow/cli 1.0.26 → 1.1.0

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 webpack from "webpack";
1838
+ import { execSync } from "child_process";
1839
1839
  async function buildBlock() {
1840
1840
  const { block, outputDir, webpackConfigPath, scriptsPath, tempDir } = workerData;
1841
1841
  try {
@@ -2002,71 +2002,27 @@ function parseBlockJsonFromSource(block) {
2002
2002
  };
2003
2003
  }
2004
2004
  async function runWebpackBuild(entryPoint, outputDir, webpackConfigPath) {
2005
- if (!fs.existsSync(webpackConfigPath)) {
2006
- throw new Error(`Webpack config not found: ${webpackConfigPath}. Please check your wpblock.config.json settings.`);
2007
- }
2008
- let configModule;
2009
- try {
2010
- delete __require.cache[__require.resolve(webpackConfigPath)];
2011
- configModule = __require(webpackConfigPath);
2012
- } catch (loadError) {
2013
- throw new Error(`Failed to load webpack config from ${webpackConfigPath}: ${loadError.message}`);
2014
- }
2015
- const configFactory = configModule.default || configModule;
2016
- const env = { entry: entryPoint, output: outputDir };
2017
- let baseConfig;
2018
- try {
2019
- baseConfig = typeof configFactory === "function" ? configFactory(env) : configFactory;
2020
- } catch (configError) {
2021
- throw new Error(`Failed to execute webpack config factory: ${configError.message}`);
2022
- }
2023
- const config = {
2024
- ...baseConfig,
2025
- mode: "production",
2026
- entry: entryPoint,
2027
- output: {
2028
- ...baseConfig.output,
2029
- path: outputDir
2030
- }
2031
- };
2032
- return new Promise((resolve2, reject) => {
2033
- try {
2034
- const compiler = webpack(config);
2035
- compiler.run((err, stats) => {
2036
- compiler.close((closeErr) => {
2037
- if (closeErr) {
2038
- console.error(`Webpack compiler close error: ${closeErr.message}`);
2039
- }
2040
- });
2041
- if (err) {
2042
- reject(new Error(`Webpack compilation error: ${err.message}
2043
- Stack: ${err.stack}`));
2044
- return;
2045
- }
2046
- if (!stats) {
2047
- reject(new Error(`Webpack returned no stats object`));
2048
- return;
2049
- }
2050
- if (stats.hasErrors()) {
2051
- const info = stats.toJson();
2052
- const errorMessages = info.errors?.map((e) => {
2053
- if (typeof e === "string")
2054
- return e;
2055
- return e.message || JSON.stringify(e);
2056
- }).join(`
2057
- `) || "Unknown webpack error";
2058
- reject(new Error(`Webpack build errors:
2059
- ${errorMessages}`));
2060
- return;
2061
- }
2062
- resolve2();
2063
- });
2064
- } catch (webpackError) {
2065
- reject(new Error(`Failed to start webpack: ${webpackError.message}
2066
- Stack: ${webpackError.stack}`));
2067
- }
2005
+ const webpackBinary = findWebpackBinary();
2006
+ const envString = `--env entry="${entryPoint}" --env output="${outputDir}"`;
2007
+ const command = `${webpackBinary} --config "${webpackConfigPath}" ${envString} --mode production`;
2008
+ execSync(command, {
2009
+ cwd: path.dirname(webpackConfigPath),
2010
+ encoding: "utf8",
2011
+ stdio: "pipe"
2068
2012
  });
2069
2013
  }
2014
+ function findWebpackBinary() {
2015
+ const possiblePaths = [
2016
+ path.join(process.cwd(), "packages", "block", "node_modules", ".bin", "webpack"),
2017
+ path.join(process.cwd(), "node_modules", ".bin", "webpack")
2018
+ ];
2019
+ for (const webpackPath of possiblePaths) {
2020
+ if (fs.existsSync(webpackPath)) {
2021
+ return webpackPath;
2022
+ }
2023
+ }
2024
+ return "npx webpack";
2025
+ }
2070
2026
  function verifyBuildOutput(outputDir) {
2071
2027
  const requiredFiles = ["block.json", "index.js", "ssr.js"];
2072
2028
  for (const file of requiredFiles) {