@@ -3,6 +3,13 @@ import { $, Glob } from "bun";
33import { createMarkdown } from "./utils/create-markdown" ;
44import { postcssScopedStyles } from "./utils/postcss-scoped-styles" ;
55import { preprocessStyles } from "./utils/preprocess-styles" ;
6+ import {
7+ BACKTICK ,
8+ CSS_FILE ,
9+ DEFAULT_STRING ,
10+ NON_MINIFIED_CSS ,
11+ STARTS_WITH_DIGIT ,
12+ } from "./utils/regexes" ;
613import { toCamelCase } from "./utils/to-camel-case" ;
714import { writeTo } from "./utils/write-to" ;
815
@@ -29,11 +36,14 @@ export async function buildStyles() {
2936
3037 for await ( const file of glob . scan ( "node_modules/highlight.js/styles" ) ) {
3138 const absPath = path . resolve ( "node_modules/highlight.js/styles" , file ) ;
32- if ( / (?< ! \. m i n ) \. ( c s s ) $ / . test ( file ) ) {
39+ if ( NON_MINIFIED_CSS . test ( file ) ) {
3340 let { name, dir } = path . parse ( file ) ;
3441 let moduleName = toCamelCase ( name ) ;
3542
36- if ( / ^ [ 0 - 9 ] / . test ( moduleName ) || / ^ d e f a u l t $ / . test ( moduleName ) ) {
43+ if (
44+ STARTS_WITH_DIGIT . test ( moduleName ) ||
45+ DEFAULT_STRING . test ( moduleName )
46+ ) {
3747 moduleName = `_${ moduleName } ` ;
3848 }
3949
@@ -46,7 +56,7 @@ export async function buildStyles() {
4656 styles . push ( { name, moduleName } ) ;
4757 cssFiles . push ( { file, absPath, name, dir, moduleName } ) ;
4858 } else {
49- if ( ! / \. ( c s s ) $ / . test ( file ) ) {
59+ if ( ! CSS_FILE . test ( file ) ) {
5060 copyCommands . push ( absPath ) ;
5161 }
5262 }
@@ -65,7 +75,7 @@ export async function buildStyles() {
6575 const cssMinified = preprocessStyles ( content , {
6676 discardComments : "preserve-license" ,
6777 } ) ;
68- const contentCssForJs = cssMinified . replace ( / ` / g , "\\`" ) ;
78+ const contentCssForJs = cssMinified . replace ( BACKTICK , "\\`" ) ;
6979
7080 const exportee = `const ${ moduleName } = \`<style>${ contentCssForJs } </style>\`;\n
7181 export default ${ moduleName } ;\n` ;
0 commit comments