@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 +2 -2
- package/dist/cjs/generateTypes.cjs +10 -7
- package/dist/cjs/generateTypes.cjs.map +1 -1
- package/dist/cjs/lexer.cjs +229 -0
- package/dist/cjs/lexer.cjs.map +1 -0
- package/dist/cjs/lexer.d.cts +11 -0
- package/dist/cjs/moduleGraph.cjs +134 -7
- package/dist/cjs/moduleGraph.cjs.map +1 -1
- package/dist/cjs/moduleInfo.cjs +5 -20
- package/dist/cjs/moduleInfo.cjs.map +1 -1
- package/dist/cjs/moduleInfo.d.cts +3 -2
- package/dist/generateTypes.js +10 -7
- package/dist/generateTypes.js.map +1 -1
- package/dist/lexer.d.ts +11 -0
- package/dist/lexer.js +223 -0
- package/dist/lexer.js.map +1 -0
- package/dist/moduleGraph.js +134 -7
- package/dist/moduleGraph.js.map +1 -1
- package/dist/moduleInfo.d.ts +3 -2
- package/dist/moduleInfo.js +5 -20
- package/dist/moduleInfo.js.map +1 -1
- package/loader-queries.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://codecov.io/gh/knightedcodemonkey/css)
|
|
5
5
|
[](https://www.npmjs.com/package/@knighted/css)
|
|
6
6
|
|
|
7
|
-
`@knighted/css` walks your
|
|
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 (
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
const specifier
|
|
217
|
-
|
|
218
|
-
|
|
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) {
|