Skip to content

Commit

Permalink
feat(core): add initial draft of v2 project inference
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Jul 14, 2023
1 parent cd8c61d commit 1297568
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 160 deletions.
20 changes: 11 additions & 9 deletions docs/generated/devkit/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ It only uses language primitives and immutable objects
- [ModuleFederationConfig](../../devkit/documents/nx_devkit#modulefederationconfig)
- [NxAffectedConfig](../../devkit/documents/nx_devkit#nxaffectedconfig)
- [NxJsonConfiguration](../../devkit/documents/nx_devkit#nxjsonconfiguration)
- [NxPlugin](../../devkit/documents/nx_devkit#nxplugin)
- [ProjectConfiguration](../../devkit/documents/nx_devkit#projectconfiguration)
- [ProjectFileMap](../../devkit/documents/nx_devkit#projectfilemap)
- [ProjectGraph](../../devkit/documents/nx_devkit#projectgraph)
Expand Down Expand Up @@ -70,6 +69,7 @@ It only uses language primitives and immutable objects
- [Hasher](../../devkit/documents/nx_devkit#hasher)
- [ImplicitDependencyEntry](../../devkit/documents/nx_devkit#implicitdependencyentry)
- [ModuleFederationLibrary](../../devkit/documents/nx_devkit#modulefederationlibrary)
- [NxPlugin](../../devkit/documents/nx_devkit#nxplugin)
- [PackageManager](../../devkit/documents/nx_devkit#packagemanager)
- [ProjectGraphNode](../../devkit/documents/nx_devkit#projectgraphnode)
- [ProjectTargetConfigurator](../../devkit/documents/nx_devkit#projecttargetconfigurator)
Expand Down Expand Up @@ -303,14 +303,6 @@ Nx.json configuration

---

### NxPlugin

**NxPlugin**: `Object`

A plugin for Nx

---

### ProjectConfiguration

**ProjectConfiguration**: `Object`
Expand Down Expand Up @@ -611,6 +603,14 @@ A callback function that is executed after changes are made to the file system

---

### NxPlugin

Ƭ **NxPlugin**: `NxPluginV1` \| `NxPluginV2`

A plugin for Nx

---

### PackageManager

Ƭ **PackageManager**: `"yarn"` \| `"pnpm"` \| `"npm"`
Expand All @@ -635,6 +635,8 @@ this type will be removed in v16. Use [ProjectGraphProjectNode](../../devkit/doc

▸ (`file`): `Record`<`string`, [`TargetConfiguration`](../../devkit/documents/nx_devkit#targetconfiguration)\>

@deprecated(v18) Add targets to the nodes when building them instead.

##### Parameters

| Name | Type |
Expand Down
20 changes: 11 additions & 9 deletions docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ It only uses language primitives and immutable objects
- [ModuleFederationConfig](../../devkit/documents/nx_devkit#modulefederationconfig)
- [NxAffectedConfig](../../devkit/documents/nx_devkit#nxaffectedconfig)
- [NxJsonConfiguration](../../devkit/documents/nx_devkit#nxjsonconfiguration)
- [NxPlugin](../../devkit/documents/nx_devkit#nxplugin)
- [ProjectConfiguration](../../devkit/documents/nx_devkit#projectconfiguration)
- [ProjectFileMap](../../devkit/documents/nx_devkit#projectfilemap)
- [ProjectGraph](../../devkit/documents/nx_devkit#projectgraph)
Expand Down Expand Up @@ -70,6 +69,7 @@ It only uses language primitives and immutable objects
- [Hasher](../../devkit/documents/nx_devkit#hasher)
- [ImplicitDependencyEntry](../../devkit/documents/nx_devkit#implicitdependencyentry)
- [ModuleFederationLibrary](../../devkit/documents/nx_devkit#modulefederationlibrary)
- [NxPlugin](../../devkit/documents/nx_devkit#nxplugin)
- [PackageManager](../../devkit/documents/nx_devkit#packagemanager)
- [ProjectGraphNode](../../devkit/documents/nx_devkit#projectgraphnode)
- [ProjectTargetConfigurator](../../devkit/documents/nx_devkit#projecttargetconfigurator)
Expand Down Expand Up @@ -303,14 +303,6 @@ Nx.json configuration

---

### NxPlugin

**NxPlugin**: `Object`

A plugin for Nx

---

### ProjectConfiguration

**ProjectConfiguration**: `Object`
Expand Down Expand Up @@ -611,6 +603,14 @@ A callback function that is executed after changes are made to the file system

---

### NxPlugin

Ƭ **NxPlugin**: `NxPluginV1` \| `NxPluginV2`

A plugin for Nx

---

### PackageManager

Ƭ **PackageManager**: `"yarn"` \| `"pnpm"` \| `"npm"`
Expand All @@ -635,6 +635,8 @@ this type will be removed in v16. Use [ProjectGraphProjectNode](../../devkit/doc

▸ (`file`): `Record`<`string`, [`TargetConfiguration`](../../devkit/documents/nx_devkit#targetconfiguration)\>

@deprecated(v18) Add targets to the nodes when building them instead.

##### Parameters

| Name | Type |
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
"@tailwindcss/line-clamp": "^0.4.2",
"@tailwindcss/typography": "^0.5.7",
"@types/license-checker": "^25.0.3",
"@types/minimatch": "^5.1.2",
"@yarnpkg/lockfile": "^1.1.0",
"@yarnpkg/parsers": "3.0.0-rc.46",
"@zkochan/js-yaml": "0.0.6",
Expand Down Expand Up @@ -359,4 +360,4 @@
"[email protected]": "patches/[email protected]"
}
}
}
}
1 change: 1 addition & 0 deletions packages/nx/src/config/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export interface ProjectGraphProcessorContext {

/**
* A function that produces an updated ProjectGraph
* @deprecated(v18) Use `buildProjectDependencies` and `buildProjectNodes` instead.
*/
export type ProjectGraphProcessor = (
currentGraph: ProjectGraph,
Expand Down
23 changes: 17 additions & 6 deletions packages/nx/src/config/workspaces.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { TargetConfiguration } from './workspace-json-project-json';

jest.mock('fs', () => require('memfs').fs);

const libConfig = (name) => ({
root: `libs/${name}`,
sourceRoot: `libs/${name}/src`,
const libConfig = (root, name?: string) => ({
name: name ?? toProjectName(`${root}/some-file`),
root: `libs/${root}`,
sourceRoot: `libs/${root}/src`,
});

const packageLibConfig = (root) => ({
const packageLibConfig = (root, name?: string) => ({
name: name ?? toProjectName(`${root}/some-file`),
root,
sourceRoot: root,
projectType: 'library',
Expand Down Expand Up @@ -66,13 +68,17 @@ describe('Workspaces', () => {

const workspaces = new Workspaces('/root');
const resolved = workspaces.readProjectsConfigurations();
console.log(resolved);
expect(resolved.projects.lib1).toEqual(standaloneConfig);
});

it('should build project configurations from glob', () => {
const lib1Config = libConfig('lib1');
const lib2Config = packageLibConfig('libs/lib2');
const domainPackageConfig = packageLibConfig('libs/domain/lib3');
const domainPackageConfig = packageLibConfig(
'libs/domain/lib3',
'domain-lib3'
);
const domainLibConfig = libConfig('domain/lib4');

vol.fromJSON(
Expand All @@ -94,10 +100,14 @@ describe('Workspaces', () => {

const workspaces = new Workspaces('/root');
const { projects } = workspaces.readProjectsConfigurations();
// projects got deduped so the workspace one remained
console.log(projects);

// projects got merged for lib1
expect(projects['lib1']).toEqual({
name: 'lib1',
root: 'libs/lib1',
sourceRoot: 'libs/lib1/src',
projectType: 'library',
});
expect(projects.lib2).toEqual(lib2Config);
expect(projects['domain-lib3']).toEqual(domainPackageConfig);
Expand Down Expand Up @@ -137,6 +147,7 @@ describe('Workspaces', () => {
const workspaces = new Workspaces('/root2');
const resolved = workspaces.readProjectsConfigurations();
expect(resolved.projects['my-package']).toEqual({
name: 'my-package',
root: 'packages/my-package',
sourceRoot: 'packages/my-package',
projectType: 'library',
Expand Down
Loading

0 comments on commit 1297568

Please sign in to comment.