electron-incremental-update 3.0.0 → 3.1.1

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/README.md CHANGED
@@ -242,7 +242,8 @@ Common options overview:
242
242
  - `sourcemap`: defaults to development or `VSCODE_DEBUG`.
243
243
  - `minify`: defaults to production builds.
244
244
  - `bytecode`: `true` or bytecode options.
245
- - `notBundle`: externalizes Node modules in development. Defaults to `true`.
245
+ - `bundleDeps`: controls dependency bundling. Defaults to Vite's server-environment behavior.
246
+ `electron-incremental-update` is always bundled.
246
247
  - `external`: additional Vite/Rolldown externals. Use `true` to externalize `dependencies`.
247
248
  - `buildVersionJson`: generates update JSON. Defaults to CI only.
248
249
  - `localDevUpdate`: generates and serves a local update package during dev startup. Use `true`
@@ -565,13 +566,21 @@ Notes:
565
566
  - To include preload scripts, use `bytecode: { enablePreload: true }`.
566
567
  - If preload bytecode is enabled, create the `BrowserWindow` with `sandbox: false`.
567
568
 
568
- ## Development Bundling
569
+ ## Dependency Bundling
569
570
 
570
- `notBundle` is enabled by default in development. It externalizes Node modules in entry and main builds to improve startup speed.
571
+ `bundleDeps` controls dependency handling for entry, main, and preload environments. It defaults to
572
+ `'vite'`, which preserves Vite's server-environment behavior.
571
573
 
572
574
  ```ts
573
575
  electronWithUpdater({
574
- notBundle: false,
576
+ bundleDeps: {
577
+ dev: {
578
+ exclude: true,
579
+ },
580
+ build: {
581
+ include: ['some-dependency'],
582
+ },
583
+ },
575
584
  entry: {
576
585
  files: './electron/entry.ts',
577
586
  },
@@ -581,6 +590,12 @@ electronWithUpdater({
581
590
  })
582
591
  ```
583
592
 
593
+ Use `'auto'` to bundle all dependencies except package.json dependencies, `true` to bundle all
594
+ dependencies, or `false` to externalize all dependencies. `both` applies a policy in both modes
595
+ and is merged with the active `dev` or `build` policy. `include` maps to Vite's
596
+ `resolve.noExternal`; `exclude` maps to `resolve.external`. `electron-incremental-update` and its
597
+ subpath imports are always bundled.
598
+
584
599
  ## Utilities
585
600
 
586
601
  Import from `electron-incremental-update/utils` for path helpers, platform checks, native module loading, crypto, compression, download, and version parsing utilities.
package/dist/vite.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Plugin, UserConfig } from "vite";
2
2
  import { MultiEnvElectronOptions } from "vite-plugin-electron/multi-env";
3
- import { RolldownOrRollupOptions } from "vite-plugin-electron";
3
+ import { CreateOptions } from "@electron/asar";
4
4
 
5
5
  //#region src/utils/type.d.ts
6
6
  type Promisable<T> = T | Promise<T>;
@@ -124,7 +124,12 @@ interface CommonBuildOption {
124
124
  };
125
125
  };
126
126
  }
