@rel-packages/osu-beatmap-parser 1.0.3 → 1.0.4

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.
Binary file
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { OsuKey, OsuInput } from "./types";
2
+ import { init_wasm } from "./lib/bindings";
2
3
  export declare const get_property: (data: Uint8Array, key: OsuKey) => any;
3
4
  export declare const get_properties: (input: Uint8Array | OsuInput, keys: OsuKey[]) => any;
4
- export { OsuKey, OsuInput };
5
+ export { OsuKey, OsuInput, init_wasm };
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.get_properties = exports.get_property = void 0;
3
+ exports.init_wasm = exports.get_properties = exports.get_property = void 0;
4
4
  const bindings_1 = require("./lib/bindings");
5
+ Object.defineProperty(exports, "init_wasm", { enumerable: true, get: function () { return bindings_1.init_wasm; } });
5
6
  const get_property = (data, key) => {
6
7
  return bindings_1.native.get_property(data, key);
7
8
  };
@@ -1 +1,2 @@
1
+ export declare const init_wasm: () => Promise<void>;
1
2
  export declare let native: any;
@@ -1,92 +1,119 @@
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
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.native = void 0;
36
+ exports.native = exports.init_wasm = void 0;
4
37
  const IS_BROWSER = globalThis.window != undefined;
