win_webview2 1.1.12 → 1.1.14

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.
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ww2Init = ww2Init;
7
- const dirnameTool_1 = require("../tsExport/dirnameTool");
8
7
  const child_process_1 = require("child_process");
9
8
  const prompts_1 = __importDefault(require("prompts"));
10
9
  function runCommand(command) {
@@ -18,7 +17,6 @@ function runCommand(command) {
18
17
  }
19
18
  }
20
19
  const jsonConfigFilePath = "./win_webview2.json";
21
- let mdirname = (0, dirnameTool_1.getWw2Dirname)();
22
20
  let ww2Choise = {
23
21
  "ww2_typescript": {
24
22
  description: "init win_webview2",
@@ -1,14 +1,2 @@
1
- /**
2
- *
3
- * Penting!! jangan pindah file ini ketempat lain,
4
- * Sesuaikan ulang jika file ini dipindah karena ini menggunakan __dirname
5
- * dan juga file ini akan ditranspile ke js ke folder Dist, posisi file ini terhadap root antara file ts dan
6
- * file js harus sama,
7
- *
8
- */
9
- export declare function getWw2Dirname(): {
10
- _dirname: string;
11
- _filename: string;
12
- };
13
1
  export declare function findUserProjectRoot(): string | null;
14
2
  export declare function getWWVNodeModuleFolder(): string;
@@ -1,63 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
35
5
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getWw2Dirname = getWw2Dirname;
37
6
  exports.findUserProjectRoot = findUserProjectRoot;
38
7
  exports.getWWVNodeModuleFolder = getWWVNodeModuleFolder;
39
- const node_url_1 = require("node:url");
40
- const node_path_1 = __importStar(require("node:path"));
8
+ const node_path_1 = __importDefault(require("node:path"));
41
9
  const node_fs_1 = require("node:fs");
42
- /**
43
- *
44
- * Penting!! jangan pindah file ini ketempat lain,
45
- * Sesuaikan ulang jika file ini dipindah karena ini menggunakan __dirname
46
- * dan juga file ini akan ditranspile ke js ke folder Dist, posisi file ini terhadap root antara file ts dan
47
- * file js harus sama,
48
- *
49
- */
50
- function getWw2Dirname() {
51
- // Trik deteksi lingkungan
52
- const _filename = typeof __filename !== 'undefined'
53
- ? __filename
54
- // @ts-ignore:
55
- : (0, node_url_1.fileURLToPath)(eval('import.meta.url'));
56
- const _dirname = typeof __dirname !== 'undefined'
57
- ? __dirname
58
- : (0, node_path_1.dirname)(_filename);
59
- return { _dirname, _filename };
60
- }
61
10
  function findUserProjectRootRecrusive(currentDir = process.cwd()) {
62
11
  const packagePath = node_path_1.default.join(currentDir, 'package.json');
63
12
  if ((0, node_fs_1.existsSync)(packagePath)) {
@@ -1,4 +1,4 @@
1
- import { getWw2Dirname } from "./dirnameTool";
1
+ import { getWWVNodeModuleFolder } from "./dirnameTool";
2
2
  import { readConfig } from "./ww2_config";
3
3
  interface Ww2WebConfig {
4
4
  callback: (err: any, data: any) => void;
@@ -35,4 +35,4 @@ export declare function closeSplash(): Promise<void>;
35
35
  export * from "./ww2_server";
36
36
  export { findUserProjectRoot } from "./dirnameTool";
37
37
  export { readConfig };
38
- export { getWw2Dirname };
38
+ export { getWWVNodeModuleFolder };
@@ -17,24 +17,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.getWw2Dirname = exports.readConfig = exports.findUserProjectRoot = void 0;
20
+ exports.getWWVNodeModuleFolder = exports.readConfig = exports.findUserProjectRoot = void 0;
21
21
  exports.getModule = getModule;
22
22
  exports.closeSplash = closeSplash;
23
23
  const node_fs_1 = require("node:fs");
24
24
  const node_path_1 = __importDefault(require("node:path"));
25
25
  const dirnameTool_1 = require("./dirnameTool");
26
- Object.defineProperty(exports, "getWw2Dirname", { enumerable: true, get: function () { return dirnameTool_1.getWw2Dirname; } });
26
+ Object.defineProperty(exports, "getWWVNodeModuleFolder", { enumerable: true, get: function () { return dirnameTool_1.getWWVNodeModuleFolder; } });
27
27
  const ww2_config_1 = require("./ww2_config");
28
28
  Object.defineProperty(exports, "readConfig", { enumerable: true, get: function () { return ww2_config_1.readConfig; } });
29
29
  async function getModule() {
30
- let dirname = (0, dirnameTool_1.getWw2Dirname)();
31
- let filepath = node_path_1.default.join(dirname._dirname, "./ww2_addon.node");
32
- if (!(0, node_fs_1.existsSync)(filepath)) {
30
+ let addOnName = "ww2_addon.node";
31
+ let filepath = (() => {
32
+ let userFolder = (0, dirnameTool_1.findUserProjectRoot)();
33
+ if (userFolder == null)
34
+ return null;
35
+ let r = node_path_1.default.join(userFolder, addOnName);
36
+ if (!(0, node_fs_1.existsSync)(r))
37
+ return null;
38
+ return r;
39
+ })();
40
+ filepath = await (async () => {
41
+ if (filepath != null)
42
+ return filepath;
43
+ let wwvModulePath = (0, dirnameTool_1.getWWVNodeModuleFolder)();
33
44
  let config = await (0, ww2_config_1.readConfig)();
34
45
  if (config == null)
35
- throw "user config null";
36
- filepath = node_path_1.default.join(dirname._dirname, `../../../win_lib/${config.platform}/ww2_addon.node`);
37
- }
46
+ return null;
47
+ let r = node_path_1.default.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
48
+ return r;
49
+ })();
50
+ if (filepath == null)
51
+ throw "file not found";
38
52
  let myAddon = require(filepath);
39
53
  return myAddon;
40
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "win_webview2",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nnttoo/win_webview2"
@@ -1,9 +1,5 @@
1
- import { existsSync } from "fs";
2
- import { copyFile, mkdir, readFile, writeFile } from "fs/promises";
3
- import { getWw2Dirname } from "../tsExport/dirnameTool";
4
- import path from "path";
5
- import { exec, execSync } from "child_process";
6
- import { ConfigWW2 } from "../tsExport/ww2_config";
1
+
2
+ import { exec, execSync } from "child_process";
7
3
  import prompts from "prompts";
8
4
 
9
5
 
@@ -17,8 +13,7 @@ function runCommand(command: string) {
17
13
  }
18
14
  }
19
15
 
20
- const jsonConfigFilePath = "./win_webview2.json";
21
- let mdirname = getWw2Dirname();
16
+ const jsonConfigFilePath = "./win_webview2.json";
22
17
 
23
18
 
24
19
  interface ChoiseItem {
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { getWw2Dirname, getWWVNodeModuleFolder } from "../tsExport/dirnameTool";
2
+ import { getWWVNodeModuleFolder } from "../tsExport/dirnameTool";
3
3
  import { readFile } from "node:fs/promises";
4
4
 
5
5
 
@@ -2,30 +2,8 @@ import { fileURLToPath } from 'node:url';
2
2
  import path, { dirname } from 'node:path';
3
3
  import { existsSync } from 'node:fs';
4
4
 
5
-
6
- /**
7
- *
8
- * Penting!! jangan pindah file ini ketempat lain,
9
- * Sesuaikan ulang jika file ini dipindah karena ini menggunakan __dirname
10
- * dan juga file ini akan ditranspile ke js ke folder Dist, posisi file ini terhadap root antara file ts dan
11
- * file js harus sama,
12
- *
13
- */
14
- export function getWw2Dirname() {
15
- // Trik deteksi lingkungan
16
- const _filename = typeof __filename !== 'undefined'
17
- ? __filename
18
- // @ts-ignore:
19
- : fileURLToPath(eval('import.meta.url'));
20
-
21
- const _dirname = typeof __dirname !== 'undefined'
22
- ? __dirname
23
- : dirname(_filename);
24
5
 
25
6
 
26
- return { _dirname, _filename };
27
- }
28
-
29
7
  function findUserProjectRootRecrusive(currentDir : string = process.cwd()) {
30
8
 
31
9
  const packagePath = path.join(currentDir, 'package.json');
@@ -2,7 +2,7 @@ import { execFile } from "node:child_process";
2
2
  import { existsSync } from "node:fs";
3
3
  import { readFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
- import { getWw2Dirname } from "./dirnameTool";
5
+ import { findUserProjectRoot, getWWVNodeModuleFolder } from "./dirnameTool";
6
6
  import { ConfigWW2, readConfig } from "./ww2_config";
7
7
 
8
8
  interface Ww2WebConfig {
@@ -44,20 +44,37 @@ interface Ww2Module {
44
44
 
45
45
 
46
46
  export async function getModule() {
47
- let dirname = getWw2Dirname();
47
+ let addOnName = "ww2_addon.node";
48
48
 
49
- let filepath = path.join(
50
- dirname._dirname,
51
- "./ww2_addon.node"
52
- );
49
+ let filepath = (()=>{
53
50
 
54
- if (!existsSync(filepath)) {
51
+ let userFolder = findUserProjectRoot();
52
+ if(userFolder == null) return null;
53
+ let r = path.join(
54
+ userFolder,
55
+ addOnName
56
+ );
55
57
 
58
+ if(!existsSync(r)) return null;
59
+
60
+ return r;
61
+
62
+ })();
63
+
64
+ filepath = await ( async ()=>{
65
+ if(filepath != null) return filepath;
66
+ let wwvModulePath = getWWVNodeModuleFolder();
56
67
  let config = await readConfig();
57
- if(config == null) throw "user config null";
58
- filepath = path.join(dirname._dirname, `../../../win_lib/${config.platform}/ww2_addon.node`);
68
+ if(config == null) return null;
69
+
70
+ let r = path.join(wwvModulePath, `win_lib/${config.platform}/ww2_addon.node`);
59
71
 
60
- }
72
+ return r;
73
+
74
+
75
+ })();
76
+
77
+ if(filepath == null) throw "file not found";
61
78
 
62
79
  let myAddon = require(filepath) as Ww2Module;
63
80
  return myAddon;
@@ -72,7 +89,9 @@ export function closeSplash(){
72
89
  });
73
90
  }
74
91
 
92
+
93
+
75
94
  export * from "./ww2_server"
76
95
  export {findUserProjectRoot } from "./dirnameTool"
77
- export {readConfig} ;
78
- export {getWw2Dirname}
96
+ export {readConfig} ;
97
+ export {getWWVNodeModuleFolder}
@@ -1,5 +1,5 @@
1
1
  import { readFile } from "node:fs/promises";
2
- import { findUserProjectRoot, getWw2Dirname } from "./dirnameTool";
2
+ import { findUserProjectRoot } from "./dirnameTool";
3
3
  import path from "node:path";
4
4
  import { existsSync } from "node:fs";
5
5