@smoothbricks/nx-plugin 0.3.14 → 0.4.1

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.
Files changed (38) hide show
  1. package/README.md +36 -13
  2. package/dist/bin/smoo-nx-exec.d.ts +3 -0
  3. package/dist/bin/smoo-nx-exec.d.ts.map +1 -0
  4. package/dist/bin/{ensure-built.js → smoo-nx-exec.js} +17 -5
  5. package/dist/bounded-test-policy.d.ts.map +1 -1
  6. package/dist/bounded-test-policy.js +5 -2
  7. package/dist/cargo-workspace.d.ts +15 -1
  8. package/dist/cargo-workspace.d.ts.map +1 -1
  9. package/dist/cargo-workspace.js +113 -8
  10. package/dist/ensure-built.d.ts +3 -0
  11. package/dist/ensure-built.d.ts.map +1 -1
  12. package/dist/ensure-built.js +21 -1
  13. package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
  14. package/dist/executors/typescript-emit/executor.js +20 -2
  15. package/dist/executors/typescript-emit/schema.d.ts +1 -0
  16. package/dist/executors/typescript-emit/schema.d.ts.map +1 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +345 -88
  19. package/dist/package-target-policy.d.ts.map +1 -1
  20. package/dist/package-target-policy.js +2 -1
  21. package/package.json +4 -4
  22. package/src/bin/{ensure-built.ts → smoo-nx-exec.ts} +18 -6
  23. package/src/bounded-test-policy.test.ts +21 -0
  24. package/src/bounded-test-policy.ts +6 -2
  25. package/src/cargo-workspace.test.ts +142 -0
  26. package/src/cargo-workspace.ts +137 -8
  27. package/src/ensure-built.test.ts +121 -21
  28. package/src/ensure-built.ts +23 -1
  29. package/src/executors/typescript-emit/executor.test.ts +37 -1
  30. package/src/executors/typescript-emit/executor.ts +24 -2
  31. package/src/executors/typescript-emit/schema.json +8 -0
  32. package/src/executors/typescript-emit/schema.ts +1 -0
  33. package/src/index.test.ts +177 -10
  34. package/src/index.ts +436 -90
  35. package/src/package-target-policy.test.ts +13 -0
  36. package/src/package-target-policy.ts +2 -1
  37. package/dist/bin/ensure-built.d.ts +0 -3
  38. package/dist/bin/ensure-built.d.ts.map +0 -1
package/README.md CHANGED
@@ -14,6 +14,21 @@ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typeche
14
14
  - Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
15
15
  - aggregate `build` and `lint` targets
16
16
 
17
+ ## Cargo Workspace Layouts
18
+
19
+ The plugin supports both Cargo placements without moving crate sources:
20
+
21
+ - **Package-rooted:** `packages/example/package.json` sits beside `packages/example/Cargo.toml`. The package owns the
22
+ whole Cargo target set, and commands keep `cwd: packages/example`.
23
+ - **Repository-rooted:** the repository `package.json` sits beside the one root `Cargo.toml`, whose members may live
24
+ below several `packages/*` projects. The root Nx project owns the single `cargo-fetch`, `cargo-test-compile`,
25
+ `cargo-lint`, mutation, bench, and sweep targets. Each crate's `cargo-test-<crate>` target and declared Wasm/N-API
26
+ output targets belong to the deepest Nx project directory containing that crate. All Cargo commands run from the
27
+ repository root, select the crate with `-p <crate>`, and share the root `target/`; cross-project dependencies keep the
28
+ runners in one serialization chain. Member and exclude patterns may use `*` and `?` in any path segment (for example,
29
+ `packages/*/crates/*`); unsupported patterns and member patterns that match no directory fail graph construction
30
+ instead of silently omitting crates.
31
+
17
32
  ## Nx Target Naming
18
33
 
19
34
  Target names are `{tool}-{output}` names. Use names like `tsc-js`, `tsdown-js`, and `cargo-wasm`; `build` and `lint` are
@@ -21,9 +36,9 @@ aggregates.
21
36
 
22
37
  Concrete targets come from concrete files:
23
38
 
