@forge/bundler 4.11.1-next.9 → 4.11.2-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,179 @@
1
1
  # @forge/bundler
2
2
 
3
+ ## 4.11.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fbb55b2c: Bumping dependencies via Renovate:
8
+
9
+ - @babel/core
10
+ - @babel/plugin-transform-class-static-block
11
+ - @babel/plugin-transform-numeric-separator
12
+ - @babel/plugin-transform-optional-chaining
13
+ - @babel/preset-typescript
14
+ - @babel/traverse
15
+ - @babel/types
16
+
17
+ - bdb0f05b: Bumping dependencies via Renovate:
18
+
19
+ - @atlassian/xen-test-util
20
+
21
+ - 9b9f58d3: Bumping dependencies via Renovate:
22
+
23
+ - @types/node
24
+
25
+ - Updated dependencies [fbb55b2c]
26
+ - Updated dependencies [bdb0f05b]
27
+ - Updated dependencies [9b9f58d3]
28
+ - @forge/babel-plugin-transform-ui@1.1.7-next.0
29
+ - @forge/cli-shared@3.17.3-next.0
30
+ - @forge/lint@3.6.6-next.0
31
+ - @forge/api@2.18.6-next.0
32
+ - @forge/node-runtime@0.1.2-next.0
33
+
34
+ ## 4.11.1
35
+
36
+ ### Patch Changes
37
+
38
+ - 4941db4a: Fix HTTP error handling in sandbox
39
+ - b9806172: Updated logging headers
40
+ - a9e43a70: Don't include runtime in sandbox wrapper
41
+ - 8c4ec99f: Bumping dependencies via Renovate:
42
+
43
+ - @atlassian/xen-test-util
44
+
45
+ - 1d4230e6: Bumping dependencies via Renovate:
46
+
47
+ - eslint
48
+ - @types/eslint
49
+
50
+ - 4f5f44dc: Bumping dependencies via Renovate:
51
+
52
+ - buffer
53
+
54
+ - 89e0c881: Use \_HANDLER to determine functions to expose on Node runtime
55
+ - 4769ae06: Bumping dependencies via Renovate:
56
+
57
+ - eslint-config-prettier
58
+
59
+ - 4be20514: Bumping dependencies via Renovate:
60
+
61
+ - eslint-plugin-prettier
62
+
63
+ - cd2b8e51: Bundle wrapper ahead of compilation for node runtime
64
+ - a5b25d46: Bumping dependencies via Renovate:
65
+
66
+ - assert
67
+
68
+ - Updated dependencies [30713ea9]
69
+ - Updated dependencies [a9e43a70]
70
+ - Updated dependencies [cdf28f27]
71
+ - Updated dependencies [8c4ec99f]
72
+ - Updated dependencies [63f3f2db]
73
+ - Updated dependencies [81556b08]
74
+ - Updated dependencies [1d4230e6]
75
+ - Updated dependencies [035116d2]
76
+ - Updated dependencies [439098ca]
77
+ - Updated dependencies [cd2b8e51]
78
+ - @forge/cli-shared@3.17.2
79
+ - @forge/node-runtime@0.1.1
80
+ - @forge/lint@3.6.5
81
+ - @forge/api@2.18.5
82
+
83
+ ## 4.11.1-next.20
84
+
85
+ ### Patch Changes
86
+
87
+ - Updated dependencies [63f3f2db]
88
+ - @forge/node-runtime@0.1.1-next.5
89
+
90
+ ## 4.11.1-next.19
91
+
92
+ ### Patch Changes
93
+
94
+ - 4941db4a: Fix HTTP error handling in sandbox
95
+
96
+ ## 4.11.1-next.18
97
+
98
+ ### Patch Changes
99
+
100
+ - 8c4ec99f: Bumping dependencies via Renovate:
101
+
102
+ - @atlassian/xen-test-util
103
+
104
+ - Updated dependencies [8c4ec99f]
105
+ - @forge/cli-shared@3.17.2-next.8
106
+ - @forge/lint@3.6.5-next.9
107
+
108
+ ## 4.11.1-next.17
109
+
110
+ ### Patch Changes
111
+
112
+ - a9e43a70: Don't include runtime in sandbox wrapper
113
+ - Updated dependencies [a9e43a70]
114
+ - @forge/node-runtime@0.1.1-next.4
115
+
116
+ ## 4.11.1-next.16
117
+
118
+ ### Patch Changes
119
+
120
+ - b9806172: Updated logging headers
121
+ - Updated dependencies [b9806172]
122
+ - @forge/runtime@5.0.0-next.5
123
+ - @forge/node-runtime@0.1.1-next.3
124
+
125
+ ## 4.11.1-next.15
126
+
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies [39a3fe44]
130
+ - @forge/runtime@5.0.0-next.4
131
+ - @forge/node-runtime@0.1.1-next.2
132
+
133
+ ## 4.11.1-next.14
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies [439098ca]
138
+ - @forge/cli-shared@3.17.2-next.7
139
+ - @forge/lint@3.6.5-next.8
140
+ - @forge/api@2.18.5-next.2
141
+ - @forge/node-runtime@0.1.1-next.1
142
+
143
+ ## 4.11.1-next.13
144
+
145
+ ### Patch Changes
146
+
147
+ - cd2b8e51: Bundle wrapper ahead of compilation for node runtime
148
+ - Updated dependencies [cd2b8e51]
149
+ - @forge/node-runtime@0.1.1-next.0
150
+ - @forge/runtime@5.0.0-next.3
151
+
152
+ ## 4.11.1-next.12
153
+
154
+ ### Patch Changes
155
+
156
+ - @forge/cli-shared@3.17.2-next.6
157
+ - @forge/lint@3.6.5-next.7
158
+
159
+ ## 4.11.1-next.11
160
+
161
+ ### Patch Changes
162
+
163
+ - Updated dependencies [ba548d9]
164
+ - @forge/runtime@4.4.7-next.2
165
+ - @forge/api@2.18.5-next.1
166
+
167
+ ## 4.11.1-next.10
168
+
169
+ ### Patch Changes
170
+
171
+ - Updated dependencies [035116d]
172
+ - @forge/api@2.18.5-next.0
173
+ - @forge/cli-shared@3.17.2-next.5
174
+ - @forge/lint@3.6.5-next.6
175
+ - @forge/runtime@4.4.7-next.1
176
+
3
177
  ## 4.11.1-next.9
