@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.
- package/dist/build/block-build-worker.js +29 -12
- package/dist/index.js +58 -46
- package/package.json +1 -1
|
@@ -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 {
|
|
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
|
|
2031
|
-
const
|
|
2032
|
-
|
|
2033
|
-
|
|
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
|
|
2056
|
+
function findWebpackCliPath() {
|
|
2040
2057
|
const possiblePaths = [
|
|
2041
|
-
path.join(process.cwd(), "packages", "block", "node_modules", "
|
|
2042
|
-
path.join(process.cwd(), "node_modules", "
|
|
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
|
|
2045
|
-
if (fs.existsSync(
|
|
2046
|
-
return
|
|
2061
|
+
for (const cliPath of possiblePaths) {
|
|
2062
|
+
if (fs.existsSync(cliPath)) {
|
|
2063
|
+
return cliPath;
|
|
2047
2064
|
}
|
|
2048
2065
|
}
|
|
2049
|
-
|
|
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.
|
|
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 {
|
|
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
|
|
116433
|
-
logger.debug(`Using webpack
|
|
116434
|
-
const
|
|
116435
|
-
|
|
116436
|
-
|
|
116437
|
-
|
|
116438
|
-
|
|
116439
|
-
|
|
116440
|
-
|
|
116441
|
-
|
|
116442
|
-
|
|
116443
|
-
|
|
116444
|
-
|
|
116445
|
-
|
|
116446
|
-
|
|
116447
|
-
|
|
116448
|
-
|
|
116449
|
-
|
|
116450
|
-
|
|
116451
|
-
|
|
116452
|
-
}
|
|
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(
|
|
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(
|
|
116478
|
+
console.error(import_chalk3.default.gray(workingDir));
|
|
116463
116479
|
console.error("");
|
|
116464
|
-
if (
|
|
116480
|
+
if (stdout.trim()) {
|
|
116465
116481
|
console.error(import_chalk3.default.yellow("Standard output:"));
|
|
116466
|
-
console.error(
|
|
116482
|
+
console.error(stdout);
|
|
116467
116483
|
console.error("");
|
|
116468
116484
|
}
|
|
116469
|
-
if (
|
|
116485
|
+
if (stderr.trim()) {
|
|
116470
116486
|
console.error(import_chalk3.default.yellow("Error output:"));
|
|
116471
|
-
console.error(
|
|
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
|
-
|
|
116497
|
+
findWebpackCliPath() {
|
|
116485
116498
|
const possiblePaths = [
|
|
116486
|
-
path17.join(process.cwd(), "packages", "block", "node_modules", "
|
|
116487
|
-
path17.join(process.cwd(), "node_modules", "
|
|
116488
|
-
path17.join(import.meta.dirname, "..", "..", "..", "node_modules", "
|
|
116489
|
-
path17.join(process.cwd(), "..", "node_modules", "
|
|
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
|
|
116492
|
-
if (fs15.existsSync(
|
|
116493
|
-
logger.debug(`Found webpack at: ${
|
|
116494
|
-
return
|
|
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
|
-
|
|
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
|
|