@freestyle-sh/with-java 0.2.0 → 0.2.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.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { VmWithInstance, VmWith, CreateVmOptions } from 'freestyle-sandboxes';
1
+ import { VmWithInstance, VmWith, VmSpec } from 'freestyle-sandboxes';
2
2
  import { VmRunCodeInstance, JSONValue, RunCodeResponse, VmRunCode } from '@freestyle-sh/with-type-run-code';
3
3
 
4
4
  declare class VmJavaInstance extends VmWithInstance implements VmRunCodeInstance {
5
- runCode<Result extends JSONValue = any>({ code, }: {
5
+ runCode<Result extends JSONValue = any>(args: string | {
6
6
  code: string;
7
7
  }): Promise<RunCodeResponse<Result>>;
8
8
  }
@@ -11,7 +11,7 @@ declare class VmJava extends VmWith<VmJavaInstance> implements VmRunCode<VmRunCo
11
11
  constructor(options?: {
12
12
  version: string;
13
13
  });
14
- configure(existingConfig: CreateVmOptions): CreateVmOptions | Promise<CreateVmOptions>;
14
+ configureSnapshotSpec(spec: VmSpec): VmSpec;
15
15
  createInstance(): VmJavaInstance;
16
16
  installServiceName(): string;
17
17
  }
package/dist/index.js CHANGED
@@ -1,9 +1,8 @@
1
- import { VmWithInstance, VmWith, VmTemplate } from 'freestyle-sandboxes';
1
+ import { VmWithInstance, VmWith, VmSpec } from 'freestyle-sandboxes';
2
2
 
3
3
  class VmJavaInstance extends VmWithInstance {
4
- async runCode({
5
- code
6
- }) {
4
+ async runCode(args) {
5
+ const code = typeof args === "string" ? args : args.code;
7
6
  const result = await this.vm.exec({
8
7
  command: `java -cp /tmp -c "${code.replace(/"/g, '\\"')}"`
9
8
  });
@@ -30,7 +29,7 @@ class VmJava extends VmWith {
30
29
  super();
31
30
  this.options = options;
32
31
  }
33
- configure(existingConfig) {
32
+ configureSnapshotSpec(spec) {
34
33
  const installScript = `#!/bin/bash
35
34
  set -e
36
35
  sudo apt-get update
@@ -42,8 +41,9 @@ echo "deb [signed-by=/usr/share/keyrings/corretto-keyring.gpg] https://apt.corre
42
41
  sudo apt-get update
43
42
  sudo apt-get install -y java-${this.options.version}-amazon-corretto-jdk libxi6 libxtst6 libxrender1
44
43
  `;
45
- const javaConfig = {
46
- template: new VmTemplate({
44
+ return this.composeSpecs(
45
+ spec,
46
+ new VmSpec({
47
47
  additionalFiles: {
48
48
  "/opt/install-java.sh": {
49
49
  content: installScript
@@ -61,8 +61,7 @@ sudo apt-get install -y java-${this.options.version}-amazon-corretto-jdk libxi6
61
61
  ]
62
62
  }
63
63
  })
64
- };
65
- return this.compose(existingConfig, javaConfig);
64
+ );
66
65
  }
67
66
  createInstance() {
68
67
  return new VmJavaInstance();
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@freestyle-sh/with-java",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "private": false,
5
5
  "dependencies": {
6
- "freestyle-sandboxes": "^0.1.2",
7
- "@freestyle-sh/with-type-run-code": "^0.2.0"
6
+ "freestyle-sandboxes": "^0.1.8",
7
+ "@freestyle-sh/with-type-run-code": "^0.2.1"
8
8
  },
9
9
  "type": "module",
10
10
  "main": "./dist/index.js",