@cordy/electro-cli 1.2.5 → 1.2.7
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 +186 -155
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -490,7 +490,7 @@ const cac = (name = "") => new CAC(name);
|
|
|
490
490
|
|
|
491
491
|
//#endregion
|
|
492
492
|
//#region package.json
|
|
493
|
-
var version$1 = "1.2.
|
|
493
|
+
var version$1 = "1.2.7";
|
|
494
494
|
|
|
495
495
|
//#endregion
|
|
496
496
|
//#region src/dev/logger.ts
|
|
@@ -805,160 +805,15 @@ async function loadConfig(configPath) {
|
|
|
805
805
|
/**
|
|
806
806
|
* Resolve externals for Node scope builds (main/preload).
|
|
807
807
|
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
808
|
+
* Only externalizes electron and Node builtins.
|
|
809
|
+
* All npm dependencies are bundled by Vite (handles CJS→ESM conversion).
|
|
810
810
|
*/
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
const pkg = JSON.parse(await readFile(pkgPath, "utf-8"));
|
|
814
|
-
const deps = new Set([
|
|
811
|
+
function resolveExternals() {
|
|
812
|
+
return [
|
|
815
813
|
"electron",
|
|
816
|
-
|
|
817
|
-
...
|
|
818
|
-
]
|
|
819
|
-
deps.delete("@cordy/electro");
|
|
820
|
-
const builtins = builtinModules.flatMap((m) => [m, `node:${m}`]);
|
|
821
|
-
const depsArray = [...deps];
|
|
822
|
-
const deepPattern = depsArray.length > 0 ? new RegExp(`^(${depsArray.map(escapeRegExp).join("|")})/.+`) : null;
|
|
823
|
-
return deepPattern ? [
|
|
824
|
-
...depsArray,
|
|
825
|
-
...builtins,
|
|
826
|
-
deepPattern
|
|
827
|
-
] : [...depsArray, ...builtins];
|
|
828
|
-
}
|
|
829
|
-
function escapeRegExp(str) {
|
|
830
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
//#endregion
|
|
834
|
-
//#region src/dev/vite-node-config.ts
|
|
835
|
-
function resolveSourcemap$1(mode) {
|
|
836
|
-
if (!mode || mode === "linked" || mode === "external") return true;
|
|
837
|
-
if (mode === "inline") return "inline";
|
|
838
|
-
if (mode === "none") return false;
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
function createNodeConfig(opts) {
|
|
842
|
-
const resolveConditions = opts.scope === "preload" ? [
|
|
843
|
-
"node",
|
|
844
|
-
"import",
|
|
845
|
-
"default"
|
|
846
|
-
] : ["node", "import"];
|
|
847
|
-
const envPrefix = opts.scope === "main" ? ["MAIN_VITE_", "VITE_"] : ["PRELOAD_VITE_", "VITE_"];
|
|
848
|
-
const config = {
|
|
849
|
-
configFile: false,
|
|
850
|
-
root: opts.root,
|
|
851
|
-
plugins: opts.plugins ?? [],
|
|
852
|
-
customLogger: opts.customLogger,
|
|
853
|
-
envPrefix,
|
|
854
|
-
define: {
|
|
855
|
-
"process.env": "process.env",
|
|
856
|
-
...opts.define
|
|
857
|
-
},
|
|
858
|
-
build: {
|
|
859
|
-
ssr: opts.entry,
|
|
860
|
-
ssrEmitAssets: true,
|
|
861
|
-
outDir: opts.outDir,
|
|
862
|
-
emptyOutDir: true,
|
|
863
|
-
rolldownOptions: {
|
|
864
|
-
output: {
|
|
865
|
-
format: "es",
|
|
866
|
-
entryFileNames: "index.mjs"
|
|
867
|
-
},
|
|
868
|
-
external: opts.externals
|
|
869
|
-
},
|
|
870
|
-
target: "esnext",
|
|
871
|
-
sourcemap: resolveSourcemap$1(opts.sourcemap),
|
|
872
|
-
minify: false,
|
|
873
|
-
modulePreload: false,
|
|
874
|
-
watch: opts.watch ? {} : null,
|
|
875
|
-
reportCompressedSize: !opts.watch
|
|
876
|
-
},
|
|
877
|
-
ssr: {
|
|
878
|
-
target: "node",
|
|
879
|
-
noExternal: ["@cordy/electro"]
|
|
880
|
-
},
|
|
881
|
-
resolve: { conditions: resolveConditions },
|
|
882
|
-
logLevel: opts.logLevel ?? "warn",
|
|
883
|
-
clearScreen: opts.clearScreen
|
|
884
|
-
};
|
|
885
|
-
if (opts.scope === "main") {
|
|
886
|
-
const resourcesDir = resolve(opts.root, "resources");
|
|
887
|
-
if (existsSync(resourcesDir)) config.publicDir = resourcesDir;
|
|
888
|
-
}
|
|
889
|
-
if (opts.userViteConfig) {
|
|
890
|
-
const merged = mergeConfig(config, opts.userViteConfig);
|
|
891
|
-
validateMergedNodeConfig(merged, opts.scope);
|
|
892
|
-
enforceMergedNodeConfig(merged, opts.scope);
|
|
893
|
-
return merged;
|
|
894
|
-
}
|
|
895
|
-
return config;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
//#endregion
|
|
899
|
-
//#region src/dev/vite-renderer-config.ts
|
|
900
|
-
function resolveSourcemap(mode) {
|
|
901
|
-
if (!mode || mode === "linked" || mode === "external") return true;
|
|
902
|
-
if (mode === "inline") return "inline";
|
|
903
|
-
if (mode === "none") return false;
|
|
904
|
-
return true;
|
|
905
|
-
}
|
|
906
|
-
function createRendererConfig(opts) {
|
|
907
|
-
const input = {};
|
|
908
|
-
for (const view of opts.views) {
|
|
909
|
-
const sourceDir = dirname(view.__source);
|
|
910
|
-
input[view.name] = resolve(sourceDir, view.entry);
|
|
911
|
-
}
|
|
912
|
-
const isBuild = !!opts.outDir;
|
|
913
|
-
const config = {
|
|
914
|
-
configFile: false,
|
|
915
|
-
root: opts.root,
|
|
916
|
-
customLogger: opts.customLogger,
|
|
917
|
-
envPrefix: ["RENDERER_VITE_", "VITE_"],
|
|
918
|
-
...!isBuild && { server: { strictPort: false } },
|
|
919
|
-
...isBuild && { base: "./" },
|
|
920
|
-
build: {
|
|
921
|
-
rolldownOptions: { input },
|
|
922
|
-
...isBuild && {
|
|
923
|
-
outDir: opts.outDir,
|
|
924
|
-
emptyOutDir: true,
|
|
925
|
-
minify: opts.minify ?? true,
|
|
926
|
-
sourcemap: resolveSourcemap(opts.sourcemap),
|
|
927
|
-
reportCompressedSize: true,
|
|
928
|
-
modulePreload: { polyfill: false }
|
|
929
|
-
}
|
|
930
|
-
},
|
|
931
|
-
logLevel: opts.logLevel ?? "info",
|
|
932
|
-
clearScreen: opts.clearScreen
|
|
933
|
-
};
|
|
934
|
-
if (opts.userViteConfigs?.length) {
|
|
935
|
-
let merged = config;
|
|
936
|
-
for (const userConfig of opts.userViteConfigs) merged = mergeConfig(merged, userConfig);
|
|
937
|
-
merged.plugins = deduplicatePlugins(merged.plugins);
|
|
938
|
-
return merged;
|
|
939
|
-
}
|
|
940
|
-
return config;
|
|
941
|
-
}
|
|
942
|
-
/**
|
|
943
|
-
* Deduplicate plugins by name — keeps the first occurrence of each named plugin.
|
|
944
|
-
* This allows multiple views to declare the same plugins (e.g. react()) without
|
|
945
|
-
* causing duplicate injection errors when configs are merged.
|
|
946
|
-
*/
|
|
947
|
-
function deduplicatePlugins(plugins) {
|
|
948
|
-
if (!plugins) return [];
|
|
949
|
-
const seen = /* @__PURE__ */ new Set();
|
|
950
|
-
const result = [];
|
|
951
|
-
for (const plugin of plugins.flat(Infinity)) {
|
|
952
|
-
const name = plugin?.name;
|
|
953
|
-
if (!name) {
|
|
954
|
-
result.push(plugin);
|
|
955
|
-
continue;
|
|
956
|
-
}
|
|
957
|
-
if (seen.has(name)) continue;
|
|
958
|
-
seen.add(name);
|
|
959
|
-
result.push(plugin);
|
|
960
|
-
}
|
|
961
|
-
return result;
|
|
814
|
+
/^electron\/.+/,
|
|
815
|
+
...builtinModules.flatMap((m) => [m, `node:${m}`])
|
|
816
|
+
];
|
|
962
817
|
}
|
|
963
818
|
|
|
964
819
|
//#endregion
|
|
@@ -1973,6 +1828,182 @@ var MagicString = class MagicString {
|
|
|
1973
1828
|
}
|
|
1974
1829
|
};
|
|
1975
1830
|
|
|
1831
|
+
//#endregion
|
|
1832
|
+
//#region src/plugins/esm-shim.ts
|
|
1833
|
+
/**
|
|
1834
|
+
* ESM Shim Plugin — injects CommonJS shims into ESM output.
|
|
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 = `
|
|
1844
|
+
// -- CommonJS Shims --
|
|
1845
|
+
import __cjs_mod__ from 'node:module';
|
|
1846
|
+
const __filename = import.meta.filename;
|
|
1847
|
+
const __dirname = import.meta.dirname;
|
|
1848
|
+
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
1849
|
+
`;
|
|
1850
|
+
const ESMStaticImportRe = /(?<=\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
|
+
function findStaticImports(code) {
|
|
1852
|
+
const matches = [];
|
|
1853
|
+
for (const match of code.matchAll(ESMStaticImportRe)) matches.push({ end: (match.index || 0) + match[0].length });
|
|
1854
|
+
return matches;
|
|
1855
|
+
}
|
|
1856
|
+
function esmShimPlugin() {
|
|
1857
|
+
return {
|
|
1858
|
+
name: "electro:esm-shim",
|
|
1859
|
+
apply: "build",
|
|
1860
|
+
enforce: "post",
|
|
1861
|
+
renderChunk(code, _chunk, { format, sourcemap }) {
|
|
1862
|
+
if (format !== "es") return null;
|
|
1863
|
+
if (code.includes(CJSShim) || !CJSyntaxRe.test(code)) return null;
|
|
1864
|
+
const lastESMImport = findStaticImports(code).pop();
|
|
1865
|
+
const indexToAppend = lastESMImport ? lastESMImport.end : 0;
|
|
1866
|
+
const s = new MagicString(code);
|
|
1867
|
+
s.appendRight(indexToAppend, CJSShim);
|
|
1868
|
+
return {
|
|
1869
|
+
code: s.toString(),
|
|
1870
|
+
map: sourcemap ? s.generateMap({ hires: "boundary" }) : null
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
//#endregion
|
|
1877
|
+
//#region src/dev/vite-node-config.ts
|
|
1878
|
+
function resolveSourcemap$1(mode) {
|
|
1879
|
+
if (!mode || mode === "linked" || mode === "external") return true;
|
|
1880
|
+
if (mode === "inline") return "inline";
|
|
1881
|
+
if (mode === "none") return false;
|
|
1882
|
+
return true;
|
|
1883
|
+
}
|
|
1884
|
+
function createNodeConfig(opts) {
|
|
1885
|
+
const resolveConditions = opts.scope === "preload" ? [
|
|
1886
|
+
"node",
|
|
1887
|
+
"import",
|
|
1888
|
+
"default"
|
|
1889
|
+
] : ["node", "import"];
|
|
1890
|
+
const envPrefix = opts.scope === "main" ? ["MAIN_VITE_", "VITE_"] : ["PRELOAD_VITE_", "VITE_"];
|
|
1891
|
+
const config = {
|
|
1892
|
+
configFile: false,
|
|
1893
|
+
root: opts.root,
|
|
1894
|
+
plugins: [esmShimPlugin(), ...opts.plugins ?? []],
|
|
1895
|
+
customLogger: opts.customLogger,
|
|
1896
|
+
envPrefix,
|
|
1897
|
+
define: {
|
|
1898
|
+
"process.env": "process.env",
|
|
1899
|
+
...opts.define
|
|
1900
|
+
},
|
|
1901
|
+
build: {
|
|
1902
|
+
ssr: opts.entry,
|
|
1903
|
+
ssrEmitAssets: true,
|
|
1904
|
+
outDir: opts.outDir,
|
|
1905
|
+
emptyOutDir: true,
|
|
1906
|
+
rolldownOptions: {
|
|
1907
|
+
output: {
|
|
1908
|
+
format: "es",
|
|
1909
|
+
entryFileNames: "index.mjs"
|
|
1910
|
+
},
|
|
1911
|
+
external: opts.externals
|
|
1912
|
+
},
|
|
1913
|
+
target: "esnext",
|
|
1914
|
+
sourcemap: resolveSourcemap$1(opts.sourcemap),
|
|
1915
|
+
minify: false,
|
|
1916
|
+
modulePreload: false,
|
|
1917
|
+
watch: opts.watch ? {} : null,
|
|
1918
|
+
reportCompressedSize: !opts.watch
|
|
1919
|
+
},
|
|
1920
|
+
ssr: {
|
|
1921
|
+
target: "node",
|
|
1922
|
+
noExternal: true
|
|
1923
|
+
},
|
|
1924
|
+
resolve: { conditions: resolveConditions },
|
|
1925
|
+
logLevel: opts.logLevel ?? "warn",
|
|
1926
|
+
clearScreen: opts.clearScreen
|
|
1927
|
+
};
|
|
1928
|
+
if (opts.scope === "main") {
|
|
1929
|
+
const resourcesDir = resolve(opts.root, "resources");
|
|
1930
|
+
if (existsSync(resourcesDir)) config.publicDir = resourcesDir;
|
|
1931
|
+
}
|
|
1932
|
+
if (opts.userViteConfig) {
|
|
1933
|
+
const merged = mergeConfig(config, opts.userViteConfig);
|
|
1934
|
+
validateMergedNodeConfig(merged, opts.scope);
|
|
1935
|
+
enforceMergedNodeConfig(merged, opts.scope);
|
|
1936
|
+
return merged;
|
|
1937
|
+
}
|
|
1938
|
+
return config;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
//#endregion
|
|
1942
|
+
//#region src/dev/vite-renderer-config.ts
|
|
1943
|
+
function resolveSourcemap(mode) {
|
|
1944
|
+
if (!mode || mode === "linked" || mode === "external") return true;
|
|
1945
|
+
if (mode === "inline") return "inline";
|
|
1946
|
+
if (mode === "none") return false;
|
|
1947
|
+
return true;
|
|
1948
|
+
}
|
|
1949
|
+
function createRendererConfig(opts) {
|
|
1950
|
+
const input = {};
|
|
1951
|
+
for (const view of opts.views) {
|
|
1952
|
+
const sourceDir = dirname(view.__source);
|
|
1953
|
+
input[view.name] = resolve(sourceDir, view.entry);
|
|
1954
|
+
}
|
|
1955
|
+
const isBuild = !!opts.outDir;
|
|
1956
|
+
const config = {
|
|
1957
|
+
configFile: false,
|
|
1958
|
+
root: opts.root,
|
|
1959
|
+
customLogger: opts.customLogger,
|
|
1960
|
+
envPrefix: ["RENDERER_VITE_", "VITE_"],
|
|
1961
|
+
...!isBuild && { server: { strictPort: false } },
|
|
1962
|
+
...isBuild && { base: "./" },
|
|
1963
|
+
build: {
|
|
1964
|
+
rolldownOptions: { input },
|
|
1965
|
+
...isBuild && {
|
|
1966
|
+
outDir: opts.outDir,
|
|
1967
|
+
emptyOutDir: true,
|
|
1968
|
+
minify: opts.minify ?? true,
|
|
1969
|
+
sourcemap: resolveSourcemap(opts.sourcemap),
|
|
1970
|
+
reportCompressedSize: true,
|
|
1971
|
+
modulePreload: { polyfill: false }
|
|
1972
|
+
}
|
|
1973
|
+
},
|
|
1974
|
+
logLevel: opts.logLevel ?? "info",
|
|
1975
|
+
clearScreen: opts.clearScreen
|
|
1976
|
+
};
|
|
1977
|
+
if (opts.userViteConfigs?.length) {
|
|
1978
|
+
let merged = config;
|
|
1979
|
+
for (const userConfig of opts.userViteConfigs) merged = mergeConfig(merged, userConfig);
|
|
1980
|
+
merged.plugins = deduplicatePlugins(merged.plugins);
|
|
1981
|
+
return merged;
|
|
1982
|
+
}
|
|
1983
|
+
return config;
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Deduplicate plugins by name — keeps the first occurrence of each named plugin.
|
|
1987
|
+
* This allows multiple views to declare the same plugins (e.g. react()) without
|
|
1988
|
+
* causing duplicate injection errors when configs are merged.
|
|
1989
|
+
*/
|
|
1990
|
+
function deduplicatePlugins(plugins) {
|
|
1991
|
+
if (!plugins) return [];
|
|
1992
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1993
|
+
const result = [];
|
|
1994
|
+
for (const plugin of plugins.flat(Infinity)) {
|
|
1995
|
+
const name = plugin?.name;
|
|
1996
|
+
if (!name) {
|
|
1997
|
+
result.push(plugin);
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
if (seen.has(name)) continue;
|
|
2001
|
+
seen.add(name);
|
|
2002
|
+
result.push(plugin);
|
|
2003
|
+
}
|
|
2004
|
+
return result;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
1976
2007
|
//#endregion
|
|
1977
2008
|
//#region src/plugins/utils.ts
|
|
1978
2009
|
/** Strip query and hash from a URL/path. */
|
|
@@ -2694,7 +2725,7 @@ async function build$1(options) {
|
|
|
2694
2725
|
stepFail("codegen", err instanceof Error ? err.message : String(err));
|
|
2695
2726
|
process.exit(1);
|
|
2696
2727
|
}
|
|
2697
|
-
const externals =
|
|
2728
|
+
const externals = resolveExternals();
|
|
2698
2729
|
const logger = createBuildLogger();
|
|
2699
2730
|
try {
|
|
2700
2731
|
buildScope("main");
|
|
@@ -2945,7 +2976,7 @@ var DevServer = class {
|
|
|
2945
2976
|
this.attachConfigWatcher();
|
|
2946
2977
|
return;
|
|
2947
2978
|
}
|
|
2948
|
-
const externals =
|
|
2979
|
+
const externals = resolveExternals();
|
|
2949
2980
|
if (views.length > 0) {
|
|
2950
2981
|
const preloadTimer = startTimer();
|
|
2951
2982
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cordy/electro-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
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.7",
|
|
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.7"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@cordy/electro": "1.2.
|
|
58
|
+
"@cordy/electro": "1.2.7",
|
|
59
59
|
"@types/node": "^25.2.3",
|
|
60
60
|
"cac": "^6.7.14",
|
|
61
61
|
"electron": "^40.4.1",
|