@knighted/css 1.0.8 → 1.0.10

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
@@ -4,7 +4,7 @@
4
4
  [![codecov](https://codecov.io/gh/knightedcodemonkey/css/graph/badge.svg?token=q93Qqwvq6l)](https://codecov.io/gh/knightedcodemonkey/css)
5
5
  [![NPM version](https://img.shields.io/npm/v/@knighted/css.svg)](https://www.npmjs.com/package/@knighted/css)
6
6
 
7
- `@knighted/css` walks your JavaScript/TypeScript module graph, compiles every CSS-like dependency (plain CSS, Sass/SCSS, Less, vanilla-extract), and ships both the concatenated stylesheet string and optional `.knighted-css.*` imports that keep selectors typed. Use it when you need fully materialized styles ahead of runtime—Shadow DOM surfaces, server-rendered routes, static site builds, or any entry point that should inline CSS without spinning up a full bundler.
7
+ `@knighted/css` walks your module graph, compiles every CSS-like dependency (plain CSS, Sass/SCSS, Less, vanilla-extract), and ships both the concatenated stylesheet string and optional `.knighted-css.*` imports that keep selectors typed. Use it with or without a bundler: run the `css()` API in scripts/SSR pipelines, or lean on the `?knighted-css` loader query so bundlers import compiled CSS alongside modules. Either path yields fully materialized styles for Shadow DOM surfaces, server-rendered routes, static site builds, or any entry point that should inline CSS.
8
8
 
9
9
  ## Why
10
10
 
@@ -23,7 +23,7 @@ I needed a single source of truth for UI components that could drop into both li
23
23
 
24
24
  ## Features
25
25
 
26
- - Traverses module graphs with a built-in walker to find transitive style imports (no bundler required).
26
+ - Traverses module graphs with a built-in walker to find transitive style imports (bundler optional—works standalone or through bundler loaders), including static import attributes (`with { type: "css" }`) for extensionless or aliased specifiers.
27
27
  - Resolution parity via [`oxc-resolver`](https://github.com/oxc-project/oxc-resolver): tsconfig `paths`, package `exports` + `imports`, and extension aliasing (e.g., `.css.js` → `.css.ts`) are honored without wiring up a bundler.
28
28
  - Compiles `*.css`, `*.scss`, `*.sass`, `*.less`, and `*.css.ts` (vanilla-extract) files out of the box.
29
29
  - Optional post-processing via [`lightningcss`](https://github.com/parcel-bundler/lightningcss) for minification, prefixing, media query optimizations, or specificity boosts.
@@ -11,11 +11,11 @@ const promises_1 = __importDefault(require("node:fs/promises"));
11
11
  const node_path_1 = __importDefault(require("node:path"));
12
12
  const node_module_1 = require("node:module");
13
13
  const node_url_1 = require("node:url");
14
- const es_module_lexer_1 = require("es-module-lexer");
15
14
  const node_module_type_1 = require("node-module-type");
16
15
  const get_tsconfig_1 = require("get-tsconfig");
17
16
  const tsconfig_paths_1 = require("tsconfig-paths");
18
17
  const css_js_1 = require("./css.cjs");
18
+ const lexer_js_1 = require("./lexer.cjs");
19
19
  const stableSelectorsLiteral_js_1 = require("./stableSelectorsLiteral.cjs");
20
20
  const stableNamespace_js_1 = require("./stableNamespace.cjs");
21
21
  let activeCssWithMeta = css_js_1.cssWithMeta;
@@ -70,7 +70,6 @@ async function generateTypes(options = {}) {
70
70
  const include = normalizeIncludeOptions(options.include, rootDir);
71
71
  const cacheDir = node_path_1.default.resolve(options.outDir ?? node_path_1.default.join(rootDir, '.knighted-css'));
72
72
  const tsconfig = loadTsconfigResolutionContext(rootDir);
73
- await es_module_lexer_1.init;
74
73
  await promises_1.default.mkdir(cacheDir, { recursive: true });
75
74
  const internalOptions = {
76
75
  rootDir,
@@ -211,13 +210,17 @@ async function findSpecifierImports(filePath) {
211
210
  return [];
212
211
  }
213
212
  const matches = [];
214
- const [imports] = (0, es_module_lexer_1.parse)(source, filePath);
215
- for (const record of imports) {
216
- const specifier = record.n ?? source.slice(record.s, record.e);
217
- if (specifier && specifier.includes(SELECTOR_REFERENCE)) {
218
- matches.push({ specifier, importer: filePath });
213
+ try {
214
+ const { imports } = await (0, lexer_js_1.analyzeModule)(source, filePath);
215
+ for (const specifier of imports) {
216
+ if (specifier.includes(SELECTOR_REFERENCE)) {
217
+ matches.push({ specifier, importer: filePath });
218
+ }
219
219
  }
220
220
  }
221
+ catch {
222
+ // ignore and fall back to regex below
223
+ }
221
224
  const requireRegex = /require\((['"])([^'"`]+?\.knighted-css[^'"`]*)\1\)/g;
222
225
  let reqMatch;
223
226
  while ((reqMatch = requireRegex.exec(source)) !== null) {