@smoothbricks/nx-plugin 0.4.22 → 0.4.23
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/README.md +77 -21
- package/dist/bin/smoo-nx-exec.js +35 -11
- package/dist/cargo-closure-input.d.ts +63 -0
- package/dist/cargo-closure-input.d.ts.map +1 -0
- package/dist/cargo-closure-input.js +197 -0
- package/dist/cargo-source-hash.d.ts +37 -0
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +108 -190
- package/dist/cross-check-policy.d.ts +14 -0
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +15 -1
- package/dist/ensure-built.d.ts +3 -2
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +33 -56
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -76
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +12 -15
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +10 -0
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +12 -6
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +24 -30
- package/dist/package-target-policy.js +1 -1
- package/dist/platform-targets.d.ts +7 -0
- package/dist/platform-targets.d.ts.map +1 -1
- package/dist/platform-targets.js +7 -0
- package/dist/workspace-config-policy.d.ts +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +1 -1
- package/managed/raw/envrc +38 -1
- package/managed/raw/tooling/direnv/developer-links.ts +201 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +75 -51
- package/managed/raw/tooling/direnv/secret-references.ts +3 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +562 -78
- package/managed/raw/tooling/direnv/shared-caches.sh +53 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +22 -1
- package/managed/templates/github/workflows/managed-files.yml +4 -3
- package/nextest.toml +5 -5
- package/package.json +2 -2
- package/src/__tests__/fixture-nx-env.ts +31 -0
- package/src/__tests__/in-process-nx-index.ts +9 -0
- package/src/bin/smoo-nx-exec.ts +40 -11
- package/src/cargo-closure-input.test.ts +184 -0
- package/src/cargo-closure-input.ts +247 -0
- package/src/cargo-source-hash.test.ts +8 -9
- package/src/cargo-source-hash.ts +146 -47
- package/src/cross-check-policy.ts +15 -3
- package/src/ensure-built.test.ts +65 -5
- package/src/ensure-built.ts +40 -85
- package/src/index.test.ts +94 -53
- package/src/index.ts +164 -84
- package/src/managed-files/ci-workflow.ts +12 -15
- package/src/managed-files/files.ts +10 -0
- package/src/managed-files/generator.test.ts +29 -0
- package/src/managed-files/publish-workflow.ts +17 -6
- package/src/manifest-hash.test.ts +21 -1
- package/src/manifest-hash.ts +26 -29
- package/src/package-target-policy.ts +1 -1
- package/src/platform-targets.ts +8 -0
- package/src/workspace-config-policy.ts +6 -1
package/dist/manifest-hash.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { join,
|
|
4
|
-
import {
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join, posix } from 'node:path';
|
|
4
|
+
import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
5
5
|
/**
|
|
6
6
|
* A release rewrites `version` in every manifest it publishes. Those manifests
|
|
7
7
|
* are inputs of the validation targets, so a publish run misses the cache for
|
|
@@ -145,41 +145,35 @@ export function updateVersionlessCrateManifest(hash, manifest) {
|
|
|
145
145
|
* answer: the dependency the digest describes really did change.
|
|
146
146
|
*/
|
|
147
147
|
export async function hashVersionlessCrateManifests(projectRoot, workspaceRoot) {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const manifests = await Promise.all(paths.map((path) => readFile(join(root, path))));
|
|
148
|
+
const manifests = await Promise.all((await listCrateManifests(projectRoot, workspaceRoot)).map(async (path) => ({
|
|
149
|
+
path,
|
|
150
|
+
bytes: await readFile(join(workspaceRoot, projectRoot, path)),
|
|
151
|
+
})));
|
|
153
152
|
const hash = createHash('sha256');
|
|
154
153
|
hash.update(DIGEST_TAG);
|
|
155
154
|
hash.update(SEPARATOR);
|
|
156
|
-
for (
|
|
157
|
-
hash.update(
|
|
155
|
+
for (const { path, bytes } of manifests) {
|
|
156
|
+
hash.update(path);
|
|
158
157
|
hash.update(SEPARATOR);
|
|
159
|
-
updateVersionlessCrateManifest(hash,
|
|
158
|
+
updateVersionlessCrateManifest(hash, bytes);
|
|
160
159
|
hash.update(SEPARATOR);
|
|
161
160
|
}
|
|
162
161
|
return hash.digest('hex');
|
|
163
162
|
}
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
else if (entry.name === CARGO_MANIFEST) {
|
|
180
|
-
found.push(`${prefix}${entry.name}`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
163
|
+
/**
|
|
164
|
+
* Crate manifest paths relative to the project root, `/`-separated and sorted,
|
|
165
|
+
* so the digest is platform-independent. They come from Nx's own workspace
|
|
166
|
+
* file index — exactly the files the project's `Cargo.toml` exclusion removes
|
|
167
|
+
* from its filesets, with `.gitignore` applied — rather than from a walk of
|
|
168
|
+
* the tree: a walk reads ignored build output, which an Nx cache restore can
|
|
169
|
+
* delete while it is being read. No `catch`: a listing or read that fails
|
|
170
|
+
* would otherwise hash as a smaller manifest set, the silent staleness this
|
|
171
|
+
* module exists to avoid; the caller degrades to the raw manifests instead.
|
|
172
|
+
*/
|
|
173
|
+
async function listCrateManifests(projectRoot, workspaceRoot) {
|
|
174
|
+
const prefix = projectRoot === '.' ? '' : `${posix.normalize(projectRoot)}/`;
|
|
175
|
+
const files = await globWithWorkspaceContext(workspaceRoot, [`${prefix}**/${CARGO_MANIFEST}`]);
|
|
176
|
+
return files.map((file) => file.slice(prefix.length)).sort();
|
|
183
177
|
}
|
|
184
178
|
/** `from` is just past the `[`. */
|
|
185
179
|
function isOwnVersionTable(manifest, from, to) {
|
|
@@ -236,7 +236,7 @@ function isRedundantBuildDeclaration(build, resolvedTargets) {
|
|
|
236
236
|
* Deliberately NOT decided against the resolved project graph. Nx replaces a
|
|
237
237
|
* named property of an inferred target with the declared one, so the resolved
|
|
238
238
|
* `build.dependsOn` IS the declaration: comparing them answered "redundant"
|
|
239
|
-
* for every noop aggregate anyone ever wrote.
|
|
239
|
+
* for every noop aggregate anyone ever wrote. A downstream runtime host lost seven
|
|
240
240
|
* edges that way — four of them targets no inference can reach — and a clean
|
|
241
241
|
* checkout then built it without its producers. The question this has to
|
|
242
242
|
* answer is what inference yields WITHOUT the declaration, so the test is
|
|
@@ -2,4 +2,11 @@
|
|
|
2
2
|
export declare const MACOS_PLATFORM_TARGET_GLOBS: readonly ['*-macos', '*-ios'];
|
|
3
3
|
export declare const LINUX_PLATFORM_TARGET_GLOBS: readonly ['*-linux'];
|
|
4
4
|
export declare const PLATFORM_TARGET_GLOBS: readonly ["*-macos", "*-ios", "*-linux"];
|
|
5
|
+
/**
|
|
6
|
+
* The Nx configuration that builds what ships. A cargo build target's default
|
|
7
|
+
* options compile cargo's `dev` profile, which every local build, test and
|
|
8
|
+
* gate shares; this configuration adds `--release`. Only release tooling
|
|
9
|
+
* selects it, so a shipped artifact is the only thing compiled twice.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RELEASE_CONFIGURATION = "production";
|
|
5
12
|
//# sourceMappingURL=platform-targets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-targets.d.ts","sourceRoot":"","sources":["../src/platform-targets.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AACzE,eAAO,MAAM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC"}
|
|
1
|
+
{"version":3,"file":"platform-targets.d.ts","sourceRoot":"","sources":["../src/platform-targets.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AACzE,eAAO,MAAM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC;AAE/G;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,eAAe,CAAC"}
|
package/dist/platform-targets.js
CHANGED
|
@@ -2,3 +2,10 @@
|
|
|
2
2
|
export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'];
|
|
3
3
|
export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'];
|
|
4
4
|
export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS];
|
|
5
|
+
/**
|
|
6
|
+
* The Nx configuration that builds what ships. A cargo build target's default
|
|
7
|
+
* options compile cargo's `dev` profile, which every local build, test and
|
|
8
|
+
* gate shares; this configuration adds `--release`. Only release tooling
|
|
9
|
+
* selects it, so a shipped artifact is the only thing compiled twice.
|
|
10
|
+
*/
|
|
11
|
+
export const RELEASE_CONFIGURATION = 'production';
|
|
@@ -5,7 +5,7 @@ export interface NxPolicyIssue {
|
|
|
5
5
|
message: string;
|
|
6
6
|
}
|
|
7
7
|
export declare const BUILD_OUTPUT_DEPENDENCIES: readonly ['*-js', '*-web', '*-html', '*-css', '*-android', '*-native', '*-napi', '*-bun', '*-wasm'];
|
|
8
|
-
export { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, PLATFORM_TARGET_GLOBS } from './platform-targets.js';
|
|
8
|
+
export { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, PLATFORM_TARGET_GLOBS, RELEASE_CONFIGURATION, } from './platform-targets.js';
|
|
9
9
|
/**
|
|
10
10
|
* The glob list above, spelled as a target name: a target whose name ends in a
|
|
11
11
|
* reserved family suffix EMITS that kind of artifact. Inference collects
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD,eAAO,MAAM,4BAA4B,0CAA0C,CAAC;AAEpF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,OAAO,
|
|
1
|
+
{"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD,eAAO,MAAM,4BAA4B,0CAA0C,CAAC;AAEpF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAI/B;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI5D;AAgBD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CA4DrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAqB7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
|
|
@@ -14,7 +14,7 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
|
14
14
|
'*-bun',
|
|
15
15
|
'*-wasm',
|
|
16
16
|
];
|
|
17
|
-
export { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, PLATFORM_TARGET_GLOBS } from './platform-targets.js';
|
|
17
|
+
export { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, PLATFORM_TARGET_GLOBS, RELEASE_CONFIGURATION, } from './platform-targets.js';
|
|
18
18
|
const buildOutputTargetSuffixes = BUILD_OUTPUT_DEPENDENCIES.map((glob) => glob.slice(1));
|
|
19
19
|
/**
|
|
20
20
|
* The glob list above, spelled as a target name: a target whose name ends in a
|
package/managed/raw/envrc
CHANGED
|
@@ -11,10 +11,47 @@ esac
|
|
|
11
11
|
|
|
12
12
|
watch_file tooling/direnv/envrc.sh
|
|
13
13
|
|
|
14
|
+
# devenv asks the Cachix API for the signing key of each binary cache it pulls
|
|
15
|
+
# from (`cachix.pull`, `devenv` by default) unless cachix_trusted_keys.json in
|
|
16
|
+
# its home already records it. A cowshed sandbox gives every workspace a private
|
|
17
|
+
# data home and no route to that API (devenv's TLS client rejects the gateway's
|
|
18
|
+
# certificate), so each activation there asked again and was refused. The key is
|
|
19
|
+
# public and fixed, so it is recorded before devenv starts; an existing file is
|
|
20
|
+
# devenv's and stays as it is.
|
|
21
|
+
devenv_keys="${DEVENV_HOME:-${XDG_DATA_HOME:-$HOME/.local/share}/devenv}/cachix_trusted_keys.json"
|
|
22
|
+
if [ ! -e "$devenv_keys" ]; then
|
|
23
|
+
mkdir -p "$(dirname "$devenv_keys")"
|
|
24
|
+
printf '{\n "devenv": "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="\n}\n' >"$devenv_keys.$$"
|
|
25
|
+
mv -f "$devenv_keys.$$" "$devenv_keys"
|
|
26
|
+
fi
|
|
27
|
+
unset devenv_keys
|
|
28
|
+
|
|
14
29
|
# Load local extensions and overrides from the project root (the gitignored
|
|
15
30
|
# .envrc-local); capture it before we cd into tooling/direnv, since envrc.sh
|
|
16
31
|
# leaves us there and a bare relative path would resolve under tooling/direnv.
|
|
17
|
-
|
|
32
|
+
project_root="$PWD"
|
|
33
|
+
local_override="$project_root/.envrc-local"
|
|
18
34
|
cd tooling/direnv
|
|
19
35
|
. envrc.sh
|
|
36
|
+
|
|
37
|
+
# Re-enter exactly when shell entry has something to do. The scripts it runs
|
|
38
|
+
# decide what that is, and setup-environment.ts records the files its install
|
|
39
|
+
# stamps cover — lockfiles, every workspace manifest, bunfig.toml, patches,
|
|
40
|
+
# every pyproject.toml — one per line in $DEVENV_STATE/install-inputs. A shell
|
|
41
|
+
# direnv keeps loaded, or a pool of them gated on direnv's watches, then
|
|
42
|
+
# reinstalls after a pull or a manifest edit and stays put otherwise.
|
|
43
|
+
install_inputs=()
|
|
44
|
+
if [ -f "${DEVENV_STATE:-}/install-inputs" ]; then
|
|
45
|
+
while IFS= read -r install_input; do
|
|
46
|
+
install_inputs+=("$install_input")
|
|
47
|
+
done <"$DEVENV_STATE/install-inputs"
|
|
48
|
+
fi
|
|
49
|
+
watch_file \
|
|
50
|
+
"$project_root/tooling/direnv/repo-path" \
|
|
51
|
+
"$project_root/tooling/direnv/shared-caches.sh" \
|
|
52
|
+
"$project_root/tooling/direnv/setup-environment.ts" \
|
|
53
|
+
"$project_root/tooling/direnv/secret-references.ts" \
|
|
54
|
+
"$project_root/tooling/direnv/toolchain-stamp.ts" \
|
|
55
|
+
${install_inputs[@]+"${install_inputs[@]}"}
|
|
56
|
+
|
|
20
57
|
source_env_if_exists "$local_override"
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The links a developer points out of this checkout, kept across every
|
|
3
|
+
* install smoo runs.
|
|
4
|
+
*
|
|
5
|
+
* `bun link <name>`, or a hand-made `ln -s`, replaces a dependency's entry in
|
|
6
|
+
* a node_modules tree with a link to a local checkout of that package: how a
|
|
7
|
+
* consumer runs against a build that is not published yet. Every `bun
|
|
8
|
+
* install` re-points every declared dependency at the lockfile's version —
|
|
9
|
+
* an install with nothing to do included, and before the root `preinstall`
|
|
10
|
+
* script runs (measured on Bun 1.4.2), so no lifecycle script ever sees the
|
|
11
|
+
* link. So each install smoo runs (shell entry's, a CI runner's
|
|
12
|
+
* frozen-lockfile one, `smoo monorepo update`'s) records these links before
|
|
13
|
+
* it installs and puts exactly those back afterwards. A plain `bun install`
|
|
14
|
+
* still relinks them: only a wrapper around bun itself could intercept that.
|
|
15
|
+
*
|
|
16
|
+
* A developer link is a symlink directly inside a node_modules tree bun
|
|
17
|
+
* installs (the root's or a workspace member's, scoped names included) whose
|
|
18
|
+
* target lies outside the project root. The target is resolved against the
|
|
19
|
+
* link's own directory and no further. Everything bun links there resolves
|
|
20
|
+
* inside the root: workspace members by relative path, packages into
|
|
21
|
+
* node_modules/.bun. Following the links further would misclassify: under
|
|
22
|
+
* `globalStore`, each .bun entry is itself a link into the shared install
|
|
23
|
+
* cache, outside every checkout.
|
|
24
|
+
*
|
|
25
|
+
* Nothing is recorded across installs, so the state is the filesystem itself:
|
|
26
|
+
* unlinking a package means removing its link, and the next install puts the
|
|
27
|
+
* lockfile's version there. A link whose target no longer exists is removed
|
|
28
|
+
* before the install, with a warning, so that install puts the lockfile's
|
|
29
|
+
* version in its place.
|
|
30
|
+
*
|
|
31
|
+
* Like secret-references.ts, this is a managed raw script: shell entry imports
|
|
32
|
+
* it before anything is installed, and `smoo monorepo update` loads the copy
|
|
33
|
+
* the nx-plugin ships. Because both use the one implementation, the shell and
|
|
34
|
+
* the command keep the same links.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
type Dirent,
|
|
39
|
+
existsSync,
|
|
40
|
+
mkdirSync,
|
|
41
|
+
readdirSync,
|
|
42
|
+
readFileSync,
|
|
43
|
+
readlinkSync,
|
|
44
|
+
rmSync,
|
|
45
|
+
symlinkSync,
|
|
46
|
+
} from 'node:fs';
|
|
47
|
+
import path from 'node:path';
|
|
48
|
+
|
|
49
|
+
interface DeveloperLink {
|
|
50
|
+
/** Where the link is, relative to the project root. */
|
|
51
|
+
readonly path: string;
|
|
52
|
+
/** The link's own text, restored byte for byte. */
|
|
53
|
+
readonly target: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface DeveloperLinks {
|
|
57
|
+
readonly live: readonly DeveloperLink[];
|
|
58
|
+
/** Links whose target no longer exists. */
|
|
59
|
+
readonly dangling: readonly DeveloperLink[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Runs `install` with every developer link under `root` kept. The links in
|
|
64
|
+
* place when it starts are exactly the links in place when it settles,
|
|
65
|
+
* whether it resolved or rejected, less those that already dangled. It then
|
|
66
|
+
* names them as `reportDeveloperLinks` does.
|
|
67
|
+
*/
|
|
68
|
+
export async function keepDeveloperLinks<T>(root: string, install: () => Promise<T>): Promise<T> {
|
|
69
|
+
const { live, dangling } = findDeveloperLinks(root);
|
|
70
|
+
for (const link of dangling) {
|
|
71
|
+
rmSync(path.join(root, link.path), { force: true });
|
|
72
|
+
console.error(`! removed developer link ${link.path}: its target ${resolvedTarget(root, link)} no longer exists`);
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
return await install();
|
|
76
|
+
} finally {
|
|
77
|
+
for (const link of live) {
|
|
78
|
+
restoreLink(root, link);
|
|
79
|
+
}
|
|
80
|
+
describeDeveloperLinks(root, live);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One stderr line naming each linked package and the checkout it points at,
|
|
86
|
+
* so a shell running a local build says so. Shell entry prints it on every
|
|
87
|
+
* entry that installs nothing. The entry that installs gets the same line
|
|
88
|
+
* from `keepDeveloperLinks`, but devenv's direnv integration runs that entry
|
|
89
|
+
* where its output is not shown. A dangling link is left for the next
|
|
90
|
+
* install to remove.
|
|
91
|
+
*/
|
|
92
|
+
export function reportDeveloperLinks(root: string): void {
|
|
93
|
+
describeDeveloperLinks(root, findDeveloperLinks(root).live);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** A package linked from many members is named once, with its count. */
|
|
97
|
+
function describeDeveloperLinks(root: string, links: readonly DeveloperLink[]): void {
|
|
98
|
+
if (links.length === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const counts = new Map<string, number>();
|
|
102
|
+
for (const link of links) {
|
|
103
|
+
const name = link.path.slice(link.path.lastIndexOf('node_modules/') + 'node_modules/'.length);
|
|
104
|
+
const named = `${name} -> ${resolvedTarget(root, link)}`;
|
|
105
|
+
counts.set(named, (counts.get(named) ?? 0) + 1);
|
|
106
|
+
}
|
|
107
|
+
const entries = [...counts].map(([named, count]) => (count === 1 ? named : `${named} (${count} links)`));
|
|
108
|
+
console.error(`linked to local checkouts: ${entries.join(', ')}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function findDeveloperLinks(root: string): DeveloperLinks {
|
|
112
|
+
const live: DeveloperLink[] = [];
|
|
113
|
+
const dangling: DeveloperLink[] = [];
|
|
114
|
+
for (const tree of nodeModulesTrees(root)) {
|
|
115
|
+
for (const entry of packageLinks(root, tree)) {
|
|
116
|
+
const link: DeveloperLink = { path: entry, target: readlinkSync(path.join(root, entry)) };
|
|
117
|
+
const target = resolvedTarget(root, link);
|
|
118
|
+
const relative = path.relative(root, target);
|
|
119
|
+
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
120
|
+
(existsSync(target) ? live : dangling).push(link);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { live, dangling };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The node_modules trees the last install wrote, relative to the root: the
|
|
129
|
+
* root's and each workspace member's, as bun.lock names them. The lockfile,
|
|
130
|
+
* not the manifest's workspace globs, because it is bun's own record of the
|
|
131
|
+
* members it installed. A missing or unreadable lockfile leaves the root's
|
|
132
|
+
* tree alone; the install that follows reports the lockfile in its own words.
|
|
133
|
+
*/
|
|
134
|
+
function nodeModulesTrees(root: string): string[] {
|
|
135
|
+
let lock: unknown;
|
|
136
|
+
try {
|
|
137
|
+
lock = Bun.JSONC.parse(readFileSync(path.join(root, 'bun.lock'), 'utf8'));
|
|
138
|
+
} catch {
|
|
139
|
+
return ['node_modules'];
|
|
140
|
+
}
|
|
141
|
+
const workspaces = typeof lock === 'object' && lock !== null ? Reflect.get(lock, 'workspaces') : undefined;
|
|
142
|
+
const members = typeof workspaces === 'object' && workspaces !== null ? Object.keys(workspaces) : [];
|
|
143
|
+
return [...new Set(['', ...members])].map((member) => path.join(member, 'node_modules'));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Every symlink a package name could be in `tree`: `name` and `@scope/name`. */
|
|
147
|
+
function packageLinks(root: string, tree: string): string[] {
|
|
148
|
+
const links: string[] = [];
|
|
149
|
+
for (const entry of directoryEntries(path.join(root, tree))) {
|
|
150
|
+
if (entry.name.startsWith('.')) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (entry.isSymbolicLink()) {
|
|
154
|
+
links.push(path.join(tree, entry.name));
|
|
155
|
+
} else if (entry.name.startsWith('@') && entry.isDirectory()) {
|
|
156
|
+
for (const scoped of directoryEntries(path.join(root, tree, entry.name))) {
|
|
157
|
+
if (scoped.isSymbolicLink()) {
|
|
158
|
+
links.push(path.join(tree, entry.name, scoped.name));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return links;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function directoryEntries(directory: string): Dirent[] {
|
|
167
|
+
try {
|
|
168
|
+
return readdirSync(directory, { withFileTypes: true });
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error instanceof Error && 'code' in error && (error.code === 'ENOENT' || error.code === 'ENOTDIR')) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function resolvedTarget(root: string, link: DeveloperLink): string {
|
|
178
|
+
return path.resolve(root, path.dirname(link.path), link.target);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Puts `link` back unless the install left it as it was. */
|
|
182
|
+
function restoreLink(root: string, link: DeveloperLink): void {
|
|
183
|
+
const at = path.join(root, link.path);
|
|
184
|
+
let current: string | null;
|
|
185
|
+
try {
|
|
186
|
+
current = readlinkSync(at);
|
|
187
|
+
} catch {
|
|
188
|
+
// Nothing there, or no link: either way the install replaced it.
|
|
189
|
+
current = null;
|
|
190
|
+
}
|
|
191
|
+
if (current === link.target) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
// What the install put there: a link into node_modules/.bun, or, under the
|
|
195
|
+
// hoisted linker, a copied package directory. Removing a link never
|
|
196
|
+
// follows it. The parent is created again for a dependency the install
|
|
197
|
+
// dropped along with its scope directory.
|
|
198
|
+
rmSync(at, { recursive: true, force: true });
|
|
199
|
+
mkdirSync(path.dirname(at), { recursive: true });
|
|
200
|
+
symlinkSync(link.target, at);
|
|
201
|
+
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
# Every explanation lives out here in Nix comments. Hook bodies are exported as
|
|
14
14
|
# shell text, so a comment inside one becomes part of an environment variable.
|
|
15
15
|
{
|
|
16
|
+
config,
|
|
16
17
|
inputs,
|
|
17
18
|
lib,
|
|
18
19
|
pkgs,
|
|
@@ -29,12 +30,29 @@
|
|
|
29
30
|
rev = "56ab4af42157";
|
|
30
31
|
hash = "sha256-ebjX+1+9axEqsnZXCRZSumA38gPNdmoz98tMt2oftN4=";
|
|
31
32
|
};
|
|
33
|
+
|
|
34
|
+
# A repository that enables uv under languages.python gets its uv workspace
|
|
35
|
+
# synced and activated by this contract (enterShell item 5), never by
|
|
36
|
+
# devenv's own python tasks.
|
|
37
|
+
python = config.languages.python;
|
|
38
|
+
uvProject = python.enable && python.uv.enable;
|
|
32
39
|
in {
|
|
33
40
|
env = lib.mkMerge [
|
|
34
41
|
{
|
|
35
42
|
# Nx otherwise defaults to three workers. Scale to the cores available in each
|
|
36
43
|
# developer shell or CI runner; explicit --parallel flags still take precedence.
|
|
37
44
|
NX_PARALLEL = "100%";
|
|
45
|
+
# Every Nx daemon, when it starts, installs nx@latest from the registry
|
|
46
|
+
# into a temporary directory to ask the newest release whether to prompt
|
|
47
|
+
# for Nx Console and whether AI agent configuration is outdated, and
|
|
48
|
+
# `nx configure-ai-agents` and `nx init` do the same. NX_USE_LOCAL answers
|
|
49
|
+
# from the installed nx, so starting Nx installs nothing from the registry.
|
|
50
|
+
# (A daemon still runs `git ls-remote` against GitHub's
|
|
51
|
+
# nrwl/nx-ai-agents-config when an agent has both rules and Nx's MCP
|
|
52
|
+
# configured; a cowshed sandbox runs Nx without a daemon.) It also makes
|
|
53
|
+
# `nx migrate` run with the installed CLI instead of the newest one;
|
|
54
|
+
# `NX_USE_LOCAL=false nx migrate` restores that for the one command.
|
|
55
|
+
NX_USE_LOCAL = "true";
|
|
38
56
|
TTSC_TYPESCRIPT_GO_DIR = "${typescriptGo}";
|
|
39
57
|
}
|
|
40
58
|
# Playwright's downloaded Ubuntu browser has no runtime closure on NixOS
|
|
@@ -255,6 +273,16 @@ in {
|
|
|
255
273
|
]
|
|
256
274
|
++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [pkgs.chromium];
|
|
257
275
|
|
|
276
|
+
# devenv wraps the Python interpreter to find native libraries in
|
|
277
|
+
# `languages.python.libraries`, whose default is this checkout's
|
|
278
|
+
# `.devenv/profile`. That path then lands in the interpreter's store path, the
|
|
279
|
+
# profile that holds it and the uv environment built with it, so every clone
|
|
280
|
+
# evaluates and builds its own interpreter and profile on first entry, and its
|
|
281
|
+
# copied uv environment names another checkout's interpreter. Cleared, the
|
|
282
|
+
# interpreter is one store path in every checkout. devenv still adds the C++
|
|
283
|
+
# runtime; a wheel that needs another library names that library here.
|
|
284
|
+
languages.python.libraries = lib.mkIf uvProject (lib.mkDefault []);
|
|
285
|
+
|
|
258
286
|
enterShell = lib.mkMerge [
|
|
259
287
|
# Prologue, in order:
|
|
260
288
|
#
|
|
@@ -264,47 +292,35 @@ in {
|
|
|
264
292
|
# use, so a hook and a shell resolve one binary the same way.
|
|
265
293
|
# 3. ttsc drives the native TypeScript 7 binary while Nx imports the TypeScript
|
|
266
294
|
# 6 API, so the two must be named separately.
|
|
267
|
-
# 4.
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
#
|
|
271
|
-
#
|
|
272
|
-
#
|
|
273
|
-
#
|
|
274
|
-
#
|
|
275
|
-
# unlike Rust's trim-paths it costs no cache reuse.
|
|
276
|
-
#
|
|
277
|
-
# ttsc's plugin builds use the Go it bundles rather than ours, so the
|
|
278
|
-
# repository's own Go work and ttsc's plugin builds are two toolchains by
|
|
279
|
-
# construction. Placing both caches in the shared store is what keeps that
|
|
280
|
-
# from costing a rebuild per workspace.
|
|
295
|
+
# 4. Go and ttsc caches: tooling/direnv/shared-caches.sh places them under
|
|
296
|
+
# the machine's shared caches root when it exists and states why.
|
|
297
|
+
# 5. The shared setup-environment.ts bootstraps repository dependencies. It
|
|
298
|
+
# runs `bun install` — and, for a uv project, `uv sync` — only when that
|
|
299
|
+
# installer's inputs changed since its last successful run, so an
|
|
300
|
+
# unchanged checkout enters in the time it takes to hash a lockfile. It
|
|
301
|
+
# records those inputs, and the managed .envrc watches them, so a shell
|
|
302
|
+
# that direnv keeps loaded re-enters exactly when one of them changes.
|
|
281
303
|
#
|
|
282
|
-
#
|
|
283
|
-
#
|
|
284
|
-
#
|
|
285
|
-
#
|
|
286
|
-
#
|
|
287
|
-
#
|
|
288
|
-
#
|
|
289
|
-
#
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
304
|
+
# The uv project environment is devenv's UV_PROJECT_ENVIRONMENT, synced
|
|
305
|
+
# with the interpreter devenv would use and activated here after the
|
|
306
|
+
# sync. It lives under this checkout and names no path of it: uv creates
|
|
307
|
+
# it relocatable, setup-environment.ts rewrites the editable installs of
|
|
308
|
+
# workspace members relative to it, and the interpreter is the same
|
|
309
|
+
# store path everywhere (languages.python.libraries above). A
|
|
310
|
+
# copy-on-write clone copies it along with everything else, installed.
|
|
311
|
+
# devenv's own virtualenv and uv sync tasks are refused below: they
|
|
312
|
+
# activate the environment from its own activation script — which in a
|
|
313
|
+
# clone names the original checkout — before this prologue runs, and key
|
|
314
|
+
# their skip on pyproject.toml alone.
|
|
293
315
|
#
|
|
294
|
-
#
|
|
295
|
-
#
|
|
296
|
-
#
|
|
297
|
-
#
|
|
298
|
-
#
|
|
299
|
-
#
|
|
300
|
-
#
|
|
301
|
-
#
|
|
302
|
-
# Repo-owned enterShell bodies merge after this prologue.
|
|
303
|
-
# 6. Shell entry resolves the `shell` group of `smoo.secrets` and nothing
|
|
304
|
-
# else. Shell entry happens on every direnv reload and every
|
|
305
|
-
# `devenv shell -- <command>`, and a provider command that runs then is a
|
|
306
|
-
# credential prompt on every one of them (1Password authorises per
|
|
307
|
-
# requesting process lineage, and this one is new each time). A
|
|
316
|
+
# A local install failure is reported and the shell still loads, so the
|
|
317
|
+
# tools to repair it stay available; CI fails. Repo-owned enterShell
|
|
318
|
+
# bodies merge after this prologue.
|
|
319
|
+
# 6. Shell entry resolves the `shell` group of `smoo.secrets`, only when it
|
|
320
|
+
# installs, and nothing else. Shell entry happens on every direnv reload
|
|
321
|
+
# and every `devenv shell -- <command>`, and a provider command that runs
|
|
322
|
+
# then is a credential prompt on every one of them (1Password authorises
|
|
323
|
+
# per requesting process lineage, and this one is new each time). A
|
|
308
324
|
# credential only one deliberate command needs belongs to that command:
|
|
309
325
|
# `smoo secrets run <group> <command...>`. The full statement, and the
|
|
310
326
|
# derivation below, live in tooling/direnv/secret-references.ts.
|
|
@@ -383,19 +399,15 @@ in {
|
|
|
383
399
|
export TMPDIR="''${TMPDIR:-/tmp}"
|
|
384
400
|
fi
|
|
385
401
|
export TTSC_TSGO_BINARY="$PWD/node_modules/@typescript/native/bin/tsc"
|
|
386
|
-
|
|
387
|
-
export TTSC_CACHE_DIR="''${TTSC_CACHE_DIR:-$HOME/.cowshed/caches/ttsc}"
|
|
388
|
-
export GOCACHE="''${GOCACHE:-$HOME/.cowshed/caches/go/build}"
|
|
389
|
-
export GOMODCACHE="''${GOMODCACHE:-$HOME/.cowshed/caches/go/mod}"
|
|
390
|
-
mkdir -p "$GOCACHE" "$GOMODCACHE"
|
|
391
|
-
else
|
|
392
|
-
export TTSC_CACHE_DIR="''${TTSC_CACHE_DIR:-$PWD/.cache/ttsc}"
|
|
393
|
-
fi
|
|
394
|
-
export TTSC_GO_CACHE_DIR="''${TTSC_GO_CACHE_DIR:-$TTSC_CACHE_DIR/go-build}"
|
|
395
|
-
mkdir -p "$TTSC_CACHE_DIR" "$TTSC_GO_CACHE_DIR"
|
|
396
|
-
export GOFLAGS="''${GOFLAGS:--trimpath}"
|
|
402
|
+
. "$DEVENV_ROOT/shared-caches.sh" /private/cowshed/caches
|
|
397
403
|
unset GOROOT
|
|
398
|
-
bun "$DEVENV_ROOT/setup-environment.ts" || exit $?
|
|
404
|
+
bun "$DEVENV_ROOT/setup-environment.ts"${lib.optionalString uvProject " --python ${python.package.interpreter}"} || exit $?
|
|
405
|
+
${lib.optionalString uvProject ''
|
|
406
|
+
if [ -f pyproject.toml ]; then
|
|
407
|
+
export VIRTUAL_ENV="$UV_PROJECT_ENVIRONMENT"
|
|
408
|
+
export PATH="$VIRTUAL_ENV/bin:$PATH"
|
|
409
|
+
fi
|
|
410
|
+
''}
|
|
399
411
|
# One socket dir per Nx workspace. DEVENV_RUNTIME is keyed to the devenv
|
|
400
412
|
# ROOT, so every workspace sharing one devenv - a sibling repository, a
|
|
401
413
|
# copy-on-write clone, a scratch workspace created inside this shell -
|
|
@@ -432,4 +444,16 @@ in {
|
|
|
432
444
|
fi
|
|
433
445
|
'')
|
|
434
446
|
];
|
|
447
|
+
|
|
448
|
+
assertions = [
|
|
449
|
+
{
|
|
450
|
+
assertion = !(uvProject && (python.venv.enable || python.uv.sync.enable));
|
|
451
|
+
message = ''
|
|
452
|
+
devenv.smoo.nix syncs and activates the uv project environment itself (enterShell item 5).
|
|
453
|
+
Set languages.python.venv.enable and languages.python.uv.sync.enable to false in devenv.nix:
|
|
454
|
+
devenv's tasks activate the environment from its own activation script, which in a
|
|
455
|
+
copy-on-write clone names the original checkout, and skip the sync while uv.lock changes.
|
|
456
|
+
'';
|
|
457
|
+
}
|
|
458
|
+
];
|
|
435
459
|
}
|
|
@@ -393,7 +393,9 @@ async function routeSecret(
|
|
|
393
393
|
}
|
|
394
394
|
const requested = group === context.group;
|
|
395
395
|
if (requested || context.dependsOn.includes(group)) {
|
|
396
|
-
|
|
396
|
+
// A CI runner (GitHub or Forgejo Actions, which sets GITHUB_ACTIONS too), never
|
|
397
|
+
// `CI`: agent harnesses set CI=true on every command they run.
|
|
398
|
+
if (env.GITHUB_ACTIONS === 'true') {
|
|
397
399
|
return {
|
|
398
400
|
name,
|
|
399
401
|
group,
|