38
+ const wasm_proxy = {
39
+ instance: null,
40
+ init_promise: null,
41
+ get_property: (data, key) => {
42
+ if (wasm_proxy.instance == null)
43
+ throw Error("WASM not loaded yet...");
44
+ const wasm_inst = wasm_proxy.instance;
45
+ const buffer_ptr = wasm_inst._malloc(data.length);
46
+ wasm_inst.HEAPU8.set(data, buffer_ptr);
47
+ const result = wasm_inst.get_property(buffer_ptr, data.length, key);
48
+ wasm_inst._free(buffer_ptr);
49
+ return result;
50
+ },
51
+ get_properties: (data, keys) => {
52
+ if (wasm_proxy.instance == null)
53
+ throw Error("WASM not loaded yet...");
54
+ const wasm_inst = wasm_proxy.instance;
55
+ const buffer_ptr = wasm_inst._malloc(data.length);
56
+ wasm_inst.HEAPU8.set(data, buffer_ptr);
57
+ const result = wasm_inst.get_properties(buffer_ptr, data.length, keys);
58
+ wasm_inst._free(buffer_ptr);
59
+ return result;
60
+ },
61
+ };
62
+ const init_wasm = async () => {
63
+ if (!IS_BROWSER)
64
+ return;
65
+ if (wasm_proxy.instance)
66
+ return;
67
+ if (wasm_proxy.init_promise)
68
+ return wasm_proxy.init_promise;
69
+ wasm_proxy.init_promise = (async () => {
70
+ // try dynamic import first, fallback to globalThis
71
+ let create_func;
72
+ try {
73
+ // @ts-ignore
74
+ const mod = await Promise.resolve().then(() => __importStar(require("../../build/osu-beatmap-parser.js")));
75
+ create_func = mod.default || mod.create_osu_parser;
76
+ }
77
+ catch (e) {
78
+ create_func = globalThis.create_osu_parser;
79
+ }
80
+ if (!create_func) {
81
+ throw Error("create_osu_parser not found");
82
+ }
83
+ wasm_proxy.instance = await create_func();
84
+ })();
85
+ return wasm_proxy.init_promise;
86
+ };
87
+ exports.init_wasm = init_wasm;
5
88
  const load_native_module = () => {
6
89
  if (IS_BROWSER) {
7
- const wasm_proxy = {
8
- instance: null,
9
- get_property: (data, key) => {
10
- if (wasm_proxy.instance == null) {
11
- throw Error("WASM not loaded yet");
12
- }
13
- const wasm_inst = wasm_proxy.instance;
14
- const buffer_ptr = wasm_inst._malloc(data.length);
15
- wasm_inst.HEAPU8.set(data, buffer_ptr);
16
- const result_val = wasm_inst.get_property(buffer_ptr, data.length, key);
17
- wasm_inst._free(buffer_ptr);
18
- return result_val;
19
- },
20
- get_properties: (data, keys) => {
21
- if (wasm_proxy.instance == null) {
22
- throw Error("WASM not loaded yet");
23
- }
24
- const wasm_inst = wasm_proxy.instance;
25
- const buffer_ptr = wasm_inst._malloc(data.length);
26
- wasm_inst.HEAPU8.set(data, buffer_ptr);
27
- const results_obj = wasm_inst.get_properties(buffer_ptr, data.length, keys);
28
- wasm_inst._free(buffer_ptr);
29
- return results_obj;
30
- },
31
- };
32
- const create_func = globalThis.create_osu_parser;
33
- if (create_func != undefined) {
34
- create_func().then((instance) => {
35
- wasm_proxy.instance = instance;
36
- });
37
- }
38
90
  return wasm_proxy;
39
91
  }
40
92
  try {
41
- const fs_mod = require("fs");
42
- const path_mod = require("path");
43
- const load_prebuilt = () => {
44
- const OS_PLATFORM = process.platform;
45
- const CPU_ARCH = process.arch;
46
- const SCAN_PATHS = [
47
- path_mod.join(__dirname, "..", "..", "prebuilds", `${OS_PLATFORM}-${CPU_ARCH}`, "osu-beatmap-parser.node"),
48
- path_mod.join(__dirname, "prebuilds", `${OS_PLATFORM}-${CPU_ARCH}`, "osu-beatmap-parser.node"),
49
- ];
50
- for (const path_str of SCAN_PATHS) {
51
- if (fs_mod.existsSync(path_str)) {
52
- return require(path_str);
53
- }
93
+ const fs = require("fs");
94
+ const path = require("path");
95
+ const platform = process.platform;
96
+ const arch = process.arch;
97
+ const paths = [
98
+ // prebuilt binaries
99
+ path.join(__dirname, "..", "..", "prebuilds", `${platform}-${arch}`, "osu-beatmap-parser.node"),
100
+ path.join(__dirname, "..", "prebuilds", `${platform}-${arch}`, "osu-beatmap-parser.node"),
101
+ // local builds
102
+ path.join(__dirname, "..", "..", "build", "osu-beatmap-parser.node"),
103
+ path.join(__dirname, "..", "..", "build", "Release", "osu-beatmap-parser.node"),
104
+ path.join(__dirname, "..", "build", "osu-beatmap-parser.node"),
105
+ path.join(__dirname, "build", "osu-beatmap-parser.node"),
106
+ ];
107
+ for (const p of paths) {
108
+ if (fs.existsSync(p)) {
109
+ return require(p);
54
110
  }
55
- return false;
56
- };
57
- const load_local = () => {
58
- const SCAN_PATHS = [
59
- path_mod.join(__dirname, "..", "..", "build", "osu-beatmap-parser.node"),
60
- path_mod.join(__dirname, "..", "..", "build", "Release", "osu-beatmap-parser.node"),
61
- path_mod.join(__dirname, "..", "build", "osu-beatmap-parser.node"),
62
- path_mod.join(__dirname, "build", "osu-beatmap-parser.node"),
63
- ];
64
- for (const path_str of SCAN_PATHS) {
65
- if (fs_mod.existsSync(path_str)) {
66
- return require(path_str);
67
- }
68
- }
69
- return false;
70
- };
71
- const bin_module = load_prebuilt() || load_local();
72
- if (bin_module) {
73
- return bin_module;
74
111
  }
75
112
  }
76
113
  catch (e) { }
77
114
  return false;
78
115
  };
79
116
  exports.native = load_native_module();
80
- try {
81
- if (exports.native == false && IS_BROWSER == false) {
82
- throw Error("failed to find native module...");
83
- }
84
- }
85
- catch (err) {
86
- if (IS_BROWSER) {
87
- exports.native = {};
88
- }
89
- else {
90
- throw new Error("failed to load native module...\n" + err);
91
- }
117
+ if (exports.native == false && !IS_BROWSER) {
118
+ throw new Error("failed to load native module...");
92
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rel-packages/osu-beatmap-parser",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": ".osu parser for nodejs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
Binary file