@adobe/helix-deploy 4.13.0 → 4.15.1
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 +56 -0
- package/README.md +1 -1
- package/index.js +1 -1
- package/package.json +20 -15
- package/src/ActionBuilder.js +70 -28
- package/src/BaseConfig.js +30 -1
- package/src/DevelopmentServer.js +10 -4
- package/src/{BaseBundler.js → bundler/BaseBundler.js} +13 -4
- package/src/bundler/EdgeBundler.js +118 -0
- package/src/{RollupBundler.js → bundler/RollupBundler.js} +2 -2
- package/src/{Bundler.js → bundler/WebpackBundler.js} +13 -8
- package/src/cli.js +4 -0
- package/src/deploy/BaseDeployer.js +5 -0
- package/src/deploy/CloudflareConfig.js +71 -0
- package/src/deploy/CloudflareDeployer.js +145 -0
- package/src/deploy/ComputeAtEdgeConfig.js +93 -0
- package/src/deploy/ComputeAtEdgeDeployer.js +190 -0
- package/src/deploy/GoogleDeployer.js +15 -19
- package/src/gateway/FastlyGateway.js +245 -166
- package/src/template/cloudflare-adapter.js +62 -0
- package/src/template/fastly-adapter.js +99 -0
- package/src/template/{index.js → node-index.js} +0 -1
- package/src/template/{index.mjs → node-index.mjs} +0 -0
- package/src/template/polyfills/helix-fetch.js +19 -0
- package/src/template/serviceworker-index.js +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
## [4.15.1](https://github.com/adobe/helix-deploy/compare/v4.15.0...v4.15.1) (2021-11-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([21e2af6](https://github.com/adobe/helix-deploy/commit/21e2af69186b80607747d390aa4f98507b02e070))
|
|
7
|
+
|
|
8
|
+
# [4.15.0](https://github.com/adobe/helix-deploy/compare/v4.14.1...v4.15.0) (2021-11-20)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* improve development server setup ([#338](https://github.com/adobe/helix-deploy/issues/338)) ([9d2b44a](https://github.com/adobe/helix-deploy/commit/9d2b44a6a8d14953fe351dd0b8362ebdfd4a9a6b))
|
|
14
|
+
|
|
15
|
+
## [4.14.1](https://github.com/adobe/helix-deploy/compare/v4.14.0...v4.14.1) (2021-11-15)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* update package in gateway is missing dicts ([854b87e](https://github.com/adobe/helix-deploy/commit/854b87e929dcbdc22bbc33d03f60dcf3dcd82a7b))
|
|
21
|
+
|
|
22
|
+
# [4.14.0](https://github.com/adobe/helix-deploy/compare/v4.13.0...v4.14.0) (2021-11-12)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **bundler:** add browser-based shims as fallbacks for node core API when running in edge compute ([8f54188](https://github.com/adobe/helix-deploy/commit/8f541884f456c6c28dcb252a4fb97b88c355c272))
|
|
28
|
+
* **bundler:** exclude google storage dependency (included in Google Runtime) ([024f09f](https://github.com/adobe/helix-deploy/commit/024f09f2a123b8f23643f7a894a0e195515113a9))
|
|
29
|
+
* **bundler:** use `globalThis` for increased compatibility with Cloudflare Workers ([8fef7bf](https://github.com/adobe/helix-deploy/commit/8fef7bf86ef0dd42e2b209d9774df3af6402adb1))
|
|
30
|
+
* **cloudflare:** remove hard-coded account id ([3a11aa1](https://github.com/adobe/helix-deploy/commit/3a11aa1602b4766c7327029a521f03068ef2824e))
|
|
31
|
+
* **fastly:** fix package param code ([c77fe82](https://github.com/adobe/helix-deploy/commit/c77fe82c5b5cff3cc27efaeb57ecb2043acbb66e))
|
|
32
|
+
* **fastly:** fix test domain subdomain ([ec60b2a](https://github.com/adobe/helix-deploy/commit/ec60b2a527ac8946ee5e6b44045e4ceedf8aec51))
|
|
33
|
+
* **gateway:** do not attempt to perform empty updates ([e99f4be](https://github.com/adobe/helix-deploy/commit/e99f4be0af2c6a82ee098f88399b16c7d59bd027))
|
|
34
|
+
* **gateway:** do not create duplicate dictionaries ([2ca6eca](https://github.com/adobe/helix-deploy/commit/2ca6eca36af22b74a3eacb43ea3a9adbda869bb8))
|
|
35
|
+
* **gateway:** further massaging of gateway syntax ([4935538](https://github.com/adobe/helix-deploy/commit/49355385adfeb9589ff676e23fa0077a6682208b))
|
|
36
|
+
* **gateway:** set content type of synthetic response ([873ea06](https://github.com/adobe/helix-deploy/commit/873ea067c7ff42e598605e7e0fb0d576fec51b07))
|
|
37
|
+
* **gateway:** tweak synthetic syntax, again ([00f47e3](https://github.com/adobe/helix-deploy/commit/00f47e3cdc820333a56bdf1bc6524474a90d2eed))
|
|
38
|
+
* **gateway:** use correct dictionary name ([91d219e](https://github.com/adobe/helix-deploy/commit/91d219e7deefb43d69850d7022cfe5aba1c894da))
|
|
39
|
+
* **gateway:** use correct number of commas in JSON ([3250f6c](https://github.com/adobe/helix-deploy/commit/3250f6c2b11bd63541e8d45d28cdd55301f7bd75))
|
|
40
|
+
* **template:** better check for existence of `addEventListener` ([c5d8568](https://github.com/adobe/helix-deploy/commit/c5d85684edb130a473930516b617b4a78214801d))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### Features
|
|
44
|
+
|
|
45
|
+
* **bundler:** add working cloudflare support ([09635c2](https://github.com/adobe/helix-deploy/commit/09635c2c13679e401bcc6d2b9bebe0208399b38b))
|
|
46
|
+
* **cloudflare:** add support for `context.env` in wrapper ([ecc0e7b](https://github.com/adobe/helix-deploy/commit/ecc0e7bda6a55a43b81c81e0279813688889c599))
|
|
47
|
+
* **cloudflare:** create KV store for package params, use env vars for action params ([d63144d](https://github.com/adobe/helix-deploy/commit/d63144d8569e3ef71f96b9eb41cdc1dfbc0aae25))
|
|
48
|
+
* **cloudflare:** deploy edge script as cloudflare worker script ([66ed931](https://github.com/adobe/helix-deploy/commit/66ed931101e3b560f665d3b9d0f151c18facc72b))
|
|
49
|
+
* **cloudflare:** minimal wrapper script ([bb56dcd](https://github.com/adobe/helix-deploy/commit/bb56dcd7ea5967ddccbc1aa354e43d63873d735a))
|
|
50
|
+
* **fastly:** create bundle and deploy to compute at edge ([476a605](https://github.com/adobe/helix-deploy/commit/476a605e7f19aec316e093d82f7f411f2fbc0a85))
|
|
51
|
+
* **fastly:** use parameters from edge dictionary ([0c586a7](https://github.com/adobe/helix-deploy/commit/0c586a78b0c0a2aa2314f914d562a5008338c568))
|
|
52
|
+
* **gateway:** add basic support for package parameters in gateway ([36519e4](https://github.com/adobe/helix-deploy/commit/36519e40a1a24b4a329318b97557d06797ed8cd2))
|
|
53
|
+
* **gateway:** set shared secret (token) for package parameters ([adcbd92](https://github.com/adobe/helix-deploy/commit/adcbd92b27a91ffb44a8f115da7230a6095fe37f))
|
|
54
|
+
* **gateway:** update package parameters in dictionary ([5315dd4](https://github.com/adobe/helix-deploy/commit/5315dd46098cd5d4ed1c0d8eb391487d6c2dad5a))
|
|
55
|
+
* **template:** support service worker API as main entry point for Fastly/Cloudflare ([ba0ec25](https://github.com/adobe/helix-deploy/commit/ba0ec25b148de242ae207e4013641dac9223df22))
|
|
56
|
+
|
|
1
57
|
# [4.13.0](https://github.com/adobe/helix-deploy/compare/v4.12.2...v4.13.0) (2021-11-10)
|
|
2
58
|
|
|
3
59
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Helix Deploy
|
|
2
|
-
> A multi-cloud deployment tool for serverless functions running on AWS Lambda, Adobe I/O Runtime, Azure Functions,
|
|
2
|
+
> A multi-cloud deployment tool for serverless and edge-compute functions running on AWS Lambda, Adobe I/O Runtime, Azure Functions, Google Cloud Functions, Cloudflare Workers, and Fastly Compute@Edge. Write once, run everywhere.
|
|
3
3
|
|
|
4
4
|
## Status
|
|
5
5
|
[](https://github.com/adobe/helix-deploy/blob/main/LICENSE.txt)
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
const ActionBuilder = require('./src/ActionBuilder.js');
|
|
13
|
-
const Bundler = require('./src/
|
|
13
|
+
const Bundler = require('./src/bundler/WebpackBundler.js');
|
|
14
14
|
const BaseConfig = require('./src/BaseConfig.js');
|
|
15
15
|
const CLI = require('./src/cli.js');
|
|
16
16
|
const DevelopmentServer = require('./src/DevelopmentServer.js');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-deploy",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.1",
|
|
4
4
|
"description": "Library and Commandline Tools to build and deploy OpenWhisk Actions",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,32 +36,37 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/fastly-native-promises": "2.0.0",
|
|
38
38
|
"@adobe/helix-fetch": "3.0.0",
|
|
39
|
-
"@aws-sdk/client-apigatewayv2": "3.
|
|
40
|
-
"@aws-sdk/client-lambda": "3.
|
|
41
|
-
"@aws-sdk/client-s3": "3.
|
|
42
|
-
"@aws-sdk/client-secrets-manager": "3.
|
|
43
|
-
"@aws-sdk/client-ssm": "3.
|
|
39
|
+
"@aws-sdk/client-apigatewayv2": "3.42.0",
|
|
40
|
+
"@aws-sdk/client-lambda": "3.42.0",
|
|
41
|
+
"@aws-sdk/client-s3": "3.42.0",
|
|
42
|
+
"@aws-sdk/client-secrets-manager": "3.42.0",
|
|
43
|
+
"@aws-sdk/client-ssm": "3.42.0",
|
|
44
44
|
"@azure/arm-appservice": "9.0.0",
|
|
45
45
|
"@azure/ms-rest-nodeauth": "3.1.0",
|
|
46
|
+
"@fastly/js-compute": "0.2.1",
|
|
46
47
|
"@google-cloud/functions": "1.2.0",
|
|
47
48
|
"@google-cloud/secret-manager": "3.10.1",
|
|
48
|
-
"@google-cloud/storage": "5.
|
|
49
|
-
"@rollup/plugin-alias": "3.1.
|
|
50
|
-
"@rollup/plugin-commonjs": "21.0.
|
|
49
|
+
"@google-cloud/storage": "5.16.0",
|
|
50
|
+
"@rollup/plugin-alias": "3.1.8",
|
|
51
|
+
"@rollup/plugin-commonjs": "21.0.1",
|
|
51
52
|
"@rollup/plugin-json": "4.1.0",
|
|
52
53
|
"@rollup/plugin-node-resolve": "13.0.6",
|
|
53
54
|
"archiver": "5.3.0",
|
|
54
55
|
"chalk": "4.1.2",
|
|
56
|
+
"constants-browserify": "1.0.0",
|
|
55
57
|
"dotenv": "10.0.0",
|
|
56
58
|
"express": "4.17.1",
|
|
59
|
+
"form-data": "4.0.0",
|
|
57
60
|
"fs-extra": "10.0.0",
|
|
61
|
+
"get-stream": "6.0.1",
|
|
58
62
|
"isomorphic-git": "1.10.1",
|
|
59
|
-
"openwhisk": "3.21.
|
|
63
|
+
"openwhisk": "3.21.5",
|
|
60
64
|
"proxyquire": "2.1.3",
|
|
61
|
-
"rollup": "2.
|
|
65
|
+
"rollup": "2.60.0",
|
|
62
66
|
"rollup-plugin-terser": "7.0.2",
|
|
63
67
|
"semver": "7.3.5",
|
|
64
|
-
"
|
|
68
|
+
"tar": "6.1.11",
|
|
69
|
+
"webpack": "5.64.2",
|
|
65
70
|
"yargs": "17.2.1"
|
|
66
71
|
},
|
|
67
72
|
"devDependencies": {
|
|
@@ -76,13 +81,13 @@
|
|
|
76
81
|
"codecov": "3.8.3",
|
|
77
82
|
"eslint": "8.2.0",
|
|
78
83
|
"eslint-plugin-header": "3.1.1",
|
|
79
|
-
"eslint-plugin-import": "2.25.
|
|
84
|
+
"eslint-plugin-import": "2.25.3",
|
|
80
85
|
"ghooks": "2.0.4",
|
|
81
|
-
"lint-staged": "
|
|
86
|
+
"lint-staged": "12.0.3",
|
|
82
87
|
"mocha": "9.1.3",
|
|
83
88
|
"mocha-junit-reporter": "2.0.2",
|
|
84
89
|
"mocha-multi-reporters": "1.5.1",
|
|
85
|
-
"nock": "13.1
|
|
90
|
+
"nock": "13.2.1",
|
|
86
91
|
"nyc": "15.1.0",
|
|
87
92
|
"semantic-release": "18.0.0",
|
|
88
93
|
"sinon": "12.0.1",
|
package/src/ActionBuilder.js
CHANGED
|
@@ -9,19 +9,26 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
+
/* eslint-disable no-await-in-loop */
|
|
12
13
|
|
|
13
14
|
const path = require('path');
|
|
14
15
|
const fs = require('fs');
|
|
15
16
|
const fse = require('fs-extra');
|
|
16
17
|
const chalk = require('chalk');
|
|
17
18
|
const git = require('isomorphic-git');
|
|
18
|
-
const WebpackBundler = require('./
|
|
19
|
-
const
|
|
19
|
+
const WebpackBundler = require('./bundler/WebpackBundler');
|
|
20
|
+
const EdgeBundler = require('./bundler/EdgeBundler');
|
|
21
|
+
const RollupBundler = require('./bundler/RollupBundler');
|
|
20
22
|
const { version } = require('../package.json');
|
|
21
23
|
|
|
22
24
|
const Bundlers = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
node: {
|
|
26
|
+
webpack: WebpackBundler,
|
|
27
|
+
rollup: RollupBundler,
|
|
28
|
+
},
|
|
29
|
+
edge: {
|
|
30
|
+
webpack: EdgeBundler,
|
|
31
|
+
},
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
/**
|
|
@@ -194,6 +201,9 @@ module.exports = class ActionBuilder {
|
|
|
194
201
|
const ext = cfg.esm ? '.mjs' : '.cjs';
|
|
195
202
|
cfg.bundle = path.resolve(cfg.distDir, cfg.packageName, `${cfg.name}-bundle${ext}`);
|
|
196
203
|
}
|
|
204
|
+
if (!cfg.edgeBundle) {
|
|
205
|
+
cfg.edgeBundle = path.resolve(cfg.distDir, cfg.packageName, `${cfg.name}-edge-bundle.cjs`);
|
|
206
|
+
}
|
|
197
207
|
if (!cfg.depFile) {
|
|
198
208
|
cfg.depFile = path.resolve(cfg.distDir, cfg.packageName, `${cfg.name}-dependencies.json`);
|
|
199
209
|
}
|
|
@@ -262,6 +272,30 @@ module.exports = class ActionBuilder {
|
|
|
262
272
|
this.validated = true;
|
|
263
273
|
}
|
|
264
274
|
|
|
275
|
+
async validateBundlers() {
|
|
276
|
+
if (this.validated) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
// disable edge build
|
|
280
|
+
|
|
281
|
+
const { cfg } = this;
|
|
282
|
+
this.bundlers = [];
|
|
283
|
+
cfg.archs.forEach((arch) => {
|
|
284
|
+
const bnds = Bundlers[arch];
|
|
285
|
+
if (!bnds) {
|
|
286
|
+
throw Error(`Invalid arch '${arch}' specified. Valid options are: ${Object.keys(Bundlers)}`);
|
|
287
|
+
}
|
|
288
|
+
const BundlerClass = bnds[cfg.bundler];
|
|
289
|
+
if (!BundlerClass) {
|
|
290
|
+
throw Error(`Invalid bundler '${cfg.bundler}' for '${arch}'. Valid options are: ${Object.keys(bnds)}`);
|
|
291
|
+
}
|
|
292
|
+
this.bundlers.push(new BundlerClass().withConfig(cfg));
|
|
293
|
+
});
|
|
294
|
+
for (const bundler of this.bundlers) {
|
|
295
|
+
await bundler.init();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
265
299
|
async execute(fnName, msg, ...args) {
|
|
266
300
|
const { cfg } = this;
|
|
267
301
|
const deps = Object.values(this._deployers)
|
|
@@ -341,18 +375,14 @@ module.exports = class ActionBuilder {
|
|
|
341
375
|
cfg.log.info(chalk`{grey universal-action-builder v${version}}`);
|
|
342
376
|
await this.validate();
|
|
343
377
|
await this.validateAdditionalTasks();
|
|
344
|
-
|
|
345
|
-
const BundlerClass = Bundlers[cfg.bundler];
|
|
346
|
-
if (!BundlerClass) {
|
|
347
|
-
throw Error(`Invalid no bundler found for: ${cfg.bundler}. Valid options are: ${Object.keys(Bundlers)}`);
|
|
348
|
-
}
|
|
349
|
-
const bundler = new BundlerClass().withConfig(cfg);
|
|
350
|
-
await bundler.init();
|
|
378
|
+
await this.validateBundlers();
|
|
351
379
|
|
|
352
380
|
if (cfg.build) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
381
|
+
for (const bundler of this.bundlers) {
|
|
382
|
+
await bundler.createBundle();
|
|
383
|
+
await bundler.createArchive();
|
|
384
|
+
await bundler.validateBundle();
|
|
385
|
+
}
|
|
356
386
|
}
|
|
357
387
|
|
|
358
388
|
if (cfg.updatePackage) {
|
|
@@ -366,7 +396,9 @@ module.exports = class ActionBuilder {
|
|
|
366
396
|
const relZip = path.relative(process.cwd(), cfg.zipFile);
|
|
367
397
|
cfg.log.info(chalk`{green ok:} using: {yellow ${relZip}}.`);
|
|
368
398
|
cfg.dependencies = await fse.readJson(cfg.depFile);
|
|
369
|
-
|
|
399
|
+
for (const bundler of this.bundlers) {
|
|
400
|
+
await bundler.validateBundle();
|
|
401
|
+
}
|
|
370
402
|
}
|
|
371
403
|
await this.deploy();
|
|
372
404
|
}
|
|
@@ -391,22 +423,32 @@ module.exports = class ActionBuilder {
|
|
|
391
423
|
await this.runCleanup();
|
|
392
424
|
}
|
|
393
425
|
|
|
426
|
+
// update gateway
|
|
394
427
|
if (this._gateways.fastly && this._gateways.fastly.ready()) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
428
|
+
Object.values(this._deployers)
|
|
429
|
+
.filter((deployer) => !deployer.noGatewayBackend)
|
|
430
|
+
.forEach((deplyer) => {
|
|
431
|
+
this._gateways.fastly.withDeployer(deplyer);
|
|
432
|
+
});
|
|
399
433
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
434
|
+
const updateLinks = cfg.links && cfg.links.length;
|
|
435
|
+
const updatePackage = cfg.updatePackage && cfg.packageParams && cfg.packageToken;
|
|
403
436
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
437
|
+
// links and package also need a deployed gateway
|
|
438
|
+
if ((updateLinks || updatePackage || cfg.deploy)) {
|
|
439
|
+
this._gateways.fastly.init();
|
|
440
|
+
if (this._gateways.fastly.canDeploy()) {
|
|
441
|
+
await this._gateways.fastly.deploy();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (updateLinks) {
|
|
446
|
+
await this._gateways.fastly.updateLinks(cfg.links, cfg.version);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (updatePackage) {
|
|
450
|
+
await this._gateways.fastly.updatePackage();
|
|
451
|
+
}
|
|
410
452
|
}
|
|
411
453
|
|
|
412
454
|
if (cfg.deploy) {
|
package/src/BaseConfig.js
CHANGED
|
@@ -88,6 +88,7 @@ class BaseConfig {
|
|
|
88
88
|
targets: [],
|
|
89
89
|
functionURL: '',
|
|
90
90
|
esm: false,
|
|
91
|
+
archs: ['node', 'edge'],
|
|
91
92
|
bundler: 'webpack',
|
|
92
93
|
format: {
|
|
93
94
|
aws: DEFAULT_ACTION_FORMAT,
|
|
@@ -164,6 +165,7 @@ class BaseConfig {
|
|
|
164
165
|
.withVerbose(argv.verbose)
|
|
165
166
|
.withDirectory(argv.directory)
|
|
166
167
|
.withTarget(argv.target)
|
|
168
|
+
.withArch(argv.arch)
|
|
167
169
|
.withBuild(argv.build)
|
|
168
170
|
.withMinify(argv.minify)
|
|
169
171
|
.withESM(argv.esm)
|
|
@@ -203,6 +205,7 @@ class BaseConfig {
|
|
|
203
205
|
.withCleanupPatch(argv.cleanupPatch)
|
|
204
206
|
.withCleanupMinor(argv.cleanupMinor)
|
|
205
207
|
.withCleanupMajor(argv.cleanupMajor)
|
|
208
|
+
.withPackageToken(argv.packageToken)
|
|
206
209
|
.withProperties(argv.property);
|
|
207
210
|
}
|
|
208
211
|
|
|
@@ -226,6 +229,16 @@ class BaseConfig {
|
|
|
226
229
|
return this;
|
|
227
230
|
}
|
|
228
231
|
|
|
232
|
+
withArch(value) {
|
|
233
|
+
this.archs = [];
|
|
234
|
+
value.forEach((v) => {
|
|
235
|
+
v.split(',').forEach((t) => {
|
|
236
|
+
this.archs.push(t.trim());
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
|
|
229
242
|
withDeploy(enable) {
|
|
230
243
|
this.deploy = enable;
|
|
231
244
|
return this;
|
|
@@ -521,6 +534,11 @@ class BaseConfig {
|
|
|
521
534
|
return this;
|
|
522
535
|
}
|
|
523
536
|
|
|
537
|
+
withPackageToken(value) {
|
|
538
|
+
this.packageToken = value;
|
|
539
|
+
return this;
|
|
540
|
+
}
|
|
541
|
+
|
|
524
542
|
get log() {
|
|
525
543
|
if (!this._logger) {
|
|
526
544
|
// poor men's logging...
|
|
@@ -598,7 +616,7 @@ class BaseConfig {
|
|
|
598
616
|
default: 'webpack',
|
|
599
617
|
})
|
|
600
618
|
.option('esm', {
|
|
601
|
-
description: 'Produce EcmaScript Module (experimental)',
|
|
619
|
+
description: 'Produce EcmaScript Module (experimental, disables edge arch)',
|
|
602
620
|
type: 'boolean',
|
|
603
621
|
default: false,
|
|
604
622
|
})
|
|
@@ -626,6 +644,12 @@ class BaseConfig {
|
|
|
626
644
|
type: 'array',
|
|
627
645
|
default: [],
|
|
628
646
|
})
|
|
647
|
+
.option('arch', {
|
|
648
|
+
description: 'Select archs(s) for bundles (node,edge).',
|
|
649
|
+
type: 'string',
|
|
650
|
+
default: ['node'],
|
|
651
|
+
array: true,
|
|
652
|
+
})
|
|
629
653
|
|
|
630
654
|
.group(['target', 'hints'], 'Deploy Options')
|
|
631
655
|
.option('target', {
|
|
@@ -736,6 +760,11 @@ class BaseConfig {
|
|
|
736
760
|
return value;
|
|
737
761
|
},
|
|
738
762
|
})
|
|
763
|
+
.option('package-token', {
|
|
764
|
+
description: 'Protects access to the gateway-stored package parameters with this token. leave empty to generate random token.',
|
|
765
|
+
type: 'string',
|
|
766
|
+
default: crypto.randomBytes(32).toString('base64'),
|
|
767
|
+
})
|
|
739
768
|
.option('params', {
|
|
740
769
|
alias: 'p',
|
|
741
770
|
description: 'Include the given action param. can be json or env.',
|
package/src/DevelopmentServer.js
CHANGED
|
@@ -70,6 +70,7 @@ module.exports = class DevelopmentServer {
|
|
|
70
70
|
this._main = main;
|
|
71
71
|
this._cwd = process.cwd();
|
|
72
72
|
this._port = process.env.WEBSERVER_PORT || 3000;
|
|
73
|
+
this._xfh = 'helix-pages.anywhere.run';
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
withPort(value) {
|
|
@@ -77,6 +78,11 @@ module.exports = class DevelopmentServer {
|
|
|
77
78
|
return this;
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
withXFH(value) {
|
|
82
|
+
this._xfh = value;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
80
86
|
get port() {
|
|
81
87
|
return this._port;
|
|
82
88
|
}
|
|
@@ -131,21 +137,21 @@ module.exports = class DevelopmentServer {
|
|
|
131
137
|
*/
|
|
132
138
|
async start() {
|
|
133
139
|
this.app = express();
|
|
134
|
-
this.app.use(rawBody());
|
|
135
|
-
this.app.use(addRequestHeader('x-forwarded-host', 'helix-pages.anywhere.run'));
|
|
136
|
-
this.app.all('*', this._handler);
|
|
137
140
|
await new Promise((resolve, reject) => {
|
|
138
141
|
try {
|
|
139
142
|
this.server = this.app.listen(this._port, () => {
|
|
140
143
|
this._port = this.server.address().port;
|
|
141
144
|
// eslint-disable-next-line no-console
|
|
142
|
-
console.log(`Started development server
|
|
145
|
+
console.log(`Started development server at http://localhost:${this._port}/`);
|
|
143
146
|
resolve();
|
|
144
147
|
});
|
|
145
148
|
} catch (e) {
|
|
146
149
|
reject(e);
|
|
147
150
|
}
|
|
148
151
|
});
|
|
152
|
+
this.app.use(rawBody());
|
|
153
|
+
this.app.use(addRequestHeader('x-forwarded-host', this._xfh.replace('{port}', this._port)));
|
|
154
|
+
this.app.all('*', this._handler);
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
/**
|
|
@@ -15,11 +15,11 @@ const fse = require('fs-extra');
|
|
|
15
15
|
const chalk = require('chalk');
|
|
16
16
|
const archiver = require('archiver');
|
|
17
17
|
const semver = require('semver');
|
|
18
|
-
const { validateBundle } = require('
|
|
19
|
-
const { dependencies } = require('
|
|
18
|
+
const { validateBundle } = require('../utils.js');
|
|
19
|
+
const { dependencies } = require('../../package.json');
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Base for all bundlers
|
|
23
23
|
*/
|
|
24
24
|
module.exports = class BaseBundler {
|
|
25
25
|
/**
|
|
@@ -167,6 +167,15 @@ module.exports = class BaseBundler {
|
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
archive.append(JSON.stringify(packageJson, null, ' '), { name: 'package.json' });
|
|
170
|
+
|
|
171
|
+
// edge function stuff
|
|
172
|
+
archive.append([
|
|
173
|
+
'account_id = "fakefakefake"',
|
|
174
|
+
`name = "${this.cfg.packageName}/${this.cfg.name}"`,
|
|
175
|
+
'type = "javascript"',
|
|
176
|
+
'workers_dev = true',
|
|
177
|
+
].join('\n'), { name: 'wrangler.toml' });
|
|
178
|
+
|
|
170
179
|
// azure functions manifest
|
|
171
180
|
archive.append(JSON.stringify(this.functionJson, null, ' '), { name: 'function.json' });
|
|
172
181
|
|
|
@@ -174,7 +183,7 @@ module.exports = class BaseBundler {
|
|
|
174
183
|
if (cfg.esm) {
|
|
175
184
|
archive.directory('esm-adapter');
|
|
176
185
|
archive.append('{}', { name: 'esm-adapter/package.json' });
|
|
177
|
-
archive.file(path.resolve(__dirname, 'template', 'aws-esm-adapter.js'), { name: 'esm-adapter/index.js' });
|
|
186
|
+
archive.file(path.resolve(__dirname, '..', 'template', 'aws-esm-adapter.js'), { name: 'esm-adapter/index.js' });
|
|
178
187
|
}
|
|
179
188
|
}
|
|
180
189
|
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const webpack = require('webpack');
|
|
15
|
+
const WebpackBundler = require('./WebpackBundler.js');
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates the action bundle
|
|
19
|
+
*/
|
|
20
|
+
module.exports = class EdgeBundler extends WebpackBundler {
|
|
21
|
+
async getWebpackConfig() {
|
|
22
|
+
const { cfg } = this;
|
|
23
|
+
const opts = {
|
|
24
|
+
target: 'webworker',
|
|
25
|
+
mode: 'development',
|
|
26
|
+
// the universal adapter is the entry point
|
|
27
|
+
entry: cfg.adapterFile || path.resolve(__dirname, '..', 'template', 'serviceworker-index.js'),
|
|
28
|
+
output: {
|
|
29
|
+
path: cfg.cwd,
|
|
30
|
+
filename: path.relative(cfg.cwd, cfg.edgeBundle),
|
|
31
|
+
library: 'main',
|
|
32
|
+
libraryTarget: 'umd',
|
|
33
|
+
globalObject: 'globalThis',
|
|
34
|
+
},
|
|
35
|
+
devtool: false,
|
|
36
|
+
externals: [
|
|
37
|
+
...cfg.externals,
|
|
38
|
+
// the following are imported by the universal adapter and are assumed to be available
|
|
39
|
+
'./params.json',
|
|
40
|
+
'aws-sdk',
|
|
41
|
+
'@google-cloud/secret-manager',
|
|
42
|
+
'@google-cloud/storage',
|
|
43
|
+
].reduce((obj, ext) => {
|
|
44
|
+
// this makes webpack to ignore the module and just leave it as normal require.
|
|
45
|
+
// eslint-disable-next-line no-param-reassign
|
|
46
|
+
obj[ext] = `commonjs2 ${ext}`;
|
|
47
|
+
return obj;
|
|
48
|
+
}, {}),
|
|
49
|
+
module: {
|
|
50
|
+
rules: [{
|
|
51
|
+
test: /\.mjs$/,
|
|
52
|
+
type: 'javascript/auto',
|
|
53
|
+
}],
|
|
54
|
+
},
|
|
55
|
+
resolve: {
|
|
56
|
+
mainFields: ['main', 'module'],
|
|
57
|
+
extensions: ['.wasm', '.js', '.mjs', '.json'],
|
|
58
|
+
alias: {
|
|
59
|
+
// the main.js is imported in the universal adapter and is _the_ action entry point
|
|
60
|
+
'./main.js': cfg.file,
|
|
61
|
+
// 'psl': path.resolve(__dirname, '../node_modules/psl/dist/psl.js'), // inlined data
|
|
62
|
+
'@adobe/helix-fetch': path.resolve(__dirname, '../template/polyfills/helix-fetch.js'),
|
|
63
|
+
},
|
|
64
|
+
/* fallback: {
|
|
65
|
+
assert: require.resolve('assert'),
|
|
66
|
+
buffer: require.resolve('buffer'),
|
|
67
|
+
console: require.resolve('console-browserify'),
|
|
68
|
+
constants: require.resolve('constants-browserify'),
|
|
69
|
+
crypto: require.resolve('crypto-browserify'),
|
|
70
|
+
domain: require.resolve('domain-browser'),
|
|
71
|
+
events: path.resolve(__dirname, '../node_modules/events/events.js'),
|
|
72
|
+
http: require.resolve('stream-http'),
|
|
73
|
+
https: require.resolve('https-browserify'),
|
|
74
|
+
os: require.resolve('os-browserify/browser'),
|
|
75
|
+
path: require.resolve('path-browserify'),
|
|
76
|
+
punycode: require.resolve('punycode'),
|
|
77
|
+
process: require.resolve('process/browser'),
|
|
78
|
+
querystring: require.resolve('querystring-es3'),
|
|
79
|
+
stream: require.resolve('stream-browserify'),
|
|
80
|
+
string_decoder: require.resolve('string_decoder'),
|
|
81
|
+
sys: require.resolve('util'),
|
|
82
|
+
timers: require.resolve('timers-browserify'),
|
|
83
|
+
tty: require.resolve('tty-browserify'),
|
|
84
|
+
url: require.resolve('url'),
|
|
85
|
+
util: require.resolve('util'),
|
|
86
|
+
vm: require.resolve('vm-browserify'),
|
|
87
|
+
zlib: require.resolve('browserify-zlib'),
|
|
88
|
+
}, */
|
|
89
|
+
},
|
|
90
|
+
node: {
|
|
91
|
+
__dirname: true,
|
|
92
|
+
__filename: false,
|
|
93
|
+
},
|
|
94
|
+
plugins: [],
|
|
95
|
+
};
|
|
96
|
+
if (cfg.minify) {
|
|
97
|
+
opts.optimization = {
|
|
98
|
+
minimize: cfg.minify,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (cfg.modulePaths && cfg.modulePaths.length > 0) {
|
|
102
|
+
opts.resolve.modules = cfg.modulePaths;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (cfg.progressHandler) {
|
|
106
|
+
opts.plugins.push(new webpack.ProgressPlugin(cfg.progressHandler));
|
|
107
|
+
}
|
|
108
|
+
return opts;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async createBundle() {
|
|
112
|
+
const { cfg } = this;
|
|
113
|
+
if (!cfg.edgeBundle) {
|
|
114
|
+
throw Error('edge bundle path is undefined');
|
|
115
|
+
}
|
|
116
|
+
return this.createWebpackBundle('edge');
|
|
117
|
+
}
|
|
118
|
+
};
|
|
@@ -31,7 +31,7 @@ module.exports = class Bundler extends BaseBundler {
|
|
|
31
31
|
* @type {import('rollup').RollupOptions}
|
|
32
32
|
*/
|
|
33
33
|
const opts = {
|
|
34
|
-
input: cfg.adapterFile || path.resolve(__dirname, 'template', cfg.esm ? 'index.mjs' : 'index.js'),
|
|
34
|
+
input: cfg.adapterFile || path.resolve(__dirname, '..', 'template', cfg.esm ? 'node-index.mjs' : 'node-index.js'),
|
|
35
35
|
output: {
|
|
36
36
|
file: cfg.bundle,
|
|
37
37
|
name: 'main',
|
|
@@ -154,7 +154,7 @@ module.exports = class Bundler extends BaseBundler {
|
|
|
154
154
|
Object.entries(depsByFile)
|
|
155
155
|
.forEach(([scriptFile, deps]) => {
|
|
156
156
|
// map 'index' to 'main', in order to be compatible with rollup
|
|
157
|
-
if (scriptFile === 'index') {
|
|
157
|
+
if (scriptFile === 'node-index') {
|
|
158
158
|
// eslint-disable-next-line no-param-reassign
|
|
159
159
|
scriptFile = 'main';
|
|
160
160
|
}
|