Skip to content

Commit

Permalink
Merge branch 'master' into fixing-vue-homepages
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackDeRose authored Feb 16, 2024
2 parents c6177d0 + 90ba366 commit af69668
Show file tree
Hide file tree
Showing 27 changed files with 634 additions and 152 deletions.
28 changes: 28 additions & 0 deletions docs/changelog/18_0_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Nx 18

We were so excited about the features in Nx 18 that we created a whole [Launch Nx Week](https://nx.dev/launch-nx) to share our excitement with you. During the launch week, we made the following announcements:

- [Project Crystal](https://blog.nrwl.io/what-if-nx-plugins-were-more-like-vscode-extensions-dcdad140ae09?source=friends_link&sk=ade76fe8d50d44aafb4d4d89ab882e24&__hstc=221401095.5d21139e33f975ecef01c1783a7523db.1673975383152.1708023233215.1708026196201.468&__hssc=221401095.2.1708026196201&__hsfp=589919331) allows you to use inferred tasks
- A new [`@nx/nuxt`](https://blog.nrwl.io/introducing-nx-nuxt-enhanced-nuxt-js-support-in-nx-01eac78034fc?source=friends_link&sk=91582cdbd0719dc23375338ad92afa9b&__hstc=221401095.5d21139e33f975ecef01c1783a7523db.1673975383152.1708023233215.1708026196201.468&__hssc=221401095.2.1708026196201&__hsfp=589919331) plugin is available
- [Nx Agents](https://blog.nrwl.io/fast-effortless-ci-67812514ffb4?source=friends_link&sk=89e1b5c0388dda077e64a2eab5495d95&__hstc=221401095.5d21139e33f975ecef01c1783a7523db.1673975383152.1708023233215.1708026196201.468&__hssc=221401095.2.1708026196201&__hsfp=589919331) are publicly available
- [`nx release`](https://blog.nrwl.io/versioning-and-releasing-packages-in-a-monorepo-45ee194378d1?source=friends_link&sk=934e4c5321774c8a9f88433e0dea578b&__hstc=221401095.5d21139e33f975ecef01c1783a7523db.1673975383152.1708023233215.1708026196201.468&__hssc=221401095.2.1708026196201&__hsfp=589919331) is out of beta

{% youtube
src="https://www.youtube.com/embed/znR_cv9hS-0"
title="Nx 18.0!!!"
/%}

## Features

{% cards cols="2" %}
{% card title="Inferred tasks (Project Crystal)" type="document" url="/concepts/inferred-tasks" /%}
{% card title="Project Details View" type="document" url="/features/explore-graph#explore-projects-in-your-workspace" /%}
{% card title="New @nx/nuxt plugin" type="document" url="/nx-api/nuxt" /%}
{% card title="Distribute tasks on Nx Agents" type="document" url="/ci/features/distribute-task-execution" /%}
{% card title="Automatically split e2e tasks (Test Atomizer)" type="document" url="/ci/features/split-e2e-tasks" /%}
{% card title="Re-run flaky tasks" type="document" url="/ci/features/flaky-tasks" /%}
{% /cards %}

## Breaking Changes

Note: Though this is a major version, there are no removals of previous deprecations. Any deprecations which were previously scheduled for Nx 18 are now scheduled for Nx 19 which will still be coming out around April 2024.
5 changes: 5 additions & 0 deletions docs/generated/packages/expo/executors/sync-deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"items": { "type": "string" },
"default": [],
"description": "An array of npm packages to exclude."
},
"all": {
"type": "boolean",
"description": "Copy all dependencies and devDependencies from the workspace root package.json.",
"default": false
}
},
"presets": []
Expand Down
5 changes: 5 additions & 0 deletions docs/generated/packages/react-native/executors/sync-deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"items": { "type": "string" },
"default": [],
"description": "An array of npm packages to exclude."
},
"all": {
"type": "boolean",
"description": "Copy all dependencies and devDependencies from the workspace root package.json.",
"default": false
}
},
"presets": []
Expand Down
20 changes: 16 additions & 4 deletions docs/shared/recipes/ci-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Some executors automatically generate output `package.json` and the lock file ge
{% /tab %}
{% /tabs %}

## Programmtic usage
## Programmatic usage

If you are using a custom setup that does not support the creation of a `package.json` or a lock file, you can still use Nx to generate them via The `createPackageJson` and `createLockFile` functions which are exported from `@nx/js`:

Expand Down Expand Up @@ -159,14 +159,21 @@ You can replace _npm_ with _yarn_ or _pnpm_ if you are using those package manag
{% tab label="Custom executor" %}

```typescript
import { createPackageJson, createLockFile } from '@nx/js';
import { Schema } from './schema';
import { createPackageJson, createLockFile, getLockFileName } from '@nx/js';
import { writeFileSync } from 'fs';
import {
detectPackageManager,
ExecutorContext,
writeJsonFile,
} from '@nx/devkit';

export default async function buildExecutor(
options: Schema,
context: ExecutorContext
) {
// ...your executor code
const packageManager = detectPackageManager();

const packageJson = createPackageJson(
context.projectName,
Expand All @@ -179,9 +186,14 @@ export default async function buildExecutor(

// do any additional manipulations to "package.json" here

const lockFile = createLockFile(packageJson);
const lockFile = createLockFile(
packageJson,
context.projectGraph,
packageManager
);
const lockFileName = getLockFileName(packageManager);
writeJsonFile(`${options.outputPath}/package.json`, packageJson);
writeFileSync(`${options.outputPath}/${packageLockFileName}`, lockFile, {
writeFileSync(`${options.outputPath}/${lockFileName}`, lockFile, {
encoding: 'utf-8',
});

Expand Down
22 changes: 19 additions & 3 deletions e2e/react-native/src/react-native-legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,34 @@ describe('@nx/react-native (legacy)', () => {
return `import AsyncStorage from '@react-native-async-storage/async-storage';${content}`;
});

await runCLIAsync(`sync-deps ${appName}`);
let result = readJson(join('apps', appName, 'package.json'));
expect(result).toMatchObject({
dependencies: {
'@react-native-async-storage/async-storage': '*',
},
});

await runCLIAsync(
`sync-deps ${appName} --include=react-native-image-picker`
);
result = readJson(join('apps', appName, 'package.json'));
expect(result).toMatchObject({
dependencies: {
'@react-native-async-storage/async-storage': '*',
'react-native-image-picker': '*',
},
});

const result = readJson(join('apps', appName, 'package.json'));
await runCLIAsync(`sync-deps ${appName} --all`);
result = readJson(join('apps', appName, 'package.json'));
expect(result).toMatchObject({
dependencies: {
'@react-native-async-storage/async-storage': '*',
'react-native-image-picker': '*',
'react-native': '*',
},
devDependencies: {
'@react-native-async-storage/async-storage': '*',
'@nx/react-native': '*',
},
});
});
Expand Down
4 changes: 2 additions & 2 deletions e2e/remix/tests/nx-remix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Remix E2E Tests', () => {
expect(result).toContain('Successfully ran target build');

// TODO(colum): uncomment line below when fixed
checkFilesExist(`dist/apps/sub/${plugin}/build/index.js`);
checkFilesExist(`apps/sub/${plugin}/build/index.js`);
}, 120000);

it('should create src in the specified directory --projectNameAndRootFormat=as-provided', async () => {
Expand All @@ -58,7 +58,7 @@ describe('Remix E2E Tests', () => {

const result = runCLI(`build ${plugin}`);
expect(result).toContain('Successfully ran target build');
checkFilesExist(`dist/subdir/build/index.js`);
checkFilesExist(`subdir/build/index.js`);
}, 120000);
});

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@pnpm/lockfile-types": "^5.0.0",
"@reduxjs/toolkit": "1.9.0",
"@remix-run/dev": "^2.3.0",
"@remix-run/node": "^2.3.0",
"@remix-run/dev": "^2.6.0",
"@remix-run/node": "^2.6.0",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-image": "^2.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/expo/src/executors/sync-deps/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface ExpoSyncDepsOptions {
include: string[] | string; // default is an empty array []
exclude: string[] | string; // default is an empty array []
all: boolean; // default is false
}
5 changes: 5 additions & 0 deletions packages/expo/src/executors/sync-deps/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
},
"default": [],
"description": "An array of npm packages to exclude."
},
"all": {
"type": "boolean",
"description": "Copy all dependencies and devDependencies from the workspace root package.json.",
"default": false
}
}
}
74 changes: 51 additions & 23 deletions packages/expo/src/executors/sync-deps/sync-deps.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import { join } from 'path';
import * as chalk from 'chalk';
import {
ExecutorContext,
ProjectGraph,
logger,
readCachedProjectGraph,
readJsonFile,
writeJsonFile,
} from '@nx/devkit';

import { ExpoSyncDepsOptions } from './schema';
import { findAllNpmDependencies } from '../../utils/find-all-npm-dependencies';
import { PackageJson } from 'nx/src/utils/package-json';

export interface ReactNativeSyncDepsOutput {
success: boolean;
Expand All @@ -19,41 +23,59 @@ export default async function* syncDepsExecutor(
): AsyncGenerator<ReactNativeSyncDepsOutput> {
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;

const workspacePackageJsonPath = join(context.root, 'package.json');
const projectPackageJsonPath = join(
context.root,
projectRoot,
'package.json'
);

const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
const projectPackageJson = readJsonFile(projectPackageJsonPath);
displayNewlyAddedDepsMessage(
context.projectName,
await syncDeps(
projectRoot,
context.root,
context.projectName,
projectPackageJson,
projectPackageJsonPath,
workspacePackageJson,
context.projectGraph,
typeof options.include === 'string'
? options.include.split(',')
: options.include,
typeof options.exclude === 'string'
? options.exclude.split(',')
: options.exclude
: options.exclude,
options.all
)
);

yield { success: true };
}

export async function syncDeps(
projectRoot: string,
workspaceRoot: string,
projectName: string,
projectPackageJson: PackageJson,
projectPackageJsonPath: string,
workspacePackageJson: PackageJson,
projectGraph: ProjectGraph = readCachedProjectGraph(),
include: string[] = [],
exclude: string[] = []
exclude: string[] = [],
all: boolean = false
): Promise<string[]> {
const workspacePackageJsonPath = join(workspaceRoot, 'package.json');
const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
let npmDeps = Object.keys(workspacePackageJson.dependencies || {});
let npmDevdeps = Object.keys(workspacePackageJson.devDependencies || {});
let npmDeps = all
? Object.keys(workspacePackageJson.dependencies || {})
: findAllNpmDependencies(projectGraph, projectName);
let npmDevdeps = all
? Object.keys(workspacePackageJson.devDependencies || {})
: [];

const packageJsonPath = join(workspaceRoot, projectRoot, 'package.json');
const packageJson = readJsonFile(packageJsonPath);
const newDeps = [];
let updated = false;

if (!packageJson.dependencies) {
packageJson.dependencies = {};
if (!projectPackageJson.dependencies) {
projectPackageJson.dependencies = {};
updated = true;
}

Expand All @@ -64,30 +86,36 @@ export async function syncDeps(
npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
}

if (!packageJson.devDependencies) {
packageJson.devDependencies = {};
if (!projectPackageJson.devDependencies) {
projectPackageJson.devDependencies = {};
}
if (!packageJson.dependencies) {
packageJson.dependencies = {};
if (!projectPackageJson.dependencies) {
projectPackageJson.dependencies = {};
}

npmDeps.forEach((dep) => {
if (!packageJson.dependencies[dep] && !packageJson.devDependencies[dep]) {
packageJson.dependencies[dep] = '*';
if (
!projectPackageJson.dependencies[dep] &&
!projectPackageJson.devDependencies[dep]
) {
projectPackageJson.dependencies[dep] = '*';
newDeps.push(dep);
updated = true;
}
});
npmDevdeps.forEach((dep) => {
if (!packageJson.dependencies[dep] && !packageJson.devDependencies[dep]) {
packageJson.devDependencies[dep] = '*';
if (
!projectPackageJson.dependencies[dep] &&
!projectPackageJson.devDependencies[dep]
) {
projectPackageJson.devDependencies[dep] = '*';
newDeps.push(dep);
updated = true;
}
});

if (updated) {
writeJsonFile(packageJsonPath, packageJson);
writeJsonFile(projectPackageJsonPath, projectPackageJson);
}

return newDeps;
Expand Down
23 changes: 20 additions & 3 deletions packages/expo/src/executors/update/update.impl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorContext, names } from '@nx/devkit';
import { resolve as pathResolve } from 'path';
import { ExecutorContext, names, readJsonFile } from '@nx/devkit';
import { join, resolve as pathResolve } from 'path';
import { ChildProcess, fork } from 'child_process';

import { resolveEas } from '../../utils/resolve-eas';
Expand All @@ -23,10 +23,27 @@ export default async function* buildExecutor(
): AsyncGenerator<ReactNativeUpdateOutput> {
const projectRoot =
context.projectsConfigurations.projects[context.projectName].root;
const workspacePackageJsonPath = join(context.root, 'package.json');
const projectPackageJsonPath = join(
context.root,
projectRoot,
'package.json'
);

const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
const projectPackageJson = readJsonFile(projectPackageJsonPath);

await installAsync(context.root, { packages: ['expo-updates'] });
displayNewlyAddedDepsMessage(
context.projectName,
await syncDeps(projectRoot, context.root, ['expo-updates'])
await syncDeps(
context.projectName,
projectPackageJson,
projectPackageJsonPath,
workspacePackageJson,
context.projectGraph,
['expo-updates']
)
);

try {
Expand Down
Loading

0 comments on commit af69668

Please sign in to comment.