@forge/bundler 4.4.0-next.2 → 4.4.0-next.4

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,24 @@
1
1
  # @forge/bundler
2
2
 
3
+ ## 4.4.0-next.4
4
+
5
+ ### Minor Changes
6
+
7
+ - e25c75e8: Update Node runtime response payload
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [e25c75e8]
12
+ - @forge/runtime@4.1.0-next.1
13
+
14
+ ## 4.4.0-next.3
15
+
16
+ ### Patch Changes
17
+
18
+ - d98339a: Non-Docker tunnel for Node runtime
19
+ - Updated dependencies [d98339a]
20
+ - @forge/runtime@4.0.1-next.0
21
+
3
22
  ## 4.4.0-next.2
4
23
 
5
24
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/config/node.ts"],"names":[],"mappings":"AACA,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,mBA8CF,CAAC"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/config/node.ts"],"names":[],"mappings":"AACA,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,mBAwCF,CAAC"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNodeRuntimeBuildConfig = exports.NODE_WEBPACK_CONFIG_NAME = void 0;
4
- const tslib_1 = require("tslib");
5
- const webpack_1 = tslib_1.__importStar(require("webpack"));
4
+ const webpack_1 = require("webpack");
6
5
  const common_1 = require("./common");
7
6
  exports.NODE_WEBPACK_CONFIG_NAME = 'node-runtime';
