@adobe/helix-deploy 4.12.2 → 4.15.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 +56 -0
- package/README.md +1 -1
- package/index.js +1 -1
- package/package.json +28 -16
- package/src/ActionBuilder.js +76 -22
- package/src/BaseConfig.js +59 -4
- package/src/DevelopmentServer.js +10 -4
- package/src/bundler/BaseBundler.js +189 -0
- package/src/bundler/EdgeBundler.js +118 -0
- package/src/bundler/RollupBundler.js +165 -0
- package/src/{Bundler.js → bundler/WebpackBundler.js} +18 -158
- package/src/cli.js +4 -0
- package/src/deploy/AWSDeployer.js +4 -2
- package/src/deploy/AzureDeployer.js +8 -4
- package/src/deploy/BaseDeployer.js +11 -4
- 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/aws-esm-adapter.js +20 -0
- package/src/template/cloudflare-adapter.js +62 -0
- package/src/template/fastly-adapter.js +99 -0
- package/src/template/{index.js → node-index.js} +2 -0
- package/src/template/node-index.mjs +25 -0
- package/src/template/polyfills/helix-fetch.js +19 -0
- package/src/template/serviceworker-index.js +24 -0
- package/src/template/validate-bundle.js +32 -0
- package/src/utils.js +33 -1
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
/* eslint-env serviceworker */
|
|
13
|
+
/* global Dictionary */
|
|
14
|
+
|
|
15
|
+
async function handler(event) {
|
|
16
|
+
try {
|
|
17
|
+
const { request } = event;
|
|
18
|
+
console.log('Fastly Adapter is here');
|
|
19
|
+
let packageParams;
|
|
20
|
+
// eslint-disable-next-line import/no-unresolved,global-require
|
|
21
|
+
const { main } = require('./main.js');
|
|
22
|
+
const context = {
|
|
23
|
+
resolver: null,
|
|
24
|
+
pathInfo: {
|
|
25
|
+
suffix: request.url.replace(/\?.*/, ''),
|
|
26
|
+
},
|
|
27
|
+
runtime: {
|
|
28
|
+
name: 'compute-at-edge',
|
|
29
|
+
// region: request.cf.colo,
|
|
30
|
+
},
|
|
31
|
+
func: {
|
|
32
|
+
name: null,
|
|
33
|
+
package: null,
|
|
34
|
+
version: null,
|
|
35
|
+
fqn: null,
|
|
36
|
+
app: null,
|
|
37
|
+
},
|
|
38
|
+
invocation: {
|
|
39
|
+
id: null,
|
|
40
|
+
deadline: null,
|
|
41
|
+
transactionId: null,
|
|
42
|
+
requestId: null,
|
|
43
|
+
},
|
|
44
|
+
env: new Proxy(new Dictionary('secrets'), {
|
|
45
|
+
get: (target, prop) => {
|
|
46
|
+
try {
|
|
47
|
+
return target.get(prop);
|
|
48
|
+
} catch {
|
|
49
|
+
if (packageParams) {
|
|
50
|
+
console.log('Using cached params');
|
|
51
|
+
return packageParams[prop];
|
|
52
|
+
}
|
|
53
|
+
const url = target.get('_package');
|
|
54
|
+
const token = target.get('_token');
|
|
55
|
+
// console.log(`Getting secrets from ${url} with ${token}`);
|
|
56
|
+
return fetch(url, {
|
|
57
|
+
backend: 'gateway',
|
|
58
|
+
headers: {
|
|
59
|
+
authorization: `Bearer ${token}`,
|
|
60
|
+
},
|
|
61
|
+
}).then((response) => {
|
|
62
|
+
if (response.ok) {
|
|
63
|
+
// console.log('response is ok...');
|
|
64
|
+
return response.text().then((json) => {
|
|
65
|
+
// console.log('json received: ' + json);
|
|
66
|
+
packageParams = JSON.parse(json);
|
|
67
|
+
return packageParams[prop];
|
|
68
|
+
}).catch((error) => {
|
|
69
|
+
console.error(`Unable to parse JSON: ${error.message}`);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
console.error(`HTTP status is not ok: ${response.status}`);
|
|
73
|
+
return undefined;
|
|
74
|
+
}).catch((err) => {
|
|
75
|
+
console.error(`Unable to fetch parames: ${err.message}`);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
storage: null,
|
|
81
|
+
};
|
|
82
|
+
const response = await main(request, context);
|
|
83
|
+
return response;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.log(e.message);
|
|
86
|
+
return new Response(`Error: ${e.message}`, { status: 500 });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function fastly() {
|
|
91
|
+
console.log('checking for fastly environment');
|
|
92
|
+
/* eslint-disable-next-line no-undef */
|
|
93
|
+
if (CacheOverride) {
|
|
94
|
+
return handler;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = fastly;
|
|
@@ -9,6 +9,8 @@
|
|
|
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-next-line no-underscore-dangle
|
|
13
|
+
global.__rootdir = __dirname;
|
|
12
14
|
|
|
13
15
|
const {
|
|
14
16
|
openwhisk,
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import { dirname } from 'path';
|
|
14
|
+
import { fileURLToPath } from 'url';
|
|
15
|
+
import { adapter } from '@adobe/helix-universal';
|
|
16
|
+
const { openwhisk, aws, google, azure } = adapter;
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
19
|
+
global.__rootdir = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
|
|
21
|
+
export default Object.assign(azure, {
|
|
22
|
+
main: openwhisk,
|
|
23
|
+
lambda: aws,
|
|
24
|
+
google,
|
|
25
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
/* eslint-env serviceworker */
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
// replacing helix-fetch with the built-in APIs
|
|
16
|
+
fetch,
|
|
17
|
+
Request,
|
|
18
|
+
Response,
|
|
19
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
/* eslint-env serviceworker */
|
|
13
|
+
const fastly = require('./fastly-adapter');
|
|
14
|
+
const cloudflare = require('./cloudflare-adapter');
|
|
15
|
+
|
|
16
|
+
/* eslint-disable no-restricted-globals */
|
|
17
|
+
if (typeof addEventListener === 'function') {
|
|
18
|
+
addEventListener('fetch', (event) => {
|
|
19
|
+
const handler = cloudflare() || fastly();
|
|
20
|
+
if (typeof handler === 'function') {
|
|
21
|
+
event.respondWith(handler(event));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
async function run(bundlePath, opts) {
|
|
13
|
+
const result = {
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
const bundle = await import(bundlePath);
|
|
17
|
+
const main = bundle.default?.main;
|
|
18
|
+
if (!main || typeof main !== 'function') {
|
|
19
|
+
throw Error('Action has no main() function.');
|
|
20
|
+
}
|
|
21
|
+
if (opts.invoke) {
|
|
22
|
+
result.response = await main({});
|
|
23
|
+
}
|
|
24
|
+
result.status = 'ok';
|
|
25
|
+
} catch (e) {
|
|
26
|
+
result.status = 'error';
|
|
27
|
+
result.error = `${e.message}\n${e.stack}`;
|
|
28
|
+
}
|
|
29
|
+
process.send(JSON.stringify(result));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
run(process.argv[2], JSON.parse(process.argv[3])).then(process.stdout).catch(process.stderr);
|
package/src/utils.js
CHANGED
|
@@ -9,6 +9,9 @@
|
|
|
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
|
+
const { fork } = require('child_process');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
12
15
|
/**
|
|
13
16
|
* @typedef {object} VersionCoordinates
|
|
14
17
|
* @property {number} ci - CI build number
|
|
@@ -41,6 +44,7 @@
|
|
|
41
44
|
* @property {VersionCoordinates} version - version of the action
|
|
42
45
|
* @property {Date} updated - timestamp of the update of the action
|
|
43
46
|
*/
|
|
47
|
+
|
|
44
48
|
/**
|
|
45
49
|
* Filters a list of named actions according
|
|
46
50
|
* to maximum age or number of versions.
|
|
@@ -147,4 +151,32 @@ function filterActions(fns, now, {
|
|
|
147
151
|
...cleanmajorbyage, ...cleanmajorbycount];
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
|
|
154
|
+
async function validateBundle(bundlePath, invoke = false) {
|
|
155
|
+
try {
|
|
156
|
+
const opts = {
|
|
157
|
+
invoke,
|
|
158
|
+
};
|
|
159
|
+
const child = fork(path.resolve(__dirname, 'template', 'validate-bundle.js'), [bundlePath, JSON.stringify(opts)]);
|
|
160
|
+
const ret = await new Promise((resolve, reject) => {
|
|
161
|
+
child.on('message', resolve);
|
|
162
|
+
child.on('error', reject);
|
|
163
|
+
child.on('exit', (code) => {
|
|
164
|
+
resolve(JSON.stringify({
|
|
165
|
+
status: 'error',
|
|
166
|
+
error: `Child process stopped with exit code ${code}`,
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
return JSON.parse(ret);
|
|
171
|
+
} catch (e) {
|
|
172
|
+
return {
|
|
173
|
+
status: 'error',
|
|
174
|
+
error: e.message,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
module.exports = {
|
|
180
|
+
filterActions,
|
|
181
|
+
validateBundle,
|
|
182
|
+
};
|