@shd101wyy/yo 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shd101wyy/yo",
3
3
  "displayName": "Yo",
4
- "version": "0.1.8",
4
+ "version": "0.1.9",
5
5
  "main": "./out/cjs/index.cjs",
6
6
  "module": "./out/esm/index.mjs",
7
7
  "types": "./out/types/src/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "test": "jest",
35
35
  "test:watch": "jest --watch",
36
36
  "test:coverage": "jest --coverage",
37
- "postinstall": "node scripts/check-liburing.js",
37
+ "postinstall": "node scripts/print-welcome.js && node scripts/check-liburing.js",
38
38
  "prepare": "husky"
39
39
  },
40
40
  "lint-staged": {
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-undef */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
4
+
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+
8
+ function printWelcome() {
9
+ // Find package.json - could be in the installed package or a dependency
10
+ let packageJsonPath;
11
+
12
+ // Try to find the @shd101wyy/yo package.json
13
+ const possiblePaths = [path.join(__dirname, "..", "package.json")];
14
+
15
+ // Also try to resolve from node_modules (when installed as a dependency)
16
+ try {
17
+ possiblePaths.push(require.resolve("@shd101wyy/yo/package.json"));
18
+ } catch (e) {
19
+ // Module not found, that's okay - we'll use the local path
20
+ }
21
+
22
+ for (const pkgPath of possiblePaths) {
23
+ try {
24
+ if (fs.existsSync(pkgPath)) {
25
+ packageJsonPath = pkgPath;
26
+ break;
27
+ }
28
+ } catch (e) {
29
+ // Continue to next path
30
+ }
31
+ }
32
+
33
+ if (!packageJsonPath || !fs.existsSync(packageJsonPath)) {
34
+ return; // Silently fail if we can't find the package.json
35
+ }
36
+
37
+ try {
38
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
39
+ const version = packageJson.version;
40
+
41
+ if (!version) {
42
+ return;
43
+ }
44
+
45
+ console.log("");
46
+ console.log("👋 Welcome to Yo!");
47
+ console.log(` You have installed @shd101wyy/yo@${version}`);
48
+ console.log("");
49
+ } catch (e) {
50
+ // Silently fail - don't want to break installation
51
+ }
52
+ }
53
+
54
+ printWelcome();
@@ -243,4 +243,141 @@ impl(rune, ToString(
243
243
  })
244
244
  ));
245
245
 