8
7
  const getNodeRuntimeBuildConfig = (entrypoints, config) => {
@@ -14,12 +13,7 @@ const getNodeRuntimeBuildConfig = (entrypoints, config) => {
14
13
  newEntries[entryKey] = wrapperPath;
15
14
  }
16
15
  webpackConfig.entry = newEntries;
17
- const nodeConfigPlugin = new webpack_1.default.ProvidePlugin({
18
- console: (0, common_1.resolveStubPath)('console'),
19
- 'global.console': (0, common_1.resolveStubPath)('console')
20
- });
21
- webpackConfig.plugins.push(nodeConfigPlugin);
22
- webpackConfig.target = 'node14';
16
+ webpackConfig.target = 'node18';
23
17
  const defineExports = ({ filename }) => {
24
18
  const entryName = filename.replace(/\.js$/, '');
25
19
  const entrypoint = entrypoints.find((e) => e.name === entryName);
package/out/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export { Bundler, InDiskBundler, Watcher, WatcherMonitor, BundlerOutput } from '
2
2
  export { sandboxBundle, nodeBundle, nativeUiBundle, watch, getCompiler, getInMemoryBundle, handleWebpackCompilationResult, runLinter } from './webpack';
3
3
  export { EntryPoint, FunctionsEntryPoint, getEntryPoints } from './config/common';
4
4
  export { getNativeUiBuildConfig } from './config/nativeui';
5
+ export { getNodeRuntimeBuildConfig } from './config/node';
5
6
  export { getSandboxedRuntimeBuildConfig } from './config/sandbox';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,KAAK,EACL,WAAW,EACX,iBAAiB,EACjB,8BAA8B,EAC9B,SAAS,EACV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,KAAK,EACL,WAAW,EACX,iBAAiB,EACjB,8BAA8B,EAC9B,SAAS,EACV,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC"}
package/out/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSandboxedRuntimeBuildConfig = exports.getNativeUiBuildConfig = exports.getEntryPoints = exports.runLinter = exports.handleWebpackCompilationResult = exports.getInMemoryBundle = exports.getCompiler = exports.watch = exports.nativeUiBundle = exports.nodeBundle = exports.sandboxBundle = void 0;
3
+ exports.getSandboxedRuntimeBuildConfig = exports.getNodeRuntimeBuildConfig = exports.getNativeUiBuildConfig = exports.getEntryPoints = exports.runLinter = exports.handleWebpackCompilationResult = exports.getInMemoryBundle = exports.getCompiler = exports.watch = exports.nativeUiBundle = exports.nodeBundle = exports.sandboxBundle = void 0;
4
4
  var webpack_1 = require("./webpack");
5
5
  Object.defineProperty(exports, "sandboxBundle", { enumerable: true, get: function () { return webpack_1.sandboxBundle; } });
6
6
  Object.defineProperty(exports, "nodeBundle", { enumerable: true, get: function () { return webpack_1.nodeBundle; } });
@@ -14,5 +14,7 @@ var common_1 = require("./config/common");
14
14
  Object.defineProperty(exports, "getEntryPoints", { enumerable: true, get: function () { return common_1.getEntryPoints; } });
15
15
  var nativeui_1 = require("./config/nativeui");
16
16
  Object.defineProperty(exports, "getNativeUiBuildConfig", { enumerable: true, get: function () { return nativeui_1.getNativeUiBuildConfig; } });
17
+ var node_1 = require("./config/node");
18
+ Object.defineProperty(exports, "getNodeRuntimeBuildConfig", { enumerable: true, get: function () { return node_1.getNodeRuntimeBuildConfig; } });
17
19
  var sandbox_1 = require("./config/sandbox");
18
20
  Object.defineProperty(exports, "getSandboxedRuntimeBuildConfig", { enumerable: true, get: function () { return sandbox_1.getSandboxedRuntimeBuildConfig; } });
@@ -1,2 +1,5 @@
1
+ /// <reference types="node" />
2
+ import { ConsoleMethod } from '@forge/runtime';
1
3
  export declare const starSerializer: (arg: any) => any;
4
+ export declare const forgeConsole: Pick<Console, ConsoleMethod>;
2
5
  //# sourceMappingURL=console.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":"AAoDA,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,GAsBzC,CAAC"}
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":";AAEA,OAAO,EAAsB,aAAa,EAA+B,MAAM,gBAAgB,CAAC;AAyChG,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,GAsBzC,CAAC;AAgDF,eAAO,MAAM,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAMrD,CAAC"}
@@ -1,29 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.starSerializer = void 0;
3
+ exports.forgeConsole = exports.starSerializer = void 0;
4
4
  const bunyan_1 = require("bunyan");
5
5
  const api_1 = require("@forge/api");
6
- const isNonEmptyArray = (arr) => arr.length > 0;
7
- function transformSandBoxLogMessage(message) {
8
- let msg = '', starval = [];
9
- if (typeof message === 'string') {
10
- msg = message;
6
+ const runtime_1 = require("@forge/runtime");
7
+ function stringMessage(arg) {
8
+ if (typeof arg === 'string') {
9
+ return arg;
10
+ }
11
+ else if (arg instanceof Error) {
12
+ return arg.toString();
11
13
  }
12
14
  else {
13
- if (Array.isArray(message) && message.length > 0) {
14
- const first = message[0];
15
- if (typeof first === 'string') {
16
- msg = first;
17
- starval = message.slice(1);
18
- }
19
- else {
20
- starval = message;
21
- }
15
+ return null;
16
+ }
17
+ }
18
+ function transformSandBoxLogMessage(arg) {
19
+ let msg = stringMessage(arg);
20
+ if (msg === null && Array.isArray(arg) && arg.length > 0) {
21
+ msg = stringMessage(arg[0]);
22
+ if (msg !== null) {
23
+ arg = arg.slice(1);
22
24
  }
23
25
  }
26
+ if (msg === null) {
27
+ msg = '';
28
+ }
24
29
  return {
25
- msg: msg,
26
- '*': starval
30
+ msg,
31
+ '*': arg
27
32
  };
28
33
  }
29
34
  const starSerializer = (arg) => {
@@ -37,7 +42,7 @@ const starSerializer = (arg) => {
37
42
  if (arg instanceof Error) {
38
43
  return {
39
44
  message: arg.message,
40
- name: arg.name,
45
+ name: (0, api_1.isForgePlatformError)(arg) ? arg.name : api_1.FUNCTION_ERR,
41
46
  stack: (_a = arg.stack) !== null && _a !== void 0 ? _a : ''
42
47
  };
43
48
  }
@@ -66,23 +71,30 @@ function formatLogMessage(requestId, logEventData) {
66
71
  const logger = (0, bunyan_1.createLogger)({
67
72
  name: 'node-runtime',
68
73
  level: bunyan_1.levelFromName.info,
69
- serializers: { err: bunyan_1.stdSerializers.err, '*': exports.starSerializer }
74
+ serializers: { '*': exports.starSerializer }
70
75
  });
71
76
  function customConsole(logMethod) {
72
77
  return (...rawData) => {
73
- const context = (0, api_1.getRuntime)().lambdaContext;
74
- if (isNonEmptyArray(rawData)) {
78
+ var _a;
79
+ const runtime = (0, api_1.getRuntime)();
80
+ if ((0, runtime_1.isNonEmptyArray)(rawData)) {
81
+ const awsRequestId = (_a = runtime.lambdaContext) === null || _a === void 0 ? void 0 : _a.awsRequestId;
75
82
  const logEventData = {
76
- invocationId: context === null || context === void 0 ? void 0 : context.awsRequestId,
83
+ invocationId: awsRequestId,
77
84
  logLevel: bunyan_1.levelFromName[logMethod],
78
85
  logArguments: rawData
79
86
  };
80
- const data = formatLogMessage(context === null || context === void 0 ? void 0 : context.awsRequestId, logEventData);
81
- logger.info(data, data.msg);
87
+ if (global.__forge_tunnel__) {
88
+ process.stdout.write(JSON.stringify((0, exports.starSerializer)(logEventData)) + '\n');
89
+ }
90
+ else {
91
+ const data = formatLogMessage(awsRequestId, logEventData);
92
+ logger.info(data, data.msg);
93
+ }
82
94
  }
83
95
  };
84
96
  }
85
- module.exports = {
97
+ exports.forgeConsole = {
86
98
  log: customConsole('info'),
87
99
  info: customConsole('info'),
88
100
  warn: customConsole('warn'),
@@ -1,60 +1,12 @@
1
1
  "use strict";
2
2
  var _a, _b;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
4
+ const bunyan_1 = require("bunyan");
5
5
  const api_1 = require("@forge/api");
6
- const ARI = tslib_1.__importStar(require("@forge/util/packages/cs-ari"));
7
- function createInstallationContext({ contextAri }) {
8
- const ari = ARI.parse(contextAri);
9
- if (ari.resourceType === 'project') {
10
- return { projectId: ari.resourceId, installContext: contextAri };
11
- }
12
- if (ari.resourceType === 'repository') {
13
- return { repositoryId: ari.resourceId, installContext: contextAri };
14
- }
15
- return { installContext: contextAri };
16
- }
17
- function isAccountIdDefined(accountId) {
18
- return accountId !== undefined && accountId !== 'undefined';
19
- }
20
- function createPrincipal({ aaid: accountId }) {
21
- return isAccountIdDefined(accountId) ? { accountId } : undefined;
22
- }
23
- function createLicenseContext({ license }) {
24
- if (license) {
25
- return {
26
- license: {
27
- isActive: license.isActive ? true : false
28
- }
29
- };
30
- }
31
- }
32
- function setupRequestContext(meta) {
33
- return Object.assign(Object.assign({ principal: createPrincipal(meta) }, createLicenseContext(meta)), createInstallationContext(meta));
34
- }
35
- function serializeThrownObjects(arg) {
36
- var _a, _b;
37
- if (typeof arg !== 'object') {
38
- return arg;
39
- }
40
- if (Array.isArray(arg)) {
41
- return arg.map(serializeThrownObjects);
42
- }
43
- if (arg instanceof Error) {
44
- return {
45
- message: arg.message,
46
- name: (0, api_1.isForgePlatformError)(arg) ? arg.name : api_1.FUNCTION_ERR,
47
- stack: (_a = arg.stack) !== null && _a !== void 0 ? _a : ''
48
- };
49
- }
50
- if (((_b = arg === null || arg === void 0 ? void 0 : arg.constructor) === null || _b === void 0 ? void 0 : _b.name) !== 'Object') {
51
- return arg;
52
- }
53
- const res = {};
54
- for (const prop in arg) {
55
- res[prop] = serializeThrownObjects(arg[prop]);
56
- }
57
- return res;
6
+ const runtime_1 = require("@forge/runtime");
7
+ const console_1 = require("./console");
8
+ for (const method of runtime_1.CONSOLE_METHODS) {
9
+ global.console[method] = console_1.forgeConsole[method];
58
10
  }
59
11
  function invocationHeaderLogs(lambdaEvent) {
60
12
  const { featureFlags, contextAri, appContext, tracing } = lambdaEvent === null || lambdaEvent === void 0 ? void 0 : lambdaEvent._meta;
@@ -97,43 +49,39 @@ function invocationFooterLogs(successfulInvocation) {
97
49
  }
98
50
  };
99
51
  }
100
- var BunyanCoreLogEventTypes;
101
- (function (BunyanCoreLogEventTypes) {
102
- BunyanCoreLogEventTypes["HEADER"] = "header";
103
- BunyanCoreLogEventTypes["FOOTER"] = "footer";
104
- BunyanCoreLogEventTypes["LOG"] = "log";
105
- })(BunyanCoreLogEventTypes || (BunyanCoreLogEventTypes = {}));
106
- var BunyanCoreLogEventLevels;
107
- (function (BunyanCoreLogEventLevels) {
108
- BunyanCoreLogEventLevels[BunyanCoreLogEventLevels["ERROR"] = 50] = "ERROR";
109
- BunyanCoreLogEventLevels[BunyanCoreLogEventLevels["INFO"] = 30] = "INFO";
110
- })(BunyanCoreLogEventLevels || (BunyanCoreLogEventLevels = {}));
111
- function simpleBunyanLogEvent(eventType, eventLevel, invocationId, data) {
52
+ var EventType;
53
+ (function (EventType) {
54
+ EventType["HEADER"] = "header";
55
+ EventType["FOOTER"] = "footer";
56
+ EventType["LOG"] = "log";
57
+ })(EventType || (EventType = {}));
58
+ function simpleBunyanLogEvent(eventType, eventLevel, data) {
112
59
  function groupLogData(logData) {
113
60
  if (eventType === 'footer' || eventType === 'header') {
114
61
  return logData;
115
62
  }
116
63
  return {
117
- '*': [serializeThrownObjects(logData)],
64
+ '*': [(0, console_1.starSerializer)(logData)],
118
65
  P: 3,
119
66
  lvl: eventLevel,
120
67
  ts: Date.now()
121
68
  };
122
69
  }
70
+ const invocationId = (0, api_1.getRuntime)().lambdaContext.awsRequestId;
123
71
  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));
124
72
  process.stdout.write(JSON.stringify(logEvent) + '\n');
125
73
  }
126
74
  function emitHeaderEvent(lambdaEvent) {
127
- simpleBunyanLogEvent(BunyanCoreLogEventTypes.HEADER, BunyanCoreLogEventLevels.INFO, (0, api_1.getRuntime)().lambdaContext.awsRequestId, invocationHeaderLogs(lambdaEvent));
75
+ simpleBunyanLogEvent(EventType.HEADER, bunyan_1.levelFromName.info, invocationHeaderLogs(lambdaEvent));
128
76
  }
129
77
  function emitSuccessfulFooterEvent() {
130
- simpleBunyanLogEvent(BunyanCoreLogEventTypes.FOOTER, BunyanCoreLogEventLevels.INFO, (0, api_1.getRuntime)().lambdaContext.awsRequestId, invocationFooterLogs(true));
78
+ simpleBunyanLogEvent(EventType.FOOTER, bunyan_1.levelFromName.info, invocationFooterLogs(true));
131
79
  }
132
80
  function emitFailedFooterEvent() {
133
- simpleBunyanLogEvent(BunyanCoreLogEventTypes.FOOTER, BunyanCoreLogEventLevels.INFO, (0, api_1.getRuntime)().lambdaContext.awsRequestId, invocationFooterLogs(false));
81
+ simpleBunyanLogEvent(EventType.FOOTER, bunyan_1.levelFromName.info, invocationFooterLogs(false));
134
82
  }
135
83
  function emitErrorEvent(caughtObject) {
136
- simpleBunyanLogEvent(BunyanCoreLogEventTypes.LOG, BunyanCoreLogEventLevels.ERROR, (0, api_1.getRuntime)().lambdaContext.awsRequestId, caughtObject);
84
+ simpleBunyanLogEvent(EventType.LOG, bunyan_1.levelFromName.error, caughtObject);
137
85
  }
138
86
  const wrappedFilename = __filename.replace(/\/[^/]+.js$/, (name) => '/bundled' + name);
139
87
  const realRequire = eval('require');
@@ -146,17 +94,17 @@ if (!bundledExports || bundledExports.length === 0) {
146
94
  }
147
95
  const adapter = (name) => {
148
96
  return async (lambdaEvent, lambdaContext) => {
149
- var _a;
97
+ var _a, _b;
150
98
  const event = lambdaEvent.body;
151
- const context = setupRequestContext(lambdaEvent._meta);
99
+ const context = (0, runtime_1.setupRequestContext)({ meta: lambdaEvent._meta, handler: lambdaEvent.handler });
152
100
  const runtime = {
153
101
  proxy: lambdaEvent._meta.proxy,
154
102
  contextAri: lambdaEvent._meta.contextAri,
155
- allowedEgress: lambdaEvent._meta.fetchAllowList,
103
+ allowedEgress: (_a = lambdaEvent._meta.fetchAllowList) !== null && _a !== void 0 ? _a : [],
156
104
  lambdaContext: lambdaContext
157
105
  };
158
106
  global.__forge_runtime__ = runtime;
159
- for (const { key, value } of (_a = lambdaEvent.variables) !== null && _a !== void 0 ? _a : []) {
107
+ for (const { key, value } of (_b = lambdaEvent.variables) !== null && _b !== void 0 ? _b : []) {
160
108
  process.env[key] = value;
161
109
  }
162
110
  try {
@@ -165,6 +113,7 @@ const adapter = (name) => {
165
113
  const result = await bundled[name](event, context);
166
114
  emitSuccessfulFooterEvent();
167
115
  return {
116
+ success: true,
168
117
  body: result,
169
118
  metrics: []
170
119
  };
@@ -173,11 +122,14 @@ const adapter = (name) => {
173
122
  emitErrorEvent(err);
174
123
  emitFailedFooterEvent();
175
124
  return {
176
- errorMessage: err.message,
177
- errorType: err.name,
178
- isHostedCodeError: (0, api_1.isHostedCodeError)(err),
179
- stack: (err.stack || '').split('\n'),
180
- serviceKey: err.serviceKey,
125
+ success: false,
126
+ error: {
127
+ errorMessage: err.message,
128
+ errorType: err.name,
129
+ isHostedCodeError: (0, api_1.isHostedCodeError)(err),
130
+ stack: (err.stack || '').split('\n'),
131
+ serviceKey: err.serviceKey
132
+ },
181
133
  metrics: []
182
134
  };
183
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bundler",
3
- "version": "4.4.0-next.2",
3
+ "version": "4.4.0-next.4",
4
4
  "description": "Default bundler for Forge apps",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Atlassian",
@@ -22,6 +22,7 @@
22
22
  "@forge/babel-plugin-transform-ui": "1.1.0",
23
23
  "@forge/cli-shared": "3.5.1",
24
24
  "@forge/lint": "3.2.14-next.0",
25
+ "@forge/runtime": "4.1.0-next.1",
25
26
  "@forge/util": "1.2.0",
26
27
  "assert": "^1.1.1",
27
28
  "babel-loader": "^8.2.3",