@knighted/css 1.0.10 → 1.1.0-rc.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.
@@ -1,19 +1,23 @@
1
1
  import { type TransformOptions as LightningTransformOptions } from 'lightningcss';
2
2
  import { type SpecificitySelector, type SpecificityStrategy } from './helpers.cjs';
3
+ import { type AutoStableOption } from './autoStableSelectors.cjs';
3
4
  import type { ModuleGraphOptions } from './moduleGraph.cjs';
4
5
  import type { CssResolver } from './types.cjs';
6
+ export type { AutoStableOption } from './autoStableSelectors.cjs';
5
7
  export type { CssResolver } from './types.cjs';
6
8
  export type { ModuleGraphOptions } from './moduleGraph.cjs';
7
9
  export declare const DEFAULT_EXTENSIONS: string[];
8
10
  type LightningCssConfig = boolean | Partial<Omit<LightningTransformOptions<never>, 'code'>>;
9
11
  type PeerLoader = (name: string) => Promise<unknown>;
12
+ type StrictLightningVisitor = Exclude<LightningTransformOptions<never>['visitor'], undefined>;
10
13
  export interface CssOptions {
11
14
  extensions?: string[];
12
15
  cwd?: string;
13
16
  filter?: (filePath: string) => boolean;
14
17
  lightningcss?: LightningCssConfig;
18
+ autoStable?: AutoStableOption;
15
19
  specificityBoost?: {
16
- visitor?: LightningTransformOptions<never>['visitor'];
20
+ visitor?: StrictLightningVisitor;
17
21
  strategy?: SpecificityStrategy;
18
22
  match?: SpecificitySelector[];
19
23
  };
@@ -31,6 +35,7 @@ export interface VanillaCompileResult {
31
35
  export interface CssResult {
32
36
  css: string;
33
37
  files: string[];
38
+ exports?: Record<string, string | string[]>;
34
39
  }
35
40
  export declare function css(entry: string, options?: CssOptions): Promise<string>;
36
41
  export declare function cssWithMeta(entry: string, options?: CssOptions): Promise<CssResult>;
@@ -76,6 +76,7 @@ async function generateTypes(options = {}) {
76
76
  include,
77
77
  cacheDir,
78
78
  stableNamespace: options.stableNamespace,
79
+ autoStable: options.autoStable,
79
80
  tsconfig,
80
81
  };
81
82
  return generateDeclarations(internalOptions);
@@ -110,9 +111,14 @@ async function generateDeclarations(options) {
110
111
  let selectorMap = selectorCache.get(cacheKey);
111
112
  if (!selectorMap) {
112
113
  try {
114
+ const shouldUseCssModules = resolvedPath.endsWith('.module.css');
113
115
  const { css } = await activeCssWithMeta(resolvedPath, {
114
116
  cwd: options.rootDir,
115
117
  peerResolver,
118
+ autoStable: options.autoStable ? { namespace: resolvedNamespace } : undefined,
119
+ lightningcss: options.autoStable && shouldUseCssModules
120
+ ? { cssModules: true }
121
+ : undefined,
116
122
  });
117
123
  selectorMap = (0, stableSelectorsLiteral_js_1.buildStableSelectorsLiteral)({
118
124
  css,
@@ -484,6 +490,7 @@ async function runGenerateTypesCli(argv = process.argv.slice(2)) {
484
490
  include: parsed.include,
485
491
  outDir: parsed.outDir,
486
492
  stableNamespace: parsed.stableNamespace,
493
+ autoStable: parsed.autoStable,
487
494
  });
488
495
  reportCliResult(result);
489
496
  }
@@ -498,10 +505,15 @@ function parseCliArgs(argv) {
498
505
  const include = [];
499
506
  let outDir;
500
507
  let stableNamespace;
508
+ let autoStable = false;
501
509
  for (let i = 0; i < argv.length; i += 1) {
502
510
  const arg = argv[i];
503
511
  if (arg === '--help' || arg === '-h') {
504
- return { rootDir, include, outDir, stableNamespace, help: true };
512
+ return { rootDir, include, outDir, stableNamespace, autoStable, help: true };
513
+ }
514
+ if (arg === '--auto-stable') {
515
+ autoStable = true;
516
+ continue;
505
517
  }
506
518
  if (arg === '--root' || arg === '-r') {
507
519
  const value = argv[++i];
@@ -540,7 +552,7 @@ function parseCliArgs(argv) {
540
552
  }
541
553
  include.push(arg);
542
554
  }
543
- return { rootDir, include, outDir, stableNamespace };
555
+ return { rootDir, include, outDir, stableNamespace, autoStable };
544
556
  }
545
557
  function printHelp() {
546
558
  console.log(`Usage: knighted-css-generate-types [options]
@@ -550,6 +562,7 @@ Options:
550
562
  -i, --include <path> Additional directories/files to scan (repeatable)
551
563
  --out-dir <path> Directory to store selector module manifest cache
552
564
  --stable-namespace <name> Stable namespace prefix for generated selector maps
565
+ --auto-stable Enable autoStable when extracting CSS for selectors
553
566
  -h, --help Show this help message
554
567
  `);
555
568
  }