File tree Expand file tree Collapse file tree 2 files changed +42
-10
lines changed Expand file tree Collapse file tree 2 files changed +42
-10
lines changed Original file line number Diff line number Diff line change @@ -189,8 +189,10 @@ export class UserscriptPlugin
189
189
) ,
190
190
) ;
191
191
192
- for ( const { originalFile } of context . fileInfo ) {
193
- compilation . deleteAsset ( originalFile ) ;
192
+ for ( const { originalFile, userjsFile } of context . fileInfo ) {
193
+ if ( originalFile !== userjsFile ) {
194
+ compilation . deleteAsset ( originalFile ) ;
195
+ }
194
196
}
195
197
196
198
await this . hooks . process . promise ( compilation , context ) ;
@@ -300,14 +302,24 @@ export class UserscriptPlugin
300
302
? await this . hooks . renderProxyHeaders . promise ( proxyHeaders )
301
303
: undefined ;
302
304
303
- compilation . emitAsset (
304
- userjsFile ,
305
- new ConcatSource ( headersStr , '\n' , sourceAsset . source ) ,
306
- {
307
- minimized : true ,
308
- } ,
309
- ) ;
310
- chunk . files . add ( userjsFile ) ;
305
+ if ( userjsFile !== originalFile ) {
306
+ compilation . emitAsset (
307
+ userjsFile ,
308
+ new ConcatSource ( headersStr , '\n' , sourceAsset . source ) ,
309
+ {
310
+ minimized : true ,
311
+ } ,
312
+ ) ;
313
+ chunk . files . add ( userjsFile ) ;
314
+ } else {
315
+ compilation . updateAsset (
316
+ userjsFile ,
317
+ new ConcatSource ( headersStr , '\n' , sourceAsset . source ) ,
318
+ {
319
+ minimized : true ,
320
+ } ,
321
+ ) ;
322
+ }
311
323
312
324
if ( metajs !== false ) {
313
325
compilation . emitAsset ( metajsFile , new RawSource ( headersStr ) , {
Original file line number Diff line number Diff line change @@ -40,4 +40,24 @@ describe('general', () => {
40
40
'/dist/output.js' : Fixtures . entryMinJs ,
41
41
} ) ;
42
42
} ) ;
43
+
44
+ // eslint-disable-next-line max-len
45
+ it ( 'should successfully compile even the file extension is .user.js' , async ( ) => {
46
+ input . renameSync ( '/entry.js' , '/entry.user.js' ) ;
47
+
48
+ const output = await compile ( input , {
49
+ ...Fixtures . webpackConfig ,
50
+ entry : '/entry.user.js' ,
51
+ output : {
52
+ path : '/dist' ,
53
+ filename : 'output.user.js' ,
54
+ } ,
55
+ plugins : [ new UserscriptPlugin ( ) ] ,
56
+ } ) ;
57
+
58
+ expect ( output . toJSON ( ) ) . toEqual ( {
59
+ '/dist/output.user.js' : Fixtures . entryUserJs ( Fixtures . headers ) ,
60
+ '/dist/output.meta.js' : Fixtures . headers ,
61
+ } ) ;
62
+ } ) ;
43
63
} ) ;
You can’t perform that action at this time.
0 commit comments