Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make initial ModuleInfo.meta mutable and maintain object identity (#4328
- Loading branch information
1 parent
a54b798
commit 2fea0d7
Showing
6 changed files
with
95 additions
and
8 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
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,66 @@ | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
|
||
let initialMeta; | ||
|
||
module.exports = { | ||
description: 'allows to freely modify moduleInfo.meta and maintain object identity', | ||
options: { | ||
plugins: [ | ||
{ | ||
name: 'first', | ||
buildStart() { | ||
this.load({ id: ID_MAIN }); | ||
initialMeta = this.getModuleInfo(ID_MAIN).meta; | ||
initialMeta.buildStart = true; | ||
}, | ||
load(id) { | ||
assert.strictEqual(id, ID_MAIN); | ||
const meta = this.getModuleInfo(ID_MAIN).meta; | ||
assert.deepStrictEqual(meta, { buildStart: true }, 'load'); | ||
assert.strictEqual(meta, initialMeta); | ||
meta.load1a = true; | ||
return { code: `assert.ok(true);`, meta: { load1b: true } }; | ||
}, | ||
transform(code, id) { | ||
assert.strictEqual(id, ID_MAIN); | ||
const meta = this.getModuleInfo(ID_MAIN).meta; | ||
assert.deepStrictEqual( | ||
meta, | ||
{ buildStart: true, load1a: true, load1b: true }, | ||
'transform' | ||
); | ||
assert.strictEqual(meta, initialMeta); | ||
meta.transform1a = true; | ||
return { code: `assert.ok(true);`, meta: { transform1b: true } }; | ||
}, | ||
buildEnd(error) { | ||
if (error) { | ||
throw error; | ||
} | ||
const meta = this.getModuleInfo(ID_MAIN).meta; | ||
assert.deepStrictEqual( | ||
meta, | ||
{ | ||
buildStart: true, | ||
load1a: true, | ||
load1b: true, | ||
transform1a: true, | ||
transform1b: true, | ||
transform2: true | ||
}, | ||
'buildEnd' | ||
); | ||
} | ||
}, | ||
{ | ||
name: 'second', | ||
transform(code, id) { | ||
assert.strictEqual(id, ID_MAIN); | ||
return { code: `assert.ok(true);`, meta: { transform2: true } }; | ||
} | ||
} | ||
] | ||
} | ||
}; |
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 @@ | ||
assert.ok(true); |
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