@smoothbricks/nx-plugin 0.7.11 → 0.7.13

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 (108) hide show
  1. package/README.md +87 -25
  2. package/dist/.build-inputs.json +25 -17
  3. package/dist/built-output-packages.d.ts +27 -0
  4. package/dist/built-output-packages.d.ts.map +1 -0
  5. package/dist/built-output-packages.js +97 -0
  6. package/dist/cross-check-policy.d.ts +13 -1
  7. package/dist/cross-check-policy.d.ts.map +1 -1
  8. package/dist/cross-check-policy.js +13 -1
  9. package/dist/executors/bounded-exec/admission-queue.d.ts +68 -0
  10. package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -0
  11. package/dist/executors/bounded-exec/admission-queue.js +131 -0
  12. package/dist/executors/bounded-exec/cpu-grant.d.ts +14 -0
  13. package/dist/executors/bounded-exec/cpu-grant.d.ts.map +1 -0
  14. package/dist/executors/bounded-exec/cpu-grant.js +18 -0
  15. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +5 -4
  16. package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
  17. package/dist/executors/bounded-exec/cpu-pool.d.ts +26 -24
  18. package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
  19. package/dist/executors/bounded-exec/cpu-pool.js +88 -72
  20. package/dist/executors/bounded-exec/executor.d.ts +5 -7
  21. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  22. package/dist/executors/bounded-exec/executor.js +69 -133
  23. package/dist/executors/bounded-exec/host-memory.d.ts +22 -0
  24. package/dist/executors/bounded-exec/host-memory.d.ts.map +1 -1
  25. package/dist/executors/bounded-exec/host-memory.darwin.d.ts.map +1 -1
  26. package/dist/executors/bounded-exec/host-memory.darwin.js +7 -1
  27. package/dist/executors/bounded-exec/host-memory.js +6 -0
  28. package/dist/executors/bounded-exec/host-memory.linux.d.ts +3 -1
  29. package/dist/executors/bounded-exec/host-memory.linux.d.ts.map +1 -1
  30. package/dist/executors/bounded-exec/host-memory.linux.js +43 -1
  31. package/dist/executors/bounded-exec/memory-retry.d.ts +39 -0
  32. package/dist/executors/bounded-exec/memory-retry.d.ts.map +1 -0
  33. package/dist/executors/bounded-exec/memory-retry.js +33 -0
  34. package/dist/executors/bounded-exec/parent-grant.d.ts +43 -0
  35. package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -0
  36. package/dist/executors/bounded-exec/parent-grant.js +37 -0
  37. package/dist/executors/bounded-exec/peak-charge.d.ts +17 -0
  38. package/dist/executors/bounded-exec/peak-charge.d.ts.map +1 -0
  39. package/dist/executors/bounded-exec/peak-charge.js +20 -0
  40. package/dist/executors/bounded-exec/pool-admission.d.ts +31 -7
  41. package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
  42. package/dist/executors/bounded-exec/pool-admission.js +44 -8
  43. package/dist/executors/bounded-exec/pool-environment.d.ts +25 -0
  44. package/dist/executors/bounded-exec/pool-environment.d.ts.map +1 -0
  45. package/dist/executors/bounded-exec/pool-environment.js +34 -0
  46. package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
  47. package/dist/executors/bounded-exec/run-cpu-pool.js +2 -2
  48. package/dist/executors/bounded-exec/verdict.d.ts +5 -18
  49. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  50. package/dist/executors/bounded-exec/verdict.js +12 -16
  51. package/dist/index.d.ts +4 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +62 -21
  54. package/dist/managed-files/ci-workflow.d.ts +29 -5
  55. package/dist/managed-files/ci-workflow.d.ts.map +1 -1
  56. package/dist/managed-files/ci-workflow.js +111 -16
  57. package/dist/managed-files/context.d.ts.map +1 -1
  58. package/dist/managed-files/context.js +1 -0
  59. package/dist/managed-files/files.d.ts +3 -1
  60. package/dist/managed-files/files.d.ts.map +1 -1
  61. package/dist/managed-files/files.js +2 -0
  62. package/dist/managed-files/publish-workflow.d.ts +6 -1
  63. package/dist/managed-files/publish-workflow.d.ts.map +1 -1
  64. package/dist/managed-files/publish-workflow.js +16 -11
  65. package/dist/owned-installation.d.ts.map +1 -1
  66. package/dist/owned-installation.js +48 -14
  67. package/dist/typecheck-route.d.ts +28 -0
  68. package/dist/typecheck-route.d.ts.map +1 -0
  69. package/dist/typecheck-route.js +109 -0
  70. package/dist/workspace-manifest.d.ts +50 -5
  71. package/dist/workspace-manifest.d.ts.map +1 -1
  72. package/executors.json +10 -0
  73. package/managed/raw/patches/nx@24.0.3.patch +16 -0
  74. package/managed/raw/patches/ttsc@0.34.1.patch +93 -8
  75. package/managed/raw/tooling/direnv/apple-developer.sh +8 -1
  76. package/managed/raw/tooling/direnv/compiler-variables.sh +1 -1
  77. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +4 -2
  78. package/managed/raw/tooling/direnv/secret-references.ts +19 -5
  79. package/managed/raw/tooling/git-hooks/pre-push.sh +20 -10
  80. package/managed/templates/github/actions/forgejo-artifact.cjs +9 -9
  81. package/managed/templates/github/actions/setup-devenv/action.yml +53 -0
  82. package/package.json +2 -2
  83. package/src/built-output-packages.ts +125 -0
  84. package/src/cross-check-policy.ts +14 -1
  85. package/src/executors/bounded-exec/admission-queue.ts +163 -0
  86. package/src/executors/bounded-exec/cpu-grant.ts +32 -0
  87. package/src/executors/bounded-exec/cpu-pool-thread.ts +5 -4
  88. package/src/executors/bounded-exec/cpu-pool.ts +123 -58
  89. package/src/executors/bounded-exec/executor.ts +93 -168
  90. package/src/executors/bounded-exec/host-memory.darwin.ts +7 -1
  91. package/src/executors/bounded-exec/host-memory.linux.ts +42 -2
  92. package/src/executors/bounded-exec/host-memory.ts +25 -0
  93. package/src/executors/bounded-exec/memory-retry.ts +63 -0
  94. package/src/executors/bounded-exec/parent-grant.ts +75 -0
  95. package/src/executors/bounded-exec/peak-charge.ts +25 -0
  96. package/src/executors/bounded-exec/pool-admission.ts +66 -11
  97. package/src/executors/bounded-exec/pool-environment.ts +45 -0
  98. package/src/executors/bounded-exec/run-cpu-pool.ts +5 -4
  99. package/src/executors/bounded-exec/verdict.ts +17 -25
  100. package/src/index.ts +70 -21
  101. package/src/managed-files/ci-workflow.ts +143 -16
  102. package/src/managed-files/context.ts +1 -0
  103. package/src/managed-files/files.ts +5 -0
  104. package/src/managed-files/publish-workflow.ts +26 -10
  105. package/src/owned-installation.ts +63 -14
  106. package/src/typecheck-route.ts +64 -0
  107. package/src/workspace-manifest.ts +56 -5
  108. package/test-timings.json +141 -137
