Skip to content

Commit

Permalink
fix: Use a regex to filter files for processing
Browse files Browse the repository at this point in the history
fixes: #48
  • Loading branch information
deepjoy committed Jul 19, 2024
1 parent 6ccdd2e commit e5a4870
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/core/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export function getOptions(options: UnpluginStylexOptions): Required<UnpluginSty
return {
...options,
dev: isDev,
invalidExts: ['.json', '.html', '.jade', '.json5', ...(options.invalidExts ?? [])],
// .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts
validExts: options.validExts ?? /\.[mc]?[jt]sx?$/,
stylex: {
filename: stylex.filename || 'stylex.css',
stylexImports: stylex.stylexImports || ['@stylexjs/stylex'],
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>

transformInclude(id) {
// webpack will contain these files, which will occur errors
const invalidExts = options.invalidExts
const validExts = options.validExts
const extname = path.extname(id)
// for handle vite
const questionMarkIndex = extname.indexOf('?')
const validExtName = questionMarkIndex > -1 ? extname.slice(0, questionMarkIndex) : extname
return !invalidExts.includes(validExtName)
return validExts.test(validExtName)
},

async transform(code, id) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type StylexOptions = {

export type UnpluginStylexOptions = {
// compiler?: string
invalidExts?: string[]
validExts?: RegExp
dev?: boolean
// enforce?: 'post' | 'pre'
stylex?: StylexOptions
Expand Down

0 comments on commit e5a4870

Please sign in to comment.