@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
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join, relative } from 'node:path';
|
|
3
3
|
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
4
|
-
import { getProjects, readJson, readProjectConfiguration
|
|
4
|
+
import { getProjects, readJson, readProjectConfiguration } from 'nx/src/devkit-exports.js';
|
|
5
|
+
import typia from 'typia';
|
|
6
|
+
import { ManagedContentConflict } from './managed-files/managed-content.js';
|
|
7
|
+
import type { ManagedFile } from './managed-files/tree.js';
|
|
5
8
|
|
|
6
9
|
import type { NxPolicyIssue } from './workspace-config-policy.js';
|
|
7
10
|
|
|
@@ -41,7 +44,7 @@ export function detectPackageTestRunners(
|
|
|
41
44
|
continue;
|
|
42
45
|
}
|
|
43
46
|
const options = recordProperty(target, 'options');
|
|
44
|
-
const command = options ? stringProperty(options, 'command') : null;
|
|
47
|
+
const command = (options ? stringProperty(options, 'command') : null) ?? stringProperty(target, 'command');
|
|
45
48
|
if (command) {
|
|
46
49
|
const runner = detectTestRunnerFromCommand(command);
|
|
47
50
|
if (runner) {
|
|
@@ -58,7 +61,7 @@ export function detectPackageTestRunners(
|
|
|
58
61
|
continue;
|
|
59
62
|
}
|
|
60
63
|
const options = recordProperty(target, 'options');
|
|
61
|
-
const command = options ? stringProperty(options, 'command') : null;
|
|
64
|
+
const command = (options ? stringProperty(options, 'command') : null) ?? stringProperty(target, 'command');
|
|
62
65
|
if (command) {
|
|
63
66
|
const runner = detectTestRunnerFromCommand(command);
|
|
64
67
|
if (runner) {
|
|
@@ -156,13 +159,13 @@ export function applyTypecheckTestDefaults(
|
|
|
156
159
|
tsconfigTest: Record<string, unknown>,
|
|
157
160
|
options: {
|
|
158
161
|
testRunners: ReadonlySet<TestRunner>;
|
|
159
|
-
tsconfigLibExtends?: string;
|
|
162
|
+
tsconfigLibExtends?: string | string[];
|
|
160
163
|
libCompilerOptions?: Record<string, unknown>;
|
|
161
164
|
referencePaths: string[];
|
|
162
165
|
},
|
|
163
166
|
): boolean {
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
let changed = !Object.hasOwn(tsconfigTest, 'extends');
|
|
168
|
+
if (changed) tsconfigTest.extends = options.tsconfigLibExtends ?? '../../tsconfig.base.json';
|
|
166
169
|
|
|
167
170
|
const compilerOptions = getOrCreateRecord(tsconfigTest, 'compilerOptions');
|
|
168
171
|
|
|
@@ -275,11 +278,11 @@ export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
|
|
|
275
278
|
}
|
|
276
279
|
|
|
277
280
|
/**
|
|
278
|
-
*
|
|
279
|
-
*
|
|
281
|
+
* Render test typechecking policy from the caller's Tree. The managed generator
|
|
282
|
+
* owns staging, permission checks, and flushing together with its other files.
|
|
280
283
|
*/
|
|
281
|
-
export function
|
|
282
|
-
|
|
284
|
+
export function renderTypecheckTestFiles(tree: Tree): ManagedFile[] {
|
|
285
|
+
const files: ManagedFile[] = [];
|
|
283
286
|
const workspacePackages = collectWorkspacePackagesTree(tree);
|
|
284
287
|
|
|
285
288
|
for (const [projectName, config] of getProjects(tree)) {
|
|
@@ -302,39 +305,42 @@ export function applyTypecheckTestPolicyTree(tree: Tree): boolean {
|
|
|
302
305
|
// Read lib tsconfig for extends and compiler options
|
|
303
306
|
const libTsconfigPath = `${config.root}/tsconfig.lib.json`;
|
|
304
307
|
const libTsconfig = tree.exists(libTsconfigPath) ? readJson<Record<string, unknown>>(tree, libTsconfigPath) : null;
|
|
305
|
-
const tsconfigLibExtends =
|
|
306
|
-
(libTsconfig ? stringProperty(libTsconfig, 'extends') : null) ?? '../../tsconfig.base.json';
|
|
308
|
+
const tsconfigLibExtends = tsconfigExtends(libTsconfig) ?? '../../tsconfig.base.json';
|
|
307
309
|
const libCompilerOptions = libTsconfig ? recordProperty(libTsconfig, 'compilerOptions') : null;
|
|
308
310
|
|
|
309
311
|
// Collect reference paths
|
|
310
312
|
const referencePaths = collectReferencePathsTree(tree, config.root, pkg, workspacePackages);
|
|
311
313
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
isNew
|
|
320
|
-
) {
|
|
321
|
-
writeJson(tree, tsconfigTestPath, tsconfigTest);
|
|
322
|
-
changed = true;
|
|
323
|
-
}
|
|
314
|
+
const changed = applyTypecheckTestDefaults(tsconfigTest, {
|
|
315
|
+
testRunners,
|
|
316
|
+
tsconfigLibExtends,
|
|
317
|
+
libCompilerOptions: libCompilerOptions ?? undefined,
|
|
318
|
+
referencePaths,
|
|
319
|
+
});
|
|
320
|
+
files.push(renderTsconfig(tree, tsconfigTestPath, tsconfigTest, changed || isNew));
|
|
324
321
|
|
|
325
322
|
// Remove test reference from tsconfig.json
|
|
326
323
|
const tsconfigPath = `${config.root}/tsconfig.json`;
|
|
327
324
|
if (tree.exists(tsconfigPath)) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
changed = true;
|
|
331
|
-
}
|
|
332
|
-
return tsconfig;
|
|
333
|
-
});
|
|
325
|
+
const tsconfig = readJson<Record<string, unknown>>(tree, tsconfigPath);
|
|
326
|
+
files.push(renderTsconfig(tree, tsconfigPath, tsconfig, removeTsconfigTestReference(tsconfig)));
|
|
334
327
|
}
|
|
335
328
|
}
|
|
336
329
|
|
|
337
|
-
return
|
|
330
|
+
return files;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function renderTsconfig(tree: Tree, target: string, config: Record<string, unknown>, changed: boolean): ManagedFile {
|
|
334
|
+
const current = tree.read(target, 'utf8');
|
|
335
|
+
if (!changed) return { target, content: current };
|
|
336
|
+
// A documented config cannot survive JSON.stringify. Preserve its reasoning
|
|
337
|
+
// and refuse before the shared generator stages or flushes any managed file.
|
|
338
|
+
if (current !== null && hasJsonComments(current)) {
|
|
339
|
+
throw new ManagedContentConflict(
|
|
340
|
+
`${target} carries comments a rewrite would delete; apply the no-emit test typecheck policy by hand`,
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return { target, content: `${JSON.stringify(config, null, 2)}\n` };
|
|
338
344
|
}
|
|
339
345
|
|
|
340
346
|
/**
|
|
@@ -383,7 +389,7 @@ export function checkTypecheckTestPolicy(root: string): NxPolicyIssue[] {
|
|
|
383
389
|
issues.push(...absoluteIssues);
|
|
384
390
|
if (absoluteIssues.length === 0) {
|
|
385
391
|
const libTsconfig = readJsonObject(join(root, packagePath, 'tsconfig.lib.json'));
|
|
386
|
-
const tsconfigLibExtends =
|
|
392
|
+
const tsconfigLibExtends = tsconfigExtends(libTsconfig) ?? '../../tsconfig.base.json';
|
|
387
393
|
const libCompilerOptions = libTsconfig ? recordProperty(libTsconfig, 'compilerOptions') : null;
|
|
388
394
|
const referencePaths = collectTsconfigTestReferencePaths(root, packagePath, pkg, workspaceNames);
|
|
389
395
|
const normalized = structuredClone(tsconfig);
|
|
@@ -412,79 +418,6 @@ export function checkTypecheckTestPolicy(root: string): NxPolicyIssue[] {
|
|
|
412
418
|
return issues;
|
|
413
419
|
}
|
|
414
420
|
|
|
415
|
-
/**
|
|
416
|
-
* Fix all workspace packages' tsconfig.test.json configuration.
|
|
417
|
-
* Returns whether any files changed.
|
|
418
|
-
*/
|
|
419
|
-
export function applyTypecheckTestPolicy(root: string): boolean {
|
|
420
|
-
const workspaceNames = getWorkspacePackageNames(root);
|
|
421
|
-
let changed = false;
|
|
422
|
-
|
|
423
|
-
for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
|
|
424
|
-
const pkg = readJsonObject(packageJsonPath);
|
|
425
|
-
if (!pkg) {
|
|
426
|
-
continue;
|
|
427
|
-
}
|
|
428
|
-
const packageDir = packageJsonPath.slice(0, -'/package.json'.length);
|
|
429
|
-
const packagePath = relative(root, packageDir);
|
|
430
|
-
if (packagePath === '' || packagePath === '.') {
|
|
431
|
-
continue;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const testRunners = detectPackageTestRunners(pkg);
|
|
435
|
-
if (testRunners.size === 0) {
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// Create/update tsconfig.test.json
|
|
440
|
-
const tsconfigTestPath = join(root, packagePath, 'tsconfig.test.json');
|
|
441
|
-
const existing = readJsonObject(tsconfigTestPath);
|
|
442
|
-
const tsconfigTest = existing ?? {};
|
|
443
|
-
let fileChanged = existing === null;
|
|
444
|
-
|
|
445
|
-
// Read lib tsconfig for extends and compiler options
|
|
446
|
-
const libTsconfig = readJsonObject(join(root, packagePath, 'tsconfig.lib.json'));
|
|
447
|
-
const tsconfigLibExtends = stringProperty(libTsconfig ?? {}, 'extends') ?? '../../tsconfig.base.json';
|
|
448
|
-
const libCompilerOptions = libTsconfig ? recordProperty(libTsconfig, 'compilerOptions') : null;
|
|
449
|
-
|
|
450
|
-
// Collect reference paths
|
|
451
|
-
const referencePaths = collectTsconfigTestReferencePaths(root, packagePath, pkg, workspaceNames);
|
|
452
|
-
|
|
453
|
-
fileChanged =
|
|
454
|
-
applyTypecheckTestDefaults(tsconfigTest, {
|
|
455
|
-
testRunners,
|
|
456
|
-
tsconfigLibExtends,
|
|
457
|
-
libCompilerOptions: libCompilerOptions ?? undefined,
|
|
458
|
-
referencePaths,
|
|
459
|
-
}) || fileChanged;
|
|
460
|
-
|
|
461
|
-
if (fileChanged) {
|
|
462
|
-
// A documented tsconfig cannot survive JSON.stringify, so the policy says
|
|
463
|
-
// what it wants instead of quietly deleting the reasoning. The check
|
|
464
|
-
// half (checkTypecheckTestPolicy) reports the same drift, so CI still
|
|
465
|
-
// fails until a human applies it.
|
|
466
|
-
if (existsSync(tsconfigTestPath) && hasJsonComments(readFileSync(tsconfigTestPath, 'utf8'))) {
|
|
467
|
-
console.error(
|
|
468
|
-
`refused ${packagePath}/tsconfig.test.json carries comments a rewrite would delete; apply the policy by hand`,
|
|
469
|
-
);
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
writeJsonObjectFs(tsconfigTestPath, tsconfigTest);
|
|
473
|
-
changed = true;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// Remove ./tsconfig.test.json from tsconfig.json references if present
|
|
477
|
-
const projectTsconfigPath = join(root, packagePath, 'tsconfig.json');
|
|
478
|
-
const projectTsconfig = readJsonObject(projectTsconfigPath);
|
|
479
|
-
if (projectTsconfig && removeTsconfigTestReference(projectTsconfig)) {
|
|
480
|
-
writeJsonObjectFs(projectTsconfigPath, projectTsconfig);
|
|
481
|
-
changed = true;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
return changed;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
421
|
function detectTestRunnerFromCommand(command: string): TestRunner | null {
|
|
489
422
|
const trimmed = parseEnvPrefixedCommand(command).command.trim();
|
|
490
423
|
if (/^bun\s+test(?:\s|$)/.test(trimmed)) {
|
|
@@ -704,9 +637,8 @@ function collectTsconfigTestReferencePaths(
|
|
|
704
637
|
* documented one. Returning null there meant "file absent", and the caller
|
|
705
638
|
* regenerated it from scratch: a `lib` the test program declared, an
|
|
706
639
|
* `exclude`, an extra `include` glob and every comment explaining them
|
|
707
|
-
* disappeared on the next
|
|
708
|
-
*
|
|
709
|
-
* about them (see writeJsonObjectFs's caller).
|
|
640
|
+
* disappeared on the next update. Comments are stripped for parsing only;
|
|
641
|
+
* renderTsconfig refuses a policy repair that would discard them.
|
|
710
642
|
*/
|
|
711
643
|
function readJsonObject(path: string): Record<string, unknown> | null {
|
|
712
644
|
if (!existsSync(path)) {
|
|
@@ -774,14 +706,15 @@ function stripJsonComments(text: string): string {
|
|
|
774
706
|
return output.replace(/,(\s*[}\]])/g, '$1');
|
|
775
707
|
}
|
|
776
708
|
|
|
777
|
-
function writeJsonObjectFs(path: string, value: Record<string, unknown>): void {
|
|
778
|
-
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
779
|
-
}
|
|
780
|
-
|
|
781
709
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
782
710
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
783
711
|
}
|
|
784
712
|
|
|
713
|
+
/** TypeScript 5 accepts ordered base-config arrays as well as a single base. */
|
|
714
|
+
function tsconfigExtends(config: Record<string, unknown> | null): string | string[] | undefined {
|
|
715
|
+
return typia.assert<string | string[] | undefined>(config?.extends);
|
|
716
|
+
}
|
|
717
|
+
|
|
785
718
|
function stringProperty(record: Record<string, unknown>, key: string): string | null {
|
|
786
719
|
const value = record[key];
|
|
787
720
|
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
@@ -803,14 +736,6 @@ function getOrCreateRecord(record: Record<string, unknown>, key: string): Record
|
|
|
803
736
|
return next;
|
|
804
737
|
}
|
|
805
738
|
|
|
806
|
-
function setMissingStringProperty(record: Record<string, unknown>, key: string, value: string): boolean {
|
|
807
|
-
if (typeof record[key] === 'string') {
|
|
808
|
-
return false;
|
|
809
|
-
}
|
|
810
|
-
record[key] = value;
|
|
811
|
-
return true;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
739
|
function setBooleanProperty(record: Record<string, unknown>, key: string, value: boolean): boolean {
|
|
815
740
|
if (record[key] === value) {
|
|
816
741
|
return false;
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
function validNxJson(): Record<string, unknown> {
|
|
27
27
|
return {
|
|
28
28
|
plugins: ['@smoothbricks/nx-plugin'],
|
|
29
|
+
sync: { globalGenerators: ['@smoothbricks/nx-plugin:managed-files'] },
|
|
29
30
|
targetDefaults: validTargetDefaults(),
|
|
30
31
|
namedInputs: validNamedInputs(),
|
|
31
32
|
};
|
|
@@ -344,8 +345,7 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
344
345
|
|
|
345
346
|
it('accepts custom precise production inputs unchanged', () => {
|
|
346
347
|
const nxJson: Record<string, unknown> = {
|
|
347
|
-
|
|
348
|
-
targetDefaults: validTargetDefaults(),
|
|
348
|
+
...validNxJson(),
|
|
349
349
|
namedInputs: {
|
|
350
350
|
...validNamedInputs(),
|
|
351
351
|
production: ['{projectRoot}/src/**/*.rs', '{projectRoot}/Cargo.toml', '!{projectRoot}/**/*.test.*'],
|
|
@@ -524,3 +524,15 @@ function readPluginNames(value: unknown): unknown[] {
|
|
|
524
524
|
const plugins: unknown[] = value;
|
|
525
525
|
return plugins.map((plugin) => (typeof plugin === 'string' ? plugin : expectRecord(plugin).plugin));
|
|
526
526
|
}
|
|
527
|
+
|
|
528
|
+
describe('managed-file sync registration', () => {
|
|
529
|
+
it('preserves other generators and is idempotent', () => {
|
|
530
|
+
const nxJson = { sync: { applyChanges: true, globalGenerators: ['example:sync'] } };
|
|
531
|
+
applyWorkspaceConfig(nxJson);
|
|
532
|
+
expect(nxJson.sync).toEqual({
|
|
533
|
+
applyChanges: true,
|
|
534
|
+
globalGenerators: ['example:sync', '@smoothbricks/nx-plugin:managed-files'],
|
|
535
|
+
});
|
|
536
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
537
|
+
});
|
|
538
|
+
});
|
|
@@ -5,6 +5,8 @@ import { readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
|
5
5
|
|
|
6
6
|
import { CARGO_TEST_TARGET } from './cargo-workspace.js';
|
|
7
7
|
|
|
8
|
+
export const MANAGED_FILES_SYNC_GENERATOR = '@smoothbricks/nx-plugin:managed-files';
|
|
9
|
+
|
|
8
10
|
export interface NxPolicyIssue {
|
|
9
11
|
path: string;
|
|
10
12
|
message: string;
|
|
@@ -22,9 +24,7 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
|
22
24
|
'*-wasm',
|
|
23
25
|
] as const;
|
|
24
26
|
|
|
25
|
-
export
|
|
26
|
-
export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'] as const;
|
|
27
|
-
export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS] as const;
|
|
27
|
+
export { LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, PLATFORM_TARGET_GLOBS } from './platform-targets.js';
|
|
28
28
|
|
|
29
29
|
const buildOutputTargetSuffixes = BUILD_OUTPUT_DEPENDENCIES.map((glob) => glob.slice(1));
|
|
30
30
|
|
|
@@ -154,6 +154,12 @@ export function applyWorkspaceConfig(nxJson: Record<string, unknown>): boolean {
|
|
|
154
154
|
nxJson.plugins = nextPlugins;
|
|
155
155
|
changed = true;
|
|
156
156
|
}
|
|
157
|
+
const sync = recordProperty(nxJson, 'sync') ?? {};
|
|
158
|
+
const generators = Array.isArray(sync.globalGenerators) ? sync.globalGenerators : [];
|
|
159
|
+
if (!generators.includes(MANAGED_FILES_SYNC_GENERATOR)) {
|
|
160
|
+
nxJson.sync = { ...sync, globalGenerators: [...generators, MANAGED_FILES_SYNC_GENERATOR] };
|
|
161
|
+
changed = true;
|
|
162
|
+
}
|
|
157
163
|
return changed;
|
|
158
164
|
}
|
|
159
165
|
|
|
@@ -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
|
+
}
|