@rg-dev/electron-helpers 1.0.6 → 1.0.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/backend.cjs CHANGED
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var backend_exports = {};
32
32
  __export(backend_exports, {
33
33
  __electron_helpers: () => __electron_helpers,
34
+ checkIfDirExistsOrThrowSync: () => checkIfDirExistsOrThrowSync,
35
+ checkIfFileExistsOrThrowSync: () => checkIfFileExistsOrThrowSync,
34
36
  electronHelpers: () => electronHelpers
35
37
  });
36
38
  module.exports = __toCommonJS(backend_exports);
@@ -42,8 +44,19 @@ var __electron_helpers = "1";
42
44
  // src/backend.ts
43
45
  var import_path = __toESM(require("path"), 1);
44
46
  var import_fs = __toESM(require("fs"), 1);
45
- var import_node_env = require("@rg-dev/stdlib/lib/node-env");
46
47
  var import_electron2 = __toESM(require("electron"), 1);
48
+ function checkIfDirExistsOrThrowSync(dir) {
49
+ const stat = import_fs.default.statSync(dir);
50
+ if (!stat.isDirectory()) {
51
+ throw new Error(`Expected directory, but found: ${dir}`);
52
+ }
53
+ }
54
+ function checkIfFileExistsOrThrowSync(file) {
55
+ const stat = import_fs.default.statSync(file);
56
+ if (!stat.isFile()) {
57
+ throw new Error(`Expected file, but found: ${file}`);
58
+ }
59
+ }
47
60
  var electronHelpers = class {
48
61
  static isRunningInElectron() {
49
62
  return process.versions["electron"] != void 0;
@@ -74,9 +87,9 @@ var electronHelpers = class {
74
87
  return { sessionName, session: session2 };
75
88
  }
76
89
  //win.loadURL('file://')
77
- static async intercept(opts) {
78
- await (0, import_node_env.checkIfDirExistsOrThrow)(opts.filesDir);
79
- await (0, import_node_env.checkIfFileExistsOrThrow)(import_path.default.join(opts.filesDir, "index.html"));
90
+ static intercept(opts) {
91
+ checkIfDirExistsOrThrowSync(opts.filesDir);
92
+ checkIfFileExistsOrThrowSync(import_path.default.join(opts.filesDir, "index.html"));
80
93
  const filesDir = import_path.default.resolve(opts.filesDir);
81
94
  const indexFile = import_path.default.join(filesDir, "index.html");
82
95
  const proto = opts.session ? opts.session.protocol : import_electron.protocol;
@@ -1,5 +1,7 @@
1
1
  export { __electron_helpers } from './index.cjs';
2
2
 
3
+ declare function checkIfDirExistsOrThrowSync(dir: string): void;
4
+ declare function checkIfFileExistsOrThrowSync(file: string): void;
3
5
  declare class electronHelpers {
4
6
  static isRunningInElectron(): boolean;
5
7
  static electronSaveFileDialog(type: string): Promise<string>;
@@ -10,8 +12,8 @@ declare class electronHelpers {
10
12
  static intercept(opts: {
11
13
  filesDir: string;
12
14
  session?: Electron.Session;
13
- }): Promise<void>;
15
+ }): void;
14
16
  static electronFilePicker(): Promise<string>;
15
17
  }
16
18
 
17
- export { electronHelpers };
19
+ export { checkIfDirExistsOrThrowSync, checkIfFileExistsOrThrowSync, electronHelpers };
package/dist/backend.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { __electron_helpers } from './index.js';
2
2
 
3
+ declare function checkIfDirExistsOrThrowSync(dir: string): void;
4
+ declare function checkIfFileExistsOrThrowSync(file: string): void;
3
5
  declare class electronHelpers {
4
6
  static isRunningInElectron(): boolean;
5
7
  static electronSaveFileDialog(type: string): Promise<string>;
@@ -10,8 +12,8 @@ declare class electronHelpers {
10
12
  static intercept(opts: {
11
13
  filesDir: string;
12
14
  session?: Electron.Session;
13
- }): Promise<void>;
15
+ }): void;
14
16
  static electronFilePicker(): Promise<string>;
15
17
  }
16
18
 
17
- export { electronHelpers };
19
+ export { checkIfDirExistsOrThrowSync, checkIfFileExistsOrThrowSync, electronHelpers };
package/dist/backend.js CHANGED
@@ -7,8 +7,19 @@ var __electron_helpers = "1";
7
7
  // src/backend.ts
8
8
  import path from "path";
9
9
  import fs from "fs";
10
- import { checkIfDirExistsOrThrow, checkIfFileExistsOrThrow } from "@rg-dev/stdlib/lib/node-env";
11
10
  import electron from "electron";
11
+ function checkIfDirExistsOrThrowSync(dir) {
12
+ const stat = fs.statSync(dir);
13
+ if (!stat.isDirectory()) {
14
+ throw new Error(`Expected directory, but found: ${dir}`);
15
+ }
16
+ }
17
+ function checkIfFileExistsOrThrowSync(file) {
18
+ const stat = fs.statSync(file);
19
+ if (!stat.isFile()) {
20
+ throw new Error(`Expected file, but found: ${file}`);
21
+ }
22
+ }
12
23
  var electronHelpers = class {
13
24
  static isRunningInElectron() {
14
25
  return process.versions["electron"] != void 0;
@@ -39,9 +50,9 @@ var electronHelpers = class {
39
50
  return { sessionName, session: session2 };
40
51
  }
41
52
  //win.loadURL('file://')
42
- static async intercept(opts) {
43
- await checkIfDirExistsOrThrow(opts.filesDir);
44
- await checkIfFileExistsOrThrow(path.join(opts.filesDir, "index.html"));
53
+ static intercept(opts) {
54
+ checkIfDirExistsOrThrowSync(opts.filesDir);
55
+ checkIfFileExistsOrThrowSync(path.join(opts.filesDir, "index.html"));
45
56
  const filesDir = path.resolve(opts.filesDir);
46
57
  const indexFile = path.join(filesDir, "index.html");
47
58
  const proto = opts.session ? opts.session.protocol : protocol;
@@ -90,5 +101,7 @@ var electronHelpers = class {
90
101
  };
91
102
  export {
92
103
  __electron_helpers,
104
+ checkIfDirExistsOrThrowSync,
105
+ checkIfFileExistsOrThrowSync,
93
106
  electronHelpers
94
107
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/electron-helpers",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "tsup && node dist/index.cjs",
@@ -51,6 +51,5 @@
51
51
  "typescript": "^5.4.5"
52
52
  },
53
53
  "dependencies": {
54
- "@rg-dev/stdlib": "^1.0.80"
55
54
  }
56
55
  }