4
178
 
5
179
  ### Patch Changes
@@ -1,4 +1,5 @@
1
1
  import { CommonWebpackConfig, ConfigBuilder, FunctionsEntryPoint } from './common';
2
2
  export declare const NODE_WEBPACK_CONFIG_NAME = "node-runtime";
3
+ export declare const NODE_WEBPACK_USER_CODE_DIR = "bundled";
3
4
  export declare const getNodeRuntimeBuildConfig: (entrypoints: FunctionsEntryPoint[], config: ConfigBuilder) => CommonWebpackConfig;
4
5
  //# sourceMappingURL=node.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/config/node.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EAIpB,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AAEvD,eAAO,MAAM,yBAAyB,gBACvB,mBAAmB,EAAE,UAC1B,aAAa,KACpB,mBAkCF,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/config/node.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EAGpB,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,wBAAwB,iBAAiB,CAAC;AACvD,eAAO,MAAM,0BAA0B,YAAY,CAAC;AAEpD,eAAO,MAAM,yBAAyB,gBACvB,mBAAmB,EAAE,UAC1B,aAAa,KACpB,mBA6CF,CAAC"}
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNodeRuntimeBuildConfig = exports.NODE_WEBPACK_CONFIG_NAME = void 0;
3
+ exports.getNodeRuntimeBuildConfig = exports.NODE_WEBPACK_USER_CODE_DIR = exports.NODE_WEBPACK_CONFIG_NAME = void 0;
4
+ const node_runtime_1 = require("@forge/node-runtime");
4
5
  const common_1 = require("./common");
6
+ const promises_1 = require("fs/promises");
5
7
  exports.NODE_WEBPACK_CONFIG_NAME = 'node-runtime';
8
+ exports.NODE_WEBPACK_USER_CODE_DIR = 'bundled';
6
9
  const getNodeRuntimeBuildConfig = (entrypoints, config) => {
7
10
  const webpackConfig = (0, common_1.getCommonWebpackConfig)(entrypoints, config);
8
- const wrapperPath = (0, common_1.resolveStubPath)('wrapper');
9
11
  const newEntries = {};
10
12
  for (const [entryKey, entryPath] of Object.entries(webpackConfig.entry)) {
11
- newEntries[`bundled/${entryKey}`] = entryPath;
12
- newEntries[entryKey] = wrapperPath;
13
+ newEntries[`${exports.NODE_WEBPACK_USER_CODE_DIR}/${entryKey}`] = entryPath;
13
14
  }
14
15
  webpackConfig.entry = newEntries;
15
16
  webpackConfig.target = 'node18';
@@ -20,6 +21,18 @@ const getNodeRuntimeBuildConfig = (entrypoints, config) => {
20
21
  fullySpecified: false
21
22
  }
22
23
  });
24
+ webpackConfig.plugins.push({
25
+ apply: (compiler) => {
26
+ compiler.hooks.make.tapPromise('AfterEmitPlugin', async (compilation) => {
27
+ const { RawSource } = compiler.webpack.sources;
28
+ const wrapper = await (0, promises_1.readFile)(node_runtime_1.WRAPPER_PATH, 'utf-8');
29
+ const source = new RawSource(wrapper);
30
+ for (const entrypoint of entrypoints) {
31
+ compilation.emitAsset(`${entrypoint.name}.js`, source);
32
+ }
33
+ });
34
+ }
35
+ });
23
36
  return webpackConfig;
24
37
  };
25
38
  exports.getNodeRuntimeBuildConfig = getNodeRuntimeBuildConfig;
@@ -1,10 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { IncomingMessage } from 'http';
3
5
  import { RequestOptions } from 'https';
4
6
  import { Writable } from 'readable-stream';
5
7
  import { URL } from 'url';
6
8
  import { FetchOptions } from '@forge/api';