24
- - `tsc-js` emits transformed JavaScript through a temporary JS-only `ttsc` config, then emits declarations and
25
- declaration maps from the original project with native `tsc`. Direct project references and every cached output lane
26
- are preserved.
39
+ - `tsc-js` emits transformed JavaScript through a temporary JS-only `ttsc` config, restores execute bits on outputs
40
+ declared by `package.json#bin`, then emits declarations and declaration maps from the original project with native
41
+ `tsc`. Direct project references and every cached output lane are preserved.
27
42
  - `typecheck` is inferred from `tsconfig.lib.json` and runs native `tsc -p tsconfig.lib.json --noEmit`.
28
43
  - `typecheck-tests` is inferred from `tsconfig.test.json` and runs `tsc -p tsconfig.test.json --noEmit`. It first
29
44
  rebuilds the current package's `tsc-js` output (or its non-TypeScript `build`) so self-imports resolve after `clean`.
@@ -32,13 +47,14 @@ Concrete targets come from concrete files:
32
47
  the corresponding watch command and makes it depend on `typecheck-tests`.
33
48
  - A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`.
34
49
  `cargo-test-compile` is one workspace `cargo test --no-run`. Each member crate gets a cached `cargo-test-<package>`
35
- run (`cargo nextest run --workspace -E 'package(<crate>)'`, 30s per-test timeout like `bun test --timeout=30000`)
36
- whose inputs are that crate and its path deps, so unchanged crates are skipped. The filterset, rather than
37
- `--package <crate>`, is what makes the run cheap: `--package` re-resolves features for that crate alone, which
38
- fingerprints differently from the workspace build `cargo-test-compile` already paid for and rebuilds it inside the
39
- bounded window. Those runs are chained so two cargos never share `target/`; `napi-debug` sits on that chain after
40
- compile. Clippy uses `--target-dir target/cargo-lint` so lint can overlap tests. Workspaces with `cdylib` member
41
- crates also receive the cacheable `cargo-wasm` output target.
50
+ run (30s per-test timeout like `bun test --timeout=30000`) whose inputs are that crate and its path deps, so unchanged
51
+ crates are skipped. Package-rooted workspaces use `cargo nextest run --workspace -E 'package(<crate>)'`;
52
+ repository-rooted workspaces additionally use `-p <crate>` to bind the runner to the project that owns the crate.
53
+ Per-crate runners accept an empty nextest selection because a valid workspace member may have no tests and a hash
54
+ partition may legitimately be empty. Those runs are chained across project boundaries so two cargos never share
55
+ `target/`; `napi-debug` sits on that chain after compile. Clippy uses `--target-dir target/cargo-lint` so lint can
56
+ overlap tests. A crate declaring `[package.metadata.smoothbricks.wasm-bindgen]` also receives the cacheable
57
+ `cargo-wasm` output target in its owning project.
42
58
  - A crate whose suite outgrows one bounded window declares `[package.metadata.smoothbricks.test] shards = N`, and gets
43
59
  `cargo-test-<package>-shard1..N`, each running `--partition hash:i/N` with the full bound. nextest assigns a test to a
44
60
  shard by hashing its name, so the shards stay an exact partition of the crate as tests and test binaries are added,
@@ -125,13 +141,20 @@ if (result.disposition === 'failed') {
125
141
  }
126
142
  ```
127
143
 
128
- The packaged wrapper performs the build check and then replaces itself with the binary, preserving the binary's
129
- arguments, exit status, and signals:
144
+ The packaged `smoo-nx-exec` wrapper performs the build check and then replaces itself with the binary:
130
145
 
131
146
  ```bash
132
- smoothbricks-ensure-built my-cli:build -- ./packages/my-cli/dist/my-cli argument
147
+ smoo-nx-exec my-cli:build -- ./packages/my-cli/dist/my-cli argument
133
148
  ```
134
149
 
150
+ It is deliberately not `nx run <target> && exec`:
151
+
152
+ - A hit costs one daemon round-trip and a local cache read, not an Nx CLI start.
153
+ - A hit is silent. `nx run` replays the cached log and prints its `[local cache]` banner, which a CLI wrapper must not
154
+ print.
155
+ - It execs the binary, preserving its argv, exit status, and signals. `nx run` has no notion of handing the process over
156
+ to another binary.
157
+
135
158
  Pass `--workspace-root <dir>` before `--` when invoking the wrapper outside the workspace. The binary path resolves
136
159
  against the caller's current directory.
