@forge/bundler 4.6.4-next.0 → 4.6.4-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,21 @@
1
1
  # @forge/bundler
2
2
 
3
+ ## 4.6.4-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e8d41b0]
8
+ - @forge/cli-shared@3.10.1-next.0
9
+ - @forge/lint@3.2.20-next.0
10
+
11
+ ## 4.6.4-next.1
12
+
13
+ ### Patch Changes
14
+
15
+ - e91cabc: Route HTTPS calls from the new runtime through @forge/api
16
+ - Updated dependencies [e91cabc]
17
+ - @forge/api@2.15.1-next.1
18
+
3
19
  ## 4.6.4-next.0
4
20
 
5
21
  ### Patch Changes
@@ -34,8 +34,8 @@ const getCustomModulesAliases = () => {
34
34
  util: (0, common_1.resolveModulePath)('util/'),
35
35
  zlib: (0, common_1.resolveModulePath)('browserify-zlib'),
36
36
  fs: (0, common_1.resolveModulePath)('memfs'),
37
- http: (0, common_1.resolveStubPath)('http'),
38
- https: (0, common_1.resolveStubPath)('http'),
37
+ http: (0, common_1.resolveStubPath)('http-sandbox'),
38
+ https: (0, common_1.resolveStubPath)('http-sandbox'),
39
39
  path: (0, common_1.resolveModulePath)('path-browserify'),
40
40
  querystring: (0, common_1.resolveModulePath)('querystring-browser'),
41
41
  stream: (0, common_1.resolveModulePath)('readable-stream'),
@@ -1,4 +1,6 @@
1
1
  import { ConsoleMethod, LogHeader } from '@forge/runtime';
2
2
  export declare const starSerializer: (arg: any[]) => any;
3
3
  export declare function forgeConsole(consoleMethod: ConsoleMethod, header: LogHeader): (...rawData: any[]) => void;
4
+ export declare function replaceConsole(header: LogHeader): void;
5
+ export declare function restoreConsole(): void;
4
6
  //# sourceMappingURL=console.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,aAAa,EAIb,SAAS,EAEV,MAAM,gBAAgB,CAAC;AA2CxB,eAAO,MAAM,cAAc,QAAS,GAAG,EAAE,KAAG,GAAoC,CAAC;AAoDjF,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,+BAW3E"}
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,aAAa,EAIb,SAAS,EAGV,MAAM,gBAAgB,CAAC;AA2CxB,eAAO,MAAM,cAAc,QAAS,GAAG,EAAE,KAAG,GAAoC,CAAC;AAoDjF,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,+BAW3E;AAMD,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,QAI/C;AAED,wBAAgB,cAAc,SAI7B"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.forgeConsole = exports.starSerializer = void 0;
3
+ exports.restoreConsole = exports.replaceConsole = exports.forgeConsole = exports.starSerializer = void 0;
4
4
  const bunyan_1 = require("bunyan");
5
5
  const api_1 = require("@forge/api");
6
6
  const runtime_1 = require("@forge/runtime");
@@ -84,3 +84,16 @@ function forgeConsole(consoleMethod, header) {
84
84
  }
85
85
  }
86
86
  exports.forgeConsole = forgeConsole;
87
+ const originalConsole = new Map(runtime_1.CONSOLE_METHODS.map((method) => [method, global.console[method]]));
88
+ function replaceConsole(header) {
89
+ for (const method of runtime_1.CONSOLE_METHODS) {
90
+ global.console[method] = forgeConsole(method, header);
91
+ }
92
+ }
93
+ exports.replaceConsole = replaceConsole;
94
+ function restoreConsole() {
95
+ for (const method of runtime_1.CONSOLE_METHODS) {
96
+ global.console[method] = originalConsole.get(method);
97
+ }
98
+ }
99
+ exports.restoreConsole = restoreConsole;
@@ -12,6 +12,7 @@ export interface ChainableOptions {
12
12
  [key: string]: string;
13
13
  };
14
14
  }
