-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose Graph information for pluginContext calls (#2565)
* Expose graph module information for plugins. * Refactor plugin module information and add test * Add test that early access to moduleIds and module information is handled gracefully
- Loading branch information
1 parent
7924d35
commit 1ef9f6b
Showing
9 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
test/function/samples/plugin-module-information-early-access/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
|
||
module.exports = { | ||
description: 'handles accessing module information via plugins early in a graceful way', | ||
options: { | ||
external: ['path'], | ||
plugins: [ | ||
{ | ||
buildStart() { | ||
assert.deepEqual(Array.from(this.moduleIds), []); | ||
// should throw "not found" error | ||
this.getModuleInfo(ID_MAIN); | ||
} | ||
} | ||
] | ||
}, | ||
error: { | ||
code: 'PLUGIN_ERROR', | ||
hook: 'buildStart', | ||
message: `Unable to find module ${ID_MAIN}`, | ||
plugin: 'Plugin at pos 0' | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
test/function/samples/plugin-module-information-early-access/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 42; |
47 changes: 47 additions & 0 deletions
47
test/function/samples/plugin-module-information/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
|
||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
const ID_FOO = path.join(__dirname, 'foo.js'); | ||
const ID_NESTED = path.join(__dirname, 'nested', 'nested.js'); | ||
const ID_PATH = 'path'; | ||
|
||
let rendered = false; | ||
|
||
module.exports = { | ||
description: 'provides module information on the plugin context', | ||
options: { | ||
external: ['path'], | ||
plugins: [ | ||
{ | ||
renderStart() { | ||
rendered = true; | ||
assert.deepEqual(Array.from(this.moduleIds), [ID_MAIN, ID_FOO, ID_NESTED, ID_PATH]); | ||
assert.deepEqual(this.getModuleInfo(ID_MAIN), { | ||
id: ID_MAIN, | ||
importedIds: [ID_FOO, ID_NESTED], | ||
isExternal: false | ||
}); | ||
assert.deepEqual(this.getModuleInfo(ID_FOO), { | ||
id: ID_FOO, | ||
importedIds: [ID_PATH], | ||
isExternal: false | ||
}); | ||
assert.deepEqual(this.getModuleInfo(ID_NESTED), { | ||
id: ID_NESTED, | ||
importedIds: [ID_FOO], | ||
isExternal: false | ||
}); | ||
assert.deepEqual(this.getModuleInfo(ID_PATH), { | ||
id: ID_PATH, | ||
importedIds: [], | ||
isExternal: true | ||
}); | ||
} | ||
} | ||
] | ||
}, | ||
bundle() { | ||
assert.ok(rendered); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import path from 'path'; | ||
|
||
export const foo = path.resolve('foo'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export {foo} from './foo.js'; | ||
import { nested } from './nested/nested'; | ||
|
||
export {nested}; |
3 changes: 3 additions & 0 deletions
3
test/function/samples/plugin-module-information/nested/nested.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { foo } from '../foo.js'; | ||
|
||
export const nested = 'nested' + foo; |