@@ -143,6 +143,108 @@ let buildTests = {
143143 assert . strictEqual ( require ( bOut ) . y , true )
144144 } ,
145145
146+ async absPathsCodeTest ( { esbuild, testDir } ) {
147+ let srcDir = path . join ( testDir , 'src' ) ;
148+ let outfile = path . join ( testDir , 'out' , 'result.js' ) ;
149+ let entry = path . join ( srcDir , 'entry.js' ) ;
150+ fs . mkdirSync ( srcDir , { recursive : true } ) ;
151+ fs . writeFileSync ( entry , `x = typeof y == "null"` ) ;
152+
153+ const { metafile, warnings, outputFiles } = await esbuild . build ( {
154+ entryPoints : [ entry ] ,
155+ outfile,
156+ bundle : true ,
157+ write : false ,
158+ metafile : true ,
159+ format : 'cjs' ,
160+ logLevel : 'silent' ,
161+ absPaths : [ 'code' ] ,
162+ } )
163+ const cwd = process . cwd ( )
164+ const makePath = absPath => path . relative ( cwd , absPath ) . split ( path . sep ) . join ( '/' )
165+
166+ assert . strictEqual ( outputFiles . length , 1 )
167+ assert . deepStrictEqual ( outputFiles [ 0 ] . path , outfile )
168+ assert . deepStrictEqual ( outputFiles [ 0 ] . text , `// ${ entry } \nx = typeof y == "null";\n` )
169+
170+ assert . deepStrictEqual ( Object . keys ( metafile . inputs ) , [ makePath ( entry ) ] )
171+ assert . deepStrictEqual ( Object . keys ( metafile . outputs ) , [ makePath ( outfile ) ] )
172+ assert . strictEqual ( metafile . inputs [ makePath ( entry ) ] . imports . length , 0 )
173+ assert . strictEqual ( metafile . outputs [ makePath ( outfile ) ] . entryPoint , makePath ( entry ) )
174+
175+ assert . strictEqual ( warnings . length , 1 )
176+ assert . strictEqual ( warnings [ 0 ] . text , 'The "typeof" operator will never evaluate to "null"' )
177+ assert . strictEqual ( warnings [ 0 ] . location . file , makePath ( entry ) )
178+ } ,
179+
180+ async absPathsLogTest ( { esbuild, testDir } ) {
181+ let srcDir = path . join ( testDir , 'src' ) ;
182+ let outfile = path . join ( testDir , 'out' , 'result.js' ) ;
183+ let entry = path . join ( srcDir , 'entry.js' ) ;
184+ fs . mkdirSync ( srcDir , { recursive : true } ) ;
185+ fs . writeFileSync ( entry , `x = typeof y == "null"` ) ;
186+
187+ const { metafile, warnings, outputFiles } = await esbuild . build ( {
188+ entryPoints : [ entry ] ,
189+ outfile,
190+ bundle : true ,
191+ write : false ,
192+ metafile : true ,
193+ format : 'cjs' ,
194+ logLevel : 'silent' ,
195+ absPaths : [ 'log' ] ,
196+ } )
197+ const cwd = process . cwd ( )
198+ const makePath = absPath => path . relative ( cwd , absPath ) . split ( path . sep ) . join ( '/' )
199+
200+ assert . strictEqual ( outputFiles . length , 1 )
201+ assert . deepStrictEqual ( outputFiles [ 0 ] . path , outfile )
202+ assert . deepStrictEqual ( outputFiles [ 0 ] . text , `// ${ makePath ( entry ) } \nx = typeof y == "null";\n` )
203+
204+ assert . deepStrictEqual ( Object . keys ( metafile . inputs ) , [ makePath ( entry ) ] )
205+ assert . deepStrictEqual ( Object . keys ( metafile . outputs ) , [ makePath ( outfile ) ] )
206+ assert . strictEqual ( metafile . inputs [ makePath ( entry ) ] . imports . length , 0 )
207+ assert . strictEqual ( metafile . outputs [ makePath ( outfile ) ] . entryPoint , makePath ( entry ) )
208+
209+ assert . strictEqual ( warnings . length , 1 )
210+ assert . strictEqual ( warnings [ 0 ] . text , 'The "typeof" operator will never evaluate to "null"' )
211+ assert . strictEqual ( warnings [ 0 ] . location . file , entry )
212+ } ,
213+
214+ async absPathsMetafileTest ( { esbuild, testDir } ) {
215+ let srcDir = path . join ( testDir , 'src' ) ;
216+ let outfile = path . join ( testDir , 'out' , 'result.js' ) ;
217+ let entry = path . join ( srcDir , 'entry.js' ) ;
218+ fs . mkdirSync ( srcDir , { recursive : true } ) ;
219+ fs . writeFileSync ( entry , `x = typeof y == "null"` ) ;
220+
221+ const { metafile, warnings, outputFiles } = await esbuild . build ( {
222+ entryPoints : [ entry ] ,
223+ outfile,
224+ bundle : true ,
225+ write : false ,
226+ metafile : true ,
227+ format : 'cjs' ,
228+ logLevel : 'silent' ,
229+ absPaths : [ 'metafile' ] ,
230+ } )
231+ const cwd = process . cwd ( )
232+ const makePath = absPath => path . relative ( cwd , absPath ) . split ( path . sep ) . join ( '/' )
233+
234+ assert . strictEqual ( outputFiles . length , 1 )
235+ assert . deepStrictEqual ( outputFiles [ 0 ] . path , outfile )
236+ assert . deepStrictEqual ( outputFiles [ 0 ] . text , `// ${ makePath ( entry ) } \nx = typeof y == "null";\n` )
237+
238+ assert . deepStrictEqual ( Object . keys ( metafile . inputs ) , [ entry ] )
239+ assert . deepStrictEqual ( Object . keys ( metafile . outputs ) , [ outfile ] )
240+ assert . strictEqual ( metafile . inputs [ entry ] . imports . length , 0 )
241+ assert . strictEqual ( metafile . outputs [ outfile ] . entryPoint , entry )
242+
243+ assert . strictEqual ( warnings . length , 1 )
244+ assert . strictEqual ( warnings [ 0 ] . text , 'The "typeof" operator will never evaluate to "null"' )
245+ assert . strictEqual ( warnings [ 0 ] . location . file , makePath ( entry ) )
246+ } ,
247+
146248 async aliasValidity ( { esbuild } ) {
147249 const valid = async alias => {
148250 const result = await esbuild . build ( {
0 commit comments