New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement amd.autoId
/amd.basePath
options
#3867
Merged
Merged
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
cef70d8
implement `amd.idFromChunkName` option
a44bef3
update output-options-hook test
eadea09
update NormalizedOutputOptions type
462c69c
simiplify removeExtension()
287769a
fix `idFromChunkName` type
65f0921
make `idFromChunkName` required in normalized options
3a42519
reference actual types in normalizeOutputOptions
04ec70f
switch to using a pattern instead
tjenkinson 3bcd1cd
also removeExtensionFromRelativeAmdId in UMD finaliser
tjenkinson 02b8f21
Merge branch 'remove-extension-amd-umd' into amd-id-code-split
tjenkinson 2e9d487
support id in output.amd.id in umd finaliser
tjenkinson cb76695
move test to chunking-form/samples
tjenkinson 881b932
remove test from cli section
tjenkinson e3cf09c
remove idFromChunkName
tjenkinson 95d605f
revert chunking-form index change
96088e2
break out to amd.autoId and amd.basePath options
bde40bc
Merge remote-tracking branch 'upstream/master' into amd-id-code-split
ad09886
remove unneeded changes
114364f
update docs
9434622
update test to also put chunks in folder
8eeece1
throw error if amd.id used with muli-file build
1654ded
more accurate amd options type
1d4efc9
update output.amd doc
84e8099
fix `@ts-expect-error` comments
96ea9c1
add tests for invalid options
c9ec971
add test for entryFileNames with output.preserveModules
48d01b1
ignore internal error in coverage
e1d9173
simplify type
e6944ae
fix output options test
9cecce3
fix type tests
6ef8520
improve types again
bba3d17
simply again
cbae7b8
make it a warning
tjenkinson File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,15 @@ import { getExportBlock, getNamespaceMarkers } from './shared/getExportBlock'; | |
import getInteropBlock from './shared/getInteropBlock'; | ||
import warnOnBuiltins from './shared/warnOnBuiltins'; | ||
|
||
function removeExtension(name: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this |
||
return name.endsWith('.js') ? name.slice(0, -3) : name; | ||
} | ||
|
||
// 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 | ||
function removeExtensionFromRelativeAmdId(id: string) { | ||
if (id[0] === '.' && id.endsWith('.js')) { | ||
return id.slice(0, -3); | ||
} | ||
return id; | ||
return id[0] === '.' ? removeExtension(id) : id; | ||
} | ||
|
||
export default function amd( | ||
|
@@ -22,6 +23,7 @@ export default function amd( | |
dependencies, | ||
exports, | ||
hasExports, | ||
id, | ||
indentString: t, | ||
intro, | ||
isEntryFacade, | ||
|
@@ -32,7 +34,7 @@ export default function amd( | |
warn | ||
}: FinaliserOptions, | ||
{ | ||
amd: { define: amdDefine, id: amdId }, | ||
amd: { define: amdDefine, id: amdId, idFromChunkName: amdIdFromChunkName }, | ||
compact, | ||
esModule, | ||
externalLiveBindings, | ||
|
@@ -64,8 +66,18 @@ export default function amd( | |
deps.unshift(`'module'`); | ||
} | ||
|
||
let completeAmdId = ''; | ||
if (amdId) { | ||
completeAmdId += amdId; | ||
} | ||
|
||
if (amdIdFromChunkName) { | ||
completeAmdId += removeExtension(id); | ||
} | ||
|
||
const params = | ||
(amdId ? `'${amdId}',${_}` : ``) + (deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``); | ||
(completeAmdId ? `'${completeAmdId}',${_}` : ``) + | ||
(deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``); | ||
const useStrict = strict ? `${_}'use strict';` : ''; | ||
|
||
magicString.prepend( | ||
|
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
5 changes: 5 additions & 0 deletions
5
test/cli/samples/amd-code-splitting-id-from-chunk-name-with-id/_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,5 @@ | ||
module.exports = { | ||
description: | ||
'sets AMD module ID for each chunk appended with chunk id when there is code splitting and `idFromChunkName` option', | ||
command: 'rollup -i main.js -f amd --amd.id "foo/" --amd.idFromChunkName' | ||
}; |
21 changes: 21 additions & 0 deletions
21
test/cli/samples/amd-code-splitting-id-from-chunk-name-with-id/_expected.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,21 @@ | ||
//→ main.js: | ||
define('foo/main', ['require', 'exports'], function (require, exports) { 'use strict'; | ||
|
||
function getA() { | ||
return new Promise(function (resolve, reject) { require(['./a-44b1f428'], resolve, reject) }); | ||
} | ||
|
||
exports.getA = getA; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); | ||
|
||
//→ a-44b1f428.js: | ||
define('foo/a-44b1f428', ['exports'], function (exports) { 'use strict'; | ||
|
||
const something = 42; | ||
|
||
exports.something = something; | ||
|
||
}); |
1 change: 1 addition & 0 deletions
1
test/cli/samples/amd-code-splitting-id-from-chunk-name-with-id/a.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 const something = 42; |
3 changes: 3 additions & 0 deletions
3
test/cli/samples/amd-code-splitting-id-from-chunk-name-with-id/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 @@ | ||
export function getA() { | ||
return import('./a'); | ||
} |
5 changes: 5 additions & 0 deletions
5
test/cli/samples/amd-code-splitting-id-from-chunk-name-without-id/_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,5 @@ | ||
module.exports = { | ||
description: | ||
'sets AMD module ID for each chunk as the chunk id when there is code splitting and `idFromChunkName` option', | ||
command: 'rollup -i main.js -f amd --amd.idFromChunkName' | ||
}; |
21 changes: 21 additions & 0 deletions
21
test/cli/samples/amd-code-splitting-id-from-chunk-name-without-id/_expected.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,21 @@ | ||
//→ main.js: | ||
define('main', ['require', 'exports'], function (require, exports) { 'use strict'; | ||
|
||
function getA() { | ||
return new Promise(function (resolve, reject) { require(['./a-44b1f428'], resolve, reject) }); | ||
} | ||
|
||
exports.getA = getA; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
}); | ||
|
||
//→ a-44b1f428.js: | ||
define('a-44b1f428', ['exports'], function (exports) { 'use strict'; | ||
|
||
const something = 42; | ||
|
||
exports.something = something; | ||
|
||
}); |
1 change: 1 addition & 0 deletions
1
test/cli/samples/amd-code-splitting-id-from-chunk-name-without-id/a.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 const something = 42; |
3 changes: 3 additions & 0 deletions
3
test/cli/samples/amd-code-splitting-id-from-chunk-name-without-id/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 @@ | ||
export function getA() { | ||
return import('./a'); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct assuming
id
is always a string at this point?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, yes.