@smoothbricks/nx-plugin 0.4.16 → 0.4.18

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.
@@ -1,132 +1,81 @@
1
1
  import { describe, expect, it } from 'bun:test';
2
- import { existsSync } from 'node:fs';
3
- import { chmod, mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';
2
+ import { mkdir, mkdtemp, rm, stat, symlink, writeFile } from 'node:fs/promises';
3
+ import { createRequire } from 'node:module';
4
4
  import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
5
+ import { dirname, join } from 'node:path';
6
+ import typescriptEmitExecutor from './executor.js';
6
7
 
7
- import { type CompilerInvocation, runTypeScriptEmit } from './executor.js';
8
+ async function fixture(source: string) {
9
+ const root = await mkdtemp(join(tmpdir(), 'smoo-typescript-emit-'));
10
+ await mkdir(join(root, 'src'));
11
+ await mkdir(join(root, 'node_modules'));
12
+ await symlink(
13
+ dirname(createRequire(import.meta.url).resolve('typia/package.json')),
14
+ join(root, 'node_modules/typia'),
15
+ 'dir',
16
+ );
17
+ await writeFile(join(root, 'package.json'), JSON.stringify({ type: 'module', dependencies: { typia: '*' } }));
18
+ await writeFile(
19
+ join(root, 'tsconfig.lib.json'),
20
+ JSON.stringify({
21
+ compilerOptions: {
22
+ target: 'ES2022',
23
+ module: 'NodeNext',
24
+ rootDir: 'src',
25
+ outDir: 'dist',
26
+ declaration: true,
27
+ declarationMap: true,
28
+ emitDeclarationOnly: true,
29
+ types: [],
30
+ skipLibCheck: true,
31
+ },
32
+ include: ['src/**/*.ts'],
33
+ }),
34
+ );
35
+ await writeFile(join(root, 'src/index.ts'), source);
36
+ return root;
37
+ }
8
38
 
9
39
  describe('@smoothbricks/nx-plugin TypeScript emit executor', () => {
10
- it('runs transformed JavaScript and native declaration lanes with project references preserved', async () => {
11
- const root = await mkdtemp(join(tmpdir(), 'smoo-typescript-emit-'));
12
- const projectRoot = join(root, 'packages/example');
13
- await mkdir(projectRoot, { recursive: true });
14
- await writeFile(
15
- join(projectRoot, 'tsconfig.lib.json'),
16
- '{\n // Project references are intentionally not inherited through extends.\n "references": [{ "path": "../dependency/tsconfig.lib.json" }]\n}\n',
40
+ it('emits executable transformed validation and declarations from the same program', async () => {
41
+ const root = await fixture(
42
+ "#!/usr/bin/env node\nimport typia from 'typia';\nexport const validate = typia.createValidate<{ value: number }>();\n",
17
43
  );
18
-
19
- const invocations: CompilerInvocation[] = [];
20
- let overlayContents = '';
21
- let overlayPath = '';
22
- try {
23
- const result = await runTypeScriptEmit(
24
- { cwd: 'packages/example', tsConfig: 'tsconfig.lib.json' },
25
- { root },
26
- async (invocation) => {
27
- invocations.push(invocation);
28
- if (invocation.command === 'ttsc') {
29
- overlayPath = invocation.args[1] ?? '';
30
- overlayContents = await readFile(overlayPath, 'utf8');
31
- }
32
- return true;
33
- },
34
- );
35
-
36
- expect(result).toEqual({ success: true });
37
- expect(invocations).toHaveLength(2);
38
- expect(invocations[0]).toEqual({
39
- command: 'ttsc',
40
- args: ['-p', overlayPath, '--emit'],
41
- cwd: projectRoot,
42
- });
43
- expect(overlayPath).toMatch(/\/\.ttsc-js-\d+-[0-9a-f-]+\.json$/);
44
- expect(overlayContents).toBe(
45
- `${JSON.stringify(
46
- {
47
- extends: './tsconfig.lib.json',
48
- compilerOptions: {
49
- composite: false,
50
- declaration: false,
51
- declarationMap: false,
52
- emitDeclarationOnly: false,
53
- incremental: false,
54
- },
55
- references: [{ path: '../dependency/tsconfig.lib.json' }],
56
- },
57
- null,
58
- 2,
59
- )}\n`,
60
- );
61
- expect(invocations[1]).toEqual({
62
- command: 'tsc',
63
- args: ['-p', overlayPath, '--emitDeclarationOnly', '--declaration', '--declarationMap'],
64
- cwd: projectRoot,
65
- });
66
- expect(existsSync(overlayPath)).toBe(false);
67
- } finally {
68
- await rm(root, { recursive: true, force: true });
69
- }
70
- });
71
-
72
- it('makes emitted package bins executable before declaration emit', async () => {
73
- const root = await mkdtemp(join(tmpdir(), 'smoo-typescript-emit-bin-'));
74
- const projectRoot = join(root, 'packages/example');
75
- const emittedBin = join(projectRoot, 'dist/bin/example.js');
76
- await mkdir(projectRoot, { recursive: true });
77
- await writeFile(join(projectRoot, 'tsconfig.lib.json'), '{}\n');
78
-
79
- let executableBeforeDeclarations = false;
80
44
  try {
81
- const result = await runTypeScriptEmit(
82
- {
83
- cwd: 'packages/example',
84
- executableOutputs: ['./dist/bin/example.js'],
85
- tsConfig: 'tsconfig.lib.json',
86
- },
87
- { root },
88
- async (invocation) => {
89
- if (invocation.command === 'ttsc') {
90
- await mkdir(join(projectRoot, 'dist/bin'), { recursive: true });
91
- await writeFile(emittedBin, '#!/usr/bin/env node\n');
92
- await chmod(emittedBin, 0o644);
93
- } else {
94
- executableBeforeDeclarations = ((await stat(emittedBin)).mode & 0o111) === 0o111;
95
- }
96
- return true;
97
- },
45
+ expect(
46
+ await typescriptEmitExecutor(
47
+ { cwd: root, tsConfig: 'tsconfig.lib.json', executableOutputs: ['dist/index.js'] },
48
+ { root },
49
+ ),
50
+ ).toEqual({ success: true });
51
+ expect((await stat(join(root, 'dist/index.js'))).mode & 0o111).toBe(0o111);
52
+ expect((await stat(join(root, 'dist/index.d.ts'))).isFile()).toBe(true);
53
+ const child = Bun.spawn(
54
+ [
55
+ 'bun',
56
+ '-e',
57
+ "import { validate } from './dist/index.js'; process.stdout.write(JSON.stringify([validate({value: 7}).success, validate({value: 'bad'}).success]))",
58
+ ],
59
+ { cwd: root, stdout: 'pipe', stderr: 'pipe' },
98
60
  );
99
-
100
- expect(result).toEqual({ success: true });
101
- expect(executableBeforeDeclarations).toBe(true);
102
- expect((await stat(emittedBin)).mode & 0o111).toBe(0o111);
61
+ const [text, errors, exit] = await Promise.all([
62
+ new Response(child.stdout).text(),
63
+ new Response(child.stderr).text(),
64
+ child.exited,
65
+ ]);
66
+ expect(exit, errors).toBe(0);
67
+ expect(text).toBe('[true,false]');
103
68
  } finally {
104
69
  await rm(root, { recursive: true, force: true });
105
70
  }
106
71
  });
107
72
 
108
- it('does not emit declarations when transformed JavaScript fails and still removes its overlay', async () => {
109
- const root = await mkdtemp(join(tmpdir(), 'smoo-typescript-emit-'));
110
- const projectRoot = join(root, 'packages/example');
111
- await mkdir(projectRoot, { recursive: true });
112
- await writeFile(join(projectRoot, 'tsconfig.lib.json'), '{}\n');
113
-
114
- const invocations: CompilerInvocation[] = [];
115
- let overlayPath = '';
73
+ it('reports real type errors instead of claiming a successful build', async () => {
74
+ const root = await fixture("export const amount: number = 'not a number';\n");
116
75
  try {
117
- const result = await runTypeScriptEmit(
118
- { cwd: projectRoot, tsConfig: 'tsconfig.lib.json' },
119
- { root },
120
- async (invocation) => {
121
- invocations.push(invocation);
122
- overlayPath = invocation.args[1] ?? '';
123
- return false;
124
- },
125
- );
126
-
127
- expect(result).toEqual({ success: false });
128
- expect(invocations.map(({ command }) => command)).toEqual(['ttsc']);
129
- expect(existsSync(overlayPath)).toBe(false);
76
+ expect(await typescriptEmitExecutor({ cwd: root, tsConfig: 'tsconfig.lib.json' }, { root })).toEqual({
77
+ success: false,
78
+ });
130
79
  } finally {
131
80
  await rm(root, { recursive: true, force: true });
132
81
  }
@@ -21,7 +21,7 @@ interface TsConfigJson {
21
21
  }
22
22
 
23
23
  export interface CompilerInvocation {
24
- command: 'tsc' | 'ttsc';
24
+ command: 'ttsc';
25
25
  args: string[];
26
26
  cwd: string;
27
27
  }
@@ -48,8 +48,8 @@ export async function runTypeScriptEmit(
48
48
  extends: `./${basename(tsConfigPath)}`,
49
49
  compilerOptions: {
50
50
  composite: false,
51
- declaration: false,
52
- declarationMap: false,
51
+ declaration: true,
52
+ declarationMap: true,
53
53
  emitDeclarationOnly: false,
54
54
  incremental: false,
55
55
  },
@@ -69,12 +69,7 @@ export async function runTypeScriptEmit(
69
69
 
70
70
  await makePackageBinsExecutable(cwd, options.executableOutputs ?? []);
71
71
 
72
- const declarationsSucceeded = await runner({
73
- command: 'tsc',
74
- args: ['-p', overlayPath, '--emitDeclarationOnly', '--declaration', '--declarationMap'],
75
- cwd,
76
- });
77
- return { success: declarationsSucceeded };
72
+ return { success: true };
78
73
  } finally {
79
74
  await rm(overlayPath, { force: true });
80
75
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/schema",
3
3
  "version": 2,
4
4
  "title": "TypeScript emit executor",
5
- "description": "Emit transformer-generated JavaScript with ttsc and declarations with native tsc",
5
+ "description": "Emit transformed JavaScript and declarations together with ttsc",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "executableOutputs": {
package/src/index.test.ts CHANGED
@@ -168,7 +168,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
168
168
  }
169
169
  });
170
170
 
171
- it('splits transformed JavaScript emit from native declarations and typechecking', async () => {
171
+ it('uses the transformer-aware compiler for emit and validation', async () => {
172
172
  const workspace = await createWorkspace();
173
173
  try {
174
174
  await workspace.write(
@@ -202,7 +202,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
202
202
  ]);
203
203
  expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
204
204
  expect(targets.typecheck?.options).toMatchObject({
205
- command: 'tsc -p tsconfig.lib.json --noEmit',
205
+ command: 'ttsc -p tsconfig.lib.json --noEmit',
206
206
  cwd: 'packages/example',
207
207
  });
208
208
  const checkToolchainInputs = [
@@ -233,7 +233,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
233
233
  expect(targets['typecheck-tests']?.cache).toBe(true);
234
234
  expect(targets['typecheck-tests']?.dependsOn).toEqual(['tsc-js', 'typecheck']);
235
235
  expect(targets['typecheck-tests']?.options).toMatchObject({
236
- command: 'tsc -p tsconfig.test.json --noEmit',
236
+ command: 'ttsc -p tsconfig.test.json --noEmit',
237
237
  cwd: 'packages/example',
238
238
  });
239
239
  expect(targets['typecheck-tests']?.inputs).toEqual([
@@ -246,7 +246,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
246
246
  expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
247
247
  expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
248
248
  expect(targets['typecheck-tests:watch']?.options).toMatchObject({
249
- command: 'tsc -p tsconfig.test.json --noEmit --watch',
249
+ command: 'ttsc -p tsconfig.test.json --noEmit --watch',
250
250
  cwd: 'packages/example',
251
251
  });
252
252
 
package/src/index.ts CHANGED
@@ -1051,10 +1051,7 @@ async function createProjectTargets(
1051
1051
  // Build every JavaScript output lane before resolving package exports, without pulling
1052
1052
  // unrelated Wasm, N-API, native, or web outputs onto the compiler critical path.
1053
1053
  //
1054
- // ttsc transforms the source program before declaration emit, so typia's
1055
- // generated implementation identifiers are not valid declaration inputs.
1056
- // The executor gives ttsc a JS-only overlay and emits declarations from the
1057
- // original project with native tsc.
1054
+ // One transformer-aware compiler emits JavaScript and declarations.
1058
1055
  targets['tsc-js'] = {
1059
1056
  executor: '@smoothbricks/nx-plugin:typescript-emit',
1060
1057
  cache: true,
@@ -1074,7 +1071,7 @@ async function createProjectTargets(
1074
1071
  outputs: [],
1075
1072
  dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
1076
1073
  options: {
1077
- command: 'tsc -p tsconfig.lib.json --noEmit',
1074
+ command: 'ttsc -p tsconfig.lib.json --noEmit',
1078
1075
  cwd: projectRoot,
1079
1076
  },
1080
1077
  };
@@ -1087,7 +1084,7 @@ async function createProjectTargets(
1087
1084
  inputs: [selfDefault, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.test.json'],
1088
1085
  dependsOn: ['typecheck'],
1089
1086
  options: {
1090
- command: 'tsc -p tsconfig.test.json --noEmit',
1087
+ command: 'ttsc -p tsconfig.test.json --noEmit',
1091
1088
  cwd: projectRoot,
1092
1089
  },
1093
1090
  };
@@ -1095,7 +1092,7 @@ async function createProjectTargets(
1095
1092
  executor: 'nx:run-commands',
1096
1093
  continuous: true,
1097
1094
  options: {
1098
- command: 'tsc -p tsconfig.test.json --noEmit --watch',
1095
+ command: 'ttsc -p tsconfig.test.json --noEmit --watch',
1099
1096
  cwd: projectRoot,
1100
1097
  },
1101
1098
  };
@@ -1382,11 +1379,15 @@ async function createProjectTargets(
1382
1379
  }
1383
1380
  }
1384
1381
 
1385
- if ('test' in declaredTargets && targets.test === undefined) {
1382
+ if (('test' in declaredTargets || typeof packageJson.scripts?.test === 'string') && targets.test === undefined) {
1386
1383
  targets.test = {
1387
1384
  dependsOn: ['^build', 'build'],
1388
1385
  };
1389
1386
  }
1387
+ for (const name of Object.keys(declaredTargets)) {
1388
+ if (name === 'test' || !isTestRunnerTargetName(name) || targets[name] !== undefined) continue;
1389
+ targets[name] = { dependsOn: ['^build', 'build'] };
1390
+ }
1390
1391
 
1391
1392
  // Every `cargoFrozen` command needs a registry cache holding the whole locked
1392
1393
  // graph, and offline cargo checks that at RESOLUTION — so a dev-dependency no
@@ -67,7 +67,19 @@ export interface ManagedFileContext {
67
67
  crossTestArchives: CiCrossTestArchive[];
68
68
  }
69
69
 
70
+ /** Temporary upstream compiler repairs distributed to smoo-managed Bun workspaces. */
71
+ export const managedTtscPatch = {
72
+ version: '0.30.4',
73
+ key: 'ttsc@0.30.4',
74
+ path: 'patches/ttsc@0.30.4.patch',
75
+ } as const;
76
+
70
77
  const managedFiles: ManagedFileDescriptor[] = [
78
+ {
79
+ kind: 'raw',
80
+ source: managedTtscPatch.path,
81
+ target: managedTtscPatch.path,
82
+ },
71
83
  {
72
84
  kind: 'raw',
73
85
  source: 'envrc',
@@ -0,0 +1,60 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ const action = readFileSync(
5
+ new URL('../../managed/templates/github/actions/setup-devenv/action.yml', import.meta.url),
6
+ 'utf8',
7
+ );
8
+ const assignments = action.split('\n').filter((line) => line.trimStart().startsWith('scope=$('));
9
+
10
+ function scope(overrides: Record<string, string> = {}): string {
11
+ const assignment = assignments[0];
12
+ if (!assignment) throw new Error('The setup action must scope its mutable host caches');
13
+ const result = Bun.spawnSync(['bash', '-ceu', `${assignment}\nprintf '%s' "$scope"`], {
14
+ env: {
15
+ ...process.env,
16
+ GITHUB_WORKFLOW: 'CI',
17
+ GITHUB_REF: 'refs/pull/10/merge',
18
+ GITHUB_JOB: 'main',
19
+ RUNNER_OS: 'Linux',
20
+ RUNNER_ARCH: 'X64',
21
+ ...overrides,
22
+ },
23
+ });
24
+ expect(result.exitCode).toBe(0);
25
+ return result.stdout.toString();
26
+ }
27
+
28
+ describe('host CI mutable cache isolation', () => {
29
+ test('Nx and devenv use the same exact workflow/ref/job/platform identity', () => {
30
+ expect(assignments).toHaveLength(2);
31
+ expect(assignments[0]).toBe(assignments[1]);
32
+ expect(action).toContain('/${lane:-default}/$scope');
33
+ expect(action).toContain('/${lane:-default}/$DEVENV_STATE_JOB/$scope');
34
+ expect(action).toContain('NX_CACHE_DIRECTORY=$NX_CACHE_ROOT/cache');
35
+ expect(action).toContain('NX_WORKSPACE_DATA_DIRECTORY=$NX_CACHE_ROOT/workspace-data');
36
+ });
37
+
38
+ test('repeat runs stay warm but distinct PRs, jobs and platforms cannot share graph state', () => {
39
+ const original = scope();
40
+ expect(original).toMatch(/^[a-f0-9]{40}$/);
41
+ expect(scope({ GITHUB_RUN_ID: 'another-run', GITHUB_RUN_ATTEMPT: '2' })).toBe(original);
42
+ const identities: Record<string, string>[] = [
43
+ { GITHUB_WORKFLOW: 'Publish' },
44
+ { GITHUB_REF: 'refs/pull/11/merge' },
45
+ { GITHUB_REF: 'refs/heads/main' },
46
+ { GITHUB_JOB: 'e2e-deployment' },
47
+ { RUNNER_OS: 'macOS' },
48
+ { RUNNER_ARCH: 'ARM64' },
49
+ ];
50
+ for (const other of identities) {
51
+ expect(scope(other)).not.toBe(original);
52
+ }
53
+ });
54
+
55
+ test('similar-looking refs do not collide or become filesystem paths', () => {
56
+ expect(scope({ GITHUB_REF: 'refs/heads/feature/a' })).not.toBe(scope({ GITHUB_REF: 'refs/heads/feature-a' }));
57
+ expect(scope({ GITHUB_REF: 'refs/heads/Feature' })).not.toBe(scope({ GITHUB_REF: 'refs/heads/feature' }));
58
+ expect(scope({ GITHUB_REF: 'refs/heads/../../other' })).toMatch(/^[a-f0-9]{40}$/);
59
+ });
60
+ });