@jsii/kernel 1.70.0 → 1.72.0

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/lib/api.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { JsiiErrorType } from './kernel';
1
2
  export declare const TOKEN_REF = "$jsii.byref";
2
3
  export declare const TOKEN_INTERFACES = "$jsii.interfaces";
3
4
  export declare const TOKEN_DATE = "$jsii.date";
@@ -65,6 +66,16 @@ export interface LoadResponse {
65
66
  readonly assembly: string;
66
67
  readonly types: number;
67
68
  }
69
+ export interface GetScriptCommandRequest {
70
+ readonly assembly: string;
71
+ readonly script: string;
72
+ readonly args?: string[];
73
+ }
74
+ export interface GetScriptCommandResponse {
75
+ command: string;
76
+ args: string[];
77
+ env: Record<string, string>;
78
+ }
68
79
  export interface InvokeScriptRequest {
69
80
  readonly assembly: string;
70
81
  readonly script: string;
@@ -190,5 +201,6 @@ export interface OkayResponse {
190
201
  export interface ErrorResponse {
191
202
  readonly error: string;
192
203
  readonly stack?: string;
204
+ readonly name?: JsiiErrorType;
193
205
  }
194
206
  //# sourceMappingURL=api.d.ts.map
package/lib/kernel.d.ts CHANGED
@@ -44,6 +44,7 @@ export declare class Kernel {
44
44
  constructor(callbackHandler: (callback: api.Callback) => any);
45
45
  load(req: api.LoadRequest): api.LoadResponse;
46
46
  private _load;
47
+ getBinScriptCommand(req: api.GetScriptCommandRequest): api.GetScriptCommandResponse;
47
48
  invokeBinScript(req: api.InvokeScriptRequest): api.InvokeScriptResponse;
48
49
  create(req: api.CreateRequest): api.CreateResponse;
49
50
  del(req: api.DelRequest): api.DelResponse;
@@ -94,6 +95,10 @@ export declare class Kernel {
94
95
  */
95
96
  private _ensureSync;
96
97
  private _findPropertyTarget;
98
+ /**
99
+ * Shared (non-public implementation) to as not to break API recording.
100
+ */
101
+ private _getBinScriptCommand;
97
102
  private _makecbid;
98
103
  private _makeprid;
99
104
  }
package/lib/kernel.js CHANGED
@@ -116,38 +116,22 @@ class Kernel {
116
116
  types: Object.keys((_c = assmSpec.types) !== null && _c !== void 0 ? _c : {}).length,
117
117
  };
118
118
  }
119
+ getBinScriptCommand(req) {
120
+ return this._getBinScriptCommand(req);
121
+ }
119
122
  invokeBinScript(req) {
120
- var _a;
121
- const packageDir = this._getPackageDir(req.assembly);
122
- if (fs.pathExistsSync(packageDir)) {
123
- // module exists, verify version
124
- const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
125
- if (!epkg.bin) {
126
- throw new JsiiFault('There is no bin scripts defined for this package.');
127
- }
128
- const scriptPath = epkg.bin[req.script];
129
- if (!epkg.bin) {
130
- throw new JsiiFault(`Script with name ${req.script} was not defined.`);
131
- }
132
- const result = cp.spawnSync(path.join(packageDir, scriptPath), (_a = req.args) !== null && _a !== void 0 ? _a : [], {
133
- encoding: 'utf-8',
134
- env: {
135
- ...process.env,
136
- // Make sure the current NODE_OPTIONS are honored if we shell out to node
137
- NODE_OPTIONS: process.execArgv.join(' '),
138
- // Make sure "this" node is ahead of $PATH just in case
139
- PATH: `${path.dirname(process.execPath)}:${process.env.PATH}`,
140
- },
141
- shell: true,
142
- });
143
- return {
144
- stdout: result.stdout,
145
- stderr: result.stderr,
146
- status: result.status,
147
- signal: result.signal,
148
- };
149
- }
150
- throw new JsiiFault(`Package with name ${req.assembly} was not loaded.`);
123
+ const { command, args, env } = this._getBinScriptCommand(req);
124
+ const result = cp.spawnSync(command, args, {
125
+ encoding: 'utf-8',
126
+ env,
127
+ shell: true,
128
+ });
129
+ return {
130
+ stdout: result.stdout,
131
+ stderr: result.stderr,
132
+ status: result.status,
133
+ signal: result.signal,
134
+ };
151
135
  }
152
136
  create(req) {
153
137
  return this._create(req);
@@ -303,10 +287,16 @@ class Kernel {
303
287
  catch (e) {
304
288
  this._debug('promise error:', e);
305
289
  if (e.name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */) {
290
+ if (e instanceof JsiiFault) {
291
+ throw e;
292
+ }
306
293
  throw new JsiiFault(e.message);
307
294
  }
308
295
  // default to RuntimeError, since non-kernel errors may not
309
296
  // have their `name` field defined
297
+ if (e instanceof RuntimeError) {
298
+ throw e;
299
+ }
310
300
  throw new RuntimeError(e);
311
301
  }
312
302
  return {
@@ -876,11 +866,17 @@ class Kernel {
876
866
  }
877
867
  catch (e) {
878
868
  if (e.name === "@jsii/kernel.Fault" /* JsiiErrorType.JSII_FAULT */) {
869
+ if (e instanceof JsiiFault) {
870
+ throw e;
871
+ }
879
872
  throw new JsiiFault(e);
880
873
  }
881
874
  // This error can be thrown by the kernel directly, or it can be
882
875
  // thrown from user code. If the error comes from the kernel, then its name field will be populated;
883
876
  // if the error comes from user code, the name field will not be populated.
877
+ if (e instanceof RuntimeError) {
878
+ throw e;
879
+ }
884
880
  throw new RuntimeError(e);
885
881
  }
886
882
  finally {
@@ -894,6 +890,33 @@ class Kernel {
894
890
  }
895
891
  return property;
896
892
  }
893
+ /**
894
+ * Shared (non-public implementation) to as not to break API recording.
895
+ */
896
+ _getBinScriptCommand(req) {
897
+ var _a, _b;
898
+ const packageDir = this._getPackageDir(req.assembly);
899
+ if (fs.pathExistsSync(packageDir)) {
900
+ // module exists, verify version
901
+ const epkg = fs.readJsonSync(path.join(packageDir, 'package.json'));
902
+ const scriptPath = (_a = epkg.bin) === null || _a === void 0 ? void 0 : _a[req.script];
903
+ if (!epkg.bin) {
904
+ throw new JsiiFault(`Script with name ${req.script} was not defined.`);
905
+ }
906
+ return {
907
+ command: path.join(packageDir, scriptPath),
908
+ args: (_b = req.args) !== null && _b !== void 0 ? _b : [],
909
+ env: {
910
+ ...process.env,
911
+ // Make sure the current NODE_OPTIONS are honored if we shell out to node
912
+ NODE_OPTIONS: process.execArgv.join(' '),
913
+ // Make sure "this" node is ahead of $PATH just in case
914
+ PATH: `${path.dirname(process.execPath)}:${process.env.PATH}`,
915
+ },
916
+ };
917
+ }
918
+ throw new JsiiFault(`Package with name ${req.assembly} was not loaded.`);
919
+ }
897
920
  //
898
921
  // type information
899
922
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsii/kernel",
3
- "version": "1.70.0",
3
+ "version": "1.72.0",
4
4
  "description": "kernel for jsii execution environment",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -31,19 +31,19 @@
31
31
  "package": "package-js"
32
32
  },
33
33
  "dependencies": {
34
- "@jsii/spec": "^1.70.0",
34
+ "@jsii/spec": "^1.72.0",
35
35
  "fs-extra": "^10.1.0",
36
36
  "lockfile": "^1.0.4",
37
- "tar": "^6.1.11"
37
+ "tar": "^6.1.12"
38
38
  },
39
39
  "devDependencies": {
40
- "@scope/jsii-calc-base": "^1.70.0",
41
- "@scope/jsii-calc-lib": "^1.70.0",
40
+ "@scope/jsii-calc-base": "^1.72.0",
41
+ "@scope/jsii-calc-lib": "^1.72.0",
42
42
  "@types/fs-extra": "^9.0.13",
43
43
  "@types/lockfile": "^1.0.2",
44
44
  "@types/tar": "^6.1.3",
45
45
  "jest-expect-message": "^1.1.3",
46
- "jsii-build-tools": "^1.70.0",
46
+ "jsii-build-tools": "^1.72.0",
47
47
  "jsii-calc": "^3.20.120"
48
48
  }
49
49
  }