File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
packages/rollup-plugin-html/src Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { Document , Element } from 'parse5' ;
2
2
import path from 'path' ;
3
+ import picomatch from 'picomatch' ;
3
4
import { findElements , getTagName , getAttribute } from '@web/parse5-utils' ;
4
5
import { createError } from '../utils.js' ;
5
6
import { serialize } from 'v8' ;
@@ -143,3 +144,11 @@ export function getSourcePaths(node: Element) {
143
144
export function findAssets ( document : Document ) {
144
145
return findElements ( document , isAsset ) ;
145
146
}
147
+
148
+ // picomatch follows glob spec and requires "./" to be removed for the matcher to work
149
+ // it is safe, because with or without it resolves to the same file
150
+ // read more: https://github.com/micromatch/picomatch/issues/77
151
+ const removeLeadingSlash = ( str : string ) => ( str . startsWith ( './' ) ? str . slice ( 2 ) : str ) ;
152
+ export function createAssetPicomatchMatcher ( glob ?: string | string [ ] ) {
153
+ return picomatch ( glob || [ ] , { format : removeLeadingSlash } ) ;
154
+ }
Original file line number Diff line number Diff line change 1
1
import { Document , serialize } from 'parse5' ;
2
2
import fs from 'fs' ;
3
3
import path from 'path' ;
4
- import picomatch from 'picomatch' ;
5
4
import { InputAsset } from '../InputData.js' ;
6
5
import {
7
6
findAssets ,
8
7
getSourcePaths ,
9
8
isHashedAsset ,
10
9
resolveAssetFilePath ,
10
+ createAssetPicomatchMatcher ,
11
11
} from '../../assets/utils.js' ;
12
12
13
13
export interface ExtractAssetsParams {
@@ -22,7 +22,7 @@ export interface ExtractAssetsParams {
22
22
export function extractAssets ( params : ExtractAssetsParams ) : InputAsset [ ] {
23
23
const assetNodes = findAssets ( params . document ) ;
24
24
const allAssets : InputAsset [ ] = [ ] ;
25
- const isExternal = picomatch ( params . externalAssets || [ ] ) ;
25
+ const isExternal = createAssetPicomatchMatcher ( params . externalAssets ) ;
26
26
27
27
for ( const node of assetNodes ) {
28
28
const sourcePaths = getSourcePaths ( node ) ;
Original file line number Diff line number Diff line change 1
1
import { getAttribute , setAttribute } from '@web/parse5-utils' ;
2
2
import { Document } from 'parse5' ;
3
3
import path from 'path' ;
4
- import picomatch from 'picomatch' ;
5
4
6
5
import {
7
6
findAssets ,
8
7
getSourceAttribute ,
9
8
getSourcePaths ,
10
9
isHashedAsset ,
11
10
resolveAssetFilePath ,
11
+ createAssetPicomatchMatcher ,
12
12
} from '../assets/utils.js' ;
13
13
import { InputData } from '../input/InputData.js' ;
14
14
import { createError } from '../utils.js' ;
@@ -49,7 +49,7 @@ export function injectedUpdatedAssetPaths(args: InjectUpdatedAssetPathsArgs) {
49
49
absolutePathPrefix,
50
50
} = args ;
51
51
const assetNodes = findAssets ( document ) ;
52
- const isExternal = picomatch ( externalAssets || [ ] ) ;
52
+ const isExternal = createAssetPicomatchMatcher ( externalAssets ) ;
53
53
54
54
for ( const node of assetNodes ) {
55
55
const sourcePaths = getSourcePaths ( node ) ;
You can’t perform that action at this time.
0 commit comments