@@ -1890,6 +1890,112 @@ describe ('API: Plugin Context', () => {
18901890 fs . reset ( ) ;
18911891 } ) ;
18921892
1893+ it ( 'should accept custom for options' , async ( ) => {
1894+ fs . stub ( './src/main.js' , ( ) => 'export default 123' ) ;
1895+ fs . stub ( './src/lol.js' , ( ) => 'export default 456' ) ;
1896+ let passed = false ;
1897+
1898+ let bundle = await nollup ( {
1899+ input : './src/main.js' ,
1900+ plugins : [ {
1901+ resolveId ( importee , importer , options ) {
1902+ if ( importee . indexOf ( 'lol' ) > - 1 ) {
1903+ expect ( options . isEntry ) . to . be . false ;
1904+ expect ( options . custom ) . to . deep . equal ( { hello : 'world' } )
1905+ passed = true ;
1906+ }
1907+ } ,
1908+
1909+ transform ( ) {
1910+ return new Promise ( resolve => {
1911+ this . resolve (
1912+ './lol' ,
1913+ path . resolve ( process . cwd ( ) , './src/main.js' ) ,
1914+ { custom : { hello : 'world' } }
1915+ ) . then ( resolved => {
1916+ resolve ( ) ;
1917+ } ) ;
1918+ } ) ;
1919+ }
1920+ } ]
1921+ } ) ;
1922+
1923+ let { output } = await bundle . generate ( { format : 'esm' } ) ;
1924+ expect ( passed ) . to . be . true ;
1925+ fs . reset ( ) ;
1926+ } ) ;
1927+
1928+ it ( 'should accept isEntry for options' , async ( ) => {
1929+ fs . stub ( './src/main.js' , ( ) => 'export default 123' ) ;
1930+ fs . stub ( './src/lol.js' , ( ) => 'export default 456' ) ;
1931+ let passed = false ;
1932+
1933+ let bundle = await nollup ( {
1934+ input : './src/main.js' ,
1935+ plugins : [ {
1936+ resolveId ( importee , importer , options ) {
1937+ if ( importee . indexOf ( 'lol' ) > - 1 ) {
1938+ expect ( options . isEntry ) . to . be . true ;
1939+ expect ( options . custom ) . to . be . undefined ;
1940+ passed = true ;
1941+ }
1942+ } ,
1943+
1944+ transform ( ) {
1945+ return new Promise ( resolve => {
1946+ this . resolve (
1947+ './lol' ,
1948+ path . resolve ( process . cwd ( ) , './src/main.js' ) ,
1949+ { isEntry : true }
1950+ ) . then ( resolved => {
1951+ resolve ( ) ;
1952+ } ) ;
1953+ } ) ;
1954+ }
1955+ } ]
1956+ } ) ;
1957+
1958+ let { output } = await bundle . generate ( { format : 'esm' } ) ;
1959+ expect ( passed ) . to . be . true ;
1960+ fs . reset ( ) ;
1961+ } ) ;
1962+
1963+ it ( 'should not have skipSelf for options in resolveId' , async ( ) => {
1964+ fs . stub ( './src/main.js' , ( ) => 'export default 123' ) ;
1965+ fs . stub ( './src/lol.js' , ( ) => 'export default 456' ) ;
1966+ let passed = false ;
1967+
1968+ let bundle = await nollup ( {
1969+ input : './src/main.js' ,
1970+ plugins : [ {
1971+ resolveId ( importee , importer , options ) {
1972+ if ( importee . indexOf ( 'lol' ) > - 1 ) {
1973+ expect ( options . isEntry ) . to . be . false ;
1974+ expect ( options . custom ) . to . be . undefined ;
1975+ expect ( options . skipSelf ) . to . be . undefined ;
1976+ passed = true ;
1977+ }
1978+ }
1979+ } , {
1980+ transform ( ) {
1981+ return new Promise ( resolve => {
1982+ this . resolve (
1983+ './lol' ,
1984+ path . resolve ( process . cwd ( ) , './src/main.js' ) ,
1985+ { skipSelf : true }
1986+ ) . then ( resolved => {
1987+ resolve ( ) ;
1988+ } ) ;
1989+ } ) ;
1990+ }
1991+ } ]
1992+ } ) ;
1993+
1994+ let { output } = await bundle . generate ( { format : 'esm' } ) ;
1995+ expect ( passed ) . to . be . true ;
1996+ fs . reset ( ) ;
1997+ } ) ;
1998+
18931999 it ( 'should return null if module cannot be resolved by anyone and isn\'t external' ) ;
18942000
18952001 } ) ;
0 commit comments