@wordpress-flow/cli 1.0.25 → 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.
- package/dist/build/block-build-worker.js +20 -44
- package/dist/index.js +2727 -1370
- package/package.json +3 -9
- package/webpack.config.cjs +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 { execSync } from "child_process";
|
|
1839
1839
|
async function buildBlock() {
|
|
1840
1840
|
const { block, outputDir, webpackConfigPath, scriptsPath, tempDir } = workerData;
|
|
1841
1841
|
try {
|
|
@@ -2002,51 +2002,27 @@ function parseBlockJsonFromSource(block) {
|
|
|
2002
2002
|
};
|
|
2003
2003
|
}
|
|
2004
2004
|
async function runWebpackBuild(entryPoint, outputDir, webpackConfigPath) {
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
}
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
const baseConfig = typeof configFactory === "function" ? configFactory(env) : configFactory;
|
|
2013
|
-
const config = {
|
|
2014
|
-
...baseConfig,
|
|
2015
|
-
mode: "production",
|
|
2016
|
-
entry: entryPoint,
|
|
2017
|
-
output: {
|
|
2018
|
-
...baseConfig.output,
|
|
2019
|
-
path: outputDir
|
|
2020
|
-
}
|
|
2021
|
-
};
|
|
2022
|
-
return new Promise((resolve2, reject) => {
|
|
2023
|
-
webpack(config, (err, stats) => {
|
|
2024
|
-
if (err) {
|
|
2025
|
-
reject(new Error(`Webpack error: ${err.message}
|
|
2026
|
-
Stack: ${err.stack}`));
|
|
2027
|
-
return;
|
|
2028
|
-
}
|
|
2029
|
-
if (stats?.hasErrors()) {
|
|
2030
|
-
const info = stats.toJson();
|
|
2031
|
-
const errorMessages = info.errors?.map((e) => {
|
|
2032
|
-
if (typeof e === "string")
|
|
2033
|
-
return e;
|
|
2034
|
-
return e.message || JSON.stringify(e);
|
|
2035
|
-
}).join(`
|
|
2036
|
-
`) || "Unknown webpack error";
|
|
2037
|
-
reject(new Error(`Webpack build errors:
|
|
2038
|
-
${errorMessages}`));
|
|
2039
|
-
return;
|
|
2040
|
-
}
|
|
2041
|
-
if (stats?.hasWarnings()) {
|
|
2042
|
-
const info = stats.toJson();
|
|
2043
|
-
console.warn(`Webpack warnings for ${outputDir}:`, info.warnings?.map((w) => w.message || w).join(`
|
|
2044
|
-
`));
|
|
2045
|
-
}
|
|
2046
|
-
resolve2();
|
|
2047
|
-
});
|
|
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"
|
|
2048
2012
|
});
|
|
2049
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
|
+
}
|
|
2050
2026
|
function verifyBuildOutput(outputDir) {
|
|
2051
2027
|
const requiredFiles = ["block.json", "index.js", "ssr.js"];
|
|
2052
2028
|
for (const file of requiredFiles) {
|