File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed
integration/plugins/sub-folder Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -88,13 +88,20 @@ class Bundler extends EventEmitter {
8888 this . packagers . add ( type , packager ) ;
8989 }
9090
91- loadPlugins ( ) {
91+ loadPlugins ( location = this . mainFile ) {
92+ let pkg ;
93+ try {
94+ pkg = localRequire ( './package.json' , location ) ;
95+ } catch ( err ) {
96+ if ( err . code === 'MODULE_NOT_FOUND' && location . length > 1 ) {
97+ return this . loadPlugins ( Path . join ( location , '..' ) ) ;
98+ }
99+ }
92100 try {
93- let pkg = localRequire ( './package.json' , this . mainFile ) ;
94101 let deps = Object . assign ( { } , pkg . dependencies , pkg . devDependencies ) ;
95102 for ( let dep in deps ) {
96103 if ( dep . startsWith ( 'parcel-plugin-' ) ) {
97- localRequire ( dep , this . mainFile ) ( this ) ;
104+ localRequire ( dep , location ) ( this ) ;
98105 }
99106 }
100107 } catch ( err ) {
Original file line number Diff line number Diff line change 1+ module . exports = require ( './test.txt' ) ;
Original file line number Diff line number Diff line change 1+ hello world
Original file line number Diff line number Diff line change @@ -14,4 +14,17 @@ describe('plugins', function() {
1414 let output = run ( b ) ;
1515 assert . equal ( output , 'hello world' ) ;
1616 } ) ;
17+
18+ it ( 'should load package.json from parent tree' , async function ( ) {
19+ let b = await bundle ( __dirname + '/integration/plugins/sub-folder/index.js' ) ;
20+
21+ assertBundleTree ( b , {
22+ name : 'index.js' ,
23+ assets : [ 'index.js' , 'test.txt' ] ,
24+ childBundles : [ ]
25+ } ) ;
26+
27+ let output = run ( b ) ;
28+ assert . equal ( output , 'hello world' ) ;
29+ } ) ;
1730} ) ;
You canβt perform that action at this time.
0 commit comments