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 08689b0 commit 6d9c86d
Show file tree
Hide file tree
Showing 58 changed files with 884 additions and 588 deletions.
135 changes: 135 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,28 @@ of the dependencies for the Module Federation build.

---

### combineAsyncIterableIterators

**combineAsyncIterableIterators**<`T`\>(...`iterators`): `AsyncIterableIterator`<`T`\>

#### Type parameters

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

#### Parameters

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

#### Returns

`AsyncIterableIterator`<`T`\>

---

### convertNxExecutor

**convertNxExecutor**(`executor`): `any`
Expand Down Expand Up @@ -1062,6 +1089,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 +1213,42 @@ 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 file system tree |
| `pkg` | `string` | the package to check (e.g. @nrwl/jest) |
| `requiredVersion` | `string` | the version to check |
| `options` | `Object` | |
| `options.cwd?` | `string` | - |
| `options.dev?` | `boolean` | - |
| `options.packageJsonPath?` | `string` | - |
| `options.packageManager?` | `"yarn"` \| `"pnpm"` \| `"npm"` | - |
| `options.throwOnMissing?` | `boolean` | - |

#### Returns

`Promise`<`void`\>

---

### extractLayoutDirectory

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

---

### mapAsyncIterable

**mapAsyncIterable**<`T`, `I`, `O`\>(`data`, `transform`): `AsyncIterable`<`O`\> \| `AsyncIterableIterator`<`O`\>

#### 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

`AsyncIterable`<`O`\> \| `AsyncIterableIterator`<`O`\>

---

### mapRemotes

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

---

### tapAsyncIterable

**tapAsyncIterable**<`T`, `I`, `O`\>(`data`, `fn`): `AsyncIterable`<`T`\> \| `AsyncIterableIterator`<`T`\>

#### Type parameters

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

#### Parameters

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

#### Returns

`AsyncIterable`<`T`\> \| `AsyncIterableIterator`<`T`\>

---

### 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
@@ -1,6 +1,6 @@
export async function* combineAsyncIterableIterators(
...iterators: { 0: AsyncIterableIterator<any> } & AsyncIterableIterator<any>[]
) {
export async function* combineAsyncIterableIterators<T = any>(
...iterators: { 0: AsyncIterableIterator<T> } & AsyncIterableIterator<T>[]
): AsyncGenerator<T> {
let [options] = iterators;
if (typeof options.next === 'function') {
options = Object.create(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function* mapAsyncIterable<T = any, I = any, O = any>(
index?: number,
data?: AsyncIterable<T> | AsyncIterableIterator<T>
) => O
) {
): AsyncIterable<O> | AsyncIterableIterator<O> {
async function* f() {
const generator = data[Symbol.asyncIterator] || data[Symbol.iterator];
const iterator = generator.call(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tapAsyncIterator } from './tap-async-iteratable';
import { tapAsyncIterable } from './tap-async-iteratable';

describe('tapAsyncIterator', () => {
it('should tap values', async () => {
Expand All @@ -11,7 +11,7 @@ describe('tapAsyncIterator', () => {
const tapped = [];
const results = [];

const c = tapAsyncIterator(f(), (x) => {
const c = tapAsyncIterable(f(), (x) => {
tapped.push(`tap: ${x}`);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { mapAsyncIterable } from './map-async-iteratable';

export async function* tapAsyncIterator<T = any, I = any, O = any>(
export async function* tapAsyncIterable<T = any, I = any, O = any>(
data: AsyncIterable<T> | AsyncIterableIterator<T>,
fn: (input: I) => void
) {
): AsyncIterable<T> | AsyncIterableIterator<T> {
return yield* mapAsyncIterable(data, (x) => {
fn(x);
return x;
Expand Down
30 changes: 29 additions & 1 deletion packages/devkit/src/utils/package-json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Tree } from 'nx/src/generators/tree';
import { readJson, writeJson } from 'nx/src/generators/utils/json';
import { addDependenciesToPackageJson } from './package-json';
import { addDependenciesToPackageJson, ensurePackage } from './package-json';
import { createTree } from 'nx/src/generators/testing-utils/create-tree';

describe('addDependenciesToPackageJson', () => {
Expand Down Expand Up @@ -310,3 +310,31 @@ describe('addDependenciesToPackageJson', () => {
expect(installTask).toBeDefined();
});
});

describe('ensureDependencies', () => {
let tree: Tree;

beforeEach(() => {
tree = createTree();
});

it('should throw when dependencies are missing', async () => {
writeJson(tree, 'package.json', {});

await expect(() =>
ensurePackage(tree, '@nrwl/webpack', '1.0.0', {
dev: true,
packageManager: 'npm',
throwOnMissing: true,
})
).rejects.toThrow('npm install -D @nrwl/[email protected]');

await expect(() =>
ensurePackage(tree, 'tslib', '2.4.0', {
dev: false,
packageManager: 'npm',
throwOnMissing: true,
})
).rejects.toThrow('npm install [email protected]');
});
});
Loading

0 comments on commit 6d9c86d

Please sign in to comment.