Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create chunks for virtual modules when preserving modules (#2511)
* Create test * Enable functional tests with code-splitting and add red code splitting module order test * Sort external and inter-chunk imports according to execution order * Extract execution order sorting, improve some names and clean up code * Extract module execution order analysis from Graph * Create chunks for virtual modules when preserving modules * Automatically deconflict virtual modules from existing ones
- Loading branch information
1 parent
fa341ab
commit 7746e0f
Showing
23 changed files
with
195 additions
and
22 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
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
23 changes: 23 additions & 0 deletions
23
test/chunking-form/samples/preserve-modules-virtual-modules/_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,23 @@ | ||
module.exports = { | ||
solo: true, | ||
description: 'Generates actual files for virtual modules when preserving modules', | ||
options: { | ||
input: 'main.js', | ||
experimentalPreserveModules: true, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id === '\0virtualModule') return id; | ||
}, | ||
load(id) { | ||
if (id !== '\0virtualModule') return null; | ||
return 'export const virtual = "Virtual!";\n'; | ||
}, | ||
transform(code, id) { | ||
if (id === '\0virtualModule') return null; | ||
return 'import {virtual} from "\0virtualModule";\n' + code; | ||
} | ||
} | ||
] | ||
} | ||
}; |
7 changes: 7 additions & 0 deletions
7
...nking-form/samples/preserve-modules-virtual-modules/_expected/amd/_virtual/_virtualModule
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,7 @@ | ||
define(['exports'], function (exports) { 'use strict'; | ||
|
||
const virtual = "Virtual!"; | ||
|
||
exports.virtual = virtual; | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/preserve-modules-virtual-modules/_expected/amd/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,5 @@ | ||
define(['./_virtual/_virtualModule'], function (__chunk_1) { 'use strict'; | ||
|
||
assert.equal(__chunk_1.virtual, 'Virtual!'); | ||
|
||
}); |
5 changes: 5 additions & 0 deletions
5
...nking-form/samples/preserve-modules-virtual-modules/_expected/cjs/_virtual/_virtualModule
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,5 @@ | ||
'use strict'; | ||
|
||
const virtual = "Virtual!"; | ||
|
||
exports.virtual = virtual; |
5 changes: 5 additions & 0 deletions
5
test/chunking-form/samples/preserve-modules-virtual-modules/_expected/cjs/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,5 @@ | ||
'use strict'; | ||
|
||
var __chunk_1 = require('./_virtual/_virtualModule'); | ||
|
||
assert.equal(__chunk_1.virtual, 'Virtual!'); |
3 changes: 3 additions & 0 deletions
3
...unking-form/samples/preserve-modules-virtual-modules/_expected/es/_virtual/_virtualModule
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 @@ | ||
const virtual = "Virtual!"; | ||
|
||
export { virtual }; |
3 changes: 3 additions & 0 deletions
3
test/chunking-form/samples/preserve-modules-virtual-modules/_expected/es/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,3 @@ | ||
import { virtual } from './_virtual/_virtualModule'; | ||
|
||
assert.equal(virtual, 'Virtual!'); |
10 changes: 10 additions & 0 deletions
10
...ng-form/samples/preserve-modules-virtual-modules/_expected/system/_virtual/_virtualModule
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,10 @@ | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
const virtual = exports('virtual', "Virtual!"); | ||
|
||
} | ||
}; | ||
}); |
14 changes: 14 additions & 0 deletions
14
test/chunking-form/samples/preserve-modules-virtual-modules/_expected/system/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,14 @@ | ||
System.register(['./_virtual/_virtualModule'], function (exports, module) { | ||
'use strict'; | ||
var virtual; | ||
return { | ||
setters: [function (module) { | ||
virtual = module.virtual; | ||
}], | ||
execute: function () { | ||
|
||
assert.equal(virtual, 'Virtual!'); | ||
|
||
} | ||
}; | ||
}); |
1 change: 1 addition & 0 deletions
1
test/chunking-form/samples/preserve-modules-virtual-modules/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 @@ | ||
assert.equal(virtual, 'Virtual!'); |
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
36 changes: 36 additions & 0 deletions
36
test/function/samples/preserve-modules-virtual-modules-conflict/_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,36 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'Generates actual files for virtual modules when preserving modules', | ||
options: { | ||
input: ['main.js'], | ||
experimentalCodeSplitting: true, | ||
experimentalPreserveModules: true, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id === '\0virtualModule.js') return id; | ||
}, | ||
load(id) { | ||
if (id !== '\0virtualModule.js') return null; | ||
return 'export const virtual = "Virtual!";\n'; | ||
}, | ||
transform(code, id) { | ||
if (id === '\0virtualModule.js') return null; | ||
return 'import {virtual} from "\0virtualModule.js";\n' + code; | ||
} | ||
} | ||
] | ||
}, | ||
bundle(bundle) { | ||
return bundle | ||
.generate({ format: 'esm' }) | ||
.then(generated => | ||
assert.deepEqual(Object.keys(generated.output), [ | ||
'_virtual/_virtualModule.js', | ||
'_virtual/_virtualModule2.js', | ||
'main.js' | ||
]) | ||
); | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/function/samples/preserve-modules-virtual-modules-conflict/_virtual/_virtualModule.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 @@ | ||
export const notSoVirtual = 'real'; | ||
|
||
assert.equal(virtual, 'Virtual!'); |
4 changes: 4 additions & 0 deletions
4
test/function/samples/preserve-modules-virtual-modules-conflict/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,4 @@ | ||
import { notSoVirtual } from './_virtual/_virtualModule'; | ||
|
||
assert.equal(virtual, 'Virtual!'); | ||
assert.equal(notSoVirtual, 'real'); |
36 changes: 36 additions & 0 deletions
36
test/function/samples/preserve-modules-virtual-modules/_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,36 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'Generates actual files for virtual modules when preserving modules', | ||
options: { | ||
input: ['main.js'], | ||
experimentalCodeSplitting: true, | ||
experimentalPreserveModules: true, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id === '\0virtualModule') return id; | ||
}, | ||
load(id) { | ||
if (id !== '\0virtualModule') return null; | ||
return 'export const virtual = "Virtual!";\n'; | ||
}, | ||
transform(code, id) { | ||
if (id === '\0virtualModule') return null; | ||
return 'import {virtual} from "\0virtualModule";\n' + code; | ||
} | ||
} | ||
] | ||
}, | ||
bundle(bundle) { | ||
return bundle | ||
.generate({ format: 'esm' }) | ||
.then(generated => | ||
assert.deepEqual(Object.keys(generated.output), [ | ||
'_virtual/_virtualModule', | ||
'lib/lib.js', | ||
'main.js' | ||
]) | ||
); | ||
} | ||
}; |
1 change: 1 addition & 0 deletions
1
test/function/samples/preserve-modules-virtual-modules/lib/lib.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 @@ | ||
assert.equal(virtual, 'Virtual!'); |
3 changes: 3 additions & 0 deletions
3
test/function/samples/preserve-modules-virtual-modules/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,3 @@ | ||
import './lib/lib.js'; | ||
|
||
assert.equal(virtual, 'Virtual!'); |
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