File tree 2 files changed +18
-18
lines changed
2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,13 @@ import { parse } from 'svelte/compiler';
2
2
import type { Ast } from 'svelte/types/compiler/interfaces.d' ;
3
3
import type { PluginOptions , PreprocessorOptions , PreprocessorResult } from './types' ;
4
4
import { 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' ;
6
12
7
13
const defaultOptions = ( ) : PluginOptions => {
8
14
return {
@@ -21,7 +27,7 @@ const defaultOptions = (): PluginOptions => {
21
27
let pluginOptions : PluginOptions ;
22
28
23
29
const markup = async ( { content, filename } : PreprocessorOptions ) : Promise < PreprocessorResult > => {
24
- const isIncluded = await isFileIncluded ( pluginOptions . includePaths , filename ) ;
30
+ const isIncluded = isFileIncluded ( pluginOptions . includePaths , filename ) ;
25
31
26
32
if ( ! isIncluded || ( ! pluginOptions . parseStyleTag && ! pluginOptions . parseExternalStylesheet ) ) {
27
33
return { code : content } ;
@@ -84,6 +90,8 @@ export default module.exports = (options: Partial<PluginOptions>) => {
84
90
...defaultOptions ( ) ,
85
91
...options ,
86
92
} ;
93
+
94
+ pluginOptions . includePaths = normalizeIncludePaths ( pluginOptions . includePaths ) ;
87
95
return {
88
96
markup,
89
97
} ;
Original file line number Diff line number Diff line change 1
1
import path from 'path' ;
2
2
import type { Ast } from 'svelte/types/compiler/interfaces.d' ;
3
3
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
+
4
10
/**
5
11
* Check if a file requires processing
6
12
* @param includePaths List of allowd paths
7
13
* @param filename the current filename to compare with the paths
8
14
* @returns The permission status
9
15
*/
10
- export const isFileIncluded = async (
11
- includePaths : string [ ] ,
12
- filename : string
13
- ) : Promise < boolean > => {
16
+ export const isFileIncluded = ( includePaths : string [ ] , filename : string ) : boolean => {
14
17
if ( includePaths . length < 1 ) {
15
18
return true ;
16
19
}
17
20
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 ) ) ;
30
22
} ;
31
23
32
24
/**
You can’t perform that action at this time.
0 commit comments