electron-incremental-update 2.3.2 → 2.3.3

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
@@ -920,9 +920,9 @@ export interface BuildEntryOption {
920
920
  */
921
921
  ignoreDynamicRequires?: boolean
922
922
  /**
923
- * `external` option in `build.rollupOptions`, external `.node` by default
923
+ * `external` option in `build.rollupOptions`, default is node built-in modules or native modules
924
924
  */
925
- external?: string | string[] | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void)
925
+ external?: NonNullable<NonNullable<InlineConfig['build']>['rollupOptions']>['external']
926
926
  /**
927
927
  * Custom options for `vite` build
928
928
  * ```ts
package/dist/vite.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Promisable } from '@subframe7536/type-utils';
1
+ import { Promisable, AnyFunction } from '@subframe7536/type-utils';
2
2
  import { InlineConfig, PluginOption } from 'vite';
3
3
  import { ElectronSimpleOptions } from 'vite-plugin-electron/simple';
4
4
  export { isCI } from 'ci-info';
@@ -104,9 +104,9 @@ interface BuildEntryOption {
104
104
  */
105
105
  ignoreDynamicRequires?: boolean;
106
106
  /**
107
- * `external` option in `build.rollupOptions`, external `.node` by default
107
+ * `external` option in `build.rollupOptions`, default is node built-in modules or native modules
108
108
  */
109
- external?: string | string[] | ((source: string, importer: string | undefined, isResolved: boolean) => boolean | null | undefined | void);
109
+ external?: NonNullable<NonNullable<InlineConfig['build']>['rollupOptions']>['external'];
110
110
  /**
111
111
  * Custom options for `vite` build
112
112
  * ```ts
@@ -297,7 +297,8 @@ type ReplaceKey<T, Key extends keyof T, NewKey extends string> = Omit<T, Key> &
297
297
  type MakeRequiredAndReplaceKey<T, K extends keyof T, NewKey extends string> = MakeRequired<ReplaceKey<T, K, NewKey>, NewKey>;
298
298
  type StartupFn = NonNullable<NonNullable<ElectronSimpleOptions['main']>['onstart']>;
299
299
  /**
300
- * Startup function for debug (see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template})
300
+ * Startup function for debug
301
+ * @see {@link https://github.com/electron-vite/electron-vite-vue/blob/main/vite.config.ts electron-vite-vue template}
301
302
  * @example
302
303
  * import { debugStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
303
304
  * const options = buildElectronPluginOptions({
@@ -309,6 +310,24 @@ type StartupFn = NonNullable<NonNullable<ElectronSimpleOptions['main']>['onstart
309
310
  * })
310
311
  */
311
312
  declare const debugStartup: StartupFn;
313
+ /**
314
+ * Startup function to filter unwanted error message
315
+ * @see {@link https://github.com/electron/electron/issues/46903#issuecomment-2848483520 reference}
316
+ * @example
317
+ * import { filterErrorMessageStartup, buildElectronPluginOptions } from 'electron-incremental-update/vite'
318
+ * const options = buildElectronPluginOptions({
319
+ * // ...
320
+ * main: {
321
+ * // ...
322
+ * startup: args => filterErrorMessageStartup(
323
+ * args,
324
+ * // ignore error message when function returns false
325
+ * msg => !/"code":-32601/.test(message)
326
+ * )
327
+ * },
328
+ * })
329
+ */
330
+ declare function filterErrorMessageStartup(args: Parameters<StartupFn>[0], filter: (msg: string) => boolean): Promise<void>;
312
331
  /**
313
332
  * Startup function util to fix Windows terminal charset
314
333
  * @example
@@ -321,7 +340,7 @@ declare const debugStartup: StartupFn;
321
340
  * },
322
341
  * })
323
342
  */
