@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.
- package/README.md +35 -8
- package/dist/bounded-test-policy.d.ts +32 -0
- package/dist/bounded-test-policy.d.ts.map +1 -0
- package/dist/bounded-test-policy.js +184 -0
- package/dist/executors/bounded-exec/executor.d.ts +15 -0
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
- package/dist/executors/bounded-exec/executor.js +179 -0
- package/dist/executors/bounded-exec/schema.d.ts +11 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
- package/dist/executors/bounded-exec/schema.js +1 -0
- package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
- package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
- package/dist/generators/bounded-test-targets/generator.js +40 -0
- package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -1
- package/dist/generators/bun-test-tracing/generator.js +5 -4
- package/dist/generators/create-package/generator.d.ts +4 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -0
- package/dist/generators/create-package/generator.js +204 -0
- package/dist/generators/make-public/generator.d.ts +4 -0
- package/dist/generators/make-public/generator.d.ts.map +1 -0
- package/dist/generators/make-public/generator.js +55 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -7
- package/dist/package-target-policy.d.ts +31 -0
- package/dist/package-target-policy.d.ts.map +1 -0
- package/dist/package-target-policy.js +937 -0
- package/dist/release-config-policy.d.ts +32 -0
- package/dist/release-config-policy.d.ts.map +1 -0
- package/dist/release-config-policy.js +225 -0
- package/dist/typecheck-test-policy.d.ts +56 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -0
- package/dist/typecheck-test-policy.js +640 -0
- package/dist/version-actions.cjs +78 -0
- package/dist/version-actions.d.cts +6 -0
- package/dist/version-actions.d.cts.map +1 -0
- package/dist/workspace-config-policy.d.ts +33 -0
- package/dist/workspace-config-policy.d.ts.map +1 -0
- package/dist/workspace-config-policy.js +334 -0
- package/executors.json +9 -0
- package/generators.json +15 -0
- package/package.json +45 -11
- package/src/bounded-test-policy.test.ts +257 -0
- package/src/bounded-test-policy.ts +257 -0
- package/src/bun-bootstrap.test.ts +52 -0
- package/src/executors/bounded-exec/executor.test.ts +258 -0
- package/src/executors/bounded-exec/executor.ts +228 -0
- package/src/executors/bounded-exec/schema.json +68 -0
- package/src/executors/bounded-exec/schema.ts +10 -0
- package/src/generators/bounded-test-targets/generator.test.ts +136 -0
- package/src/generators/bounded-test-targets/generator.ts +67 -0
- package/src/generators/bounded-test-targets/schema.d.ts +3 -0
- package/src/generators/bounded-test-targets/schema.json +14 -0
- package/src/generators/bun-test-tracing/generator.test.ts +25 -1
- package/src/generators/bun-test-tracing/generator.ts +6 -5
- package/src/generators/create-package/generator.test.ts +206 -0
- package/src/generators/create-package/generator.ts +251 -0
- package/src/generators/create-package/schema.d.ts +5 -0
- package/src/generators/create-package/schema.json +24 -0
- package/src/generators/make-public/generator.test.ts +137 -0
- package/src/generators/make-public/generator.ts +83 -0
- package/src/generators/make-public/schema.d.ts +3 -0
- package/src/generators/make-public/schema.json +13 -0
- package/src/index.test.ts +85 -18
- package/src/index.ts +99 -8
- package/src/package-target-policy.test.ts +785 -0
- package/src/package-target-policy.ts +1140 -0
- package/src/release-config-policy.test.ts +280 -0
- package/src/release-config-policy.ts +258 -0
- package/src/typecheck-test-policy.test.ts +797 -0
- package/src/typecheck-test-policy.ts +752 -0
- package/src/version-actions.cts +94 -0
- package/src/workspace-config-policy.test.ts +376 -0
- package/src/workspace-config-policy.ts +390 -0
- package/src/test-suite-tracer.ts +0 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
4
|
+
import { readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
5
|
+
|
|
6
|
+
export interface NxPolicyIssue {
|
|
7
|
+
path: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
12
|
+
'*-js',
|
|
13
|
+
'*-web',
|
|
14
|
+
'*-html',
|
|
15
|
+
'*-css',
|
|
16
|
+
'*-ios',
|
|
17
|
+
'*-android',
|
|
18
|
+
'*-native',
|
|
19
|
+
'*-napi',
|
|
20
|
+
'*-bun',
|
|
21
|
+
'*-wasm',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const nxJsTypescriptPlugin = '@nx/js/typescript';
|
|
25
|
+
const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
|
|
26
|
+
const expectedSharedGlobalsNamedInput = ['{workspaceRoot}/.github/workflows/ci.yml'];
|
|
27
|
+
const defaultProductionNamedInput = [
|
|
28
|
+
'{projectRoot}/src/**/*',
|
|
29
|
+
'{projectRoot}/package.json',
|
|
30
|
+
'!{projectRoot}/**/__tests__/**',
|
|
31
|
+
'!{projectRoot}/**/*.test.*',
|
|
32
|
+
'!{projectRoot}/**/*.spec.*',
|
|
33
|
+
];
|
|
34
|
+
const impreciseProductionInputs = new Set(['default', '{projectRoot}/**/*', '{projectRoot}/**']);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check workspace config policy on an in-memory nx.json object.
|
|
38
|
+
*/
|
|
39
|
+
export function checkWorkspaceConfig(nxJson: Record<string, unknown>): NxPolicyIssue[] {
|
|
40
|
+
const issues: NxPolicyIssue[] = [];
|
|
41
|
+
|
|
42
|
+
// Colon target defaults
|
|
43
|
+
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
44
|
+
if (targetDefaults) {
|
|
45
|
+
for (const targetName of Object.keys(targetDefaults)) {
|
|
46
|
+
if (targetName.includes(':')) {
|
|
47
|
+
issues.push({
|
|
48
|
+
path: 'nx.json',
|
|
49
|
+
message:
|
|
50
|
+
`targetDefaults.${targetName} must not use colon target names. ` +
|
|
51
|
+
'Nx CLI syntax already uses project:target:configuration, so smoo Nx target names must be unambiguous tool-output names.',
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Build target default
|
|
58
|
+
validateBuildTargetDefault(nxJson, 'nx.json', issues);
|
|
59
|
+
|
|
60
|
+
// Named input defaults
|
|
61
|
+
validateNamedInputDefaults(nxJson, 'nx.json', issues);
|
|
62
|
+
|
|
63
|
+
// Plugin configuration
|
|
64
|
+
const plugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
65
|
+
const nxJsPlugin = plugins.find(isNxJsTypescriptPlugin);
|
|
66
|
+
if (!nxJsPlugin) {
|
|
67
|
+
issues.push({
|
|
68
|
+
path: 'nx.json',
|
|
69
|
+
message:
|
|
70
|
+
`plugins must configure ${nxJsTypescriptPlugin}. ` +
|
|
71
|
+
'Official Nx owns TypeScript library inference; smoo configures it so tsconfig.lib.json produces tsc-js and leaves build available as an aggregate target.',
|
|
72
|
+
});
|
|
73
|
+
} else if (nxJsBuildTargetName(nxJsPlugin) !== 'tsc-js') {
|
|
74
|
+
issues.push({
|
|
75
|
+
path: 'nx.json',
|
|
76
|
+
message:
|
|
77
|
+
`${nxJsTypescriptPlugin} build.targetName must be tsc-js. ` +
|
|
78
|
+
'TypeScript library output is a concrete tool-output target; build is reserved for aggregate targets that depend on concrete build work.',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (!plugins.includes(smoothBricksNxPlugin) && !plugins.some(isSmoothBricksNxPluginRecord)) {
|
|
82
|
+
issues.push({
|
|
83
|
+
path: 'nx.json',
|
|
84
|
+
message:
|
|
85
|
+
`plugins must include ${smoothBricksNxPlugin}. ` +
|
|
86
|
+
'Smoo relies on this plugin to infer convention targets that official Nx does not provide, including typecheck-tests, non-TypeScript build-tool targets, and aggregate build/lint targets.',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return issues;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Apply workspace config policy to an in-memory nx.json object.
|
|
95
|
+
* Mutates in place, returns whether anything changed.
|
|
96
|
+
*/
|
|
97
|
+
export function applyWorkspaceConfig(nxJson: Record<string, unknown>): boolean {
|
|
98
|
+
let changed = removeColonTargetDefaults(nxJson);
|
|
99
|
+
changed = applyBuildTargetDefault(nxJson) || changed;
|
|
100
|
+
changed = applyNamedInputDefaults(nxJson) || changed;
|
|
101
|
+
const currentPlugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
102
|
+
const nextPlugins = upsertNxPlugin(
|
|
103
|
+
upsertNxPlugin(currentPlugins, expectedNxJsTypescriptPlugin()),
|
|
104
|
+
smoothBricksNxPlugin,
|
|
105
|
+
);
|
|
106
|
+
if (JSON.stringify(currentPlugins) !== JSON.stringify(nextPlugins)) {
|
|
107
|
+
nxJson.plugins = nextPlugins;
|
|
108
|
+
changed = true;
|
|
109
|
+
}
|
|
110
|
+
return changed;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Check workspace config policy using an Nx Tree.
|
|
115
|
+
*/
|
|
116
|
+
export function checkWorkspaceConfigTree(tree: Tree): NxPolicyIssue[] {
|
|
117
|
+
if (!tree.exists('nx.json')) {
|
|
118
|
+
return [{ path: 'nx.json', message: 'nx.json not found' }];
|
|
119
|
+
}
|
|
120
|
+
return checkWorkspaceConfig(readJson(tree, 'nx.json'));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Apply workspace config policy using an Nx Tree.
|
|
125
|
+
* Returns whether anything changed.
|
|
126
|
+
*/
|
|
127
|
+
export function applyWorkspaceConfigTree(tree: Tree): boolean {
|
|
128
|
+
if (!tree.exists('nx.json')) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
let changed = false;
|
|
132
|
+
updateJson(tree, 'nx.json', (nxJson: Record<string, unknown>) => {
|
|
133
|
+
changed = applyWorkspaceConfig(nxJson);
|
|
134
|
+
return nxJson;
|
|
135
|
+
});
|
|
136
|
+
return changed;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Check nx.json workspace config policy, returns issues found.
|
|
141
|
+
*/
|
|
142
|
+
export function checkWorkspaceConfigPolicy(root: string): NxPolicyIssue[] {
|
|
143
|
+
const nxJsonPath = join(root, 'nx.json');
|
|
144
|
+
const nxJson = readJsonObject(nxJsonPath);
|
|
145
|
+
if (!nxJson) {
|
|
146
|
+
return [{ path: nxJsonPath, message: 'nx.json not found or invalid' }];
|
|
147
|
+
}
|
|
148
|
+
const coreIssues = checkWorkspaceConfig(nxJson);
|
|
149
|
+
// Remap 'nx.json' paths to absolute paths for filesystem callers
|
|
150
|
+
return coreIssues.map((issue) => ({
|
|
151
|
+
...issue,
|
|
152
|
+
path: issue.path === 'nx.json' ? nxJsonPath : issue.path,
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Fix nx.json workspace config policy. Returns whether anything changed.
|
|
158
|
+
*/
|
|
159
|
+
export function applyWorkspaceConfigPolicy(root: string): boolean {
|
|
160
|
+
const nxJsonPath = join(root, 'nx.json');
|
|
161
|
+
const nxJson = readJsonObject(nxJsonPath);
|
|
162
|
+
if (!nxJson) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const changed = applyWorkspaceConfig(nxJson);
|
|
166
|
+
if (changed) {
|
|
167
|
+
writeJsonObject(nxJsonPath, nxJson);
|
|
168
|
+
}
|
|
169
|
+
return changed;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function validateBuildTargetDefault(
|
|
173
|
+
nxJson: Record<string, unknown>,
|
|
174
|
+
nxJsonPath: string,
|
|
175
|
+
issues: NxPolicyIssue[],
|
|
176
|
+
): void {
|
|
177
|
+
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
178
|
+
const build = targetDefaults ? recordProperty(targetDefaults, 'build') : null;
|
|
179
|
+
if (!build || build.cache !== true) {
|
|
180
|
+
issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
|
|
181
|
+
}
|
|
182
|
+
const outputs = build?.outputs;
|
|
183
|
+
if (!Array.isArray(outputs) || outputs.length !== 1 || outputs[0] !== '{projectRoot}/dist') {
|
|
184
|
+
issues.push({ path: nxJsonPath, message: 'targetDefaults.build.outputs must be ["{projectRoot}/dist"]' });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function validateNamedInputDefaults(
|
|
189
|
+
nxJson: Record<string, unknown>,
|
|
190
|
+
nxJsonPath: string,
|
|
191
|
+
issues: NxPolicyIssue[],
|
|
192
|
+
): void {
|
|
193
|
+
const namedInputs = recordProperty(nxJson, 'namedInputs');
|
|
194
|
+
if (!namedInputs) {
|
|
195
|
+
issues.push({
|
|
196
|
+
path: nxJsonPath,
|
|
197
|
+
message: 'namedInputs must be configured so production builds have precise cache inputs.',
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (!Array.isArray(namedInputs.default)) {
|
|
202
|
+
issues.push({
|
|
203
|
+
path: nxJsonPath,
|
|
204
|
+
message: 'namedInputs.default must be an array; smoo allows it to remain broad for non-production tasks.',
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (!stringArrayEquals(namedInputs.sharedGlobals, expectedSharedGlobalsNamedInput)) {
|
|
208
|
+
issues.push({
|
|
209
|
+
path: nxJsonPath,
|
|
210
|
+
message: 'namedInputs.sharedGlobals must include only {workspaceRoot}/.github/workflows/ci.yml',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const production = namedInputs.production;
|
|
214
|
+
if (!Array.isArray(production)) {
|
|
215
|
+
issues.push({
|
|
216
|
+
path: nxJsonPath,
|
|
217
|
+
message: 'namedInputs.production must be an array of precise production inputs.',
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (!isPreciseProductionNamedInput(production)) {
|
|
222
|
+
issues.push({
|
|
223
|
+
path: nxJsonPath,
|
|
224
|
+
message:
|
|
225
|
+
'namedInputs.production must enumerate precise production inputs. Do not include default or broad {projectRoot}/** globs; use language/tool-specific paths such as {projectRoot}/src/**/*, {projectRoot}/Cargo.toml, or {projectRoot}/pyproject.toml.',
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function applyBuildTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
231
|
+
const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
|
|
232
|
+
const build = getOrCreateRecord(targetDefaults, 'build');
|
|
233
|
+
let changed = setBooleanProperty(build, 'cache', true);
|
|
234
|
+
changed = setStringArrayProperty(build, 'outputs', ['{projectRoot}/dist']) || changed;
|
|
235
|
+
return changed;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function applyNamedInputDefaults(nxJson: Record<string, unknown>): boolean {
|
|
239
|
+
const namedInputs = getOrCreateRecord(nxJson, 'namedInputs');
|
|
240
|
+
let changed = false;
|
|
241
|
+
if (!Array.isArray(namedInputs.default)) {
|
|
242
|
+
namedInputs.default = ['{projectRoot}/**/*', 'sharedGlobals'];
|
|
243
|
+
changed = true;
|
|
244
|
+
}
|
|
245
|
+
changed = setStringArrayProperty(namedInputs, 'sharedGlobals', expectedSharedGlobalsNamedInput) || changed;
|
|
246
|
+
const production = namedInputs.production;
|
|
247
|
+
if (!Array.isArray(production) || !isPreciseProductionNamedInput(production)) {
|
|
248
|
+
namedInputs.production = defaultProductionNamedInput;
|
|
249
|
+
changed = true;
|
|
250
|
+
}
|
|
251
|
+
return changed;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function removeColonTargetDefaults(nxJson: Record<string, unknown>): boolean {
|
|
255
|
+
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
256
|
+
if (!targetDefaults) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
let changed = false;
|
|
260
|
+
for (const targetName of Object.keys(targetDefaults)) {
|
|
261
|
+
if (targetName.includes(':')) {
|
|
262
|
+
delete targetDefaults[targetName];
|
|
263
|
+
changed = true;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return changed;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function isPreciseProductionNamedInput(production: unknown[]): boolean {
|
|
270
|
+
let hasPositiveProjectInput = false;
|
|
271
|
+
for (const input of production) {
|
|
272
|
+
if (typeof input !== 'string') {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
const normalized = input.startsWith('!') ? input.slice(1) : input;
|
|
276
|
+
if (impreciseProductionInputs.has(input) || impreciseProductionInputs.has(normalized)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
if (!input.startsWith('!') && normalized.startsWith('{projectRoot}/')) {
|
|
280
|
+
hasPositiveProjectInput = true;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return hasPositiveProjectInput;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function expectedNxJsTypescriptPlugin(): Record<string, unknown> {
|
|
287
|
+
return {
|
|
288
|
+
plugin: nxJsTypescriptPlugin,
|
|
289
|
+
options: {
|
|
290
|
+
typecheck: { targetName: 'typecheck' },
|
|
291
|
+
build: {
|
|
292
|
+
targetName: 'tsc-js',
|
|
293
|
+
configName: 'tsconfig.lib.json',
|
|
294
|
+
buildDepsName: 'build-deps',
|
|
295
|
+
watchDepsName: 'watch-deps',
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function upsertNxPlugin(plugins: readonly unknown[], plugin: string | Record<string, unknown>): unknown[] {
|
|
302
|
+
const pluginName = typeof plugin === 'string' ? plugin : stringProperty(plugin, 'plugin');
|
|
303
|
+
const next = plugins.filter((entry) => nxPluginName(entry) !== pluginName);
|
|
304
|
+
next.push(plugin);
|
|
305
|
+
return next;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function nxPluginName(value: unknown): string | null {
|
|
309
|
+
if (typeof value === 'string') {
|
|
310
|
+
return value;
|
|
311
|
+
}
|
|
312
|
+
return isRecord(value) ? stringProperty(value, 'plugin') : null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function isNxJsTypescriptPlugin(value: unknown): value is Record<string, unknown> {
|
|
316
|
+
return isRecord(value) && stringProperty(value, 'plugin') === nxJsTypescriptPlugin;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function isSmoothBricksNxPluginRecord(value: unknown): boolean {
|
|
320
|
+
return isRecord(value) && stringProperty(value, 'plugin') === smoothBricksNxPlugin;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function nxJsBuildTargetName(plugin: Record<string, unknown>): string | null {
|
|
324
|
+
const options = recordProperty(plugin, 'options');
|
|
325
|
+
const build = options ? recordProperty(options, 'build') : null;
|
|
326
|
+
return build ? stringProperty(build, 'targetName') : null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function readJsonObject(path: string): Record<string, unknown> | null {
|
|
330
|
+
if (!existsSync(path)) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'));
|
|
335
|
+
return isRecord(parsed) ? parsed : null;
|
|
336
|
+
} catch {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function writeJsonObject(path: string, value: Record<string, unknown>): void {
|
|
342
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
346
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function stringProperty(record: Record<string, unknown>, key: string): string | null {
|
|
350
|
+
const value = record[key];
|
|
351
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function recordProperty(record: Record<string, unknown>, key: string): Record<string, unknown> | null {
|
|
355
|
+
const value = record[key];
|
|
356
|
+
return isRecord(value) ? value : null;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function getOrCreateRecord(record: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
360
|
+
const value = record[key];
|
|
361
|
+
if (isRecord(value)) {
|
|
362
|
+
return value;
|
|
363
|
+
}
|
|
364
|
+
const next: Record<string, unknown> = {};
|
|
365
|
+
record[key] = next;
|
|
366
|
+
return next;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function setBooleanProperty(record: Record<string, unknown>, key: string, value: boolean): boolean {
|
|
370
|
+
if (record[key] === value) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
record[key] = value;
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function setStringArrayProperty(record: Record<string, unknown>, key: string, value: string[]): boolean {
|
|
378
|
+
const current = record[key];
|
|
379
|
+
if (stringArrayEquals(current, value)) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
record[key] = value;
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function stringArrayEquals(value: unknown, expected: readonly string[]): boolean {
|
|
387
|
+
return (
|
|
388
|
+
Array.isArray(value) && value.length === expected.length && value.every((entry, index) => entry === expected[index])
|
|
389
|
+
);
|
|
390
|
+
}
|
package/src/test-suite-tracer.ts
DELETED
|
File without changes
|