@smoothbricks/nx-plugin 0.0.0-bootstrap.0 → 0.2.0

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 (78) hide show
  1. package/README.md +93 -2
  2. package/dist/bounded-test-policy.d.ts +32 -0
  3. package/dist/bounded-test-policy.d.ts.map +1 -0
  4. package/dist/bounded-test-policy.js +184 -0
  5. package/dist/executors/bounded-exec/executor.d.ts +15 -0
  6. package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
  7. package/dist/executors/bounded-exec/executor.js +179 -0
  8. package/dist/executors/bounded-exec/schema.d.ts +11 -0
  9. package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
  10. package/dist/executors/bounded-exec/schema.js +1 -0
  11. package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
  12. package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
  13. package/dist/generators/bounded-test-targets/generator.js +40 -0
  14. package/dist/generators/bun-test-tracing/generator.d.ts +10 -0
  15. package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -0
  16. package/dist/generators/bun-test-tracing/generator.js +247 -0
  17. package/dist/generators/create-package/generator.d.ts +4 -0
  18. package/dist/generators/create-package/generator.d.ts.map +1 -0
  19. package/dist/generators/create-package/generator.js +204 -0
  20. package/dist/generators/make-public/generator.d.ts +4 -0
  21. package/dist/generators/make-public/generator.d.ts.map +1 -0
  22. package/dist/generators/make-public/generator.js +55 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +197 -0
  26. package/dist/package-target-policy.d.ts +31 -0
  27. package/dist/package-target-policy.d.ts.map +1 -0
  28. package/dist/package-target-policy.js +930 -0
  29. package/dist/release-config-policy.d.ts +32 -0
  30. package/dist/release-config-policy.d.ts.map +1 -0
  31. package/dist/release-config-policy.js +225 -0
  32. package/dist/typecheck-test-policy.d.ts +56 -0
  33. package/dist/typecheck-test-policy.d.ts.map +1 -0
  34. package/dist/typecheck-test-policy.js +640 -0
  35. package/dist/version-actions.cjs +78 -0
  36. package/dist/version-actions.d.cts +6 -0
  37. package/dist/version-actions.d.cts.map +1 -0
  38. package/dist/workspace-config-policy.d.ts +33 -0
  39. package/dist/workspace-config-policy.d.ts.map +1 -0
  40. package/dist/workspace-config-policy.js +334 -0
  41. package/executors.json +9 -0
  42. package/generators.json +24 -0
  43. package/loader.js +16 -0
  44. package/package.json +89 -4
  45. package/src/bounded-test-policy.test.ts +257 -0
  46. package/src/bounded-test-policy.ts +257 -0
  47. package/src/bun-bootstrap.test.ts +52 -0
  48. package/src/executors/bounded-exec/executor.test.ts +258 -0
  49. package/src/executors/bounded-exec/executor.ts +228 -0
  50. package/src/executors/bounded-exec/schema.json +68 -0
  51. package/src/executors/bounded-exec/schema.ts +10 -0
  52. package/src/generators/bounded-test-targets/generator.test.ts +136 -0
  53. package/src/generators/bounded-test-targets/generator.ts +67 -0
  54. package/src/generators/bounded-test-targets/schema.d.ts +3 -0
  55. package/src/generators/bounded-test-targets/schema.json +14 -0
  56. package/src/generators/bun-test-tracing/generator.test.ts +243 -0
  57. package/src/generators/bun-test-tracing/generator.ts +348 -0
  58. package/src/generators/bun-test-tracing/schema.d.ts +8 -0
  59. package/src/generators/bun-test-tracing/schema.json +28 -0
  60. package/src/generators/create-package/generator.test.ts +206 -0
  61. package/src/generators/create-package/generator.ts +251 -0
  62. package/src/generators/create-package/schema.d.ts +5 -0
  63. package/src/generators/create-package/schema.json +24 -0
  64. package/src/generators/make-public/generator.test.ts +137 -0
  65. package/src/generators/make-public/generator.ts +83 -0
  66. package/src/generators/make-public/schema.d.ts +3 -0
  67. package/src/generators/make-public/schema.json +13 -0
  68. package/src/index.test.ts +200 -0
  69. package/src/index.ts +242 -0
  70. package/src/package-target-policy.test.ts +778 -0
  71. package/src/package-target-policy.ts +1127 -0
  72. package/src/release-config-policy.test.ts +280 -0
  73. package/src/release-config-policy.ts +258 -0
  74. package/src/typecheck-test-policy.test.ts +797 -0
  75. package/src/typecheck-test-policy.ts +752 -0
  76. package/src/version-actions.cts +94 -0
  77. package/src/workspace-config-policy.test.ts +376 -0
  78. package/src/workspace-config-policy.ts +390 -0
