java-bridge 2.1.7 → 2.1.8-beta.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.
@@ -16,6 +16,11 @@ export interface JVMOptions extends JavaOptions {
16
16
  * Additional arguments to pass to the JVM
17
17
  */
18
18
  opts?: Array<string> | null;
19
+ /**
20
+ * Additional items to add to the class path.
21
+ * This also allows wildcard imports, e.g. `/lib/*`
22
+ */
23
+ classpath?: string[];
19
24
  }
20
25
  /**
21
26
  * Ensure the java vm is created.
@@ -50,9 +55,30 @@ export interface JVMOptions extends JavaOptions {
50
55
  * ensureJvm();
51
56
  * ```
52
57
  *
58
+ * ## Notes on the `classpath` option
59
+ *
60
+ * If you need to set the class path *before* jvm startup, for example
61
+ * when using libraries with custom class loaders, you'd need to call
62
+ * `ensureJvm` *before* making any other call to `java-bridge` as those
63
+ * methods may themselves call `ensureJvm` with no arguments
64
+ * (see comment above). Altering the startup classpath after jvm boot is
65
+ * not possible, you can only alter the runtime classpath using
66
+ * `appendClasspath` or `appendClasspathAny` which may not reflect
67
+ * in an altered classpath in your java application/library if your
68
+ * application is using a custom classpath (e.g. Spring Boot).
69
+ *
70
+ * Also, it is not possible to restart the jvm after is has been started
71
+ * once, in order to alter the startup classpath. This is due to some
72
+ * limitations with the destructor feature of the node.js native api,
73
+ * which may not call the destructor in time and having two jvm instances
74
+ * in the same application is not allowed by java. Additionally, destroying
75
+ * the jvm instance may cause *undefined behaviour*, which may or may not
76
+ * cause the application to crash. Let's not do that.
77
+ *
53
78
  * @param options the options to use when creating the jvm
79
+ * @return true if the jvm was created and false if the jvm already existed and was not created
54
80
  */
55
- export declare function ensureJvm(options?: JVMOptions): void;
81
+ export declare function ensureJvm(options?: JVMOptions): boolean;
56
82
  /**
57
83
  * Get the addon's internal class loader.
58
84
  * This may be used in combination with {@link setClassLoader}
@@ -160,6 +186,8 @@ export declare function importClassAsync<T extends JavaClassConstructorType = Un
160
186
  * This doesn't check if the jars are valid and/or even exist.
161
187
  * The new classpath will be available to all classes imported after this call.
162
188
  *
189
+ * **Note: This can only import single files, not directories.**
190
+ *
163
191
  * ## Example
164
192
  * ```ts
165
193
  * import { appendClasspath } from 'java-bridge';
@@ -181,6 +209,27 @@ export declare function importClassAsync<T extends JavaClassConstructorType = Un
181
209
  * @param path the path(s) to add
182
210
  */
183
211
  export declare function appendClasspath(path: string | string[]): void;
212
+ /**
213
+ * Append either a single or multiple jars or directories to the class path.
214
+ * This will check if the path(s) passed are directories and will
215
+ * add a trailing slash to the path if it doesn't already have one
216
+ * so the class loader will treat it as a directory. This will
217
+ * check if the file or directory exists and throw an error if it doesn't exist.
218
+ *
219
+ * ## Example
220
+ * ```ts
221
+ * appendClasspathAny('/path/to/dir');
222
+ * ```
223
+ *
224
+ * Pass multiple paths:
225
+ * ```ts
226
+ * appendClasspathAny(['/path/to/dir1', '/path/to/my.jar']);
227
+ * ```
228
+ *
229
+ * @param path the file(s) or directory(s) to add
230
+ * @param recursive whether to recursively add all files in the directory
231
+ */
232
+ export declare function appendClasspathAny(path: string | string[], recursive?: boolean): void;
184
233
  /**
185
234
  * Check if `this_obj` is instance of `other`.
186
235
  * This uses the native java `instanceof` operator.
@@ -215,7 +264,7 @@ export declare function appendClasspath(path: string | string[]): void;
215
264
  * @param other the class or class name to check against
216
265
  * @return true if `this_obj` is an instance of `other`
217
266
  */
218
- export declare function isInstanceOf<T extends JavaClassConstructorType>(this_obj: JavaClass, other: string | T): boolean;
267
+ export declare function isInstanceOf<T extends object>(this_obj: JavaClass, other: string | T): boolean;
219
268
  /**
220
269
  * Methods for altering and querying the class path.
221
270
  * @example
@@ -233,9 +282,13 @@ export declare namespace classpath {
233
282
  */
234
283
  function append(path: string | string[]): void;
235
284
  /**
236
- * Get the loaded jars in the class path
285
+ * @inheritDoc appendClasspathAny
286
+ */
287
+ function appendAny(path: string | string[], recursive?: boolean): void;
288
+ /**
289
+ * Get the loaded files or directories in the class path
237
290
  *
238
- * @returns a list of the loaded jars
291
+ * @returns a list of the loaded files
239
292
  */