324
- declare function fixWinCharEncoding(fn: StartupFn): StartupFn;
343
+ declare function fixWinCharEncoding<T extends AnyFunction>(fn: T): T;
325
344
  type ExcludeOutputDirOptions = {
326
345
  vite?: {
327
346
  build?: {
@@ -454,4 +473,4 @@ interface ElectronWithUpdaterOptions {
454
473
  */
455
474
  declare function electronWithUpdater(options: ElectronWithUpdaterOptions): Promise<PluginOption[] | undefined>;
456
475
 
457
- export { type ElectronWithUpdaterOptions, convertLiteral, debugStartup, electronWithUpdater as default, electronWithUpdater, fixWinCharEncoding };
476
+ export { type ElectronWithUpdaterOptions, convertLiteral, debugStartup, electronWithUpdater as default, electronWithUpdater, filterErrorMessageStartup, fixWinCharEncoding };
package/dist/vite.js CHANGED
@@ -13,6 +13,7 @@ import { startup, build } from 'vite-plugin-electron';
13
13
  import { notBundle } from 'vite-plugin-electron/plugin';
14
14
  import ElectronSimple from 'vite-plugin-electron/simple';
15
15
  import Asar from '@electron/asar';
16
+ import { builtinModules } from 'node:module';
16
17
  import crypto from 'node:crypto';
17
18
  import zlib from 'node:zlib';
18
19
  import { generate } from 'selfsigned';
@@ -166,7 +167,7 @@ function parseSubjects(subject) {
166
167
  }
167
168
 
168
169
  // src/vite/option.ts
169
- function parseOptions(pkg, defaultExternal, sourcemap = false, minify = false, options = {}) {
170
+ function parseOptions(pkg, sourcemap = false, minify = false, options = {}) {
170
171
  const {
171
172
  minimumVersion = "0.0.0",
172
173
  entry: {
@@ -177,7 +178,12 @@ function parseOptions(pkg, defaultExternal, sourcemap = false, minify = false, o
177
178
  nativeModuleEntryMap = {},
178
179
  postBuild,
179
180
  ignoreDynamicRequires = false,
180
- external,
181
+ external = [
182
+ /^node:.*/,
183
+ /.*\.(node|dll|dylib|so)$/,
184
+ "original-fs",
185
+ ...builtinModules
186
+ ],
181
187
  overrideViteOptions = {}
182
188
  } = {},
183
189
  paths: {
@@ -221,18 +227,7 @@ function parseOptions(pkg, defaultExternal, sourcemap = false, minify = false, o
221
227
  nativeModuleEntryMap,
222
228
  overrideViteOptions,
223
229
  ignoreDynamicRequires,
224
- external: (source, importer, isResolved) => {
225
- if (!external) {
226
- return defaultExternal(source);
227
- }
228
- if (typeof external === "string") {
229
- return source === external;
230
- }
231
- if (Array.isArray(external)) {
232
- return external.includes(source);
233
- }
234
- return external(source, importer, isResolved);
235
- }
230
+ external
236
231
  };
237
232
  const { privateKey, cert } = parseKeys({
238
233
  keyLength,
@@ -253,13 +248,23 @@ function parseOptions(pkg, defaultExternal, sourcemap = false, minify = false, o
253
248
  return { buildAsarOption, buildEntryOption, buildVersionOption, postBuild, cert };
254
249
  }
255
250
  var vite_default = electronWithUpdater;
256
- var debugStartup = (args) => {
251
+ var debugStartup = async (args) => {
257
252
  if (process.env.VSCODE_DEBUG) {
258
253
  console.log("[startup] Electron App");
259
254
  } else {
260
- args.startup();
255
+ await args.startup();
261
256
  }
262
257
  };
258
+ async function filterErrorMessageStartup(args, filter) {
259
+ await args.startup(void 0, { stdio: ["inherit", "inherit", "pipe", "ipc"] });
260
+ const elec = process.electronApp;
261
+ elec.stderr.addListener("data", (data) => {
262
+ const message = data.toString();
263
+ if (filter(message)) {
264
+ console.error(message);
265
+ }
266
+ });
267
+ }
263
268
  function fixWinCharEncoding(fn) {
264
269
  return async (...args) => {
265
270
  if (process.platform === "win32") {
@@ -318,17 +323,14 @@ async function electronWithUpdater(options) {
318
323
  );
319
324
  bytecodeOptions = void 0;
320
325
  }
321
- const defaultExternal = (src) => {
322
- return src.startsWith("node:") || Object.keys("dependencies" in pkg ? pkg.dependencies : {}).includes(src) || src === "original-fs";
323
- };
324
326
  const {
325
327
  buildAsarOption,
326
328
  buildEntryOption,
327
329
  buildVersionOption,
328
330
  postBuild,
329
331
  cert
330
- } = parseOptions(pkg, defaultExternal, sourcemap, minify, updater);
331
- const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath } = buildEntryOption;
332
+ } = parseOptions(pkg, sourcemap, minify, updater);
333
+ const { entryOutputDirPath, nativeModuleEntryMap, appEntryPath, external } = buildEntryOption;
332
334
  try {
333
335
  fs2.rmSync(buildAsarOption.electronDistPath, { recursive: true, force: true });
334
336
  fs2.rmSync(entryOutputDirPath, { recursive: true, force: true });
@@ -385,7 +387,7 @@ async function electronWithUpdater(options) {
385
387
  }
386
388
  let isInit = false;
387
389
  const rollupOptions = {
388
- external: defaultExternal,
390
+ external,
389
391
  treeshake: true
390
392
  };
391
393
  const esmShimPlugin = isESM ? import('./esm-4S4XCVEW.js').then((m) => m.esm()) : void 0;
@@ -398,9 +400,9 @@ async function electronWithUpdater(options) {
398
400
  await _buildEntry();
399
401
  }
400
402
  if (_main.onstart) {
401
- _main.onstart(args);
403
+ await _main.onstart(args);
402
404
  } else {
403
- args.startup();
405
+ await args.startup();
404
406
  }
405
407
  },
406
408
  vite: mergeConfig(
@@ -513,4 +515,4 @@ async function electronWithUpdater(options) {
513
515
  return [ElectronSimple(electronPluginOptions), extraHmrPlugin];
514
516
  }
515
517
 
516
- export { debugStartup, vite_default as default, electronWithUpdater, fixWinCharEncoding };
518
+ export { debugStartup, vite_default as default, electronWithUpdater, filterErrorMessageStartup, fixWinCharEncoding };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "electron-incremental-update",
3
3
  "type": "module",
4
- "version": "2.3.2",
4
+ "version": "2.3.3",
5
5
  "description": "Electron incremental update tools with Vite plugin, support bytecode protection",
6
6
  "author": "subframe7536",
7
7
  "license": "MIT",