@smoothbricks/nx-plugin 0.3.1 → 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.
@@ -11,10 +11,12 @@ const afterAllProjectsVersioned = async (cwd, options) => {
11
11
  // - https://github.com/oven-sh/bun/issues/18906
12
12
  // - https://github.com/oven-sh/bun/issues/20477
13
13
  // - https://github.com/oven-sh/bun/issues/20829
14
- // Nx runs `bun install --lockfile-only`, but Bun currently leaves workspace
15
- // versions stale in bun.lock. `bun pm pack` then rewrites `workspace:*` using
16
- // those stale lockfile versions instead of the current package.json versions.
17
- const updated = syncBunLockfileVersions(cwd);
14
+ //
15
+ // After version bumps, rewrite bun.lock for pack/publish:
16
+ // - stable package.json versions stay as-is
17
+ // - unpublished package.json prereleases (prepare-next) map to last stable tag
18
+ // so a releasing package does not embed unpublishable -next deps via workspace:*
19
+ const updated = syncBunLockfileVersionsForPublish(cwd);
18
20
  if (updated === 0) {
19
21
  return result;
20
22
  }
@@ -24,7 +26,7 @@ const afterAllProjectsVersioned = async (cwd, options) => {
24
26
  };
25
27
  };
26
28
  baseVersionActions.afterAllProjectsVersioned = afterAllProjectsVersioned;
