@cordy/electro-cli 1.2.7 → 1.2.8
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/index.mjs +179 -50
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { build, createLogger, createServer, mergeConfig, version } from "vite";
|
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
import { tmpdir } from "node:os";
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
11
12
|
|
|
12
13
|
//#region ../../node_modules/.bun/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
13
14
|
function toArr(any) {
|
|
@@ -490,7 +491,7 @@ const cac = (name = "") => new CAC(name);
|
|
|
490
491
|
|
|
491
492
|
//#endregion
|
|
492
493
|
//#region package.json
|
|
493
|
-
var version$1 = "1.2.
|
|
494
|
+
var version$1 = "1.2.8";
|
|
494
495
|
|
|
495
496
|
//#endregion
|
|
496
497
|
//#region src/dev/logger.ts
|
|
@@ -752,7 +753,7 @@ function validateMergedNodeConfig(config, scope) {
|
|
|
752
753
|
const output = rolldownOpts.output;
|
|
753
754
|
if (output && typeof output === "object" && !Array.isArray(output)) {
|
|
754
755
|
const fmt = output.format;
|
|
755
|
-
if (fmt && fmt !== "es") throw new Error(`[electro] ${scope}: invalid output format "${fmt}". Electro
|
|
756
|
+
if (fmt && fmt !== "es" && fmt !== "cjs") throw new Error(`[electro] ${scope}: invalid output format "${fmt}". Electro supports "es" and "cjs" for Node scopes. Update build.rolldownOptions.output.format in your config.`);
|
|
756
757
|
}
|
|
757
758
|
}
|
|
758
759
|
if (config.ssr === false || config.build?.ssr === false) throw new Error(`[electro] ${scope}: SSR cannot be disabled in Node scopes. SSR mode is required for correct Node.js module resolution.`);
|
|
@@ -766,11 +767,6 @@ function enforceMergedNodeConfig(config, _scope) {
|
|
|
766
767
|
const build = config.build;
|
|
767
768
|
if (!build) return;
|
|
768
769
|
if (build.target !== "esnext") build.target = "esnext";
|
|
769
|
-
const rolldownOpts = build.rolldownOptions;
|
|
770
|
-
if (rolldownOpts) {
|
|
771
|
-
const output = rolldownOpts.output;
|
|
772
|
-
if (output && output.format !== "es") output.format = "es";
|
|
773
|
-
}
|
|
774
770
|
if (!build.ssr) build.ssr = true;
|
|
775
771
|
}
|
|
776
772
|
/** Validate that installed Vite version is within the supported range. */
|
|
@@ -805,15 +801,69 @@ async function loadConfig(configPath) {
|
|
|
805
801
|
/**
|
|
806
802
|
* Resolve externals for Node scope builds (main/preload).
|
|
807
803
|
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
804
|
+
* Auto-externalizes: electron, Node builtins (bare + node: prefixed),
|
|
805
|
+
* package.json dependencies + optionalDependencies, and deep imports (pkg/subpath).
|
|
810
806
|
*/
|
|
811
|
-
function resolveExternals() {
|
|
812
|
-
|
|
807
|
+
async function resolveExternals(root) {
|
|
808
|
+
const pkgPath = resolve(root, "package.json");
|
|
809
|
+
const pkg = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
810
|
+
const deps = new Set([
|
|
813
811
|
"electron",
|
|
814
|
-
|
|
815
|
-
...
|
|
816
|
-
];
|
|
812
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
813
|
+
...Object.keys(pkg.optionalDependencies ?? {})
|
|
814
|
+
]);
|
|
815
|
+
deps.delete("@cordy/electro");
|
|
816
|
+
const builtins = builtinModules.flatMap((m) => [m, `node:${m}`]);
|
|
817
|
+
const depsArray = [...deps];
|
|
818
|
+
const deepPattern = depsArray.length > 0 ? new RegExp(`^(${depsArray.map(escapeRegExp).join("|")})/.+`) : null;
|
|
819
|
+
return deepPattern ? [
|
|
820
|
+
...depsArray,
|
|
821
|
+
...builtins,
|
|
822
|
+
deepPattern
|
|
823
|
+
] : [...depsArray, ...builtins];
|
|
824
|
+
}
|
|
825
|
+
function escapeRegExp(str) {
|
|
826
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
//#endregion
|
|
830
|
+
//#region src/dev/node-format.ts
|
|
831
|
+
/**
|
|
832
|
+
* Mirrors Node package behavior:
|
|
833
|
+
* - package.json "type": "module" => ESM output
|
|
834
|
+
* - otherwise => CJS output
|
|
835
|
+
*/
|
|
836
|
+
async function resolveNodeOutputFormat(root) {
|
|
837
|
+
const pkgPath = resolve(root, "package.json");
|
|
838
|
+
try {
|
|
839
|
+
const raw = await readFile(pkgPath, "utf-8");
|
|
840
|
+
return JSON.parse(raw).type === "module" ? "es" : "cjs";
|
|
841
|
+
} catch {
|
|
842
|
+
return "cjs";
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const MAIN_ENTRY_CANDIDATES = [
|
|
846
|
+
"index.mjs",
|
|
847
|
+
"index.cjs",
|
|
848
|
+
"index.js"
|
|
849
|
+
];
|
|
850
|
+
/**
|
|
851
|
+
* Find built main entry regardless of selected output format.
|
|
852
|
+
*/
|
|
853
|
+
async function resolveMainEntryPath(mainOutDir) {
|
|
854
|
+
for (const candidate of MAIN_ENTRY_CANDIDATES) {
|
|
855
|
+
const fullPath = resolve(mainOutDir, candidate);
|
|
856
|
+
if (await pathExists(fullPath)) return fullPath;
|
|
857
|
+
}
|
|
858
|
+
throw new Error(`Main entry not found in ${mainOutDir}. Expected one of: ${MAIN_ENTRY_CANDIDATES.join(", ")}`);
|
|
859
|
+
}
|
|
860
|
+
async function pathExists(filePath) {
|
|
861
|
+
try {
|
|
862
|
+
await access(filePath);
|
|
863
|
+
return true;
|
|
864
|
+
} catch {
|
|
865
|
+
return false;
|
|
866
|
+
}
|
|
817
867
|
}
|
|
818
868
|
|
|
819
869
|
//#endregion
|
|
@@ -1830,29 +1880,26 @@ var MagicString = class MagicString {
|
|
|
1830
1880
|
|
|
1831
1881
|
//#endregion
|
|
1832
1882
|
//#region src/plugins/esm-shim.ts
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
*
|
|
1836
|
-
* When bundling CJS dependencies into ESM format, the output may contain
|
|
1837
|
-
* references to `__filename`, `__dirname`, or `require()` which don't exist
|
|
1838
|
-
* in ES modules. This plugin detects those references and injects shims.
|
|
1839
|
-
*
|
|
1840
|
-
* Based on electron-vite's esmShimPlugin (from unbuild).
|
|
1841
|
-
*/
|
|
1842
|
-
const CJSyntaxRe = /__filename|__dirname|require\(|require\.resolve\(/;
|
|
1843
|
-
const CJSShim = `
|
|
1883
|
+
const CJSYNTAX_RE = /__filename|__dirname|require\(|require\.resolve\(/;
|
|
1884
|
+
const CJS_SHIM = `
|
|
1844
1885
|
// -- CommonJS Shims --
|
|
1845
|
-
import
|
|
1846
|
-
|
|
1847
|
-
|
|
1886
|
+
import __cjs_url__ from "node:url";
|
|
1887
|
+
import __cjs_path__ from "node:path";
|
|
1888
|
+
import __cjs_mod__ from "node:module";
|
|
1889
|
+
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
1890
|
+
const __dirname = __cjs_path__.dirname(__filename);
|
|
1848
1891
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
1849
1892
|
`;
|
|
1850
|
-
const
|
|
1893
|
+
const ESM_STATIC_IMPORT_RE = /(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
|
|
1851
1894
|
function findStaticImports(code) {
|
|
1852
1895
|
const matches = [];
|
|
1853
|
-
for (const match of code.matchAll(
|
|
1896
|
+
for (const match of code.matchAll(ESM_STATIC_IMPORT_RE)) matches.push({ end: (match.index || 0) + match[0].length });
|
|
1854
1897
|
return matches;
|
|
1855
1898
|
}
|
|
1899
|
+
/**
|
|
1900
|
+
* Inject CommonJS shims into ESM output when bundled code contains
|
|
1901
|
+
* require/__dirname/__filename references.
|
|
1902
|
+
*/
|
|
1856
1903
|
function esmShimPlugin() {
|
|
1857
1904
|
return {
|
|
1858
1905
|
name: "electro:esm-shim",
|
|
@@ -1860,11 +1907,11 @@ function esmShimPlugin() {
|
|
|
1860
1907
|
enforce: "post",
|
|
1861
1908
|
renderChunk(code, _chunk, { format, sourcemap }) {
|
|
1862
1909
|
if (format !== "es") return null;
|
|
1863
|
-
if (code.includes(
|
|
1864
|
-
const
|
|
1865
|
-
const indexToAppend =
|
|
1910
|
+
if (code.includes(CJS_SHIM) || !CJSYNTAX_RE.test(code)) return null;
|
|
1911
|
+
const lastImport = findStaticImports(code).pop();
|
|
1912
|
+
const indexToAppend = lastImport ? lastImport.end : 0;
|
|
1866
1913
|
const s = new MagicString(code);
|
|
1867
|
-
s.appendRight(indexToAppend,
|
|
1914
|
+
s.appendRight(indexToAppend, CJS_SHIM);
|
|
1868
1915
|
return {
|
|
1869
1916
|
code: s.toString(),
|
|
1870
1917
|
map: sourcemap ? s.generateMap({ hires: "boundary" }) : null
|
|
@@ -1873,6 +1920,26 @@ function esmShimPlugin() {
|
|
|
1873
1920
|
};
|
|
1874
1921
|
}
|
|
1875
1922
|
|
|
1923
|
+
//#endregion
|
|
1924
|
+
//#region src/plugins/import-meta.ts
|
|
1925
|
+
/**
|
|
1926
|
+
* Rewrites import.meta.* expressions for CommonJS output format.
|
|
1927
|
+
*/
|
|
1928
|
+
function importMetaPlugin() {
|
|
1929
|
+
return {
|
|
1930
|
+
name: "electro:import-meta",
|
|
1931
|
+
apply: "build",
|
|
1932
|
+
enforce: "pre",
|
|
1933
|
+
resolveImportMeta(property, { format }) {
|
|
1934
|
+
if (format !== "cjs") return null;
|
|
1935
|
+
if (property === "url") return `require("node:url").pathToFileURL(__filename).href`;
|
|
1936
|
+
if (property === "filename") return `__filename`;
|
|
1937
|
+
if (property === "dirname") return `__dirname`;
|
|
1938
|
+
return null;
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1876
1943
|
//#endregion
|
|
1877
1944
|
//#region src/dev/vite-node-config.ts
|
|
1878
1945
|
function resolveSourcemap$1(mode) {
|
|
@@ -1882,16 +1949,23 @@ function resolveSourcemap$1(mode) {
|
|
|
1882
1949
|
return true;
|
|
1883
1950
|
}
|
|
1884
1951
|
function createNodeConfig(opts) {
|
|
1952
|
+
const format = opts.format ?? "es";
|
|
1953
|
+
const moduleCondition = format === "cjs" ? "require" : "import";
|
|
1885
1954
|
const resolveConditions = opts.scope === "preload" ? [
|
|
1886
1955
|
"node",
|
|
1887
|
-
|
|
1956
|
+
moduleCondition,
|
|
1888
1957
|
"default"
|
|
1889
|
-
] : ["node",
|
|
1958
|
+
] : ["node", moduleCondition];
|
|
1890
1959
|
const envPrefix = opts.scope === "main" ? ["MAIN_VITE_", "VITE_"] : ["PRELOAD_VITE_", "VITE_"];
|
|
1960
|
+
const entryExt = format === "cjs" ? "cjs" : "mjs";
|
|
1891
1961
|
const config = {
|
|
1892
1962
|
configFile: false,
|
|
1893
1963
|
root: opts.root,
|
|
1894
|
-
plugins: [
|
|
1964
|
+
plugins: [
|
|
1965
|
+
importMetaPlugin(),
|
|
1966
|
+
...opts.plugins ?? [],
|
|
1967
|
+
esmShimPlugin()
|
|
1968
|
+
],
|
|
1895
1969
|
customLogger: opts.customLogger,
|
|
1896
1970
|
envPrefix,
|
|
1897
1971
|
define: {
|
|
@@ -1905,8 +1979,8 @@ function createNodeConfig(opts) {
|
|
|
1905
1979
|
emptyOutDir: true,
|
|
1906
1980
|
rolldownOptions: {
|
|
1907
1981
|
output: {
|
|
1908
|
-
format
|
|
1909
|
-
entryFileNames:
|
|
1982
|
+
format,
|
|
1983
|
+
entryFileNames: `index.${entryExt}`
|
|
1910
1984
|
},
|
|
1911
1985
|
external: opts.externals
|
|
1912
1986
|
},
|
|
@@ -1919,7 +1993,7 @@ function createNodeConfig(opts) {
|
|
|
1919
1993
|
},
|
|
1920
1994
|
ssr: {
|
|
1921
1995
|
target: "node",
|
|
1922
|
-
noExternal:
|
|
1996
|
+
noExternal: ["@cordy/electro"]
|
|
1923
1997
|
},
|
|
1924
1998
|
resolve: { conditions: resolveConditions },
|
|
1925
1999
|
logLevel: opts.logLevel ?? "warn",
|
|
@@ -2689,6 +2763,7 @@ async function build$1(options) {
|
|
|
2689
2763
|
const root = loaded.root;
|
|
2690
2764
|
const outDir = resolve(root, options.outDir);
|
|
2691
2765
|
const codegenDir = resolve(root, ".electro");
|
|
2766
|
+
const nodeFormat = await resolveNodeOutputFormat(root);
|
|
2692
2767
|
const views = config.views ?? [];
|
|
2693
2768
|
const rendererViews = views.filter((v) => v.entry);
|
|
2694
2769
|
const srcDir = resolve(root, "src");
|
|
@@ -2725,7 +2800,7 @@ async function build$1(options) {
|
|
|
2725
2800
|
stepFail("codegen", err instanceof Error ? err.message : String(err));
|
|
2726
2801
|
process.exit(1);
|
|
2727
2802
|
}
|
|
2728
|
-
const externals = resolveExternals();
|
|
2803
|
+
const externals = await resolveExternals(root);
|
|
2729
2804
|
const logger = createBuildLogger();
|
|
2730
2805
|
try {
|
|
2731
2806
|
buildScope("main");
|
|
@@ -2736,7 +2811,8 @@ async function build$1(options) {
|
|
|
2736
2811
|
externals,
|
|
2737
2812
|
sourcemap: options.sourcemap,
|
|
2738
2813
|
logger,
|
|
2739
|
-
bytecode: options.bytecode
|
|
2814
|
+
bytecode: options.bytecode,
|
|
2815
|
+
format: nodeFormat
|
|
2740
2816
|
});
|
|
2741
2817
|
} catch (err) {
|
|
2742
2818
|
stepFail("main", err instanceof Error ? err.message : String(err));
|
|
@@ -2752,7 +2828,8 @@ async function build$1(options) {
|
|
|
2752
2828
|
externals,
|
|
2753
2829
|
sourcemap: options.sourcemap,
|
|
2754
2830
|
logger,
|
|
2755
|
-
bytecode: options.bytecode
|
|
2831
|
+
bytecode: options.bytecode,
|
|
2832
|
+
format: nodeFormat
|
|
2756
2833
|
});
|
|
2757
2834
|
} catch (err) {
|
|
2758
2835
|
stepFail("preload", err instanceof Error ? err.message : String(err));
|
|
@@ -2804,6 +2881,7 @@ async function buildMain(args) {
|
|
|
2804
2881
|
sourcemap: args.sourcemap,
|
|
2805
2882
|
customLogger: args.logger,
|
|
2806
2883
|
logLevel: "info",
|
|
2884
|
+
format: args.format,
|
|
2807
2885
|
define: { __ELECTRO_VIEW_REGISTRY__: JSON.stringify(viewRegistry) }
|
|
2808
2886
|
}));
|
|
2809
2887
|
}
|
|
@@ -2829,7 +2907,8 @@ async function buildPreload(args) {
|
|
|
2829
2907
|
plugins: preloadPlugins,
|
|
2830
2908
|
sourcemap: args.sourcemap,
|
|
2831
2909
|
customLogger: args.logger,
|
|
2832
|
-
logLevel: "info"
|
|
2910
|
+
logLevel: "info",
|
|
2911
|
+
format: args.format
|
|
2833
2912
|
});
|
|
2834
2913
|
if (Object.keys(input).length > 1) {
|
|
2835
2914
|
const subBuildConfig = createNodeConfig({
|
|
@@ -2846,7 +2925,8 @@ async function buildPreload(args) {
|
|
|
2846
2925
|
],
|
|
2847
2926
|
sourcemap: args.sourcemap,
|
|
2848
2927
|
customLogger: args.logger,
|
|
2849
|
-
logLevel: "info"
|
|
2928
|
+
logLevel: "info",
|
|
2929
|
+
format: args.format
|
|
2850
2930
|
});
|
|
2851
2931
|
baseConfig.plugins.push(isolateEntriesPlugin(subBuildConfig));
|
|
2852
2932
|
}
|
|
@@ -2891,6 +2971,8 @@ async function flattenRendererOutput(rendererDir, views, root) {
|
|
|
2891
2971
|
//#region src/dev/dev-server.ts
|
|
2892
2972
|
const MAIN_RESTART_DEBOUNCE_MS = 80;
|
|
2893
2973
|
const CONFIG_DEBOUNCE_MS = 300;
|
|
2974
|
+
const MAIN_ENTRY_WAIT_TIMEOUT_MS = 1e4;
|
|
2975
|
+
const MAIN_ENTRY_WAIT_INTERVAL_MS = 50;
|
|
2894
2976
|
var DevServer = class {
|
|
2895
2977
|
rendererServer = null;
|
|
2896
2978
|
electronProcess = null;
|
|
@@ -2909,6 +2991,9 @@ var DevServer = class {
|
|
|
2909
2991
|
mainWatch = null;
|
|
2910
2992
|
preloadWatch = null;
|
|
2911
2993
|
outputDir = "";
|
|
2994
|
+
nodeFormat = "es";
|
|
2995
|
+
mainInitialBuildPromise = null;
|
|
2996
|
+
resolveMainInitialBuild = null;
|
|
2912
2997
|
logLevel;
|
|
2913
2998
|
clearScreen;
|
|
2914
2999
|
rendererOnly;
|
|
@@ -2936,6 +3021,7 @@ var DevServer = class {
|
|
|
2936
3021
|
this.config = loaded.config;
|
|
2937
3022
|
this.root = loaded.root;
|
|
2938
3023
|
this.outputDir = this.outDirOverride ? resolve(this.root, this.outDirOverride) : resolve(this.root, ".electro");
|
|
3024
|
+
this.nodeFormat = await resolveNodeOutputFormat(this.root);
|
|
2939
3025
|
this.configPaths.add(loaded.configPath);
|
|
2940
3026
|
for (const view of this.config.views ?? []) this.configPaths.add(view.__source);
|
|
2941
3027
|
const views = this.config.views ?? [];
|
|
@@ -2976,7 +3062,7 @@ var DevServer = class {
|
|
|
2976
3062
|
this.attachConfigWatcher();
|
|
2977
3063
|
return;
|
|
2978
3064
|
}
|
|
2979
|
-
const externals = resolveExternals();
|
|
3065
|
+
const externals = await resolveExternals(this.root);
|
|
2980
3066
|
if (views.length > 0) {
|
|
2981
3067
|
const preloadTimer = startTimer();
|
|
2982
3068
|
try {
|
|
@@ -2997,6 +3083,7 @@ var DevServer = class {
|
|
|
2997
3083
|
}
|
|
2998
3084
|
const electronTimer = startTimer();
|
|
2999
3085
|
try {
|
|
3086
|
+
await this.waitForMainInitialBuild();
|
|
3000
3087
|
await this.attachElectronProcess();
|
|
3001
3088
|
step("electron", electronTimer());
|
|
3002
3089
|
} catch (err) {
|
|
@@ -3025,6 +3112,8 @@ var DevServer = class {
|
|
|
3025
3112
|
this.mainWatch = null;
|
|
3026
3113
|
this.preloadWatch?.close();
|
|
3027
3114
|
this.preloadWatch = null;
|
|
3115
|
+
this.resolveMainInitialBuild = null;
|
|
3116
|
+
this.mainInitialBuildPromise = null;
|
|
3028
3117
|
if (this.mainRestartFlushTimer) {
|
|
3029
3118
|
clearTimeout(this.mainRestartFlushTimer);
|
|
3030
3119
|
this.mainRestartFlushTimer = null;
|
|
@@ -3093,7 +3182,8 @@ var DevServer = class {
|
|
|
3093
3182
|
],
|
|
3094
3183
|
logLevel: this.logLevel,
|
|
3095
3184
|
clearScreen: this.clearScreen,
|
|
3096
|
-
sourcemap: this.sourcemap
|
|
3185
|
+
sourcemap: this.sourcemap,
|
|
3186
|
+
format: this.nodeFormat
|
|
3097
3187
|
});
|
|
3098
3188
|
if (Object.keys(input).length > 1) {
|
|
3099
3189
|
const subBuildConfig = createNodeConfig({
|
|
@@ -3110,7 +3200,8 @@ var DevServer = class {
|
|
|
3110
3200
|
],
|
|
3111
3201
|
logLevel: this.logLevel,
|
|
3112
3202
|
clearScreen: this.clearScreen,
|
|
3113
|
-
sourcemap: this.sourcemap
|
|
3203
|
+
sourcemap: this.sourcemap,
|
|
3204
|
+
format: this.nodeFormat
|
|
3114
3205
|
});
|
|
3115
3206
|
baseConfig.plugins.push(isolateEntriesPlugin(subBuildConfig));
|
|
3116
3207
|
}
|
|
@@ -3139,6 +3230,12 @@ var DevServer = class {
|
|
|
3139
3230
|
async buildMain(externals) {
|
|
3140
3231
|
const runtimeEntry = this.config.runtime.entry;
|
|
3141
3232
|
const entry = resolve(dirname(this.config.runtime.__source), runtimeEntry);
|
|
3233
|
+
this.mainInitialBuildPromise = new Promise((resolve) => {
|
|
3234
|
+
this.resolveMainInitialBuild = () => {
|
|
3235
|
+
resolve();
|
|
3236
|
+
this.resolveMainInitialBuild = null;
|
|
3237
|
+
};
|
|
3238
|
+
});
|
|
3142
3239
|
const viewRegistry = (this.config.views ?? []).map((v) => ({
|
|
3143
3240
|
id: v.name,
|
|
3144
3241
|
hasRenderer: !!v.entry,
|
|
@@ -3161,6 +3258,7 @@ var DevServer = class {
|
|
|
3161
3258
|
clearScreen: this.clearScreen,
|
|
3162
3259
|
userViteConfig: this.config.runtime.vite,
|
|
3163
3260
|
sourcemap: this.sourcemap,
|
|
3261
|
+
format: this.nodeFormat,
|
|
3164
3262
|
define: { __ELECTRO_VIEW_REGISTRY__: JSON.stringify(viewRegistry) }
|
|
3165
3263
|
});
|
|
3166
3264
|
const self = this;
|
|
@@ -3176,6 +3274,7 @@ var DevServer = class {
|
|
|
3176
3274
|
if (firstBuild) {
|
|
3177
3275
|
firstBuild = false;
|
|
3178
3276
|
changedFile = null;
|
|
3277
|
+
self.resolveMainInitialBuild?.();
|
|
3179
3278
|
return;
|
|
3180
3279
|
}
|
|
3181
3280
|
const currentChanged = changedFile;
|
|
@@ -3191,8 +3290,21 @@ var DevServer = class {
|
|
|
3191
3290
|
});
|
|
3192
3291
|
this.mainWatch = await build(mainConfig);
|
|
3193
3292
|
}
|
|
3293
|
+
/**
|
|
3294
|
+
* Primary startup synchronization for dev mode:
|
|
3295
|
+
* wait until the initial main watch build has completed.
|
|
3296
|
+
*/
|
|
3297
|
+
async waitForMainInitialBuild() {
|
|
3298
|
+
if (!this.mainInitialBuildPromise) return;
|
|
3299
|
+
const timeout = setTimeout$1(MAIN_ENTRY_WAIT_TIMEOUT_MS).then(() => {
|
|
3300
|
+
throw new Error(`Main initial build did not finish in ${MAIN_ENTRY_WAIT_TIMEOUT_MS}ms.`);
|
|
3301
|
+
});
|
|
3302
|
+
const promise = this.mainInitialBuildPromise;
|
|
3303
|
+
this.mainInitialBuildPromise = null;
|
|
3304
|
+
await Promise.race([promise, timeout]);
|
|
3305
|
+
}
|
|
3194
3306
|
async attachElectronProcess() {
|
|
3195
|
-
const mainEntry =
|
|
3307
|
+
const mainEntry = await this.waitForMainEntry();
|
|
3196
3308
|
const env = { ELECTRO_DEV: "true" };
|
|
3197
3309
|
if (this.rendererServer) {
|
|
3198
3310
|
const addr = this.rendererServer.httpServer?.address();
|
|
@@ -3221,6 +3333,23 @@ var DevServer = class {
|
|
|
3221
3333
|
});
|
|
3222
3334
|
}
|
|
3223
3335
|
/**
|
|
3336
|
+
* In watch mode, Vite can return the watcher before the first output file
|
|
3337
|
+
* is written. Wait for the built main entry to appear before spawning Electron.
|
|
3338
|
+
*/
|
|
3339
|
+
async waitForMainEntry() {
|
|
3340
|
+
const mainOutDir = resolve(this.outputDir, "main");
|
|
3341
|
+
const deadline = Date.now() + MAIN_ENTRY_WAIT_TIMEOUT_MS;
|
|
3342
|
+
let lastError;
|
|
3343
|
+
while (Date.now() < deadline) try {
|
|
3344
|
+
return await resolveMainEntryPath(mainOutDir);
|
|
3345
|
+
} catch (err) {
|
|
3346
|
+
lastError = err;
|
|
3347
|
+
await setTimeout$1(MAIN_ENTRY_WAIT_INTERVAL_MS);
|
|
3348
|
+
}
|
|
3349
|
+
const detail = lastError instanceof Error ? ` Last error: ${lastError.message}` : "";
|
|
3350
|
+
throw new Error(`Main entry was not generated in time (${MAIN_ENTRY_WAIT_TIMEOUT_MS}ms). Checked in: ${mainOutDir}.${detail}`);
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3224
3353
|
* Restart Electron — handles queued restarts if another rebuild
|
|
3225
3354
|
* arrives while restart is in flight.
|
|
3226
3355
|
*/
|
|
@@ -3374,7 +3503,7 @@ async function preview(options) {
|
|
|
3374
3503
|
if (!options.skipBuild) await build$1(options);
|
|
3375
3504
|
else note("Skipped build (--skip-build)");
|
|
3376
3505
|
const root = process.cwd();
|
|
3377
|
-
const mainEntry = resolve(resolve(root, options.outDir), "main
|
|
3506
|
+
const mainEntry = await resolveMainEntryPath(resolve(resolve(root, options.outDir), "main"));
|
|
3378
3507
|
const launchTimer = startTimer();
|
|
3379
3508
|
try {
|
|
3380
3509
|
const proc = await launchElectron({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordy/electro-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "CLI for @cordy/electro — dev server, build, and code generation commands",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -47,15 +47,15 @@
|
|
|
47
47
|
"prepublishOnly": "bun run build"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@cordy/electro": "1.2.
|
|
50
|
+
"@cordy/electro": "1.2.8",
|
|
51
51
|
"electron": ">=40.4.1",
|
|
52
52
|
"vite": ">=8.0.0"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@cordy/electro-generator": "1.2.
|
|
55
|
+
"@cordy/electro-generator": "1.2.8"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@cordy/electro": "1.2.
|
|
58
|
+
"@cordy/electro": "1.2.6",
|
|
59
59
|
"@types/node": "^25.2.3",
|
|
60
60
|
"cac": "^6.7.14",
|
|
61
61
|
"electron": "^40.4.1",
|