-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
982b796
commit 05f3820
Showing
8 changed files
with
259 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,6 +350,11 @@ | |
"depcheck", | ||
"documentation" | ||
] | ||
}, | ||
"pnpm": { | ||
"patchedDependencies": { | ||
"@nx/[email protected]": "patches/@[email protected]", | ||
"@nx/[email protected]": "patches/@[email protected]" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} | ||
}); | ||
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.