@forge/bundler 3.1.1-next.0 → 3.1.1-next.2

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,18 @@
1
1
  # @forge/bundler
2
2
 
3
+ ## 3.1.1-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - cbe3fb6: Added console overrides to the new runtime and integration with expected XLI format
8
+
9
+ ## 3.1.1-next.1
10
+
11
+ ### Patch Changes
12
+
13
+ - @forge/cli-shared@3.1.1-next.1
14
+ - @forge/lint@3.2.5-next.1
15
+
3
16
  ## 3.1.1-next.0
4
17
 
5
18
  ### Patch Changes
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=__PLACEHOLDER_MODULE__.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"__PLACEHOLDER_MODULE__.d.ts","sourceRoot":"","sources":["../src/__PLACEHOLDER_MODULE__.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -1 +1 @@
1
- {"version":3,"file":"node-webpack-config.d.ts","sourceRoot":"","sources":["../../src/bundler-config/node-webpack-config.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,WAAW,EAA0B,MAAM,YAAY,CAAC;AAEhF,eAAO,MAAM,yBAAyB,qCAAsC,aAAa,KAAG,aAY3F,CAAC"}
1
+ {"version":3,"file":"node-webpack-config.d.ts","sourceRoot":"","sources":["../../src/bundler-config/node-webpack-config.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,aAAa,IAAI,aAAa,EAAE,MAAM,SAAS,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,WAAW,EAA0B,MAAM,YAAY,CAAC;AAEhF,eAAO,MAAM,yBAAyB,qCAAsC,aAAa,KAAG,aAc3F,CAAC"}
@@ -9,7 +9,9 @@ exports.getNodeRuntimeBuildConfig = (entrypoints, config) => {
9
9
  const webpackConfig = webpack_2.getCommonWebpackConfig(entrypoints, config);
10
10
  const nodeConfigPlugin = new webpack_1.default.ProvidePlugin({
11
11
  api: path_1.resolve(path_1.join(__dirname, '..', 'forge-api')),
12
- 'global.api': path_1.resolve(path_1.join(__dirname, '..', 'forge-api'))
12
+ 'global.api': path_1.resolve(path_1.join(__dirname, '..', 'forge-api')),
13
+ console: path_1.resolve(path_1.join(__dirname, '..', 'console')),
14
+ 'global.console': path_1.resolve(path_1.join(__dirname, '..', 'console'))
13
15
  });
14
16
  webpackConfig.plugins.push(nodeConfigPlugin);
15
17
  webpackConfig.target = 'node14';
@@ -0,0 +1,2 @@
1
+ export declare const starSerializer: (arg: any) => any;
2
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../src/console.ts"],"names":[],"mappings":"AAmDA,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,GAsBzC,CAAC"}
package/out/console.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.starSerializer = void 0;
4
+ const bunyan_1 = require("bunyan");
5
+ const isNonEmptyArray = (arr) => arr.length > 0;
6
+ function transformSandBoxLogMessage(message) {
7
+ let msg = '', starval = [];
8
+ if (typeof message === 'string') {
9
+ msg = message;
10
+ }
11
+ else {
12
+ if (Array.isArray(message) && message.length > 0) {
13
+ const first = message[0];
14
+ if (typeof first === 'string') {
15
+ msg = first;
16
+ starval = message.slice(1);
17
+ }
18
+ else {
19
+ starval = message;
20
+ }
21
+ }
22
+ }
23
+ return {
24
+ msg: msg,
25
+ '*': starval
26
+ };
27
+ }
28
+ exports.starSerializer = (arg) => {
29
+ var _a, _b;
30
+ if (typeof arg !== 'object') {
31
+ return arg;
32
+ }
33
+ if (Array.isArray(arg)) {
34
+ return arg.map(exports.starSerializer);
35
+ }
36
+ if (arg instanceof Error) {
37
+ return {
38
+ message: arg.message,
39
+ name: arg.name,
40
+ stack: (_a = arg.stack) !== null && _a !== void 0 ? _a : ''
41
+ };
42
+ }
43
+ if (((_b = arg === null || arg === void 0 ? void 0 : arg.constructor) === null || _b === void 0 ? void 0 : _b.name) !== 'Object') {
44
+ return arg;
45
+ }
46
+ const res = {};
47
+ for (const prop in arg) {
48
+ res[prop] = exports.starSerializer(arg[prop]);
49
+ }
50
+ return res;
51
+ };
52
+ function formatLogMessage(requestId, logEventData) {
53
+ const transformedMessage = transformSandBoxLogMessage(logEventData.logArguments);
54
+ return {
55
+ msg: transformedMessage.msg,
56
+ id: requestId,
57
+ type: 'log',
58
+ P: 3,
59
+ ts: Date.now(),
60
+ lvl: logEventData.logLevel,
61
+ '*': transformedMessage['*']
62
+ };
63
+ }
64
+ const logger = bunyan_1.createLogger({
65
+ name: 'node-runtime',
66
+ level: bunyan_1.levelFromName.info,
67
+ serializers: { err: bunyan_1.stdSerializers.err, '*': exports.starSerializer }
68
+ });
69
+ function customConsole(logMethod) {
70
+ return (...rawData) => {
71
+ const context = global.lambdaContext;
72
+ if (isNonEmptyArray(rawData)) {
73
+ const logEventData = {
74
+ invocationId: context === null || context === void 0 ? void 0 : context.awsRequestId,
75
+ logLevel: bunyan_1.levelFromName[logMethod],
76
+ logArguments: rawData
77
+ };
78
+ const data = formatLogMessage(context === null || context === void 0 ? void 0 : context.awsRequestId, logEventData);
79
+ logger.info(data, data.msg);
80
+ }
81
+ };
82
+ }
83
+ module.exports = {
84
+ log: customConsole('info'),
85
+ info: customConsole('info'),
86
+ warn: customConsole('warn'),
87
+ debug: customConsole('debug'),
88
+ error: customConsole('error')
89
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAGA,OAAgB,EAAY,aAAa,IAAI,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE3F,OAAO,EAAE,OAAO,EAAkC,OAAO,EAAkB,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB1G,oBAAY,WAAW,GAAG,KAAK,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAQH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,MAEtD,CAAC;AAsCF,eAAO,MAAM,gBAAgB,WAAY,aAAa,KAAG,MASxD,CAAC;AACF,aAAK,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACrE,aAAK,mBAAmB,GAAG,cAAc,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAClE,aAAK,mBAAmB,GAAG,cAAc,CAAC,aAAa,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;AACvH,eAAO,MAAM,sBAAsB,qCAAsC,aAAa,KAAG,mBA8FxF,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAwED,eAAO,MAAM,KAAK,EAAE,OAwCnB,CAAC;AAEF,eAAO,MAAM,aAAa,6DACkC,aAAa,KAAK,aAAa,KACxF,OAyCF,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,OAAuD,CAAC;AAEpF,eAAO,MAAM,UAAU,EAAE,OAwBxB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,aAoB5B,CAAC"}
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../src/webpack.ts"],"names":[],"mappings":"AAGA,OAAgB,EAAY,aAAa,IAAI,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE3F,OAAO,EAAE,OAAO,EAAkC,OAAO,EAAkB,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB1G,oBAAY,WAAW,GAAG,KAAK,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAQH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,MAEtD,CAAC;AAsCF,eAAO,MAAM,gBAAgB,WAAY,aAAa,KAAG,MASxD,CAAC;AACF,aAAK,cAAc,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACrE,aAAK,mBAAmB,GAAG,cAAc,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAClE,aAAK,mBAAmB,GAAG,cAAc,CAAC,aAAa,EAAE,SAAS,GAAG,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;AACvH,eAAO,MAAM,sBAAsB,qCAAsC,aAAa,KAAG,mBA8FxF,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAwED,eAAO,MAAM,KAAK,EAAE,OAwCnB,CAAC;AAEF,eAAO,MAAM,aAAa,6DACkC,aAAa,KAAK,aAAa,KACxF,OAyCF,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,OAAuD,CAAC;AAEpF,eAAO,MAAM,UAAU,EAAE,OAuBxB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,aAoB5B,CAAC"}
package/out/webpack.js CHANGED
@@ -273,7 +273,7 @@ exports.sandboxBundle = exports.createBundler(sandboxed_webpack_config_1.getSand
273
273
  exports.nodeBundle = async (appDirectory, entryPoints) => {
274
274
  const bundler = exports.createBundler(node_webpack_config_1.getNodeRuntimeBuildConfig);
275
275
  const { output: bundlerOutput, sourceMap: bundlerSourceMap, metadata } = await bundler(appDirectory, entryPoints);
276
- const wrapper = fs_1.readFileSync(path_1.join(__dirname, 'wrapper.js')).toString();
276
+ const wrapper = fs_1.readFileSync(path_1.join(__dirname, '../out/wrapper.js')).toString();
277
277
  const output = {};
278
278
  const sourceMap = {};
279
279
  entryPoints.forEach(({ name }) => {
@@ -283,7 +283,7 @@ exports.nodeBundle = async (appDirectory, entryPoints) => {
283
283
  if (sourceMapValue) {
284
284
  sourceMap[wrappedName] = sourceMapValue;
285
285
  }
286
- output[name] = wrapper.replace("'__MODULE__'", JSON.stringify('./' + wrappedName));
286
+ output[name] = wrapper.replace("'./__PLACEHOLDER_MODULE__'", JSON.stringify('./' + wrappedName));
287
287
  });
288
288
  return { output, sourceMap, metadata };
289
289
  };
package/out/wrapper.d.ts CHANGED
@@ -1,2 +1,82 @@
1
- export {};
1
+ declare function createInstallationContext({ contextAri }: {
2
+ contextAri: any;
3
+ }): {
4
+ projectId: string | undefined;
5
+ installContext: any;
6
+ repositoryId?: undefined;
7
+ } | {
8
+ repositoryId: string | undefined;
9
+ installContext: any;
10
+ projectId?: undefined;
11
+ } | {
12
+ installContext: any;
13
+ projectId?: undefined;
14
+ repositoryId?: undefined;
15
+ };
16
+ declare function isAccountIdDefined(accountId: any): boolean;
17
+ declare function createPrincipal({ aaid: accountId }: {
18
+ aaid: any;
19
+ }): {
20
+ accountId: any;
21
+ } | undefined;
22
+ declare function createLicenseContext({ license }: {
23
+ license: {
24
+ isActive: boolean;
25
+ };
26
+ }): {
27
+ license: {
28
+ isActive: boolean;
29
+ };
30
+ } | undefined;
31
+ declare function setupRequestContext(meta: any): {
32
+ projectId: string | undefined;
33
+ installContext: any;
34
+ repositoryId?: undefined;
35
+ license?: {
36
+ isActive: boolean;
37
+ };
38
+ principal: {
39
+ accountId: any;
40
+ } | undefined;
41
+ } | {
42
+ repositoryId: string | undefined;
43
+ installContext: any;
44
+ projectId?: undefined;
45
+ license?: {
46
+ isActive: boolean;
47
+ };
48
+ principal: {
49
+ accountId: any;
50
+ } | undefined;
51
+ } | {
52
+ installContext: any;
53
+ projectId?: undefined;
54
+ repositoryId?: undefined;
55
+ license?: {
56
+ isActive: boolean;
57
+ };
58
+ principal: {
59
+ accountId: any;
60
+ } | undefined;
61
+ };
62
+ declare function serializeThrownObjects(arg: any): any;
63
+ declare function invocationHeaderLogs(lambdaEvent: any): Record<string, any>;
64
+ declare function invocationFooterLogs(successfulInvocation: boolean): Record<string, any>;
65
+ declare enum BunyanCoreLogEventTypes {
66
+ HEADER = "header",
67
+ FOOTER = "footer",
68
+ LOG = "log"
69
+ }
70
+ declare enum BunyanCoreLogEventLevels {
71
+ ERROR = 50,
72
+ INFO = 30
73
+ }
74
+ declare function simpleBunyanLogEvent(eventType: BunyanCoreLogEventTypes, eventLevel: BunyanCoreLogEventLevels, invocationId: string, data: any): void;
75
+ declare function emitHeaderEvent(lambdaEvent: any): void;
76
+ declare function emitSuccessfulFooterEvent(): void;
77
+ declare function emitFailedFooterEvent(): void;
78
+ declare function emitErrorEvent(caughtObject: any): void;
79
+ declare const adapter: (fn: any) => any;
80
+ declare const bundled: any;
81
+ declare const wrappedExports: Record<string, any>;
2
82
  //# sourceMappingURL=wrapper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../src/wrapper.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAUA,iBAAS,yBAAyB,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,GAAG,CAAA;CAAE;;;;;;;;;;;;EAYrE;AAED,iBAAS,kBAAkB,CAAC,SAAS,EAAE,GAAG,WAEzC;AAED,iBAAS,eAAe,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE;;cAE1D;AAED,iBAAS,oBAAoB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE;;;;cAQ5E;AACD,iBAAS,mBAAmB,CAAC,IAAI,EAAE,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMrC;AASD,iBAAS,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAsB7C;AAID,iBAAS,oBAAoB,CAAC,WAAW,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAenE;AAID,iBAAS,oBAAoB,CAAC,oBAAoB,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAwBhF;AAOD,aAAK,uBAAuB;IAC1B,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,GAAG,QAAQ;CACZ;AAGD,aAAK,wBAAwB;IAC3B,KAAK,KAAK;IACV,IAAI,KAAK;CACV;AAED,iBAAS,oBAAoB,CAC3B,SAAS,EAAE,uBAAuB,EAClC,UAAU,EAAE,wBAAwB,EACpC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,GAAG,GACR,IAAI,CA2BN;AAGD,iBAAS,eAAe,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,CAO/C;AACD,iBAAS,yBAAyB,IAAI,IAAI,CAOzC;AACD,iBAAS,qBAAqB,IAAI,IAAI,CAOrC;AACD,iBAAS,cAAc,CAAC,YAAY,EAAE,GAAG,GAAG,IAAI,CAO/C;AAED,QAAA,MAAM,OAAO,OAAQ,GAAG,QAkCvB,CAAC;AAGF,QAAA,MAAM,OAAO,KAAsC,CAAC;AACpD,QAAA,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,CAAC"}
package/out/wrapper.js CHANGED
@@ -27,23 +27,145 @@ function createLicenseContext({ license }) {
27
27
  function setupRequestContext(meta) {
28
28
  return Object.assign(Object.assign({ principal: createPrincipal(meta) }, createLicenseContext(meta)), createInstallationContext(meta));
29
29
  }
30
+ function serializeThrownObjects(arg) {
31
+ var _a, _b;
32
+ if (typeof arg !== 'object') {
33
+ return arg;
34
+ }
35
+ if (Array.isArray(arg)) {
36
+ return arg.map(serializeThrownObjects);
37
+ }
38
+ if (arg instanceof Error) {
39
+ return {
40
+ message: arg.message,
41
+ name: 'FUNCTION_ERR',
42
+ stack: (_a = arg.stack) !== null && _a !== void 0 ? _a : ''
43
+ };
44
+ }
45
+ if (((_b = arg === null || arg === void 0 ? void 0 : arg.constructor) === null || _b === void 0 ? void 0 : _b.name) !== 'Object') {
46
+ return arg;
47
+ }
48
+ const res = {};
49
+ for (const prop in arg) {
50
+ res[prop] = serializeThrownObjects(arg[prop]);
51
+ }
52
+ return res;
53
+ }
54
+ function invocationHeaderLogs(lambdaEvent) {
55
+ const { featureFlags, contextAri, appContext, tracing } = lambdaEvent === null || lambdaEvent === void 0 ? void 0 : lambdaEvent._meta;
56
+ const { appId, environmentId, appVersion, functionKey, moduleKey, moduleType } = appContext !== null && appContext !== void 0 ? appContext : {};
57
+ return {
58
+ appId,
59
+ environmentId,
60
+ appVersion,
61
+ installationContext: contextAri,
62
+ functionKey,
63
+ moduleType,
64
+ moduleKey,
65
+ b3: `${tracing.traceId}-${tracing.spanId}`,
66
+ featureFlags: featureFlags || [],
67
+ runtime: 'banana'
68
+ };
69
+ }
70
+ function invocationFooterLogs(successfulInvocation) {
71
+ return {
72
+ success: successfulInvocation,
73
+ logMetadata: {
74
+ bytes: 0,
75
+ truncated: false,
76
+ errorCount: 0
77
+ },
78
+ outboundCalls: {
79
+ count: 0,
80
+ stargateCount: 0,
81
+ externalCount: 0,
82
+ rejectedCount: 0,
83
+ bytesOut: 0,
84
+ bytesIn: 0,
85
+ msWaiting: 0
86
+ },
87
+ function: {
88
+ bytesIn: 0,
89
+ bytesOut: 0,
90
+ durationMs: 0,
91
+ mem: 0
92
+ }
93
+ };
94
+ }
95
+ var BunyanCoreLogEventTypes;
96
+ (function (BunyanCoreLogEventTypes) {
97
+ BunyanCoreLogEventTypes["HEADER"] = "header";
98
+ BunyanCoreLogEventTypes["FOOTER"] = "footer";
99
+ BunyanCoreLogEventTypes["LOG"] = "log";
100
+ })(BunyanCoreLogEventTypes || (BunyanCoreLogEventTypes = {}));
101
+ var BunyanCoreLogEventLevels;
102
+ (function (BunyanCoreLogEventLevels) {
103
+ BunyanCoreLogEventLevels[BunyanCoreLogEventLevels["ERROR"] = 50] = "ERROR";
104
+ BunyanCoreLogEventLevels[BunyanCoreLogEventLevels["INFO"] = 30] = "INFO";
105
+ })(BunyanCoreLogEventLevels || (BunyanCoreLogEventLevels = {}));
106
+ function simpleBunyanLogEvent(eventType, eventLevel, invocationId, data) {
107
+ function groupLogData(logData) {
108
+ if (eventType === 'footer' || eventType === 'header') {
109
+ return logData;
110
+ }
111
+ return {
112
+ '*': [serializeThrownObjects(logData)],
113
+ P: 3,
114
+ lvl: eventLevel,
115
+ ts: Date.now()
116
+ };
117
+ }
118
+ const logEvent = Object.assign({ name: 'node-runtime', id: invocationId, hostname: 'some-runtime-hostname', pid: process.pid, level: 30, msg: '', time: new Date().toISOString(), v: 0, type: eventType }, groupLogData(data));
119
+ process.stdout.write(JSON.stringify(logEvent) + '\n');
120
+ }
121
+ function emitHeaderEvent(lambdaEvent) {
122
+ simpleBunyanLogEvent(BunyanCoreLogEventTypes.HEADER, BunyanCoreLogEventLevels.INFO, global.lambdaContext.awsRequestId, invocationHeaderLogs(lambdaEvent));
123
+ }
124
+ function emitSuccessfulFooterEvent() {
125
+ simpleBunyanLogEvent(BunyanCoreLogEventTypes.FOOTER, BunyanCoreLogEventLevels.INFO, global.lambdaContext.awsRequestId, invocationFooterLogs(true));
126
+ }
127
+ function emitFailedFooterEvent() {
128
+ simpleBunyanLogEvent(BunyanCoreLogEventTypes.FOOTER, BunyanCoreLogEventLevels.INFO, global.lambdaContext.awsRequestId, invocationFooterLogs(false));
129
+ }
130
+ function emitErrorEvent(caughtObject) {
131
+ simpleBunyanLogEvent(BunyanCoreLogEventTypes.LOG, BunyanCoreLogEventLevels.ERROR, global.lambdaContext.awsRequestId, caughtObject);
132
+ }
30
133
  const adapter = (fn) => {
31
134
  if (typeof fn === 'function') {
32
- return async (lambdaEvent, _lambdaContext) => {
135
+ return async (lambdaEvent, lambdaContext) => {
33
136
  const event = lambdaEvent.body;
34
137
  const context = setupRequestContext(lambdaEvent._meta);
35
- const result = await fn(event, context);
36
- return {
37
- body: result,
38
- metrics: []
39
- };
138
+ global.lambdaContext = lambdaContext;
139
+ try {
140
+ emitHeaderEvent(lambdaEvent);
141
+ const result = await fn(event, context);
142
+ emitSuccessfulFooterEvent();
143
+ return {
144
+ body: result,
145
+ metrics: []
146
+ };
147
+ }
148
+ catch (err) {
149
+ emitErrorEvent(err);
150
+ emitFailedFooterEvent();
151
+ return {
152
+ errorMessage: err.message,
153
+ errorType: err.name,
154
+ isHostedCodeError: true,
155
+ stack: (err.stack || '').split('\n'),
156
+ serviceKey: err.serviceKey,
157
+ metrics: err.metrics
158
+ };
159
+ }
40
160
  };
41
161
  }
42
162
  else {
43
163
  return fn;
44
164
  }
45
165
  };
46
- const bundled = require('__MODULE__');
166
+ const bundled = require('./__PLACEHOLDER_MODULE__');
167
+ const wrappedExports = {};
47
168
  for (const key in bundled) {
48
- exports[key] = adapter(bundled[key]);
169
+ wrappedExports[key] = adapter(bundled[key]);
49
170
  }
171
+ module.exports = wrappedExports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bundler",
3
- "version": "3.1.1-next.0",
3
+ "version": "3.1.1-next.2",
4
4
  "description": "Default bundler for Forge apps",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Atlassian",
@@ -20,8 +20,8 @@
20
20
  "@babel/preset-typescript": "^7.16.7",
21
21
  "@forge/api": "2.7.0",
22
22
  "@forge/babel-plugin-transform-ui": "1.1.0",
23
- "@forge/cli-shared": "3.1.1-next.0",
24
- "@forge/lint": "3.2.5-next.0",
23
+ "@forge/cli-shared": "3.1.1-next.1",
24
+ "@forge/lint": "3.2.5-next.1",
25
25
  "assert": "^1.1.1",
26
26
  "babel-loader": "^8.2.3",
27
27
  "browserify-zlib": "^0.2.0",