@@ -9,14 +9,17 @@ import {
9
9
  } from '../cross-check-policy.js';
10
10
  import { PRODUCTION_PUSH_DEPLOY_TAG } from '../deploy-policy.js';
11
11
  import type {
12
+ LiteralCacheOrigin,
12
13
  NonEmptyArray,
13
14
  PackageCargoCredentialsConfig,
14
15
  PackageCargoGitOrigin,
16
+ PackageMbxRemoteConfig,
15
17
  PackagePrivateNpmConfig,
16
18
  PackageRemoteCacheConfig,
17
19
  PackageSmooGithub,
18
20
  PackageSmooGithubEnvironments,
19
21
  PackageSourceCheckoutConfig,
22
+ VariableCacheOrigin,
20
23
  } from '../workspace-manifest.js';
21
24
  import { renderRunsOnLine } from './github-runs-on.js';
22
25
 
@@ -146,6 +149,11 @@ export interface CiWorkflowDefinitionOptions extends DeployStepSecretConfig {
146
149
  * cache serves the whole fleet. Absent means each runner caches locally.
147
150
  */
148
151
  remoteCache?: PackageRemoteCacheConfig;
152
+ /**
153
+ * Declared mbx remote cache (package.json `smoo.mbxRemote`). Every job carries mbx's remote settings, which is
154
+ * what makes setup-devenv route Cargo through mbx. Absent means Cargo builds without mbx.
155
+ */
156
+ mbxRemote?: PackageMbxRemoteConfig;
149
157
  /** GitHub Environments: staging for the validate/e2e jobs, production for the production-on-push job. */
150
158
  environments?: PackageSmooGithubEnvironments;
151
159
  /** Secrets for the e2e-deployment step, env var name → repository secret name. */
@@ -316,7 +324,10 @@ jobs:
316
324
  ${renderRunsOnLine(options.runsOn)}
317
325
  timeout-minutes: 45
318
326
  ${
319
- options.privateNpm?.readTokenEnv || options.cargoCredentials !== undefined || options.remoteCache !== undefined
327
+ options.privateNpm?.readTokenEnv ||
328
+ options.cargoCredentials !== undefined ||
329
+ options.remoteCache !== undefined ||
330
+ options.mbxRemote !== undefined
320
331
  ? ` # Fork PRs receive no secrets, so neither a private dependency install nor an
321
332
  # authenticated remote cache read can run there.
322
333
  if: \${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
@@ -330,7 +341,7 @@ ${
330
341
  : ''
331
342
  } env:
332
343
  GH_TOKEN: ${githubExpression('github.token')}
333
- ${remoteCacheJobEnvLines(options.remoteCache)}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
344
+ ${remoteCacheJobEnvLines(options.remoteCache, 'internal')}${mbxRemoteJobEnvLines(options.mbxRemote, 'internal')}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
334
345
  `;
335
346
  }
336
347
 
@@ -679,30 +690,58 @@ export function normalizeSourceCheckout(config: PackageSourceCheckoutConfig): Pa
679
690
  * fail every task on 401, which is why the job carries the same fork-PR gate
680
691
  * as a private dependency install (see `renderCiWorkflowHeader`).
681
692
  *
682
- * A declared `internalServer` is the address managed runners use, exactly as a
683
- * git origin's `internalMirror` is: both say this repository's runners sit
684
- * inside that network, and shells outside it keep the public origin.
693
+ * A declared `internalServer` is the address the repository's own runners use, exactly as a git origin's
694
+ * `internalMirror` is: both say those runners sit inside that network. A job on any other runner — a GitHub-hosted
695
+ * one, a macOS label — sits outside it and reaches the public `server`, as a developer shell does. Each job names
696
+ * its reach, so no job is pointed at an address its runner cannot route to.
685
697
  * Mechanism errors surface at managed-file render time, never inside CI.
686
698
  */
687
- export function remoteCacheJobEnvLines(config: PackageRemoteCacheConfig | undefined): string {
699
+ export function remoteCacheJobEnvLines(config: PackageRemoteCacheConfig | undefined, reach: CacheReach): string {
688
700
  if (config === undefined) {
689
701
  return '';
690
702
  }
691
703
  const normalized = normalizeRemoteCache(config);
704
+ const server =
705
+ reach === 'internal' ? (normalized.internalServer ?? publicCacheOrigin(normalized)) : publicCacheOrigin(normalized);
692
706
  return [
693
- ` NX_SELF_HOSTED_REMOTE_CACHE_SERVER: ${normalized.internalServer ?? normalized.server}\n`,
707
+ ` NX_SELF_HOSTED_REMOTE_CACHE_SERVER: ${server}\n`,
694
708
  ` NX_SELF_HOSTED_REMOTE_CACHE_ACCESS_TOKEN: ${githubExpression(`secrets.${normalized.tokenSecret}`)}\n`,
695
709
  ].join('');
696
710
  }
697
711
 
712
+ /**
713
+ * Which origin of a declared remote cache a job reaches: `internal` for a job on the repository's own runners
714
+ * (`smoo.github.runsOn`), inside the network `internalServer` names; `public` for any other runner, which reaches
715
+ * only `server`.
716
+ */
717
+ export type CacheReach = 'internal' | 'public';
718
+
719
+ /**
720
+ * The public origin as a job env value: the declared origin, or the expression that reads the repository variable
721
+ * naming it.
722
+ */
723
+ function publicCacheOrigin(config: LiteralCacheOrigin | VariableCacheOrigin): string {
724
+ return 'serverVariable' in config ? githubExpression(`vars.${config.serverVariable}`) : config.server;
725
+ }
726
+
698
727
  /** Mechanism errors surface at managed-file render time, never inside CI. */
699
728
  export function normalizeRemoteCache(config: PackageRemoteCacheConfig): PackageRemoteCacheConfig {
700
- assertCacheOrigin('server', config.server);
729
+ const literal = 'server' in config ? config.server : undefined;
730
+ if ('server' in config && 'serverVariable' in config) {
731
+ throw new Error('smoo.remoteCache names its public origin twice; declare server or serverVariable, not both');
732
+ }
733
+ if (literal !== undefined) {
734
+ assertCacheOrigin('smoo.remoteCache', 'server', literal);
735
+ } else if (!('serverVariable' in config) || !/^[A-Z_][A-Z0-9_]*$/.test(config.serverVariable)) {
736
+ throw new Error(
737
+ `smoo.remoteCache needs server, or an upper-case repository variable name for serverVariable, got ${JSON.stringify(config)}`,
738
+ );
739
+ }
701
740
  if (config.internalServer !== undefined) {
702
- assertCacheOrigin('internalServer', config.internalServer);
703
- if (config.internalServer === config.server) {
741
+ assertCacheOrigin('smoo.remoteCache', 'internalServer', config.internalServer);
742
+ if (config.internalServer === literal) {
704
743
  throw new Error(
705
- `smoo.remoteCache internalServer repeats server ${config.server}; drop internalServer or point it at the address internal runners reach`,
744
+ `smoo.remoteCache internalServer repeats server ${literal}; drop internalServer or point it at the address internal runners reach`,
706
745
  );
707
746
  }
708
747
  }
@@ -720,7 +759,7 @@ export function normalizeRemoteCache(config: PackageRemoteCacheConfig): PackageR
720
759
  * slash the server routes nowhere, and a path or credential would be dropped
721
760
  * or leaked rather than honored.
722
761
  */
723
- function assertCacheOrigin(field: 'server' | 'internalServer', value: string): void {
762
+ function assertCacheOrigin(declaration: string, field: 'server' | 'internalServer', value: string): void {
724
763
  let url: URL | null = null;
725
764
  try {
726
765
  url = new URL(value);
@@ -738,7 +777,95 @@ function assertCacheOrigin(field: 'server' | 'internalServer', value: string): v
738
777
  url.hash !== ''
739
778
  ) {
740
779
  throw new Error(
741
- `smoo.remoteCache ${field} needs a credential-free http(s) origin with no path and no trailing slash, got ${JSON.stringify(value)}`,
780
+ `${declaration} ${field} needs a credential-free http(s) origin with no path and no trailing slash, got ${JSON.stringify(value)}`,
781
+ );
782
+ }
783
+ }
784
+
785
+ /**
786
+ * The default branch's own runs: a push to it, or a workflow dispatched on it (a release). These are the only lanes
787
+ * given the mbx write token. A pull request's ref is never the default branch, and `pull_request_target` is left out
788
+ * because its ref is the base branch while the code it runs is not.
789
+ */
790
+ const DEFAULT_BRANCH_LANE =
791
+ "(github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)";
792
+
793
+ /**
794
+ * Job env lines carrying the declared mbx remote cache (`smoo.mbxRemote`). setup-devenv routes Cargo through mbx's
795
+ * Cargo shim when `MBX_REMOTE_URL` is set, so these lines are what turn mbx on for the job; `reach` picks the origin
796
+ * exactly as for the Nx cache. The token is chosen by lane: the write token and `MBX_REMOTE_TRUST_WRITES` on the
797
+ * default branch's own runs, the read-only token everywhere else. mbx's own write policy cannot make that call here:
798
+ * it requires `GITHUB_REF_PROTECTED`, which Forgejo Actions never sets, and it reads a release's `workflow_dispatch`
799
+ * as untrusted. The server's grant on the token is what stops any other job publishing.
800
+ * Mechanism errors surface at managed-file render time, never inside CI.
801
+ */
802
+ export function mbxRemoteJobEnvLines(config: PackageMbxRemoteConfig | undefined, reach: CacheReach): string {
803
+ if (config === undefined) {
804
+ return '';
805
+ }
806
+ const normalized = normalizeMbxRemote(config);
807
+ const server =
808
+ reach === 'internal' ? (normalized.internalServer ?? publicCacheOrigin(normalized)) : publicCacheOrigin(normalized);
809
+ const token = `${DEFAULT_BRANCH_LANE} && secrets.${normalized.writeTokenSecret} || secrets.${normalized.readTokenSecret}`;
810
+ return [
811
+ ` MBX_REMOTE_URL: ${server}\n`,
812
+ ` MBX_REMOTE_NAMESPACE: ${normalized.namespace}\n`,
813
+ // One expression per line: a folded scalar would split the lane condition, and Prettier refolds it otherwise.
814
+ ' # prettier-ignore\n',
815
+ ` MBX_REMOTE_TOKEN: ${githubExpression(token)}\n`,
816
+ ' # prettier-ignore\n',
817
+ ` MBX_REMOTE_TRUST_WRITES: ${githubExpression(DEFAULT_BRANCH_LANE)}\n`,
818
+ ].join('');
819
+ }
820
+
821
+ /** Mechanism errors surface at managed-file render time, never inside CI. */
822
+ export function normalizeMbxRemote(config: PackageMbxRemoteConfig): PackageMbxRemoteConfig {
823
+ if ('server' in config && 'serverVariable' in config) {
824
+ throw new Error('smoo.mbxRemote names its public origin twice; declare server or serverVariable, not both');
825
+ }
826
+ if ('server' in config) {
827
+ assertMbxOrigin('server', config.server);
828
+ } else if (!/^[A-Z_][A-Z0-9_]*$/.test(config.serverVariable)) {
829
+ throw new Error(
830
+ `smoo.mbxRemote needs server, or an upper-case repository variable name for serverVariable, got ${JSON.stringify(config)}`,
831
+ );
832
+ }
833
+ if (config.internalServer !== undefined) {
834
+ assertMbxOrigin('internalServer', config.internalServer);
835
+ }
836
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*(\/[A-Za-z0-9][A-Za-z0-9._-]*)*$/.test(config.namespace)) {
837
+ throw new Error(
838
+ `smoo.mbxRemote namespace must be slash-separated segments of letters, digits, '.', '_' and '-', got ${JSON.stringify(config.namespace)}`,
839
+ );
840
+ }
841
+ for (const [field, name] of [
842
+ ['writeTokenSecret', config.writeTokenSecret],
843
+ ['readTokenSecret', config.readTokenSecret],
844
+ ] as const) {
845
+ if (!/^[A-Z_][A-Z0-9_]*$/.test(name)) {
846
+ throw new Error(`smoo.mbxRemote needs an upper-case secret name for ${field}, got ${JSON.stringify(name)}`);
847
+ }
848
+ }
849
+ if (config.writeTokenSecret === config.readTokenSecret) {
850
+ throw new Error(
851
+ `smoo.mbxRemote writeTokenSecret and readTokenSecret both name ${config.writeTokenSecret}; untrusted jobs would hold the write token`,
852
+ );
853
+ }
854
+ return config;
855
+ }
856
+
857
+ /**
858
+ * An mbx origin is a cache origin mbx will send its token to: HTTPS, or plain HTTP to a loopback address only, which
859
+ * is mbx's own rule (it refuses the remote otherwise), checked here so a bad declaration fails at render time.
860
+ */
861
+ function assertMbxOrigin(field: 'server' | 'internalServer', value: string): void {
862
+ assertCacheOrigin('smoo.mbxRemote', field, value);
863
+ const url = new URL(value);
864
+ const loopback =
865
+ url.hostname === 'localhost' || url.hostname === '[::1]' || /^127\.\d+\.\d+\.\d+$/.test(url.hostname);
866
+ if (url.protocol === 'http:' && !loopback) {
867
+ throw new Error(
868
+ `smoo.mbxRemote ${field} ${JSON.stringify(value)} is plain HTTP to a non-loopback host; mbx sends its token only over HTTPS or to loopback`,
742
869
  );
743
870
  }
744
871
  }
@@ -1268,7 +1395,7 @@ ${options.macosRunsOn === undefined ? ' runs-on: macos-latest' : renderRunsOn
1268
1395
  if: \${{ needs.main.result == 'success' }}
1269
1396
  env:
1270
1397
  GH_TOKEN: \${{ github.token }}
1271
- ${remoteCacheJobEnvLines(options.remoteCache)}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
1398
+ ${remoteCacheJobEnvLines(options.remoteCache, 'public')}${mbxRemoteJobEnvLines(options.mbxRemote, 'public')}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
1272
1399
  ${renderCiWorkflowSteps(followUpSetupSteps(options, numbers), options)}
1273
1400
  ${renderCiWorkflowSteps(middleSteps, options)}
1274
1401
  ${renderCiWorkflowSteps(followUpCleanupStep(numbers), options)}`;
@@ -1366,7 +1493,7 @@ ${renderRunsOnLine(options.runsOn)}
1366
1493
  ${environmentLine(options.environments?.staging)} if: \${{ needs.main.result == 'success' && needs.main.outputs.deployment-stage != '' }}
1367
1494
  env:
1368
1495
  GH_TOKEN: \${{ github.token }}
1369
- ${remoteCacheJobEnvLines(options.remoteCache)}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
1496
+ ${remoteCacheJobEnvLines(options.remoteCache, 'internal')}${mbxRemoteJobEnvLines(options.mbxRemote, 'internal')}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
1370
1497
  ${renderCiWorkflowSteps(followUpSetupSteps(options, numbers), options)}
1371
1498
  # Step ${numbers.middle}
1372
1499
  - name: E2E Tests (Deployed Stage)
@@ -1398,7 +1525,7 @@ ${renderRunsOnLine(options.runsOn)}
1398
1525
  if: \${{ !cancelled() && github.event_name == 'push' && github.ref == ${stagingRefLiteral(options)} && needs.main.result == 'success'${e2eGate} }}
1399
1526
  ${environmentLine(options.environments?.production)} env:
1400
1527
  GH_TOKEN: \${{ github.token }}
1401
- ${remoteCacheJobEnvLines(options.remoteCache)}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
1528
+ ${remoteCacheJobEnvLines(options.remoteCache, 'internal')}${mbxRemoteJobEnvLines(options.mbxRemote, 'internal')}${cargoCredentialJobEnvLines(options.cargoCredentials)}${privateNpmReadTokenJobEnv(options)} steps:
1402
1529
  ${renderCiWorkflowSteps(followUpSetupSteps(options, numbers), options)}
1403
1530
  # Step ${numbers.middle}
1404
1531
  - name: 🚀 Deploy Production
@@ -77,6 +77,7 @@ export function deriveManagedFileContext(
77
77
  sourceCheckouts,
78
78
  cargoCredentials,
79
79
  remoteCache: manifest?.smoo?.remoteCache,
80
+ mbxRemote: manifest?.smoo?.mbxRemote,
80
81
  macosPlatformArchitectures: MACOS_PLATFORM_TARGET_GLOBS.some((glob) => releasePlatformTargetGlobs.includes(glob))
81
82
  ? macosPlatformArchitecturesForTest(targetNames)
82
83
  : [],
@@ -4,6 +4,7 @@ import { managedAssetsRoot } from '../managed-assets.js';
4
4
  import type {
5
5
  NonEmptyArray,
6
6
  PackageCargoCredentialsConfig,
7
+ PackageMbxRemoteConfig,
7
8
  PackagePrivateNpmConfig,
8
9
  PackageRemoteCacheConfig,
9
10
  PackageSmooGithub,
@@ -59,6 +60,8 @@ export interface ManagedFileContext {
59
60
  cargoCredentials?: PackageCargoCredentialsConfig;
60
61
  /** Declared self-hosted Nx remote cache from the root smoo config; absent means local caching only. */
61
62
  remoteCache?: PackageRemoteCacheConfig;
63
+ /** Declared mbx remote cache from the root smoo config; absent means Cargo builds without mbx. */
64
+ mbxRemote?: PackageMbxRemoteConfig;
62
65
  /**
63
66
  * Cross-built test archives the graph can produce, one per foreign target
64
67
  * triple the cargo workspace declares. Empty for a repository that declares
@@ -380,6 +383,7 @@ function getManagedContent(file: ManagedFileDescriptor, context: ManagedFileCont
380
383
  sourceCheckouts: context.sourceCheckouts,
381
384
  cargoCredentials: context.cargoCredentials,
382
385
  remoteCache: context.remoteCache,
386
+ mbxRemote: context.mbxRemote,
383
387
  environments: context.ciEnvironments,
384
388
  deploySecrets: context.ciDeploySecrets,
385
389
  e2eSecrets: context.ciE2eSecrets,
@@ -407,6 +411,7 @@ function getManagedContent(file: ManagedFileDescriptor, context: ManagedFileCont
407
411
  sourceCheckouts: context.sourceCheckouts,
408
412
  cargoCredentials: context.cargoCredentials,
409
413
  remoteCache: context.remoteCache,
414
+ mbxRemote: context.mbxRemote,
410
415
  deploySecrets: context.ciDeploySecrets,
411
416
  });
412
417
  }
@@ -9,6 +9,7 @@ import {
9
9
  } from '../platform-targets.js';
10
10
  import type {
11
11
  PackageCargoCredentialsConfig,
12
+ PackageMbxRemoteConfig,
12
13
  PackagePrivateNpmConfig,
13
14
  PackageRemoteCacheConfig,
14
15
  PackageSmooGithub,
@@ -17,6 +18,7 @@ import type {
17
18
  import { isSmoothBricksCodebasePackageName } from '../workspace-package-policy.js';
18
19
  import {
19
20
  artifactStepLines,
21
+ type CacheReach,
20
22
  CI_JOB_ID,
21
23
  CI_WORKFLOW_NAME,
22
24
  CiWorkflowStepKind,
@@ -25,6 +27,7 @@ import {
25
27
  type DeployStepSecretConfig,
26
28
  deployStepSecretEnvLines,
27
29
  githubActionPins,
30
+ mbxRemoteJobEnvLines,
28
31
  remoteCacheJobEnvLines,
29
32
  sourceCheckoutsStepLines,
30
33
  TRACE_DB_ARTIFACT_GLOB,
@@ -127,6 +130,11 @@ export interface PublishWorkflowDefinitionOptions extends DeployStepSecretConfig
127
130
  * built for the same hashes.
128
131
  */
129
132
  remoteCache?: PackageRemoteCacheConfig;
133
+ /**
134
+ * Declared mbx remote cache. Every job here may build Cargo, so each carries mbx's remote settings; a release
135
+ * dispatched on the default branch publishes what it compiles.
136
+ */
137
+ mbxRemote?: PackageMbxRemoteConfig;
130
138
  }
131
139
 
132
140
  export interface PublishWorkflowInputs {
@@ -527,7 +535,7 @@ ${options.release === false ? renderRunsOnLine(options.runsOn) : publishJobRunsO
527
535
  timeout-minutes: ${options.platformTargetGlobs?.length ? 90 : 45}
528
536
  env:
529
537
  LMAO_GIT_REVISION: ${githubExpression('github.sha')}
530
- GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
538
+ GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options, options.release === false ? 'internal' : publisherReach(options))}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
531
539
  steps:
532
540
  `;
533
541
  }
@@ -821,13 +829,16 @@ function cargoCredentialsJobEnv(options: PublishWorkflowDefinitionOptions): stri
821
829
  }
822
830
 
823
831
  /**
824
- * The remote cache is job env for the same reason: every Nx target in the job
825
- * reads it, and a release build that missed the cache would rebuild what CI
826
- * already built for the identical hashes. Only `${{ secrets.NAME }}` is
827
- * rendered for the token. Malformed declarations throw here, not in CI.
832
+ * The remote caches are job env for the same reason: every Nx target in the job
833
+ * reads the Nx cache and every Cargo build the mbx one, and a release build
834
+ * that missed them would rebuild what CI already built for the identical
835
+ * inputs. Only `${{ secrets.NAME }}` is rendered for a token. Malformed
836
+ * declarations throw here, not in CI.
828
837
  */
829
- function remoteCacheJobEnv(options: PublishWorkflowDefinitionOptions): string {
830
- const rendered = remoteCacheJobEnvLines(options.remoteCache).trimEnd();
838
+ function remoteCacheJobEnv(options: PublishWorkflowDefinitionOptions, reach: CacheReach): string {
839
+ const rendered = (
840
+ remoteCacheJobEnvLines(options.remoteCache, reach) + mbxRemoteJobEnvLines(options.mbxRemote, reach)
841
+ ).trimEnd();
831
842
  return rendered === '' ? '' : `\n${rendered}`;
832
843
  }
833
844
 
@@ -946,7 +957,7 @@ ${renderRunsOnLine(options.runsOn)}
946
957
  release-sha: ${githubExpression('steps.release-state.outputs.sha')}
947
958
  env:
948
959
  LMAO_GIT_REVISION: ${githubExpression('github.sha')}
949
- GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
960
+ GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options, 'internal')}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
950
961
  steps:
951
962
  ${renderLinuxReleaseCandidateSteps(steps, options)}
952
963
 
@@ -958,7 +969,7 @@ ${renderMacosJobHeaderLines(options)}
958
969
  id-token: none
959
970
  env:
960
971
  LMAO_GIT_REVISION: ${githubExpression('github.sha')}
961
- GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
972
+ GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options, options.platformProducer?.kind === 'linux-cross' ? 'internal' : 'public')}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
962
973
  steps:
