Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use entryFileNames when generating filenames for virtual modules (#4270)
* Use entryFileNames for virtual files when preserveModules is set * Fix existing tests - virtual files now have a .js extension by default - systemjs module references include this file extension - amd module references omit this file extension. this seems to be consistent with amd output of other chunks * Add new test for virtual file output when modifying entryFileNames Use entryFileNames to change the extension of the filename to be mjs, and see that the file created from the virtual file chunk has a .mjs extension Note that the amd definition contains the .mjs extension, as amd ids only strip the .js file extension, which is slightly odd but probably ok as this amd is not the targetted usecase for this behaviour * Refactor - don't repeat pattern generation logic
- Loading branch information
Showing
69 changed files
with
234 additions
and
55 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
File renamed without changes.
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/deprecated/preserve-modules-commonjs/_expected/cjs/other.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/deprecated/preserve-modules-commonjs/_expected/es/commonjs.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
4 changes: 2 additions & 2 deletions
4
test/chunking-form/samples/deprecated/preserve-modules-commonjs/_expected/es/other.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { __exports as other } from './_virtual/other.js_commonjs-exports'; | ||
export { __exports as default } from './_virtual/other.js_commonjs-exports'; | ||
import { __exports as other } from './_virtual/other.js_commonjs-exports.js'; | ||
export { __exports as default } from './_virtual/other.js_commonjs-exports.js'; | ||
|
||
other.value = 43; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/deprecated/preserve-modules-commonjs/_expected/system/commonjs.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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/deprecated/preserve-modules-commonjs/_expected/system/other.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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/deprecated/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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use strict'; | ||
|
||
var _virtualModule = require('./_virtual/_virtualModule'); | ||
var _virtualModule = require('./_virtual/_virtualModule.js'); | ||
|
||
assert.equal(_virtualModule.virtual, 'Virtual!'); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/deprecated/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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { virtual } from './_virtual/_virtualModule'; | ||
import { virtual } from './_virtual/_virtualModule.js'; | ||
|
||
assert.equal(virtual, 'Virtual!'); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...hunking-form/samples/deprecated/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
File renamed without changes.
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-commonjs/_expected/cjs/other.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-commonjs/_expected/es/commonjs.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
4 changes: 2 additions & 2 deletions
4
test/chunking-form/samples/preserve-modules-commonjs/_expected/es/other.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { __exports as other } from './_virtual/other.js_commonjs-exports'; | ||
export { __exports as default } from './_virtual/other.js_commonjs-exports'; | ||
import { __exports as other } from './_virtual/other.js_commonjs-exports.js'; | ||
export { __exports as default } from './_virtual/other.js_commonjs-exports.js'; | ||
|
||
other.value = 43; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-commonjs/_expected/system/commonjs.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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-commonjs/_expected/system/other.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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-root/_expected/cjs/below/module.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
2 changes: 1 addition & 1 deletion
2
...samples/preserve-modules-root/_expected/cjs/custom_modules/@my-scope/my-base-pkg/index.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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-root/_expected/cjs/under-build.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-root/_expected/es/below/module.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
4 changes: 2 additions & 2 deletions
4
.../samples/preserve-modules-root/_expected/es/custom_modules/@my-scope/my-base-pkg/index.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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-root/_expected/es/under-build.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-root/_expected/system/below/module.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
2 changes: 1 addition & 1 deletion
2
...ples/preserve-modules-root/_expected/system/custom_modules/@my-scope/my-base-pkg/index.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
2 changes: 1 addition & 1 deletion
2
test/chunking-form/samples/preserve-modules-root/_expected/system/under-build.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
34 changes: 34 additions & 0 deletions
34
test/chunking-form/samples/preserve-modules-virtual-modules-filename-pattern/_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,34 @@ | ||
module.exports = { | ||
description: | ||
'Generates actual files whose filename adheres to entryFileNames for virtual modules when preserving modules', | ||
options: { | ||
input: 'main.js', | ||
output: { | ||
preserveModules: true, | ||
entryFileNames: 'entry-[name]-[format]-[ext][extname][assetExtname].mjs' | ||
}, | ||
plugins: [ | ||
{ | ||
resolveId(id) { | ||
if (id === '\0virtualModule') return id; | ||
if (id === '\0virtualWithExt.js') return id; | ||
if (id === '\0virtualWithAssetExt.str') return id; | ||
}, | ||
load(id) { | ||
if (id === '\0virtualModule') return 'export const virtual = "Virtual!";\n'; | ||
if (id === '\0virtualWithExt.js') return 'export const virtual2 = "Virtual2!";\n'; | ||
if (id === '\0virtualWithAssetExt.str') return 'export const virtual3 = "Virtual3!";\n'; | ||
}, | ||
transform(code, id) { | ||
if (id === '\0virtualModule') return null; | ||
if (id === '\0virtualWithExt.js') return null; | ||
if (id === '\0virtualWithAssetExt.str') return null; | ||
return ( | ||
'import {virtual} from "\0virtualModule";\nimport {virtual2} from "\0virtualWithExt.js";\nimport {virtual3} from "\0virtualWithAssetExt.str";' + | ||
code | ||
); | ||
} | ||
} | ||
] | ||
} | ||
}; |
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
...es-filename-pattern/_expected/amd/_virtual/entry-_virtualWithAssetExt-amd-str.str.str.mjs
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,9 @@ | ||
define(['exports'], (function (exports) { 'use strict'; | ||
|
||
const virtual3 = "Virtual3!"; | ||
|
||
exports.virtual3 = virtual3; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
})); |
9 changes: 9 additions & 0 deletions
9
...rtual-modules-filename-pattern/_expected/amd/_virtual/entry-_virtualWithExt-amd-js.js.mjs
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,9 @@ | ||
define(['exports'], (function (exports) { 'use strict'; | ||
|
||
const virtual2 = "Virtual2!"; | ||
|
||
exports.virtual2 = virtual2; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
})); |
7 changes: 7 additions & 0 deletions
7
.../preserve-modules-virtual-modules-filename-pattern/_expected/amd/entry-main-amd-js.js.mjs
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(['./_virtual/entry-_virtualModule-amd-.mjs', './_virtual/entry-_virtualWithExt-amd-js.js.mjs', './_virtual/entry-_virtualWithAssetExt-amd-str.str.str.mjs'], (function (_virtualModule, _virtualWithExt, _virtualWithAssetExt) { 'use strict'; | ||
|
||
assert.equal(_virtualModule.virtual, 'Virtual!'); | ||
assert.equal(_virtualWithExt.virtual2, 'Virtual2!'); | ||
assert.equal(_virtualWithAssetExt.virtual3, 'Virtual3!'); | ||
|
||
})); |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...es-filename-pattern/_expected/cjs/_virtual/entry-_virtualWithAssetExt-cjs-str.str.str.mjs
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 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
const virtual3 = "Virtual3!"; | ||
|
||
exports.virtual3 = virtual3; |
7 changes: 7 additions & 0 deletions
7
...rtual-modules-filename-pattern/_expected/cjs/_virtual/entry-_virtualWithExt-cjs-js.js.mjs
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 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
const virtual2 = "Virtual2!"; | ||
|
||
exports.virtual2 = virtual2; |
9 changes: 9 additions & 0 deletions
9
.../preserve-modules-virtual-modules-filename-pattern/_expected/cjs/entry-main-cjs-js.js.mjs
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,9 @@ | ||
'use strict'; | ||
|
||
var _virtualModule = require('./_virtual/entry-_virtualModule-cjs-.mjs'); | ||
var _virtualWithExt = require('./_virtual/entry-_virtualWithExt-cjs-js.js.mjs'); | ||
var _virtualWithAssetExt = require('./_virtual/entry-_virtualWithAssetExt-cjs-str.str.str.mjs'); | ||
|
||
assert.equal(_virtualModule.virtual, 'Virtual!'); | ||
assert.equal(_virtualWithExt.virtual2, 'Virtual2!'); | ||
assert.equal(_virtualWithAssetExt.virtual3, 'Virtual3!'); |
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
...ules-filename-pattern/_expected/es/_virtual/entry-_virtualWithAssetExt-es-str.str.str.mjs
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 virtual3 = "Virtual3!"; | ||
|
||
export { virtual3 }; |
3 changes: 3 additions & 0 deletions
3
...virtual-modules-filename-pattern/_expected/es/_virtual/entry-_virtualWithExt-es-js.js.mjs
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 virtual2 = "Virtual2!"; | ||
|
||
export { virtual2 }; |
7 changes: 7 additions & 0 deletions
7
...es/preserve-modules-virtual-modules-filename-pattern/_expected/es/entry-main-es-js.js.mjs
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 @@ | ||
import { virtual } from './_virtual/entry-_virtualModule-es-.mjs'; | ||
import { virtual2 } from './_virtual/entry-_virtualWithExt-es-js.js.mjs'; | ||
import { virtual3 } from './_virtual/entry-_virtualWithAssetExt-es-str.str.str.mjs'; | ||
|
||
assert.equal(virtual, 'Virtual!'); | ||
assert.equal(virtual2, 'Virtual2!'); | ||
assert.equal(virtual3, 'Virtual3!'); |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
...ename-pattern/_expected/system/_virtual/entry-_virtualWithAssetExt-system-str.str.str.mjs
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) { | ||
'use strict'; | ||
return { | ||
execute: (function () { | ||
|
||
const virtual3 = exports('virtual3', "Virtual3!"); | ||
|
||
}) | ||
}; | ||
})); |
10 changes: 10 additions & 0 deletions
10
...modules-filename-pattern/_expected/system/_virtual/entry-_virtualWithExt-system-js.js.mjs
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) { | ||
'use strict'; | ||
return { | ||
execute: (function () { | ||
|
||
const virtual2 = exports('virtual2', "Virtual2!"); | ||
|
||
}) | ||
}; | ||
})); |
20 changes: 20 additions & 0 deletions
20
...rve-modules-virtual-modules-filename-pattern/_expected/system/entry-main-system-js.js.mjs
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,20 @@ | ||
System.register(['./_virtual/entry-_virtualModule-system-.mjs', './_virtual/entry-_virtualWithExt-system-js.js.mjs', './_virtual/entry-_virtualWithAssetExt-system-str.str.str.mjs'], (function () { | ||
'use strict'; | ||
var virtual, virtual2, virtual3; | ||
return { | ||
setters: [function (module) { | ||
virtual = module.virtual; | ||
}, function (module) { | ||
virtual2 = module.virtual2; | ||
}, function (module) { | ||
virtual3 = module.virtual3; | ||
}], | ||
execute: (function () { | ||
|
||
assert.equal(virtual, 'Virtual!'); | ||
assert.equal(virtual2, 'Virtual2!'); | ||
assert.equal(virtual3, 'Virtual3!'); | ||
|
||
}) | ||
}; | ||
})); |
3 changes: 3 additions & 0 deletions
3
test/chunking-form/samples/preserve-modules-virtual-modules-filename-pattern/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 @@ | ||
assert.equal(virtual, 'Virtual!'); | ||
assert.equal(virtual2, 'Virtual2!'); | ||
assert.equal(virtual3, 'Virtual3!'); |
9 changes: 9 additions & 0 deletions
9
...ng-form/samples/preserve-modules-virtual-modules/_expected/amd/_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,9 @@ | ||
define(['exports'], (function (exports) { 'use strict'; | ||
|
||
const virtual = "Virtual!"; | ||
|
||
exports.virtual = virtual; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
})); |
7 changes: 7 additions & 0 deletions
7
...ng-form/samples/preserve-modules-virtual-modules/_expected/cjs/_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,7 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
const virtual = "Virtual!"; | ||
|
||
exports.virtual = virtual; |
Oops, something went wrong.