7
- import { Callback } from './http-shared';
9
+ type HttpCallback = (res: IncomingMessage) => void;
10
+ type HttpArg = RequestOptions | string | URL | HttpCallback;
11
+ export declare const isHttpRequestOptions: (options: HttpArg) => options is RequestOptions;
8
12
  interface ChainableOptions {
9
13
  timeout?: number;
10
14
  headers: {
@@ -14,7 +18,7 @@ interface ChainableOptions {
14
18
  export declare class Request extends Writable {
15
19
  private reqBody;
16
20
  private chainableOptions;
17
- constructor(options: RequestOptions | string | URL, callback?: Callback);
21
+ constructor(options: RequestOptions | string | URL, callback?: HttpCallback);
18
22
  setHeader(name: string, value: string): Request;
19
23
  setTimeout(value: number, callback?: () => void): Request;
20
24
  private fetch;
@@ -1 +1 @@
1
- {"version":3,"file":"http-sandbox-impl.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox-impl.ts"],"names":[],"mappings":";;AAIA,OAAO,EAAE,cAA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CAC5B,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EACtC,gBAAgB,EAAE,gBAAgB,GACjC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,YAAY,CAAA;KAAE;IAuBtC,KAAK;CAGN"}
@@ -1,9 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Request = void 0;
3
+ exports.Request = exports.isHttpRequestOptions = void 0;
4
4
  const readable_stream_1 = require("readable-stream");
5
5
  const api_1 = require("@forge/api");
6
- const http_shared_1 = require("./http-shared");
6
+ const isCallback = (options) => typeof options === 'function';
7
+ const isString = (options) => typeof options === 'string';
8
+ const isURL = (options) => typeof options === 'object' && options.constructor.name === 'URL';
9
+ const isStringOrURL = (options) => isString(options) || isURL(options);
10
+ const isHttpRequestOptions = (options) => !isStringOrURL(options) && !isCallback(options);
11
+ exports.isHttpRequestOptions = isHttpRequestOptions;
12
+ function formatHttpRequestArgsToUrl(options) {
13
+ var _a, _b;
14
+ const protocol = 'https:';
15
+ const auth = options.auth ? `${options.auth}@` : '';
16
+ const host = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host;
17
+ const port = options.port ? `:${options.port}` : '';
18
+ const path = (_b = options.path) !== null && _b !== void 0 ? _b : '/';
19
+ return `${protocol}//${auth}${host}${port}${path}`;
20
+ }
7
21
  class Request extends readable_stream_1.Writable {
8
22
  constructor(options, callback) {
9
23
  super();
@@ -27,25 +41,25 @@ class Request extends readable_stream_1.Writable {
27
41
  }
28
42
  return this;
29
43
  }
30
- fetch(options) {
44
+ async fetch(options) {
31
45
  const { url, init } = Request.convertToForgeFetchArgs(options, this.chainableOptions);
32
46
  if (init.method && init.method !== 'HEAD' && init.method !== 'GET') {
33
47
  init.body = Buffer.concat(this.reqBody);
34
48
  }
35
- (0, api_1.fetch)(url, init)
36
- .then(async (response) => {
49
+ try {
50
+ const response = await (0, api_1.fetch)(url, init);
37
51
  const content = await response.arrayBuffer();
38
52
  const transformedAPIResponse = new Response(content, response);
39
53
  this.emit('response', transformedAPIResponse);
40
- })
41
- .catch((err) => {
54
+ }
55
+ catch (err) {
42
56
  if (err.message.startsWith('network timeout')) {
43
57
  this.emit('timeout');
44
58
  }
45
59
  else {
46
60
  this.emit('error', err);
47
61
  }
48
- });
62
+ }
49
63
  }
50
64
  _write(chunk, encoding, callback) {
51
65
  try {
@@ -65,15 +79,15 @@ class Request extends readable_stream_1.Writable {
65
79
  }
66
80
  }
67
81
  static urlFromFetchArgs(options) {
68
- if ((0, http_shared_1.isString)(options)) {
82
+ if (isString(options)) {
69
83
  return options;
70
84
  }
71
- else if ((0, http_shared_1.isURL)(options)) {
85
+ else if (isURL(options)) {
72
86
  return options.toString();
73
87
  }
74
88
  else {
75
89
  try {
76
- return (0, http_shared_1.formatUrl)(options);
90
+ return formatHttpRequestArgsToUrl(options);
77
91
  }
78
92
  catch (err) {
79
93
  console.error('Unable to make request with unrecognised URL options:', options);
@@ -83,7 +97,7 @@ class Request extends readable_stream_1.Writable {
83
97
  }
84
98
  static convertToForgeFetchArgs(options, chainableOptions) {
85
99
  const url = Request.urlFromFetchArgs(options);
86
- if ((0, http_shared_1.isStringOrURL)(options)) {
100
+ if (isStringOrURL(options)) {
87
101
  return { url, init: chainableOptions };
88
102
  }
89
103
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"http-sandbox.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAG1B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAElH;AAED,wBAAgB,GAAG,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAO9G;AAID,qBAAa,KAAK;gBACJ,OAAO,EAAE,YAAY;CAOlC"}
1
+ {"version":3,"file":"http-sandbox.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,OAAO,EAAE,OAAO,EAAwB,MAAM,qBAAqB,CAAC;AAEpE,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAElH;AAED,wBAAgB,GAAG,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,GAAG,OAAO,CAO9G;AAID,qBAAa,KAAK;gBACJ,OAAO,EAAE,YAAY;CAOlC"}
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Agent = exports.get = exports.request = void 0;
4
- const http_shared_1 = require("./http-shared");
5
4
  const http_sandbox_impl_1 = require("./http-sandbox-impl");
6
5
  function request(options, callback) {
7
6
  return new http_sandbox_impl_1.Request(options, callback);
8
7
  }
9
8
  exports.request = request;
10
9
  function get(options, callback) {
11
- if ((0, http_shared_1.isRequestOptions)(options)) {
10
+ if ((0, http_sandbox_impl_1.isHttpRequestOptions)(options)) {
12
11
  options = Object.assign(Object.assign({}, options), { method: 'GET' });
13
12
  }
14
13
  const result = new http_sandbox_impl_1.Request(options, callback);
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,GAAG,EAAU,MAAM,OAAO,CAAC;AACxD,OAAO,OAAO,EAAE,EAAE,QAAQ,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAG5E,OAAO,EACL,OAAO,EAGP,OAAO,EAEP,aAAa,EACb,aAAa,EACb,YAAY,EACb,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,gBAAgB,EAGhB,gBAAgB,EAGjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAA2B,UAAU,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAKtG,OAAO,EAAE,UAAU,EAAE,CAAC;AAQtB,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS,EAC7B,KAAK,EAAE,OAAO,CAAC,KAAK,GAAG,SAAS,GAC/B,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAkChC;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,EAAE,UAAU,CAAC,EAAE,GAAG,GAAG,aAAa,CAiB9F;AAED,UAAU,eAAe;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,eAAO,MAAM,WAAW,kBAAmB,aAAa,YAAY,eAAe,KAAG,QAOrF,CAAC;AA6BF,eAAO,MAAM,SAAS,YAEZ,UAAU,+EAGjB,QAAQ,IAAI,CA+Bd,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,OAwBnB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,SAAS,UAAU,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,aAAa,YAAY,eAAe,KAAG,QAOrF,CAAC;AA6BF,eAAO,MAAM,SAAS,YAEZ,UAAU,+EAGjB,QAAQ,IAAI,CA+Bd,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,OAwBnB,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAAE,SAAS,UAAU,GAAG,UAAU,EAC9D,cAAc,EAAE,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,aAAa,EAAE,aAAa,KAAK,mBAAmB,GACvF,OAAO,CAAC,EAAE,CAAC,CA8Bb;AAED,eAAO,MAAM,aAAa,EAAE,OAAuD,CAAC;AACpF,eAAO,MAAM,UAAU,EAAE,OAAO,CAAC,mBAAmB,CAA4C,CAAC;AAEjG,eAAO,MAAM,cAAc,EAAE,aAkB5B,CAAC"}
package/out/webpack.js CHANGED
@@ -42,16 +42,24 @@ function handleWebpackCompilationResult(logger, err, stats) {
42
42
  }
43
43
  }
44
44
  exports.handleWebpackCompilationResult = handleWebpackCompilationResult;
45
+ function tryReadSourceMapSync(fileSystem, sourceMap, entryName) {
46
+ try {
47
+ sourceMap[entryName] = readMemoryFileSync(fileSystem, `${entryName}.js.map`);
48
+ }
49
+ catch (e) {
50
+ }
51
+ }
45
52
  function getInMemoryBundle(config, fileSystem) {
46
53
  const output = {}, sourceMap = {};
47
54
  const outputFileSystem = fileSystem || compilerOutputFileSystem;
48
55
  for (const name in config.entry) {
49
56
  output[name] = readMemoryFileSync(outputFileSystem, `/${name}.js`).toString();
50
- try {
51
- sourceMap[name] = readMemoryFileSync(outputFileSystem, `/${name}.js.map`);
52
- }
53
- catch (e) {
57
+ if (config.name === node_1.NODE_WEBPACK_CONFIG_NAME && name.startsWith(node_1.NODE_WEBPACK_USER_CODE_DIR + '/')) {
58
+ const wrapperName = name.slice(node_1.NODE_WEBPACK_USER_CODE_DIR.length + 1);
59
+ output[wrapperName] = readMemoryFileSync(outputFileSystem, `/${wrapperName}.js`).toString();
60
+ tryReadSourceMapSync(outputFileSystem, sourceMap, wrapperName);
54
61
  }
62
+ tryReadSourceMapSync(outputFileSystem, sourceMap, name);
55
63
  }
56
64
  return { output, sourceMap };
57
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bundler",
3
- "version": "4.11.1-next.9",
3
+ "version": "4.11.2-next.0",
4
4
  "description": "Default bundler for Forge apps",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Atlassian",
@@ -12,18 +12,18 @@
12
12
  "clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo"
13
13
  },
14
14
  "dependencies": {
15
- "@babel/core": "^7.22.10",
15
+ "@babel/core": "^7.22.11",
16
16
  "@babel/plugin-transform-class-properties": "^7.22.5",
17
- "@babel/plugin-transform-class-static-block": "^7.22.5",
18
- "@babel/plugin-transform-numeric-separator": "^7.22.5",
19
- "@babel/plugin-transform-optional-chaining": "^7.22.10",
17
+ "@babel/plugin-transform-class-static-block": "^7.22.11",
18
+ "@babel/plugin-transform-numeric-separator": "^7.22.11",
19
+ "@babel/plugin-transform-optional-chaining": "^7.22.12",
20
20
  "@babel/plugin-transform-react-jsx": "^7.22.5",
21
- "@babel/preset-typescript": "^7.22.5",
22
- "@forge/api": "2.18.4",
23
- "@forge/babel-plugin-transform-ui": "1.1.6",
24
- "@forge/cli-shared": "3.17.2-next.4",
25
- "@forge/lint": "3.6.5-next.5",
26
- "@forge/runtime": "4.4.7-next.0",
21
+ "@babel/preset-typescript": "^7.22.11",
22
+ "@forge/api": "2.18.6-next.0",
23
+ "@forge/babel-plugin-transform-ui": "1.1.7-next.0",
24
+ "@forge/cli-shared": "3.17.3-next.0",
25
+ "@forge/lint": "3.6.6-next.0",
26
+ "@forge/node-runtime": "0.1.2-next.0",
27
27
  "@forge/util": "1.3.1",
28
28
  "assert": "^2.0.0",
29
29
  "babel-loader": "^8.3.0",
@@ -56,9 +56,9 @@
56
56
  "whatwg-url": "^7.1.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@atlassian/xen-test-util": "^2.1.5",
59
+ "@atlassian/xen-test-util": "^3.0.4",
60
60
  "@types/jest": "^29.5.3",
61
- "@types/node": "14.18.54",
61
+ "@types/node": "14.18.56",
62
62
  "@types/react": "^17.0.64",
63
63
  "@types/readable-stream": "^2.3.15",
64
64
  "@types/webpack-bundle-analyzer": "^4.6.0",
@@ -67,9 +67,10 @@
67
67
  "eslint": "^8.47.0",
68
68
  "eslint-config-prettier": "^9.0.0",
69
69
  "eslint-plugin-prettier": "^5.0.0",
70
- "prettier": "3.0.2"
70
+ "prettier": "3.0.2",
71
+ "@forge/runtime": "5.0.1-next.0"
71
72
  },
72
73
  "engines": {
73
74
  "node": ">=12.13.1"
74
75
  }
75
- }
76
+ }
@@ -1,8 +0,0 @@
1
- import { ConsoleMethod, P3LogEvent, LogHeader, HeadedLogLine } from '@forge/runtime';
2
- export declare function emitTunnelEvent(event: P3LogEvent): void;
3
- export declare function emitLogEvent(event: HeadedLogLine): void;
4
- export declare function forgeConsole(consoleMethod: ConsoleMethod, header: LogHeader): (...rawData: unknown[]) => void;
5
- export declare function replaceConsole(header: LogHeader): void;
6
- export declare function restoreConsole(): void;
7
- export declare function sendLogCache(): Promise<void>;
8
- //# sourceMappingURL=console.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,aAAa,EACb,UAAU,EAEV,SAAS,EAET,aAAa,EAEd,MAAM,gBAAgB,CAAC;AAWxB,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAEvD;AAOD,wBAAgB,YAAY,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAEvD;AA6BD,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,mCAY3E;AAMD,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,QAI/C;AAED,wBAAgB,cAAc,SAI7B;AAED,wBAAsB,YAAY,kBAwCjC"}
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendLogCache = exports.restoreConsole = exports.replaceConsole = exports.forgeConsole = exports.emitLogEvent = exports.emitTunnelEvent = void 0;
4
- const tslib_1 = require("tslib");
5
- const api_1 = require("@forge/api");
6
- const runtime_1 = require("@forge/runtime");
7
- const util_1 = require("util");
8
- const https = tslib_1.__importStar(require("https"));
9
- let logEventCache = [];
10
- function emitTunnelEvent(event) {
11
- process.stdout.write(JSON.stringify(event) + '\n');
12
- }
13
- exports.emitTunnelEvent = emitTunnelEvent;
14
- function emitLogEvent(event) {
15
- logEventCache.push(event);
16
- }
17
- exports.emitLogEvent = emitLogEvent;
18
- function customConsole(logLevel, header) {
19
- return (...rawData) => {
20
- var _a;
21
- const msg = (0, util_1.format)((_a = rawData[0]) !== null && _a !== void 0 ? _a : '');
22
- const rest = rawData.slice(1).map((val) => (0, util_1.format)(val));
23
- const invocationId = (0, api_1.getRuntime)().lambdaContext.awsRequestId;
24
- if (global.__forge_tunnel__) {
25
- const logEventData = { invocationId, logLevel, logArguments: [msg, ...rest] };
26
- emitTunnelEvent(logEventData);
27
- }
28
- else {
29
- const logLine = Object.assign(Object.assign({}, header), { type: runtime_1.LogType.LOG, id: invocationId, P: 3, ts: Date.now(), lvl: logLevel, msg, '*': rest });
30
- emitLogEvent(logLine);
31
- }
32
- };
33
- }
34
- function forgeConsole(consoleMethod, header) {
35
- switch (consoleMethod) {
36
- case 'debug':
37
- return customConsole(runtime_1.LogLevel.DEBUG, header);
38
- case 'warn':
39
- return customConsole(runtime_1.LogLevel.WARN, header);
40
- case 'error':
41
- return customConsole(runtime_1.LogLevel.ERROR, header);
42
- default:
43
- return customConsole(runtime_1.LogLevel.INFO, header);
44
- }
45
- }
46
- exports.forgeConsole = forgeConsole;
47
- const originalConsole = new Map(runtime_1.CONSOLE_METHODS.map((method) => [method, global.console[method]]));
48
- function replaceConsole(header) {
49
- for (const method of runtime_1.CONSOLE_METHODS) {
50
- global.console[method] = forgeConsole(method, header);
51
- }
52
- }
53
- exports.replaceConsole = replaceConsole;
54
- function restoreConsole() {
55
- for (const method of runtime_1.CONSOLE_METHODS) {
56
- global.console[method] = originalConsole.get(method);
57
- }
58
- }
59
- exports.restoreConsole = restoreConsole;
60
- async function sendLogCache() {
61
- var _a;
62
- const options = {
63
- method: 'POST',
64
- protocol: 'https',
65
- host: 'logs',
66
- path: '',
67
- headers: {
68
- 'Content-Type': 'application/json'
69
- },
70
- agent: 'FORGE_PRODUCT_REQUEST'
71
- };
72
- if (logEventCache.length > 0) {
73
- try {
74
- const req = https.request(options);
75
- req.write(JSON.stringify(logEventCache));
76
- const result = await new Promise((resolve, reject) => {
77
- req.on('response', ({ statusCode, statusMessage }) => resolve({
78
- statusCode,
79
- statusMessage
80
- }));
81
- req.on('error', reject);
82
- req.end();
83
- });
84
- if (result.statusCode === 200) {
85
- }
86
- else {
87
- process.stderr.write(`Error returned from proxy when sending logs: status code ${result.statusCode}\n`);
88
- }
89
- }
90
- catch (error) {
91
- process.stderr.write(`Sending logs to proxy ${(_a = error.stack) !== null && _a !== void 0 ? _a : error}\n`);
92
- }
93
- finally {
94
- logEventCache = [];
95
- }
96
- }
97
- }
98
- exports.sendLogCache = sendLogCache;
@@ -1,3 +0,0 @@
1
- export declare function replaceHttps(): void;
2
- export declare function restoreHttps(): void;
3
- //# sourceMappingURL=http-node.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-node.d.ts","sourceRoot":"","sources":["../../src/stubs/http-node.ts"],"names":[],"mappings":"AAsRA,wBAAgB,YAAY,SAG3B;AAED,wBAAgB,YAAY,SAG3B"}
@@ -1,160 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.restoreHttps = exports.replaceHttps = void 0;
4
- const http_1 = require("http");
5
- const perf_hooks_1 = require("perf_hooks");
6
- const url_1 = require("url");
7
- const http_shared_1 = require("./http-shared");
8
- const api_1 = require("@forge/api");
9
- const https = require('https');
10
- const FORGE_PROXY_UPSTREAM_LATENCY_HEADER = 'forge-proxy-upstream-latency';
11
- const FORGE_PROXY_RELATIVE_LOCATION_HEADER = 'forge-proxy-relative-location';
12
- const REDIRECT_STATUS = new Set([300, 301, 302, 303, 307, 308]);
13
- const originalHttpsRequest = https.request;
14
- const originalHttpsGet = https.get;
15
- function parseArgs(args) {
16
- const result = {
17
- options: {}
18
- };
19
- if (args.length > 0 && (0, http_shared_1.isStringOrURL)(args[0])) {
20
- const url = (0, http_shared_1.isString)(args[0]) ? new url_1.URL(args[0]) : args[0];
21
- result.options = (0, url_1.urlToHttpOptions)(url);
22
- args.shift();
23
- }
24
- if (args.length > 0 && (0, http_shared_1.isRequestOptions)(args[0])) {
25
- result.options = Object.assign(result.options, args[0]);
26
- args.shift();
27
- }
28
- if (args.length > 0 && (0, http_shared_1.isCallback)(args[0])) {
29
- result.callback = args[0];
30
- args.shift();
31
- }
32
- return result;
33
- }
34
- const AUTH_PROVIDERS = ['app', 'user', 'none'];
35
- function isAuthProvider(provider) {
36
- return AUTH_PROVIDERS.includes(provider);
37
- }
38
- const REMOTE_APIS = ['jira', 'confluence', 'stargate', 'bitbucket'];
39
- function isRemoteAPI(remote) {
40
- return REMOTE_APIS.includes(remote);
41
- }
42
- function getProxyPath(args) {
43
- switch (args.type) {
44
- case 'egress':
45
- return '/egress';
46
- case 'logs':
47
- return '/logs';
48
- case 'fpp':
49
- return `/fpp/provider/${args.provider}/remote/${args.remote}`;
50
- }
51
- }
52
- const providerToMetric = {
53
- app: 'asApp',
54
- user: 'asUser'
55
- };
56
- const remoteToMetric = {
57
- jira: 'requestJira',
58
- confluence: 'requestConfluence',
59
- bitbucket: 'requestBitbucket',
60
- stargate: 'requestAtlassian'
61
- };
62
- const METRICS_TAGS = { proxy: 'true' };
63
- function getMetricsName(args) {
64
- switch (args.type) {
65
- case 'logs':
66
- return 'api.log';
67
- case 'egress':
68
- return 'api.fetch';
69
- case 'fpp':
70
- const { provider, remote } = args;
71
- if (provider === 'none') {
72
- return `api.${remoteToMetric[remote]}`;
73
- }
74
- return `api.${providerToMetric[provider]}.${remoteToMetric[remote]}`;
75
- }
76
- }
77
- function getSingleString(values) {
78
- if (typeof values === 'string') {
79
- return values;
80
- }
81
- if (Array.isArray(values)) {
82
- return values[0];
83
- }
84
- }
85
- function getSingleHeader(response, header) {
86
- return getSingleString(response.headers[header]);
87
- }
88
- function request(...args) {
89
- var _a, _b;
90
- const { options, callback } = parseArgs(args);
91
- let proxyArgs = { type: 'egress' };
92
- const host = (_a = options.host) !== null && _a !== void 0 ? _a : options.hostname;
93
- if ((options === null || options === void 0 ? void 0 : options.agent) === 'FORGE_PRODUCT_REQUEST') {
94
- delete options.agent;
95
- if (host && isRemoteAPI(host)) {
96
- const authorization = getSingleString((_b = options.headers) === null || _b === void 0 ? void 0 : _b.authorization);
97
- if (authorization === null || authorization === void 0 ? void 0 : authorization.startsWith('Forge ')) {
98
- const [, provider] = authorization.split(' ');
99
- if (isAuthProvider(provider)) {
100
- proxyArgs = { type: 'fpp', provider, remote: host };
101
- }
102
- }
103
- }
104
- else if (host === 'logs') {
105
- proxyArgs = { type: 'logs' };
106
- }
107
- }
108
- const { metrics, proxy } = (0, api_1.getRuntime)();
109
- const metricsName = getMetricsName(proxyArgs);
110
- const headers = Object.assign(Object.assign({}, options.headers), { 'forge-proxy-authorization': `Bearer ${proxy.token}` });
111
- if (proxy.host) {
112
- headers['Host'] = proxy.host;
113
- }
114
- switch (proxyArgs.type) {
115
- case 'egress':
116
- headers['forge-proxy-target'] = (0, http_shared_1.formatUrl)(options);
117
- break;
118
- case 'fpp':
119
- headers['forge-proxy-target'] = options.path;
120
- break;
121
- case 'logs':
122
- break;
123
- }
124
- const proxyOptions = Object.assign(Object.assign(Object.assign({}, options), (0, url_1.urlToHttpOptions)(new url_1.URL(`${proxy.url}${getProxyPath(proxyArgs)}`))), { headers });
125
- metrics.counter(metricsName, METRICS_TAGS).incr();
126
- const originalRequest = proxyOptions.protocol === 'http:' ? http_1.request : originalHttpsRequest;
127
- const requestStart = perf_hooks_1.performance.now();
128
- return originalRequest(proxyOptions, (response) => {
129
- const requestEnd = perf_hooks_1.performance.now();
130
- metrics.timing(metricsName, METRICS_TAGS).set(requestEnd - requestStart);
131
- const upstreamLatencyHeader = getSingleHeader(response, FORGE_PROXY_UPSTREAM_LATENCY_HEADER);
132
- if (upstreamLatencyHeader !== undefined) {
133
- const proxyUpstreamLatency = parseInt(upstreamLatencyHeader);
134
- metrics.timing('proxy-success-overhead', METRICS_TAGS).set(requestEnd - requestStart - proxyUpstreamLatency);
135
- }
136
- if (response.statusCode && REDIRECT_STATUS.has(response.statusCode)) {
137
- const relativeLocation = getSingleHeader(response, FORGE_PROXY_RELATIVE_LOCATION_HEADER);
138
- if (relativeLocation) {
139
- response.headers['location'] = `https://${host}${relativeLocation}`;
140
- }
141
- }
142
- callback === null || callback === void 0 ? void 0 : callback(response);
143
- });
144
- }
145
- function get(...args) {
146
- const { options, callback } = parseArgs(args);
147
- const result = request(Object.assign(Object.assign({}, options), { method: 'GET' }), ...(callback ? [callback] : []));
148
- result.end();
149
- return result;
150
- }
151
- function replaceHttps() {
152
- https.request = request;
153
- https.get = get;
154
- }
155
- exports.replaceHttps = replaceHttps;
156
- function restoreHttps() {
157
- https.request = originalHttpsRequest;
158
- https.get = originalHttpsGet;
159
- }
160
- exports.restoreHttps = restoreHttps;
@@ -1,15 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import { IncomingMessage } from 'http';
5
- import { RequestOptions } from 'https';
6
- import { URL } from 'url';
7
- export type Callback = (res: IncomingMessage) => void;
8
- export type Arg = RequestOptions | string | URL | Callback;
9
- export declare const isCallback: (options: Arg) => options is Callback;
10
- export declare const isString: (options: Arg) => options is string;
11
- export declare const isURL: (options: Arg) => options is URL;
12
- export declare const isStringOrURL: (options: Arg) => options is string | URL;
13
- export declare const isRequestOptions: (options: Arg) => options is RequestOptions;
14
- export declare function formatUrl(options: RequestOptions): string;
15
- //# sourceMappingURL=http-shared.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-shared.d.ts","sourceRoot":"","sources":["../../src/stubs/http-shared.ts"],"names":[],"mappings":";;;AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI,CAAC;AAEtD,MAAM,MAAM,GAAG,GAAG,cAAc,GAAG,MAAM,GAAG,GAAG,GAAG,QAAQ,CAAC;AAE3D,eAAO,MAAM,UAAU,YAAa,GAAG,wBAAuD,CAAC;AAC/F,eAAO,MAAM,QAAQ,YAAa,GAAG,sBAAmD,CAAC;AACzF,eAAO,MAAM,KAAK,YAAa,GAAG,mBACiC,CAAC;AAEpE,eAAO,MAAM,aAAa,YAAa,GAAG,4BAAiE,CAAC;AAE5G,eAAO,MAAM,gBAAgB,YAAa,GAAG,8BACI,CAAC;AAElD,wBAAgB,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAQzD"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatUrl = exports.isRequestOptions = exports.isStringOrURL = exports.isURL = exports.isString = exports.isCallback = void 0;
4
- const isCallback = (options) => typeof options === 'function';
5
- exports.isCallback = isCallback;
6
- const isString = (options) => typeof options === 'string';
7
- exports.isString = isString;
8
- const isURL = (options) => typeof options === 'object' && options.constructor.name === 'URL';
9
- exports.isURL = isURL;
10
- const isStringOrURL = (options) => (0, exports.isString)(options) || (0, exports.isURL)(options);
11
- exports.isStringOrURL = isStringOrURL;
12
- const isRequestOptions = (options) => !(0, exports.isStringOrURL)(options) && !(0, exports.isCallback)(options);
13
- exports.isRequestOptions = isRequestOptions;
14
- function formatUrl(options) {
15
- var _a, _b;
16
- const protocol = 'https:';
17
- const auth = options.auth ? `${options.auth}@` : '';
18
- const host = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host;
19
- const port = options.port ? `:${options.port}` : '';
20
- const path = (_b = options.path) !== null && _b !== void 0 ? _b : '/';
21
- return `${protocol}//${auth}${host}${port}${path}`;
22
- }
23
- exports.formatUrl = formatUrl;
@@ -1,6 +0,0 @@
1
- import { ExternalRequestBody, LogHeader } from '@forge/runtime';
2
- export declare const AWS_EXECUTION_ENV_PREFIX = "AWS_Lambda_";
3
- export declare const RUNTIME_NAME_FALLBACK = "node";
4
- export declare function getRuntimeName(): string;
5
- export declare function invocationHeaderLogs(lambdaEvent: ExternalRequestBody): LogHeader;
6
- //# sourceMappingURL=log-events.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"log-events.d.ts","sourceRoot":"","sources":["../../src/stubs/log-events.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAW,MAAM,gBAAgB,CAAC;AAEzE,eAAO,MAAM,wBAAwB,gBAAgB,CAAC;AACtD,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C,wBAAgB,cAAc,IAAI,MAAM,CAavC;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,mBAAmB,GAAG,SAAS,CAiBhF"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invocationHeaderLogs = exports.getRuntimeName = exports.RUNTIME_NAME_FALLBACK = exports.AWS_EXECUTION_ENV_PREFIX = void 0;
4
- const api_1 = require("@forge/api");
5
- const runtime_1 = require("@forge/runtime");
6
- exports.AWS_EXECUTION_ENV_PREFIX = 'AWS_Lambda_';
7
- exports.RUNTIME_NAME_FALLBACK = 'node';
8
- function getRuntimeName() {
9
- const awsRuntime = process.env.AWS_EXECUTION_ENV;
10
- if (!awsRuntime) {
11
- return exports.RUNTIME_NAME_FALLBACK;
12
- }
13
- if (awsRuntime.startsWith(exports.AWS_EXECUTION_ENV_PREFIX)) {
14
- return awsRuntime.substring(exports.AWS_EXECUTION_ENV_PREFIX.length);
15
- }
16
- return awsRuntime;
17
- }
18
- exports.getRuntimeName = getRuntimeName;
19
- function invocationHeaderLogs(lambdaEvent) {
20
- const { featureFlags, contextAri, appContext, tracing } = lambdaEvent === null || lambdaEvent === void 0 ? void 0 : lambdaEvent._meta;
21
- const { appId, environmentId, appVersion, functionKey, moduleKey, moduleType } = appContext !== null && appContext !== void 0 ? appContext : {};
22
- return {
23
- id: (0, api_1.getRuntime)().lambdaContext.awsRequestId,
24
- type: runtime_1.LogType.HEADER,
25
- appId,
26
- environmentId,
27
- appVersion,
28
- installationContext: contextAri,
29
- functionKey,
30
- moduleType,
31
- moduleKey,
32
- b3: `${tracing.traceId}-${tracing.spanId}`,
33
- featureFlags: featureFlags || [],
34
- runtime: getRuntimeName()
35
- };
36
- }
37
- exports.invocationHeaderLogs = invocationHeaderLogs;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=wrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../src/stubs/wrapper.ts"],"names":[],"mappings":""}
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var _a, _b, _c, _d;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const api_1 = require("@forge/api");
5
- const runtime_1 = require("@forge/runtime");
6
- const console_1 = require("./console");
7
- const http_node_1 = require("./http-node");
8
- const log_events_1 = require("./log-events");
9
- const wrappedFilename = __filename.replace(/\/[^/]+.js$/, (name) => '/bundled' + name);
10
- const realRequire = eval('require');
11
- if (!realRequire) {
12
- throw new Error(`Unexpected require: ${realRequire}`);
13
- }
14
- const handler = (_b = (_a = process.env._HANDLER) === null || _a === void 0 ? void 0 : _a.split('.')) === null || _b === void 0 ? void 0 : _b[1];
15
- if (!handler) {
16
- throw new Error('Expected to find function handler name in _HANDLER environment variable.');
17
- }
18
- const adapter = (name) => {
19
- return async (lambdaEvent, lambdaContext) => {
20
- var _a, _b;
21
- const event = lambdaEvent.body;
22
- const context = (0, runtime_1.setupRequestContext)({ meta: lambdaEvent._meta, handler: lambdaEvent.handler });
23
- const metricsCollector = new runtime_1.MetricsCollector(new runtime_1.InMemoryMetrics({ runtime: 'nodejs' }));
24
- const metrics = metricsCollector.metrics();
25
- const rms = lambdaEvent._meta.rms;
26
- const runtime = Object.assign(Object.assign({ proxy: lambdaEvent._meta.proxy, contextAri: lambdaEvent._meta.contextAri, appContext: lambdaEvent._meta.appContext, allowedEgress: (_a = lambdaEvent._meta.fetchAllowList) !== null && _a !== void 0 ? _a : [], lambdaContext: lambdaContext, tracing: lambdaEvent._meta.tracing, aaid: lambdaEvent._meta.aaid }, (rms && { rms })), { metrics });
27
- global.__forge_runtime__ = runtime;
28
- for (const { key, value } of (_b = lambdaEvent.variables) !== null && _b !== void 0 ? _b : []) {
29
- process.env[key] = value;
30
- }
31
- try {
32
- const header = (0, log_events_1.invocationHeaderLogs)(lambdaEvent);
33
- (0, console_1.replaceConsole)(header);
34
- (0, http_node_1.replaceHttps)();
35
- const timer = metrics.timing('invoke').measure();
36
- const bundled = realRequire(wrappedFilename);
37
- let result;
38
- try {
39
- try {
40
- result = await bundled[name](event, context);
41
- }
42
- catch (err) {
43
- console.error(err);
44
- throw err;
45
- }
46
- }
47
- finally {
48
- await (0, console_1.sendLogCache)();
49
- timer.stop();
50
- }
51
- return {
52
- success: true,
53
- body: result,
54
- metrics: metricsCollector.collectMetrics()
55
- };
56
- }
57
- catch (err) {
58
- const errorName = (0, api_1.isForgePlatformError)(err) ? err.name : api_1.FUNCTION_ERR;
59
- return {
60
- success: false,
61
- error: {
62
- errorMessage: err.message,
63
- errorType: errorName,
64
- isHostedCodeError: (0, api_1.isHostedCodeError)(errorName),
65
- stack: (err.stack || '').split('\n'),
66
- serviceKey: err.serviceKey
67
- },
68
- metrics: metricsCollector.collectMetrics()
69
- };
70
- }
71
- };
72
- };
73
- (_d = (_c = process).setSourceMapsEnabled) === null || _d === void 0 ? void 0 : _d.call(_c, true);
74
- exports[handler] = adapter(handler);