@@ -0,0 +1,247 @@
1
+ import { posix as path } from 'node:path';
2
+ import { getProjects, joinPathFragments, normalizePath, readJson, updateJson, } from 'nx/src/devkit-exports.js';
3
+ import { applyBoundedTestTargetPolicy } from '../../bounded-test-policy.js';
4
+ const DEFAULT_TEST_INCLUDES = [
5
+ 'src/**/*.test.ts',
6
+ 'src/**/*.spec.ts',
7
+ 'src/**/__tests__/**/*.ts',
8
+ 'src/**/__tests__/**/*.tsx',
9
+ 'src/test-suite-tracer.ts',
10
+ ];
11
+ const COPIED_COMPILER_OPTIONS = ['baseUrl', 'module', 'moduleResolution', 'jsx', 'lib'];
12
+ const DEFAULT_BUN_TEST_TIMEOUT_MS = 30_000;
13
+ export default async function generator(tree, schema) {
14
+ const options = normalizeOptions(schema);
15
+ const resolved = resolveProject(tree, options.project);
16
+ const packageJsonPath = joinPathFragments(resolved.root, 'package.json');
17
+ const tsconfigPath = joinPathFragments(resolved.root, 'tsconfig.json');
18
+ const libTsconfigPath = joinPathFragments(resolved.root, 'tsconfig.lib.json');
19
+ if (!tree.exists(packageJsonPath)) {
20
+ throw new Error(`Project ${resolved.name} is missing ${packageJsonPath}`);
21
+ }
22
+ if (!tree.exists(tsconfigPath)) {
23
+ throw new Error(`Project ${resolved.name} is missing ${tsconfigPath}`);
24
+ }
25
+ if (!tree.exists(libTsconfigPath)) {
26
+ throw new Error(`Project ${resolved.name} is missing ${libTsconfigPath}`);
27
+ }
28
+ updatePackageJson(tree, packageJsonPath, resolved.name);
29
+ writeBunfig(tree, resolved.root);
30
+ tree.write(joinPathFragments(resolved.root, 'src/test-suite-tracer.ts'), renderSuiteTracer(options));
31
+ updateTsconfigTest(tree, resolved.root, packageJsonPath, tsconfigPath, libTsconfigPath);
32
+ }
33
+ function normalizeOptions(schema) {
34
+ return {
35
+ project: schema.project,
36
+ opContextModule: schema.opContextModule,
37
+ opContextExport: schema.opContextExport ?? 'opContext',
38
+ tracerModule: schema.tracerModule ?? '@smoothbricks/lmao/testing/bun',
39
+ };
40
+ }
41
+ function resolveProject(tree, projectInput) {
42
+ const normalizedInput = normalizeLookupValue(projectInput);
43
+ for (const [name, config] of getProjects(tree)) {
44
+ if (normalizeLookupValue(name) === normalizedInput || normalizeLookupValue(config.root) === normalizedInput) {
45
+ return { name, root: config.root };
46
+ }
47
+ const packageJsonPath = joinPathFragments(config.root, 'package.json');
48
+ if (!tree.exists(packageJsonPath)) {
49
+ continue;
50
+ }
51
+ const packageJson = readJson(tree, packageJsonPath);
52
+ if (packageJson.name && normalizeLookupValue(packageJson.name) === normalizedInput) {
53
+ return { name, root: config.root };
54
+ }
55
+ }
56
+ throw new Error(`Could not resolve project ${projectInput}`);
57
+ }
58
+ function normalizeLookupValue(value) {
59
+ return value.replace(/^\.\//, '').replace(/\\/g, '/');
60
+ }
61
+ function updatePackageJson(tree, packageJsonPath, projectName) {
62
+ updateJson(tree, packageJsonPath, (packageJson) => {
63
+ packageJson.nx ??= {};
64
+ packageJson.nx.targets ??= {};
65
+ packageJson.nx.targets.test ??= { dependsOn: ['typecheck-tests', '^build'] };
66
+ applyBoundedTestTargetPolicy(packageJson, { projectName });
67
+ packageJson.nx.targets.lint ??= {};
68
+ const hasLmaoDependency = Boolean(packageJson.dependencies?.['@smoothbricks/lmao'] || packageJson.devDependencies?.['@smoothbricks/lmao']);
69
+ if (!hasLmaoDependency) {
70
+ packageJson.devDependencies ??= {};
71
+ packageJson.devDependencies['@smoothbricks/lmao'] = 'workspace:*';
72
+ }
73
+ return packageJson;
74
+ });
75
+ }
76
+ function writeBunfig(tree, projectRoot) {
77
+ const bunfigPath = joinPathFragments(projectRoot, 'bunfig.toml');
78
+ const preloadEntries = '"@smoothbricks/lmao/bun/preload", "@smoothbricks/lmao/bun/trace-preload"';
79
+ if (!tree.exists(bunfigPath)) {
80
+ tree.write(bunfigPath, `[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\npreload = [${preloadEntries}]\n`);
81
+ return;
82
+ }
83
+ const current = tree.read(bunfigPath, 'utf-8') ?? '';
84
+ const next = ensureBunTestTimeout(current);
85
+ // Already has the package specifier preloads
86
+ if (next.includes('@smoothbricks/lmao/bun/preload')) {
87
+ if (next !== current) {
88
+ tree.write(bunfigPath, next);
89
+ }
90
+ return;
91
+ }
92
+ // Replace old patterns with the package specifier preloads
93
+ if (next.includes('preload = [')) {
94
+ tree.write(bunfigPath, next.replace(/preload\s*=\s*\[.*?\]/s, `preload = [${preloadEntries}]`));
95
+ return;
96
+ }
97
+ if (next.includes('[test]')) {
98
+ tree.write(bunfigPath, next.replace('[test]', `[test]\npreload = [${preloadEntries}]`));
99
+ return;
100
+ }
101
+ const suffix = next.endsWith('\n') ? '' : '\n';
102
+ tree.write(bunfigPath, `${next}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\npreload = [${preloadEntries}]\n`);
103
+ }
104
+ function ensureBunTestTimeout(current) {
105
+ if (/(^|\n)\s*timeout\s*=/.test(current)) {
106
+ return current;
107
+ }
108
+ if (current.includes('[test]')) {
109
+ return current.replace('[test]', `[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}`);
110
+ }
111
+ const suffix = current.endsWith('\n') ? '' : '\n';
112
+ return `${current}${suffix}[test]\ntimeout = ${DEFAULT_BUN_TEST_TIMEOUT_MS}\n`;
113
+ }
114
+ function renderSuiteTracer(options) {
115
+ return [
116
+ `import { ${options.opContextExport} } from '${options.opContextModule}';`,
117
+ `import { defineTestTracer } from '${options.tracerModule}';`,
118
+ '',
119
+ `export const { useTestSpan, opContext, extraTestColumns } = defineTestTracer(${options.opContextExport});`,
120
+ '',
121
+ ].join('\n');
122
+ }
123
+ function updateTsconfigTest(tree, projectRoot, packageJsonPath, tsconfigPath, libTsconfigPath) {
124
+ const tsconfigTestPath = joinPathFragments(projectRoot, 'tsconfig.test.json');
125
+ const packageJson = readJson(tree, packageJsonPath);
126
+ const projectTsconfig = readJson(tree, tsconfigPath);
127
+ const libTsconfig = readJson(tree, libTsconfigPath);
128
+ const extendsPath = chooseTsconfigTestExtends(projectTsconfig, libTsconfig);
129
+ const copiedCompilerOptions = getCopiedCompilerOptions(libTsconfig);
130
+ const referencePaths = collectReferencePaths(tree, projectRoot, packageJson);
131
+ if (!tree.exists(tsconfigTestPath)) {
132
+ const compilerOptions = {
133
+ ...copiedCompilerOptions,
134
+ types: mergeStringArray([], ['bun']),
135
+ composite: false,
136
+ declaration: false,
137
+ declarationMap: false,
138
+ emitDeclarationOnly: false,
139
+ noEmit: true,
140
+ };
141
+ const tsconfigTest = {
142
+ extends: extendsPath,
143
+ compilerOptions,
144
+ include: [...DEFAULT_TEST_INCLUDES],
145
+ references: referencePaths.map((refPath) => ({ path: refPath })),
146
+ };
147
+ tree.write(tsconfigTestPath, `${JSON.stringify(tsconfigTest, null, 2)}\n`);
148
+ return;
149
+ }
150
+ updateJson(tree, tsconfigTestPath, (tsconfigTest) => {
151
+ tsconfigTest.extends ??= extendsPath;
152
+ tsconfigTest.compilerOptions = {
153
+ ...copiedCompilerOptions,
154
+ ...tsconfigTest.compilerOptions,
155
+ types: mergeStringArray(readStringArray(tsconfigTest.compilerOptions?.types), ['bun']),
156
+ composite: false,
157
+ declaration: false,
158
+ declarationMap: false,
159
+ emitDeclarationOnly: false,
160
+ noEmit: true,
161
+ };
162
+ delete tsconfigTest.compilerOptions.outDir;
163
+ delete tsconfigTest.compilerOptions.tsBuildInfoFile;
164
+ tsconfigTest.include = mergeStringArray(tsconfigTest.include, DEFAULT_TEST_INCLUDES);
165
+ tsconfigTest.references = mergeReferences(tsconfigTest.references, referencePaths);
166
+ return tsconfigTest;
167
+ });
168
+ }
169
+ function chooseTsconfigTestExtends(projectTsconfig, libTsconfig) {
170
+ return isWrapperTsconfig(projectTsconfig) ? (libTsconfig.extends ?? '../../tsconfig.base.json') : './tsconfig.json';
171
+ }
172
+ function isWrapperTsconfig(tsconfig) {
173
+ const includeLength = Array.isArray(tsconfig.include) ? tsconfig.include.length : 0;
174
+ const filesLength = Array.isArray(tsconfig.files) ? tsconfig.files.length : 0;
175
+ const compilerOptionKeys = Object.keys(tsconfig.compilerOptions ?? {});
176
+ return includeLength === 0 && filesLength === 0 && compilerOptionKeys.length === 0;
177
+ }
178
+ function getCopiedCompilerOptions(libTsconfig) {
179
+ const result = {};
180
+ const compilerOptions = libTsconfig.compilerOptions ?? {};
181
+ for (const key of COPIED_COMPILER_OPTIONS) {
182
+ if (key in compilerOptions) {
183
+ result[key] = compilerOptions[key];
184
+ }
185
+ }
186
+ return result;
187
+ }
188
+ function collectReferencePaths(tree, projectRoot, packageJson) {
189
+ const referencePaths = ['./tsconfig.lib.json'];
190
+ const workspacePackages = buildWorkspacePackageMap(tree);
191
+ const dependencyNames = new Set([
192
+ ...Object.keys(packageJson.dependencies ?? {}),
193
+ ...Object.keys(packageJson.devDependencies ?? {}),
194
+ ]);
195
+ dependencyNames.add('@smoothbricks/lmao');
196
+ for (const dependencyName of dependencyNames) {
197
+ const dependencyProject = workspacePackages.get(dependencyName);
198
+ if (!dependencyProject) {
199
+ continue;
200
+ }
201
+ const dependencyTsconfig = joinPathFragments(dependencyProject.root, 'tsconfig.lib.json');
202
+ if (!tree.exists(dependencyTsconfig)) {
203
+ continue;
204
+ }
205
+ const relativePath = normalizePath(path.relative(projectRoot, dependencyTsconfig));
206
+ if (!referencePaths.includes(relativePath)) {
207
+ referencePaths.push(relativePath);
208
+ }
209
+ }
210
+ return referencePaths;
211
+ }
212
+ function buildWorkspacePackageMap(tree) {
213
+ const packageMap = new Map();
214
+ for (const [, config] of getProjects(tree)) {
215
+ const packageJsonPath = joinPathFragments(config.root, 'package.json');
216
+ if (!tree.exists(packageJsonPath)) {
217
+ continue;
218
+ }
219
+ const packageJson = readJson(tree, packageJsonPath);
220
+ if (packageJson.name) {
221
+ packageMap.set(packageJson.name, config);
222
+ }
223
+ }
224
+ return packageMap;
225
+ }
226
+ function mergeStringArray(a, b) {
227
+ const aArray = a ?? [];
228
+ const set = new Set([...aArray, ...b]);
229
+ return Array.from(set);
230
+ }
231
+ function readStringArray(value) {
232
+ if (Array.isArray(value)) {
233
+ return value.filter((item) => typeof item === 'string');
234
+ }
235
+ return [];
236
+ }
237
+ function mergeReferences(existing, newPaths) {
238
+ const existingPaths = existing ?? [];
239
+ const existingSet = new Set(existingPaths.map((ref) => ref.path));
240
+ const merged = [...existingPaths];
241
+ for (const path of newPaths) {
242
+ if (!existingSet.has(path)) {
243
+ merged.push({ path });
244
+ }
245
+ }
246
+ return merged;
247
+ }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from 'nx/src/devkit-exports.js';
2
+ import type { CreatePackageGeneratorSchema } from './schema.js';
3
+ export default function generator(tree: Tree, schema: CreatePackageGeneratorSchema): Promise<void>;
4
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAevG"}
@@ -0,0 +1,204 @@
1
+ // Scaffold a new workspace package. Invoked by `smoo g ts-lib|ts-zig <name>`.
2
+ // CLI wiring: packages/cli/src/generate/index.ts (variant registry)
3
+ import { readJson, writeJson } from 'nx/src/devkit-exports.js';
4
+ export default async function generator(tree, schema) {
5
+ const rootPkg = readJson(tree, 'package.json');
6
+ const scope = extractScope(rootPkg.name);
7
+ const packageName = scope ? `${scope}/${schema.name}` : schema.name;
8
+ const projectRoot = `packages/${schema.name}`;
9
+ if (tree.exists(`${projectRoot}/package.json`)) {
10
+ throw new Error(`Package already exists at ${projectRoot}`);
11
+ }
12
+ writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg);
13
+ if (schema.variant === 'ts-zig') {
14
+ writeZigFiles(tree, schema, projectRoot);
15
+ }
16
+ }
17
+ function extractScope(name) {
18
+ if (!name)
19
+ return null;
20
+ const match = /^(@[^/]+)\//.exec(name);
21
+ return match?.[1] ?? null;
22
+ }
23
+ function writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg) {
24
+ const packageJson = buildPackageJson(schema, packageName, projectRoot, rootPkg);
25
+ writeJson(tree, `${projectRoot}/package.json`, packageJson);
26
+ writeJson(tree, `${projectRoot}/tsconfig.json`, {
27
+ extends: '../../tsconfig.base.json',
28
+ files: [],
29
+ include: [],
30
+ references: [{ path: './tsconfig.lib.json' }],
31
+ });
32
+ writeJson(tree, `${projectRoot}/tsconfig.lib.json`, {
33
+ extends: '../../tsconfig.base.json',
34
+ compilerOptions: {
35
+ rootDir: 'src',
36
+ outDir: 'dist',
37
+ tsBuildInfoFile: 'dist/tsconfig.lib.tsbuildinfo',
38
+ emitDeclarationOnly: false,
39
+ forceConsistentCasingInFileNames: true,
40
+ types: [],
41
+ },
42
+ include: ['src/**/*.ts'],
43
+ exclude: ['src/**/*.test.ts', 'src/**/__tests__/**'],
44
+ });
45
+ writeJson(tree, `${projectRoot}/tsconfig.test.json`, {
46
+ extends: '../../tsconfig.base.json',
47
+ compilerOptions: {
48
+ types: ['bun'],
49
+ composite: false,
50
+ declaration: false,
51
+ declarationMap: false,
52
+ emitDeclarationOnly: false,
53
+ noEmit: true,
54
+ },
55
+ include: [
56
+ 'src/**/*.test.ts',
57
+ 'src/**/*.spec.ts',
58
+ 'src/**/__tests__/**/*.ts',
59
+ 'src/**/__tests__/**/*.tsx',
60
+ 'src/test-suite-tracer.ts',
61
+ ],
62
+ references: [{ path: './tsconfig.lib.json' }],
63
+ });
64
+ tree.write(`${projectRoot}/bunfig.toml`, '[test]\ntimeout = 30000\npreload = ["@smoothbricks/validation/bun/preload"]\n');
65
+ tree.write(`${projectRoot}/src/index.ts`, '');
66
+ }
67
+ function buildPackageJson(schema, packageName, projectRoot, rootPkg) {
68
+ const packageJson = {
69
+ name: packageName,
70
+ version: '0.0.0',
71
+ type: 'module',
72
+ sideEffects: false,
73
+ main: './dist/index.js',
74
+ module: './dist/index.js',
75
+ types: './dist/index.d.ts',
76
+ exports: {
77
+ './package.json': './package.json',
78
+ '.': {
79
+ types: './dist/index.d.ts',
80
+ development: './src/index.ts',
81
+ import: './dist/index.js',
82
+ default: './dist/index.js',
83
+ },
84
+ },
85
+ files: ['dist', 'src', '!**/*.tsbuildinfo'],
86
+ scripts: {
87
+ test: `nx run ${schema.name}:test --tui=false --outputStyle=stream`,
88
+ },
89
+ dependencies: {
90
+ tslib: '^2.8.1',
91
+ },
92
+ devDependencies: {
93
+ '@smoothbricks/validation': 'workspace:*',
94
+ },
95
+ nx: {
96
+ name: schema.name,
97
+ targets: {
98
+ lint: {},
99
+ test: {
100
+ executor: '@smoothbricks/nx-plugin:bounded-exec',
101
+ options: {
102
+ command: 'bun test',
103
+ cwd: '{projectRoot}',
104
+ timeoutMs: 120000,
105
+ killAfterMs: 10000,
106
+ },
107
+ },
108
+ },
109
+ },
110
+ };
111
+ if (schema.public) {
112
+ packageJson.license = 'MIT';
113
+ packageJson.publishConfig = { access: 'public' };
114
+ const rootRepository = rootPkg.repository;
115
+ if (rootRepository && typeof rootRepository === 'object') {
116
+ packageJson.repository = {
117
+ type: rootRepository.type ?? 'git',
118
+ url: rootRepository.url,
119
+ directory: projectRoot,
120
+ };
121
+ }
122
+ packageJson.nx.tags = ['npm:public'];
123
+ }
124
+ else {
125
+ packageJson.private = true;
126
+ }
127
+ return packageJson;
128
+ }
129
+ function writeZigFiles(tree, schema, projectRoot) {
130
+ // Modify package.json for ts-zig variant
131
+ const packageJson = readJson(tree, `${projectRoot}/package.json`);
132
+ // Add wasm export and remove development condition
133
+ const exports = packageJson.exports;
134
+ exports['./wasm'] = `./dist/${schema.name}.wasm`;
135
+ const dotExport = exports['.'];
136
+ delete dotExport.development;
137
+ // Add build scripts
138
+ const scripts = packageJson.scripts;
139
+ scripts['build:zig'] = `nx run ${schema.name}:zig-wasm`;
140
+ scripts['build:ts'] = `nx run ${schema.name}:tsc-js`;
141
+ scripts.build = 'bun run build:ts && bun run build:zig';
142
+ // Change files for zig packages (no src published)
143
+ packageJson.files = ['dist'];
144
+ writeJson(tree, `${projectRoot}/package.json`, packageJson);
145
+ // Modify tsconfig.lib.json for ts-zig
146
+ const tsconfigLib = readJson(tree, `${projectRoot}/tsconfig.lib.json`);
147
+ const libCompilerOptions = tsconfigLib.compilerOptions;
148
+ libCompilerOptions.lib = ['es2022', 'webworker'];
149
+ libCompilerOptions.declaration = true;
150
+ libCompilerOptions.sourceMap = true;
151
+ libCompilerOptions.skipLibCheck = true;
152
+ writeJson(tree, `${projectRoot}/tsconfig.lib.json`, tsconfigLib);
153
+ // Modify tsconfig.test.json for ts-zig
154
+ const tsconfigTest = readJson(tree, `${projectRoot}/tsconfig.test.json`);
155
+ const testCompilerOptions = tsconfigTest.compilerOptions;
156
+ testCompilerOptions.lib = ['es2022', 'webworker'];
157
+ writeJson(tree, `${projectRoot}/tsconfig.test.json`, tsconfigTest);
158
+ // Write build.zig
159
+ tree.write(`${projectRoot}/build.zig`, `const std = @import("std");
160
+
161
+ pub fn build(b: *std.Build) void {
162
+ const optimize = b.standardOptimizeOption(.{});
163
+
164
+ const wasm_step = b.step("wasm", "Build WASM artifact");
165
+
166
+ const wasm_target = b.resolveTargetQuery(.{
167
+ .cpu_arch = .wasm32,
168
+ .os_tag = .freestanding,
169
+ });
170
+
171
+ const lib = b.addExecutable(.{
172
+ .name = "${schema.name}",
173
+ .root_source_file = b.path("src/${schema.name}.zig"),
174
+ .target = wasm_target,
175
+ .optimize = optimize,
176
+ });
177
+ lib.entry = .disabled;
178
+ lib.rdynamic = true;
179
+
180
+ const install = b.addInstallArtifact(lib, .{
181
+ .dest_dir = .{ .override = .{ .custom = "../dist" } },
182
+ });
183
+ wasm_step.dependOn(&install.step);
184
+ }
185
+ `);
186
+ // Write build.zig.zon
187
+ tree.write(`${projectRoot}/build.zig.zon`, `.{
188
+ .name = .${schema.name},
189
+ .version = "0.0.0",
190
+ .minimum_zig_version = "0.14.0",
191
+ .dependencies = .{},
192
+ .paths = .{
193
+ "build.zig",
194
+ "build.zig.zon",
195
+ "src",
196
+ },
197
+ }
198
+ `);
199
+ // Write src/<name>.zig
200
+ tree.write(`${projectRoot}/src/${schema.name}.zig`, `export fn add(a: i32, b: i32) i32 {
201
+ return a + b;
202
+ }
203
+ `);
204
+ }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from 'nx/src/devkit-exports.js';
2
+ import type { MakePublicGeneratorSchema } from './schema.js';
3
+ export default function generator(tree: Tree, schema: MakePublicGeneratorSchema): Promise<void>;
4
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/make-public/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,IAAI,EAEV,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2CpG"}
@@ -0,0 +1,55 @@
1
+ // Promote a private package to npm publication. Invoked by `smoo g make-public <name>`.
2
+ // CLI wiring: packages/cli/src/generate/index.ts (variant registry)
3
+ import { getProjects, joinPathFragments, normalizePath, readJson, updateJson, } from 'nx/src/devkit-exports.js';
4
+ export default async function generator(tree, schema) {
5
+ const resolved = resolveProject(tree, schema.project);
6
+ const packageJsonPath = joinPathFragments(resolved.root, 'package.json');
7
+ if (!tree.exists(packageJsonPath)) {
8
+ throw new Error(`Project ${resolved.name} is missing ${packageJsonPath}`);
9
+ }
10
+ const rootPkg = readJson(tree, 'package.json');
11
+ updateJson(tree, packageJsonPath, (pkg) => {
12
+ delete pkg.private;
13
+ if (!pkg.license && rootPkg.license) {
14
+ pkg.license = rootPkg.license;
15
+ }
16
+ pkg.publishConfig = { access: 'public' };
17
+ if (rootPkg.repository) {
18
+ pkg.repository = {
19
+ ...(typeof rootPkg.repository === 'object' ? rootPkg.repository : {}),
20
+ directory: resolved.root,
21
+ };
22
+ }
23
+ const nx = (pkg.nx ?? {});
24
+ const tags = Array.isArray(nx.tags) ? [...nx.tags] : [];
25
+ if (!tags.includes('npm:public')) {
26
+ tags.push('npm:public');
27
+ }
28
+ nx.tags = tags;
29
+ pkg.nx = nx;
30
+ if (pkg.version === '0.0.0') {
31
+ pkg.version = '0.1.0';
32
+ }
33
+ return pkg;
34
+ });
35
+ }
36
+ function resolveProject(tree, projectInput) {
37
+ const normalizedInput = normalizeLookupValue(projectInput);
38
+ for (const [name, config] of getProjects(tree)) {
39
+ if (normalizeLookupValue(name) === normalizedInput || normalizeLookupValue(config.root) === normalizedInput) {
40
+ return { name, root: config.root };
41
+ }
42
+ const packageJsonPath = joinPathFragments(config.root, 'package.json');
43
+ if (!tree.exists(packageJsonPath)) {
44
+ continue;
45
+ }
46
+ const packageJson = readJson(tree, packageJsonPath);
47
+ if (packageJson.name && normalizeLookupValue(packageJson.name) === normalizedInput) {
48
+ return { name, root: config.root };
49
+ }
50
+ }
51
+ throw new Error(`Could not resolve project ${projectInput}`);
52
+ }
53
+ function normalizeLookupValue(value) {
54
+ return normalizePath(value.replace(/^\.\//, ''));
55
+ }
@@ -0,0 +1,7 @@
1
+ import type { CreateNodesV2 } from 'nx/src/devkit-exports.js';
2
+ export declare const createNodesV2: CreateNodesV2;
3
+ declare const _default: {
4
+ createNodesV2: CreateNodesV2;
5
+ };
6
+ export default _default;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAUxG,eAAO,MAAM,aAAa,EAAE,aAsB3B,CAAC;;;;AAEF,wBAAiC"}