27
- function syncBunLockfileVersions(root) {
29
+ function syncBunLockfileVersionsForPublish(root) {
28
30
  const lockfilePath = (0, node_path_1.join)(root, 'bun.lock');
29
31
  if (!(0, node_fs_1.existsSync)(lockfilePath)) {
30
32
  throw new Error('bun.lock not found');
@@ -33,12 +35,7 @@ function syncBunLockfileVersions(root) {
33
35
  let lockfile = (0, node_fs_1.readFileSync)(lockfilePath, 'utf8');
34
36
  let updated = 0;
35
37
  for (const pkg of packages) {
36
- // If the package.json version is a prerelease (e.g. 0.2.2-next.0) it may
37
- // never have been published. Use the latest stable git tag version so
38
- // that `bun pm pack` writes an installable dependency range for consumers.
39
- const targetVersion = pkg.version.includes('-')
40
- ? (latestStableTagVersion(root, pkg.projectName) ?? pkg.version)
41
- : pkg.version;
38
+ const targetVersion = publishLockfileVersion(root, pkg.projectName, pkg.version);
42
39
  const relativePath = pkg.path.replaceAll('\\', '/');
43
40
  const escaped = escapeRegex(relativePath);
44
41
  const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
@@ -53,7 +50,8 @@ function syncBunLockfileVersions(root) {
53
50
  continue;
54
51
  }
55
52
  lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
56
- console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : ''}`);
53
+ const suffix = targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : '';
54
+ console.log(`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${suffix}`);
57
55
  updated++;
58
56
  }
59
57
  if (updated > 0) {
@@ -62,6 +60,35 @@ function syncBunLockfileVersions(root) {
62
60
  console.log(updated > 0 ? `Updated ${updated} workspace version(s) in bun.lock` : 'All workspace versions already in sync.');
63
61
  return updated;
64
62
  }
63
+ function publishLockfileVersion(root, projectName, packageVersion) {
64
+ if (!packageVersion.includes('-')) {
65
+ return packageVersion;
66
+ }
67
+ return latestStableTagVersion(root, projectName) ?? packageVersion;
68
+ }
69
+ function latestStableTagVersion(root, projectName) {
70
+ try {
71
+ const output = (0, node_child_process_1.execSync)(`git tag --list '${projectName}@*' --sort=-v:refname`, {
72
+ cwd: root,
73
+ encoding: 'utf8',
74
+ stdio: ['pipe', 'pipe', 'pipe'],
75
+ });
76
+ const prefix = `${projectName}@`;
77
+ for (const line of output.split('\n')) {
78
+ const tag = line.trim();
79
+ if (!tag.startsWith(prefix))
80
+ continue;
81
+ const version = tag.slice(prefix.length);
82
+ if (version && !version.includes('-')) {
83
+ return version;
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ }
65
92
  function workspacePackages(root) {
66
93
  const packagesRoot = (0, node_path_1.join)(root, 'packages');
67
94
  return (0, node_fs_1.readdirSync)(packagesRoot, { withFileTypes: true })
@@ -89,27 +116,4 @@ function isRecord(value) {
89
116
  function escapeRegex(value) {
90
117
  return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
91
118
  }
92
- function latestStableTagVersion(root, projectName) {
93
- try {
94
- const output = (0, node_child_process_1.execSync)(`git tag --list '${projectName}@*' --sort=-v:refname`, {
95
- cwd: root,
96
- encoding: 'utf8',
97
- stdio: ['pipe', 'pipe', 'pipe'],
98
- });
99
- const prefix = `${projectName}@`;
100
- for (const line of output.split('\n')) {
101
- const tag = line.trim();
102
- if (!tag.startsWith(prefix))
103
- continue;
104
- const version = tag.slice(prefix.length);
105
- if (version && !version.includes('-')) {
106
- return version;
107
- }
108
- }
109
- return null;
110
- }
111
- catch {
112
- return null;
113
- }
114
- }
115
119
  module.exports = baseVersionActions;
@@ -1 +1 @@
1
- {"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQ5E,QAAA,MAAM,kBAAkB;+BALyC,yBAAyB;CAKf,CAAC;SA0BnE,kBAAkB"}
1
+ {"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAQ5E,QAAA,MAAM,kBAAkB;+BALyC,yBAAyB;CAKf,CAAC;SA4BnE,kBAAkB"}
@@ -3,7 +3,10 @@ export interface NxPolicyIssue {
3
3
  path: string;
4
4
  message: string;
5
5
  }
6
- export declare const BUILD_OUTPUT_DEPENDENCIES: string[];
6
+ export declare const BUILD_OUTPUT_DEPENDENCIES: readonly ['*-js', '*-web', '*-html', '*-css', '*-android', '*-native', '*-napi', '*-bun', '*-wasm'];
7
+ export declare const MACOS_PLATFORM_TARGET_GLOBS: readonly ['*-macos', '*-ios'];
8
+ export declare const LINUX_PLATFORM_TARGET_GLOBS: readonly ['*-linux'];
9
+ export declare const PLATFORM_TARGET_GLOBS: readonly ["*-macos", "*-ios", "*-linux"];
7
10
  /**
8
11
  * Check workspace config policy on an in-memory nx.json object.
9
12
  */
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,UAWrC,CAAC;AAeF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CA+CrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAa7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
1
+ {"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AACzE,eAAO,MAAM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC;AAe/G;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CA+CrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAa7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
@@ -6,13 +6,15 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
6
6
  '*-web',
7
7
  '*-html',
8
8
  '*-css',
9
- '*-ios',
10
9
  '*-android',
11
10
  '*-native',
12
11
  '*-napi',
13
12
  '*-bun',
14
13
  '*-wasm',
15
14
  ];
15
+ export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'];
16
+ export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'];
17
+ export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS];
16
18
  const nxJsTypescriptPlugin = '@nx/js/typescript';
17
19
  const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
18
20
  const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
package/generators.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "create-package": {
14
14
  "factory": "./dist/generators/create-package/generator.js",
15
15
  "schema": "./src/generators/create-package/schema.json",
16
- "description": "Scaffold a new workspace package (ts-lib or ts-zig)"
16
+ "description": "Scaffold a new TypeScript workspace package"
17
17
  },
18
18
  "make-public": {
19
19
  "factory": "./dist/generators/make-public/generator.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -124,77 +124,6 @@ describe('create-package generator', () => {
124
124
  });
125
125
  });
126
126
 
127
- describe('ts-zig variant', () => {
128
- it('creates zig scaffold on top of ts-lib', async () => {
129
- const tree = setupTree();
130
- await generator(tree, { name: 'columine', variant: 'ts-zig' });
131
-
132
- // Zig files exist
133
- expect(tree.exists('packages/columine/build.zig')).toBe(true);
134
- expect(tree.exists('packages/columine/build.zig.zon')).toBe(true);
135
- expect(tree.exists('packages/columine/src/columine.zig')).toBe(true);
136
-
137
- // build.zig contains wasm step
138
- const buildZig = tree.read('packages/columine/build.zig', 'utf-8') ?? '';
139
- expect(buildZig).toContain('b.step("wasm", "Build WASM artifact")');
140
- expect(buildZig).toContain('.name = "columine"');
141
- expect(buildZig).toContain('b.path("src/columine.zig")');
142
-
143
- // build.zig.zon
144
- const buildZigZon = tree.read('packages/columine/build.zig.zon', 'utf-8') ?? '';
145
- expect(buildZigZon).toContain('.name = .columine');
146
-
147
- // src/<name>.zig
148
- const zigSrc = tree.read('packages/columine/src/columine.zig', 'utf-8') ?? '';
149
- expect(zigSrc).toContain('export fn add');
150
-
151
- // package.json has wasm export and build scripts
152
- const pkg = readJson(tree, 'packages/columine/package.json');
153
- expect(pkg.exports['./wasm']).toBe('./dist/columine.wasm');
154
- expect(pkg.exports['.'].development).toBeUndefined();
155
- expect(pkg.scripts['build:zig']).toBe('nx run columine:zig-wasm');
156
- expect(pkg.scripts['build:ts']).toBe('nx run columine:tsc-js');
157
- expect(pkg.scripts.build).toBe('bun run build:ts && bun run build:zig');
158
- expect(pkg.files).toEqual(['dist']);
159
-
160
- // tsconfig.lib.json has webworker lib
161
- const tsconfigLib = readJson(tree, 'packages/columine/tsconfig.lib.json');
162
- expect(tsconfigLib.compilerOptions.lib).toEqual(['es2022', 'webworker']);
163
- expect(tsconfigLib.compilerOptions.declaration).toBe(true);
164
- expect(tsconfigLib.compilerOptions.sourceMap).toBe(true);
165
-
166
- // tsconfig.test.json has webworker lib
167
- const tsconfigTest = readJson(tree, 'packages/columine/tsconfig.test.json');
168
- expect(tsconfigTest.compilerOptions.lib).toEqual(['es2022', 'webworker']);
169
- });
170
-
171
- it('combines zig and publication metadata when public', async () => {
172
- const tree = setupTree();
173
- await generator(tree, { name: 'zigpub', variant: 'ts-zig', public: true });
174
-
175
- const pkg = readJson(tree, 'packages/zigpub/package.json');
176
-
177
- // Has zig files
178
- expect(tree.exists('packages/zigpub/build.zig')).toBe(true);
179
- expect(tree.exists('packages/zigpub/build.zig.zon')).toBe(true);
180
- expect(tree.exists('packages/zigpub/src/zigpub.zig')).toBe(true);
181
-
182
- // Has publication metadata
183
- expect(pkg.private).toBeUndefined();
184
- expect(pkg.license).toBe('MIT');
185
- expect(pkg.publishConfig).toEqual({ access: 'public' });
186
- expect(pkg.repository).toEqual({
187
- type: 'git',
188
- url: 'git+https://github.com/smoothbricks/codebase.git',
189
- directory: 'packages/zigpub',
190
- });
191
- expect(pkg.nx?.tags).toEqual(['npm:public']);
192
-
193
- // Has wasm export
194
- expect(pkg.exports['./wasm']).toBe('./dist/zigpub.wasm');
195
- });
196
- });
197
-
198
127
  it('rejects existing package', async () => {
199
128
  const tree = setupTree();
200
129
  tree.write('packages/existing/package.json', '{}');
@@ -1,4 +1,4 @@
1
- // Scaffold a new workspace package. Invoked by `smoo g ts-lib|ts-zig <name>`.
1
+ // Scaffold a new TypeScript workspace package. Invoked by `smoo g ts-lib <name>`.
2
2
  // CLI wiring: packages/cli/src/generate/index.ts (variant registry)
3
3
  import { readJson, type Tree, writeJson } from 'nx/src/devkit-exports.js';
4
4
 
@@ -15,10 +15,6 @@ export default async function generator(tree: Tree, schema: CreatePackageGenerat
15
15
  }
16
16
 
17
17
  writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg);
18
-
19
- if (schema.variant === 'ts-zig') {
20
- writeZigFiles(tree, schema, projectRoot);
21
- }
22
18
  }
23
19
 
24
20
  function extractScope(name: string | undefined): string | null {
@@ -158,122 +154,6 @@ function buildPackageJson(
158
154
 
159
155
  return packageJson;
160
156
  }
161
-
162
- function writeZigFiles(tree: Tree, schema: CreatePackageGeneratorSchema, projectRoot: string): void {
163
- // Modify package.json for ts-zig variant
164
- const packageJson = readJson<Record<string, unknown>>(tree, `${projectRoot}/package.json`);
165
-
166
- // Add wasm export and remove development condition
167
- const exports = packageJson.exports;
168
- if (!isRecord(exports)) {
169
- // invariant throw: writeCommonFiles always emits an object-valued exports map.
170
- throw new Error('generated package.json exports must be an object');
171
- }
172
- exports['./wasm'] = `./dist/${schema.name}.wasm`;
173
- const dotExport = exports['.'];
174
- if (!isRecord(dotExport)) {
175
- // invariant throw: writeCommonFiles always emits an object-valued "." export.
176
- throw new Error('generated package.json "." export must be an object');
177
- }
178
- delete dotExport.development;
179
-
180
- // Add build scripts
181
- const scripts = packageJson.scripts;
182
- if (!isRecord(scripts)) {
183
- // invariant throw: writeCommonFiles always emits an object-valued scripts map.
184
- throw new Error('generated package.json scripts must be an object');
185
- }
186
- scripts['build:zig'] = `nx run ${schema.name}:zig-wasm`;
187
- scripts['build:ts'] = `nx run ${schema.name}:tsc-js`;
188
- scripts.build = 'bun run build:ts && bun run build:zig';
189
-
190
- // Change files for zig packages (no src published)
191
- packageJson.files = ['dist'];
192
-
193
- writeJson(tree, `${projectRoot}/package.json`, packageJson);
194
-
195
- // Modify tsconfig.lib.json for ts-zig
196
- const tsconfigLib = readJson<Record<string, unknown>>(tree, `${projectRoot}/tsconfig.lib.json`);
197
- const libCompilerOptions = tsconfigLib.compilerOptions;
198
- if (!isRecord(libCompilerOptions)) {
199
- // invariant throw: writeCommonFiles always emits compilerOptions for library builds.
200
- throw new Error('generated tsconfig.lib.json compilerOptions must be an object');
201
- }
202
- libCompilerOptions.lib = ['es2022', 'webworker'];
203
- libCompilerOptions.declaration = true;
204
- libCompilerOptions.sourceMap = true;
205
- libCompilerOptions.skipLibCheck = true;
206
- writeJson(tree, `${projectRoot}/tsconfig.lib.json`, tsconfigLib);
207
-
208
- // Modify tsconfig.test.json for ts-zig
209
- const tsconfigTest = readJson<Record<string, unknown>>(tree, `${projectRoot}/tsconfig.test.json`);
210
- const testCompilerOptions = tsconfigTest.compilerOptions;
211
- if (!isRecord(testCompilerOptions)) {
212
- // invariant throw: writeCommonFiles always emits compilerOptions for test builds.
213
- throw new Error('generated tsconfig.test.json compilerOptions must be an object');
214
- }
215
- testCompilerOptions.lib = ['es2022', 'webworker'];
216
- writeJson(tree, `${projectRoot}/tsconfig.test.json`, tsconfigTest);
217
-
218
- // Write build.zig
219
- tree.write(
220
- `${projectRoot}/build.zig`,
221
- `const std = @import("std");
222
-
223
- pub fn build(b: *std.Build) void {
224
- const optimize = b.standardOptimizeOption(.{});
225
-
226
- const wasm_step = b.step("wasm", "Build WASM artifact");
227
-
228
- const wasm_target = b.resolveTargetQuery(.{
229
- .cpu_arch = .wasm32,
230
- .os_tag = .freestanding,
231
- });
232
-
233
- const lib = b.addExecutable(.{
234
- .name = "${schema.name}",
235
- .root_source_file = b.path("src/${schema.name}.zig"),
236
- .target = wasm_target,
237
- .optimize = optimize,
238
- });
239
- lib.entry = .disabled;
240
- lib.rdynamic = true;
241
-
242
- const install = b.addInstallArtifact(lib, .{
243
- .dest_dir = .{ .override = .{ .custom = "../dist" } },
244
- });
245
- wasm_step.dependOn(&install.step);
246
- }
247
- `,
248
- );
249
-
250
- // Write build.zig.zon
251
- tree.write(
252
- `${projectRoot}/build.zig.zon`,
253
- `.{
254
- .name = .${schema.name},
255
- .version = "0.0.0",
256
- .minimum_zig_version = "0.14.0",
257
- .dependencies = .{},
258
- .paths = .{
259
- "build.zig",
260
- "build.zig.zon",
261
- "src",
262
- },
263
- }
264
- `,
265
- );
266
-
267
- // Write src/<name>.zig
268
- tree.write(
269
- `${projectRoot}/src/${schema.name}.zig`,
270
- `export fn add(a: i32, b: i32) i32 {
271
- return a + b;
272
- }
273
- `,
274
- );
275
- }
276
-
277
157
  function isRecord(value: unknown): value is Record<string, unknown> {
278
158
  return value !== null && typeof value === 'object' && !Array.isArray(value);
279
159
  }
@@ -1,5 +1,5 @@
1
1
  export interface CreatePackageGeneratorSchema {
2
2
  name: string;
3
- variant: 'ts-lib' | 'ts-zig';
3
+ variant: 'ts-lib';
4
4
  public?: boolean;
5
5
  }
@@ -11,7 +11,7 @@
11
11
  "variant": {
12
12
  "type": "string",
13
13
  "description": "Package variant to scaffold.",
14
- "enum": ["ts-lib", "ts-zig"],
14
+ "enum": ["ts-lib"],
15
15
  "default": "ts-lib"
16
16
  },
17
17
  "public": {