@smoothbricks/nx-plugin 0.4.15 → 0.4.17

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 (115) hide show
  1. package/README.md +17 -0
  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 +153 -14
  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/platform-targets.d.ts +5 -0
  47. package/dist/platform-targets.d.ts.map +1 -0
  48. package/dist/platform-targets.js +4 -0
  49. package/dist/typecheck-test-policy.d.ts +5 -9
  50. package/dist/typecheck-test-policy.d.ts.map +1 -1
  51. package/dist/typecheck-test-policy.js +69 -99
  52. package/dist/workspace-config-policy.d.ts +2 -3
  53. package/dist/workspace-config-policy.d.ts.map +1 -1
  54. package/dist/workspace-config-policy.js +8 -3
  55. package/dist/workspace-manifest.d.ts +291 -0
  56. package/dist/workspace-manifest.d.ts.map +1 -0
  57. package/dist/workspace-manifest.js +6 -0
  58. package/dist/workspace-package-policy.d.ts +13 -0
  59. package/dist/workspace-package-policy.d.ts.map +1 -0
  60. package/dist/workspace-package-policy.js +24 -0
  61. package/generators.json +5 -0
  62. package/managed/raw/envrc +20 -0
  63. package/managed/raw/git-format-staged.yml +82 -0
  64. package/managed/raw/gitattributes +8 -0
  65. package/managed/raw/tooling/devenv +83 -0
  66. package/managed/raw/tooling/direnv/devenv.smoo.nix +422 -0
  67. package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +251 -0
  68. package/managed/raw/tooling/direnv/merge-newer-pins.sh +48 -0
  69. package/managed/raw/tooling/direnv/repo-path +34 -0
  70. package/managed/raw/tooling/direnv/secret-references.ts +636 -0
  71. package/managed/raw/tooling/direnv/setup-environment.ts +585 -0
  72. package/managed/raw/tooling/direnv/toolchain-stamp.ts +88 -0
  73. package/managed/raw/tooling/git-hooks/commit-msg.sh +9 -0
  74. package/managed/raw/tooling/git-hooks/post-commit.sh +71 -0
  75. package/managed/raw/tooling/git-hooks/pre-commit.sh +18 -0
  76. package/managed/raw/tooling/git-hooks/pre-push.sh +48 -0
  77. package/managed/raw/tsconfig.lib.json +28 -0
  78. package/managed/templates/github/actions/cache-nix-devenv/action.yml +45 -0
  79. package/managed/templates/github/actions/cache-node-modules/action.yml +17 -0
  80. package/managed/templates/github/actions/cache-nx/action.yml +21 -0
  81. package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +19 -0
  82. package/managed/templates/github/actions/save-nix-devenv/action.yml +32 -0
  83. package/managed/templates/github/actions/setup-devenv/action.yml +245 -0
  84. package/managed/templates/github/workflows/managed-files.yml +127 -0
  85. package/package.json +89 -5
  86. package/src/bun-bootstrap.test.ts +0 -6
  87. package/src/deploy-policy.ts +40 -0
  88. package/src/index.test.ts +225 -2
  89. package/src/index.ts +180 -14
  90. package/src/managed-assets.ts +4 -0
  91. package/src/managed-files/ci-workflow.ts +1365 -0
  92. package/src/managed-files/context.ts +240 -0
  93. package/src/managed-files/files.ts +324 -0
  94. package/src/managed-files/generator.test.ts +151 -0
  95. package/src/managed-files/generator.ts +60 -0
  96. package/src/managed-files/github-host-cache-isolation.test.ts +60 -0
  97. package/src/managed-files/github-runs-on.ts +51 -0
  98. package/src/managed-files/managed-content.test.ts +147 -0
  99. package/src/managed-files/managed-content.ts +121 -0
  100. package/src/managed-files/managed-format.ts +102 -0
  101. package/src/managed-files/paths.ts +44 -0
  102. package/src/managed-files/pr-preview-cleanup-workflow.ts +44 -0
  103. package/src/managed-files/private-npm-policy.ts +62 -0
  104. package/src/managed-files/publish-workflow.ts +1523 -0
  105. package/src/managed-files/schema.json +8 -0
  106. package/src/managed-files/tree-permissions.test.ts +109 -0
  107. package/src/managed-files/tree.test.ts +123 -0
  108. package/src/managed-files/tree.ts +118 -0
  109. package/src/platform-targets.ts +4 -0
  110. package/src/typecheck-test-policy.test.ts +28 -3
  111. package/src/typecheck-test-policy.ts +46 -121
  112. package/src/workspace-config-policy.test.ts +14 -2
  113. package/src/workspace-config-policy.ts +9 -3
  114. package/src/workspace-manifest.ts +327 -0
  115. package/src/workspace-package-policy.ts +32 -0