137
160
 
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=smoo-nx-exec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smoo-nx-exec.d.ts","sourceRoot":"","sources":["../../src/bin/smoo-nx-exec.ts"],"names":[],"mappings":""}
@@ -1,13 +1,25 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync } from 'node:fs';
3
3
  import { dirname, isAbsolute, join, resolve } from 'node:path';
4
+ import { inspect } from 'node:util';
4
5
  import { describeMiss, ensureBuilt, parseTargetSelector } from '../ensure-built.js';
5
- const USAGE = 'usage: smoothbricks-ensure-built <project:target[:configuration]> [--workspace-root <dir>] -- <binary> [args...]';
6
+ const USAGE = 'usage: smoo-nx-exec <project:target[:configuration]> [--workspace-root <dir>] -- <binary> [args...]';
6
7
  /** Argument and environment problems all exit 2, the shell's "usage" code. */
7
8
  function usageError(message) {
8
- process.stderr.write(`smoothbricks-ensure-built: ${message}\n${USAGE}\n`);
9
+ process.stderr.write(`smoo-nx-exec: ${message}\n${USAGE}\n`);
9
10
  process.exit(2);
10
11
  }
12
+ function describeError(error) {
13
+ if (error instanceof Error) {
14
+ return error.message;
15
+ }
16
+ if (typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string') {
17
+ return error.message;
18
+ }
19
+ return typeof error === 'string'
20
+ ? error
21
+ : inspect(error, { breakLength: Number.POSITIVE_INFINITY, colors: false, depth: 5 });
22
+ }
11
23
  /**
12
24
  * Split `--flag=value` into two tokens so both spellings parse identically.
13
25
  * Only leading `--` forms are split: a value may legitimately contain `=`.
@@ -82,11 +94,11 @@ if (!command[0].includes('/')) {
82
94
  const binary = isAbsolute(command[0]) ? command[0] : resolve(process.cwd(), command[0]);
83
95
  const workspaceRoot = workspaceRootArg === undefined ? findWorkspaceRoot(process.cwd()) : resolve(process.cwd(), workspaceRootArg);
84
96
  const result = await ensureBuilt({ target, cwd: workspaceRoot }).catch((error) => {
85
- process.stderr.write(`smoothbricks-ensure-built: ${error instanceof Error ? error.message : String(error)}\n`);
97
+ process.stderr.write(`smoo-nx-exec: ${describeError(error)}\n`);
86
98
  process.exit(1);
87
99
  });
88
100
  if (result.disposition !== 'hit' && process.env.NX_VERBOSE_LOGGING === 'true') {
89
- process.stderr.write(`smoothbricks-ensure-built: ran ${target} because ${describeMiss(result.reason)}\n`);
101
+ process.stderr.write(`smoo-nx-exec: ran ${target} because ${describeMiss(result.reason)}\n`);
90
102
  }
91
103
  if (result.disposition === 'failed') {
92
104
  if (result.signal !== null) {
@@ -97,7 +109,7 @@ if (result.disposition === 'failed') {
97
109
  process.exit(result.exitCode);
98
110
  }
99
111
  if (process.execve === undefined) {
100
- throw new Error('smoothbricks-ensure-built needs process.execve, which requires a POSIX host on Node 24+ or Bun');
112
+ throw new Error('smoo-nx-exec needs process.execve, which requires a POSIX host on Node 24+ or Bun');
101
113
  }
102
114
  // `execve`, not spawn-and-wait: the built binary replaces this process, so it
103
115
  // owns the terminal, the signals and the exit status directly, with no wrapper
@@ -1 +1 @@
1
- {"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAErG,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAKjD,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mCAAmC;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,eAAe,CAAC,EAAE,sBAAsB,CAAC;CAC1C;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,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4BAA4B,EACzC,cAAc,SAAa,EAC3B,WAAW,CAAC,EAAE,4BAA4B,GACzC,MAAM,CAER;AA+CD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAmC,GAAG,MAAM,CAa9G"}
@@ -311,6 +311,9 @@ function isNoopAggregateTarget(target) {
311
311
  }
312
312
  return Array.isArray(target.dependsOn) && target.dependsOn.length > 0;
313
313
  }
314
+ function isPositiveSafeInteger(value) {
315
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
316
+ }
314
317
  function isBoundedExecutionTarget(executor, rawOptions, allowedCwds) {
315
318
  if (executor !== BOUNDED_TEST_EXECUTOR || !isRecord(rawOptions)) {
316
319
  return false;
@@ -322,8 +325,8 @@ function isBoundedExecutionTarget(executor, rawOptions, allowedCwds) {
322
325
  command === ensureBunTestTimeoutFlag(command) &&
323
326
  typeof rawOptions.cwd === 'string' &&
324
327
  allowedCwds.has(rawOptions.cwd) &&
325
- rawOptions.timeoutMs === BOUNDED_TEST_TIMEOUT_MS &&
326
- rawOptions.killAfterMs === BOUNDED_TEST_KILL_AFTER_MS);
328
+ isPositiveSafeInteger(rawOptions.timeoutMs) &&
329
+ isPositiveSafeInteger(rawOptions.killAfterMs));
327
330
  }
328
331
  function resolvedAggregateTestIsBounded(project) {
329
332
  if (!project?.targetDependencies || !project.targetExecutors || !project.targetOptions) {
@@ -7,8 +7,22 @@ export interface CargoWorkspacePackage {
7
7
  */
