Skip to content

Commit

Permalink
chore(repo): debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed May 23, 2023
1 parent 982b796 commit 05f3820
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
NX_E2E_CI_CACHE_KEY: e2e-circleci-<< parameters.os >>
SELECTED_PM: << parameters.pm >>
NX_E2E_RUN_CYPRESS: 'true'
NX_VERBOSE_LOGGING: 'false'
NX_VERBOSE_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
steps:
- run:
Expand All @@ -151,7 +151,7 @@ jobs:
executor: linux
environment:
NX_E2E_CI_CACHE_KEY: e2e-circleci-linux
NX_VERBOSE_LOGGING: 'false'
NX_VERBOSE_LOGGING: 'true'
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'false'
steps:
Expand Down
4 changes: 2 additions & 2 deletions nx-dev/nx-dev-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"e2e": {
"dependsOn": [
{
"target": "build-base",
"dependencies": true
"dependencies": true,
"target": "build-base"
}
],
"executor": "@nx/cypress:cypress",
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@
"depcheck",
"documentation"
]
},
"pnpm": {
"patchedDependencies": {
"@nx/[email protected]": "patches/@[email protected]",
"@nx/[email protected]": "patches/@[email protected]"
}
}
}

7 changes: 7 additions & 0 deletions packages/cypress/src/executors/cypress/cypress.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,25 @@ export default async function cypressExecutor(

for await (const devServerValues of devServerIter) {
try {
console.log('Running Cypress...');
success = await runCypress(devServerValues.baseUrl, {
...options,
portLockFilePath: devServerValues.portLockFilePath,
});
console.log('Cypress finished', { success });
if (!options.watch) {
console.log('Cypress tests finished, trying to exit the dev server');
devServerIter.return();
break;
}
} catch (e) {
logger.error(e.message);
success = false;
if (!options.watch) {
console.log(
'Cypress tests finished with error, trying to exit the dev server',
e
);
devServerIter.return();
break;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/next/src/executors/server/server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async function* serveExecutor(
// Client to check if server is ready.
const client = new net.Socket();
const cleanupClient = () => {
console.log('cleanupClient');
client.removeAllListeners('connect');
client.removeAllListeners('error');
client.end();
Expand All @@ -62,9 +63,11 @@ export default async function* serveExecutor(
};

const waitForServerReady = (retries = 30) => {
console.log('waitForServerReady', retries);
const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET'];

client.once('connect', () => {
console.log('connect');
cleanupClient();
next({
success: true,
Expand All @@ -73,17 +76,21 @@ export default async function* serveExecutor(
});

client.on('error', (err) => {
console.log('error', err);
if (retries === 0 || !allowedErrorCodes.includes(err['code'])) {
console.log('actual error');
cleanupClient();
error(err);
} else {
console.log('retrying', retries);
setTimeout(() => waitForServerReady(retries - 1), 1000);
}
});

client.connect({ port, host: '127.0.0.1' });
};

console.log('spawning', command);
const server = spawn(command, {
cwd: options.dev ? root : nextDir,
stdio: 'inherit',
Expand All @@ -93,6 +100,7 @@ export default async function* serveExecutor(
waitForServerReady();

server.once('exit', (code) => {
console.log('server exit', code);
cleanupClient();
if (code === 0) {
done();
Expand All @@ -102,6 +110,7 @@ export default async function* serveExecutor(
});

process.on('exit', async (code) => {
console.log('process exit', code);
if (code === 128 + 2) {
server.kill('SIGINT');
} else if (code === 128 + 1) {
Expand Down
32 changes: 32 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/src/utils/async-iterable/create-async-iterable.js b/src/utils/async-iterable/create-async-iterable.js
index fa52c15f2dd6d19178d8df77e26d8703987f29c7..304d6f1d2d0b8abe590c91b3b9d53c9461d57334 100644
--- a/src/utils/async-iterable/create-async-iterable.js
+++ b/src/utils/async-iterable/create-async-iterable.js
@@ -35,22 +35,27 @@ function createAsyncIterable(listener) {
(_a = pullQueue.shift()) === null || _a === void 0 ? void 0 : _a[0]({ value: undefined, done: true });
}
done = true;
+ console.log('createAsyncIterable done was called', {done, error, pushQueue, pullQueue});
},
});
return {
next() {
return new Promise((resolve, reject) => {
if (pushQueue.length > 0) {
+ console.log('createAsyncIterable resolving next pushQueue item', {done, error, pushQueue, pullQueue});
resolve({ value: pushQueue.shift(), done: false });
}
else if (done) {
+ console.log('createAsyncIterable resolving done', {done, error, pushQueue, pullQueue});
resolve({ value: undefined, done: true });
}
else if (error) {
+ console.log('createAsyncIterable rejecting error', {done, error, pushQueue, pullQueue});
reject(error);
}
else {
pullQueue.push([resolve, reject]);
+ console.log('createAsyncIterable adding to pullQueue', {done, error, pushQueue, pullQueue});
}
});
},
174 changes: 174 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
diff --git a/src/executors/server/server.impl.js b/src/executors/server/server.impl.js
index 9f5b4e742a3f1f0c5a2687187cad8983908cba97..15229397e77c39c9cab0916cf1d65243ba95ed32 100644
--- a/src/executors/server/server.impl.js
+++ b/src/executors/server/server.impl.js
@@ -10,85 +10,91 @@ const custom_server_impl_1 = require("./custom-server.impl");
const create_cli_options_1 = require("../../utils/create-cli-options");
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
function serveExecutor(options, context) {
- return tslib_1.__asyncGenerator(this, arguments, function* serveExecutor_1() {
- if (options.customServerTarget) {
- return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, custom_server_impl_1.default)(options, context)))));
+ return tslib_1.__asyncGenerator(this, arguments, function* serveExecutor_1() {
+ if (options.customServerTarget) {
+ return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, custom_server_impl_1.default)(options, context)))));
+ }
+ // Cast to any to overwrite NODE_ENV
+ process.env.NODE_ENV = process.env.NODE_ENV
+ ? process.env.NODE_ENV
+ : options.dev
+ ? 'development'
+ : 'production';
+ // Setting port that the custom server should use.
+ process.env.PORT = options.port;
+ const buildOptions = (0, devkit_1.readTargetOptions)((0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph), context);
+ const root = (0, path_1.resolve)(context.root, buildOptions.root);
+ const { port, keepAliveTimeout, hostname } = options;
+ const args = (0, create_cli_options_1.createCliOptions)({ port, keepAliveTimeout, hostname });
+ const nextDir = (0, path_1.resolve)(context.root, buildOptions.outputPath);
+ const mode = options.dev ? 'dev' : 'start';
+ const turbo = options.turbo && options.dev ? '--turbo' : '';
+ const command = `npx next ${mode} ${args} ${turbo}`;
+ yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ done, next, error }) => {
+ // Client to check if server is ready.
+ const client = new net.Socket();
+ const cleanupClient = () => {
+ client.removeAllListeners('connect');
+ client.removeAllListeners('error');
+ client.end();
+ client.destroy();
+ client.unref();
+ console.log('client cleaned up')
+ };
+ const waitForServerReady = (retries = 30) => {
+ const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET'];
+ client.once('connect', () => {
+ var _a;
+ cleanupClient();
+ next({
+ success: true,
+ baseUrl: `http://${(_a = options.hostname) !== null && _a !== void 0 ? _a : 'localhost'}:${port}`,
+ });
+ });
+ client.on('error', (err) => {
+ if (retries === 0 || !allowedErrorCodes.includes(err['code'])) {
+ cleanupClient();
+ error(err);
+ }
+ else {
+ setTimeout(() => waitForServerReady(retries - 1), 1000);
+ }
+ });
+ client.connect({ port, host: '127.0.0.1' });
+ };
+ const server = (0, child_process_1.spawn)(command, {
+ cwd: options.dev ? root : nextDir,
+ stdio: 'inherit',
+ shell: true,
+ });
+ waitForServerReady();
+ server.once('exit', (code) => {
+ console.log('calling done in server exit')
+ cleanupClient();
+ if (code === 0) {
+ done();
}
- // Cast to any to overwrite NODE_ENV
- process.env.NODE_ENV = process.env.NODE_ENV
- ? process.env.NODE_ENV
- : options.dev
- ? 'development'
- : 'production';
- // Setting port that the custom server should use.
- process.env.PORT = options.port;
- const buildOptions = (0, devkit_1.readTargetOptions)((0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph), context);
- const root = (0, path_1.resolve)(context.root, buildOptions.root);
- const { port, keepAliveTimeout, hostname } = options;
- const args = (0, create_cli_options_1.createCliOptions)({ port, keepAliveTimeout, hostname });
- const nextDir = (0, path_1.resolve)(context.root, buildOptions.outputPath);
- const mode = options.dev ? 'dev' : 'start';
- const turbo = options.turbo && options.dev ? '--turbo' : '';
- const command = `npx next ${mode} ${args} ${turbo}`;
- yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ done, next, error }) => {
- // Client to check if server is ready.
- const client = new net.Socket();
- const cleanupClient = () => {
- client.removeAllListeners('connect');
- client.removeAllListeners('error');
- client.end();
- client.destroy();
- client.unref();
- };
- const waitForServerReady = (retries = 30) => {
- const allowedErrorCodes = ['ECONNREFUSED', 'ECONNRESET'];
- client.once('connect', () => {
- var _a;
- cleanupClient();
- next({
- success: true,
- baseUrl: `http://${(_a = options.hostname) !== null && _a !== void 0 ? _a : 'localhost'}:${port}`,
- });
- });
- client.on('error', (err) => {
- if (retries === 0 || !allowedErrorCodes.includes(err['code'])) {
- cleanupClient();
- error(err);
- }
- else {
- setTimeout(() => waitForServerReady(retries - 1), 1000);
- }
- });
- client.connect({ port, host: '127.0.0.1' });
- };
- const server = (0, child_process_1.spawn)(command, {
- cwd: options.dev ? root : nextDir,
- stdio: 'inherit',
- shell: true,
- });
- waitForServerReady();
- server.once('exit', (code) => {
- cleanupClient();
- if (code === 0) {
- done();
- }
- else {
- error(new Error(`Next.js app exited with code ${code}`));
- }
- });
- process.on('exit', (code) => tslib_1.__awaiter(this, void 0, void 0, function* () {
- if (code === 128 + 2) {
- server.kill('SIGINT');
- }
- else if (code === 128 + 1) {
- server.kill('SIGHUP');
- }
- else {
- server.kill('SIGTERM');
- }
- }));
- }))));
- });
+ else {
+ error(new Error(`Next.js app exited with code ${code}`));
+ }
+ });
+ process.on('exit', (code) => {
+ if (code === 128 + 2) {
+ server.kill('SIGINT');
+ }
+ else if (code === 128 + 1) {
+ server.kill('SIGHUP');
+ }
+ else {
+ server.kill('SIGTERM');
+ }
+ console.log('calling done in process exit')
+ cleanupClient();
+ done();
+ console.log('done called in process exit')
+ });
+ }))));
+ });
}
exports.default = serveExecutor;
//# sourceMappingURL=server.impl.js.map
Loading

0 comments on commit 05f3820

Please sign in to comment.