@nx/node 0.0.0-pr-30457-6a22ba8 → 0.0.0-pr-30516-94d09ba
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/package.json +7 -5
- package/src/generators/application/application.js +10 -3
- package/src/generators/e2e-project/e2e-project.js +2 -2
- package/src/generators/e2e-project/files/server/common/src/support/global-setup.ts__tmpl__ +6 -0
- package/src/generators/e2e-project/files/server/common/src/support/global-teardown.ts__tmpl__ +3 -0
- package/src/utils/kill-port.d.ts +7 -0
- package/src/utils/kill-port.js +36 -0
- package/src/utils/wait-for-port-open.d.ts +24 -0
- package/src/utils/wait-for-port-open.js +47 -0
- package/utils.d.ts +2 -0
- package/utils.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/node",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-30516-94d09ba",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Node Plugin for Nx contains generators to manage Node applications within an Nx workspace.",
|
|
6
6
|
"repository": {
|
|
@@ -32,10 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"tslib": "^2.3.0",
|
|
35
|
-
"@nx/devkit": "0.0.0-pr-
|
|
36
|
-
"@nx/jest": "0.0.0-pr-
|
|
37
|
-
"@nx/js": "0.0.0-pr-
|
|
38
|
-
"@nx/eslint": "0.0.0-pr-
|
|
35
|
+
"@nx/devkit": "0.0.0-pr-30516-94d09ba",
|
|
36
|
+
"@nx/jest": "0.0.0-pr-30516-94d09ba",
|
|
37
|
+
"@nx/js": "0.0.0-pr-30516-94d09ba",
|
|
38
|
+
"@nx/eslint": "0.0.0-pr-30516-94d09ba",
|
|
39
|
+
"tcp-port-used": "^1.0.2",
|
|
40
|
+
"kill-port": "^1.6.1"
|
|
39
41
|
},
|
|
40
42
|
"publishConfig": {
|
|
41
43
|
"access": "public"
|
|
@@ -78,6 +78,7 @@ function getEsBuildConfig(project, options) {
|
|
|
78
78
|
}
|
|
79
79
|
function getServeConfig(options) {
|
|
80
80
|
return {
|
|
81
|
+
continuous: true,
|
|
81
82
|
executor: '@nx/js:node',
|
|
82
83
|
defaultConfiguration: 'development',
|
|
83
84
|
// Run build, which includes dependency on "^build" by default, so the first run
|
|
@@ -194,10 +195,16 @@ function addAppFiles(tree, options) {
|
|
|
194
195
|
}
|
|
195
196
|
function addProxy(tree, options) {
|
|
196
197
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.frontendProject);
|
|
197
|
-
if (projectConfig.targets &&
|
|
198
|
+
if (projectConfig.targets &&
|
|
199
|
+
['serve', 'dev'].find((t) => !!projectConfig.targets[t])) {
|
|
200
|
+
const targetName = ['serve', 'dev'].find((t) => !!projectConfig.targets[t]);
|
|
201
|
+
projectConfig.targets[targetName].dependsOn = [
|
|
202
|
+
...(projectConfig.targets[targetName].dependsOn ?? []),
|
|
203
|
+
`${options.name}:serve`,
|
|
204
|
+
];
|
|
198
205
|
const pathToProxyFile = `${projectConfig.root}/proxy.conf.json`;
|
|
199
|
-
projectConfig.targets.
|
|
200
|
-
...projectConfig.targets.
|
|
206
|
+
projectConfig.targets[targetName].options = {
|
|
207
|
+
...projectConfig.targets[targetName].options,
|
|
201
208
|
proxyConfig: pathToProxyFile,
|
|
202
209
|
};
|
|
203
210
|
if (!tree.exists(pathToProxyFile)) {
|
|
@@ -45,7 +45,7 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
|
45
45
|
jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
|
|
46
46
|
passWithNoTests: true,
|
|
47
47
|
},
|
|
48
|
-
dependsOn: [`${options.project}:build`],
|
|
48
|
+
dependsOn: [`${options.project}:build`, `${options.project}:serve`],
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
};
|
|
@@ -63,7 +63,7 @@ async function e2eProjectGeneratorInternal(host, _options) {
|
|
|
63
63
|
jestConfig: `${options.e2eProjectRoot}/jest.config.ts`,
|
|
64
64
|
passWithNoTests: true,
|
|
65
65
|
},
|
|
66
|
-
dependsOn: [`${options.project}:build`],
|
|
66
|
+
dependsOn: [`${options.project}:build`, `${options.project}:serve`],
|
|
67
67
|
},
|
|
68
68
|
},
|
|
69
69
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { waitForPortOpen } from '@nx/node/utils';
|
|
2
|
+
|
|
1
3
|
/* eslint-disable */
|
|
2
4
|
var __TEARDOWN_MESSAGE__: string;
|
|
3
5
|
|
|
@@ -5,6 +7,10 @@ module.exports = async function() {
|
|
|
5
7
|
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
|
|
6
8
|
console.log('\nSetting up...\n');
|
|
7
9
|
|
|
10
|
+
const host = process.env.HOST ?? 'localhost';
|
|
11
|
+
const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>;
|
|
12
|
+
await waitForPortOpen(port, { host });
|
|
13
|
+
|
|
8
14
|
// Hint: Use `globalThis` to pass variables to global teardown.
|
|
9
15
|
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
|
|
10
16
|
};
|
package/src/generators/e2e-project/files/server/common/src/support/global-teardown.ts__tmpl__
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { killPort } from '@nx/node/utils';
|
|
1
2
|
/* eslint-disable */
|
|
2
3
|
|
|
3
4
|
module.exports = async function() {
|
|
4
5
|
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
|
|
5
6
|
// Hint: `globalThis` is shared between setup and teardown.
|
|
7
|
+
const port = process.env.PORT ? Number(process.env.PORT) : <%= port %>;
|
|
8
|
+
await killPort(port);
|
|
6
9
|
console.log(globalThis.__TEARDOWN_MESSAGE__);
|
|
7
10
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kill = void 0;
|
|
4
|
+
exports.killPort = killPort;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const tcp_port_used_1 = require("tcp-port-used");
|
|
7
|
+
exports.kill = require('kill-port');
|
|
8
|
+
/**
|
|
9
|
+
* Kills the process on the given port
|
|
10
|
+
* @param port
|
|
11
|
+
* @param killPortDelay
|
|
12
|
+
*/
|
|
13
|
+
async function killPort(port, killPortDelay = 2500) {
|
|
14
|
+
if (await (0, tcp_port_used_1.check)(port)) {
|
|
15
|
+
let killPortResult;
|
|
16
|
+
try {
|
|
17
|
+
devkit_1.logger.info(`Attempting to close port ${port}`);
|
|
18
|
+
killPortResult = await (0, exports.kill)(port);
|
|
19
|
+
await new Promise((resolve) => setTimeout(() => resolve(), killPortDelay));
|
|
20
|
+
if (await (0, tcp_port_used_1.check)(port)) {
|
|
21
|
+
devkit_1.logger.error(`Port ${port} still open ${JSON.stringify(killPortResult)}`);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
devkit_1.logger.info(`Port ${port} successfully closed`);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
devkit_1.logger.error(`Port ${port} closing failed`);
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface WaitForPortOpenOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The host to connect to
|
|
4
|
+
* @default 'localhost'
|
|
5
|
+
*/
|
|
6
|
+
host?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The number of retries to attempt
|
|
9
|
+
* @default 120
|
|
10
|
+
*/
|
|
11
|
+
retries?: number;
|
|
12
|
+
/**
|
|
13
|
+
* The delay between retries
|
|
14
|
+
* @default 1000
|
|
15
|
+
*/
|
|
16
|
+
retryDelay?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Waits for the given port to be open
|
|
20
|
+
* @param port
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
export declare function waitForPortOpen(port: number, options?: WaitForPortOpenOptions): Promise<void>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForPortOpen = waitForPortOpen;
|
|
4
|
+
const net = require("net");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
/**
|
|
7
|
+
* Waits for the given port to be open
|
|
8
|
+
* @param port
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
function waitForPortOpen(port, options = {}) {
|
|
12
|
+
const host = options.host ?? 'localhost';
|
|
13
|
+
const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET', 'ETIMEDOUT'];
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const checkPort = (retries = options.retries ?? 120) => {
|
|
16
|
+
const client = new net.Socket();
|
|
17
|
+
const cleanupClient = () => {
|
|
18
|
+
client.removeAllListeners('connect');
|
|
19
|
+
client.removeAllListeners('error');
|
|
20
|
+
client.end();
|
|
21
|
+
client.destroy();
|
|
22
|
+
client.unref();
|
|
23
|
+
};
|
|
24
|
+
client.once('connect', () => {
|
|
25
|
+
cleanupClient();
|
|
26
|
+
resolve();
|
|
27
|
+
});
|
|
28
|
+
client.once('error', (err) => {
|
|
29
|
+
if (retries === 0 || !allowedErrorCodes.includes(err['code'])) {
|
|
30
|
+
if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
|
|
31
|
+
devkit_1.logger.info(`Error connecting on ${host}:${port}: ${err['code'] || err}`);
|
|
32
|
+
}
|
|
33
|
+
cleanupClient();
|
|
34
|
+
reject(err);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
setTimeout(() => checkPort(retries - 1), options.retryDelay ?? 1000);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (process.env['NX_VERBOSE_LOGGING'] === 'true') {
|
|
41
|
+
devkit_1.logger.info(`Connecting on ${host}:${port}`);
|
|
42
|
+
}
|
|
43
|
+
client.connect({ port, host });
|
|
44
|
+
};
|
|
45
|
+
checkPort();
|
|
46
|
+
});
|
|
47
|
+
}
|
package/utils.d.ts
ADDED
package/utils.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.killPort = exports.waitForPortOpen = void 0;
|
|
4
|
+
var wait_for_port_open_1 = require("./src/utils/wait-for-port-open");
|
|
5
|
+
Object.defineProperty(exports, "waitForPortOpen", { enumerable: true, get: function () { return wait_for_port_open_1.waitForPortOpen; } });
|
|
6
|
+
var kill_port_1 = require("./src/utils/kill-port");
|
|
7
|
+
Object.defineProperty(exports, "killPort", { enumerable: true, get: function () { return kill_port_1.killPort; } });
|