@smoothbricks/nx-plugin 0.4.14 → 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.
Files changed (119) hide show
  1. package/README.md +20 -3
  2. package/dist/deploy-policy.d.ts +26 -0
  3. package/dist/deploy-policy.d.ts.map +1 -0
  4. package/dist/deploy-policy.js +36 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +160 -37
  7. package/dist/managed-assets.d.ts +3 -0
  8. package/dist/managed-assets.d.ts.map +1 -0
  9. package/dist/managed-assets.js +3 -0
  10. package/dist/managed-files/ci-workflow.d.ts +215 -0
  11. package/dist/managed-files/ci-workflow.d.ts.map +1 -0
  12. package/dist/managed-files/ci-workflow.js +1082 -0
  13. package/dist/managed-files/context.d.ts +51 -0
  14. package/dist/managed-files/context.d.ts.map +1 -0
  15. package/dist/managed-files/context.js +206 -0
  16. package/dist/managed-files/files.d.ts +53 -0
  17. package/dist/managed-files/files.d.ts.map +1 -0
  18. package/dist/managed-files/files.js +248 -0
  19. package/dist/managed-files/generator.d.ts +16 -0
  20. package/dist/managed-files/generator.d.ts.map +1 -0
  21. package/dist/managed-files/generator.js +41 -0
  22. package/dist/managed-files/github-runs-on.d.ts +19 -0
  23. package/dist/managed-files/github-runs-on.d.ts.map +1 -0
  24. package/dist/managed-files/github-runs-on.js +48 -0
  25. package/dist/managed-files/managed-content.d.ts +45 -0
  26. package/dist/managed-files/managed-content.d.ts.map +1 -0
  27. package/dist/managed-files/managed-content.js +102 -0
  28. package/dist/managed-files/managed-format.d.ts +37 -0
  29. package/dist/managed-files/managed-format.d.ts.map +1 -0
  30. package/dist/managed-files/managed-format.js +94 -0
  31. package/dist/managed-files/paths.d.ts +8 -0
  32. package/dist/managed-files/paths.d.ts.map +1 -0
  33. package/dist/managed-files/paths.js +46 -0
  34. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +5 -0
  35. package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -0
  36. package/dist/managed-files/pr-preview-cleanup-workflow.js +38 -0
  37. package/dist/managed-files/private-npm-policy.d.ts +7 -0
  38. package/dist/managed-files/private-npm-policy.d.ts.map +1 -0
  39. package/dist/managed-files/private-npm-policy.js +51 -0
  40. package/dist/managed-files/publish-workflow.d.ts +150 -0
  41. package/dist/managed-files/publish-workflow.d.ts.map +1 -0
  42. package/dist/managed-files/publish-workflow.js +989 -0
  43. package/dist/managed-files/tree.d.ts +30 -0
  44. package/dist/managed-files/tree.d.ts.map +1 -0
  45. package/dist/managed-files/tree.js +91 -0
  46. package/dist/package-target-policy.d.ts +0 -1
  47. package/dist/package-target-policy.d.ts.map +1 -1
  48. package/dist/package-target-policy.js +50 -23
  49. package/dist/platform-targets.d.ts +5 -0
  50. package/dist/platform-targets.d.ts.map +1 -0
  51. package/dist/platform-targets.js +4 -0
  52. package/dist/typecheck-test-policy.d.ts +5 -9
  53. package/dist/typecheck-test-policy.d.ts.map +1 -1
  54. package/dist/typecheck-test-policy.js +69 -99
  55. package/dist/workspace-config-policy.d.ts +23 -3
  56. package/dist/workspace-config-policy.d.ts.map +1 -1
  57. package/dist/workspace-config-policy.js +35 -3
  58. package/dist/workspace-manifest.d.ts +291 -0
  59. package/dist/workspace-manifest.d.ts.map +1 -0
  60. package/dist/workspace-manifest.js +6 -0
  61. package/dist/workspace-package-policy.d.ts +13 -0
  62. package/dist/workspace-package-policy.d.ts.map +1 -0
  63. package/dist/workspace-package-policy.js +24 -0
  64. package/generators.json +5 -0
  65. package/managed/raw/envrc +20 -0
  66. package/managed/raw/git-format-staged.yml +82 -0
  67. package/managed/raw/gitattributes +8 -0
  68. package/managed/raw/tooling/devenv +83 -0
  69. package/managed/raw/tooling/direnv/devenv.smoo.nix +422 -0
  70. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +251 -0
  71. package/managed/raw/tooling/direnv/merge-newer-pins.sh +48 -0
  72. package/managed/raw/tooling/direnv/repo-path +34 -0
  73. package/managed/raw/tooling/direnv/secret-references.ts +636 -0
  74. package/managed/raw/tooling/direnv/setup-environment.ts +585 -0
  75. package/managed/raw/tooling/direnv/toolchain-stamp.ts +88 -0
  76. package/managed/raw/tooling/git-hooks/commit-msg.sh +9 -0
  77. package/managed/raw/tooling/git-hooks/post-commit.sh +71 -0
  78. package/managed/raw/tooling/git-hooks/pre-commit.sh +18 -0
  79. package/managed/raw/tooling/git-hooks/pre-push.sh +48 -0
  80. package/managed/raw/tsconfig.lib.json +28 -0
  81. package/managed/templates/github/actions/cache-nix-devenv/action.yml +45 -0
  82. package/managed/templates/github/actions/cache-node-modules/action.yml +17 -0
  83. package/managed/templates/github/actions/cache-nx/action.yml +21 -0
  84. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +19 -0
  85. package/managed/templates/github/actions/save-nix-devenv/action.yml +32 -0
  86. package/managed/templates/github/actions/setup-devenv/action.yml +241 -0
  87. package/managed/templates/github/workflows/managed-files.yml +127 -0
  88. package/package.json +89 -5
  89. package/src/bun-bootstrap.test.ts +0 -6
  90. package/src/deploy-policy.ts +40 -0
  91. package/src/index.test.ts +232 -9
  92. package/src/index.ts +187 -40
  93. package/src/managed-assets.ts +4 -0
  94. package/src/managed-files/ci-workflow.ts +1365 -0
  95. package/src/managed-files/context.ts +240 -0
  96. package/src/managed-files/files.ts +324 -0
  97. package/src/managed-files/generator.test.ts +151 -0
  98. package/src/managed-files/generator.ts +60 -0
  99. package/src/managed-files/github-runs-on.ts +51 -0
  100. package/src/managed-files/managed-content.test.ts +147 -0
  101. package/src/managed-files/managed-content.ts +121 -0
  102. package/src/managed-files/managed-format.ts +102 -0
  103. package/src/managed-files/paths.ts +44 -0
  104. package/src/managed-files/pr-preview-cleanup-workflow.ts +44 -0
  105. package/src/managed-files/private-npm-policy.ts +62 -0
  106. package/src/managed-files/publish-workflow.ts +1523 -0
  107. package/src/managed-files/schema.json +8 -0
  108. package/src/managed-files/tree-permissions.test.ts +109 -0
  109. package/src/managed-files/tree.test.ts +123 -0
  110. package/src/managed-files/tree.ts +118 -0
  111. package/src/package-target-policy.test.ts +4 -28
  112. package/src/package-target-policy.ts +55 -31
  113. package/src/platform-targets.ts +4 -0
  114. package/src/typecheck-test-policy.test.ts +28 -3
  115. package/src/typecheck-test-policy.ts +46 -121
  116. package/src/workspace-config-policy.test.ts +14 -2
  117. package/src/workspace-config-policy.ts +42 -3
  118. package/src/workspace-manifest.ts +327 -0
  119. package/src/workspace-package-policy.ts +32 -0
