Skip to content

Commit

Permalink
breaking: Drop IE support. Update browser targets. (#114)
Browse files Browse the repository at this point in the history
* Updated table.

* Update tests.

* Always use async/await.
  • Loading branch information
milesj committed Apr 20, 2022
1 parent 38340df commit 6f5c730
Show file tree
Hide file tree
Showing 23 changed files with 730 additions and 1,306 deletions.
2 changes: 0 additions & 2 deletions packages/packemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"dependencies": {
"@babel/core": "^7.17.8",
"@babel/plugin-proposal-decorators": "^7.17.8",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-flow": "^7.16.7",
"@babel/preset-react": "^7.16.7",
Expand All @@ -72,7 +71,6 @@
"babel-plugin-cjs-esm-interop": "^1.2.5",
"babel-plugin-conditional-invariant": "^1.1.5",
"babel-plugin-env-constants": "^1.1.5",
"babel-plugin-transform-async-to-promises": "^0.8.18",
"builtin-modules": "^3.2.0",
"execa": "^5.1.1",
"fast-glob": "^3.2.11",
Expand Down
50 changes: 13 additions & 37 deletions packages/packemon/src/babel/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { resolve, resolveFromBabel } from './resolve';

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
function shouldKeepDynamicImport(platform: Platform, support: Support): boolean {
if (platform === 'node') {
return support === 'current' || support === 'experimental';
}

return support !== 'legacy';
return platform === 'node' ? support !== 'legacy' : true;
}

// https://babeljs.io/docs/en/babel-preset-env
Expand Down Expand Up @@ -44,7 +40,11 @@ function getPlatformEnvOptions(
modules = 'cjs'; // Babel CommonJS
}

const exclude = [];
const exclude = [
// Async/await and generators have been around for 4+ years
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-async-to-generator',
];

if (shouldKeepDynamicImport(platform, support)) {
exclude.push('@babel/plugin-proposal-dynamic-import');
Expand All @@ -67,16 +67,9 @@ function getPlatformEnvOptions(

case 'node':
return {
exclude: [
...exclude,
// Async/await has been available since v7
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-async-to-generator',
],
exclude,
modules,
targets: {
node: NODE_SUPPORTED_VERSIONS[support],
},
targets: { node: NODE_SUPPORTED_VERSIONS[support] },
};

default:
Expand Down Expand Up @@ -166,7 +159,7 @@ export function getBabelOutputConfig(
const presets: PluginItem[] = [];
const isESM = format === 'esm' || format === 'mjs';

// ENVIRONMENT
// PRESETS

const envOptions: PresetEnvOptions = {
// Prefer spec compliance in development
Expand All @@ -185,29 +178,12 @@ export function getBabelOutputConfig(

// PLUGINS

if (platform === 'browser' || platform === 'native') {
// Both browsers and Node.js support these features outside of legacy targets
if (support === 'legacy') {
plugins.push(
[
resolve('babel-plugin-transform-async-to-promises'),
{ inlineHelpers: true, target: 'es5' },
],
[
resolve('@babel/plugin-transform-runtime'),
{ helpers: false, regenerator: true, useESModules: isESM },
],
);
}
} else {
plugins.push(
// Use `Object.assign` when available
plugins.push(
[resolveFromBabel('@babel/plugin-transform-destructuring'), { useBuiltIns: true }],
[resolveFromBabel('@babel/plugin-proposal-object-rest-spread'), { useBuiltIns: true }],
);
}
[resolveFromBabel('@babel/plugin-transform-destructuring'), { useBuiltIns: true }],
[resolveFromBabel('@babel/plugin-proposal-object-rest-spread'), { useBuiltIns: true }],
);

// Support our custom plugins
if (platform === 'node') {
plugins.push([resolve('babel-plugin-cjs-esm-interop'), { format: isESM ? 'mjs' : 'cjs' }]);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/packemon/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export const EXCLUDE_RUST = [
// https://reactnative.dev/docs/javascript-environment
// Based on browserslist: https://github.com/browserslist/browserslist
export const NATIVE_TARGETS: { [K in Support]: string } = {
legacy: 'iOS 8',
stable: 'iOS 10',
current: 'iOS 12',
experimental: 'iOS 14',
legacy: 'iOS 12', // 2018
stable: 'iOS 13', // 2019
current: 'iOS 14', // 2020
experimental: 'iOS 15', // 2021
};

// Based on LTS schedule: https://nodejs.org/en/about/releases/
Expand All @@ -88,9 +88,9 @@ export const NPM_SUPPORTED_VERSIONS: { [K in Support]: string[] | string } = {

// Based on browserslist: https://github.com/browserslist/browserslist
export const BROWSER_TARGETS: { [K in Support]: string[] | string } = {
legacy: 'IE 11',
legacy: ['>=0.10%', 'not IE 11'],
stable: ['defaults', 'not IE 11'],
current: ['> 1%', 'not dead'],
current: ['>=1%', 'not dead'],
experimental: ['last 2 chrome versions', 'last 2 firefox versions'],
};

Expand Down
4 changes: 2 additions & 2 deletions packages/packemon/src/rollup/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ export function getRollupOutputConfig(
preserveModules: !artifact.bundle,
// Use ESM features when not supporting old targets
generatedCode: {
preset: support === 'legacy' ? 'es5' : 'es2015',
preset: 'es2015',
symbols: false, // Enable for pure ESM later on
},
preferConst: support !== 'legacy',
preferConst: true,
// Output specific plugins
plugins: [
isSwc
Expand Down
8 changes: 2 additions & 6 deletions packages/packemon/src/swc/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import { ConfigFile, FeatureFlags, Format, Platform, Support } from '../types';

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
function shouldKeepDynamicImport(platform: Platform, support: Support): boolean {
if (platform === 'node') {
return support === 'current' || support === 'experimental';
}

return support !== 'legacy';
return platform === 'node' ? support !== 'legacy' : true;
}

function getModuleConfigType(format: Format): ModuleConfig['type'] {
Expand Down Expand Up @@ -102,7 +98,7 @@ export function getSwcInputConfig(
// Keep the input as similar as possible
externalHelpers: false,
loose: false,
target: 'es2022',
target: SUPPORT_TO_ESM_SPEC.experimental,
},
};

Expand Down
Loading

0 comments on commit 6f5c730

Please sign in to comment.