32 Commits

Author SHA1 Message Date
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
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
Jason Jean
a64a7e2db9
feat(core): cleanup for v19 (#22993) 2024-05-01 12:12:32 -04:00
Craigory Coppola
deb0f1a492
chore(repo): bump deprecation messages to v19 (#21430) 2024-01-30 16:29:05 -05:00
wout junius
946c6a745d
feat(devkit): improving error handeling read target options (#20336) 2024-01-30 18:25:31 +00: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
Craigory Coppola
1bd95104cc
fix(devkit): make parseTargetString more tolerant to bad graph shapes (#20170) 2023-11-09 21:13:46 -05:00
Craigory Coppola
ae154e777e
cleanup(devkit): improve error messaging when project doesnt exist for readTargetOptions (#19108) 2023-09-12 23:07:20 -04:00
Craigory Coppola
228393724c
feat(devkit): update parseTargetString to allow referencing targets on the current project (#19109) 2023-09-11 16:58:03 -04:00
Leosvel Pérez Espinosa
ace8f8cf97
fix(misc): calculate cwd relative path correctly for generators and executors (#18933) 2023-09-06 14:17:35 -04:00
Jason Jean
2034cddf04
chore(devkit): move all internal nx imports to requireNx (#18639) 2023-08-16 17:40:42 -04:00
Emily Xiong
6b43833d2c
chore(core): move relativeCwd out of workspaces (#18229) 2023-08-03 13:36:28 -04:00
Emily Xiong
2f59796ac0
chore(core): move calculateDefaultProjectName out of workspaces (#18225) 2023-07-25 11:27:54 -04:00
Emily Xiong
2e6592c533
fix(devkit): use Workspace in devkit for backwards compatibility (#18246) 2023-07-21 16:54:30 -04:00
Emily Xiong
1c6a359130
chore(core): copy isNxExecutor out of Workspaces class (#17996) 2023-07-14 01:55:42 -04:00
Victor Savkin
0848031dd9 feat(core): move task hashing into daemon 2023-05-17 11:37:57 -04:00
AgentEnder
6c00f922ae chore(core): reorganize nx-commands and cli implementation 2023-05-05 12:51:22 -04:00
Leosvel Pérez Espinosa
50c0dac986
fix(devkit): ensure readTargetOptions is compatible with nx supported range (#15296) 2023-02-27 12:11:02 -05:00
Jason Jean
1d773c0d35
fix(devkit): make devkit backwards compatible back to nx 14.1 (#14854) 2023-02-09 12:48:57 -05:00
Victor Savkin
422c8c735a cleanup(core): clearly split nx.json config and projects config 2023-01-05 15:35:36 -05:00
Craigory Coppola
285dc39371
feat(core): support targets with colons in the name without quotes (#13938) 2022-12-28 15:18:07 -05:00
Júlio César
b142f385c9
fix(devkit): use target inference from plugins in readTargetOptions (#13141) 2022-11-12 13:49:54 -05:00
Craigory Coppola
e439718059
fix(devkit): parseTargetString should support targets with colons in the name (#10400) 2022-05-20 16:12:35 -04:00
Victor Savkin
428106f6be
cleanup(core): create more meaningful file structure in nx package (#9621) 2022-03-31 09:07:22 -04:00
Victor Savkin
d4b5c30eba
cleanup(core): remove the indirection left after inlining ta… (#9469) 2022-03-23 22:18:17 -04:00
Victor Savkin
6f038e7a4a feat(core): reorganize packges to consolidate all cli-related code in nx 2022-03-14 16:42:51 -04:00
Leosvel Pérez Espinosa
e677a1d82d
fix(devkit): fall back to the target default config when reading target options and the config is not provided (#8932) 2022-02-25 09:18:27 +00:00
Benjamin Cabanes
09fa02112b
docs(core): correctly format function comments for doc generation (#6055) 2021-06-17 18:32:06 +00:00
Phillip Barta
6c6e8b36b7 feat(devkit): refactoring for stricter types and better performance 2021-05-27 13:37:29 -04:00
Leosvel Pérez Espinosa
d0afa3dd89
feat(angular): add executor which allows to delegate the build to another target (#5715) 2021-05-20 12:29:46 +01:00
vsavkin
7457b16811 cleanup(misc): misc docs update and small cleanups 2021-03-11 15:45:54 -05:00
Jason Jean
34781a11c2
feat(react): migrate @nrwl/web:dev-server to devkit (#4682) 2021-02-03 16:33:51 -05:00