@smoothbricks/nx-plugin 0.3.2 → 0.3.3
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 +7 -12
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +1 -100
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -125
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +0 -30
- package/dist/version-actions.cjs +39 -35
- package/dist/version-actions.d.cts.map +1 -1
- package/generators.json +1 -1
- package/package.json +1 -1
- package/src/generators/create-package/generator.test.ts +0 -71
- package/src/generators/create-package/generator.ts +1 -121
- package/src/generators/create-package/schema.d.ts +1 -1
- package/src/generators/create-package/schema.json +1 -1
- package/src/index.test.ts +72 -81
- package/src/index.ts +25 -148
- package/src/package-target-policy.test.ts +0 -48
- package/src/package-target-policy.ts +0 -32
- package/src/version-actions.cts +39 -37
|
@@ -427,30 +427,6 @@ describe('package target policy', () => {
|
|
|
427
427
|
}
|
|
428
428
|
});
|
|
429
429
|
|
|
430
|
-
it('validates build.zig has steps', async () => {
|
|
431
|
-
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
432
|
-
try {
|
|
433
|
-
await writeJson(join(root, 'package.json'), {
|
|
434
|
-
name: '@scope/root',
|
|
435
|
-
private: true,
|
|
436
|
-
workspaces: ['packages/*'],
|
|
437
|
-
});
|
|
438
|
-
const pkgDir = join(root, 'packages/wasm');
|
|
439
|
-
await mkdir(pkgDir, { recursive: true });
|
|
440
|
-
await writeJson(join(pkgDir, 'package.json'), {
|
|
441
|
-
name: '@scope/wasm',
|
|
442
|
-
nx: { name: 'wasm' },
|
|
443
|
-
});
|
|
444
|
-
// build.zig without b.step(...)
|
|
445
|
-
await writeFile(join(pkgDir, 'build.zig'), 'const std = @import("std");\n');
|
|
446
|
-
|
|
447
|
-
const issues = checkPackageTargetPolicy(root);
|
|
448
|
-
expect(issues.some((i) => i.message.includes('build.zig must define at least one b.step'))).toBe(true);
|
|
449
|
-
} finally {
|
|
450
|
-
await rm(root, { recursive: true, force: true });
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
|
|
454
430
|
it('requires test entrypoint when test files exist', async () => {
|
|
455
431
|
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
456
432
|
try {
|
|
@@ -639,30 +615,6 @@ describe('checkPackageTargetPolicyTree', () => {
|
|
|
639
615
|
expect(issues.some((i) => i.message.includes('lint:fix') && i.message.includes('colon target names'))).toBe(true);
|
|
640
616
|
});
|
|
641
617
|
|
|
642
|
-
it('validates build.zig has steps', () => {
|
|
643
|
-
addProject(tree, 'wasm', 'packages/wasm');
|
|
644
|
-
writeJsonFile(tree, 'packages/wasm/package.json', {
|
|
645
|
-
name: '@scope/wasm',
|
|
646
|
-
nx: { name: 'wasm' },
|
|
647
|
-
});
|
|
648
|
-
tree.write('packages/wasm/build.zig', 'const std = @import("std");\n');
|
|
649
|
-
|
|
650
|
-
const issues = checkPackageTargetPolicyTree(tree);
|
|
651
|
-
expect(issues.some((i) => i.message.includes('build.zig must define at least one b.step'))).toBe(true);
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it('passes build.zig with valid steps', () => {
|
|
655
|
-
addProject(tree, 'wasm', 'packages/wasm');
|
|
656
|
-
writeJsonFile(tree, 'packages/wasm/package.json', {
|
|
657
|
-
name: '@scope/wasm',
|
|
658
|
-
nx: { name: 'wasm' },
|
|
659
|
-
});
|
|
660
|
-
tree.write('packages/wasm/build.zig', 'const step = b.step("wasm", "Build wasm");\n');
|
|
661
|
-
|
|
662
|
-
const issues = checkPackageTargetPolicyTree(tree);
|
|
663
|
-
expect(issues.filter((i) => i.message.includes('build.zig'))).toEqual([]);
|
|
664
|
-
});
|
|
665
|
-
|
|
666
618
|
it('requires test entrypoint when test files exist', () => {
|
|
667
619
|
addProject(tree, 'lib', 'packages/lib');
|
|
668
620
|
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
@@ -354,7 +354,6 @@ function isSafeNxScriptCommand(command: string): boolean {
|
|
|
354
354
|
/^tsdown(?:\s|$)/.test(trimmed) ||
|
|
355
355
|
/^vite\s+(?:build|dev|preview)(?:\s|$)/.test(trimmed) ||
|
|
356
356
|
/^astro\s+(?:build|dev|preview|check)(?:\s|$)/.test(trimmed) ||
|
|
357
|
-
/^zig\s+build(?:\s|$)/.test(trimmed) ||
|
|
358
357
|
/^bun\s+[./\w-]*build[\w.-]*\.ts(?:\s|$)/.test(trimmed) ||
|
|
359
358
|
/(?:^|\s)(?:bench|benchmark)(?:\s|$)/.test(trimmed) ||
|
|
360
359
|
/^wrangler\s+build(?:\s|$)/.test(trimmed)
|
|
@@ -418,10 +417,6 @@ function targetNameForCommand(command: string): string | null {
|
|
|
418
417
|
if (/^tsdown(?:\s|$)/.test(trimmed)) {
|
|
419
418
|
return 'tsdown-js';
|
|
420
419
|
}
|
|
421
|
-
const zigStep = /^zig\s+build\s+([A-Za-z0-9_-]+)(?:\s|$)/.exec(trimmed)?.[1];
|
|
422
|
-
if (zigStep) {
|
|
423
|
-
return `zig-${zigStep}`;
|
|
424
|
-
}
|
|
425
420
|
if (/^wrangler\s+build(?:\s|$)/.test(trimmed)) {
|
|
426
421
|
return 'build';
|
|
427
422
|
}
|
|
@@ -584,19 +579,6 @@ function directoryContainsTestFiles(path: string): boolean {
|
|
|
584
579
|
return false;
|
|
585
580
|
}
|
|
586
581
|
|
|
587
|
-
function validateBuildZigPolicy(root: string, packagePath: string): NxPolicyIssue[] {
|
|
588
|
-
const path = join(root, packagePath, 'build.zig');
|
|
589
|
-
if (!existsSync(path)) {
|
|
590
|
-
return [];
|
|
591
|
-
}
|
|
592
|
-
if (/\bb\.step\s*\(/.test(readFileSync(path, 'utf8'))) {
|
|
593
|
-
return [];
|
|
594
|
-
}
|
|
595
|
-
return [
|
|
596
|
-
{ path: join(root, packagePath), message: `${packagePath}/build.zig must define at least one b.step(...) target` },
|
|
597
|
-
];
|
|
598
|
-
}
|
|
599
|
-
|
|
600
582
|
function validateExplicitNxTargets(
|
|
601
583
|
pkg: Record<string, unknown>,
|
|
602
584
|
packagePath: string,
|
|
@@ -952,18 +934,6 @@ function directoryContainsTestFilesTree(tree: Tree, path: string): boolean {
|
|
|
952
934
|
return false;
|
|
953
935
|
}
|
|
954
936
|
|
|
955
|
-
function validateBuildZigPolicyTree(tree: Tree, packagePath: string): NxPolicyIssue[] {
|
|
956
|
-
const path = `${packagePath}/build.zig`;
|
|
957
|
-
if (!tree.exists(path)) {
|
|
958
|
-
return [];
|
|
959
|
-
}
|
|
960
|
-
const content = tree.read(path, 'utf-8');
|
|
961
|
-
if (content && /\bb\.step\s*\(/.test(content)) {
|
|
962
|
-
return [];
|
|
963
|
-
}
|
|
964
|
-
return [{ path: packagePath, message: `${packagePath}/build.zig must define at least one b.step(...) target` }];
|
|
965
|
-
}
|
|
966
|
-
|
|
967
937
|
function validateTestEntrypointPresenceTree(
|
|
968
938
|
tree: Tree,
|
|
969
939
|
packagePath: string,
|
|
@@ -998,7 +968,6 @@ export function checkPackageTargetPolicyTree(tree: Tree, options: PackageTargetP
|
|
|
998
968
|
|
|
999
969
|
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
1000
970
|
issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
|
|
1001
|
-
issues.push(...validateBuildZigPolicyTree(tree, packagePath));
|
|
1002
971
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
|
|
1003
972
|
}
|
|
1004
973
|
|
|
@@ -1222,7 +1191,6 @@ export function checkPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1222
1191
|
|
|
1223
1192
|
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
1224
1193
|
issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
|
|
1225
|
-
issues.push(...validateBuildZigPolicy(root, packagePath));
|
|
1226
1194
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
|
|
1227
1195
|
}
|
|
1228
1196
|
|
package/src/version-actions.cts
CHANGED
|
@@ -19,10 +19,12 @@ const afterAllProjectsVersioned: AfterAllProjectsVersioned = async (cwd, options
|
|
|
19
19
|
// - https://github.com/oven-sh/bun/issues/18906
|
|
20
20
|
// - https://github.com/oven-sh/bun/issues/20477
|
|
21
21
|
// - https://github.com/oven-sh/bun/issues/20829
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
|
|
22
|
+
//
|
|
23
|
+
// After version bumps, rewrite bun.lock for pack/publish:
|
|
24
|
+
// - stable package.json versions stay as-is
|
|
25
|
+
// - unpublished package.json prereleases (prepare-next) map to last stable tag
|
|
26
|
+
// so a releasing package does not embed unpublishable -next deps via workspace:*
|
|
27
|
+
const updated = syncBunLockfileVersionsForPublish(cwd);
|
|
26
28
|
if (updated === 0) {
|
|
27
29
|
return result;
|
|
28
30
|
}
|
|
@@ -37,7 +39,7 @@ baseVersionActions.afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
|
37
39
|
|
|
38
40
|
export = baseVersionActions;
|
|
39
41
|
|
|
40
|
-
function
|
|
42
|
+
function syncBunLockfileVersionsForPublish(root: string): number {
|
|
41
43
|
const lockfilePath = join(root, 'bun.lock');
|
|
42
44
|
if (!existsSync(lockfilePath)) {
|
|
43
45
|
throw new Error('bun.lock not found');
|
|
@@ -46,13 +48,7 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
46
48
|
let lockfile = readFileSync(lockfilePath, 'utf8');
|
|
47
49
|
let updated = 0;
|
|
48
50
|
for (const pkg of packages) {
|
|
49
|
-
|
|
50
|
-
// never have been published. Use the latest stable git tag version so
|
|
51
|
-
// that `bun pm pack` writes an installable dependency range for consumers.
|
|
52
|
-
const targetVersion = pkg.version.includes('-')
|
|
53
|
-
? (latestStableTagVersion(root, pkg.projectName) ?? pkg.version)
|
|
54
|
-
: pkg.version;
|
|
55
|
-
|
|
51
|
+
const targetVersion = publishLockfileVersion(root, pkg.projectName, pkg.version);
|
|
56
52
|
const relativePath = pkg.path.replaceAll('\\', '/');
|
|
57
53
|
const escaped = escapeRegex(relativePath);
|
|
58
54
|
const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
|
|
@@ -67,9 +63,8 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
67
63
|
continue;
|
|
68
64
|
}
|
|
69
65
|
lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
66
|
+
const suffix = targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : '';
|
|
67
|
+
console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${suffix}`);
|
|
73
68
|
updated++;
|
|
74
69
|
}
|
|
75
70
|
if (updated > 0) {
|
|
@@ -81,6 +76,35 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
81
76
|
return updated;
|
|
82
77
|
}
|
|
83
78
|
|
|
79
|
+
function publishLockfileVersion(root: string, projectName: string, packageVersion: string): string {
|
|
80
|
+
if (!packageVersion.includes('-')) {
|
|
81
|
+
return packageVersion;
|
|
82
|
+
}
|
|
83
|
+
return latestStableTagVersion(root, projectName) ?? packageVersion;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function latestStableTagVersion(root: string, projectName: string): string | null {
|
|
87
|
+
try {
|
|
88
|
+
const output = execSync(`git tag --list '${projectName}@*' --sort=-v:refname`, {
|
|
89
|
+
cwd: root,
|
|
90
|
+
encoding: 'utf8',
|
|
91
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
92
|
+
});
|
|
93
|
+
const prefix = `${projectName}@`;
|
|
94
|
+
for (const line of output.split('\n')) {
|
|
95
|
+
const tag = line.trim();
|
|
96
|
+
if (!tag.startsWith(prefix)) continue;
|
|
97
|
+
const version = tag.slice(prefix.length);
|
|
98
|
+
if (version && !version.includes('-')) {
|
|
99
|
+
return version;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
84
108
|
interface WorkspacePackage {
|
|
85
109
|
path: string;
|
|
86
110
|
name: string;
|
|
@@ -117,25 +141,3 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
117
141
|
function escapeRegex(value: string): string {
|
|
118
142
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
function latestStableTagVersion(root: string, projectName: string): string | null {
|
|
122
|
-
try {
|
|
123
|
-
const output = execSync(`git tag --list '${projectName}@*' --sort=-v:refname`, {
|
|
124
|
-
cwd: root,
|
|
125
|
-
encoding: 'utf8',
|
|
126
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
127
|
-
});
|
|
128
|
-
const prefix = `${projectName}@`;
|
|
129
|
-
for (const line of output.split('\n')) {
|
|
130
|
-
const tag = line.trim();
|
|
131
|
-
if (!tag.startsWith(prefix)) continue;
|
|
132
|
-
const version = tag.slice(prefix.length);
|
|
133
|
-
if (version && !version.includes('-')) {
|
|
134
|
-
return version;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
return null;
|
|
138
|
-
} catch {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|