@smoothbricks/nx-plugin 0.1.0 → 0.2.1

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 (74) hide show
  1. package/README.md +35 -8
  2. package/dist/bounded-test-policy.d.ts +32 -0
  3. package/dist/bounded-test-policy.d.ts.map +1 -0
  4. package/dist/bounded-test-policy.js +184 -0
  5. package/dist/executors/bounded-exec/executor.d.ts +15 -0
  6. package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
  7. package/dist/executors/bounded-exec/executor.js +179 -0
  8. package/dist/executors/bounded-exec/schema.d.ts +11 -0
  9. package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
  10. package/dist/executors/bounded-exec/schema.js +1 -0
  11. package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
  12. package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
  13. package/dist/generators/bounded-test-targets/generator.js +40 -0
  14. package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -1
  15. package/dist/generators/bun-test-tracing/generator.js +5 -4
  16. package/dist/generators/create-package/generator.d.ts +4 -0
  17. package/dist/generators/create-package/generator.d.ts.map +1 -0
  18. package/dist/generators/create-package/generator.js +204 -0
  19. package/dist/generators/make-public/generator.d.ts +4 -0
  20. package/dist/generators/make-public/generator.d.ts.map +1 -0
  21. package/dist/generators/make-public/generator.js +55 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +78 -7
  24. package/dist/package-target-policy.d.ts +31 -0
  25. package/dist/package-target-policy.d.ts.map +1 -0
  26. package/dist/package-target-policy.js +937 -0
  27. package/dist/release-config-policy.d.ts +32 -0
  28. package/dist/release-config-policy.d.ts.map +1 -0
  29. package/dist/release-config-policy.js +225 -0
  30. package/dist/typecheck-test-policy.d.ts +56 -0
  31. package/dist/typecheck-test-policy.d.ts.map +1 -0
  32. package/dist/typecheck-test-policy.js +640 -0
  33. package/dist/version-actions.cjs +78 -0
  34. package/dist/version-actions.d.cts +6 -0
  35. package/dist/version-actions.d.cts.map +1 -0
  36. package/dist/workspace-config-policy.d.ts +33 -0
  37. package/dist/workspace-config-policy.d.ts.map +1 -0
  38. package/dist/workspace-config-policy.js +334 -0
  39. package/executors.json +9 -0
  40. package/generators.json +15 -0
  41. package/package.json +45 -11
  42. package/src/bounded-test-policy.test.ts +257 -0
  43. package/src/bounded-test-policy.ts +257 -0
  44. package/src/bun-bootstrap.test.ts +52 -0
  45. package/src/executors/bounded-exec/executor.test.ts +258 -0
  46. package/src/executors/bounded-exec/executor.ts +228 -0
  47. package/src/executors/bounded-exec/schema.json +68 -0
  48. package/src/executors/bounded-exec/schema.ts +10 -0
  49. package/src/generators/bounded-test-targets/generator.test.ts +136 -0
  50. package/src/generators/bounded-test-targets/generator.ts +67 -0
  51. package/src/generators/bounded-test-targets/schema.d.ts +3 -0
  52. package/src/generators/bounded-test-targets/schema.json +14 -0
  53. package/src/generators/bun-test-tracing/generator.test.ts +25 -1
  54. package/src/generators/bun-test-tracing/generator.ts +6 -5
  55. package/src/generators/create-package/generator.test.ts +206 -0
  56. package/src/generators/create-package/generator.ts +251 -0
  57. package/src/generators/create-package/schema.d.ts +5 -0
  58. package/src/generators/create-package/schema.json +24 -0
  59. package/src/generators/make-public/generator.test.ts +137 -0
  60. package/src/generators/make-public/generator.ts +83 -0
  61. package/src/generators/make-public/schema.d.ts +3 -0
  62. package/src/generators/make-public/schema.json +13 -0
  63. package/src/index.test.ts +85 -18
  64. package/src/index.ts +99 -8
  65. package/src/package-target-policy.test.ts +785 -0
  66. package/src/package-target-policy.ts +1140 -0
  67. package/src/release-config-policy.test.ts +280 -0
  68. package/src/release-config-policy.ts +258 -0
  69. package/src/typecheck-test-policy.test.ts +797 -0
  70. package/src/typecheck-test-policy.ts +752 -0
  71. package/src/version-actions.cts +94 -0
  72. package/src/workspace-config-policy.test.ts +376 -0
  73. package/src/workspace-config-policy.ts +390 -0
  74. package/src/test-suite-tracer.ts +0 -0
