create-rsc-kit 0.32.0 → 0.34.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.
package/dist/index.js CHANGED
@@ -84,7 +84,7 @@ if (options.install) {
84
84
  }
85
85
  }
86
86
  if (options.shadcn)
87
- setUpShadcn({ dir: options.dir, host: options.host, unattended, installed });
87
+ setUpShadcn({ dir: options.dir, host: options.host, unattended, installed, stylesheet: 'src/app/styles.css' });
88
88
  report(options);
89
89
  await notifyIfStale(staleCheck, 'bun create rsc-kit@latest');
90
90
  // ── ─────────────────────────────────────────────────────────────────────────
@@ -181,7 +181,7 @@ function write(o) {
181
181
  ['package.json', t.packageJson(o)],
182
182
  ['tsconfig.json', t.tsconfig(o)],
183
183
  ['vite.config.ts', t.viteConfig(o)],
184
- ['.gitignore', t.gitignore],
184
+ ['.gitignore', t.gitignore(o)],
185
185
  ['README.md', t.readme(o)],
186
186
  // Between markers, stamped: `rsc-kit agents` can bring it up to date.
187
187
  ['AGENTS.md', agentsSection(agentsOptions(o))],
package/dist/init.d.ts CHANGED
@@ -32,6 +32,13 @@ export declare function isFreshDirectory(dir: string): boolean;
32
32
  /** The marker that makes this an existing project, or null. */
33
33
  export declare function projectMarker(dir: string): string | null;
34
34
  export declare function detect(dir: string): Detected;
35
+ /**
36
+ * A Tailwind stylesheet the project already has, which the app's own
37
+ * styles.css should import rather than replace: Laravel's
38
+ * resources/css/app.css. Only one that imports Tailwind - one that does not
39
+ * is a plain stylesheet for Blade, and the app starts its own.
40
+ */
41
+ export declare function projectStylesheet(dir: string): string | null;
35
42
  export declare function initialise(o: Options, found: Detected, dir: string): Step[];
36
43
  /**
37
44
  * What init assumes when nobody says: whether to offer Tailwind first, and
package/dist/init.js CHANGED
@@ -11,7 +11,7 @@
11
11
  import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync, renameSync } from 'node:fs';
12
12
  import { spawnSync } from 'node:child_process';
13
13
  import { randomBytes } from 'node:crypto';
14
- import { basename, dirname, join } from 'node:path';
14
+ import { basename, dirname, join, relative, sep } from 'node:path';
15
15
  import { argv, cwd, exit, stdout } from 'node:process';
16
16
  import { DEFAULT_COMPILER, parseArgs, publishedCore } from './options.js';
17
17
  import { setUpShadcn } from './shadcn.js';
@@ -346,6 +346,15 @@ function mergeScripts(o, found) {
346
346
  }
347
347
  return steps;
348
348
  }
349
+ /** oxlint's config, when it was asked for and the project has none. */
350
+ function lintConfig(o, dir) {
351
+ if (!o.lint)
352
+ return [];
353
+ if (existsSync(join(dir, '.oxlintrc.json')))
354
+ return [{ kind: 'skipped', what: '.oxlintrc.json', detail: 'already exists' }];
355
+ writeFileSync(join(dir, '.oxlintrc.json'), t.oxlintConfig(o));
356
+ return [{ kind: 'wrote', what: '.oxlintrc.json' }];
357
+ }
349
358
  /** The plugin entry, written if there is no config and printed if there is. */
350
359
  function viteConfig(o, found, dir) {
351
360
  const file = t.configFile(o);
@@ -408,6 +417,18 @@ function manualPluginStep(o, existing) {
408
417
  ` ]`,
409
418
  };
410
419
  }
420
+ /**
421
+ * A Tailwind stylesheet the project already has, which the app's own
422
+ * styles.css should import rather than replace: Laravel's
423
+ * resources/css/app.css. Only one that imports Tailwind - one that does not
424
+ * is a plain stylesheet for Blade, and the app starts its own.
425
+ */
426
+ export function projectStylesheet(dir) {
427
+ const path = join(dir, 'resources/css/app.css');
428
+ if (!existsSync(path))
429
+ return null;
430
+ return /@import\s+['"]tailwindcss['"]/.test(readFileSync(path, 'utf-8')) ? path : null;
431
+ }
411
432
  /** The route tree, only where there is not one already. */
412
433
  function routes(o, dir) {
413
434
  const appDir = join(dir, o.sourceDir, 'app');
@@ -424,8 +445,14 @@ function routes(o, dir) {
424
445
  [join(o.sourceDir, 'app/page.tsx'), t.page(o)],
425
446
  [join(o.sourceDir, 'components/Counter.tsx'), t.counter(o)],
426
447
  ];
427
- if (o.tailwind)
428
- files.push([join(o.sourceDir, 'app/styles.css'), t.styles]);
448
+ if (o.tailwind) {
449
+ const existing = projectStylesheet(dir);
450
+ const from = join(dir, o.sourceDir, 'app');
451
+ files.push([
452
+ join(o.sourceDir, 'app/styles.css'),
453
+ existing ? t.stylesImporting(relative(from, existing).split(sep).join('/')) : t.styles,
454
+ ]);
455
+ }
429
456
  if (o.host !== 'laravel')
430
457
  files.push(['tests/app.test.ts', t.smokeTest(o)]);
431
458
  for (const [path, contents] of files) {
@@ -554,7 +581,14 @@ function gitignore(o, dir) {
554
581
  // The declarations moved out of the source directory into .rsc-kit, so this
555
582
  // is one line where it used to be four. The stub stays put — the app imports
556
583
  // it by relative path.
557
- const generated = ['.rsc-kit/', `${o.sourceDir}/server-actions.generated.ts`];
584
+ // rsc-host.json too, where a backend writes one: Laravel's
585
+ // rsc:host-manifest, or the backend's own command, at every dev start and
586
+ // every build. It was left out, and showed up in the first commit.
587
+ const generated = [
588
+ '.rsc-kit/',
589
+ `${o.sourceDir}/server-actions.generated.ts`,
590
+ ...(o.backend || o.host === 'laravel' ? ['rsc-host.json'] : []),
591
+ ];
558
592
  const p = t.paths(o);
559
593
  // Everything the build writes: the bundles, Nitro's output, and the hot
560
594
  // file. The hot file is the worst of them to commit — it points every other
@@ -636,6 +670,7 @@ export function initialise(o, found, dir) {
636
670
  ...tsconfig(o, found, dir),
637
671
  ...gitignore(o, dir),
638
672
  ...backend(o, found, dir),
673
+ ...lintConfig(o, dir),
639
674
  ...mergeDependencies(o, found),
640
675
  ...mergeScripts(o, found),
641
676
  ];
@@ -671,6 +706,8 @@ const INIT_HELP = `
671
706
  installed by default, any other never is
672
707
  --shadcn shadcn/ui for RSC: marks an existing components.json
673
708
  "rsc": true, or runs shadcn's init after the install
709
+ --lint / --no-lint oxlint: .oxlintrc.json, lint scripts over the source
710
+ directory; not asked where oxlint or ESLint is already
674
711
  -y, --yes accept what was detected, ask nothing
675
712
  -h, --help this
676
713
  `;
@@ -749,6 +786,11 @@ export async function runInit(args) {
749
786
  let shadcn = flags.shadcn === true;
750
787
  // Set up already: the question is only whether to mark it for RSC.
751
788
  const hasShadcn = existsSync(join(dir, 'components.json'));
789
+ // Already linting - oxlint, or ESLint, which an app moves off on purpose
790
+ // rather than because an installer asked - is not asked again; with no
791
+ // answer (--yes), a linter is not added to a project that did not ask.
792
+ const lints = Boolean(found.deps.oxlint || found.deps.eslint || existsSync(join(dir, '.oxlintrc.json')));
793
+ let lint = flags.lint === true && !found.deps.oxlint;
752
794
  if (!unattended) {
753
795
  const p = new Prompter();
754
796
  try {
@@ -762,6 +804,9 @@ export async function runInit(args) {
762
804
  ? await p.confirm('components.json is here: set "rsc": true for shadcn', true)
763
805
  : await p.confirm('shadcn/ui', false);
764
806
  }
807
+ if (flags.lint === undefined && !lints) {
808
+ lint = await p.confirm('oxlint', true);
809
+ }
765
810
  if (defaults.install && flags.install === undefined) {
766
811
  install = await p.confirm('Install dependencies now', true);
767
812
  }
@@ -781,8 +826,9 @@ export async function runInit(args) {
781
826
  host: flags.host ?? found.host ?? 'bun',
782
827
  compiler,
783
828
  tailwind,
784
- lint: false,
785
- // An existing project has its own schema library and env handling; init adds neither.
829
+ lint,
830
+ // An existing project has its own schema library and env handling - a
831
+ // backend's validation, Laravel's .env - so init asks about neither.
786
832
  validation: 'none',
787
833
  env: false,
788
834
  // Adding to a project writes no service worker; that is a decision for
@@ -816,7 +862,7 @@ export async function runInit(args) {
816
862
  // After the install: shadcn's init reads the dependencies, and its
817
863
  // components need them. A project already using shadcn is only marked.
818
864
  if (shadcn)
819
- setUpShadcn({ dir, host: options.host, unattended, installed });
865
+ setUpShadcn({ dir, host: options.host, unattended, installed, stylesheet: join(options.sourceDir, 'app/styles.css') });
820
866
  if (manual.length > 0) {
821
867
  stdout.write(`\n${bold('Then, by hand:')} the steps marked ! above.\n\n`);
822
868
  return;
package/dist/shadcn.d.ts CHANGED
@@ -6,6 +6,17 @@
6
6
  * the file was there to change.
7
7
  */
8
8
  export declare function markRsc(path: string): boolean;
9
+ /**
10
+ * The stylesheet components.json names, when the app never loads it: the
11
+ * path as written, or null when it is the app's stylesheet or one that
12
+ * stylesheet imports.
13
+ *
14
+ * shadcn writes its theme - the colours, the dark variant - to that file,
15
+ * and `shadcn add` keeps writing there. In a Laravel app it found
16
+ * resources/css/app.css, which only Blade's @vite loads; the pages were
17
+ * styled by Tailwind and nothing else, and nothing said why.
18
+ */
19
+ export declare function unloadedShadcnCss(dir: string, stylesheet: string): string | null;
9
20
  /**
10
21
  * shadcn/ui for an rsc-kit app, new or existing.
11
22
  *
@@ -24,4 +35,5 @@ export declare function setUpShadcn(o: {
24
35
  host: string;
25
36
  unattended: boolean;
26
37
  installed: boolean;
38
+ stylesheet?: string;
27
39
  }): void;
package/dist/shadcn.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
3
- import { join } from 'node:path';
3
+ import { dirname, join, resolve } from 'node:path';
4
4
  import { stdout } from 'node:process';
5
5
  import { bold, cyan, dim } from './prompt.js';
6
6
  /**
@@ -24,6 +24,44 @@ export function markRsc(path) {
24
24
  writeFileSync(path, JSON.stringify(config, null, 2) + '\n');
25
25
  return true;
26
26
  }
27
+ /**
28
+ * The stylesheet components.json names, when the app never loads it: the
29
+ * path as written, or null when it is the app's stylesheet or one that
30
+ * stylesheet imports.
31
+ *
32
+ * shadcn writes its theme - the colours, the dark variant - to that file,
33
+ * and `shadcn add` keeps writing there. In a Laravel app it found
34
+ * resources/css/app.css, which only Blade's @vite loads; the pages were
35
+ * styled by Tailwind and nothing else, and nothing said why.
36
+ */
37
+ export function unloadedShadcnCss(dir, stylesheet) {
38
+ let named;
39
+ try {
40
+ named = JSON.parse(readFileSync(join(dir, 'components.json'), 'utf-8')).tailwind?.css;
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ if (typeof named !== 'string' || named === '')
46
+ return null;
47
+ const target = resolve(dir, named);
48
+ const own = resolve(dir, stylesheet);
49
+ if (target === own)
50
+ return null;
51
+ const source = existsSync(own) ? readFileSync(own, 'utf-8') : '';
52
+ for (const [, path] of source.matchAll(/@import\s+['"]([^'"]+)['"]/g)) {
53
+ if (path.startsWith('.') && resolve(dirname(own), path) === target)
54
+ return null;
55
+ }
56
+ return named;
57
+ }
58
+ function warnUnloaded(dir, stylesheet) {
59
+ const named = stylesheet ? unloadedShadcnCss(dir, stylesheet) : null;
60
+ if (!named)
61
+ return;
62
+ stdout.write(`\n${bold(`components.json names ${named}, which the app does not load.`)} shadcn's theme goes there.\n` +
63
+ ` Import it from ${cyan(stylesheet)}, or move it there and set ${cyan(`"css": "${stylesheet}"`)} in components.json.\n`);
64
+ }
27
65
  /**
28
66
  * shadcn/ui for an rsc-kit app, new or existing.
29
67
  *
@@ -42,6 +80,7 @@ export function setUpShadcn(o) {
42
80
  if (existsSync(config)) {
43
81
  markRsc(config);
44
82
  stdout.write(`\n ${cyan('~')} components.json ${dim('— "rsc": true, so shadcn adds "use client" where it is needed')}\n`);
83
+ warnUnloaded(o.dir, o.stylesheet);
45
84
  return;
46
85
  }
47
86
  const [runner, ...prefix] = o.host === 'node' ? ['npx', '--yes'] : ['bunx', '--bun'];
@@ -53,4 +92,5 @@ export function setUpShadcn(o) {
53
92
  return;
54
93
  }
55
94
  markRsc(config);
95
+ warnUnloaded(o.dir, o.stylesheet);
56
96
  }
@@ -92,16 +92,25 @@ export declare const testPreload = "import { mock } from 'bun:test'\n\n// The bu
92
92
  export declare function smokeTest(o: Options): string;
93
93
  export declare function page(o: Options): string;
94
94
  export declare function counter(o: Options): string;
95
+ export declare const styles = "@import 'tailwindcss';\n\n/* The whole source tree, not just this directory. A client component is found\n automatically because it enters the browser bundle; a server component never\n does, so anything it uses has to be declared here or it is silently absent\n from the stylesheet. */\n@source '../';\n";
95
96
  /**
96
- * Tailwind needs @source pointing at the RSC tree.
97
- *
98
- * Server components never enter the client module graph and Tailwind's
99
- * detection roots at the Vite root, so without this the utilities layer holds
100
- * only classes scraped from the generated entries. The build still succeeds
101
- * and nothing warns — the page just arrives unstyled.
97
+ * The same, for a project that already has a Tailwind stylesheet - Laravel's
98
+ * resources/css/app.css. Imported rather than started over: it is where the
99
+ * project's theme is, and where shadcn's init writes one. A second stylesheet
100
+ * beside it, importing Tailwind on its own, left that theme in a file nothing
101
+ * loaded - no colours, no dark mode, and nothing said why.
102
102
  */
103
- export declare const styles = "@import 'tailwindcss';\n\n/* The whole source tree, not just this directory. A client component is found\n automatically because it enters the browser bundle; a server component never\n does, so anything it uses has to be declared here or it is silently absent\n from the stylesheet. */\n@source '../';\n";
104
- export declare const gitignore = "node_modules\n.output\ndist\n*.bun-build\n*.log\n.DS_Store\n\n# Rewritten by the build every run: the types, the route table and the build\n# report, and the stub module the app imports its server actions from.\n.rsc-kit/\nsrc/server-actions.generated.ts\n\n# Secrets. The example is the one to commit.\n.env\n.env.*\n!.env.example\n";
103
+ export declare function stylesImporting(path: string): string;
104
+ /**
105
+ * rsc-host.json too where a backend writes one - Laravel's rsc:host-manifest,
106
+ * Go's: regenerated at every dev start and build from the backend's own
107
+ * code, so a committed copy only goes stale and conflicts. The same rule as
108
+ * init's.
109
+ */
110
+ export declare function gitignore(o: {
111
+ backend?: string;
112
+ host: string;
113
+ }): string;
105
114
  /**
106
115
  * oxlint, with the React Compiler's own rules turned on.
107
116
  *
package/dist/templates.js CHANGED
@@ -66,6 +66,7 @@ export function scripts(o) {
66
66
  build: 'vite build',
67
67
  // What the build wrote. There is no server file to start any more.
68
68
  start: 'bun .output/server/index.mjs',
69
+ ...lintScripts(o),
69
70
  };
70
71
  }
71
72
  // On Bun, Vite itself runs on Bun. `vite` is a bin with a node shebang, so
@@ -132,19 +133,25 @@ export function scripts(o) {
132
133
  // typecheck run without one read the last start's - a route added since
133
134
  // was not a Route yet.
134
135
  typecheck: 'rsc-kit-typegen && tsc --noEmit',
135
- ...(o.lint ? { lint: 'oxlint src --type-aware --fix', 'lint:check': 'oxlint src --type-aware --deny-warnings' } : {}),
136
+ ...lintScripts(o),
136
137
  // Laravel returned above: its pages call into PHP that createTestApp does
137
138
  // not run, and its tests are Pest, on the other side.
138
139
  ...testScripts(o),
139
140
  };
140
141
  }
142
+ /** Over the source directory: resources/js in a Laravel app, not src. */
143
+ function lintScripts(o) {
144
+ return o.lint
145
+ ? { lint: `oxlint ${o.sourceDir} --type-aware --fix`, 'lint:check': `oxlint ${o.sourceDir} --type-aware --deny-warnings` }
146
+ : {};
147
+ }
141
148
  function testScripts(o) {
142
149
  const test = o.host === 'node' ? 'node --test "tests/**/*.test.ts"' : 'bun test tests';
143
150
  return {
144
151
  test,
145
152
  // The one command an agent runs before saying it is done. Each part exists
146
153
  // on its own; this is so nothing has to remember the list.
147
- check: ['rsc-kit-typegen', 'tsc --noEmit', ...(o.lint ? ['oxlint src --type-aware --deny-warnings'] : []), test].join(' && '),
154
+ check: ['rsc-kit-typegen', 'tsc --noEmit', ...(o.lint ? [`oxlint ${o.sourceDir} --type-aware --deny-warnings`] : []), test].join(' && '),
148
155
  };
149
156
  }
150
157
  export function packageJson(o) {
@@ -516,15 +523,40 @@ export function Counter() {
516
523
  * only classes scraped from the generated entries. The build still succeeds
517
524
  * and nothing warns — the page just arrives unstyled.
518
525
  */
519
- export const styles = `@import 'tailwindcss';
520
-
521
- /* The whole source tree, not just this directory. A client component is found
526
+ const SOURCE = `/* The whole source tree, not just this directory. A client component is found
522
527
  automatically because it enters the browser bundle; a server component never
523
528
  does, so anything it uses has to be declared here or it is silently absent
524
529
  from the stylesheet. */
525
530
  @source '../';
526
531
  `;
527
- export const gitignore = `node_modules
532
+ export const styles = `@import 'tailwindcss';
533
+
534
+ ${SOURCE}`;
535
+ /**
536
+ * The same, for a project that already has a Tailwind stylesheet - Laravel's
537
+ * resources/css/app.css. Imported rather than started over: it is where the
538
+ * project's theme is, and where shadcn's init writes one. A second stylesheet
539
+ * beside it, importing Tailwind on its own, left that theme in a file nothing
540
+ * loaded - no colours, no dark mode, and nothing said why.
541
+ */
542
+ export function stylesImporting(path) {
543
+ return `/* The project's stylesheet - Tailwind and its theme. Keep the theme there,
544
+ or move it here and delete that file; shadcn writes to the one named in
545
+ components.json. */
546
+ @import '${path}';
547
+
548
+ ${SOURCE}`;
549
+ }
550
+ /**
551
+ * rsc-host.json too where a backend writes one - Laravel's rsc:host-manifest,
552
+ * Go's: regenerated at every dev start and build from the backend's own
553
+ * code, so a committed copy only goes stale and conflicts. The same rule as
554
+ * init's.
555
+ */
556
+ export function gitignore(o) {
557
+ return gitignoreLines.replace('src/server-actions.generated.ts\n', 'src/server-actions.generated.ts\n' + (o.backend || o.host === 'laravel' ? 'rsc-host.json\n' : ''));
558
+ }
559
+ const gitignoreLines = `node_modules
528
560
  .output
529
561
  dist
530
562
  *.bun-build
@@ -589,7 +621,7 @@ export function oxlintConfig(o) {
589
621
  },
590
622
  // The build rewrites these on every run, and lints nobody can act on
591
623
  // are lints people learn to ignore.
592
- ignorePatterns: ['.rsc-kit', 'dist', `${o.sourceDir}/rsc-*.d.ts`],
624
+ ignorePatterns: ['.rsc-kit', 'dist', `${o.sourceDir}/rsc-*.d.ts`, `${o.sourceDir}/server-actions.generated.ts`],
593
625
  }, null, 2) + '\n');
594
626
  }
595
627
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rsc-kit",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "type": "module",
5
5
  "description": "Scaffold an RSC app on Bun, Hono, Elysia or Node.",
6
6
  "bin": {