Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow plugins to add and change assertions
- Loading branch information
1 parent
cc8d5f3
commit 1fbe2a6
Showing
15 changed files
with
86 additions
and
18 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
1 change: 0 additions & 1 deletion
1
test/form/samples/import-assertions/keep-dynamic-assertions/_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
1 change: 0 additions & 1 deletion
1
test/form/samples/import-assertions/keeps-static-assertions/_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
22 changes: 22 additions & 0 deletions
22
test/form/samples/import-assertions/plugin-assertions-resolvedynamicimport/_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,22 @@ | ||
module.exports = { | ||
description: 'allows plugins to read and write import assertions in resolveDynamicImport', | ||
options: { | ||
plugins: [ | ||
{ | ||
resolveDynamicImport(specifier, importer, { assertions }) { | ||
const resolutionOptions = { | ||
external: true, | ||
assertions: Object.fromEntries(Object.keys(assertions).map(key => [key, 'changed'])) | ||
}; | ||
if (typeof specifier === 'object') { | ||
if (specifier.type === 'TemplateLiteral') { | ||
return { id: 'resolved-a', ...resolutionOptions }; | ||
} | ||
return { id: 'resolved-b', ...resolutionOptions }; | ||
} | ||
return { id: specifier, ...resolutionOptions }; | ||
} | ||
} | ||
] | ||
} | ||
}; |
4 changes: 4 additions & 0 deletions
4
test/form/samples/import-assertions/plugin-assertions-resolvedynamicimport/_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,4 @@ | ||
import('a', { assert: { type: 'changed' } }); | ||
import('resolved-b', { assert: { type: 'changed', extra: 'changed' } }); | ||
import('b'); | ||
import('resolved-a'); |
4 changes: 4 additions & 0 deletions
4
test/form/samples/import-assertions/plugin-assertions-resolvedynamicimport/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('a', { assert: { type: 'special' } }); | ||
import(globalThis.unknown, { assert: { type: 'special', extra: 'value' } }); | ||
import('b'); | ||
import(`external-${globalThis.unknown}`); |
17 changes: 17 additions & 0 deletions
17
test/form/samples/import-assertions/plugin-assertions-resolveid/_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,17 @@ | ||
module.exports = { | ||
description: 'allows plugins to read and write import assertions in resolveId', | ||
options: { | ||
output: { name: 'bundle' }, | ||
plugins: [ | ||
{ | ||
resolveId(source, importer, { assertions, isEntry }) { | ||
return { | ||
id: source, | ||
external: !isEntry, | ||
assertions: Object.fromEntries(Object.keys(assertions).map(key => [key, 'changed'])) | ||
}; | ||
} | ||
} | ||
] | ||
} | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/form/samples/import-assertions/plugin-assertions-resolveid/_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,9 @@ | ||
import { a } from 'a' assert { type: 'changed', extra: 'changed' }; | ||
import * as b from 'b' assert { type: 'changed' }; | ||
export { c } from 'c' assert { type: 'changed' }; | ||
export * from 'd' assert { type: 'changed' }; | ||
import 'e'; | ||
|
||
console.log(a, b, d); | ||
import('f', { assert: { type: 'changed' } }); | ||
import('g'); |
9 changes: 9 additions & 0 deletions
9
test/form/samples/import-assertions/plugin-assertions-resolveid/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,9 @@ | ||
import { a } from 'a' assert { type: 'a', extra: 'extra' }; | ||
import * as b from 'b' assert { type: 'b' }; | ||
export { c } from 'c' assert { type: 'c' }; | ||
export * from 'd' assert { type: 'd' }; | ||
import 'e'; | ||
|
||
console.log(a, b, d); | ||
import('f', { assert: { type: 'f' } }); | ||
import('g'); |
1 change: 0 additions & 1 deletion
1
test/form/samples/import-assertions/removes-dynamic-assertions/_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
1 change: 0 additions & 1 deletion
1
test/form/samples/import-assertions/removes-static-assertions/_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