15
+ export declare const isRequestOptions: (options: RequestOptions | string | URL) => options is RequestOptions;
15
16
  export declare class Request extends Writable {
16
17
  private reqBody;
17
18
  private chainableOptions;
@@ -21,10 +22,12 @@ export declare class Request extends Writable {
21
22
  private fetch;
22
23
  _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
23
24
  static formatUrl(options: RequestOptions): string;
25
+ static urlFromFetchArgs(options: RequestOptions | string | URL): string;
24
26
  static convertToForgeFetchArgs(options: RequestOptions | string | URL, chainableOptions: ChainableOptions): {
25
27
  url: string;
26
28
  init: FetchOptions;
27
29
  };
30
+ abort(): void;
28
31
  }
29
32
  export declare class Agent {
30
33
  constructor(options: AgentOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"http-impl.d.ts","sourceRoot":"","sources":["../../src/stubs/http-impl.ts"],"names":[],"mappings":";;;AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAY,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAkC,MAAM,KAAK,CAAC;AAC1D,OAAO,EAAe,YAAY,EAAS,MAAM,YAAY,CAAC;AAsB9D,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;KACvB,CAAC;CACH;AAMD,qBAAa,OAAQ,SAAQ,QAAQ;IACnC,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,gBAAgB,CAAmB;gBAE/B,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI;IAatF,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;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OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,KAAK,IAAI;IAatF,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAM/C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO;IAQhE,OAAO,CAAC,KAAK;IAsBN,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;IAe3F,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM;IAUjD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM;IAiBvE,MAAM,CAAC,uBAAuB,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;AAID,qBAAa,KAAK;gBACJ,OAAO,EAAE,YAAY;CAOlC"}
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Agent = exports.Request = void 0;
3
+ exports.Agent = exports.Request = exports.isRequestOptions = void 0;
4
4
  const readable_stream_1 = require("readable-stream");
5
- const url_1 = require("url");
6
5
  const api_1 = require("@forge/api");
7
6
  class Response extends readable_stream_1.Readable {
8
7
  constructor(content, response) {
@@ -17,6 +16,8 @@ class Response extends readable_stream_1.Readable {
17
16
  }
18
17
  const isString = (options) => typeof options === 'string';
19
18
  const isURL = (options) => typeof options === 'object' && options.constructor.name === 'URL';
19
+ const isRequestOptions = (options) => !isString(options) && !isURL(options);
20
+ exports.isRequestOptions = isRequestOptions;
20
21
  class Request extends readable_stream_1.Writable {
21
22
  constructor(options, callback) {
22
23
  super();
@@ -42,7 +43,7 @@ class Request extends readable_stream_1.Writable {
42
43
  }
43
44
  fetch(options) {
44
45
  const { url, init } = Request.convertToForgeFetchArgs(options, this.chainableOptions);
45
- if (init.method !== 'GET') {
46
+ if (init.method && init.method !== 'HEAD' && init.method !== 'GET') {
46
47
  init.body = Buffer.concat(this.reqBody);
47
48
  }
48
49
  (0, api_1.fetch)(url, init)
@@ -78,57 +79,24 @@ class Request extends readable_stream_1.Writable {
78
79
  }
79
80
  }
80
81
  static formatUrl(options) {
81
- const reqUrlBuilder = options;
82
- reqUrlBuilder.protocol = options.protocol || 'https:';
83
- if (reqUrlBuilder.path) {
84
- const { path: originalPath, pathname: originalPathname } = reqUrlBuilder;
85
- if (reqUrlBuilder.query === undefined) {
86
- const pathMatch = originalPath === null || originalPath === void 0 ? void 0 : originalPath.match(/(^.*)\?(.*$)/);
87
- const pathnameMatch = originalPathname === null || originalPathname === void 0 ? void 0 : originalPathname.match(/(^.*)\?(.*$)/);
88
- if (pathMatch) {
89
- const [, pathname, query] = pathMatch;
90
- reqUrlBuilder.pathname = pathname;
91
- reqUrlBuilder.query = query;
92
- reqUrlBuilder.search = `?${query}`;
93
- }
94
- else if (pathnameMatch) {
95
- const [, pathname, query] = pathnameMatch;
96
- reqUrlBuilder.path = reqUrlBuilder.pathname;
97
- reqUrlBuilder.pathname = pathname;
98
- reqUrlBuilder.query = query;
99
- reqUrlBuilder.search = `?${query}`;
100
- }
101
- else {
102
- reqUrlBuilder.pathname = reqUrlBuilder.path;
103
- }
104
- }
105
- }
106
- return (0, url_1.format)(reqUrlBuilder);
82
+ var _a, _b;
83
+ const protocol = 'https:';
84
+ const auth = options.auth ? `${options.auth}@` : '';
85
+ const host = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host;
86
+ const port = options.port ? `:${options.port}` : '';
87
+ const path = (_b = options.path) !== null && _b !== void 0 ? _b : '/';
88
+ return `${protocol}//${auth}${host}${port}${path}`;
107
89
  }
108
- static convertToForgeFetchArgs(options, chainableOptions) {
90
+ static urlFromFetchArgs(options) {
109
91
  if (isString(options)) {
110
- return { url: options, init: chainableOptions };
92
+ return options;
111
93
  }
112
94
  else if (isURL(options)) {
113
- return { url: options.toString(), init: chainableOptions };
95
+ return options.toString();
114
96
  }
115
97
  else {
116
98
  try {
117
- const reqOpts = {};
118
- if (options.headers) {
119
- reqOpts.headers = {};
120
- for (const header in options.headers) {
121
- const headerValue = options.headers[header];
122
- if (headerValue) {
123
- reqOpts.headers[header] = headerValue.toString();
124
- }
125
- }
126
- }
127
- if (options.timeout)
128
- reqOpts.timeout = options.timeout;
129
- reqOpts.method = options.method || 'GET';
130
- const url = Request.formatUrl(options);
131
- return { url, init: Object.assign(Object.assign({}, chainableOptions), reqOpts) };
99
+ return Request.formatUrl(options);
132
100
  }
133
101
  catch (err) {
134
102
  console.error('Unable to make request with unrecognised URL options:', options);
@@ -136,6 +104,30 @@ class Request extends readable_stream_1.Writable {
136
104
  }
137
105
  }
138
106
  }
107
+ static convertToForgeFetchArgs(options, chainableOptions) {
108
+ const url = Request.urlFromFetchArgs(options);
109
+ if (!(0, exports.isRequestOptions)(options)) {
110
+ return { url, init: chainableOptions };
111
+ }
112
+ else {
113
+ const reqOpts = {};
114
+ if (options.headers) {
115
+ reqOpts.headers = {};
116
+ for (const header in options.headers) {
117
+ const headerValue = options.headers[header];
118
+ if (headerValue) {
119
+ reqOpts.headers[header] = headerValue.toString();
120
+ }
121
+ }
122
+ }
123
+ if (options.timeout)
124
+ reqOpts.timeout = options.timeout;
125
+ reqOpts.method = options.method || 'GET';
126
+ return { url, init: Object.assign(Object.assign({}, chainableOptions), reqOpts) };
127
+ }
128
+ }
129
+ abort() {
130
+ }
139
131
  }
140
132
  exports.Request = Request;
141
133
  const NUM_SUPPORTED_AGENT_OPTIONS = 1;
@@ -0,0 +1,3 @@
1
+ export declare function replaceHttps(): void;
2
+ export declare function restoreHttps(): void;
3
+ //# sourceMappingURL=http-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-node.d.ts","sourceRoot":"","sources":["../../src/stubs/http-node.ts"],"names":[],"mappings":"AA0CA,wBAAgB,YAAY,SAK3B;AAED,wBAAgB,YAAY,SAG3B"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restoreHttps = exports.replaceHttps = void 0;
4
+ const http_impl_1 = require("./http-impl");
5
+ const https = require('https');
6
+ const originalHttpsRequest = https.request;
7
+ const originalHttpsGet = https.get;
8
+ function request(options, callback) {
9
+ var _a;
10
+ if ((0, http_impl_1.isRequestOptions)(options) && ((_a = options.headers) === null || _a === void 0 ? void 0 : _a['Forge-Proxy-Authorization'])) {
11
+ return originalHttpsRequest(options, callback);
12
+ }
13
+ return new http_impl_1.Request(options, callback);
14
+ }
15
+ function get(options, callback) {
16
+ if ((0, http_impl_1.isRequestOptions)(options)) {
17
+ options = Object.assign(Object.assign({}, options), { method: 'GET' });
18
+ }
19
+ const result = request(options, callback);
20
+ result.end();
21
+ return result;
22
+ }
23
+ function replaceHttps() {
24
+ https.request = request;
25
+ https.get = get;
26
+ }
27
+ exports.replaceHttps = replaceHttps;
28
+ function restoreHttps() {
29
+ https.request = originalHttpsGet;
30
+ https.get = originalHttpsGet;
31
+ }
32
+ exports.restoreHttps = restoreHttps;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=http-sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-sandbox.d.ts","sourceRoot":"","sources":["../../src/stubs/http-sandbox.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const http_impl_1 = require("./http-impl");
4
+ module.exports = {
5
+ request: (options, callback) => {
6
+ return new http_impl_1.Request(options, callback);
7
+ },
8
+ get: (options, callback) => {
9
+ if ((0, http_impl_1.isRequestOptions)(options)) {
10
+ options = Object.assign(Object.assign({}, options), { method: 'GET' });
11
+ }
12
+ const result = new http_impl_1.Request(options, callback);
13
+ result.end();
14
+ return result;
15
+ },
16
+ Agent: http_impl_1.Agent
17
+ };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const api_1 = require("@forge/api");
5
5
  const runtime_1 = require("@forge/runtime");
6
6
  const console_1 = require("./console");
7
+ const http_node_1 = require("./http-node");
7
8
  const log_events_1 = require("./log-events");
8
9
  const wrappedFilename = __filename.replace(/\/[^/]+.js$/, (name) => '/bundled' + name);
9
10
  const realRequire = eval('require');
@@ -35,9 +36,8 @@ const adapter = (name) => {
35
36
  }
36
37
  try {
37
38
  const header = (0, log_events_1.emitHeaderEvent)(lambdaEvent);
38
- for (const method of runtime_1.CONSOLE_METHODS) {
39
- global.console[method] = (0, console_1.forgeConsole)(method, header);
40
- }
39
+ (0, console_1.replaceConsole)(header);
40
+ (0, http_node_1.replaceHttps)();
41
41
  const bundled = realRequire(wrappedFilename);
42
42
  const timer = metrics.timing('invoke').measure();
43
43
  let result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bundler",
3
- "version": "4.6.4-next.0",
3
+ "version": "4.6.4-next.2",
4
4
  "description": "Default bundler for Forge apps",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Atlassian",
@@ -18,10 +18,10 @@
18
18
  "@babel/plugin-proposal-optional-chaining": "^7.16.7",
19
19
  "@babel/plugin-transform-react-jsx": "^7.16.7",
20
20
  "@babel/preset-typescript": "^7.16.7",
21
- "@forge/api": "2.15.1-next.0",
21
+ "@forge/api": "2.15.1-next.1",
22
22
  "@forge/babel-plugin-transform-ui": "1.1.1",
23
- "@forge/cli-shared": "3.10.0",
24
- "@forge/lint": "3.2.19",
23
+ "@forge/cli-shared": "3.10.1-next.0",
24
+ "@forge/lint": "3.2.20-next.0",
25
25
  "@forge/runtime": "4.3.1",
26
26
  "@forge/util": "1.2.2",
27
27
  "assert": "^1.1.1",
@@ -35,6 +35,7 @@
35
35
  "events": "^3.0.0",
36
36
  "html-webpack-plugin": "^5.5.0",
37
37
  "memfs": "^3.4.1",
38
+ "nock": "^10.0.6",
38
39
  "os-browserify": "^0.3.0",
39
40
  "path-browserify": "^1.0.0",
40
41
  "process": "^0.11.10",
@@ -56,7 +57,7 @@
56
57
  "devDependencies": {
57
58
  "@types/bunyan": "^1.8.5",
58
59
  "@types/jest": "^29.1.2",
59
- "@types/node": "^12.12.63",
60
+ "@types/node": "14.18.42",
60
61
  "@types/react": "^17.0.53",
61
62
  "@types/readable-stream": "^2.3.15",
62
63
  "@types/webpack-bundle-analyzer": "^4.6.0",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/stubs/http.ts"],"names":[],"mappings":""}
package/out/stubs/http.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const http_impl_1 = require("./http-impl");
4
- module.exports = {
5
- request: (options, callback) => {
6
- return new http_impl_1.Request(options, callback);
7
- },
8
- Agent: http_impl_1.Agent
9
- };