@smoothbricks/nx-plugin 0.4.15 → 0.4.16
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 +17 -0
- package/dist/deploy-policy.d.ts +26 -0
- package/dist/deploy-policy.d.ts.map +1 -0
- package/dist/deploy-policy.js +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -14
- package/dist/managed-assets.d.ts +3 -0
- package/dist/managed-assets.d.ts.map +1 -0
- package/dist/managed-assets.js +3 -0
- package/dist/managed-files/ci-workflow.d.ts +215 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -0
- package/dist/managed-files/ci-workflow.js +1082 -0
- package/dist/managed-files/context.d.ts +51 -0
- package/dist/managed-files/context.d.ts.map +1 -0
- package/dist/managed-files/context.js +206 -0
- package/dist/managed-files/files.d.ts +53 -0
- package/dist/managed-files/files.d.ts.map +1 -0
- package/dist/managed-files/files.js +248 -0
- package/dist/managed-files/generator.d.ts +16 -0
- package/dist/managed-files/generator.d.ts.map +1 -0
- package/dist/managed-files/generator.js +41 -0
- package/dist/managed-files/github-runs-on.d.ts +19 -0
- package/dist/managed-files/github-runs-on.d.ts.map +1 -0
- package/dist/managed-files/github-runs-on.js +48 -0
- package/dist/managed-files/managed-content.d.ts +45 -0
- package/dist/managed-files/managed-content.d.ts.map +1 -0
- package/dist/managed-files/managed-content.js +102 -0
- package/dist/managed-files/managed-format.d.ts +37 -0
- package/dist/managed-files/managed-format.d.ts.map +1 -0
- package/dist/managed-files/managed-format.js +94 -0
- package/dist/managed-files/paths.d.ts +8 -0
- package/dist/managed-files/paths.d.ts.map +1 -0
- package/dist/managed-files/paths.js +46 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +5 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.js +38 -0
- package/dist/managed-files/private-npm-policy.d.ts +7 -0
- package/dist/managed-files/private-npm-policy.d.ts.map +1 -0
- package/dist/managed-files/private-npm-policy.js +51 -0
- package/dist/managed-files/publish-workflow.d.ts +150 -0
- package/dist/managed-files/publish-workflow.d.ts.map +1 -0
- package/dist/managed-files/publish-workflow.js +989 -0
- package/dist/managed-files/tree.d.ts +30 -0
- package/dist/managed-files/tree.d.ts.map +1 -0
- package/dist/managed-files/tree.js +91 -0
- package/dist/platform-targets.d.ts +5 -0
- package/dist/platform-targets.d.ts.map +1 -0
- package/dist/platform-targets.js +4 -0
- package/dist/typecheck-test-policy.d.ts +5 -9
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +69 -99
- package/dist/workspace-config-policy.d.ts +2 -3
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +8 -3
- package/dist/workspace-manifest.d.ts +291 -0
- package/dist/workspace-manifest.d.ts.map +1 -0
- package/dist/workspace-manifest.js +6 -0
- package/dist/workspace-package-policy.d.ts +13 -0
- package/dist/workspace-package-policy.d.ts.map +1 -0
- package/dist/workspace-package-policy.js +24 -0
- package/generators.json +5 -0
- package/managed/raw/envrc +20 -0
- package/managed/raw/git-format-staged.yml +82 -0
- package/managed/raw/gitattributes +8 -0
- package/managed/raw/tooling/devenv +83 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +422 -0
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +251 -0
- package/managed/raw/tooling/direnv/merge-newer-pins.sh +48 -0
- package/managed/raw/tooling/direnv/repo-path +34 -0
- package/managed/raw/tooling/direnv/secret-references.ts +636 -0
- package/managed/raw/tooling/direnv/setup-environment.ts +585 -0
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +88 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +9 -0
- package/managed/raw/tooling/git-hooks/post-commit.sh +71 -0
- package/managed/raw/tooling/git-hooks/pre-commit.sh +18 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +48 -0
- package/managed/raw/tsconfig.lib.json +28 -0
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +45 -0
- package/managed/templates/github/actions/cache-node-modules/action.yml +17 -0
- package/managed/templates/github/actions/cache-nx/action.yml +21 -0
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +19 -0
- package/managed/templates/github/actions/save-nix-devenv/action.yml +32 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +241 -0
- package/managed/templates/github/workflows/managed-files.yml +127 -0
- package/package.json +89 -5
- package/src/bun-bootstrap.test.ts +0 -6
- package/src/deploy-policy.ts +40 -0
- package/src/index.test.ts +225 -2
- package/src/index.ts +180 -14
- package/src/managed-assets.ts +4 -0
- package/src/managed-files/ci-workflow.ts +1365 -0
- package/src/managed-files/context.ts +240 -0
- package/src/managed-files/files.ts +324 -0
- package/src/managed-files/generator.test.ts +151 -0
- package/src/managed-files/generator.ts +60 -0
- package/src/managed-files/github-runs-on.ts +51 -0
- package/src/managed-files/managed-content.test.ts +147 -0
- package/src/managed-files/managed-content.ts +121 -0
- package/src/managed-files/managed-format.ts +102 -0
- package/src/managed-files/paths.ts +44 -0
- package/src/managed-files/pr-preview-cleanup-workflow.ts +44 -0
- package/src/managed-files/private-npm-policy.ts +62 -0
- package/src/managed-files/publish-workflow.ts +1523 -0
- package/src/managed-files/schema.json +8 -0
- package/src/managed-files/tree-permissions.test.ts +109 -0
- package/src/managed-files/tree.test.ts +123 -0
- package/src/managed-files/tree.ts +118 -0
- package/src/platform-targets.ts +4 -0
- package/src/typecheck-test-policy.test.ts +28 -3
- package/src/typecheck-test-policy.ts +46 -121
- package/src/workspace-config-policy.test.ts +14 -2
- package/src/workspace-config-policy.ts +9 -3
- package/src/workspace-manifest.ts +327 -0
- package/src/workspace-package-policy.ts +32 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Managed by @smoothbricks/cli (smoo monorepo update) - do not edit by hand.
|
|
2
|
+
#
|
|
3
|
+
# Self-healing loop for smoo-managed files: ci.yml runs the authoritative
|
|
4
|
+
# `smoo monorepo check` on every default-branch push (devenv is already up
|
|
5
|
+
# there, so the check is ~free) and dispatches THIS workflow only when real
|
|
6
|
+
# drift exists - typically after a @smoothbricks/cli pin bump. It runs
|
|
7
|
+
# `smoo monorepo update` and pushes the result to ONE persistent review branch
|
|
8
|
+
# (chore/managed-files) with ONE PR. The PR is NEVER auto-merged: a template
|
|
9
|
+
# change is upstream code that deserves a human look before it lands. Re-runs
|
|
10
|
+
# refresh the same branch in place.
|
|
11
|
+
#
|
|
12
|
+
# REQUIRED SECRET: MANAGED_FILES_TOKEN
|
|
13
|
+
# Managed files include .github/workflows/*. The default GITHUB_TOKEN is
|
|
14
|
+
# server-side forbidden to create/update workflow files, even with
|
|
15
|
+
# contents:write. Configure a GitHub App installation token or classic/fine-
|
|
16
|
+
# grained PAT with:
|
|
17
|
+
# - contents: write
|
|
18
|
+
# - pull-requests: write
|
|
19
|
+
# - workflows: write
|
|
20
|
+
# as repository secret MANAGED_FILES_TOKEN. Without it, any update that
|
|
21
|
+
# touches workflow YAML fails at push (this is the usual "managed files
|
|
22
|
+
# workflow isn't doing anything" failure mode).
|
|
23
|
+
name: Managed files
|
|
24
|
+
|
|
25
|
+
on:
|
|
26
|
+
workflow_dispatch:
|
|
27
|
+
|
|
28
|
+
permissions:
|
|
29
|
+
contents: write
|
|
30
|
+
pull-requests: write
|
|
31
|
+
|
|
32
|
+
concurrency:
|
|
33
|
+
group: managed-files
|
|
34
|
+
cancel-in-progress: true
|
|
35
|
+
|
|
36
|
+
defaults:
|
|
37
|
+
run:
|
|
38
|
+
working-directory: tooling/direnv
|
|
39
|
+
|
|
40
|
+
jobs:
|
|
41
|
+
update:
|
|
42
|
+
__SMOO_CI_RUNS_ON__
|
|
43
|
+
timeout-minutes: 30
|
|
44
|
+
__SMOO_PRIVATE_INSTALL_ENV__ steps:
|
|
45
|
+
- name: 📥 Checkout
|
|
46
|
+
uses: actions/checkout@v6.0.2
|
|
47
|
+
with:
|
|
48
|
+
filter: blob:none
|
|
49
|
+
fetch-depth: 0
|
|
50
|
+
persist-credentials: true
|
|
51
|
+
# Prefer MANAGED_FILES_TOKEN so push can update workflow files.
|
|
52
|
+
token: ${{ secrets.MANAGED_FILES_TOKEN || github.token }}
|
|
53
|
+
|
|
54
|
+
- name: 🧱 Setup Nix/devenv
|
|
55
|
+
id: setup
|
|
56
|
+
uses: ./.github/actions/setup-devenv
|
|
57
|
+
|
|
58
|
+
- name: 🔄 Regenerate managed files
|
|
59
|
+
run: smoo monorepo update
|
|
60
|
+
|
|
61
|
+
- name: 📤 Push review branch and open PR
|
|
62
|
+
env:
|
|
63
|
+
GH_TOKEN: ${{ secrets.MANAGED_FILES_TOKEN || github.token }}
|
|
64
|
+
# secrets.* is empty when unset — used to fail before a useless push.
|
|
65
|
+
MANAGED_FILES_TOKEN_CONFIGURED: ${{ secrets.MANAGED_FILES_TOKEN != '' }}
|
|
66
|
+
run: |
|
|
67
|
+
set -euo pipefail
|
|
68
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
69
|
+
|
|
70
|
+
if [ -z "$(git status --porcelain)" ]; then
|
|
71
|
+
echo "Managed files are in sync; nothing to do."
|
|
72
|
+
exit 0
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
echo "Pending managed-file changes:"
|
|
76
|
+
git status --porcelain
|
|
77
|
+
|
|
78
|
+
workflow_changes="$(git status --porcelain -- .github/workflows || true)"
|
|
79
|
+
if [ -n "$workflow_changes" ] && [ "${GITHUB_SERVER_URL}" = "https://github.com" ] && [ "${MANAGED_FILES_TOKEN_CONFIGURED}" != "true" ]; then
|
|
80
|
+
{
|
|
81
|
+
echo "::error title=MANAGED_FILES_TOKEN required::Managed update touches .github/workflows/* but repository secret MANAGED_FILES_TOKEN is not set."
|
|
82
|
+
echo ""
|
|
83
|
+
echo "GitHub refuses pushes that create/update workflow files when the credentials are the default GITHUB_TOKEN / a GitHub App without the workflows permission:"
|
|
84
|
+
echo " refusing to allow a GitHub App to create or update workflow ... without \`workflows\` permission"
|
|
85
|
+
echo ""
|
|
86
|
+
echo "Fix:"
|
|
87
|
+
echo " 1. Create a GitHub App (or PAT) with contents:write, pull-requests:write, workflows:write"
|
|
88
|
+
echo " 2. Install it on this repo"
|
|
89
|
+
echo " 3. Store an installation token or PAT as repository secret MANAGED_FILES_TOKEN"
|
|
90
|
+
echo " 4. Re-run this workflow"
|
|
91
|
+
echo ""
|
|
92
|
+
echo "Workflow files that would be updated:"
|
|
93
|
+
echo "$workflow_changes"
|
|
94
|
+
} >&2
|
|
95
|
+
exit 1
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
git config user.name "github-actions[bot]"
|
|
99
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
100
|
+
git switch -C chore/managed-files
|
|
101
|
+
git add -A
|
|
102
|
+
git commit -m "chore: regenerate smoo-managed files"
|
|
103
|
+
|
|
104
|
+
if ! git push --force origin chore/managed-files 2> /tmp/managed-files-push.err; then
|
|
105
|
+
cat /tmp/managed-files-push.err >&2
|
|
106
|
+
if grep -q 'workflows' /tmp/managed-files-push.err; then
|
|
107
|
+
{
|
|
108
|
+
echo ""
|
|
109
|
+
echo "::error title=workflows permission missing::Push rejected because the token cannot update GitHub Actions workflow files."
|
|
110
|
+
echo "Set repository secret MANAGED_FILES_TOKEN to a GitHub App/PAT with contents:write + pull-requests:write + workflows:write, then re-run."
|
|
111
|
+
} >&2
|
|
112
|
+
fi
|
|
113
|
+
exit 1
|
|
114
|
+
fi
|
|
115
|
+
|
|
116
|
+
smoo github-ci ensure-pull-request \
|
|
117
|
+
--head chore/managed-files \
|
|
118
|
+
--base "${GITHUB_REF_NAME}" \
|
|
119
|
+
--title "chore: regenerate smoo-managed files" \
|
|
120
|
+
--body "Automated refresh of smoo-managed files after drift (usually a \`@smoothbricks/cli\` pin bump). One persistent PR; re-runs force-push this branch in place. Review the template changes — do NOT enable auto-merge."
|
|
121
|
+
|
|
122
|
+
- name: 🧹 Cleanup and cache Nix/devenv
|
|
123
|
+
# success() is default; always() still saves GH Nix cache after a red job.
|
|
124
|
+
if: always()
|
|
125
|
+
uses: ./.github/actions/save-nix-devenv
|
|
126
|
+
with:
|
|
127
|
+
devenv-cache-hit: ${{ steps.setup.outputs.devenv-cache-hit }}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -57,6 +57,86 @@
|
|
|
57
57
|
"types": "./dist/cargo-toolchain-policy.d.ts",
|
|
58
58
|
"import": "./dist/cargo-toolchain-policy.js",
|
|
59
59
|
"default": "./dist/cargo-toolchain-policy.js"
|
|
60
|
+
},
|
|
61
|
+
"./workspace-manifest": {
|
|
62
|
+
"types": "./dist/workspace-manifest.d.ts",
|
|
63
|
+
"import": "./dist/workspace-manifest.js",
|
|
64
|
+
"default": "./dist/workspace-manifest.js"
|
|
65
|
+
},
|
|
66
|
+
"./workspace-package-policy": {
|
|
67
|
+
"types": "./dist/workspace-package-policy.d.ts",
|
|
68
|
+
"import": "./dist/workspace-package-policy.js",
|
|
69
|
+
"default": "./dist/workspace-package-policy.js"
|
|
70
|
+
},
|
|
71
|
+
"./deploy-policy": {
|
|
72
|
+
"types": "./dist/deploy-policy.d.ts",
|
|
73
|
+
"import": "./dist/deploy-policy.js",
|
|
74
|
+
"default": "./dist/deploy-policy.js"
|
|
75
|
+
},
|
|
76
|
+
"./managed-assets": {
|
|
77
|
+
"types": "./dist/managed-assets.d.ts",
|
|
78
|
+
"import": "./dist/managed-assets.js",
|
|
79
|
+
"default": "./dist/managed-assets.js"
|
|
80
|
+
},
|
|
81
|
+
"./managed-files/generator": {
|
|
82
|
+
"types": "./dist/managed-files/generator.d.ts",
|
|
83
|
+
"import": "./dist/managed-files/generator.js",
|
|
84
|
+
"default": "./dist/managed-files/generator.js"
|
|
85
|
+
},
|
|
86
|
+
"./managed-files/managed-format": {
|
|
87
|
+
"types": "./dist/managed-files/managed-format.d.ts",
|
|
88
|
+
"import": "./dist/managed-files/managed-format.js",
|
|
89
|
+
"default": "./dist/managed-files/managed-format.js"
|
|
90
|
+
},
|
|
91
|
+
"./managed-files/managed-content": {
|
|
92
|
+
"types": "./dist/managed-files/managed-content.d.ts",
|
|
93
|
+
"import": "./dist/managed-files/managed-content.js",
|
|
94
|
+
"default": "./dist/managed-files/managed-content.js"
|
|
95
|
+
},
|
|
96
|
+
"./managed-files/tree": {
|
|
97
|
+
"types": "./dist/managed-files/tree.d.ts",
|
|
98
|
+
"import": "./dist/managed-files/tree.js",
|
|
99
|
+
"default": "./dist/managed-files/tree.js"
|
|
100
|
+
},
|
|
101
|
+
"./managed-files/files": {
|
|
102
|
+
"types": "./dist/managed-files/files.d.ts",
|
|
103
|
+
"import": "./dist/managed-files/files.js",
|
|
104
|
+
"default": "./dist/managed-files/files.js"
|
|
105
|
+
},
|
|
106
|
+
"./managed-files/paths": {
|
|
107
|
+
"types": "./dist/managed-files/paths.d.ts",
|
|
108
|
+
"import": "./dist/managed-files/paths.js",
|
|
109
|
+
"default": "./dist/managed-files/paths.js"
|
|
110
|
+
},
|
|
111
|
+
"./managed-files/ci-workflow": {
|
|
112
|
+
"types": "./dist/managed-files/ci-workflow.d.ts",
|
|
113
|
+
"import": "./dist/managed-files/ci-workflow.js",
|
|
114
|
+
"default": "./dist/managed-files/ci-workflow.js"
|
|
115
|
+
},
|
|
116
|
+
"./managed-files/publish-workflow": {
|
|
117
|
+
"types": "./dist/managed-files/publish-workflow.d.ts",
|
|
118
|
+
"import": "./dist/managed-files/publish-workflow.js",
|
|
119
|
+
"default": "./dist/managed-files/publish-workflow.js"
|
|
120
|
+
},
|
|
121
|
+
"./managed-files/github-runs-on": {
|
|
122
|
+
"types": "./dist/managed-files/github-runs-on.d.ts",
|
|
123
|
+
"import": "./dist/managed-files/github-runs-on.js",
|
|
124
|
+
"default": "./dist/managed-files/github-runs-on.js"
|
|
125
|
+
},
|
|
126
|
+
"./managed-files/pr-preview-cleanup-workflow": {
|
|
127
|
+
"types": "./dist/managed-files/pr-preview-cleanup-workflow.d.ts",
|
|
128
|
+
"import": "./dist/managed-files/pr-preview-cleanup-workflow.js",
|
|
129
|
+
"default": "./dist/managed-files/pr-preview-cleanup-workflow.js"
|
|
130
|
+
},
|
|
131
|
+
"./managed-files/private-npm-policy": {
|
|
132
|
+
"types": "./dist/managed-files/private-npm-policy.d.ts",
|
|
133
|
+
"import": "./dist/managed-files/private-npm-policy.js",
|
|
134
|
+
"default": "./dist/managed-files/private-npm-policy.js"
|
|
135
|
+
},
|
|
136
|
+
"./managed-files/context": {
|
|
137
|
+
"types": "./dist/managed-files/context.d.ts",
|
|
138
|
+
"import": "./dist/managed-files/context.js",
|
|
139
|
+
"default": "./dist/managed-files/context.js"
|
|
60
140
|
}
|
|
61
141
|
},
|
|
62
142
|
"bin": {
|
|
@@ -94,7 +174,8 @@
|
|
|
94
174
|
"loader.js",
|
|
95
175
|
"generators.json",
|
|
96
176
|
"executors.json",
|
|
97
|
-
"!**/*.tsbuildinfo"
|
|
177
|
+
"!**/*.tsbuildinfo",
|
|
178
|
+
"managed"
|
|
98
179
|
],
|
|
99
180
|
"license": "MIT",
|
|
100
181
|
"publishConfig": {
|
|
@@ -108,12 +189,15 @@
|
|
|
108
189
|
"dependencies": {
|
|
109
190
|
"@nx/js": "latest",
|
|
110
191
|
"nx": "latest",
|
|
192
|
+
"prettier": "^3.6.1",
|
|
111
193
|
"smol-toml": "^1.6.1",
|
|
112
194
|
"tslib": "^2.8.1",
|
|
113
|
-
"typia": "14.0.2"
|
|
195
|
+
"typia": "14.0.2",
|
|
196
|
+
"yaml": "^2.9.0"
|
|
114
197
|
},
|
|
115
198
|
"devDependencies": {
|
|
116
|
-
"@smoothbricks/lmao": "0.
|
|
117
|
-
"@smoothbricks/validation": "0.1.
|
|
199
|
+
"@smoothbricks/lmao": "0.4.0",
|
|
200
|
+
"@smoothbricks/validation": "0.1.9",
|
|
201
|
+
"fast-check": "^4.4.0"
|
|
118
202
|
}
|
|
119
203
|
}
|
|
@@ -45,10 +45,4 @@ describe('Bun bootstrap imports', () => {
|
|
|
45
45
|
expect(typeof policy.packageNxProjectName).toBe('function');
|
|
46
46
|
expect(Array.isArray(policy.BUILD_OUTPUT_DEPENDENCIES)).toBe(true);
|
|
47
47
|
});
|
|
48
|
-
|
|
49
|
-
it('imports typecheck-test-policy', async () => {
|
|
50
|
-
const policy = await import('./typecheck-test-policy.js');
|
|
51
|
-
expect(typeof policy.checkTypecheckTestPolicy).toBe('function');
|
|
52
|
-
expect(typeof policy.applyTypecheckTestPolicy).toBe('function');
|
|
53
|
-
});
|
|
54
48
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The Nx tags that drive stage deploys. CI selection (github-ci), workflow generation (monorepo)
|
|
2
|
+
// and the graph readers must agree on these, so they live here rather than with any one of them.
|
|
3
|
+
|
|
4
|
+
export type DeploymentStage = 'staging' | 'production' | `pr${number}`;
|
|
5
|
+
|
|
6
|
+
/** Deployed on every stage: one command that deploys whichever stage it is given. */
|
|
7
|
+
const STAGE_DEPLOY_TAG = 'stage-deploy-target';
|
|
8
|
+
|
|
9
|
+
/** Deployed on staging only: infrastructure the pull-request stages share. */
|
|
10
|
+
export const STAGING_DEPLOY_TAG = 'staging-deploy-target';
|
|
11
|
+
|
|
12
|
+
/** Excluded from every stage deploy; deployed outside the stage flow. */
|
|
13
|
+
export const PERMANENT_DEPLOY_TAG = 'permanent-deploy-target';
|
|
14
|
+
|
|
15
|
+
/** Opts a project into the generated production-on-push deploy job. */
|
|
16
|
+
export const PRODUCTION_PUSH_DEPLOY_TAG = 'production-push-deploy-target';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether the stage flow deploys a project, from its TAGS alone — the one rule
|
|
20
|
+
* CI selection and workflow generation both read, so a generated deploy job and
|
|
21
|
+
* the projects that job deploys cannot disagree.
|
|
22
|
+
*
|
|
23
|
+
* Having a `deploy` target is not that answer. A deploy target says a project
|
|
24
|
+
* CAN be deployed; only a tag says CI does it. A published library ships a
|
|
25
|
+
* wrangler manifest to document a Durable Object binding for its consumers, and
|
|
26
|
+
* that manifest is structurally identical to a deployable worker's — so the
|
|
27
|
+
* plugin infers `deploy` from one, and a repository that deploys nothing from CI
|
|
28
|
+
* would otherwise generate a deploy job, with cloud credentials, for it.
|
|
29
|
+
*
|
|
30
|
+
* The three tags compose as precedence, not as a set: `permanent` excludes a
|
|
31
|
+
* project from every stage, `staging` narrows it to one, `stage` generalizes it
|
|
32
|
+
* to all. `production-push` selects WITHIN this answer (see `--select-tag`) and
|
|
33
|
+
* never widens it.
|
|
34
|
+
*/
|
|
35
|
+
export function stageDeploysProject(tags: string[] | undefined, stage: DeploymentStage): boolean {
|
|
36
|
+
if (tags === undefined) return false;
|
|
37
|
+
if (tags.includes(PERMANENT_DEPLOY_TAG)) return false;
|
|
38
|
+
if (tags.includes(STAGING_DEPLOY_TAG)) return stage === 'staging';
|
|
39
|
+
return tags.includes(STAGE_DEPLOY_TAG);
|
|
40
|
+
}
|
package/src/index.test.ts
CHANGED
|
@@ -118,7 +118,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
118
118
|
const workspace = await createWorkspace();
|
|
119
119
|
try {
|
|
120
120
|
await workspace.write(
|
|
121
|
-
'packages/
|
|
121
|
+
'packages/nx-plugin/managed/raw/tooling/typescript-api/package.json',
|
|
122
122
|
'{"name":"@smoothbricks/typescript-api","private":true}\n',
|
|
123
123
|
);
|
|
124
124
|
await workspace.write(
|
|
@@ -127,7 +127,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
127
127
|
);
|
|
128
128
|
|
|
129
129
|
const managed = await inferTargets(
|
|
130
|
-
['packages/
|
|
130
|
+
['packages/nx-plugin/managed/raw/tooling/typescript-api/package.json'],
|
|
131
131
|
undefined,
|
|
132
132
|
workspace.context,
|
|
133
133
|
);
|
|
@@ -410,6 +410,210 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
410
410
|
}
|
|
411
411
|
});
|
|
412
412
|
|
|
413
|
+
it('hashes every tsconfig the extends chain reaches, not just the one the command names', async () => {
|
|
414
|
+
const workspace = await createWorkspace();
|
|
415
|
+
try {
|
|
416
|
+
// The shape that made this a silent cache hit: the options a check
|
|
417
|
+
// resolves live one file ABOVE the config its command names.
|
|
418
|
+
await workspace.write('tsconfig.base.json', '{"compilerOptions":{"strict":true}}\n');
|
|
419
|
+
await workspace.write(
|
|
420
|
+
'packages/tsconfig.base.json',
|
|
421
|
+
'{"extends":"../tsconfig.base.json","compilerOptions":{"noUnusedLocals":true}}\n',
|
|
422
|
+
);
|
|
423
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
424
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"../tsconfig.base.json"}\n');
|
|
425
|
+
// A deeper chain reached from the other config, named without the
|
|
426
|
+
// extension TypeScript lets a specifier omit.
|
|
427
|
+
await workspace.write('packages/example/tsconfig.strict.json', '{"extends":"../tsconfig.base"}\n');
|
|
428
|
+
await workspace.write('packages/example/tsconfig.test.json', '{"extends":"./tsconfig.strict.json"}\n');
|
|
429
|
+
|
|
430
|
+
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
431
|
+
|
|
432
|
+
// Every file in the chain, once, whichever config reached it.
|
|
433
|
+
const configChain = [
|
|
434
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
435
|
+
'{workspaceRoot}/packages/tsconfig.base.json',
|
|
436
|
+
'{workspaceRoot}/packages/example/tsconfig.strict.json',
|
|
437
|
+
];
|
|
438
|
+
const checkToolchain = [
|
|
439
|
+
'{workspaceRoot}/patches/**/*',
|
|
440
|
+
...configChain,
|
|
441
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
442
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
443
|
+
];
|
|
444
|
+
expect(targets.typecheck?.inputs).toEqual([
|
|
445
|
+
'versionlessProduction',
|
|
446
|
+
'^production',
|
|
447
|
+
...checkToolchain,
|
|
448
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
449
|
+
]);
|
|
450
|
+
expect(targets['typecheck-tests']?.inputs).toEqual([
|
|
451
|
+
'versionlessDefault',
|
|
452
|
+
'^production',
|
|
453
|
+
...checkToolchain,
|
|
454
|
+
'{projectRoot}/tsconfig.test.json',
|
|
455
|
+
]);
|
|
456
|
+
// An emit reads the same options, and a stale artifact is worse than a
|
|
457
|
+
// stale verdict.
|
|
458
|
+
expect(targets['tsc-js']?.inputs).toEqual([
|
|
459
|
+
'production',
|
|
460
|
+
'^production',
|
|
461
|
+
'{workspaceRoot}/package.json',
|
|
462
|
+
'{workspaceRoot}/bun.lock',
|
|
463
|
+
'{workspaceRoot}/patches/**/*',
|
|
464
|
+
...configChain,
|
|
465
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
466
|
+
]);
|
|
467
|
+
// Typed lint runs the same program (`projectService`), so its verdict
|
|
468
|
+
// moves with the same files.
|
|
469
|
+
expect(targets.lint?.inputs).toEqual(expect.arrayContaining(configChain));
|
|
470
|
+
} finally {
|
|
471
|
+
await workspace.cleanup();
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('refuses a project whose tsconfig extends a file that is not there', async () => {
|
|
476
|
+
const workspace = await createWorkspace();
|
|
477
|
+
try {
|
|
478
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
479
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"../tsconfig.base.json"}\n');
|
|
480
|
+
|
|
481
|
+
// Fail-closed, and the only safe direction: an ancestor left out of the
|
|
482
|
+
// hash is a cached verdict nobody can invalidate. Nx wraps a createNodes
|
|
483
|
+
// throw, so the reason lives in the nested error.
|
|
484
|
+
const failure = await inferProjectTargets(workspace, 'packages/example/package.json').then(
|
|
485
|
+
() => undefined,
|
|
486
|
+
(error: unknown) => error,
|
|
487
|
+
);
|
|
488
|
+
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
489
|
+
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
490
|
+
}
|
|
491
|
+
expect(failure.errors[0]?.[1]?.message).toMatch(/"extends": "\.\.\/tsconfig\.base\.json" names no file/);
|
|
492
|
+
} finally {
|
|
493
|
+
await workspace.cleanup();
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('walks an extends cycle once, and leaves an installed config to the lockfile wherever it is stored', async () => {
|
|
498
|
+
const workspace = await createWorkspace();
|
|
499
|
+
// WHERE an installed config's bytes sit is the installer's business: bun
|
|
500
|
+
// keeps them in a global store and points node_modules at it, so this one
|
|
501
|
+
// is outside the workspace entirely.
|
|
502
|
+
const store = await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-store-'));
|
|
503
|
+
try {
|
|
504
|
+
await workspace.write('tsconfig.base.json', '{"compilerOptions":{"strict":true}}\n');
|
|
505
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
506
|
+
// TypeScript rejects a cycle; this walk must terminate on one anyway,
|
|
507
|
+
// with both files hashed.
|
|
508
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"./tsconfig.cycle.json"}\n');
|
|
509
|
+
await workspace.write('packages/example/tsconfig.cycle.json', '{"extends":"./tsconfig.lib.json"}\n');
|
|
510
|
+
// Which bytes are in that store is pinned by the lockfile and the root
|
|
511
|
+
// manifest, both already inputs; naming the path would hash nothing.
|
|
512
|
+
await writeFile(join(store, 'package.json'), '{"name":"@fixture/tsconfig"}\n');
|
|
513
|
+
await writeFile(join(store, 'tsconfig.json'), '{"compilerOptions":{"noUnusedLocals":true}}\n');
|
|
514
|
+
await mkdir(join(workspace.context.workspaceRoot, 'node_modules/@fixture'), { recursive: true });
|
|
515
|
+
await symlink(store, join(workspace.context.workspaceRoot, 'node_modules/@fixture/tsconfig'), 'dir');
|
|
516
|
+
await workspace.write('packages/example/tsconfig.test.json', '{"extends":"@fixture/tsconfig/tsconfig.json"}\n');
|
|
517
|
+
|
|
518
|
+
const { result: targets, stderr } = await withCapturedStderr(() =>
|
|
519
|
+
inferProjectTargets(workspace, 'packages/example/package.json'),
|
|
520
|
+
);
|
|
521
|
+
const inputs = targets.typecheck?.inputs ?? [];
|
|
522
|
+
|
|
523
|
+
expect(inputs).toEqual([
|
|
524
|
+
'versionlessProduction',
|
|
525
|
+
'^production',
|
|
526
|
+
'{workspaceRoot}/patches/**/*',
|
|
527
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
528
|
+
'{workspaceRoot}/packages/example/tsconfig.cycle.json',
|
|
529
|
+
'{workspaceRoot}/packages/example/tsconfig.lib.json',
|
|
530
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
531
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
532
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
533
|
+
]);
|
|
534
|
+
expect(JSON.stringify(inputs)).not.toContain('node_modules');
|
|
535
|
+
// And silently, because nothing was lost. The noisy version of this fires
|
|
536
|
+
// on every graph build in a workspace that installs one Expo package.
|
|
537
|
+
expect(stderr).toBe('');
|
|
538
|
+
} finally {
|
|
539
|
+
await rm(store, { recursive: true, force: true });
|
|
540
|
+
await workspace.cleanup();
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("hashes a workspace member's config reached through its package name", async () => {
|
|
545
|
+
const workspace = await createWorkspace();
|
|
546
|
+
try {
|
|
547
|
+
const root = workspace.context.workspaceRoot;
|
|
548
|
+
await workspace.write('tsconfig.base.json', '{"compilerOptions":{"strict":true}}\n');
|
|
549
|
+
// The other half of that judgement: a package name can resolve to
|
|
550
|
+
// workspace SOURCE, which no lockfile pins. Dropping it would be the
|
|
551
|
+
// original bug wearing a package name.
|
|
552
|
+
await workspace.write('packages/tsconfig/package.json', '{"name":"@fixture/tsconfig"}\n');
|
|
553
|
+
await workspace.write(
|
|
554
|
+
'packages/tsconfig/base.json',
|
|
555
|
+
'{"extends":"../../tsconfig.base.json","compilerOptions":{"noUnusedLocals":true}}\n',
|
|
556
|
+
);
|
|
557
|
+
await mkdir(join(root, 'node_modules/@fixture'), { recursive: true });
|
|
558
|
+
await symlink(join(root, 'packages/tsconfig'), join(root, 'node_modules/@fixture/tsconfig'), 'dir');
|
|
559
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
560
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{"extends":"@fixture/tsconfig/base.json"}\n');
|
|
561
|
+
|
|
562
|
+
const { result: targets, stderr } = await withCapturedStderr(() =>
|
|
563
|
+
inferProjectTargets(workspace, 'packages/example/package.json'),
|
|
564
|
+
);
|
|
565
|
+
|
|
566
|
+
expect(targets.typecheck?.inputs).toEqual([
|
|
567
|
+
'versionlessProduction',
|
|
568
|
+
'^production',
|
|
569
|
+
'{workspaceRoot}/patches/**/*',
|
|
570
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
571
|
+
'{workspaceRoot}/packages/tsconfig/base.json',
|
|
572
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
573
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
574
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
575
|
+
]);
|
|
576
|
+
expect(stderr).toBe('');
|
|
577
|
+
} finally {
|
|
578
|
+
await workspace.cleanup();
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
it('says so when an extends chain leaves the workspace, where nothing can hash it', async () => {
|
|
583
|
+
const workspace = await createWorkspace();
|
|
584
|
+
const outside = await mkdtemp(join(tmpdir(), 'smoothbricks-nx-plugin-outside-'));
|
|
585
|
+
try {
|
|
586
|
+
await writeFile(join(outside, 'tsconfig.base.json'), '{"compilerOptions":{"noUnusedLocals":true}}\n');
|
|
587
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
588
|
+
await workspace.write(
|
|
589
|
+
'packages/example/tsconfig.lib.json',
|
|
590
|
+
`${JSON.stringify({ extends: join(outside, 'tsconfig.base.json') })}\n`,
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
const { result: targets, stderr } = await withCapturedStderr(() =>
|
|
594
|
+
inferProjectTargets(workspace, 'packages/example/package.json'),
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
// Nx hashes workspace files only, and no lockfile pins this one either,
|
|
598
|
+
// so the verdict really can go stale. A silent drop here is the bug this
|
|
599
|
+
// walk exists to close, so it is said out loud instead.
|
|
600
|
+
expect(stderr).toContain(join(outside, 'tsconfig.base.json'));
|
|
601
|
+
expect(stderr).toContain('outside the workspace');
|
|
602
|
+
expect(targets.typecheck?.inputs).toEqual([
|
|
603
|
+
'versionlessProduction',
|
|
604
|
+
'^production',
|
|
605
|
+
'{workspaceRoot}/patches/**/*',
|
|
606
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
607
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
608
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
609
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
610
|
+
]);
|
|
611
|
+
} finally {
|
|
612
|
+
await rm(outside, { recursive: true, force: true });
|
|
613
|
+
await workspace.cleanup();
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
|
|
413
617
|
it('rebuilds current library declarations before test typechecking after clean', async () => {
|
|
414
618
|
const workspace = await createWorkspace();
|
|
415
619
|
try {
|
|
@@ -2017,6 +2221,25 @@ interface WorkspaceFixture {
|
|
|
2017
2221
|
cleanup(): Promise<void>;
|
|
2018
2222
|
}
|
|
2019
2223
|
|
|
2224
|
+
/**
|
|
2225
|
+
* What inference told the operator while it ran. The plugin degrades out loud
|
|
2226
|
+
* — a hash it cannot make complete is a cache verdict nobody can invalidate —
|
|
2227
|
+
* so the stream is part of its behavior, not decoration.
|
|
2228
|
+
*/
|
|
2229
|
+
async function withCapturedStderr<T>(run: () => Promise<T>): Promise<{ result: T; stderr: string }> {
|
|
2230
|
+
const original = process.stderr.write.bind(process.stderr);
|
|
2231
|
+
let stderr = '';
|
|
2232
|
+
process.stderr.write = (chunk: string | Uint8Array) => {
|
|
2233
|
+
stderr += typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
|
|
2234
|
+
return true;
|
|
2235
|
+
};
|
|
2236
|
+
try {
|
|
2237
|
+
return { result: await run(), stderr };
|
|
2238
|
+
} finally {
|
|
2239
|
+
process.stderr.write = original;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2020
2243
|
/**
|
|
2021
2244
|
* A fileset Nx resolves against the workspace, or a named input nx.json
|
|
2022
2245
|
* declares. Anything else is a path this machine happens to have.
|