@@ -0,0 +1,327 @@
1
+ import type typia from 'typia';
2
+
3
+ /** String-keyed dependency / script / engine maps. */
4
+ export type StringMap = Record<string, string>;
5
+
6
+ /** An array statically known to hold at least one item. */
7
+ export type NonEmptyArray<T> = [T, ...T[]];
8
+
9
+ export function isNonEmpty<T>(items: T[]): items is NonEmptyArray<T> {
10
+ return items.length > 0;
11
+ }
12
+
13
+ /** A git branch usable as a workflow push trigger; an empty string would render a trigger that matches nothing. */
14
+ export type BranchName = string & typia.tags.MinLength<1>;
15
+
16
+ /**
17
+ * A repository secret referenced from a workflow `env:` block. GitHub forbids creating secrets whose name
18
+ * starts with GITHUB_, so such a reference could only ever resolve to an empty value.
19
+ */
20
+ export type RepositorySecretName = string &
21
+ typia.tags.MinLength<1> &
22
+ typia.tags.Pattern<'^(?![Gg][Ii][Tt][Hh][Uu][Bb]_)'>;
23
+
24
+ /** Environment variable names mapped to repository secret names. */
25
+ export type SecretEnvMap = Record<string, RepositorySecretName>;
26
+
27
+ /** A pull-request preview URL template; `{stage}` is replaced with the stage name at deploy time. */
28
+ export type PreviewUrlTemplate = string & typia.tags.Pattern<'.*\\{stage\\}.*'>;
29
+
30
+ export interface PackageRepository {
31
+ type?: string;
32
+ url?: string;
33
+ directory?: string;
34
+ }
35
+
36
+ export interface PackageNxConfig {
37
+ name?: string;
38
+ tags?: string[];
39
+ includedScripts?: string[];
40
+ targets?: Record<string, NxTargetConfig>;
41
+ }
42
+
43
+ export interface PackagePublishConfig {
44
+ access?: string;
45
+ /** Real registry URL for publication metadata. Resolved configuration only — never an environment placeholder in a packed package.json. */
46
+ registry?: string;
47
+ }
48
+
49
+ export interface PackageSmooGithubEnvironments {
50
+ /** GitHub Environment for the staging deploy and e2e jobs. */
51
+ staging?: string;
52
+ /** GitHub Environment for the production-on-push deploy job. */
53
+ production?: string;
54
+ }
55
+
56
+ export interface PackageSmooGithub {
57
+ /** Action repository provider selected while generating workflows. Default: GitHub. */
58
+ actionsProvider?: 'github' | 'forgejo';
59
+ pushBranches?: NonEmptyArray<BranchName>;
60
+ /** GitHub Actions runs-on for managed CI (string or label list). Default: ubuntu-latest. */
61
+ runsOn?: string | string[];
62
+ environments?: PackageSmooGithubEnvironments;
63
+ deploySecrets?: SecretEnvMap;
64
+ /** Secrets exposed only to the e2e-deployment step. */
65
+ e2eSecrets?: SecretEnvMap;
66
+ /** Pull-request preview URL templates; `{stage}` is replaced with the stage name. */
67
+ previewUrls?: PreviewUrlTemplate[];
68
+ /** macOS platform job runs-on labels (string or label list). Default: macos-latest. */
69
+ macosRunsOn?: string | string[];
70
+ /** Opt in to building foreign platform artifacts on Linux without native-host runtime tests. */
71
+ platformProducer?: {
72
+ kind: 'linux-cross';
73
+ /** Required shell preflight, run from the repository root before toolchain setup or builds. */
74
+ preflight: string;
75
+ /** Toolchain environment on the Linux foreign-platform producer, such as an SDK path. */
76
+ env?: StringMap;
77
+ };
78
+ /**
79
+ * Platform target families the RELEASE workflow must not produce, as target
80
+ * globs (`*-macos`, `*-ios`, `*-linux`). A repository whose Nx graph carries
81
+ * a family it does not release from `publish.yml` — because another workflow
82
+ * owns it, or because the leg is not production yet — names it here, and the
83
+ * publish workflow renders without that job instead of carrying a leg whose
84
+ * failure blocks every release.
85
+ */
86
+ releasePlatformFamiliesExcluded?: string[];
87
+ /**
88
+ * Sibling source checkouts a repo path-depends on (Cargo path
89
+ * dependencies, nix path inputs). The CI workflow clones each entry beside
90
+ * the main checkout before any build step runs, so the workspace layout on
91
+ * CI matches the developer workspace. Private sources need tokenEnv naming
92
+ * the repo-scoped read secret; fork PRs receive no secrets and skip the
93
+ * step entirely.
94
+ */
95
+ sourceCheckouts?: PackageSourceCheckoutConfig[];
96
+ /** Declared Cargo private-dependency credentials; absent means no private Cargo fetch. */
97
+ cargoCredentials?: PackageCargoCredentialsConfig;
98
+ }
99
+
100
+ /** One declared sibling source checkout for managed CI. */
101
+ export interface PackageSourceCheckoutConfig {
102
+ /** Destination relative to the CI workspace root, e.g. `../smoothbricks`. */
103
+ path: string;
104
+ /** HTTPS clone URL of the source repository. */
105
+ repository: string;
106
+ /** Exact commit or ref to check out; the remote default branch when omitted. */
107
+ ref?: string;
108
+ /** Secret name holding the source-read credential; required for private sources. */
109
+ tokenEnv?: string;
110
+ }
111
+
112
+ /**
113
+ * Declared opt-in for Cargo fetching private dependencies in managed CI. The
114
+ * generator wires the named secrets into the job environment and, for private
115
+ * git origins, installs a host-gated credential helper through `GIT_CONFIG_*`
116
+ * process environment: the token is read at helper-call time, never embedded
117
+ * in a URL, argv, or any stored git/cargo configuration, and an empty
118
+ * `credential.helper` reset keeps an ambient credential store from capturing
119
+ * it. Registry tokens are plain `CARGO_REGISTRIES_<NAME>_TOKEN` mappings read
120
+ * by Cargo's own credential provider.
121
+ */
122
+ export interface PackageCargoCredentialsConfig {
123
+ /** Private git origins Cargo fetches dependencies from. */
124
+ gitOrigins?: PackageCargoGitOrigin[];
125
+ /** Credential env names Cargo's `cargo:token` provider reads for private registries. */
126
+ registryTokenEnvs?: string[];
127
+ }
128
+
129
+ /** One private git origin with the secret that reads it. */
130
+ export interface PackageCargoGitOrigin {
131
+ /** Credential-free https origin, e.g. `https://git.example.net`. */
132
+ origin: string;
133
+ /** Secret name holding the source-read credential for this origin. */
134
+ tokenEnv: string;
135
+ /**
136
+ * Internal mirror of the origin, e.g. `http://10.89.0.1:3000` for a runner
137
+ * that reaches its own forge over guest networking instead of the public
138
+ * URL. Managed CI rewrites the origin prefix to the mirror with
139
+ * `url.<mirror>.insteadOf` and answers the same credential for the
140
+ * mirror's host (git passes helpers the rewritten URL). Omitted means the
141
+ * origin is fetched as declared.
142
+ */
143
+ internalMirror?: string;
144
+ /**
145
+ * SSH spellings of the same forge that managed CI rewrites onto
146
+ * `internalMirror` as well, e.g. `ssh://forgejo@forge.example.net:2223/`
147
+ * as Cargo and uv pin a git dependency. A runner holds the read token the
148
+ * mirror accepts and no SSH key at all, so every spelling a lockfile can
149
+ * carry needs its own rewrite: git matches `insteadOf` values as literal
150
+ * URL prefixes and infers no spelling from another — not the SSH host from
151
+ * the HTTPS one, and not the userless form from the one carrying a user.
152
+ * Each entry is a credential-free `ssh://` origin without a path; the SSH
153
+ * user is part of the spelling and stays in it. Requires
154
+ * `internalMirror`, since the entry is a rewrite source and nothing else.
155
+ */
156
+ sshOrigins?: string[];
157
+ }
158
+
159
+ /**
160
+ * Declared opt-in for private npm distribution. The registry URL itself is
161
+ * the scoped `@scope:registry` entry in the committed .npmrc — never a
162
+ * required environment variable and never a shell-entry check. Token env
163
+ * names are taken from `.npmrc` `${VAR}` auth lines when omitted. A consumer
164
+ * that never publishes packages in this scope omits publishTokenEnv; a
165
+ * producer whose install is fully `workspace:`/`link:`/`file:` omits
166
+ * readTokenEnv.
167
+ */
168
+ export interface PackagePrivateNpmConfig {
169
+ scope: string;
170
+ /** Environment variable holding the package-read token, referenced from .npmrc. */
171
+ readTokenEnv?: string;
172
+ /** Environment variable holding the separate publisher token; publishers only. */
173
+ publishTokenEnv?: string;
174
+ }
175
+
176
+ /**
177
+ * Declared self-hosted Nx remote cache (`smoo.remoteCache`). Nx enables its
178
+ * HTTP cache on a nonempty NX_SELF_HOSTED_REMOTE_CACHE_SERVER and reads the
179
+ * credential from NX_SELF_HOSTED_REMOTE_CACHE_ACCESS_TOKEN; this declaration
180
+ * is what puts that pair in a managed CI job's environment and in a developer
181
+ * shell (tooling/direnv/secret-references.ts). Absent means every workspace
182
+ * keeps its own local cache and nothing is shared.
183
+ *
184
+ * The pair is emitted whole or not at all, because Nx accepts only 200 or 404
185
+ * from a cache server: a server without a working credential fails every task
186
+ * with 401 rather than missing quietly.
187
+ */
188
+ export interface PackageRemoteCacheConfig {
189
+ /**
190
+ * Origin every runner and developer machine can reach, e.g.
191
+ * `https://nx-cache.example.net`. Credential-free, no path, and no trailing
192
+ * slash — Nx appends `/v1/cache/<hash>`, so a trailing slash requests
193
+ * `//v1/cache/<hash>`, which is a different route and answers 404 forever.
194
+ */
195
+ server: string;
196
+ /**
197
+ * Origin an internal runner reaches instead of `server`, e.g.
198
+ * `http://10.89.0.1:8765` across a container bridge. Same declaration as a
199
+ * git origin's `internalMirror`: declaring it says this repository's managed
200
+ * runners are inside that network, so managed CI uses it and shells outside
201
+ * keep `server`. Omitted means CI uses `server` too.
202
+ */
203
+ internalServer?: string;
204
+ /**
205
+ * Repository secret holding the cache token, and the same variable name a
206
+ * developer shell resolves locally (an ambient value or a `smoo.secrets`
207
+ * entry). A read-only token here keeps an untrusted context reading the
208
+ * cache without being able to publish into it.
209
+ */
210
+ tokenSecret: RepositorySecretName;
211
+ }
212
+
213
+ /**
214
+ * A `smoo.secrets` group: which operation resolves the credential. One argv
215
+ * word of `smoo secrets run <group> <command...>`, so whitespace would make
216
+ * that command unwritable. Only the shape is validated — the values are the
217
+ * repository's, and a new group must not need a new smoo release.
218
+ */
219
+ export type SecretGroupName = string & typia.tags.MinLength<1> & typia.tags.Pattern<'^\\S+$'>;
220
+
221
+ /**
222
+ * Local bootstrap fallback; existing environment values always take
223
+ * precedence, and CI injects these variables instead of running commands.
224
+ *
225
+ * Shell entry resolves the `shell` group and nothing else; every other group
226
+ * is resolved by `smoo secrets run <group> <command...>`, the one command
227
+ * that needs it. The group is DERIVED from what this manifest already
228
+ * declares — a variable `.npmrc` interpolates as `${VAR}` is `registry`, the
229
+ * variable `smoo.remoteCache.tokenSecret` names is `nx-cache`, everything
230
+ * else is `shell` — so `group` below is only for what those declarations
231
+ * cannot say. The routing lives in tooling/direnv/secret-references.ts,
232
+ * whose header states the rule and the derivation.
233
+ */
234
+ export interface PackageSecretCommand {
235
+ /** Executed directly, without a shell; stdout supplies the secret value. */
236
+ command: NonEmptyArray<string>;
237
+ /** Overrides the derived group; absent derives one from this manifest and `.npmrc`. */
238
+ group?: SecretGroupName;
239
+ }
240
+
241
+ export interface PackageSmooConfig {
242
+ github?: PackageSmooGithub;
243
+ privateNpm?: PackagePrivateNpmConfig;
244
+ /** Declared self-hosted Nx remote cache; absent means local caching only. */
245
+ remoteCache?: PackageRemoteCacheConfig;
246
+ /** Provider-neutral local secret commands. CI supplies these variables externally. */
247
+ secrets?: Record<string, PackageSecretCommand>;
248
+ }
249
+
250
+ export interface PackageWorkspacesObject {
251
+ packages?: string[];
252
+ }
253
+
254
+ /**
255
+ * package.json shape used by smoo. Optional fields stay optional so partial
256
+ * manifests parse; mutation helpers create nested objects on demand.
257
+ */
258
+ export interface PackageJson {
259
+ name?: string;
260
+ version?: string;
261
+ private?: boolean;
262
+ license?: string;
263
+ types?: string;
264
+ typings?: string;
265
+ packageManager?: string;
266
+ files?: string[];
267
+ bin?: string | StringMap;
268
+ exports?: PackageExports;
269
+ workspaces?: string[] | PackageWorkspacesObject;
270
+ dependencies?: StringMap;
271
+ devDependencies?: StringMap;
272
+ peerDependencies?: StringMap;
273
+ optionalDependencies?: StringMap;
274
+ /** Bun patchedDependencies map (package@version → patch path). */
275
+ patchedDependencies?: StringMap;
276
+ engines?: StringMap;
277
+ scripts?: StringMap;
278
+ publishConfig?: PackagePublishConfig;
279
+ repository?: string | PackageRepository;
280
+ nx?: PackageNxConfig;
281
+ smoo?: PackageSmooConfig;
282
+ }
283
+
284
+ /** Recursive package exports map (conditions nest arbitrarily). */
285
+ export type PackageExports = string | PackageExportMap | null | undefined;
286
+ export interface PackageExportMap {
287
+ [condition: string]: PackageExports;
288
+ }
289
+
290
+ export interface NxDependsOnObject {
291
+ target: string;
292
+ projects?: string | string[];
293
+ }
294
+
295
+ export type NxDependsOn = string | NxDependsOnObject;
296
+
297
+ /** Nx target options are executor-specific open bags. */
298
+ export type NxTargetOptions = Record<string, unknown>;
299
+
300
+ export type NxInput = string | object;
301
+
302
+ export interface NxTargetConfig {
303
+ executor?: string;
304
+ dependsOn?: NxDependsOn[];
305
+ outputs?: string[];
306
+ inputs?: NxInput[];
307
+ options?: NxTargetOptions;
308
+ configurations?: Record<string, NxTargetConfig>;
309
+ cache?: boolean;
310
+ command?: string;
311
+ parallelism?: boolean;
312
+ }
313
+
314
+ export interface NxProjectJson {
315
+ name?: string;
316
+ root?: string;
317
+ tags?: string[];
318
+ targets?: Record<string, NxTargetConfig>;
319
+ }
320
+
321
+ export interface NxJson {
322
+ namedInputs?: Record<string, Array<string | Record<string, unknown>> | string>;
323
+ }
324
+
325
+ export function ciPushBranches(github: PackageSmooGithub | undefined): NonEmptyArray<string> {
326
+ return github?.pushBranches ?? ['main'];
327
+ }
@@ -0,0 +1,32 @@
1
+ import type { PackageJson } from './workspace-manifest.js';
2
+
3
+ export interface RepositoryInfo {
4
+ type: string;
5
+ url: string;
6
+ }
7
+ export const smoothBricksCodebasePackageName = '@smoothbricks/codebase';
8
+ export function isSmoothBricksCodebasePackageName(name: string | undefined): boolean {
9
+ return name === smoothBricksCodebasePackageName;
10
+ }
11
+
12
+ export function isPublishablePackage(pkg: { private: boolean; tags: string[] }): boolean {
13
+ if (pkg.private) {
14
+ return false;
15
+ }
16
+ return pkg.tags.includes('npm:public') !== pkg.tags.includes('npm:private');
17
+ }
18
+
19
+ export function repositoryInfo(pkg: PackageJson): RepositoryInfo | null {
20
+ const repository = pkg.repository;
21
+ if (typeof repository === 'string') {
22
+ return { type: 'git', url: repository };
23
+ }
24
+ if (!repository || typeof repository !== 'object') {
25
+ return null;
26
+ }
27
+ const url = repository.url;
28
+ if (!url) {
29
+ return null;
30
+ }
31
+ return { type: repository.type ?? 'git', url };
32
+ }