8
8
  testShards: number;
9
9
  }
10
+ export interface CargoWorkspaceProject {
11
+ name: string;
12
+ root: string;
13
+ }
14
+ export interface AttributedCargoWorkspacePackage extends CargoWorkspacePackage {
15
+ projectName: string;
16
+ projectRoot: string;
17
+ }
10
18
  export declare function listCargoWorkspacePackages(absoluteProjectRoot: string): CargoWorkspacePackage[];
11
- export declare function cargoPackageTestInputs(absoluteProjectRoot: string, memberDir: string): Promise<string[]>;
19
+ /**
20
+ * Assign each workspace crate to the most specific Nx project that contains
21
+ * its directory. The repository root is the fallback owner; a nested package
22
+ * wins by path depth so projects under `packages/*` own their own crates.
23
+ */
24
+ export declare function attributeCargoWorkspacePackages(packages: readonly CargoWorkspacePackage[], projects: readonly CargoWorkspaceProject[]): AttributedCargoWorkspacePackage[];
25
+ export declare function cargoPackageTestInputs(absoluteProjectRoot: string, memberDir: string, inputRoot?: string): Promise<string[]>;
12
26
  /**
13
27
  * The aggregate that actually runs a cargo workspace's tests. Named here because
14
28
  * both target inference and the policy that verifies `test` reaches it need the
@@ -1 +1 @@
1
- {"version":3,"file":"cargo-workspace.d.ts","sourceRoot":"","sources":["../src/cargo-workspace.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,0BAA0B,CAAC,mBAAmB,EAAE,MAAM,GAAG,qBAAqB,EAAE,CA8B/F;AAED,wBAAsB,sBAAsB,CAAC,mBAAmB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwB9G;AA6ED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAE9C,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,eAAe,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAGtF;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoB9E;AAED,wB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GAAG,IAAI,CAQhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoB9E;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG1G"}
@@ -1,4 +1,4 @@
1
- import { existsSync, readFileSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { join, normalize, posix, relative, sep } from 'node:path';
4
4
  import { parse as parseToml } from 'smol-toml';
@@ -11,12 +11,30 @@ export function listCargoWorkspacePackages(absoluteProjectRoot) {
11
11
  if (!isRecord(parsed) || !isRecord(parsed.workspace) || !Array.isArray(parsed.workspace.members)) {
12
12
  return [];
13
13
  }
14
- const packages = [];
14
+ const excludedDirs = new Set();
15
+ if (Array.isArray(parsed.workspace.exclude)) {
16
+ for (const excluded of parsed.workspace.exclude) {
17
+ if (typeof excluded === 'string' && excluded.length > 0) {
18
+ for (const excludedDir of expandCargoMemberDirs(absoluteProjectRoot, excluded, false)) {
19
+ excludedDirs.add(excludedDir);
20
+ }
21
+ }
22
+ }
23
+ }
24
+ const packageDirs = new Set();
15
25
  for (const member of parsed.workspace.members) {
16
26
  if (typeof member !== 'string' || member.length === 0) {
17
27
  continue;
18
28
  }
19
- const crateTomlPath = join(absoluteProjectRoot, member, 'Cargo.toml');
29
+ for (const memberDir of expandCargoMemberDirs(absoluteProjectRoot, member)) {
30
+ if (!isExcludedCargoMember(memberDir, excludedDirs)) {
31
+ packageDirs.add(memberDir);
32
+ }
33
+ }
34
+ }
35
+ const packages = [];
36
+ for (const memberDir of packageDirs) {
37
+ const crateTomlPath = join(absoluteProjectRoot, memberDir, 'Cargo.toml');
20
38
  if (!existsSync(crateTomlPath)) {
21
39
  continue;
22
40
  }
@@ -26,14 +44,101 @@ export function listCargoWorkspacePackages(absoluteProjectRoot) {
26
44
  }
27
45
  packages.push({
28
46
  name: crateParsed.package.name,
29
- dir: member.split('\\').join('/'),
47
+ dir: memberDir,
30
48
  testShards: readTestShards(crateParsed.package, crateTomlPath),
31
49
  });
32
50
  }
33
51
  packages.sort((left, right) => left.name.localeCompare(right.name));
34
52
  return packages;
35
53
  }
36
- export async function cargoPackageTestInputs(absoluteProjectRoot, memberDir) {
54
+ function isExcludedCargoMember(memberDir, excludedDirs) {
55
+ for (const excludedDir of excludedDirs) {
56
+ if (memberDir === excludedDir || memberDir.startsWith(`${excludedDir}/`)) {
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ }
62
+ /**
63
+ * Cargo accepts glob patterns at any depth in `workspace.members` and
64
+ * `workspace.exclude`. Walk one path segment at a time so patterns with
65
+ * wildcards in multiple segments cannot silently erase every crate from the
66
+ * Nx graph.
67
+ */
68
+ function expandCargoMemberDirs(absoluteProjectRoot, member, requireGlobMatch = true) {
69
+ const normalized = member.split('\\').join('/').replace(/\/+$/, '');
70
+ const segments = normalized.split('/');
71
+ if (normalized.length === 0 ||
72
+ normalized.startsWith('/') ||
73
+ segments.some((segment) => segment.length === 0 || segment === '.' || segment === '..')) {
74
+ throw new Error(`Cargo workspace member must be a non-empty relative path: ${member}`);
75
+ }
76
+ if (segments.some((segment) => segment === '**' || /[[\]{}!]/.test(segment))) {
77
+ throw new Error(`Cargo workspace member uses an unsupported glob pattern: ${member}`);
78
+ }
79
+ const hasGlob = segments.some((segment) => segment.includes('*') || segment.includes('?'));
80
+ let candidates = [''];
81
+ for (const segment of segments) {
82
+ if (!segment.includes('*') && !segment.includes('?')) {
83
+ candidates = candidates.map((candidate) => posix.join(candidate, segment));
84
+ continue;
85
+ }
86
+ const matcher = cargoGlobSegmentMatcher(segment);
87
+ const expanded = [];
88
+ for (const candidate of candidates) {
89
+ const absoluteParent = join(absoluteProjectRoot, candidate);
90
+ if (!existsSync(absoluteParent)) {
91
+ continue;
92
+ }
93
+ for (const entry of readdirSync(absoluteParent, { withFileTypes: true })) {
94
+ if (entry.isDirectory() && matcher.test(entry.name)) {
95
+ expanded.push(posix.join(candidate, entry.name));
96
+ }
97
+ }
98
+ }
99
+ candidates = expanded;
100
+ }
101
+ if (requireGlobMatch && hasGlob && candidates.length === 0) {
102
+ throw new Error(`Cargo workspace member glob matched no directories: ${member}`);
103
+ }
104
+ return candidates.sort((left, right) => left.localeCompare(right));
105
+ }
106
+ function cargoGlobSegmentMatcher(segment) {
107
+ let source = '^';
108
+ for (const character of segment) {
109
+ if (character === '*') {
110
+ source += '.*';
111
+ }
112
+ else if (character === '?') {
113
+ source += '.';
114
+ }
115
+ else {
116
+ source += character.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&');
117
+ }
118
+ }
119
+ return new RegExp(`${source}$`);
120
+ }
121
+ /**
122
+ * Assign each workspace crate to the most specific Nx project that contains
123
+ * its directory. The repository root is the fallback owner; a nested package
124
+ * wins by path depth so projects under `packages/*` own their own crates.
125
+ */
126
+ export function attributeCargoWorkspacePackages(packages, projects) {
127
+ const bySpecificity = [...projects].sort((left, right) => {
128
+ const leftDepth = left.root === '.' ? 0 : left.root.split('/').length;
129
+ const rightDepth = right.root === '.' ? 0 : right.root.split('/').length;
130
+ return rightDepth - leftDepth || left.name.localeCompare(right.name);
131
+ });
132
+ const attributed = [];
133
+ for (const pkg of packages) {
134
+ const owner = bySpecificity.find((project) => project.root === '.' || pkg.dir === project.root || pkg.dir.startsWith(`${project.root}/`));
135
+ if (owner) {
136
+ attributed.push({ ...pkg, projectName: owner.name, projectRoot: owner.root });
137
+ }
138
+ }
139
+ return attributed;
140
+ }
141
+ export async function cargoPackageTestInputs(absoluteProjectRoot, memberDir, inputRoot = '{projectRoot}') {
37
142
  const workspacePathDeps = await workspacePathDependencies(absoluteProjectRoot);
38
143
  const dirs = new Set([memberDir.split('\\').join('/')]);
39
144
  const crateParsed = parseToml(await readFile(join(absoluteProjectRoot, memberDir, 'Cargo.toml'), 'utf-8'));
@@ -51,11 +156,11 @@ export async function cargoPackageTestInputs(absoluteProjectRoot, memberDir) {
51
156
  }
52
157
  }