127
- interface ElectronWithUpdaterOptions {
127
+ interface ElectronWithUpdaterOptions extends Pick<MultiEnvElectronOptions, "bundleDeps"> {
128
+ /**
129
+ * `electron-incremental-update` and its subpath imports are always bundled,
130
+ * regardless of this dependency policy.
131
+ */
132
+ bundleDeps?: MultiEnvElectronOptions["bundleDeps"];
128
133
  /**
129
134
  * Whether to generate sourcemap
130
135
  * @default !isBuild || !!process.env.VSCODE_DEBUG
@@ -144,17 +149,6 @@ interface ElectronWithUpdaterOptions {
144
149
  */
145
150
  bytecode?: boolean | BytecodeOptions;
146
151
  /**
147
- * Faster dev startup by externalize all node modules in entry and main.
148
- *
149
- * Only works in development (`isBuild === false`).
150
- * @default true
151
- */
152
- notBundle?: boolean | RolldownOrRollupOptions["external"];
153
- /**
154
- * @deprecated use `notBundle` instead
155
- */
156
- useNotBundle?: boolean;
157
- /**
158
152
  * Whether to generate version json
159
153
  * @default isCI
160
154
  */
@@ -181,6 +175,10 @@ interface ElectronWithUpdaterOptions {
181
175
  * To change output directories, use `options.updater.paths.electronDistPath` instead
182
176
  */
183
177
  entry: {
178
+ /**
179
+ * Options passed to `@electron/asar` when creating the app.asar archive
180
+ */
181
+ asarOptions?: CreateOptions;
184
182
  /**
185
183
  * By default, all the unbundled modules will be packaged by packager like `electron-builder`.
186
184
  * If setup, all the `dependencies` in `package.json` will be bundled by default, and you need
package/dist/vite.mjs CHANGED
@@ -11,7 +11,7 @@ import cp from "node:child_process";
11
11
  import * as babel from "@babel/core";
12
12
  import { copyFile, cp as cp$1, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
13
13
  import { tmpdir } from "node:os";
14
- import { createPackage, extractFile } from "@electron/asar";
14
+ import { createPackageWithOptions, extractFile } from "@electron/asar";
15
15
  import { generate } from "selfsigned";
16
16
  //#region src/vite/startup.ts
17
17
  /**
@@ -41,6 +41,9 @@ function fixWinCharEncoding(fn) {
41
41
  });
42
42
  }
43
43
  //#endregion
44
+ //#region package.json
45
+ var name = "electron-incremental-update";
46
+ //#endregion
44
47
  //#region src/utils/compress.ts
45
48
  /**
46
49
  * Default function to compress file using brotli
@@ -457,7 +460,7 @@ async function prepareLocalDevUpdateResource({ root, pkg, buildAsarOption, versi
457
460
  await mkdir(path.dirname(resolvedVersionPath), { recursive: true });
458
461
  await cp$1(path.resolve(root, buildAsarOption.electronDistPath), stagedElectronDistPath, { recursive: true });
459
462
  await writeFile(path.join(stagedElectronDistPath, "version"), targetVersion, "utf-8");
460
- await createPackage(stagedElectronDistPath, asarPath);
463
+ await createPackageWithOptions(stagedElectronDistPath, asarPath, buildAsarOption.asarOptions ?? {});
461
464
  await writeFile(compressedPath, await buildAsarOption.generateCompressedFile(await readFile(asarPath)));
462
465
  const updateJSON = defaultVersionJsonGenerator(await readExistingUpdateJSON(resolvedVersionPath, targetVersion), LOCAL_DEV_SIGNATURE, targetVersion, minimumVersion);
463
466
  if (!isUpdateJSON(updateJSON)) throw new Error("Invalid local dev update json");
@@ -570,7 +573,7 @@ function copyAndSkipIfExist(from, to, skipIfExist) {
570
573
  * @param options - Asar build options
571
574
  * @returns Buffer of the built asar file
572
575
  */
573
- async function buildAsar(root, { version, asarOutputPath, electronDistPath, rendererDistPath, compressedPath, generateCompressedFile }) {
576
+ async function buildAsar(root, { version, asarOptions, asarOutputPath, electronDistPath, rendererDistPath, compressedPath, generateCompressedFile }) {
574
577
  electronDistPath = path.resolve(root, electronDistPath);
575
578
  asarOutputPath = path.resolve(root, asarOutputPath);
576
579
  rendererDistPath = path.resolve(root, rendererDistPath);
@@ -579,7 +582,7 @@ async function buildAsar(root, { version, asarOutputPath, electronDistPath, rend
579
582
  await fs.promises.cp(rendererDistPath, rPath, { recursive: true });
580
583
  fs.writeFileSync(path.join(electronDistPath, "version"), version);
581
584
  await fs.promises.mkdir(path.dirname(asarOutputPath), { recursive: true });
582
- await createPackage(electronDistPath, asarOutputPath);
585
+ await createPackageWithOptions(electronDistPath, asarOutputPath, asarOptions ?? {});
583
586
  const buf = await generateCompressedFile(fs.readFileSync(asarOutputPath));
584
587
  await fs.promises.mkdir(path.dirname(compressedPath), { recursive: true });
585
588
  fs.writeFileSync(compressedPath, buf);
@@ -683,7 +686,7 @@ function parseSubjects(subject) {
683
686
  }
684
687
  //#endregion
685
688
  //#region src/vite/core.ts
686
- async function resolveUpdaterOption(root, pkg, options = {}, resolveSignatureKeys = true) {
689
+ async function resolveUpdaterOption(root, pkg, options = {}, resolveSignatureKeys = true, asarOptions) {
687
690
  const { minimumVersion = "0.0.0", paths: { asarOutputPath = `release/${pkg.name}.asar`, compressedPath = `release/${pkg.name}-${pkg.version}.asar.br`, entryOutDir = "dist-entry", electronDistPath = "dist-electron", rendererDistPath = "dist", versionPath = "release/version.json" } = {}, keys: { privateKeyPath = "keys/private.pem", certPath = "keys/cert.pem", keyLength = 2048, certInfo: { subject = {
688
691
  commonName: pkg.name,
689
692
  organizationName: `org.${pkg.name}`
@@ -701,6 +704,7 @@ async function resolveUpdaterOption(root, pkg, options = {}, resolveSignatureKey
701
704
  return {
702
705
  buildAsarOption: {
703
706
  version: pkg.version,
707
+ asarOptions,
704
708
  asarOutputPath,
705
709
  compressedPath,
706
710
  electronDistPath,
@@ -736,7 +740,7 @@ function normalizeVersionPath(versionPath) {
736
740
  return new URL(versionPath, "file://").pathname.slice(1);
737
741
  }
738
742
  async function createElectronOptions(options, context) {
739
- const { entry, main, preload, sourcemap = context.isDev || !!process.env.VSCODE_DEBUG, minify = !context.isDev, buildVersionJson, notBundle = true, external, updater, bytecode, localDevUpdate } = options;
743
+ const { entry, main, preload, sourcemap = context.isDev || !!process.env.VSCODE_DEBUG, minify = !context.isDev, buildVersionJson, bundleDeps, external, updater, bytecode, localDevUpdate } = options;
740
744
  const pkg = context.packageJson;
741
745
  if (!pkg || !pkg.version || !pkg.name || !pkg.main) throw new Error("package.json not found or invalid, must contains version, name and main field");
742
746
  const isESM = pkg.type === "module";
@@ -750,7 +754,7 @@ async function createElectronOptions(options, context) {
750
754
  if (isESM && bytecodeOptions?.enable) throw new Error("`bytecodePlugin` does not support ES module, please remove \"type\": \"module\" in package.json");
751
755
  const resolvedLocalDevUpdate = context.isDev ? resolveLocalDevUpdateOptions(context.root, localDevUpdate) : void 0;
752
756
  const updatePkg = await resolveLocalDevUpdatePackage(pkg, resolvedLocalDevUpdate);
753
- const { buildAsarOption, buildVersionOption, entryOutDir } = await resolveUpdaterOption(context.root, updatePkg, updater, !resolvedLocalDevUpdate);
757
+ const { buildAsarOption, buildVersionOption, entryOutDir } = await resolveUpdaterOption(context.root, updatePkg, updater, !resolvedLocalDevUpdate, entry.asarOptions);
754
758
  const mainFileName = `${resolveEntryName(main.files)}.${isESM ? "mjs" : "js"}`;
755
759
  log.info(`Using "${mainFileName}" as main file`, { timestamp: true });
756
760
  log.info(`Clear cache files`, { timestamp: true });
@@ -796,13 +800,14 @@ async function createElectronOptions(options, context) {
796
800
  name: "main",
797
801
  input: main.files,
798
802
  onstart: mainOnstart,
799
- notBundle,
803
+ bundleDeps,
800
804
  plugins: [isESM && esmShim(), bytecodeOptions && bytecodePlugin("main", minify, isESM, bytecodeOptions)],
801
805
  options: mergeConfig({
802
806
  build: {
803
807
  sourcemap,
804
808
  minify,
805
809
  outDir: `${buildAsarOption.electronDistPath}/main`,
810
+ reportCompressedSize: false,
806
811
  rolldownOptions: {
807
812
  external: finalExternal,
808
813
  output: {
@@ -812,6 +817,7 @@ async function createElectronOptions(options, context) {
812
817
  }
813
818
  }
814
819
  },
820
+ resolve: { noExternal: [name] },
815
821
  define
816
822
  }, main.options ?? {})
817
823
  }];
@@ -820,13 +826,14 @@ async function createElectronOptions(options, context) {
820
826
  onstart(args) {
821
827
  args.reload();
822
828
  },
823
- notBundle,
829
+ bundleDeps,
824
830
  input: preload.files,
825
831
  plugins: [isESM && esmShim(), bytecodeOptions && bytecodePlugin("preload", minify, isESM, bytecodeOptions)],
826
832
  options: mergeConfig({
827
833
  build: {
828
- sourcemap: sourcemap ? "inline" : void 0,
829
834
  minify,
835
+ sourcemap: sourcemap ? "inline" : void 0,
836
+ reportCompressedSize: false,
830
837
  outDir: `${buildAsarOption.electronDistPath}/preload`,
831
838
  rolldownOptions: {
832
839
  external: finalExternal,
@@ -838,6 +845,7 @@ async function createElectronOptions(options, context) {
838
845
  }
839
846
  }
840
847
  },
848
+ resolve: { noExternal: [name] },
841
849
  define
842
850
  }, preload?.options ?? {})
843
851
  });
@@ -848,7 +856,7 @@ async function createElectronOptions(options, context) {
848
856
  if (mainOnstart) await mainOnstart(args);
849
857
  else await args.startup();
850
858
  },
851
- notBundle,
859
+ bundleDeps,
852
860
  plugins: [
853
861
  isESM && esmShim(),
854
862
  bytecodeOptions && bytecodePlugin("entry", minify, isESM, bytecodeOptions),
@@ -884,6 +892,7 @@ async function createElectronOptions(options, context) {
884
892
  sourcemap,
885
893
  minify,
886
894
  outDir: entryOutDir,
895
+ reportCompressedSize: false,
887
896
  rolldownOptions: {
888
897
  external: finalExternal,
889
898
  output: {
@@ -893,6 +902,7 @@ async function createElectronOptions(options, context) {
893
902
  }
894
903
  }
895
904
  },
905
+ resolve: { noExternal: [name] },
896
906
  define
897
907
  }, entry.options || {})
898
908
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
5
5
  "keywords": [
6
6
  "bytecode",
@@ -56,19 +56,17 @@
56
56
  "build": "tsdown",
57
57
  "play": "bun run build && vite",
58
58
  "play:build": "vite build",
59
- "release": "bun run format && bun run lint && bun run test && bun run build && bumpp --all",
59
+ "release": "bun run qa && bun run test && bun run build && bumpp --all",
60
60
  "test": "bun test --preload ./tests/setup.ts",
61
61
  "test:dev": "bun test --watch",
62
- "format": "oxfmt",
63
- "lint": "oxlint --fix",
64
- "qa": "bun run lint && bun run format && tsc --noEmit"
62
+ "qa": "oxlint --fix && oxfmt && tsc --noEmit"
65
63
  },
66
64
  "dependencies": {
67
65
  "@babel/plugin-transform-arrow-functions": "^7.29.7",
68
66
  "@babel/plugin-transform-template-literals": "^7.29.7",
69
67
  "ci-info": "^4.4.0",
70
68
  "selfsigned": "^5.5.0",
71
- "vite-plugin-electron": "~1.0.4"
69
+ "vite-plugin-electron": "^1.1.0"
72
70
  },
73
71
  "devDependencies": {
74
72
  "@subf/config": "^0.2.1",