@@ -15,18 +15,18 @@ process.chdir(fixture())
1515
1616test ( "Always ignores bundle entry point" , async t => {
1717 const context = await initPlugin ( )
18- t . is ( await context . resolveId ( './path/to/entry.js' , undefined ) , null )
18+ t . is ( await context . resolveId ( './path/to/entry.js' ) , null )
1919} )
2020
2121test ( "Always ignores virtual modules from other plugins" , async t => {
2222 const context = await initPlugin ( )
23- t . is ( await context . resolveId ( '\\0virtual' , undefined ) , null , `Failed without importer` )
24- t . is ( await context . resolveId ( '\\0virtual' , 'file.js' ) , null , `Failed with importer` )
23+ t . is ( await context . resolveId ( specifiers . virtual [ 0 ] , undefined ) , null , `Failed without importer` )
24+ t . is ( await context . resolveId ( specifiers . virtual [ 0 ] , 'file.js' ) , null , `Failed with importer` )
2525} )
2626
2727test ( "Always ignores absolute specifiers" , async t => {
2828 const context = await initPlugin ( )
29- for ( const specifier of specifiers [ process . platform === 'win32' ? ' absoluteWin32' : ' absolutePosix' ] ) {
29+ for ( const specifier of ( process . platform === 'win32' ? specifiers . absoluteWin32 : specifiers . absolutePosix ) ) {
3030 t . is ( await context . resolveId ( specifier , undefined ) , null , `Failed on: ${ specifier } without importer` )
3131 t . is ( await context . resolveId ( specifier , 'file.js' ) , null , `Failed on: ${ specifier } with importer` )
3232 }
@@ -47,7 +47,7 @@ test("Always ignores bare specifiers that are not dependencies", async t => {
4747
4848test ( "Marks dependencies external by default" , async t => {
4949 const context = await initPlugin ( )
50- t . false ( await context . resolveId ( 'test-dep' , 'index.js' ) )
50+ t . is ( await context . resolveId ( 'test-dep' , 'index.js' ) , false )
5151} )
5252
5353test ( "Does NOT mark dependencies external when deps=false" , async t => {
@@ -62,32 +62,32 @@ test("Does NOT mark excluded dependencies external", async t => {
6262
6363test ( "Marks peerDependencies external by default" , async t => {
6464 const context = await initPlugin ( )
65- t . is ( await context . resolveId ( 'test-dev -dep' , 'index.js' ) , null )
65+ t . is ( await context . resolveId ( 'test-peer -dep' , 'index.js' ) , false )
6666} )
6767
6868test ( "Does NOT mark peerDependencies external when peerDeps=false" , async t => {
6969 const context = await initPlugin ( { peerDeps : false } )
70- t . is ( await context . resolveId ( 'test-dev -dep' , 'index.js' ) , null )
70+ t . is ( await context . resolveId ( 'test-peer -dep' , 'index.js' ) , null )
7171} )
7272
7373test ( "Does NOT mark excluded peerDependencies external" , async t => {
7474 const context = await initPlugin ( { exclude : 'test-peer-dep' } )
75- t . is ( await context . resolveId ( 'test-dev -dep' , 'index.js' ) , null )
75+ t . is ( await context . resolveId ( 'test-peer -dep' , 'index.js' ) , null )
7676} )
7777
7878test ( "Marks optionalDependencies external by default" , async t => {
7979 const context = await initPlugin ( )
80- t . false ( await context . resolveId ( 'test-opt-dep' , 'index.js' ) )
80+ t . is ( await context . resolveId ( 'test-opt-dep' , 'index.js' ) , false )
8181} )
8282
8383test ( "Does NOT mark optionalDependencies external when optDeps=false" , async t => {
8484 const context = await initPlugin ( { optDeps : false } )
85- t . is ( await context . resolveId ( 'test-dev -dep' , 'index.js' ) , null )
85+ t . is ( await context . resolveId ( 'test-opt -dep' , 'index.js' ) , null )
8686} )
8787
8888test ( "Does NOT mark excluded optionalDependencies external" , async t => {
8989 const context = await initPlugin ( { exclude : 'test-opt-dep' } )
90- t . is ( await context . resolveId ( 'test-dev -dep' , 'index.js' ) , null )
90+ t . is ( await context . resolveId ( 'test-opt -dep' , 'index.js' ) , null )
9191} )
9292
9393test ( "Does NOT mark devDependencies external by default" , async t => {
@@ -97,30 +97,44 @@ test("Does NOT mark devDependencies external by default", async t => {
9797
9898test ( "Marks devDependencies external when devDeps=true" , async t => {
9999 const context = await initPlugin ( { devDeps : true } )
100- t . false ( await context . resolveId ( 'test-dev-dep' , 'index.js' ) )
100+ t . is ( await context . resolveId ( 'test-dev-dep' , 'index.js' ) , false )
101101} )
102102
103103test ( "Marks included devDependencies external" , async t => {
104104 const context = await initPlugin ( { include : 'test-dev-dep' } )
105- t . false ( await context . resolveId ( 'test-dev-dep' , 'index.js' ) )
105+ t . is ( await context . resolveId ( 'test-dev-dep' , 'index.js' ) , false )
106106} )
107107
108- test ( "Marks dependencies/peerDependencies/optionalDependencies subpath imports external" , async t => {
108+ test ( "Subpath imports do not prevent dependencies/peerDependencies/optionalDependencies from being marked external" , async t => {
109109 const context = await initPlugin ( )
110110 t . is ( await context . resolveId ( 'test-dep/sub' , 'index.js' ) , false )
111111 t . is ( await context . resolveId ( 'test-peer-dep/sub' , 'index.js' ) , false )
112112 t . is ( await context . resolveId ( 'test-opt-dep/sub' , 'index.js' ) , false )
113113} )
114114
115- test ( "Marks subpath imports external (with regexes )" , async t => {
115+ test ( "Marks both dependency and dependency/ subpath as external (with regex )" , async t => {
116116 const context = await initPlugin ( { include : / ^ t e s t - d e v - d e p / } )
117117 t . is ( await context . resolveId ( 'test-dev-dep' , 'index.js' ) , false )
118118 t . is ( await context . resolveId ( 'test-dev-dep/sub' , 'index.js' ) , false )
119119} )
120120
121- test ( "External dependencies have precedence over devDependencies" , async t => {
122- const context = await initPlugin ( {
123- packagePath : '04_dual/package.json'
124- } )
125- t . false ( await context . resolveId ( 'dual-dep' , 'index.js' ) )
121+ test ( "exclude has precedence over include (builtins)" , async t => {
122+ const context = await initPlugin ( { include : 'node:fs' , exclude : 'node:fs' } )
123+ t . like ( await context . resolveId ( 'node:fs' , 'index.js' ) , { external : false } )
124+ } )
125+
126+ test ( "exclude has precedence over include (dependencies)" , async t => {
127+ const context = await initPlugin ( { include : 'test-dep' , exclude : 'test-dep' } )
128+ t . is ( await context . resolveId ( 'test-dep' , 'index.js' ) , null )
129+ } )
130+
131+ test ( "exclude has precedence over include (with regexes)" , async t => {
132+ const context = await initPlugin ( { devDeps : true , exclude : / ^ t e s t - d e v - d e p \/ s u b / } )
133+ t . is ( await context . resolveId ( 'test-dev-dep' , 'index.js' ) , false )
134+ t . is ( await context . resolveId ( 'test-dev-dep/sub' , 'index.js' ) , null )
135+ } )
136+
137+ test ( "Normal dependencies have precedence over devDependencies" , async t => {
138+ const context = await initPlugin ( { packagePath : '04_dual/package.json' } )
139+ t . is ( await context . resolveId ( 'dual-dep' , 'index.js' ) , false )
126140} )
0 commit comments