53
158
  }
54
- const inputs = ['{projectRoot}/Cargo.toml', '{projectRoot}/Cargo.lock'];
159
+ const inputs = [`${inputRoot}/Cargo.toml`, `${inputRoot}/Cargo.lock`];
55
160
  for (const dir of [...dirs].sort()) {
56
- inputs.push(`{projectRoot}/${dir}/**/*.rs`, `{projectRoot}/${dir}/Cargo.toml`);
161
+ inputs.push(`${inputRoot}/${dir}/**/*.rs`, `${inputRoot}/${dir}/Cargo.toml`);
57
162
  }
58
- inputs.push('{projectRoot}/**/.cargo/config.toml', '{projectRoot}/scripts/*.sh', '!{projectRoot}/**/target/**');
163
+ inputs.push(`${inputRoot}/**/.cargo/config.toml`, `${inputRoot}/scripts/*.sh`, `!${inputRoot}/**/target/**`);
59
164
  return inputs;
60
165
  }
61
166
  async function workspacePathDependencies(absoluteProjectRoot) {
@@ -34,6 +34,9 @@ export type MissReason = {
34
34
  } | {
35
35
  readonly kind: 'stale-outputs';
36
36
  readonly taskId: string;
37
+ } | {
38
+ readonly kind: 'cache-disabled';
39
+ readonly taskId: string;
37
40
  } | {
38
41
  readonly kind: 'no-daemon';
39
42
  readonly taskId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAkCrD;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,Q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W,kBAAkB;IACjC,0DAA0D;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;CAC5B;AAOD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAWvE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAiBvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5C,UAAU,GAAG,IAAI,CAmBnB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,EAAE,OAAO,EAAE,SAAS,OAAO,EAAE,GAAG,UAAU,GAAG,IAAI,CAOxG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAmCzF;AA8TD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;CACxC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,EACf,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,KAAK,MAAM,GACtD,iBAAiB,CAQnB"}
@@ -36,6 +36,8 @@ export function describeMiss(reason) {
36
36
  return `${reason.taskId} last failed with exit code ${reason.code}`;
37
37
  case 'stale-outputs':
38
38
  return `${reason.taskId} outputs are missing or modified on disk`;
39
+ case 'cache-disabled':
40
+ return `the Nx cache is disabled, so ${reason.taskId} must run`;
39
41
  case 'no-daemon':
40
42
  return `the Nx daemon is disabled, so ${reason.taskId} cannot be checked without running it`;
41
43
  }
@@ -153,6 +155,15 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
153
155
  if (!daemonClient.enabled()) {
154
156
  return runViaCli(workspaceRoot, selector);
155
157
  }
158
+ // An outer Nx task exports its own cache-bypass setting to the process it
159
+ // launches. That setting describes the outer task, not the nested target:
160
+ // inheriting it makes the inner runner refuse cache writes forever. Outside
161
+ // an Nx task child, however, the same variables are the caller's explicit
162
+ // request to force this target to rebuild and must remain authoritative.
163
+ if (process.env.NX_TASK_TARGET_PROJECT !== undefined || process.env.NX_TASK_TARGET_TARGET !== undefined) {
164
+ delete process.env.NX_SKIP_NX_CACHE;
165
+ delete process.env.NX_DISABLE_NX_CACHE;
166
+ }
156
167
  const { readNxJson } = requireNx('nx/src/config/nx-json');
157
168
  const { splitArgsIntoNxArgsAndOverrides } = requireNx('nx/src/utils/command-line-utils');
158
169
  const { setEnvVarsBasedOnArgs } = requireNx('nx/src/tasks-runner/run-command');
@@ -181,7 +192,16 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
181
192
  argv: process.argv,
182
193
  });
