-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): add nx.server.ready message from Node process to any pot…
…ential parent process (#13808)
- Loading branch information
Showing
19 changed files
with
285 additions
and
68 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
146 changes: 146 additions & 0 deletions
146
packages/devkit/src/utils/async-iterable/combine-async-iterables.spec.ts
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,146 @@ | ||
import { combineAsyncIterables } from './combine-async-iterables'; | ||
import { createAsyncIterable } from './create-async-iterable'; | ||
|
||
function delay(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
describe('combineAsyncIterables', () => { | ||
it('should combine generators', async () => { | ||
async function* a() { | ||
await delay(20); | ||
yield 'a'; | ||
} | ||
|
||
async function* b() { | ||
await delay(0); | ||
yield 'b'; | ||
} | ||
|
||
const c = combineAsyncIterables(a(), b()); | ||
const results = []; | ||
|
||
for await (const x of c) { | ||
results.push(x); | ||
} | ||
|
||
expect(results).toEqual(['b', 'a']); | ||
}); | ||
|
||
it('should support .throw()', async () => { | ||
async function* a() { | ||
yield 1; | ||
yield 2; | ||
} | ||
|
||
async function* b() { | ||
yield 3; | ||
yield 4; | ||
} | ||
|
||
const c = combineAsyncIterables(a(), b()); | ||
const results = []; | ||
|
||
try { | ||
for await (const x of c) { | ||
results.push(x); | ||
await c.throw(new Error('oops')); | ||
} | ||
} catch (e) { | ||
expect(e.message).toMatch(/oops/); | ||
expect(results).toEqual([1]); | ||
} | ||
}); | ||
|
||
it('should support .return()', async () => { | ||
async function* a() { | ||
yield 1; | ||
yield 2; | ||
} | ||
|
||
async function* b() { | ||
yield 3; | ||
yield 4; | ||
} | ||
|
||
const c = combineAsyncIterables(a(), b()); | ||
const results = []; | ||
|
||
for await (const x of c) { | ||
results.push(x); | ||
const { value: y } = await c.return(10); | ||
results.push(y); | ||
} | ||
|
||
expect(results).toEqual([1, 10]); | ||
}); | ||
|
||
it('should throw when one generator throws', async () => { | ||
async function* a() { | ||
await delay(20); | ||
yield 'a'; | ||
} | ||
|
||
async function* b() { | ||
throw new Error('threw in b'); | ||
} | ||
|
||
const c = combineAsyncIterables(a(), b()); | ||
|
||
async function* d() { | ||
yield* c; | ||
} | ||
|
||
try { | ||
for await (const x of d()) { | ||
} | ||
throw new Error('should not reach here'); | ||
} catch (e) { | ||
expect(e.message).toMatch(/threw in b/); | ||
} | ||
}); | ||
|
||
it('should combine async iterables', async () => { | ||
const a = createAsyncIterable<number>(({ next, done }) => { | ||
next(1); | ||
next(2); | ||
next(3); | ||
done(); | ||
}); | ||
const b = createAsyncIterable<number>(({ next, done }) => { | ||
next(4); | ||
next(5); | ||
next(6); | ||
done(); | ||
}); | ||
|
||
const c = combineAsyncIterables(a, b); | ||
|
||
const results: number[] = []; | ||
for await (const x of c) { | ||
results.push(x); | ||
} | ||
|
||
expect(results).toEqual([1, 4, 2, 5, 3, 6]); | ||
}); | ||
|
||
it('should throw error when an async iterable throws', async () => { | ||
const a = createAsyncIterable<number>(({ next, done }) => { | ||
next(1); | ||
done(); | ||
}); | ||
const b = createAsyncIterable<number>(({ next, done }) => { | ||
throw new Error('threw in b'); | ||
}); | ||
|
||
const c = combineAsyncIterables(a, b); | ||
|
||
try { | ||
for await (const _x of c) { | ||
// nothing | ||
} | ||
} catch (e) { | ||
expect(e.message).toMatch(/threw in b/); | ||
} | ||
}); | ||
}); |
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
53 changes: 0 additions & 53 deletions
53
packages/devkit/src/utils/async-iterable/combine-async-iteratables-iterators.spec.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './create-async-iterable'; | ||
export * from './combine-async-iteratable-iterators'; | ||
export * from './combine-async-iterables'; | ||
export * from './map-async-iteratable'; | ||
export * from './tap-async-iteratable'; |
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
28 changes: 28 additions & 0 deletions
28
packages/react/src/generators/host/files/module-federation-ssr/server.ts__tmpl__
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,28 @@ | ||
import * as path from 'path'; | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
|
||
import { handleRequest } from './src/main.server'; | ||
|
||
const port = process.env['PORT'] || 4200; | ||
const app = express(); | ||
|
||
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>'); | ||
const indexPath = path.join(browserDist, 'index.html'); | ||
|
||
app.use(cors()); | ||
|
||
app.get( | ||
'*.*', | ||
express.static(browserDist, { | ||
maxAge: '1y', | ||
}) | ||
); | ||
|
||
app.use('*', handleRequest(indexPath)); | ||
|
||
const server = app.listen(port, () => { | ||
console.log(`Express server listening on http://localhost:${port}`); | ||
}); | ||
|
||
server.on('error', console.error); |
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
36 changes: 36 additions & 0 deletions
36
packages/react/src/generators/remote/files/module-federation-ssr/server.ts__tmpl__
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,36 @@ | ||
import * as path from 'path'; | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
|
||
import { handleRequest } from './src/main.server'; | ||
|
||
const port = process.env['PORT'] || 4200; | ||
const app = express(); | ||
|
||
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>'); | ||
const indexPath = path.join(browserDist, 'index.html'); | ||
|
||
app.use(cors()); | ||
|
||
app.get( | ||
'*.*', | ||
express.static(browserDist, { | ||
maxAge: '1y', | ||
}) | ||
); | ||
|
||
app.use('*', handleRequest(indexPath)); | ||
|
||
const server = app.listen(port, () => { | ||
console.log(`Express server listening on http://localhost:${port}`); | ||
|
||
/** | ||
* DO NOT REMOVE IF USING @nrwl/react:module-federation-dev-ssr executor | ||
* to serve your Host application with this Remote application. | ||
* This message allows Nx to determine when the Remote is ready to be | ||
* consumed by the Host. | ||
*/ | ||
process.send?.('nx.server.ready'); | ||
}); | ||
|
||
server.on('error', console.error); |
Oops, something went wrong.
8df1834
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev