@kanso-labs/unplugin-style-dictionary 0.6.2 → 0.8.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/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # unplugin-style-dictionary
2
2
 
3
+ [![npm version][npm-version-shield]][npm]
4
+ [![npm downloads][npm-downloads-shield]][npm]
5
+ [![License][license-shield]][license] [![Build][build-shield]][build-workflow]
6
+ [![Test][test-shield]][test-workflow] [![Coverage][coverage-shield]][codecov]
7
+
3
8
  A lightweight, robust [unplugin](https://unplugin.unjs.io/)-based plugin to
4
9
  compile **Style Dictionary** design tokens ahead of your bundler, with automatic
5
10
  watching, rebuilding, and hot reloading (HMR) under Vite's dev server.
@@ -22,6 +27,9 @@ build on Rolldown/tsdown) that both need tokens compiled ahead of them.
22
27
  - **Config flexibility**: Supports file paths (JSON, JSON5, JSONC, JS, MJS, TS),
23
28
  configuration objects, or functions — including registering custom formats at
24
29
  config-resolution time.
30
+ - **Error overlay**: A rebuild that fails under Vite's dev server is pushed to
31
+ the error overlay rather than only to the terminal, and cleared on the next
32
+ one that succeeds.
25
33
  - **Atomic writes**: Every generated file is written to a temporary sibling and
26
34
  renamed into place, so code importing a token file while it is being rebuilt
27
35
  never reads a half-written file.
@@ -186,6 +194,38 @@ source and no config file does not reach it, so a dev server editing unrelated
186
194
  project files leaves it alone — treat it as the place to prepare a build, not as
187
195
  a general file-change hook.
188
196
 