@@ -0,0 +1,32 @@
1
+ import type { Tree } from 'nx/src/devkit-exports.js';
2
+ import type { NxPolicyIssue } from './workspace-config-policy.js';
3
+ export declare const SMOO_NX_VERSION_ACTIONS = "@smoothbricks/nx-plugin/version-actions";
4
+ export declare const SMOO_NX_RELEASE_TAG_PATTERN = "{projectName}@{version}";
5
+ /**
6
+ * Check release config policy on an in-memory nx.json object.
7
+ */
8
+ export declare function checkReleaseConfig(nxJson: Record<string, unknown>): NxPolicyIssue[];
9
+ /**
10
+ * Apply release config policy to an in-memory nx.json object.
11
+ * Mutates in place, returns whether anything changed.
12
+ */
13
+ export declare function applyReleaseConfig(nxJson: Record<string, unknown>): boolean;
14
+ /**
15
+ * Check release config policy using an Nx Tree.
16
+ */
17
+ export declare function checkReleaseConfigTree(tree: Tree): NxPolicyIssue[];
18
+ /**
19
+ * Apply release config policy using an Nx Tree.
20
+ * Returns whether anything changed.
21
+ */
22
+ export declare function applyReleaseConfigTree(tree: Tree): boolean;
23
+ /**
24
+ * Check nx.json release config policy, returns issues found.
25
+ * Only checks release-specific config — workspace config policy is checked separately.
26
+ */
27
+ export declare function checkReleaseConfigPolicy(root: string): NxPolicyIssue[];
28
+ /**
29
+ * Fix nx.json release config policy. Returns whether anything changed.
30
+ */
31
+ export declare function applyReleaseConfigPolicy(root: string): boolean;
32
+ //# sourceMappingURL=release-config-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release-config-policy.d.ts","sourceRoot":"","sources":["../src/release-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,eAAO,MAAM,uBAAuB,4CAA4C,CAAC;AACjF,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CAoFnF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAsC3E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKlE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU1D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYtE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW9D"}
@@ -0,0 +1,225 @@
1
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { readJson, updateJson } from 'nx/src/devkit-exports.js';
4
+ export const SMOO_NX_VERSION_ACTIONS = '@smoothbricks/nx-plugin/version-actions';
5
+ export const SMOO_NX_RELEASE_TAG_PATTERN = '{projectName}@{version}';
6
+ /**
7
+ * Check release config policy on an in-memory nx.json object.
8
+ */
9
+ export function checkReleaseConfig(nxJson) {
10
+ const issues = [];
11
+ const release = recordProperty(nxJson, 'release');
12
+ if (!release) {
13
+ issues.push({ path: 'nx.json', message: 'release config is missing' });
14
+ return issues;
15
+ }
16
+ if (stringProperty(release, 'projectsRelationship') !== 'independent') {
17
+ issues.push({ path: 'nx.json', message: 'release.projectsRelationship must be independent' });
18
+ }
19
+ const version = recordProperty(release, 'version');
20
+ if (!version) {
21
+ issues.push({ path: 'nx.json', message: 'release.version config is missing' });
22
+ }
23
+ if (version && stringProperty(version, 'specifierSource') !== 'conventional-commits') {
24
+ issues.push({ path: 'nx.json', message: 'release.version.specifierSource must be conventional-commits' });
25
+ }
26
+ if (version && stringProperty(version, 'currentVersionResolver') !== 'git-tag') {
27
+ issues.push({ path: 'nx.json', message: 'release.version.currentVersionResolver must be git-tag' });
28
+ }
29
+ if (version && stringProperty(version, 'fallbackCurrentVersionResolver') !== 'disk') {
30
+ issues.push({ path: 'nx.json', message: 'release.version.fallbackCurrentVersionResolver must be disk' });
31
+ }
32
+ if (version && stringProperty(version, 'versionActions') !== SMOO_NX_VERSION_ACTIONS) {
33
+ issues.push({
34
+ path: 'nx.json',
35
+ message: `release.version.versionActions must be ${SMOO_NX_VERSION_ACTIONS}`,
36
+ });
37
+ }
38
+ if (version && stringProperty(version, 'preVersionCommand')) {
39
+ issues.push({
40
+ path: 'nx.json',
41
+ message: 'release.version.preVersionCommand must not be defined; smoo builds npm-missing packages before publish',
42
+ });
43
+ }
44
+ const releaseTag = recordProperty(release, 'releaseTag');
45
+ if (!releaseTag) {
46
+ issues.push({ path: 'nx.json', message: 'release.releaseTag config is missing' });
47
+ }
48
+ if (releaseTag && stringProperty(releaseTag, 'pattern') !== SMOO_NX_RELEASE_TAG_PATTERN) {
49
+ issues.push({
50
+ path: 'nx.json',
51
+ message: `release.releaseTag.pattern must be ${SMOO_NX_RELEASE_TAG_PATTERN}`,
52
+ });
53
+ }
54
+ const changelog = recordProperty(release, 'changelog');
55
+ if (!changelog) {
56
+ issues.push({ path: 'nx.json', message: 'release.changelog config is missing' });
57
+ }
58
+ if (changelog && changelog.workspaceChangelog !== false) {
59
+ issues.push({ path: 'nx.json', message: 'release.changelog.workspaceChangelog must be false' });
60
+ }
61
+ const projectChangelogs = changelog ? recordProperty(changelog, 'projectChangelogs') : null;
62
+ if (!projectChangelogs) {
63
+ issues.push({ path: 'nx.json', message: 'release.changelog.projectChangelogs config is missing' });
64
+ }
65
+ if (projectChangelogs && projectChangelogs.createRelease !== false) {
66
+ issues.push({
67
+ path: 'nx.json',
68
+ message: 'release.changelog.projectChangelogs.createRelease must be false',
69
+ });
70
+ }
71
+ if (projectChangelogs && projectChangelogs.file !== false) {
72
+ issues.push({
73
+ path: 'nx.json',
74
+ message: 'release.changelog.projectChangelogs.file must be false',
75
+ });
76
+ }
77
+ const renderOptions = projectChangelogs ? recordProperty(projectChangelogs, 'renderOptions') : null;
78
+ if (!renderOptions) {
79
+ issues.push({
80
+ path: 'nx.json',
81
+ message: 'release.changelog.projectChangelogs.renderOptions config is missing',
82
+ });
83
+ }
84
+ return issues;
85
+ }
86
+ /**
87
+ * Apply release config policy to an in-memory nx.json object.
88
+ * Mutates in place, returns whether anything changed.
89
+ */
90
+ export function applyReleaseConfig(nxJson) {
91
+ let changed = false;
92
+ const release = getOrCreateRecord(nxJson, 'release');
93
+ changed = setStringProperty(release, 'projectsRelationship', 'independent') || changed;
94
+ const version = getOrCreateRecord(release, 'version');
95
+ changed = setStringProperty(version, 'specifierSource', 'conventional-commits') || changed;
96
+ changed = setStringProperty(version, 'currentVersionResolver', 'git-tag') || changed;
97
+ changed = setStringProperty(version, 'fallbackCurrentVersionResolver', 'disk') || changed;
98
+ changed = setStringProperty(version, 'versionActions', SMOO_NX_VERSION_ACTIONS) || changed;
99
+ if ('preVersionCommand' in version) {
100
+ delete version.preVersionCommand;
101
+ changed = true;
102
+ }
103
+ const releaseTag = getOrCreateRecord(release, 'releaseTag');
104
+ changed = setStringProperty(releaseTag, 'pattern', SMOO_NX_RELEASE_TAG_PATTERN) || changed;
105
+ const changelog = getOrCreateRecord(release, 'changelog');
106
+ changed = setBooleanProperty(changelog, 'workspaceChangelog', false) || changed;
107
+ const projectChangelogs = getOrCreateRecord(changelog, 'projectChangelogs');
108
+ changed = setBooleanProperty(projectChangelogs, 'createRelease', false) || changed;
109
+ changed = setBooleanProperty(projectChangelogs, 'file', false) || changed;
110
+ const renderOptions = getOrCreateRecord(projectChangelogs, 'renderOptions');
111
+ if (typeof renderOptions.authors !== 'boolean') {
112
+ renderOptions.authors = true;
113
+ changed = true;
114
+ }
115
+ if (typeof renderOptions.applyUsernameToAuthors !== 'boolean') {
116
+ renderOptions.applyUsernameToAuthors = true;
117
+ changed = true;
118
+ }
119
+ return changed;
120
+ }
121
+ /**
122
+ * Check release config policy using an Nx Tree.
123
+ */
124
+ export function checkReleaseConfigTree(tree) {
125
+ if (!tree.exists('nx.json')) {
126
+ return [{ path: 'nx.json', message: 'nx.json not found' }];
127
+ }
128
+ return checkReleaseConfig(readJson(tree, 'nx.json'));
129
+ }
130
+ /**
131
+ * Apply release config policy using an Nx Tree.
132
+ * Returns whether anything changed.
133
+ */
134
+ export function applyReleaseConfigTree(tree) {
135
+ if (!tree.exists('nx.json')) {
136
+ return false;
137
+ }
138
+ let changed = false;
139
+ updateJson(tree, 'nx.json', (nxJson) => {
140
+ changed = applyReleaseConfig(nxJson);
141
+ return nxJson;
142
+ });
143
+ return changed;
144
+ }
145
+ /**
146
+ * Check nx.json release config policy, returns issues found.
147
+ * Only checks release-specific config — workspace config policy is checked separately.
148
+ */
149
+ export function checkReleaseConfigPolicy(root) {
150
+ const nxJsonPath = join(root, 'nx.json');
151
+ const nxJson = readJsonObject(nxJsonPath);
152
+ if (!nxJson) {
153
+ return [{ path: nxJsonPath, message: 'nx.json not found or invalid' }];
154
+ }
155
+ const coreIssues = checkReleaseConfig(nxJson);
156
+ // Remap 'nx.json' paths to absolute paths for filesystem callers
157
+ return coreIssues.map((issue) => ({
158
+ ...issue,
159
+ path: issue.path === 'nx.json' ? nxJsonPath : issue.path,
160
+ }));
161
+ }
162
+ /**
163
+ * Fix nx.json release config policy. Returns whether anything changed.
164
+ */
165
+ export function applyReleaseConfigPolicy(root) {
166
+ const nxJsonPath = join(root, 'nx.json');
167
+ const nxJson = readJsonObject(nxJsonPath);
168
+ if (!nxJson) {
169
+ return false;
170
+ }
171
+ const changed = applyReleaseConfig(nxJson);
172
+ if (changed) {
173
+ writeJsonObject(nxJsonPath, nxJson);
174
+ }
175
+ return changed;
176
+ }
177
+ function readJsonObject(path) {
178
+ if (!existsSync(path)) {
179
+ return null;
180
+ }
181
+ try {
182
+ const parsed = JSON.parse(readFileSync(path, 'utf8'));
183
+ return isRecord(parsed) ? parsed : null;
184
+ }
185
+ catch {
186
+ return null;
187
+ }
188
+ }
189
+ function writeJsonObject(path, value) {
190
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
191
+ }
192
+ function isRecord(value) {
193
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
194
+ }
195
+ function stringProperty(record, key) {
196
+ const value = record[key];
197
+ return typeof value === 'string' && value.length > 0 ? value : null;
198
+ }
199
+ function recordProperty(record, key) {
200
+ const value = record[key];
201
+ return isRecord(value) ? value : null;
202
+ }
203
+ function getOrCreateRecord(record, key) {
204
+ const value = record[key];
205
+ if (isRecord(value)) {
206
+ return value;
207
+ }
208
+ const next = {};
209
+ record[key] = next;
210
+ return next;
211
+ }
212
+ function setStringProperty(record, key, value) {
213
+ if (record[key] === value) {
214
+ return false;
215
+ }
216
+ record[key] = value;
217
+ return true;
218
+ }
219
+ function setBooleanProperty(record, key, value) {
220
+ if (record[key] === value) {
221
+ return false;
222
+ }
223
+ record[key] = value;
224
+ return true;
225
+ }
@@ -0,0 +1,56 @@
1
+ import type { Tree } from 'nx/src/devkit-exports.js';
2
+ import type { NxPolicyIssue } from './workspace-config-policy.js';
3
+ export type TestRunner = 'bun' | 'vitest';
4
+ /**
5
+ * Detect test runners from a package.json object and optional project targets
6
+ * (from project.json or nx config).
7
+ */
8
+ export declare function detectPackageTestRunners(pkg: Record<string, unknown>, projectTargets?: Record<string, unknown>): ReadonlySet<TestRunner>;
9
+ /**
10
+ * Validate tsconfig.test.json contents (in-memory object).
11
+ * Returns policy issues found.
12
+ */
13
+ export declare function checkTypecheckTestConfig(tsconfigTest: Record<string, unknown> | null, packagePath: string): NxPolicyIssue[];
14
+ /**
15
+ * Check if tsconfig.json has a bad reference to ./tsconfig.test.json.
16
+ */
17
+ export declare function checkTsconfigTestReference(projectTsconfig: Record<string, unknown> | null, packagePath: string): NxPolicyIssue[];
18
+ /**
19
+ * Apply defaults to a tsconfig.test.json object (in-memory mutation).
20
+ * Returns whether anything changed.
21
+ */
22
+ export declare function applyTypecheckTestDefaults(tsconfigTest: Record<string, unknown>, options: {
23
+ testRunners: ReadonlySet<TestRunner>;
24
+ tsconfigLibExtends?: string;
25
+ libCompilerOptions?: Record<string, unknown>;
26
+ referencePaths: string[];
27
+ }): boolean;
28
+ /**
29
+ * Remove the ./tsconfig.test.json reference from a tsconfig.json object.
30
+ * Returns whether anything changed.
31
+ */
32
+ export declare function removeTsconfigTestReference(projectTsconfig: Record<string, unknown>): boolean;
33
+ /**
34
+ * Check all workspace packages for typecheck test policy compliance using an Nx Tree.
35
+ */
36
+ export declare function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[];
37
+ /**
38
+ * Fix all workspace packages' tsconfig.test.json configuration using an Nx Tree.
39
+ * Returns whether any files changed.
40
+ */
41
+ export declare function applyTypecheckTestPolicyTree(tree: Tree): boolean;
42
+ /**
43
+ * Check all workspace packages for typecheck test policy compliance.
44
+ *
45
+ * For each package that uses bun test or vitest:
46
+ * - tsconfig.test.json must exist
47
+ * - tsconfig.test.json must be noEmit, not composite, no declaration, no dist-test output
48
+ * - tsconfig.json must NOT reference ./tsconfig.test.json
49
+ */
50
+ export declare function checkTypecheckTestPolicy(root: string): NxPolicyIssue[];
51
+ /**
52
+ * Fix all workspace packages' tsconfig.test.json configuration.
53
+ * Returns whether any files changed.
54
+ */
55
+ export declare function applyTypecheckTestPolicy(root: string): boolean;
56
+ //# sourceMappingURL=typecheck-test-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typecheck-test-policy.d.ts","sourceRoot":"","sources":["../src/typecheck-test-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AAI1C;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,WAAW,CAAC,UAAU,CAAC,CAqDzB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC5C,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAgDjB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC/C,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAYjB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,OAAO,EAAE;IACP,WAAW,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IACrC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7C,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B,GACA,OAAO,CAiDT;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAO7F;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAwCxE;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAyDhE;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CA2CtE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAyD9D"}