@smoothbricks/nx-plugin 0.3.4 → 0.3.6

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 (32) hide show
  1. package/README.md +40 -8
  2. package/dist/bounded-test-policy.d.ts +4 -2
  3. package/dist/bounded-test-policy.d.ts.map +1 -1
  4. package/dist/bounded-test-policy.js +93 -15
  5. package/dist/executors/typescript-emit/executor.d.ts +17 -0
  6. package/dist/executors/typescript-emit/executor.d.ts.map +1 -0
  7. package/dist/executors/typescript-emit/executor.js +61 -0
  8. package/dist/executors/typescript-emit/schema.d.ts +5 -0
  9. package/dist/executors/typescript-emit/schema.d.ts.map +1 -0
  10. package/dist/executors/typescript-emit/schema.js +1 -0
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +280 -29
  14. package/dist/package-target-policy.d.ts +2 -0
  15. package/dist/package-target-policy.d.ts.map +1 -1
  16. package/dist/package-target-policy.js +5 -1
  17. package/dist/workspace-config-policy.d.ts.map +1 -1
  18. package/dist/workspace-config-policy.js +11 -3
  19. package/executors.json +5 -0
  20. package/package.json +4 -3
  21. package/src/bounded-test-policy.test.ts +102 -2
  22. package/src/bounded-test-policy.ts +110 -17
  23. package/src/executors/typescript-emit/executor.test.ts +98 -0
  24. package/src/executors/typescript-emit/executor.ts +94 -0
  25. package/src/executors/typescript-emit/schema.json +19 -0
  26. package/src/executors/typescript-emit/schema.ts +4 -0
  27. package/src/index.test.ts +158 -17
  28. package/src/index.ts +358 -31
  29. package/src/package-target-policy.test.ts +17 -0
  30. package/src/package-target-policy.ts +5 -1
  31. package/src/workspace-config-policy.test.ts +41 -1
  32. package/src/workspace-config-policy.ts +12 -3
package/src/index.test.ts CHANGED
@@ -58,7 +58,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
58
58
  }
59
59
  });
60
60
 
