Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to keep extensions for amd (#4607)
* feat: add option to keep extensions for amd * update extension resolving for amd * add tests * fix 'output-options-hook' test * add docs * Update docs/999-big-list-of-options.md * Change extension name to forceJsExtensionForImports * Improve coverage Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com> Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
eb1fab7
commit 71eefd1
Showing
20 changed files
with
130 additions
and
16 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
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 default function addJsExtension(name: string): string { | ||
return name.endsWith('.js') ? name : name + '.js'; | ||
} |
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
import addJsExtension from './addJsExtension'; | ||
import removeJsExtension from './removeJsExtension'; | ||
|
||
// AMD resolution will only respect the AMD baseUrl if the .js extension is omitted. | ||
// The assumption is that this makes sense for all relative ids: | ||
// https://requirejs.org/docs/api.html#jsfiles | ||
export default function updateExtensionForRelativeAmdId( | ||
id: string, | ||
forceJsExtensionForImports: boolean | ||
): string { | ||
if (id[0] !== '.') { | ||
return id; | ||
} | ||
|
||
return forceJsExtensionForImports ? addJsExtension(id) : removeJsExtension(id); | ||
} |
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,7 @@ | ||
module.exports = { | ||
description: 'keep extension for AMD modules', | ||
options: { | ||
external: ['./relative', 'abso/lute', './relative.js', 'abso/lute.js'], | ||
output: { amd: { forceJsExtensionForImports: true }, interop: 'default' } | ||
} | ||
}; |
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(['./relative.js', 'abso/lute', './relative.js', 'abso/lute.js'], (function (relative, absolute, relativeExtension, absoluteExtension) { 'use strict'; | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); | ||
|
||
})); |
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,8 @@ | ||
'use strict'; | ||
|
||
var relative = require('./relative'); | ||
var absolute = require('abso/lute'); | ||
var relativeExtension = require('./relative.js'); | ||
var absoluteExtension = require('abso/lute.js'); | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); |
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,6 @@ | ||
import relative from './relative'; | ||
import absolute from 'abso/lute'; | ||
import relativeExtension from './relative.js'; | ||
import absoluteExtension from 'abso/lute.js'; | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); |
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,6 @@ | ||
(function (relative, absolute, relativeExtension, absoluteExtension) { | ||
'use strict'; | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); | ||
|
||
})(relative, absolute, relativeExtension, absoluteExtension); |
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(['./relative', 'abso/lute', './relative.js', 'abso/lute.js'], (function () { | ||
'use strict'; | ||
var relative, absolute, relativeExtension, absoluteExtension; | ||
return { | ||
setters: [function (module) { | ||
relative = module["default"]; | ||
}, function (module) { | ||
absolute = module["default"]; | ||
}, function (module) { | ||
relativeExtension = module["default"]; | ||
}, function (module) { | ||
absoluteExtension = module["default"]; | ||
}], | ||
execute: (function () { | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); | ||
|
||
}) | ||
}; | ||
})); |
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 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('./relative'), require('abso/lute'), require('./relative.js'), require('abso/lute.js')) : | ||
typeof define === 'function' && define.amd ? define(['./relative.js', 'abso/lute', './relative.js', 'abso/lute.js'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.relative, global.absolute, global.relativeExtension, global.absoluteExtension)); | ||
})(this, (function (relative, absolute, relativeExtension, absoluteExtension) { 'use strict'; | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); | ||
|
||
})); |
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,6 @@ | ||
import relative from './relative'; | ||
import absolute from 'abso/lute'; | ||
import relativeExtension from './relative.js'; | ||
import absoluteExtension from 'abso/lute.js'; | ||
|
||
console.log(relative, absolute, relativeExtension, absoluteExtension); |
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