@joshmossas/nx-cargo 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +45 -44
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +44 -41
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const devkit = require('@nx/devkit');
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
4
|
+
const cp = require('child_process');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
10
8
|
|
|
11
9
|
function _interopNamespaceCompat(e) {
|
|
12
10
|
if (e && typeof e === 'object' && 'default' in e) return e;
|
|
@@ -20,40 +18,47 @@ function _interopNamespaceCompat(e) {
|
|
|
20
18
|
return n;
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
24
21
|
const cp__namespace = /*#__PURE__*/_interopNamespaceCompat(cp);
|
|
25
22
|
const os__namespace = /*#__PURE__*/_interopNamespaceCompat(os);
|
|
26
23
|
const path__namespace = /*#__PURE__*/_interopNamespaceCompat(path);
|
|
24
|
+
const fs__namespace = /*#__PURE__*/_interopNamespaceCompat(fs);
|
|
27
25
|
|
|
28
26
|
function createDependencies(_, ctx) {
|
|
29
27
|
const allDependencies = [];
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
const seenManifestPaths = /* @__PURE__ */ new Set();
|
|
29
|
+
const sortedManifests = Object.values(ctx.projects).map((project) => {
|
|
30
|
+
const filepath = path__namespace.resolve(ctx.workspaceRoot, project.root, "Cargo.toml");
|
|
31
|
+
const depth = filepath.split(path__namespace.sep).length;
|
|
32
|
+
return { filepath, depth };
|
|
33
|
+
}).filter((manifest) => fs__namespace.existsSync(manifest.filepath)).sort((a, b) => a.depth - b.depth);
|
|
34
|
+
for (const { filepath } of sortedManifests) {
|
|
35
|
+
if (seenManifestPaths.has(filepath)) {
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
try {
|
|
39
|
+
const metadata = getCargoMetadata(path__namespace.dirname(filepath));
|
|
40
|
+
for (const pkg of metadata.packages) {
|
|
41
|
+
seenManifestPaths.add(path__namespace.resolve(pkg.manifest_path));
|
|
42
|
+
}
|
|
43
|
+
const workspaceDeps = processWorkspaceMetadata(ctx, metadata);
|
|
44
|
+
allDependencies.push(...workspaceDeps);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.warn(
|
|
47
|
+
`[nx-rust] Skipping ${filepath} due to error:`,
|
|
48
|
+
e instanceof Error ? e.message : e
|
|
49
|
+
);
|
|
50
|
+
}
|
|
41
51
|
}
|
|
42
52
|
return allDependencies;
|
|
43
53
|
}
|
|
44
54
|
function processWorkspaceMetadata(ctx, metadata) {
|
|
45
|
-
const {
|
|
46
|
-
packages,
|
|
47
|
-
workspace_members: cargoWsMembers,
|
|
48
|
-
resolve: cargoResolve
|
|
49
|
-
} = metadata;
|
|
55
|
+
const { packages, resolve } = metadata;
|
|
50
56
|
const workspacePackages = /* @__PURE__ */ new Map();
|
|
51
|
-
for (const
|
|
52
|
-
|
|
53
|
-
if (pkg) workspacePackages.set(id, pkg);
|
|
57
|
+
for (const pkg of packages) {
|
|
58
|
+
workspacePackages.set(pkg.id, pkg);
|
|
54
59
|
}
|
|
55
60
|
const nxData = mapCargoProjects(ctx, workspacePackages);
|
|
56
|
-
return
|
|
61
|
+
return (resolve?.nodes ?? []).filter(({ id }) => nxData.has(id)).flatMap(({ id: sourceId, dependencies }) => {
|
|
57
62
|
const sourceProject = nxData.get(sourceId);
|
|
58
63
|
const cargoPackage = workspacePackages.get(sourceId);
|
|
59
64
|
const sourceManifest = path__namespace.relative(ctx.workspaceRoot, cargoPackage.manifest_path).replace(/\\/g, "/");
|
|
@@ -65,29 +70,16 @@ function processWorkspaceMetadata(ctx, metadata) {
|
|
|
65
70
|
}));
|
|
66
71
|
});
|
|
67
72
|
}
|
|
68
|
-
function getCargoMetadata(cwd) {
|
|
69
|
-
const availableMemory = os__namespace.freemem();
|
|
70
|
-
const metadata = cp__namespace.execSync("cargo metadata --format-version=1", {
|
|
71
|
-
encoding: "utf8",
|
|
72
|
-
maxBuffer: availableMemory,
|
|
73
|
-
cwd
|
|
74
|
-
// Crucial: run in the workspace directory
|
|
75
|
-
});
|
|
76
|
-
return JSON.parse(metadata);
|
|
77
|
-
}
|
|
78
73
|
function mapCargoProjects(ctx, packages) {
|
|
79
|
-
|
|
80
|
-
for (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
let manifestDir = path__namespace.dirname(cargoPackage.manifest_path);
|
|
85
|
-
let projectDir = path__namespace.relative(ctx.workspaceRoot, manifestDir).replace(/\\/g, "/");
|
|
86
|
-
let found = Object.entries(ctx.projects).find(
|
|
74
|
+
const result = /* @__PURE__ */ new Map();
|
|
75
|
+
for (const [cargoId, cargoPackage] of packages) {
|
|
76
|
+
const manifestDir = path__namespace.dirname(cargoPackage.manifest_path);
|
|
77
|
+
const projectDir = path__namespace.relative(ctx.workspaceRoot, manifestDir).replace(/\\/g, "/");
|
|
78
|
+
const found = Object.entries(ctx.projects).find(
|
|
87
79
|
([, config]) => config.root === projectDir
|
|
88
80
|
);
|
|
89
81
|
if (found) {
|
|
90
|
-
|
|
82
|
+
const [projectName, projectConfig] = found;
|
|
91
83
|
result.set(cargoId, {
|
|
92
84
|
...projectConfig,
|
|
93
85
|
name: projectName
|
|
@@ -96,5 +88,14 @@ function mapCargoProjects(ctx, packages) {
|
|
|
96
88
|
}
|
|
97
89
|
return result;
|
|
98
90
|
}
|
|
91
|
+
function getCargoMetadata(cwd) {
|
|
92
|
+
const availableMemory = os__namespace.freemem();
|
|
93
|
+
const metadata = cp__namespace.execSync("cargo metadata --format-version=1 --no-deps", {
|
|
94
|
+
encoding: "utf8",
|
|
95
|
+
maxBuffer: availableMemory,
|
|
96
|
+
cwd
|
|
97
|
+
});
|
|
98
|
+
return JSON.parse(metadata);
|
|
99
|
+
}
|
|
99
100
|
|
|
100
101
|
exports.createDependencies = createDependencies;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { CreateDependenciesContext, RawProjectGraphDependency } from '@nx/devkit';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Main Nx Dependency Creator
|
|
5
|
+
*/
|
|
3
6
|
declare function createDependencies(_: unknown, ctx: CreateDependenciesContext): RawProjectGraphDependency[];
|
|
4
7
|
|
|
5
8
|
export { createDependencies };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { CreateDependenciesContext, RawProjectGraphDependency } from '@nx/devkit';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Main Nx Dependency Creator
|
|
5
|
+
*/
|
|
3
6
|
declare function createDependencies(_: unknown, ctx: CreateDependenciesContext): RawProjectGraphDependency[];
|
|
4
7
|
|
|
5
8
|
export { createDependencies };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { CreateDependenciesContext, RawProjectGraphDependency } from '@nx/devkit';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Main Nx Dependency Creator
|
|
5
|
+
*/
|
|
3
6
|
declare function createDependencies(_: unknown, ctx: CreateDependenciesContext): RawProjectGraphDependency[];
|
|
4
7
|
|
|
5
8
|
export { createDependencies };
|
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,45 @@
|
|
|
1
1
|
import { DependencyType } from '@nx/devkit';
|
|
2
|
-
import
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
2
|
+
import * as cp from 'child_process';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import * as fs from 'fs';
|
|
6
6
|
|
|
7
7
|
function createDependencies(_, ctx) {
|
|
8
8
|
const allDependencies = [];
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const seenManifestPaths = /* @__PURE__ */ new Set();
|
|
10
|
+
const sortedManifests = Object.values(ctx.projects).map((project) => {
|
|
11
|
+
const filepath = path.resolve(ctx.workspaceRoot, project.root, "Cargo.toml");
|
|
12
|
+
const depth = filepath.split(path.sep).length;
|
|
13
|
+
return { filepath, depth };
|
|
14
|
+
}).filter((manifest) => fs.existsSync(manifest.filepath)).sort((a, b) => a.depth - b.depth);
|
|
15
|
+
for (const { filepath } of sortedManifests) {
|
|
16
|
+
if (seenManifestPaths.has(filepath)) {
|
|
15
17
|
continue;
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
try {
|
|
20
|
+
const metadata = getCargoMetadata(path.dirname(filepath));
|
|
21
|
+
for (const pkg of metadata.packages) {
|
|
22
|
+
seenManifestPaths.add(path.resolve(pkg.manifest_path));
|
|
23
|
+
}
|
|
24
|
+
const workspaceDeps = processWorkspaceMetadata(ctx, metadata);
|
|
25
|
+
allDependencies.push(...workspaceDeps);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.warn(
|
|
28
|
+
`[nx-rust] Skipping ${filepath} due to error:`,
|
|
29
|
+
e instanceof Error ? e.message : e
|
|
30
|
+
);
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
return allDependencies;
|
|
22
34
|
}
|
|
23
35
|
function processWorkspaceMetadata(ctx, metadata) {
|
|
24
|
-
const {
|
|
25
|
-
packages,
|
|
26
|
-
workspace_members: cargoWsMembers,
|
|
27
|
-
resolve: cargoResolve
|
|
28
|
-
} = metadata;
|
|
36
|
+
const { packages, resolve } = metadata;
|
|
29
37
|
const workspacePackages = /* @__PURE__ */ new Map();
|
|
30
|
-
for (const
|
|
31
|
-
|
|
32
|
-
if (pkg) workspacePackages.set(id, pkg);
|
|
38
|
+
for (const pkg of packages) {
|
|
39
|
+
workspacePackages.set(pkg.id, pkg);
|
|
33
40
|
}
|
|
34
41
|
const nxData = mapCargoProjects(ctx, workspacePackages);
|
|
35
|
-
return
|
|
42
|
+
return (resolve?.nodes ?? []).filter(({ id }) => nxData.has(id)).flatMap(({ id: sourceId, dependencies }) => {
|
|
36
43
|
const sourceProject = nxData.get(sourceId);
|
|
37
44
|
const cargoPackage = workspacePackages.get(sourceId);
|
|
38
45
|
const sourceManifest = path.relative(ctx.workspaceRoot, cargoPackage.manifest_path).replace(/\\/g, "/");
|
|
@@ -44,29 +51,16 @@ function processWorkspaceMetadata(ctx, metadata) {
|
|
|
44
51
|
}));
|
|
45
52
|
});
|
|
46
53
|
}
|
|
47
|
-
function getCargoMetadata(cwd) {
|
|
48
|
-
const availableMemory = os.freemem();
|
|
49
|
-
const metadata = cp.execSync("cargo metadata --format-version=1", {
|
|
50
|
-
encoding: "utf8",
|
|
51
|
-
maxBuffer: availableMemory,
|
|
52
|
-
cwd
|
|
53
|
-
// Crucial: run in the workspace directory
|
|
54
|
-
});
|
|
55
|
-
return JSON.parse(metadata);
|
|
56
|
-
}
|
|
57
54
|
function mapCargoProjects(ctx, packages) {
|
|
58
|
-
|
|
59
|
-
for (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let manifestDir = path.dirname(cargoPackage.manifest_path);
|
|
64
|
-
let projectDir = path.relative(ctx.workspaceRoot, manifestDir).replace(/\\/g, "/");
|
|
65
|
-
let found = Object.entries(ctx.projects).find(
|
|
55
|
+
const result = /* @__PURE__ */ new Map();
|
|
56
|
+
for (const [cargoId, cargoPackage] of packages) {
|
|
57
|
+
const manifestDir = path.dirname(cargoPackage.manifest_path);
|
|
58
|
+
const projectDir = path.relative(ctx.workspaceRoot, manifestDir).replace(/\\/g, "/");
|
|
59
|
+
const found = Object.entries(ctx.projects).find(
|
|
66
60
|
([, config]) => config.root === projectDir
|
|
67
61
|
);
|
|
68
62
|
if (found) {
|
|
69
|
-
|
|
63
|
+
const [projectName, projectConfig] = found;
|
|
70
64
|
result.set(cargoId, {
|
|
71
65
|
...projectConfig,
|
|
72
66
|
name: projectName
|
|
@@ -75,5 +69,14 @@ function mapCargoProjects(ctx, packages) {
|
|
|
75
69
|
}
|
|
76
70
|
return result;
|
|
77
71
|
}
|
|
72
|
+
function getCargoMetadata(cwd) {
|
|
73
|
+
const availableMemory = os.freemem();
|
|
74
|
+
const metadata = cp.execSync("cargo metadata --format-version=1 --no-deps", {
|
|
75
|
+
encoding: "utf8",
|
|
76
|
+
maxBuffer: availableMemory,
|
|
77
|
+
cwd
|
|
78
|
+
});
|
|
79
|
+
return JSON.parse(metadata);
|
|
80
|
+
}
|
|
78
81
|
|
|
79
82
|
export { createDependencies };
|