@adobe/helix-deploy 10.4.0 → 11.0.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 +12 -0
- package/README.md +9 -22
- package/index.js +0 -1
- package/package.json +2 -3
- package/src/bundler/WebpackBundler.js +1 -1
- package/src/DevelopmentServer.js +0 -237
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [11.0.0](https://github.com/adobe/helix-deploy/compare/v10.4.0...v11.0.0) (2024-01-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* move development server to own package ([#659](https://github.com/adobe/helix-deploy/issues/659)) ([43cbb16](https://github.com/adobe/helix-deploy/commit/43cbb16bb74ebfab1759b7b8ae0f842db6ec3ebe)), closes [#654](https://github.com/adobe/helix-deploy/issues/654)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* import { DevelopmentServer } from @adobe/helix-universal-devserver
|
|
12
|
+
|
|
1
13
|
# [10.4.0](https://github.com/adobe/helix-deploy/compare/v10.3.3...v10.4.0) (2024-01-29)
|
|
2
14
|
|
|
3
15
|
|
package/README.md
CHANGED
|
@@ -347,38 +347,25 @@ destination filename. eg:
|
|
|
347
347
|
|
|
348
348
|
## Using the development server
|
|
349
349
|
|
|
350
|
-
Testing an
|
|
351
|
-
|
|
350
|
+
Testing an universal function can be done with the [development server](https://github.com/adobe/helix-universal-devserver).
|
|
351
|
+
|
|
352
|
+
Just create a `test/dev.js` file with:
|
|
352
353
|
|
|
353
354
|
```js
|
|
354
|
-
|
|
355
|
-
|
|
355
|
+
import { DevelopmentServer } from '@adobe/helix-universal-devserver';
|
|
356
|
+
import { main } from '../src/index.js';
|
|
356
357
|
|
|
357
358
|
async function run() {
|
|
358
|
-
const devServer = await new DevelopmentServer(
|
|
359
|
-
|
|
359
|
+
const devServer = await new DevelopmentServer(main).init();
|
|
360
|
+
await devServer.start();
|
|
360
361
|
}
|
|
361
362
|
|
|
362
|
-
|
|
363
|
-
run().catch(console.error);
|
|
363
|
+
run().then(process.stdout).catch(process.stderr);
|
|
364
364
|
```
|
|
365
365
|
|
|
366
366
|
and run `node test/dev.js`.
|
|
367
367
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
Sometimes it might be useful to specify action params that would be provided during deployment
|
|
371
|
-
but are not available during development. those can be specified by a `dev-params-file` `wsk`
|
|
372
|
-
property. those parameters are loaded an applied to every action call. eg:
|
|
373
|
-
|
|
374
|
-
```json
|
|
375
|
-
...
|
|
376
|
-
"wsk": {
|
|
377
|
-
...
|
|
378
|
-
"dev-params-file": ".dev-secrets.env"
|
|
379
|
-
}
|
|
380
|
-
...
|
|
381
|
-
```
|
|
368
|
+
for more information see https://github.com/adobe/helix-universal-devserver
|
|
382
369
|
|
|
383
370
|
## Notes
|
|
384
371
|
|
package/index.js
CHANGED
|
@@ -13,4 +13,3 @@ export { default as ActionBuilder } from './src/ActionBuilder.js';
|
|
|
13
13
|
export { default as Bundler } from './src/bundler/WebpackBundler.js';
|
|
14
14
|
export { default as BaseConfig } from './src/BaseConfig.js';
|
|
15
15
|
export { default as CLI } from './src/cli.js';
|
|
16
|
-
export { default as DevelopmentServer } from './src/DevelopmentServer.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-deploy",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "Library and Commandline Tools to build and deploy OpenWhisk Actions",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/adobe/helix-deploy#readme",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"chalk-template": "1.1.0",
|
|
60
60
|
"constants-browserify": "1.0.0",
|
|
61
61
|
"dotenv": "16.4.1",
|
|
62
|
-
"express": "4.18.2",
|
|
63
62
|
"form-data": "4.0.0",
|
|
64
63
|
"fs-extra": "11.2.0",
|
|
65
64
|
"isomorphic-git": "1.25.3",
|
|
@@ -77,7 +76,7 @@
|
|
|
77
76
|
"@semantic-release/git": "10.0.1",
|
|
78
77
|
"c8": "9.1.0",
|
|
79
78
|
"eslint": "8.56.0",
|
|
80
|
-
"husky": "
|
|
79
|
+
"husky": "9.0.7",
|
|
81
80
|
"lint-staged": "15.2.0",
|
|
82
81
|
"mocha": "10.2.0",
|
|
83
82
|
"mocha-junit-reporter": "2.2.1",
|
|
@@ -81,7 +81,7 @@ export default class WebpackBundler extends BaseBundler {
|
|
|
81
81
|
},
|
|
82
82
|
// use fixed conditions to omit the `development` condition.
|
|
83
83
|
// see: https://webpack.js.org/guides/package-exports/#conditions
|
|
84
|
-
conditionNames: ['node', 'require', 'import'],
|
|
84
|
+
conditionNames: ['node', 'require', 'import', 'module'],
|
|
85
85
|
},
|
|
86
86
|
node: {
|
|
87
87
|
__dirname: true,
|
package/src/DevelopmentServer.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 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
|
-
import crypto from 'crypto';
|
|
13
|
-
import fse from 'fs-extra';
|
|
14
|
-
import path from 'path';
|
|
15
|
-
import express from 'express';
|
|
16
|
-
import { createAdapter } from '@adobe/helix-universal/aws';
|
|
17
|
-
import ActionBuilder from './ActionBuilder.js';
|
|
18
|
-
import BaseConfig from './BaseConfig.js';
|
|
19
|
-
|
|
20
|
-
function rawBody() {
|
|
21
|
-
return (req, res, next) => {
|
|
22
|
-
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
23
|
-
next();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const chunks = [];
|
|
27
|
-
req.on('data', (chunk) => {
|
|
28
|
-
chunks.push(chunk);
|
|
29
|
-
});
|
|
30
|
-
req.on('end', () => {
|
|
31
|
-
req.rawBody = Buffer.concat(chunks);
|
|
32
|
-
next();
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function addRequestHeader(name, value) {
|
|
38
|
-
return (req, res, next) => {
|
|
39
|
-
req.headers[name] = value;
|
|
40
|
-
next();
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Development server for local development.
|
|
46
|
-
*
|
|
47
|
-
* Example:
|
|
48
|
-
*
|
|
49
|
-
* ```
|
|
50
|
-
* // test/dev.js
|
|
51
|
-
*
|
|
52
|
-
* const { DevelopmentServer } = require('@adobe/helix-deploy');
|
|
53
|
-
* const { main } = require('../src/index.js');
|
|
54
|
-
*
|
|
55
|
-
* async function run() {
|
|
56
|
-
* const devServer = await new DevelopmentServer(main).init();
|
|
57
|
-
* await devServer.start();
|
|
58
|
-
* }
|
|
59
|
-
*
|
|
60
|
-
* run().then(process.stdout).catch(process.stderr);
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @type {DevelopmentServer}
|
|
64
|
-
*/
|
|
65
|
-
export default class DevelopmentServer {
|
|
66
|
-
/**
|
|
67
|
-
* Creates a new development server using the given universal function.
|
|
68
|
-
* @param {UniversalFunction} main - The universal function
|
|
69
|
-
*/
|
|
70
|
-
constructor(main) {
|
|
71
|
-
this._main = main;
|
|
72
|
-
this._cwd = process.cwd();
|
|
73
|
-
this._port = process.env.WEBSERVER_PORT || 3000;
|
|
74
|
-
this._headers = {};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
withPort(value) {
|
|
78
|
-
this._port = value;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
withXFH(value) {
|
|
83
|
-
process.emitWarning('DevelopmentServer.withXFH is deprecated. Use withHeader(\'x-forwarded-host\') instead.', 'DeprecationWarning');
|
|
84
|
-
this._headers['x-forwarded-host'] = value;
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
withHeader(name, value) {
|
|
89
|
-
this._headers[name] = value;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
withDirectory(value) {
|
|
94
|
-
this._cwd = value;
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get port() {
|
|
99
|
-
return this._port;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Initializes the development server.
|
|
104
|
-
* It uses the `wsk.package.params-file` and `wsk.params-file` to read the environment for
|
|
105
|
-
* the action params.
|
|
106
|
-
*
|
|
107
|
-
* @returns this
|
|
108
|
-
*/
|
|
109
|
-
async init() {
|
|
110
|
-
// load the action params
|
|
111
|
-
let pkgJson = {};
|
|
112
|
-
try {
|
|
113
|
-
pkgJson = await fse.readJson(path.resolve(this._cwd, 'package.json'));
|
|
114
|
-
} catch (e) {
|
|
115
|
-
// ignore
|
|
116
|
-
}
|
|
117
|
-
const config = new BaseConfig();
|
|
118
|
-
if (pkgJson.wsk) {
|
|
119
|
-
const withParamsFile = async (file) => {
|
|
120
|
-
if (!file) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
// eslint-disable-next-line no-param-reassign
|
|
124
|
-
const files = (Array.isArray(file) ? file : [file]).map((f) => path.resolve(this._cwd, f));
|
|
125
|
-
await Promise.all(files.map(async (f) => {
|
|
126
|
-
if (await fse.exists(f)) {
|
|
127
|
-
config.withParamsFile(f);
|
|
128
|
-
}
|
|
129
|
-
}));
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
await withParamsFile(pkgJson.wsk?.package?.['params-file']);
|
|
133
|
-
config.withParams(pkgJson.wsk?.package?.params);
|
|
134
|
-
await withParamsFile(pkgJson.wsk?.['params-file']);
|
|
135
|
-
config.withParams(pkgJson.wsk?.params);
|
|
136
|
-
await withParamsFile(pkgJson.wsk?.dev?.['params-file']);
|
|
137
|
-
config.withParams(pkgJson.wsk?.dev?.params);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const builder = new ActionBuilder().withConfig(config);
|
|
141
|
-
await builder.validate();
|
|
142
|
-
|
|
143
|
-
const region = process.env.AWS_REGION ?? 'us-east-1';
|
|
144
|
-
const accountId = process.env.AWS_ACCOUNT_ID ?? 'no-account';
|
|
145
|
-
|
|
146
|
-
const adapter = createAdapter({
|
|
147
|
-
factory: () => (req, ctx) => {
|
|
148
|
-
ctx.runtime.name = 'simulate';
|
|
149
|
-
return this._main(req, ctx);
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
this._handler = async (req, res) => {
|
|
153
|
-
const [rawPath, ...rest] = req.originalUrl.split('?');
|
|
154
|
-
const rawQueryString = rest.join('?');
|
|
155
|
-
const method = req.headers['x-http-method'] || req.method;
|
|
156
|
-
const event = {
|
|
157
|
-
body: req.rawBody,
|
|
158
|
-
headers: req.headers,
|
|
159
|
-
pathParameters: {
|
|
160
|
-
path: rawPath.substring(1),
|
|
161
|
-
},
|
|
162
|
-
requestContext: {
|
|
163
|
-
domainName: req.hostname,
|
|
164
|
-
http: {
|
|
165
|
-
method,
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
rawPath,
|
|
169
|
-
rawQueryString,
|
|
170
|
-
};
|
|
171
|
-
const context = {
|
|
172
|
-
awsRequestId: crypto.randomUUID(),
|
|
173
|
-
invokedFunctionArn: `arn:aws:lambda:${region}:${accountId}:function:${config.name}:${config.version}`,
|
|
174
|
-
getRemainingTimeInMillis: () => 60000,
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const {
|
|
178
|
-
statusCode,
|
|
179
|
-
headers,
|
|
180
|
-
isBase64Encoded,
|
|
181
|
-
body,
|
|
182
|
-
} = await adapter(event, context);
|
|
183
|
-
|
|
184
|
-
res.status(statusCode);
|
|
185
|
-
Object.entries(headers).forEach(([name, value]) => res.set(name, value));
|
|
186
|
-
res.send(isBase64Encoded ? Buffer.from(body, 'base64') : body);
|
|
187
|
-
};
|
|
188
|
-
this.params = config.params;
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Starts the development server
|
|
194
|
-
* @returns {Promise<void>}
|
|
195
|
-
*/
|
|
196
|
-
async start() {
|
|
197
|
-
Object.entries(this.params).forEach(([key, value]) => {
|
|
198
|
-
if (!(key in process.env)) {
|
|
199
|
-
process.env[key] = value;
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
this.app = express();
|
|
203
|
-
await new Promise((resolve, reject) => {
|
|
204
|
-
try {
|
|
205
|
-
this.server = this.app.listen(this._port, () => {
|
|
206
|
-
this._port = this.server.address().port;
|
|
207
|
-
// eslint-disable-next-line no-console
|
|
208
|
-
console.log(`Started development server at http://localhost:${this._port}/`);
|
|
209
|
-
resolve();
|
|
210
|
-
});
|
|
211
|
-
} catch (e) {
|
|
212
|
-
reject(e);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
this.app.use(rawBody());
|
|
216
|
-
Object.entries(this._headers).forEach(([name, value]) => {
|
|
217
|
-
this.app.use(addRequestHeader(name, value.replace('{port}', this._port)));
|
|
218
|
-
});
|
|
219
|
-
this.app.all('*', this._handler);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Stops the development server.
|
|
224
|
-
* @returns {Promise<void>}
|
|
225
|
-
*/
|
|
226
|
-
async stop() {
|
|
227
|
-
return new Promise((resolve, reject) => {
|
|
228
|
-
this.server.close((err) => {
|
|
229
|
-
if (err) {
|
|
230
|
-
reject(err);
|
|
231
|
-
} else {
|
|
232
|
-
resolve();
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|