@@ -26,7 +26,22 @@ function createTransformStream(flushFn, entryPoints) {
2626 return cb ( createError ( new TypeError ( 'File should be a buffer' ) ) )
2727 }
2828
29- entryPoints . push ( file )
29+ // What is going on?
30+ //
31+ // The problem attaches incrementalBuild. Because of rebuild context creates once,
32+ // resolvePlugin doesn't receive updated virtual files. We moved variable `entryPoints`
33+ // to a higher level so the plugin could receive actual files by reference.
34+ //
35+ // But now entryPoints doesn't reset its state and stores all files for every rebuilt.
36+ // This code searches existed files and updates their contents.
37+ const fileIndex = entryPoints . findIndex ( ( cfile ) => cfile . path === file . path )
38+
39+ if ( fileIndex >= 0 ) {
40+ entryPoints [ fileIndex ] = file
41+ } else {
42+ entryPoints . push ( file )
43+ }
44+
3045 cb ( null )
3146 } ,
3247 flush : flushFn ,
@@ -57,6 +72,7 @@ function simpleBuild() {
5772 const { metafileName, esbuildOptions} = splitOptions ( pluginOptions )
5873
5974 async function flushFunction ( cb ) {
75+ /** @type import('esbuild').BuildOptions */
6076 const params = {
6177 logLevel : 'silent' ,
6278 ...esbuildOptions ,
@@ -105,14 +121,16 @@ function simpleBuild() {
105121}
106122
107123function incrementalBuild ( ) {
124+ /** @type import('esbuild').BuildContext */
108125 let ctx
126+ /** @type Array<import('vinyl').BufferFile> */
127+ const entryPoints = [ ]
109128
110129 return function plugin ( pluginOptions = { } ) {
111- /** @type Array<import('vinyl').BufferFile> */
112- const entryPoints = [ ]
113130 const { metafileName, esbuildOptions} = splitOptions ( pluginOptions )
114131
115132 async function flushFunction ( cb ) {
133+ /** @type import('esbuild').BuildOptions */
116134 const params = {
117135 logLevel : 'silent' ,
118136 ...esbuildOptions ,
0 commit comments