@@ -0,0 +1,102 @@
1
+ import { join } from 'node:path';
2
+ import type * as PrettierModule from 'prettier';
3
+ import type { Options as PrettierOptions } from 'prettier';
4
+
5
+ /**
6
+ * Extensions the managed `.git-format-staged.yml` routes to Biome rather than
7
+ * Prettier. Prettier has a parser for every one of them, so they have to be
8
+ * named: running Prettier over them here would fight the commit hook instead
9
+ * of agreeing with it, which is the failure this module exists to remove.
10
+ *
11
+ * Everything Prettier cannot parse — `.nix` (Alejandra), `.rs` (rustfmt),
12
+ * `.sh`, `.envrc`, `.gitattributes` — needs no entry: Prettier infers no
13
+ * parser and the content passes through untouched, exactly as
14
+ * `prettier --ignore-unknown` leaves it in the hook.
15
+ *
16
+ * `managed-format.test.ts` pins this list to that config.
17
+ */
18
+ export const BIOME_OWNED_EXTENSIONS: readonly string[] = [
19
+ '.js',
20
+ '.cjs',
21
+ '.mjs',
22
+ '.ts',
23
+ '.cts',
24
+ '.mts',
25
+ '.jsx',
26
+ '.tsx',
27
+ '.json',
28
+ '.jsonc',
29
+ '.html',
30
+ '.css',
31
+ '.graphql',
32
+ ];
33
+
34
+ /**
35
+ * The ignore files Prettier's CLI consults by default, and the CLI is what
36
+ * `.git-format-staged.yml` invokes. A repository that tells Prettier to leave
37
+ * a path alone means the hook leaves it alone, so this writer must too.
38
+ */
39
+ const IGNORE_FILES = ['.gitignore', '.prettierignore'] as const;
40
+
41
+ /**
42
+ * Loaded on first use, not at import: most `smoo` commands never write a
43
+ * managed file, and Prettier is not a cheap module to pull into every one.
44
+ */
45
+ let prettierModule: Promise<typeof PrettierModule> | undefined;
46
+
47
+ function loadPrettier(): Promise<typeof PrettierModule> {
48
+ prettierModule ??= import('prettier');
49
+ return prettierModule;
50
+ }
51
+
52
+ /**
53
+ * The bytes a managed target has *after* the consuming repository's commit
54
+ * hook has had its say.
55
+ *
56
+ * `smoo monorepo update` writes into a repository whose hook
57
+ * (`.git-format-staged.yml`) reformats whatever it stages. Writing the
58
+ * generator's own idea of formatting there means the hook rewrites the file on
59
+ * the next commit, the next `update` writes the generator's version back, and
60
+ * the drift check reports a difference forever — on a tree where nothing
61
+ * meaningful changed. A warning that is always on is a warning nobody reads,
62
+ * and it hides the real drift underneath it.
63
+ *
64
+ * So the writer renders into the consumer's own formatting space, using the
65
+ * config Prettier resolves for *this* path in *this* repository: overrides,
66
+ * `.editorconfig` and ignore files included. The written bytes are then a
67
+ * fixed point of the hook, `update` is idempotent, and `check` reports only
68
+ * differences that are real.
69
+ *
70
+ * A consumer's formatter config is the consumer's business. This reads it and
71
+ * obeys; it never asks the repository to change it.
72
+ */
73
+ export async function formatManagedContent(root: string, target: string, content: string): Promise<string> {
74
+ if (BIOME_OWNED_EXTENSIONS.some((extension) => target.endsWith(extension))) {
75
+ return content;
76
+ }
77
+ const prettier = await loadPrettier();
78
+ const path = join(root, target);
79
+ const ignorePath = IGNORE_FILES.map((file) => join(root, file));
80
+ // `resolveConfig` so a repository that assigns a parser through an override
81
+ // gets the parser its own Prettier run would infer.
82
+ const info = await prettier.getFileInfo(path, { ignorePath, resolveConfig: true });
83
+ if (info.ignored || info.inferredParser === null) {
84
+ return content;
85
+ }
86
+ // Prettier resolves configuration from disk, not pending Nx Tree edits. If
87
+ // another generator stages formatter config, the next run after flush converges.
88
+ let options: PrettierOptions | null;
89
+ try {
90
+ options = await prettier.resolveConfig(path, { editorconfig: true });
91
+ } catch (error) {
92
+ throw new Error(
93
+ `${target}: the repository's Prettier configuration could not be read, so managed content cannot be written in the bytes its commit hook would leave behind`,
94
+ { cause: error },
95
+ );
96
+ }
97
+ try {
98
+ return await prettier.format(content, { ...options, filepath: path });
99
+ } catch (error) {
100
+ throw new Error(`${target}: generated managed content is not valid ${info.inferredParser}`, { cause: error });
101
+ }
102
+ }
@@ -0,0 +1,44 @@
1
+ import { lstatSync, realpathSync, statSync } from 'node:fs';
2
+ import { isAbsolute, relative, resolve, sep } from 'node:path';
3
+ import { isManagedTarget, type ManagedPathInfo } from './tree.js';
4
+
5
+ /**
6
+ * Small filesystem boundary for permissions and links, which Nx Tree cannot
7
+ * read. Never reads content and never writes. In-memory generator tests supply
8
+ * these facts directly; real-filesystem tests exercise this boundary separately.
9
+ */
10
+ export function inspectManagedPaths(root: string, targets: readonly string[]): Map<string, ManagedPathInfo> {
11
+ const canonicalRoot = realpathSync(root);
12
+ return new Map(targets.map((target) => [target, inspectPath(canonicalRoot, target)]));
13
+ }
14
+
15
+ function inspectPath(root: string, target: string): ManagedPathInfo {
16
+ if (!isManagedTarget(target)) return { error: 'invalid managed path' };
17
+ const parts = target.split('/');
18
+ for (let i = 1; i < parts.length; i++) {
19
+ const parent = lstatSync(resolve(root, ...parts.slice(0, i)), { throwIfNoEntry: false });
20
+ if (parent === undefined) return {};
21
+ if (!parent.isDirectory())
22
+ return { error: 'parent path is not a regular directory (symlink parents are not managed)' };
23
+ }
24
+ const path = resolve(root, target);
25
+ const info = lstatSync(path, { throwIfNoEntry: false });
26
+ if (info === undefined) return {};
27
+ if (!info.isSymbolicLink()) {
28
+ return info.isFile() ? { executable: (info.mode & 0o100) !== 0 } : { error: 'target is not a regular file' };
29
+ }
30
+ let destination: string;
31
+ try {
32
+ destination = realpathSync(path);
33
+ } catch {
34
+ return { error: 'symlink is broken, cyclic or inaccessible; refusing to follow it' };
35
+ }
36
+ const fromRoot = relative(root, destination);
37
+ if (isAbsolute(fromRoot) || fromRoot === '..' || fromRoot.startsWith(`..${sep}`)) {
38
+ return { error: 'symlink resolves outside the workspace' };
39
+ }
40
+ const linked = statSync(destination);
41
+ return linked.isFile()
42
+ ? { symlink: true, executable: (linked.mode & 0o100) !== 0 }
43
+ : { error: 'symlink does not resolve to a regular file' };
44
+ }
@@ -0,0 +1,44 @@
1
+ /* biome-ignore-all lint/suspicious/noTemplateCurlyInString: GitHub Actions expressions are emitted literally. */
2
+
3
+ import { renderRunsOnLine } from './github-runs-on.js';
4
+
5
+ export interface PrPreviewCleanupWorkflowOptions {
6
+ runsOn?: string | string[];
7
+ }
8
+
9
+ export function renderPrPreviewCleanupWorkflowYaml(options: PrPreviewCleanupWorkflowOptions = {}): string {
10
+ return `name: PR Preview Cleanup
11
+
12
+ on:
13
+ pull_request:
14
+ types: [closed]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ cleanup:
21
+ name: Cleanup PR environment
22
+ if: github.event.pull_request.head.repo.full_name == github.repository
23
+ ${renderRunsOnLine(options.runsOn)}
24
+ timeout-minutes: 15
25
+ defaults:
26
+ run:
27
+ working-directory: tooling/direnv
28
+ steps:
29
+ - name: Checkout
30
+ uses: actions/checkout@v6.0.2
31
+ with:
32
+ filter: blob:none
33
+ fetch-depth: 1
34
+
35
+ - name: Setup Nix/devenv
36
+ uses: ./.github/actions/setup-devenv
37
+
38
+ - name: Cleanup PR environment
39
+ env:
40
+ CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
41
+ CLOUDFLARE_ACCOUNT_ID: \${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
42
+ run: smoo wrangler cleanup-pr --pr \${{ github.event.pull_request.number }}
43
+ `;
44
+ }
@@ -0,0 +1,62 @@
1
+ import type { PackageJson, PackagePrivateNpmConfig } from '../workspace-manifest.js';
2
+ import { isPublishablePackage } from '../workspace-package-policy.js';
3
+
4
+ /** Committed npmrc values only; workflow generation must not depend on a user's home. */
5
+ export function npmrcValueFromText(text: string, key: string): string | undefined {
6
+ for (const line of text.split(/\r?\n/)) {
7
+ const trimmed = line.trim();
8
+ if (trimmed.startsWith('#') || trimmed.startsWith(';')) continue;
9
+ const separator = trimmed.indexOf('=');
10
+ if (separator > 0 && trimmed.slice(0, separator).trim() === key) return trimmed.slice(separator + 1).trim();
11
+ }
12
+ return undefined;
13
+ }
14
+
15
+ export function npmrcTokenEnvFromText(text: string, scope: string): string | undefined {
16
+ const registry = npmrcValueFromText(text, `${scope}:registry`);
17
+ if (!registry) return undefined;
18
+ let url: URL;
19
+ try {
20
+ url = new URL(registry);
21
+ } catch {
22
+ return undefined;
23
+ }
24
+ const pathname = url.pathname.endsWith('/') ? url.pathname : `${url.pathname}/`;
25
+ return /^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(
26
+ npmrcValueFromText(text, `//${url.host}${pathname}:_authToken`) ?? '',
27
+ )?.[1];
28
+ }
29
+
30
+ /** Resolve workflow credential NAMES without obtaining, interpolating, or persisting any secret. */
31
+ export function privateNpmWorkflowConfig(
32
+ declared: PackagePrivateNpmConfig | undefined,
33
+ root: PackageJson,
34
+ packages: readonly PackageJson[],
35
+ npmrc: string,
36
+ ): PackagePrivateNpmConfig | undefined {
37
+ if (!declared) return undefined;
38
+ const inScope = (name: string) => name === declared.scope || name.startsWith(`${declared.scope}/`);
39
+ const consumes = [root, ...packages].some((pkg) =>
40
+ [pkg.dependencies, pkg.devDependencies, pkg.peerDependencies, pkg.optionalDependencies].some((deps) =>
41
+ Object.entries(deps ?? {}).some(([name, spec]) => inScope(name) && !/^(workspace|link|file):/.test(spec)),
42
+ ),
43
+ );
44
+ const publishes = packages.some(
45
+ (pkg) =>
46
+ pkg.name &&
47
+ pkg.version &&
48
+ inScope(pkg.name) &&
49
+ isPublishablePackage({ private: pkg.private === true, tags: pkg.nx?.tags ?? [] }) &&
50
+ pkg.nx?.tags?.includes('npm:private'),
51
+ );
52
+ if (!consumes && !publishes) return undefined;
53
+ const npmrcEnv = npmrcTokenEnvFromText(npmrc, declared.scope);
54
+ const readTokenEnv = declared.readTokenEnv ?? (consumes ? npmrcEnv : undefined);
55
+ const publishTokenEnv = publishes ? (declared.publishTokenEnv ?? npmrcEnv) : undefined;
56
+ if (!readTokenEnv && !publishTokenEnv) return undefined;
57
+ return {
58
+ scope: declared.scope,
59
+ ...(readTokenEnv ? { readTokenEnv } : {}),
60
+ ...(publishTokenEnv ? { publishTokenEnv } : {}),
61
+ };
62
+ }