Skip to content

Commit

Permalink
feat(react): remove unnecessary dependencies from @nrwl/react
Browse files Browse the repository at this point in the history
- If Vite is used, then Webpack and Jest are not needed
- If e2e is not used, then Cypress is not needed
- Trims down on the amount of packages that are downloaded
  • Loading branch information
jaysoo authored and Jack Hsu committed Dec 1, 2022
1 parent 84cbcb7 commit 7a2a9b7
Show file tree
Hide file tree
Showing 40 changed files with 734 additions and 73 deletions.
131 changes: 131 additions & 0 deletions docs/generated/devkit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ It only uses language primitives and immutable objects
- [applyAdditionalShared](../../devkit/index#applyadditionalshared)
- [applyChangesToString](../../devkit/index#applychangestostring)
- [applySharedFunction](../../devkit/index#applysharedfunction)
- [combineAsyncIterableIterators](../../devkit/index#combineasynciterableiterators)
- [convertNxExecutor](../../devkit/index#convertnxexecutor)
- [convertNxGenerator](../../devkit/index#convertnxgenerator)
- [createAsyncIterable](../../devkit/index#createasynciterable)
- [createProjectGraphAsync](../../devkit/index#createprojectgraphasync)
- [defaultTasksRunner](../../devkit/index#defaulttasksrunner)
- [detectPackageManager](../../devkit/index#detectpackagemanager)
- [detectWorkspaceScope](../../devkit/index#detectworkspacescope)
- [ensurePackage](../../devkit/index#ensurepackage)
- [extractLayoutDirectory](../../devkit/index#extractlayoutdirectory)
- [formatFiles](../../devkit/index#formatfiles)
- [generateFiles](../../devkit/index#generatefiles)
Expand All @@ -162,6 +165,7 @@ It only uses language primitives and immutable objects
- [installPackagesTask](../../devkit/index#installpackagestask)
- [isStandaloneProject](../../devkit/index#isstandaloneproject)
- [joinPathFragments](../../devkit/index#joinpathfragments)
- [mapAsyncIterable](../../devkit/index#mapasynciterable)
- [mapRemotes](../../devkit/index#mapremotes)
- [mapRemotesForSSR](../../devkit/index#mapremotesforssr)
- [moveFilesToNewDirectory](../../devkit/index#movefilestonewdirectory)
Expand All @@ -188,6 +192,7 @@ It only uses language primitives and immutable objects
- [shareWorkspaceLibraries](../../devkit/index#shareworkspacelibraries)
- [stripIndents](../../devkit/index#stripindents)
- [stripJsonComments](../../devkit/index#stripjsoncomments)
- [tapAsyncIterable](../../devkit/index#tapasynciterable)
- [targetToTargetString](../../devkit/index#targettotargetstring)
- [toJS](../../devkit/index#tojs)
- [updateJson](../../devkit/index#updatejson)
Expand Down Expand Up @@ -992,6 +997,22 @@ of the dependencies for the Module Federation build.

---

### combineAsyncIterableIterators

**combineAsyncIterableIterators**(...`iterators`): `AsyncGenerator`<`any`, `void`, `unknown`\>

#### Parameters

| Name | Type |
| :------------- | :--------------------------------------------------------------------------- |
| `...iterators` | { `0`: `AsyncIterableIterator`<`any`\> } & `AsyncIterableIterator`<`any`\>[] |

#### Returns

`AsyncGenerator`<`any`, `void`, `unknown`\>

---

### convertNxExecutor

**convertNxExecutor**(`executor`): `any`
Expand Down Expand Up @@ -1062,6 +1083,28 @@ Convert an Nx Generator into an Angular Devkit Schematic.

---

### createAsyncIterable

**createAsyncIterable**<`T`\>(`listener`): `AsyncIterable`<`T`\>

#### Type parameters

| Name | Type |
| :--- | :-------- |
| `T` | `unknown` |

#### Parameters

| Name | Type |
| :--------- | :------------------------------------------- |
| `listener` | (`ls`: `AsyncPushCallbacks`<`T`\>) => `void` |

#### Returns

`AsyncIterable`<`T`\>

---

### createProjectGraphAsync

**createProjectGraphAsync**(`opts?`): `Promise`<[`ProjectGraph`](../../devkit/index#projectgraph)\>
Expand Down Expand Up @@ -1164,6 +1207,44 @@ Detect workspace scope from the package.json name

---

### ensurePackage

**ensurePackage**(`tree`, `pkg`, `requiredVersion`, `options?`): `Promise`<`void`\>

Ensure that dependencies and devDependencies from package.json are installed at the required versions.

For example:

```typescript
ensureDependencies(tree, {}, { '@nrwl/jest': nxVersion });
```

This will check that @nrwl/jest@<nxVersion> exists in devDependencies.
If it exists then function returns, otherwise it will install the package before continuing.
When running with --dryRun, the function will throw when dependencies are missing.

#### Parameters

| Name | Type | Description |
| :------------------------- | :-------------------------------- | :--------------------- |
| `tree` | [`Tree`](../../devkit/index#tree) | The Tree to check with |
| `pkg` | `string` | The package to check |
| `requiredVersion` | `string` | The version to check |
| `options` | `Object` | |
| `options.cwd?` | `string` | - |
| `options.dev?` | `boolean` | - |
| `options.dryRun?` | `boolean` | - |
| `options.packageJsonPath?` | `string` | - |
| `options.packageManager?` | `"yarn"` \| `"pnpm"` \| `"npm"` | - |

#### Returns

`Promise`<`void`\>

void

---

### extractLayoutDirectory

**extractLayoutDirectory**(`directory`): `Object`
Expand Down Expand Up @@ -1499,6 +1580,31 @@ Normalized path fragments and joins them

---

### mapAsyncIterable

**mapAsyncIterable**<`T`, `I`, `O`\>(`data`, `transform`): `AsyncGenerator`<`Awaited`<`O`\>, `void`, `unknown`\>

#### Type parameters

| Name | Type |
| :--- | :---- |
| `T` | `any` |
| `I` | `any` |
| `O` | `any` |

#### Parameters

| Name | Type |
| :---------- | :--------------------------------------------------------------------------------------------------------- |
| `data` | `AsyncIterable`<`T`\> \| `AsyncIterableIterator`<`T`\> |
| `transform` | (`input`: `I`, `index?`: `number`, `data?`: `AsyncIterable`<`T`\> \| `AsyncIterableIterator`<`T`\>) => `O` |

#### Returns

`AsyncGenerator`<`Awaited`<`O`\>, `void`, `unknown`\>

---

### mapRemotes

**mapRemotes**(`remotes`, `remoteEntryExt`, `determineRemoteUrl`): `Record`<`string`, `string`\>
Expand Down Expand Up @@ -2114,6 +2220,31 @@ of comments with a replaceCharacter

---

### tapAsyncIterable

**tapAsyncIterable**<`T`, `I`, `O`\>(`data`, `fn`): `AsyncGenerator`<`any`, `void`, `unknown`\>

#### Type parameters

| Name | Type |
| :--- | :---- |
| `T` | `any` |
| `I` | `any` |
| `O` | `any` |

#### Parameters

| Name | Type |
| :----- | :----------------------------------------------------- |
| `data` | `AsyncIterable`<`T`\> \| `AsyncIterableIterator`<`T`\> |
| `fn` | (`input`: `I`) => `void` |

#### Returns

`AsyncGenerator`<`any`, `void`, `unknown`\>

---

### targetToTargetString

**targetToTargetString**(`target`): `string`
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/packages/devkit.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions docs/generated/packages/webpack.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"description": "Init Webpack Plugin.",
"type": "object",
"properties": {
"uiFramework": {
"type": "string",
"description": "UI Framework to use for Vite.",
"enum": ["react", "none"],
"x-prompt": "What UI framework plugin should Webpack use?"
},
"compiler": {
"type": "string",
"enum": ["babel", "swc", "tsc"],
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["build/packages/*"],
"version": "15.2.0",
"version": "999999.0.217",
"granularPathspec": false,
"command": {
"publish": {
Expand Down
9 changes: 9 additions & 0 deletions packages/devkit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export { readJsonFile, writeJsonFile } from 'nx/src/utils/fileutils';
*/
export {
addDependenciesToPackageJson,
ensurePackage,
removeDependenciesFromPackageJson,
} from './src/utils/package-json';

Expand Down Expand Up @@ -357,6 +358,14 @@ export {
*/
export { Hash, Hasher } from 'nx/src/hasher/hasher';

/**
* @category Utils
*/
export { mapAsyncIterable } from './src/utils/async-iterable/map-async-iteratable';
export { tapAsyncIterable } from './src/utils/async-iterable/tap-async-iteratable';
export { combineAsyncIterableIterators } from './src/utils/async-iterable/combine-async-iteratable-iterators';
export { createAsyncIterable } from './src/utils/async-iterable/create-async-iterable';

/**
* @category Utils
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export async function* combineAsyncIterableIterators(
...iterators: { 0: AsyncIterableIterator<any> } & AsyncIterableIterator<any>[]
) {
let [options] = iterators;
if (typeof options.next === 'function') {
options = Object.create(null);
} else {
iterators.shift();
}

const getNextAsyncIteratorValue = getNextAsyncIteratorFactory(options);

try {
const asyncIteratorsValues = new Map(
iterators.map((it, idx) => [idx, getNextAsyncIteratorValue(it, idx)])
);

do {
const { iterator, index } = await Promise.race(
asyncIteratorsValues.values()
);
if (iterator.done) {
asyncIteratorsValues.delete(index);
} else {
yield iterator.value;
asyncIteratorsValues.set(
index,
getNextAsyncIteratorValue(iterators[index], index)
);
}
} while (asyncIteratorsValues.size > 0);
} finally {
await Promise.allSettled(iterators.map((it) => it.return()));
}
}

function getNextAsyncIteratorFactory(options) {
return async (asyncIterator, index) => {
try {
const iterator = await asyncIterator.next();

return { index, iterator };
} catch (err) {
if (options.errorCallback) {
options.errorCallback(err, index);
}
return Promise.reject(err);
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { combineAsyncIterableIterators } from './combine-async-iteratable-iterators';

function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

describe('combineAsyncIterators', () => {
it('should merge iterators', async () => {
async function* a() {
await delay(20);
yield 'a';
}

async function* b() {
await delay(0);
yield 'b';
}

const c = combineAsyncIterableIterators(a(), b());
const results = [];

for await (const x of c) {
results.push(x);
}

expect(results).toEqual(['b', 'a']);
});

it('should throw when one iterator throws', async () => {
async function* a() {
await delay(20);
yield 'a';
}

async function* b() {
throw new Error('threw in b');
}

const c = combineAsyncIterableIterators(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/);
}
});
});
Loading

0 comments on commit 7a2a9b7

Please sign in to comment.