183
194
  performance.mark('ensureBuilt:probe:start');
184
- const reason = await probe(nxJson, nxArgs, overrides, selector, requireNx);
195
+ let reason;
196
+ if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
197
+ const taskId = selector.configuration === undefined
198
+ ? `${selector.project}:${selector.target}`
199
+ : `${selector.project}:${selector.target}:${selector.configuration}`;
200
+ reason = { kind: 'cache-disabled', taskId };
201
+ }
202
+ else {
203
+ reason = await probe(nxJson, nxArgs, overrides, selector, requireNx);
204
+ }
185
205
  performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
186
206
  const outcome = reason === null
187
207
  ? { result: HIT, taskResults: NO_TASK_RESULTS }
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/executor.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;CAClB;AAMD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAElF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAqC/B"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/executor.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzD,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,oBAAoB;IAC5B,OAAO,EAAE,OAAO,CAAC;CAClB;AAMD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAElF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAuC/B"}
@@ -1,8 +1,8 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { once } from 'node:events';
4
- import { rm, writeFile } from 'node:fs/promises';
5
- import { basename, dirname, isAbsolute, join } from 'node:path';
4
+ import { chmod, rm, stat, writeFile } from 'node:fs/promises';
5
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
6
6
  import { readJsonFile } from 'nx/src/devkit-exports.js';
