File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,13 @@ import { parse } from 'svelte/compiler';
22import type { Ast } from 'svelte/types/compiler/interfaces.d' ;
33import type { PluginOptions , PreprocessorOptions , PreprocessorResult } from './types' ;
44import { nativeProcessor , mixedProcessor , scopedProcessor } from './processors' ;
5- import { getLocalIdent , isFileIncluded , hasModuleImports , hasModuleAttribute } from './lib' ;
5+ import {
6+ getLocalIdent ,
7+ isFileIncluded ,
8+ hasModuleImports ,
9+ hasModuleAttribute ,
10+ normalizeIncludePaths ,
11+ } from './lib' ;
612
713const defaultOptions = ( ) : PluginOptions => {
814 return {
@@ -21,7 +27,7 @@ const defaultOptions = (): PluginOptions => {
2127let pluginOptions : PluginOptions ;
2228
2329const markup = async ( { content, filename } : PreprocessorOptions ) : Promise < PreprocessorResult > => {
24- const isIncluded = await isFileIncluded ( pluginOptions . includePaths , filename ) ;
30+ const isIncluded = isFileIncluded ( pluginOptions . includePaths , filename ) ;
2531
2632 if ( ! isIncluded || ( ! pluginOptions . parseStyleTag && ! pluginOptions . parseExternalStylesheet ) ) {
2733 return { code : content } ;
@@ -84,6 +90,11 @@ export default module.exports = (options: Partial<PluginOptions>) => {
8490 ...defaultOptions ( ) ,
8591 ...options ,
8692 } ;
93+
94+ if ( pluginOptions . includePaths ) {
95+ pluginOptions . includePaths = normalizeIncludePaths ( pluginOptions . includePaths ) ;
96+ }
97+
8798 return {
8899 markup,
89100 } ;
Original file line number Diff line number Diff line change 11import path from 'path' ;
22import type { Ast } from 'svelte/types/compiler/interfaces.d' ;
33
4+ const normalizePath = ( filepath : string ) : string =>
5+ path . sep === '\\' ? filepath . replace ( / \\ / g, '/' ) : filepath ;
6+
7+ export const normalizeIncludePaths = ( paths : string [ ] ) : string [ ] =>
8+ paths . map ( ( includePath ) => normalizePath ( path . resolve ( includePath ) ) ) ;
9+
410/**
511 * Check if a file requires processing
612 * @param includePaths List of allowd paths
713 * @param filename the current filename to compare with the paths
814 * @returns The permission status
915 */
10- export const isFileIncluded = async (
11- includePaths : string [ ] ,
12- filename : string
13- ) : Promise < boolean > => {
16+ export const isFileIncluded = ( includePaths : string [ ] , filename : string ) : boolean => {
1417 if ( includePaths . length < 1 ) {
1518 return true ;
1619 }
1720
18- const isIncluded : boolean = await new Promise ( ( resolve ) : void => {
19- includePaths . forEach ( ( includePath , index ) : void => {
20- if ( filename . indexOf ( path . resolve ( includePath ) ) !== - 1 ) {
21- resolve ( true ) ;
22- }
23- if ( index === includePaths . length - 1 ) {
24- resolve ( false ) ;
25- }
26- } ) ;
27- } ) ;
28-
29- return isIncluded ;
21+ return includePaths . some ( ( includePath ) => filename . startsWith ( includePath ) ) ;
3022} ;
3123
3224/**
You can’t perform that action at this time.
0 commit comments