Skip to content

Commit

Permalink
new: Support import attributes (with only). (#256)
Browse files Browse the repository at this point in the history
* Add deps.

* Update snaps.

* Add tests.
  • Loading branch information
milesj authored May 22, 2024
1 parent 49aea80 commit b25fd9b
Show file tree
Hide file tree
Showing 10 changed files with 1,698 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/packemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"@babel/core": "^7.24.5",
"@babel/plugin-external-helpers": "^7.24.1",
"@babel/plugin-proposal-decorators": "^7.24.1",
"@babel/plugin-proposal-json-modules": "^7.24.3",
"@babel/plugin-syntax-import-attributes": "^7.24.1",
"@babel/plugin-transform-runtime": "^7.24.3",
"@babel/preset-env": "^7.24.5",
"@babel/preset-flow": "^7.24.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/packemon/src/babel/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ function getSharedConfig(
presets: PluginItem[],
features: FeatureFlags,
): ConfigStructure {
plugins.push(
resolve('@babel/plugin-syntax-import-attributes'),
resolve('@babel/plugin-proposal-json-modules'),
);

return {
caller: {
name: 'packemon',
Expand Down
1 change: 1 addition & 0 deletions packages/packemon/src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function getRollupOutputConfig(
objectShorthand: true,
symbols: isEsm,
},
importAttributesKey: 'with',
// Output specific plugins
plugins: [
preserveDynamicImport(platform, format),
Expand Down
26 changes: 24 additions & 2 deletions packages/packemon/tests/babel/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ exports[`getBabelInputConfig() > can mutate config 1`] = `
"strictMode": undefined,
},
"plugins": [
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
"babel-plugin-example",
],
"presets": [],
Expand All @@ -32,7 +34,10 @@ exports[`getBabelInputConfig() > doesnt include typescript decorators if \`types
"sourceType": "unambiguous",
"strictMode": undefined,
},
"plugins": [],
"plugins": [
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [],
}
`;
Expand Down Expand Up @@ -60,7 +65,10 @@ exports[`getBabelInputConfig() > includes no plugins or presets by default 1`] =
"sourceType": "unambiguous",
"strictMode": undefined,
},
"plugins": [],
"plugins": [
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [],
}
`;
Expand Down Expand Up @@ -142,6 +150,8 @@ exports[`getBabelInputConfig() > includes typescript decorators if \`typescript\
"loose": true,
},
],
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [
[
Expand Down Expand Up @@ -214,6 +224,8 @@ exports[`getBabelInputConfig() > supports private properties with decorators if
"loose": true,
},
],
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [
[
Expand Down Expand Up @@ -255,6 +267,8 @@ exports[`getBabelOutputConfig() > can mutate config 1`] = `
],
"babel-plugin-conditional-invariant",
"babel-plugin-env-constants",
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
"babel-plugin-example",
],
"presets": [
Expand Down Expand Up @@ -960,6 +974,8 @@ exports[`getBabelOutputConfig() > transforms async/await to promises when \`brow
],
"babel-plugin-conditional-invariant",
"babel-plugin-env-constants",
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [
[
Expand Down Expand Up @@ -1015,6 +1031,8 @@ exports[`getBabelOutputConfig() > transforms async/await to promises when \`brow
],
"babel-plugin-conditional-invariant",
"babel-plugin-env-constants",
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [
[
Expand Down Expand Up @@ -1073,6 +1091,8 @@ exports[`getBabelOutputConfig() > uses built-in destructuring and object spread
],
"babel-plugin-conditional-invariant",
"babel-plugin-env-constants",
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [
[
Expand Down Expand Up @@ -1131,6 +1151,8 @@ exports[`getBabelOutputConfig() > uses built-in destructuring and object spread
],
"babel-plugin-conditional-invariant",
"babel-plugin-env-constants",
"@babel/plugin-syntax-import-attributes",
"@babel/plugin-proposal-json-modules",
],
"presets": [
[
Expand Down
Loading

0 comments on commit b25fd9b

Please sign in to comment.