Skip to content

Commit ac498ac

Browse files
committed
feat: add support for rollup v4
1 parent f359c33 commit ac498ac

File tree

3 files changed

+153
-37
lines changed

3 files changed

+153
-37
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"css"
3939
],
4040
"peerDependencies": {
41-
"rollup": "^2.79.1||^3.0.0"
41+
"rollup": "^2.79.1||^3.0.0||^4.0.0"
4242
},
4343
"dependencies": {
4444
"@rollup/plugin-node-resolve": "^15.0.2",
@@ -57,8 +57,8 @@
5757
"pnpm": "^6.35.1",
5858
"prettier": "^2.8.8",
5959
"prettier-plugin-package": "^1.3.0",
60-
"rollup": "^3.21.6",
61-
"rollup-plugin-prettier": "^2.3.0",
60+
"rollup": "^4.0.0",
61+
"rollup-plugin-prettier": "^4.1.1",
6262
"source-map-support": "^0.5.21"
6363
},
6464
"ava": {

pnpm-lock.yaml

+135-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@ export default function importAssertions(options = {}) {
3434

3535
// we want to make sure acorn knows how to parse import assertions
3636

37-
// The acorn parser only implements stage 4 js proposals.
37+
// For rollup v2 or v2,
38+
// the acorn parser only implements stage 4 js proposals.
3839
// At the moment "import assertions" are a stage 3 proposal and as such
3940
// cannot be parsed by acorn. However, there exist a plugin,
4041
// so we inject the adhoc plugin into the options
4142
// by leveraging https://rollupjs.org/guide/en/#acorninjectplugins
4243
options(opts) {
43-
// eslint-disable-next-line no-param-reassign
44-
opts.acornInjectPlugins = opts.acornInjectPlugins || [];
45-
if (!opts.acornInjectPlugins.includes(acornImportAssertions)) {
46-
opts.acornInjectPlugins.push(acornImportAssertions);
44+
const rollupMajorVersion = Number(this.meta.rollupVersion.split('.')[0]);
45+
46+
if (rollupMajorVersion <= 3) {
47+
// eslint-disable-next-line no-param-reassign
48+
opts.acornInjectPlugins = opts.acornInjectPlugins || [];
49+
if (!opts.acornInjectPlugins.includes(acornImportAssertions)) {
50+
opts.acornInjectPlugins.push(acornImportAssertions);
51+
}
4752
}
53+
4854
return opts;
4955
},
5056

@@ -63,9 +69,11 @@ export default function importAssertions(options = {}) {
6369

6470
const moduleInfo = self.getModuleInfo(id);
6571
const assertType =
66-
'assertions' in moduleInfo
72+
'attributes' in moduleInfo
73+
? moduleInfo.attributes.type /* rollup v4 */
74+
: 'assertions' in moduleInfo
6775
? moduleInfo.assertions.type /* rollup v3 */
68-
: moduleInfo.meta['import-assertions'];
76+
: moduleInfo.meta['import-assertions']; /* rollup v<=2 */
6977

7078
if (assertType === 'json')
7179
// from @rollup/plugin-json

0 commit comments

Comments
 (0)