28 Commits

Author SHA1 Message Date
Craigory Coppola
c8d89e2f2a
feat(core)!: remove legacy cache flag from nx.json (#30787) 2025-04-29 10:39:36 -04:00
Craigory Coppola
5721ea3c21
feat(core): lock graph creation when running in another process (#29408)
## Current Behavior
Running Nx in multiple processes at the same time with the daemon
disabled can cripple a system due to excess memory usage when creating
the graph. This is due to plugin workers being started per-parent
process when there is no daemon. This change enables a file lock to
prevent the simultaneous processing, and read from the cache when the
first run completes.

Currently, running `nx show projects` 30 times in parallel looks
something like this:

30 processes exited within 37535ms

## Expected Behavior
30 processes exited within 6435ms

## Test Script
```js
//@ts-check

const { spawn } = require('child_process');

let alive = new Set();

let start = Date.now();
let iterations = 30;

for (let i = 0; i < iterations; i++) {
  const cp = spawn('npx nx show projects', [], {
    shell: true,
    env: {
      ...process.env,
      NX_DAEMON: 'false',
      NX_VERBOSE_LOGGING: 'true',
    },
  });
  alive.add(i);
  //   cp.stdout.on('data', (data) => {
  //     console.log(`stdout [${i}]: ${data}`);
  //   });
  cp.stderr.on('data', (data) => {
    console.error(`stderr [${i}]: ${data}`);
  });
  cp.on('exit', (code) => {
    console.log(`child process ${i} exited with code ${code}`);
    alive.delete(i);
  });
}

const i = setInterval(() => {
  if (alive.size > 0) {
  } else {
    clearInterval(i);
    console.log(
      `${iterations} processes exited within ${Date.now() - start}ms`
    );
  }
}, 1);

```
2025-01-28 09:46:52 -05:00
Jason Jean
4a9508b368
feat(core): add pre and post run apis (#29636)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

There is no specific API for running things before and after tasks run.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

This PR adds an API akin to npm's `preinstall` and `postinstall`.

Plugins can now specify `preTasksExecution` and `postTasksExecution`
functions which run before and after Nx runs tasks respectively.

```ts
import type { PreTasksExecutionContext, PostTasksExecutionContext } from '@nx/devkit';

interface PluginOptions {
  field: any;
}

export function preTasksExecution(options: PluginOptions, context: PreTasksExecutionContext) {
  console.log('prerun')
}

export function postTasksExecution(options: PluginOptions, context: PostTasksExecutionContext) {
  console.log('postrun', context.taskResults)
}
```

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-01-27 12:09:43 -05:00
Jason Jean
23bebd91e7
feat(devkit): bump compatibility to Nx 19 - 21.x (#28243)
BREAKING CHANGE

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

* `@nx/devkit` supports Nx 17 - 20.
* Node 18 - 22 is supported 
* `ExecutorContext.projectGraph`, `ExecutorContext.nxJsonConfiguration`,
and `ExecutorContext.projectsConfigurations` is marked as optional
because `ExecutorContext` in some versions of Nx did not have them.
* `ExecutorContext.workspace` is marked as optional because
`ExecutorContext` in some versions of Nx did not have the above
properties which contain the same information.
* `ProjectGraphNode` is deprecated.
* `NxPluginV1.processProjectGraph` was deprecated long ago and there has
been a warning since.
* `appRootPath` has been deprecated for a long time.
* `parseTargetString` had a variant that did not take either the project
graph or the executor context.
* `readNxJson` has a variant which does not take a tree. This was not
clearly deprecated.
* There are handlers to require from `@nx/` instead of `@nrwl`
* Nx tries to get a root install from `@nrwl/cli`


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

* `@nx/devkit` supports Nx 19 - 21.
* Node 20 - 22 is supported 
* `ExecutorContext.projectGraph`, `ExecutorContext.nxJsonConfiguration`,
and `ExecutorContext.projectsConfigurations` is marked as required
because `ExecutorContext` in Nx 19+ is guaranteed to have them.
* `ExecutorContext.workspace` is removed because the same information is
available in the above properties
* `ProjectGraphNode` is removed.
* `NxPluginV1` is no more. All plugins should be `NxPluginV2`.
* `workspaceRoot` is the replacement for `appRootPath`. `appRootPath` is
removed.
* `parseTargetString` no longer has a variant that did not take either
the project graph or the executor context.
* `readNxJson` still has a variant which does not take a tree but it's
clearly deprecated to be removed in Nx 21.
* `@nrwl` packages are no more so we don't have to redirect requires
anymore.
* `@nrwl/cli` is no more so Nx shouldn't try to get a root install there
* 

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2024-10-03 17:35:47 -04:00
Paweł Twardziak
2c0a50c0d8
feat(core): expose graph json type (#27496)
Closes #3283

## Current Behavior
See #3283

## Expected Behavior
See #3283

## Related Issue(s)
#3283

Fixes #
-  expose graph json type

---------

Co-authored-by: @NgDaddy Paweł Twardziak <contact@ngdaddy.com>
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
2024-08-23 18:20:59 -04:00
LongYinan
981eb30a0f
feat(core): support compile to wasi target (#22870)
This pull request is trying to add wasm32-wasi target support for the
nx/native

To test the build, you can run the following commands:

- `rustup target add wasm32-wasip1-threads`
- `pnpm exec napi build --release --platform --package-json-path
packages/nx/package.json --manifest-path packages/nx/Cargo.toml --js
./native-bindings.js -o packages/nx/src/native --target
wasm32-wasip1-threads`

And the wasm file will be built at
packages/nx/src/native/nx.wasm32-wasi.wasm

Blocked by:

- Support @napi-rs/cli 3.0  Cammisuli/monodon#48
- https://github.com/napi-rs/napi-rs/issues/2009

The pseudo_terminal mod is excluded on the wasm32 targets, which is as
expected.

The watch mod is excluded because of the upstream `watchexec` deps
introduced by ignore-files don't support the wasi target at this moment
(but we can improve it).

## Related Issues
Fixes https://github.com/nrwl/nx/issues/21860
Fixes https://github.com/nrwl/nx/issues/23821

---------

Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
2024-07-05 15:55:35 -04:00
Michal Jez
6d2e7cd2cf
feat(nx-plugin): update executor generator to have context (#16982)
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
2024-06-04 17:49:50 -04:00
Craigory Coppola
dd6eda84b0
feat(devkit): allow to customize overwrite mode in generateFiles (#26354)
Adds a new capability to choose how to handle already existing target
files when using a generator.

See #17925

Co-authored-by: Michael Monerau <micmo@qontrol.io>
2024-06-04 16:12:15 -04:00
Craigory Coppola
6f223005b8
fix(misc): ensure plugins are not creating workspace context while creating nodes (#26253) 2024-05-31 18:54:56 -04:00
Craigory Coppola
a5682d1ca5
feat(core): add create nodes v2 for batch processing config files (#26250) 2024-05-30 15:28:59 -04:00
Jason Jean
a64a7e2db9
feat(core): cleanup for v19 (#22993) 2024-05-01 12:12:32 -04:00
Craigory Coppola
7bb6e9ee14
feat(core): add API entrypoint to register metadata (#22773) 2024-04-23 17:04:51 -04:00
Craigory Coppola
7a7cbeca44
feat(core): re-enable running plugins in isolation (#22527) 2024-04-09 18:36:33 -04:00
Austin Fahsl
8bde48fc7a
fix(release): skip lock file update if workspaces are not enabled (#22055) 2024-03-01 10:15:55 -07:00
Craigory Coppola
2374d8eaba
feat(testing): add create-nodes plugin for playwright e2e targets (#20099) 2023-12-20 16:34:32 -05:00
Craigory Coppola
30d94f76ee
cleanup(core): remove async flag from signature of buildProjectsConfigurationsFromProjectPathsAndPlugins (#20228) 2023-11-17 15:31:03 -05:00
Craigory Coppola
206247f9ad
feat(core): make createNodes async (#20195)
Co-authored-by: Jonathan Cammisuli <jon@cammisuli.ca>
2023-11-13 16:57:20 -05:00
Jason Jean
d0005c954f
feat(core): remove deprecated defaultCollection and npmScope nx.json … (#19708) 2023-10-18 18:03:57 -04:00
Craigory Coppola
c56b5a3c77
fix(devkit): correct nx-json typing after plugin tweaks (#19706) 2023-10-18 15:15:00 -04:00
Craigory Coppola
94748413a5
feat(core): accept various task runner options from root of nx.json (#19243) 2023-10-05 12:02:04 -04:00
Craigory Coppola
a0ff89258d
cleanup(devkit): export FileMap interface (#19297) 2023-09-27 14:35:12 +00:00
Craigory Coppola
de2824a450
feat(devkit): add method for tree-aware glob search (#19128) 2023-09-13 17:39:45 -04:00
Craigory Coppola
f2e20c81b6
cleanup(core): adjust create dependencies context (#19070)
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
2023-09-12 09:01:32 -04:00
Colum Ferry
dd5ea7a244
feat(webpack): move module federation utils to webpack (#18996) 2023-09-08 10:22:09 -04:00
Isaac Mann
71d2994be9
feat(nx-dev): types in devkit toc (#18594) 2023-08-18 11:54:36 -04:00
Emily Xiong
40d66ec715
chore(core): remove readProjectsConfigurations from workspaces (#18329)
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
2023-08-15 14:48:40 -04:00
Craigory Coppola
a7cf272d1f
feat(core): add api for v2 of project project graph plugins (#18032)
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>
2023-08-10 14:58:29 -04:00
Isaac Mann
da2ca3a2de
feat(nx-dev): split devkit reference page (#18536) 2023-08-10 08:03:36 -04:00