240
293
  function get(): string[];
241
294
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "java-bridge",
3
- "version": "2.1.7",
3
+ "version": "2.1.8-beta.1",
4
4
  "main": "dist/index.prod.min.js",
5
5
  "types": "dist/ts-src/index.d.ts",
6
6
  "description": "A bridge between Node.js and Java APIs",
@@ -56,7 +56,8 @@
56
56
  "build:java:win32": "cd java-src && .\\gradlew.bat shadowJar",
57
57
  "prepublishOnly": "napi prepublish -t npm",
58
58
  "test": "npm run testOnly",
59
- "testOnly": "mocha -r ts-node/register test/**/*.test.ts",
59
+ "testOnly": "mocha -r ts-node/register test/*.test.ts --reporter mocha-multi-reporters --reporter-options configFile=mocha-reporter-config.json",
60
+ "pretestOnly": "npm run generateTestTypes",
60
61
  "pretest": "npm run build",
61
62
  "version": "napi version",
62
63
  "prettier": "prettier --write .",
@@ -64,7 +65,8 @@
64
65
  "prebuild:debug": "rimraf dist",
65
66
  "benchmark": "ts-node -P test/tsconfig.json test/benchmark/benchmark.ts && ts-node -P test/tsconfig.json test/benchmark/benchmarkDaemonThreads.ts",
66
67
  "prebenchmark": "npm run build",
67
- "docs": "typedoc --out docs ts-src/index.ts"
68
+ "docs": "typedoc --out docs ts-src/index.ts",
69
+ "generateTestTypes": "ts-node -P test/tsconfig.json test/generateTestTypes.ts"
68
70
  },
69
71
  "dependencies": {
70
72
  "chalk": "^5.1.2",
@@ -74,28 +76,30 @@
74
76
  "yargs": "^17.6.2"
75
77
  },
76
78
  "devDependencies": {
77
- "@napi-rs/cli": "^2.12.1",
79
+ "@napi-rs/cli": "^2.13.0",
78
80
  "@types/chai": "^4.3.4",
79
81
  "@types/glob": "^8.0.0",
80
82
  "@types/is-ci": "^3.0.0",
81
- "@types/mocha": "^10.0.0",
82
- "@types/node": "^18.11.9",
83
+ "@types/mocha": "^10.0.1",
84
+ "@types/node": "^18.11.10",
83
85
  "@types/semver": "^7.3.13",
84
86
  "@types/webpack-node-externals": "^2.5.3",
85
- "@types/yargs": "^17.0.13",
87
+ "@types/yargs": "^17.0.15",
86
88
  "chai": "^4.3.7",
87
89
  "cpy-cli": "^4.2.0",
88
90
  "expose-gc": "^1.0.0",
89
91
  "is-ci": "^3.0.1",
90
92
  "mocha": "^10.1.0",
93
+ "mocha-junit-reporter": "^2.2.0",
94
+ "mocha-multi-reporters": "^1.5.1",
91
95
  "nanobench": "^3.0.0",
92
96
  "node-loader": "^2.0.0",
93
- "prettier": "^2.7.1",
97
+ "prettier": "^2.8.0",
94
98
  "rimraf": "^3.0.2",
95
99
  "run-script-os": "^1.1.6",
96
100
  "semver": "^7.3.8",
97
101
  "string-replace-loader": "^3.1.0",
98
- "ts-loader": "^9.4.1",
102
+ "ts-loader": "^9.4.2",
99
103
  "ts-node": "^10.9.1",
100
104
  "tslib": "^2.4.1",
101
105
  "typedoc": "^0.23.21",
@@ -104,11 +108,11 @@
104
108
  "webpack-node-externals": "^3.0.0"
105
109
  },
106
110
  "optionalDependencies": {
107
- "java-bridge-win32-x64-msvc": "2.1.7",
108
- "java-bridge-darwin-x64": "2.1.7",
109
- "java-bridge-linux-x64-gnu": "2.1.7",
110
- "java-bridge-darwin-arm64": "2.1.7",
111
- "java-bridge-win32-ia32-msvc": "2.1.7",
112
- "java-bridge-linux-arm64-gnu": "2.1.7"
111
+ "java-bridge-win32-x64-msvc": "2.1.8-beta.1",
112
+ "java-bridge-darwin-x64": "2.1.8-beta.1",
113
+ "java-bridge-linux-x64-gnu": "2.1.8-beta.1",
114
+ "java-bridge-darwin-arm64": "2.1.8-beta.1",
115
+ "java-bridge-win32-ia32-msvc": "2.1.8-beta.1",
116
+ "java-bridge-linux-arm64-gnu": "2.1.8-beta.1"
113
117
  }
114
118
  }