963
974
  ${renderMacosPlatformSteps(options)}
964
975
 
@@ -972,7 +983,7 @@ ${publishJobRunsOnLine(options)}
972
983
  env:
973
984
  LMAO_GIT_REVISION: ${githubExpression('github.sha')}
974
985
  TTSC_TSGO_BINARY: ${githubExpression('github.workspace')}/node_modules/@typescript/native/bin/tsc
975
- GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options)}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
986
+ GH_TOKEN: ${githubExpression('github.token')}${remoteCacheJobEnv(options, publisherReach(options))}${cargoCredentialsJobEnv(options)}${privateNpmInstallJobEnv(options)}
976
987
  steps:
977
988
  ${renderFinalLinuxPublishSteps(options)}
978
989
  `;
@@ -1544,6 +1555,11 @@ function publishJobRunsOnLine(options: PublishWorkflowDefinitionOptions): string
1544
1555
  return renderRunsOnLine(options.actionsProvider === 'forgejo' ? options.runsOn : GITHUB_HOSTED_LINUX_RUNNER);
1545
1556
  }
1546
1557
 
1558
+ /** The remote-cache reach of the runner publishJobRunsOnLine picks: Forgejo's own runners, or a GitHub-hosted one. */
1559
+ function publisherReach(options: PublishWorkflowDefinitionOptions): CacheReach {
1560
+ return options.actionsProvider === 'forgejo' ? 'internal' : 'public';
1561
+ }
1562
+
1547
1563
  function githubExpression(expression: string): string {
1548
1564
  return ['$', '{{ ', expression, ' }}'].join('');
1549
1565
  }
@@ -9,7 +9,8 @@
9
9
  * test reads it. A fixture must not take an input it does not own.
10
10
  *
11
11
  * So the closure is copied, exactly as the witness's own census resolves it from the workspace that names it: each
12
- * package once, without its `node_modules` and `.git`, each dependency edge relinked beside
12
+ * package once, as the nodes the census holds of it (what it publishes, never its tools' state beside it), each
13
+ * dependency edge relinked beside
13
14
  * its copy as Bun's isolated layout does, the top-level packages' bins in `.bin`. Every copy is a new inode, cloned
14
15
  * where the volume allows and written otherwise, so no link count is shared with anything outside its owner.
15
16
  *
@@ -35,7 +36,21 @@
35
36
  import { spawn } from 'node:child_process';
36
37
  import { randomUUID } from 'node:crypto';
37
38
  import { constants, rmSync } from 'node:fs';
38
- import { cp, mkdir, readdir, readFile, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
39
+ import {
40
+ chmod,
41
+ copyFile,
42
+ cp,
43
+ lstat,
44
+ mkdir,
45
+ readdir,
46
+ readFile,
47
+ readlink,
48
+ realpath,
49
+ rename,
50
+ rm,
51
+ symlink,
52
+ writeFile,
53
+ } from 'node:fs/promises';
39
54
  import { basename, dirname, join, relative, resolve } from 'node:path';
40
55
  import { expandOutputs } from 'nx/src/native';
41
56
  import { readModulePackageJson } from 'nx/src/utils/package-json';
@@ -301,16 +316,49 @@ async function sweep(kept: string, keep: ReadonlySet<string>): Promise<void> {
301
316
  }
302
317
  }
303
318
 
304
- /** Copy the host package root `source` to its place under `root`, with the census's own exclusions. */
305
- function copyPackage(source: string, root: string, { place }: Placement): Promise<void> {
306
- return cp(source, join(root, place), {
307
- recursive: true,
308
- verbatimSymlinks: true,
309
- mode: constants.COPYFILE_FICLONE,
310
- // A package's own .nx is content, not Nx state: @nx/workspace 24.0.3 ships templates under one, and the census
311
- // selects their directories through the package's `files` (expandOutputs), so a copy without them holds less.
312
- filter: (path) => path === source || !['node_modules', '.git'].includes(basename(path)),
313
- });
319
+ /**
320
+ * Make the copy of the host package root `source` at its place under `root` from exactly the nodes the host census
321
+ * holds for it (`censused`, every node of the closure in the census's walk order, a directory before what it holds):
322
+ * for a package declaring `files`, what it publishes, never `node_modules` or `.git`. A censused directory's `.nx` is
323
+ * copied whole: @nx/workspace 24.0.3 ships templates under one, which the census does not walk, but what its `files`
324
+ * select there (expandOutputs) selects the directory that holds it, so a copy without it censuses less. Nothing else of the package root
325
+ * is content of the closure, and a workspace package's root also holds its own tools' state (a `.cache/` its tests
326
+ * write and remove while this copy reads), which a copy of the whole root would race. A link is copied as it reads;
327
+ * the nodes it reaches are the census's own. A file is cloned where the volume allows.
328
+ */
329
+ async function copyPackage(
330
+ source: string,
331
+ root: string,
332
+ { place }: Placement,
333
+ censused: readonly string[],
334
+ ): Promise<void> {
335
+ const target = join(root, place);
336
+ for (const path of censused) {
337
+ if (path !== source && !path.startsWith(`${source}/`)) continue;
338
+ const destination = join(target, relative(source, path));
339
+ const stats = await lstat(path);
340
+ if (stats.isSymbolicLink()) {
341
+ await symlink(await readlink(path), destination);
342
+ } else if (stats.isDirectory()) {
343
+ await mkdir(destination, { recursive: true });
344
+ await chmod(destination, stats.mode & 0o7777);
345
+ // The one absence expected here: most directories hold no .nx.
346
+ const dotNx = join(path, '.nx');
347
+ const held = await lstat(dotNx).catch((error: unknown) => {
348
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return null;
349
+ throw error;
350
+ });
351
+ if (held?.isDirectory()) {
352
+ await cp(dotNx, join(destination, '.nx'), {
353
+ recursive: true,
354
+ verbatimSymlinks: true,
355
+ mode: constants.COPYFILE_FICLONE,
356
+ });
357
+ }
358
+ } else {
359
+ await copyFile(path, destination, constants.COPYFILE_FICLONE);
360
+ }
361
+ }
314
362
  }
315
363
 
316
364
  /** Link every resolution edge of `host` beside its copy under `root`, and the top-level packages' bins in `.bin`. */
@@ -388,6 +436,7 @@ async function proveOrCopy(censusRoot: string, kept: string, inUse: ReadonlySet<
388
436
  );
389
437
  if (host === null) throw new Error(`the Nx installation closure of ${censusRoot} cannot be read: ${unread}`);
390
438
  const placed = await placements(host);
439
+ const censused = host.nodes.map(({ path }) => path);
391
440
  const wanted = holdings(host, censusRoot, new Map([...placed].map(([source, { place }]) => [source, place])));
392
441
  const placesIn = (root: string) => new Map([...placed.values()].map(({ place }) => [join(root, place), place]));
393
442
  // Only a recorded copy is censused: a census of none would resolve the host's packages through the ancestor lookup.
@@ -435,10 +484,10 @@ async function proveOrCopy(censusRoot: string, kept: string, inUse: ReadonlySet<
435
484
  : join(kept, `installation-${randomUUID()}`);
436
485
  if (root === current && stale !== null) {
437
486
  for (const [, { place }] of stale) await rm(join(root, place), { recursive: true, force: true });
438
- await Promise.all(stale.map(([source, placement]) => copyPackage(source, root, placement)));
487
+ await Promise.all(stale.map(([source, placement]) => copyPackage(source, root, placement, censused)));
439
488
  } else {
440
489
  await sweep(kept, inUse);
441
- await Promise.all([...placed].map(([source, placement]) => copyPackage(source, root, placement)));
490
+ await Promise.all([...placed].map(([source, placement]) => copyPackage(source, root, placement, censused)));
442
491
  await linkCopies(censusRoot, root, host, placed);
443
492
  }
444
493
  const census = copyCensus(root, root === current ? (found ?? undefined) : undefined, (detail) => {
@@ -0,0 +1,64 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { join } from 'node:path';
4
+ import typia from 'typia';
5
+
6
+ /**
7
+ * What a package whose ttsc plugin lowers a dialect declares in its manifest, as `smoo.typecheck`: every project that
8
+ * depends on it directly compiles sources the stock checker refuses (a construct the plugin's ProgramPlugin rewrites
9
+ * before emit, its refusal withdrawn through the driver's DiagnosticPlugin seam), so that project's typecheck runs
10
+ * through ttsc, never the pinned native compiler, which cannot judge the dialect.
11
+ */
12
+ export interface DialectTypecheck {
13
+ /** The compiler a dependent project's typecheck runs. */
14
+ readonly compiler: 'ttsc';
15
+ /**
16
+ * The Nx targets (`project:target`) that prepare the plugin binaries ttsc loads, so a typecheck loads built bytes
17
+ * and never compiles the plugin inside the check. The declaring package names them; the inference guesses none.
18
+ */
19
+ readonly dependsOn: readonly string[];
20
+ }
21
+
22
+ /** The one manifest field this module reads. Any other field is the manifest owner's. */
23
+ interface DeclaringManifest {
24
+ readonly smoo?: { readonly typecheck?: DialectTypecheck };
25
+ }
26
+
27
+ const validateManifest = typia.createValidate<DeclaringManifest>();
28
+
29
+ /** A project's typecheck route: the direct dependencies that declare a dialect, and the targets they name, once each. */
30
+ export interface TypecheckRoute {
31
+ readonly declaredBy: readonly string[];
32
+ readonly dependsOn: readonly string[];
33
+ }
34
+
35
+ /**
36
+ * The typecheck route of the project whose manifest is `packageJsonPath`, over its direct dependencies (the ones ttsc
37
+ * discovers plugins on: `dependencies` and `devDependencies`). Each dependency's manifest is the one Node resolution
38
+ * reaches from the project, as ttsc reads it; a dependency that is not installed declares nothing. A manifest that
39
+ * declares `smoo.typecheck` in another shape refuses the inference by its path and the field it got wrong.
40
+ */
41
+ export function typecheckRoute(packageJsonPath: string, dependencies: readonly string[]): TypecheckRoute {
42
+ const declaredBy: string[] = [];
43
+ const dependsOn: string[] = [];
44
+ const lookup = createRequire(packageJsonPath);
45
+ for (const name of new Set(dependencies)) {
46
+ const manifest = (lookup.resolve.paths(name) ?? [])
47
+ .map((root) => join(root, ...name.split('/'), 'package.json'))
48
+ .find((candidate) => existsSync(candidate));
49
+ if (manifest === undefined) continue;
50
+ const checked = validateManifest(JSON.parse(readFileSync(manifest, 'utf-8')));
51
+ if (!checked.success) {
52
+ throw new Error(
53
+ `${manifest}: smoo.typecheck must be { compiler: 'ttsc', dependsOn: ['<project>:<target>', ...] }: ${checked.errors
54
+ .map((error) => `${error.path} expected ${error.expected}`)
55
+ .join('; ')}`,
56
+ );
57
+ }
58
+ const declared = checked.data.smoo?.typecheck;
59
+ if (declared === undefined) continue;
60
+ declaredBy.push(name);
61
+ for (const target of declared.dependsOn) if (!dependsOn.includes(target)) dependsOn.push(target);
62
+ }
63
+ return { declaredBy, dependsOn };
64
+ }