7
7
  export default function typescriptEmitExecutor(options, context) {
8
8
  return runTypeScriptEmit(options, context, runCompiler);
@@ -33,6 +33,7 @@ export async function runTypeScriptEmit(options, context, runner) {
33
33
  if (!javascriptSucceeded) {
34
34
  return { success: false };
35
35
  }
36
+ await makePackageBinsExecutable(cwd, options.executableOutputs ?? []);
36
37
  const declarationsSucceeded = await runner({
37
38
  command: 'tsc',
38
39
  args: ['-p', overlayPath, '--emitDeclarationOnly', '--declaration', '--declarationMap'],
@@ -44,6 +45,23 @@ export async function runTypeScriptEmit(options, context, runner) {
44
45
  await rm(overlayPath, { force: true });
45
46
  }
46
47
  }
48
+ async function makePackageBinsExecutable(cwd, outputs) {
49
+ for (const output of new Set(outputs)) {
50
+ const outputPath = resolve(cwd, output);
51
+ const projectRelative = relative(cwd, outputPath);
52
+ if (projectRelative.length === 0 ||
53
+ projectRelative === '..' ||
54
+ projectRelative.startsWith(`..${sep}`) ||
55
+ isAbsolute(projectRelative)) {
56
+ throw new Error(`Executable output must stay inside the project: ${output}`);
57
+ }
58
+ const outputStat = await stat(outputPath);
59
+ // TypeScript creates emitted files with the process default mode. A package
60
+ // bin that loses its execute bits is present but unusable through
61
+ // node_modules/.bin, so restore the semantic guarantee declared by `bin`.
62
+ await chmod(outputPath, outputStat.mode | 0o111);
63
+ }
64
+ }
47
65
  async function runCompiler(invocation) {
48
66
  const child = spawn(invocation.command, invocation.args, {
49
67
  cwd: invocation.cwd,
@@ -1,4 +1,5 @@
1
1
  export interface TypeScriptEmitOptions {
2
+ executableOutputs?: string[];
2
3
  cwd: string;
3
4
  tsConfig: string;
4
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/executors/typescript-emit/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;CAClB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EACL,yBAAyB,EAQ1B,MAAM,sBAAsB,CAAC;AAY9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAUrC,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAmED,UAAU,oBAAqB,SAA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