61
- it('overrides inferred TypeScript compiler commands with ttsc', async () => {
61
+ it('splits transformed JavaScript emit from native declarations and typechecking', async () => {
62
62
  const workspace = await createWorkspace();
63
63
  try {
64
64
  await workspace.write(
@@ -70,8 +70,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
70
70
 
71
71
  const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
72
72
 
73
- expect(targets['tsc-js']?.options).toMatchObject({
74
- command: 'ttsc -p tsconfig.lib.json --emit',
73
+ expect(targets['tsc-js']?.executor).toBe('@smoothbricks/nx-plugin:typescript-emit');
74
+ expect(targets['tsc-js']?.options).toEqual({
75
+ tsConfig: 'tsconfig.lib.json',
75
76
  cwd: 'packages/example',
76
77
  });
77
78
  const toolchainInputs = [
@@ -86,9 +87,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
86
87
  ...toolchainInputs,
87
88
  '{projectRoot}/tsconfig.lib.json',
88
89
  ]);
89
- expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
90
+ expect(targets['tsc-js']?.outputs).toEqual([
91
+ '{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}',
92
+ '{projectRoot}/dist/**/*.tsbuildinfo',
93
+ ]);
90
94
  expect(targets.typecheck?.options).toMatchObject({
91
- command: 'ttsc -p tsconfig.lib.json --noEmit',
95
+ command: 'tsc -p tsconfig.lib.json --noEmit',
92
96
  cwd: 'packages/example',
93
97
  });
94
98
  expect(targets.typecheck?.inputs).toEqual([
@@ -105,9 +109,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
105
109
 
106
110
  expect(targets['typecheck-tests']?.executor).toBe('nx:run-commands');
107
111
  expect(targets['typecheck-tests']?.cache).toBe(true);
108
- expect(targets['typecheck-tests']?.dependsOn).toEqual(['typecheck']);
112
+ expect(targets['typecheck-tests']?.dependsOn).toEqual(['tsc-js', 'typecheck']);
109
113
  expect(targets['typecheck-tests']?.options).toMatchObject({
110
- command: 'ttsc -p tsconfig.test.json --noEmit',
114
+ command: 'tsc -p tsconfig.test.json --noEmit',
111
115
  cwd: 'packages/example',
112
116
  });
113
117
  expect(targets['typecheck-tests']?.inputs).toEqual([
@@ -120,7 +124,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
120
124
  expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
121
125
  expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
122
126
  expect(targets['typecheck-tests:watch']?.options).toMatchObject({
123
- command: 'ttsc -p tsconfig.test.json --noEmit --watch',
127
+ command: 'tsc -p tsconfig.test.json --noEmit --watch',
124
128
  cwd: 'packages/example',
125
129
  });
126
130
 
@@ -140,6 +144,22 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
140
144
  }
141
145
  });
142
146
 
147
+ it('rebuilds current library declarations before test typechecking after clean', async () => {
148
+ const workspace = await createWorkspace();
149
+ try {
150
+ await workspace.write('packages/example/package.json', '{"name":"example"}\n');
151
+ await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
152
+ await workspace.write('packages/example/tsconfig.test.json', '{}\n');
153
+
154
+ const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
155
+
156
+ expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
157
+ expect(targets['typecheck-tests']?.dependsOn).toEqual(['tsc-js', 'typecheck']);
158
+ } finally {
159
+ await workspace.cleanup();
160
+ }
161
+ });
162
+
143
163
  it('infers vitest watch targets from explicit test commands', async () => {
144
164
  const workspace = await createWorkspace();
145
165
  try {
@@ -234,13 +254,14 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
234
254
  expect(targets['cargo-test']?.options).toMatchObject({
235
255
  command: 'cargo test --workspace',
236
256
  cwd: 'packages/ferris',
257
+ timeoutMs: 1_200_000,
237
258
  });
238
259
  expect(targets['cargo-test']?.inputs).toEqual([
239
260
  '{projectRoot}/**/*.rs',
240
261
  '{projectRoot}/**/Cargo.toml',
241
- '{projectRoot}/Cargo.lock',
242
- '{projectRoot}/.cargo/config.toml',
243
- '!{projectRoot}/target/**',
262
+ '{projectRoot}/**/Cargo.lock',
263
+ '{projectRoot}/**/.cargo/config.toml',
264
+ '!{projectRoot}/**/target/**',
244
265
  ]);
245
266
  expect(targets['cargo-lint']?.options).toMatchObject({
246
267
  commands: ['cargo fmt --all --check', 'cargo clippy --workspace --all-targets -- -D warnings'],
@@ -259,22 +280,142 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
259
280
  }
260
281
  });
261
282
 
262
- it('does not infer wasm targets for native N-API cdylib crates', async () => {
283
+ it('infers a cached Cargo Wasm build directly from crate metadata', async () => {
284
+ const workspace = await createWorkspace();
285
+ try {
286
+ await workspace.write('packages/git-do/package.json', '{"name":"git-do"}\n');
287
+ await workspace.write(
288
+ 'packages/git-do/crates/git-do/Cargo.toml',
289
+ [
290
+ '[package]',
291
+ 'name = "git-do"',
292
+ '',
293
+ '[lib]',
294
+ 'name = "gitoxide_engine"',
295
+ 'crate-type = ["cdylib", "rlib"]',
296
+ '',
297
+ '[package.metadata.smoothbricks.wasm-bindgen]',
298
+ 'targets = ["nodejs", "web"]',
299
+ 'out-dir = "generated/wasm"',
300
+ '',
301
+ ].join('\n'),
302
+ );
303
+ await workspace.write('packages/git-do/tsconfig.lib.json', '{"compilerOptions":{"outDir":"dist"}}\n');
304
+
305
+ const targets = await inferProjectTargets(workspace, 'packages/git-do/package.json');
306
+
307
+ expect(targets['cargo-wasm']).toMatchObject({
308
+ executor: 'nx:run-commands',
309
+ cache: true,
310
+ dependsOn: ['^build'],
311
+ inputs: [
312
+ '{projectRoot}/**/*.rs',
313
+ '{projectRoot}/**/Cargo.toml',
314
+ '{projectRoot}/**/Cargo.lock',
315
+ '{projectRoot}/**/.cargo/config.toml',
316
+ '!{projectRoot}/**/target/**',
317
+ '{projectRoot}/package.json',
318
+ '{workspaceRoot}/bun.lock',
319
+ ],
320
+ outputs: ['{projectRoot}/generated/wasm'],
321
+ options: {
322
+ commands: [
323
+ 'cargo build --release --target wasm32-unknown-unknown --target-dir crates/git-do/target/cargo-wasm --manifest-path crates/git-do/Cargo.toml',
324
+ 'wasm-bindgen --target nodejs --out-dir generated/wasm/node crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
325
+ 'wasm-bindgen --target web --out-dir generated/wasm/web crates/git-do/target/cargo-wasm/wasm32-unknown-unknown/release/gitoxide_engine.wasm',
326
+ ],
327
+ cwd: 'packages/git-do',
328
+ parallel: false,
329
+ },
330
+ });
331
+ expect(targets['tsc-js']?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
332
+ expect(targets.typecheck?.dependsOn).toEqual(['^*-js', 'cargo-wasm']);
333
+ expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
334
+ expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
335
+ // A nested crate manifest is enough for output inference, but not for
336
+ // workspace-wide cargo-test/lint policy.
337
+ expect(targets['cargo-test']).toBeUndefined();
338
+ expect(targets['cargo-lint']).toBeUndefined();
339
+ } finally {
340
+ await workspace.cleanup();
341
+ }
342
+ });
343
+
344
+ it('infers disjoint host and release targets from canonical N-API metadata', async () => {
263
345
  const workspace = await createWorkspace();
264
346
  try {
265
- await workspace.write('packages/cowshed/package.json', '{"name":"cowshed"}\n');
347
+ await workspace.write(
348
+ 'packages/cowshed/package.json',
349
+ JSON.stringify({
350
+ name: 'cowshed',
351
+ scripts: { test: 'nx run cowshed:test --outputStyle=stream' },
352
+ napi: {
353
+ binaryName: 'cowshed',
354
+ targets: [
355
+ 'aarch64-apple-darwin',
356
+ 'x86_64-apple-darwin',
357
+ 'aarch64-unknown-linux-gnu',
358
+ 'x86_64-unknown-linux-gnu',
359
+ ],
360
+ },
361
+ }),
362
+ );
266
363
  await workspace.write('packages/cowshed/Cargo.toml', '[workspace]\nmembers = ["crates/cowshed-napi"]\n');
267
364
  await workspace.write(
268
365
  'packages/cowshed/crates/cowshed-napi/Cargo.toml',
269
366
  '[package]\nname = "cowshed-napi"\n\n[lib]\ncrate-type = ["cdylib"]\n',
270
367
  );
368
+ await workspace.write(
369
+ 'packages/cowshed/tsconfig.lib.json',
370
+ '{"compilerOptions":{"outDir":"dist/ts","tsBuildInfoFile":"dist/ts/tsconfig.lib.tsbuildinfo"}}\n',
371
+ );
372
+ await workspace.write('packages/cowshed/src/native.test.ts', 'export {};\n');
271
373
 
272
374
  const targets = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
273
375
 
274
376
  expect(targets['cargo-wasm']).toBeUndefined();
275
- expect(targets.build).toBeUndefined();
276
- expect(targets.clean).toBeUndefined();
277
- expect(targets['cargo-test']).toBeDefined();
377
+ expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/ts']);
378
+ expect(targets['cargo-napi']).toMatchObject({
379
+ executor: 'nx:run-commands',
380
+ cache: true,
381
+ dependsOn: ['^build'],
382
+ outputs: ['{projectRoot}/dist/native/host'],
383
+ options: {
384
+ cwd: 'packages/cowshed',
385
+ command:
386
+ 'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/host',
387
+ },
388
+ });
389
+ expect(targets['napi-arm64-macos']?.outputs).toEqual(['{projectRoot}/dist/native/darwin-arm64']);
390
+ expect(targets['napi-arm64-macos']?.options).toMatchObject({
391
+ command:
392
+ 'napi build --release --platform --no-js --dts cowshed.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/darwin-arm64',
393
+ });
394
+ expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
395
+ expect(targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
396
+ expect(targets['napi-x64-linux']?.options).toMatchObject({
397
+ command:
398
+ 'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/linux-x64-gnu',
399
+ env: { TARGET_CC: 'clang', TARGET_CXX: 'clang++' },
400
+ });
401
+ expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
402
+ expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
403
+ expect(targets['napi-test']).toMatchObject({
404
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
405
+ cache: true,
406
+ dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
407
+ options: {
408
+ command: 'bun test --timeout=30000 src/native.test.ts',
409
+ cwd: 'packages/cowshed',
410
+ timeoutMs: 120000,
411
+ killAfterMs: 10000,
412
+ },
413
+ });
414
+ await workspace.write('packages/cowshed/bunfig.napi-test.toml', '[test]\n');
415
+ const targetsWithDedicatedBunfig = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
416
+ expect(targetsWithDedicatedBunfig['napi-test']?.options?.command).toBe(
417
+ 'bun --config=bunfig.napi-test.toml test --timeout=30000 src/native.test.ts',
418
+ );
278
419
  } finally {
279
420
  await workspace.cleanup();
280
421
  }
@@ -300,7 +441,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
300
441
  );
301
442
  await workspace.write(
302
443
  'packages/columine/crates/columine-wasm/Cargo.toml',
303
- '[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n',
444
+ '[package]\nname = "columine-wasm"\n\n[lib]\ncrate-type = ["cdylib", "rlib"]\n\n[package.metadata.smoothbricks.wasm-bindgen]\ntargets = ["web"]\n',
304
445
  );
305
446
 
306
447
  const targets = await inferProjectTargets(workspace, 'packages/columine/package.json');