246
- // TODO: Array to_string implementation?
246
+ // TODO: Array to_string implementation?
247
+
248
+ // --- derive_rule for ToString ---
249
+ // Local helpers (not exported from prelude, so defined locally)
250
+ __ts_s2 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string) -> comptime(comptime_string))((a + b));
251
+ __ts_s3 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string, comptime(c) : comptime_string) -> comptime(comptime_string))(
252
+ ((a + b) + c)
253
+ );
254
+ __ts_s4 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string, comptime(c) : comptime_string, comptime(d) : comptime_string) -> comptime(comptime_string))(
255
+ (((a + b) + c) + d)
256
+ );
257
+ __ts_s5 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string, comptime(c) : comptime_string, comptime(d) : comptime_string, comptime(e) : comptime_string) -> comptime(comptime_string))(
258
+ ((((a + b) + c) + d) + e)
259
+ );
260
+ __ts_fold_range :: (fn(
261
+ comptime(n) : usize,
262
+ comptime(init) : comptime_string,
263
+ comptime(f) : (fn(comptime(acc) : comptime_string, comptime(i) : usize) -> comptime(comptime_string))
264
+ ) -> comptime(comptime_string))(
265
+ cond(
266
+ (n == usize(0)) => init,
267
+ (n == usize(1)) => f(init, usize(0)),
268
+ true => f(recur((n - usize(1)), init, f), (n - usize(1)))
269
+ )
270
+ );
271
+
272
+ // Helper: join string parts with + operator, left-to-right parenthesized
273
+ __derive_join_plus :: (fn(comptime(parts) : comptime_string, comptime(new_part) : comptime_string) -> comptime(comptime_string))(
274
+ cond(
275
+ (parts == "") => new_part,
276
+ true => __ts_s5("(", parts, " + ", new_part, ")")
277
+ )
278
+ );
279
+
280
+ __derive_tostring :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(trait_params) : ComptimeList(Expr)) -> comptime(Expr))(
281
+ {
282
+ type_name :: Type.to_comptime_string(T);
283
+ info :: Type.get_info(T);
284
+ cond(
285
+ info.is_struct() => {
286
+ fields :: Type.get_struct_fields(T);
287
+ fc :: fields.len();
288
+ cond(
289
+ (fc == 0) => {
290
+ label :: __ts_s3("String.from(\"", type_name, "()\")");
291
+ ctx.make_impl(quote(
292
+ ToString(
293
+ to_string : ((self) -> #(label.to_expr()))
294
+ )
295
+ ))
296
+ },
297
+ true => {
298
+ body :: __ts_fold_range(fc, __ts_s3("String.from(\"", type_name, "(\")" ),
299
+ (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))(
300
+ {
301
+ fname :: fields.get(fi).name;
302
+ with_sep :: cond(
303
+ (fi == 0) => a,
304
+ true => __derive_join_plus(a, "String.from(\", \")")
305
+ );
306
+ __derive_join_plus(with_sep, __ts_s3("(&(self.*.", fname, ")).to_string()"))
307
+ }
308
+ )
309
+ );
310
+ full_body :: __derive_join_plus(body, "String.from(\")\")");
311
+ ctx.make_impl(quote(
312
+ ToString(
313
+ to_string : ((self) -> #(full_body.to_expr()))
314
+ )
315
+ ))
316
+ }
317
+ )
318
+ },
319
+ info.is_enum() => {
320
+ variants :: Type.get_enum_variants(T);
321
+ vc :: variants.len();
322
+ ts_branches :: __ts_fold_range(vc, "",
323
+ (fn(comptime(acc) : comptime_string, comptime(vi) : usize) -> comptime(comptime_string))(
324
+ {
325
+ v :: variants.get(vi);
326
+ branch :: cond(
327
+ (v.fields.len() == 0) =>
328
+ __ts_s5(".", v.name, " => String.from(\"", type_name, __ts_s3(".", v.name, "\")")),
329
+ true => {
330
+ bindings :: __ts_fold_range(v.fields.len(), "",
331
+ (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))(
332
+ {
333
+ fname :: v.fields.get(fi).name;
334
+ cond(
335
+ (a == "") => __ts_s2("__v_", fname),
336
+ true => __ts_s3(a, ", __v_", fname)
337
+ )
338
+ }
339
+ )
340
+ );
341
+ body :: __ts_fold_range(v.fields.len(),
342
+ __ts_s5("String.from(\"", type_name, ".", v.name, "(\")" ),
343
+ (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))(
344
+ {
345
+ fname :: v.fields.get(fi).name;
346
+ with_sep :: cond(
347
+ (fi == 0) => a,
348
+ true => __derive_join_plus(a, "String.from(\", \")")
349
+ );
350
+ __derive_join_plus(with_sep, __ts_s3("(&(__v_", fname, ")).to_string()"))
351
+ }
352
+ )
353
+ );
354
+ full_body :: __derive_join_plus(body, "String.from(\")\")");
355
+ __ts_s4(".", v.name, __ts_s3("(", bindings, ") => "), full_body)
356
+ }
357
+ );
358
+ cond(
359
+ (acc == "") => branch,
360
+ true => __ts_s3(acc, ",\n ", branch)
361
+ )
362
+ }
363
+ )
364
+ );
365
+ match_body :: __ts_s3("match(self.*,\n ", ts_branches, "\n )");
366
+ ctx.make_impl(quote(
367
+ ToString(
368
+ to_string : ((self) -> #(match_body.to_expr()))
369
+ )
370
+ ))
371
+ },
372
+ true => {
373
+ label :: __ts_s3("String.from(\"", type_name, "\")");
374
+ ctx.make_impl(quote(
375
+ ToString(
376
+ to_string : ((self) -> #(label.to_expr()))
377
+ )
378
+ ))
379
+ }
380
+ )
381
+ }
382
+ );
383
+ derive_rule(ToString, __derive_tostring);