Skip to content
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 125 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.6",
"description": "",
"exports": "./lib/index.js",

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exports field is a string, which restricts consumers to importing only the package root. That makes the documented mistcss/lib/stats (and any other subpath like lib/stats) unavailable in Node when exports is present. If stats is intended to be a public utility, switch exports to an object and explicitly export ./stats (and any other public subpaths), while keeping . pointing at ./lib/index.js.

Suggested change
"exports": "./lib/index.js",
"exports": {
".": "./lib/index.js",
"./lib/stats": "./lib/stats.js"
},

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot don't export stats

"bin": "./lib/bin.js",
"scripts": {
"build": "rm -rf lib && tsc",
"format": "prettier --write .",
Expand Down Expand Up @@ -36,6 +37,7 @@
},
"dependencies": {
"postcss-import": "^16.1.0",
"postcss-selector-parser": "^6.1.2"
"postcss-selector-parser": "^6.1.2",
"ts-morph": "^27.0.2"
}
Comment thread
typicode marked this conversation as resolved.
}
70 changes: 70 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env node
import fs = require('node:fs')
Comment thread
typicode marked this conversation as resolved.
Outdated
import path = require('node:path')
import { parseArgs } from 'node:util'
import type { Parsed } from './index'
const { parse } = require('./index')
const { stats } = require('./stats')

const { values, positionals } = parseArgs({
args: process.argv.slice(2),
options: {
stats: {
type: 'boolean',
default: false,
},
},
strict: true,
allowPositionals: true,
})

if (positionals.length === 0) {
console.error('Error: Please provide a CSS file path')
console.error('Usage: mistcss <path-to-css-file> [--stats]')
process.exit(1)
}

const cssPath = positionals[0]
const css = fs.readFileSync(cssPath, 'utf-8')

const parsed = parse(css)

if (values.stats) {
// Find tsconfig.json in current directory or parent directories
let currentDir = process.cwd()
let tsconfigPath = null

while (currentDir !== path.dirname(currentDir)) {
const candidate = path.join(currentDir, 'tsconfig.json')
if (fs.existsSync(candidate)) {
tsconfigPath = candidate
break
}
currentDir = path.dirname(currentDir)
}

if (!tsconfigPath) {
console.error('Error: tsconfig.json not found in current directory or parent directories')
process.exit(1)
}

const statsResult = stats(parsed, tsconfigPath)
console.log(JSON.stringify(statsResult, null, 2))
} else {
// Convert Sets to Arrays for JSON serialization
const serializable = Object.fromEntries(
(Object.entries(parsed) as [string, Parsed[string]][]).map(([key, value]) => [
key,
{
...value,
attributes: Object.fromEntries(
Object.entries(value.attributes).map(([k, v]) => [k, Array.from(v)])
),
booleanAttributes: Array.from(value.booleanAttributes),
properties: Array.from(value.properties),
},
])
)

console.log(JSON.stringify(serializable, null, 2))
}
Loading