197
+ **It is handed what the host is doing**, so the configuration it returns can
198
+ depend on it — build an expensive platform on `vite build` and skip it while the
199
+ dev server runs:
200
+
201
+ ```typescript
202
+ styleDictionaryPlugin({
203
+ config: ({ command, mode, watch }) => ({
204
+ source: ['tokens/**/*.json'],
205
+ platforms: {
206
+ css: {
207
+ transformGroup: 'css',
208
+ buildPath: 'dist/',
209
+ files: [{ destination: 'vars.css', format: 'css/variables' }],
210
+ },
211
+ // Shells out to a native toolchain, so it is worth a minute of a real
212
+ // build and not worth a second of every rebuild.
213
+ ...(command === 'build' && !watch ? { ios: iosPlatform(mode) } : {}),
214
+ },
215
+ }),
216
+ })
217
+ ```
218
+
219
+ `command` is `'serve'` only under Vite's dev server; every other target builds.
220
+ `mode` is Vite's or webpack's own, and follows `command` on rollup and rolldown,
221
+ which have no such concept. `watch` is read from the host rather than inferred
222
+ from `command`, because `rollup --watch` both watches and builds. The full
223
+ contract is [`StyleDictionaryConfigContext`](#options-reference).
224
+
225
+ A function taking no arguments stays valid — TypeScript accepts one of fewer
226
+ parameters and JavaScript ignores the extra argument — so the example below
227
+ needs no change.
228
+
189
229
  ```typescript
190
230
  // Named `styleDictionaryPlugin` here to avoid colliding with the `StyleDictionary`
191
231
  // class imported from the `style-dictionary` package itself, below.
@@ -350,6 +390,41 @@ A compile that fails is reported at every level, including `'silent'`, which is
350
390
  why there is no `'error'`. `log.warnings` is never touched: if your
351
391
  configuration turns a warning into a thrown build, that stays your decision.
352
392
 
393
+ ### Where the messages go
394
+
395
+ Through your bundler, not straight to the console, and each one takes them its
396
+ own way:
397
+
398
+ | Target | Progress lines | A failed compile |
399
+ | ------------------ | ------------------------ | ---------------------------------- |
400
+ | Vite | `config.logger.info` | `config.logger.error` |
401
+ | Rollup, Rolldown | the plugin context's log | the context's warning channel |
402
+ | Webpack | the console | `compilation.warnings`, so `stats` |
403
+ | No host (one-shot) | the console | the console |
404
+
405
+ That is what makes a `customLogger` and `clearScreen` work under Vite, and what
406
+ puts a failed compile into `stats.toJson()` under webpack — where it reaches CI
407
+ annotations and anything else reading the build's own output.
408
+
409
+ **A failure is reported as a warning, never on the host's error channel.**
410
+ Rollup's `this.error` aborts the bundle, so reporting a failure through it would
411
+ stop every build that reported one — taking the decision `failOnError` exists to
412
+ make. The same reasoning puts webpack's report in `compilation.warnings` rather
413
+ than `compilation.errors`, so `failOnError: false` really does leave the build
414
+ passing.
415
+
416
+ **Your bundler's own log level applies.** `vite --logLevel silent` silences
417
+ Vite's logger, and the plugin's lines are Vite's logger's now, so they go too.
418
+ Nothing is lost by it that matters: `failOnError` decides whether a broken token
419
+ set stops the build, and it decides that whether or not anything was printed.
420
+
421
+ Colour follows the usual conventions, which it previously ignored entirely: no
422
+ escapes when `NO_COLOR` is set, or when the stream is not a terminal, or under
423
+ `TERM=dumb`; escapes when `FORCE_COLOR` is set to anything but `0`, including on
424
+ a non-terminal, which is what that variable is for. `NO_COLOR` wins over
425
+ `FORCE_COLOR`. stdout and stderr are decided separately, because they are
426
+ redirected separately.
427
+
353
428
  ## Failing the Build
354
429
 
355
430
  A token compile that fails stops the build. `vite build`, `rollup` and `webpack`
@@ -368,12 +443,196 @@ StyleDictionary({
368
443
  })
369
444
  ```
370
445
 
371
- A failure is always reported, whatever `failOnError` and `silent` are set to.
446
+ A failure is always reported by the plugin, whatever `failOnError` and `silent`
447
+ are set to — see [Where the messages go](#where-the-messages-go) for which
448
+ channel it arrives on, and for the one thing that can still suppress it.
449
+
450
+ Under Vite's dev server it is reported to the browser as well. A failed rebuild
451
+ is pushed to Vite's error overlay, naming this plugin and carrying Style
452
+ Dictionary's message, and the overlay is dismissed by the next rebuild that
453
+ succeeds — so a page left rendering the last good token file says so instead of
454
+ looking current. Set `errorOverlay: false` to keep the failure in the terminal
455
+ only.
456
+
457
+ `failOnError` and `errorOverlay` answer different questions and do not interact:
458
+ the first decides whether the host stops, the second whether the browser is
459
+ told. The dev server's default is not to stop, which is exactly when the overlay
460
+ is the only thing that can report the failure.
461
+
462
+ ## Build Hooks
463
+
464
+ Three optional callbacks, for work that has to happen around a compile rather
465
+ than inside one — formatting the generated files, type-checking them, telling
466
+ something else they have landed.
467
+
468
+ ```typescript
469
+ StyleDictionary({
470
+ config: 'sd.config.json',
471
+ onBuildStart: () => console.log('compiling tokens'),
472
+ onBuildEnd: async (files, durationMs) => {
473
+ console.log(`wrote ${files.length} files in ${durationMs}ms`)
474
+ await formatGeneratedFiles(files)
475
+ },
476
+ onBuildError: (error) => notifySomething(error),
477
+ })
478
+ ```
479
+
480
+ `files` holds the absolute, platform-native path of every file the build
481
+ declares, sorted. It is what the build declares rather than what it happened to
482
+ write this time: a configuration skipped because its output was already current
483
+ contributes its destinations too, so a post-processing step still sees the whole
484
+ set on a rebuild that changed one file.
485
+
486
+ A rebuild is a build, so all three fire again on every watch-triggered one.
487
+
488
+ **A hook cannot fail the build that called it.** The return value is not
489
+ awaited, so nothing waits for post-processing; a hook that throws is reported
490
+ and the build stands, and a promise that rejects is caught and reported rather
491
+ than reaching the host as an unhandled rejection — which would otherwise take a
492
+ dev server down from inside a step meant to reformat a file.
493
+
494
+ `onBuildError` fires whatever `failOnError` is set to, and before that option
495
+ decides whether to rethrow. The two answer different questions: one is whether
496
+ the host stops, the other is that a build went wrong.
497
+
498
+ ## Public API
499
+
500
+ Small on purpose. Four bundler entry points, one root entry, and two types.
501
+
502
+ | Import | What it is |
503
+ | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
504
+ | `…/vite`, `…/rolldown`, `…/rollup`, `…/webpack` | Default export: the plugin for that bundler. Call it with the options below. |
505
+ | `…` (the root) | Default export, also named `unplugin`: the unplugin instance, carrying `.vite`, `.rolldown`, `.rollup` and `.webpack`. |
506
+ | `UnpluginStyleDictionaryOptions` | The options type, exported from every entry above. |
507
+ | `StyleDictionaryConfigContext` | What the function form of `config` is handed, exported from every entry above. |
508
+
509
+ Anything not in that table is internal, whatever a build output happens to
510
+ contain. In particular the watch filter and the raw unplugin factory are not
511
+ exported: the filter answers a question only this plugin asks, and the factory
512
+ takes a second `meta` argument — the bundler-identifying `UnpluginContextMeta` —
513
+ that a consumer would have to construct by hand, so calling it the obvious way
514
+ is a type error rather than a plugin.
515
+
516
+ Reach for the root entry when you need a target that has no subpath of its own,
517
+ or when one configuration object feeds more than one bundler:
518
+
519
+ ```typescript
520
+ import styleDictionary from '@kanso-labs/unplugin-style-dictionary'
521
+
522
+ const plugin = styleDictionary.rollup({ config: 'sd.config.json' })
523
+ ```
372
524
 
373
525
  ## Options Reference
374
526
 
375
527
  ```typescript
528
+ /**
529
+ * Options for the Style Dictionary unplugin factory, shared across all bundler
530
+ * targets (Vite, Rolldown, Rollup, Webpack).
531
+ *
532
+ * Every target compiles tokens before the build that consumes them. Live
533
+ * rebuild-on-change is driven by the host bundler's watch mode, because token
534
+ * source files sit outside the module graph: Vite's dev server, `rollup
535
+ * --watch` and `webpack --watch` all rebuild on a token change, and a one-shot
536
+ * build (e.g. `tsdown`/`rolldown build` without `--watch`) only builds once, in
537
+ * `buildStart`.
538
+ *
539
+ * Everything the plugin says goes through the host rather than to the console:
540
+ * Vite's `config.logger`, the plugin context under rollup and rolldown, and
541
+ * `compilation.warnings` under webpack, which is what puts a failed compile in
542
+ * `stats.toJson()`. A failure is reported on the warning channel and never the
543
+ * error one — rollup's `this.error` aborts the bundle, and that decision is
544
+ * `failOnError`'s alone. Where no host offers a channel the console is used,
545
+ * with colour gated on `NO_COLOR`, `FORCE_COLOR` and whether the stream is a
546
+ * terminal.
547
+ *
548
+ * The three `onBuild*` hooks are called synchronously and their return value
549
+ * is not awaited, so a build never waits for one. A hook may still be written
550
+ * `async`: a promise it returns is left to run on its own, and a rejection is
551
+ * caught and reported rather than reaching the host as an unhandled one. A
552
+ * hook that throws is reported and does not fail the build that called it.
553
+ *
554
+ * They return `Promise<void> | void` rather than `void` for that reason. Both
555
+ * accept an `async` hook as far as the compiler is concerned, but `void` alone
556
+ * makes one a `no-misused-promises` error under the type-aware lint rules a
557
+ * consumer is likely to be running — for a hook this documents as supported.
558
+ *
559
+ * Rolldown's watch mode is the exception, and it is not about glob patterns.
560
+ * `addWatchFile` is accepted either way, but what happens next differs by
561
+ * platform — on macOS a file registered through it is watched by nothing, while
562
+ * on a Linux runner the same edit reaches a rebuild. Do not rely on a token
563
+ * edit triggering a rebuild there.
564
+ */
565
+ /**
566
+ * What the host is doing, handed to the function form of `config` so it can
567
+ * decide what to build.
568
+ *
569
+ * Only Vite reports all three. Where a host does not say, the value is
570
+ * derived rather than guessed at, and each field below says how.
571
+ */
572
+ export interface StyleDictionaryConfigContext {
573
+ /**
574
+ * Whether the host is serving or building.
575
+ *
576
+ * `'serve'` comes from Vite's own `config.command` and is the dev server.
577
+ * Every other target builds, so it is `'build'` there — rollup, rolldown and
578
+ * webpack have no serving mode of their own to report.
579
+ */
580
+ command: 'build' | 'serve'
581
+
582
+ /**
583
+ * The host's mode, as it names it.
584
+ *
585
+ * Vite reports its `config.mode` — `'development'` serving,
586
+ * `'production'` building, or whatever `--mode` named. webpack reports its
587
+ * `mode` option. rollup and rolldown have no such concept, so the value
588
+ * follows `command`: `'development'` when serving, `'production'` when
589
+ * building.
590
+ */
591
+ mode: string
592
+
593
+ /**
594
+ * Whether the host will keep rebuilding.
595
+ *
596
+ * `true` under Vite's dev server, `rollup --watch`, `rolldown.watch()` and
597
+ * `webpack --watch`; `false` for a one-shot build. It is read from the
598
+ * host — the plugin context's `meta.watchMode` on the three rollup-shaped
599
+ * targets, and `compiler.watchMode` on webpack — rather than inferred from
600
+ * `command`, because `rollup --watch` both watches and builds.
601
+ */
602
+ watch: boolean
603
+ }
604
+
376
605
  export interface UnpluginStyleDictionaryOptions {
606
+ /**
607
+ * Whether a configuration whose output is already up to date may skip its
608
+ * compile.
609
+ *
610
+ * A build's expensive half is `buildAllPlatforms` — around 80% of it on a
611
+ * 4,000-token, two-platform configuration — and under Vite it runs inside
612
+ * `server.listen()`, so the dev server does not accept a connection until
613
+ * it finishes whether or not a token changed. A configuration is treated as
614
+ * up to date when every file it declares exists and is newer than every
615
+ * file it reads, its own config file included.
616
+ *
617
+ * Two things are never skipped, because neither can be told from the
618
+ * filesystem:
619
+ *
620
+ * - **The first compile of a process, for a configuration given as an
621
+ * object or a function.** There is no config file to stat, so an edit to
622
+ * the object inside `vite.config.ts` moves no mtime. Within one process
623
+ * the resolved configuration is compared against the one that was last
624
+ * built; across processes there is nothing to compare, so it builds.
625
+ * - **A platform declaring `actions`.** An action writes what no
626
+ * `destination` names, so a skip would leave its work undone.
627
+ *
628
+ * A custom format that reads something off-disk — an environment variable,
629
+ * a network call — cannot be detected this way either, and is what this
630
+ * option exists to turn off.
631
+ *
632
+ * @default true
633
+ */
634
+ cache?: boolean
635
+
377
636
  /**
378
637
  * Style Dictionary configuration(s).
379
638
  * Can be:
@@ -384,75 +643,205 @@ export interface UnpluginStyleDictionaryOptions {
384
643
  * - A function that returns a config or array of configs (or resolves to them).
385
644
  * Useful for calling `StyleDictionary.registerFormat()` (or other `register*`
386
645
  * methods) before returning a config that references the custom format by name.
646
+ * It is handed a `StyleDictionaryConfigContext` describing what the host is
647
+ * doing, so an expensive platform can be built only when it is wanted —
648
+ * skipped under the dev server, built by `vite build`. A function taking no
649
+ * arguments stays valid: TypeScript accepts one of fewer parameters, and
650
+ * JavaScript ignores the extra argument.
387
651
  *
388
- * If not provided, it will look for 'sd.config.json' or 'config.json' in the root directory.
652
+ * If not provided, the root directory is searched for 'sd.config.json',
653
+ * 'config.json', 'sd.config.js' and 'sd.config.mjs', in that order. The
654
+ * first one that exists wins, and the rest are not looked at.
389
655
  */
390
656
  config?:
391
- | string
392
- | string[]
657
+ | ((
658
+ context: StyleDictionaryConfigContext,
659
+ ) => Config | Config[] | Promise<Config | Config[]>)
393
660
  | Config
394
661
  | Config[]
395
- | (() => Config | Config[] | Promise<Config | Config[]>)
662
+ | string
663
+ | string[]
396
664
 
397
665
  /**
398
- * Additional files or glob patterns to watch.
399
- * If config files are paths, those paths are watched automatically.
400
- * By default, the plugin also parses 'source' and 'include' properties in configurations and watches them.
666
+ * Whether a failed rebuild is pushed to Vite's error overlay.
667
+ *
668
+ * A rebuild that fails under the dev server used to reach the browser
669
+ * nowhere: the page went on rendering the last good generated file, and the
670
+ * only trace was one red terminal line the developer may not have been
671
+ * looking at. With this on, the failure is sent to the page as an error
672
+ * frame naming this plugin, and the overlay is dismissed on the next
673
+ * rebuild that succeeds.
674
+ *
675
+ * This is Vite's overlay, so it does nothing on the other three targets,
676
+ * and nothing under `vite build` — there is no page to draw on.
677
+ *
678
+ * It is not `failOnError`'s job, and the two are independent. `failOnError`
679
+ * decides whether the host stops; this decides whether the browser is told.
680
+ * A dev server deliberately keeps serving through a failed rebuild, which is
681
+ * precisely the case where the overlay is the only thing that can say so.
682
+ *
683
+ * A failure Style Dictionary raises before this plugin can catch it — a
684
+ * token file that is not valid JSON, which rejects out of band — reaches
685
+ * neither the overlay nor this option.
686
+ *
687
+ * @default true
401
688
  */
402
- watch?: string | string[]
689
+ errorOverlay?: boolean
403
690
 
404
691
  /**
405
692
  * Whether a compile that fails should throw rather than only be reported.
406
693
  *
407
- * - 'build' (the default) throws on the one-shot compile in buildStart, and
408
- * only reports a failed watch rebuild.
409
- * - 'serve' is the reverse: a failed rebuild is thrown to whatever awaited
410
- * it. Vite's dev server has no build to fail, so there it is reported.
411
- * - true throws on both, false on neither.
694
+ * A failed compile used to be logged and swallowed, so `vite build`,
695
+ * `rollup` and `webpack` all exited 0 and shipped whatever the previous
696
+ * run had written the stale values, presented as current.
697
+ *
698
+ * - `'build'` (the default) throws on the one-shot compile that runs in
699
+ * `buildStart`, and only reports a failed watch rebuild, so a dev server
700
+ * survives a half-typed token file.
701
+ * - `'serve'` is the reverse: a failed rebuild is thrown to whatever awaited
702
+ * it, which is the host under `rollup --watch`. Vite's dev server has no
703
+ * build to fail, so there it is reported and the server keeps serving.
704
+ * - `true` throws on both, `false` on neither.
412
705
  *
413
- * Reporting happens either way, and is not suppressed by 'silent'.
706
+ * Reporting happens either way, and is not suppressed by `silent`.
414
707
  *
415
708
  * @default 'build'
416
709
  */
417
710
  failOnError?: 'build' | 'serve' | boolean
418
711
 
419
712
  /**
420
- * The directory a relative config path is looked up in.
713
+ * How much this plugin and Style Dictionary say while building.
421
714
  *
422
- * Defaults to the host's own rootVite's root, webpack's context — and to
423
- * the working directory for rollup and rolldown, which offer none. A
424
- * relative value here is resolved against the working directory, and it
425
- * takes precedence over whatever the host reports.
715
+ * Style Dictionary's own warningsa name collision, a reference that
716
+ * cannot be resolved, `No tokens for vars.css. File not created.` used to
717
+ * be suppressed unconditionally, because the plugin overwrote
718
+ * `log.verbosity` on the way past. Leave this unset and whatever the
719
+ * configuration asked for stands.
720
+ *
721
+ * - `'silent'` — nothing from either.
722
+ * - `'warn'` — Style Dictionary's warnings, and nothing from the plugin.
723
+ * - `'info'` — the above, plus the plugin's progress lines and size table.
724
+ * - `'verbose'` — the above, with Style Dictionary naming what it warned
725
+ * about rather than pointing at its own `--verbose` flag.
726
+ *
727
+ * A compile that fails is reported at every level, so there is no
728
+ * `'error'`: `'silent'` is the quietest and still reports a failure.
729
+ *
730
+ * This option governs what the plugin says, not where it goes. The messages
731
+ * are handed to the host — Vite's `config.logger`, the rollup and rolldown
732
+ * plugin context, webpack's `compilation` — so a host silenced by its own
733
+ * log level suppresses them after this option has let them through. A
734
+ * failure still stops the build whenever `failOnError` says it should,
735
+ * printed or not.
426
736
  *
427
- * It does not move the paths inside a configuration. See "Where paths are
428
- * resolved from" below.
737
+ * @default undefined, which prints the plugin's own lines and leaves the
738
+ * configuration's `log.verbosity` alone
429
739
  */
430
- root?: string
740
+ logLevel?: 'info' | 'silent' | 'verbose' | 'warn'
431
741
 
432
742
  /**
433
- * How much this plugin and Style Dictionary say while building.
743
+ * Called once a build has finished, with every file it declares and how long
744
+ * it took in milliseconds.
434
745
  *
435
- * - 'silent' nothing from either.
436
- * - 'warn' Style Dictionary's warnings, and nothing from the plugin.
437
- * - 'info' the above, plus the plugin's progress lines and size table.
438
- * - 'verbose' the above, with Style Dictionary naming what it warned about.
746
+ * The paths are absolute and platform-native, sorted so two runs of the same
747
+ * configuration hand back the same order. They are what the build declares
748
+ * rather than what it wrote this time: a configuration skipped by `cache`
749
+ * contributes its destinations too, because they are on disk and current,
750
+ * and a post-processing step that ignored them would leave half the output
751
+ * untouched on a rebuild that changed one file.
439
752
  *
440
- * Leave it unset and the configuration's own log.verbosity stands.
441
- * A compile that fails is reported at every level.
753
+ * This is where formatting the generated files, type-checking them, or
754
+ * telling something else they have landed belongs.
442
755
  *
443
756
  * @default undefined
444
757
  */
445
- logLevel?: 'info' | 'silent' | 'verbose' | 'warn'
758
+ onBuildEnd?: (files: string[], durationMs: number) => Promise<void> | void
759
+
760
+ /**
761
+ * Called when a build fails, with whatever was thrown.
762
+ *
763
+ * It fires whatever `failOnError` is set to, and before that option decides
764
+ * whether to rethrow — the two answer different questions, and under a dev
765
+ * server the default is not to throw at all.
766
+ *
767
+ * The failure is reported to the console either way, so this is for reacting
768
+ * to one rather than for noticing it.
769
+ *
770
+ * @default undefined
771
+ */
772
+ onBuildError?: (error: unknown) => Promise<void> | void
773
+
774
+ /**
775
+ * Called before a build begins, once per build.
776
+ *
777
+ * A watch-triggered rebuild is a build, so this fires again for each one.
778
+ *
779
+ * @default undefined
780
+ */
781
+ onBuildStart?: () => Promise<void> | void
782
+
783
+ /**
784
+ * Whether the table of generated files and their sizes is produced.
785
+ *
786
+ * Every generated file is read in full and gzipped at level 6 to fill the
787
+ * `gzip:` column — 4.5ms for 515kB of output, and 21ms at 6MB. That is
788
+ * small beside the compile it follows, and it is pure cost to a project
789
+ * large enough to care.
790
+ *
791
+ * This is not `logLevel`'s job, and the two differ in what they leave
792
+ * standing. `logLevel: 'warn'` silences the plugin's progress lines along
793
+ * with the table; `report: false` keeps them and drops only the table,
794
+ * along with the read and the compression behind it.
795
+ *
796
+ * Dropping to gzip level 1 instead was measured and rejected: it reported a
797
+ * figure up to 8.7% off — 21.4kB against 19.7kB on the same JSON — and that
798
+ * number is one a consumer compares against their own bundler's report.
799
+ *
800
+ * @default true
801
+ */
802
+ report?: boolean
803
+
804
+ /**
805
+ * The directory a relative `config` path is looked up in.
806
+ *
807
+ * Defaults to the host's own root — Vite's `root`, webpack's `context` —
808
+ * and to the working directory for rollup and rolldown, which offer none.
809
+ * A relative value here is resolved against the working directory, and it
810
+ * takes precedence over whatever the host reports.
811
+ *
812
+ * It does not move the paths **inside** a configuration. Style Dictionary
813
+ * resolves every relative `source`, `include` and `buildPath` against the
814
+ * working directory, and this plugin reads them the same way, so a
815
+ * configuration behaves identically here and under Style Dictionary's own
816
+ * CLI. A configuration kept in a subdirectory therefore names its tokens
817
+ * relative to where the build runs, not relative to itself.
818
+ */
819
+ root?: string
446
820
 
447
821
  /**
448
822
  * Disable console logging.
449
823
  *
450
- * An alias for logLevel: 'silent', which wins if both are set. A compile
824
+ * An alias for `logLevel: 'silent'`, which wins if both are set. A compile
451
825
  * that fails is always reported.
452
826
  *
453
827
  * @default false
454
828
  */
455
829
  silent?: boolean
830
+
831
+ /**
832
+ * Additional files or glob patterns to watch, on top of what is watched
833
+ * already: a `config` given as a path, and every file matched by the
834
+ * `source` and `include` patterns inside each configuration.
835
+ *
836
+ * Patterns are expanded to the paths they match before being registered,
837
+ * because the watchers in play take filenames rather than patterns. A
838
+ * pattern's own directory is registered alongside them, so a token file
839
+ * created later is noticed too.
840
+ *
841
+ * What a change to a watched file then triggers is the host's to decide —
842
+ * see the interface documentation above.
843
+ */
844
+ watch?: string | string[]
456
845
  }
457
846
  ```
458
847
 
@@ -478,3 +867,23 @@ plugin. As of this unplugin-based rewrite:
478
867
  ## License
479
868
 
480
869
  MIT
870
+
871
+ [build-shield]:
872
+ https://img.shields.io/github/actions/workflow/status/kanso-labs/unplugin-style-dictionary/build.yaml?branch=main&label=Build
873
+ [build-workflow]:
874
+ https://github.com/kanso-labs/unplugin-style-dictionary/actions/workflows/build.yaml
875
+ [codecov]: https://codecov.io/gh/kanso-labs/unplugin-style-dictionary
876
+ [coverage-shield]:
877
+ https://img.shields.io/codecov/c/github/kanso-labs/unplugin-style-dictionary?label=Coverage
878
+ [license]: ./LICENSE
879
+ [license-shield]:
880
+ https://img.shields.io/github/license/kanso-labs/unplugin-style-dictionary
881
+ [npm]: https://www.npmjs.com/package/@kanso-labs/unplugin-style-dictionary
882
+ [npm-downloads-shield]:
883
+ https://img.shields.io/npm/dm/@kanso-labs/unplugin-style-dictionary
884
+ [npm-version-shield]:
885
+ https://img.shields.io/npm/v/@kanso-labs/unplugin-style-dictionary
886
+ [test-shield]:
887
+ https://img.shields.io/github/actions/workflow/status/kanso-labs/unplugin-style-dictionary/test.yaml?branch=main&label=Test
888
+ [test-workflow]:
889
+ https://github.com/kanso-labs/unplugin-style-dictionary/actions/workflows/test.yaml
package/dist/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
- import { UnpluginStyleDictionaryOptions } from "./types.js";
2
- import { UnpluginFactory } from "unplugin";
1
+ import { StyleDictionaryConfigContext, UnpluginStyleDictionaryOptions } from "./types.js";
3
2
  //#region src/index.d.ts
4
- export declare function matchesWatchedFile(file: string, patterns: string[]): boolean;
5
- export declare const unpluginFactory: UnpluginFactory<undefined | UnpluginStyleDictionaryOptions, false>;
6
3
  export declare const unplugin: import("unplugin").UnpluginInstance<UnpluginStyleDictionaryOptions | undefined, false>;
7
4
  //#endregion
8
- export { type UnpluginStyleDictionaryOptions, unplugin as default };
5
+ export { type StyleDictionaryConfigContext, type UnpluginStyleDictionaryOptions, unplugin as default };
9
6
  //# sourceMappingURL=index.d.ts.map