Skip to content

Commit

Permalink
fix: bundle to ES5 syntax
Browse files Browse the repository at this point in the history
Close #1023

# Conflicts:
#	packages/@interactjs/dev-tools/visualizer/plugin.ts
  • Loading branch information
taye authored and interactjs-ci committed Dec 4, 2023
1 parent 5ca9fe7 commit 3bd1df6
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 277 deletions.
5 changes: 3 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const isProd = process.env.NODE_ENV === 'production'

module.exports = {
targets: { ie: 9 },
browserslistConfigFile: false,
presets: [
[require.resolve('@babel/preset-env'), { exclude: ['transform-regenerator'] }],
[
require.resolve('@babel/preset-typescript'),
{ isTsx: false, onlyRemoveTypeImports: true, allExtensions: true, allowDeclareFields: true },
{ isTSX: false, onlyRemoveTypeImports: true, allExtensions: true, allowDeclareFields: true },
],
],

Expand All @@ -18,7 +20,6 @@ module.exports = {
regenerator: false,
},
],
isProd && require.resolve('./scripts/babel/for-of-array'),
isProd && require.resolve('@babel/plugin-transform-optional-catch-binding'),
isProd && [require.resolve('@babel/plugin-transform-optional-chaining'), { loose: true }],
isProd && [require.resolve('@babel/plugin-transform-nullish-coalescing-operator'), { loose: true }],
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@babel/register": "^7.17.7",
"@babel/runtime": "^7.18.3",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-node-resolve": "^15.2.3",
Expand Down Expand Up @@ -101,7 +100,7 @@
"symbol-tree": "^3.2.4",
"temp": "^0.9.4",
"terser": "^5.14.1",
"ts-node": "^10.8.1",
"ts-node": "^10.9.1",
"typedoc": "^0.25.4",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-rename-defaults": "^0.7.0",
Expand Down
149 changes: 0 additions & 149 deletions scripts/babel/for-of-array.js

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/bin/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ async function runBuild() {
if (!isPro) {
// bundle interactjs
shell.exec('npm run build:bundle')
// ensure that the output is valid ES5 syntax
shell.exec('acord --silent --ecma5 packages/interactjs/dist/**/*.js')

// generate docs
shell.exec('npm run build:docs')
Expand Down
15 changes: 11 additions & 4 deletions scripts/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const terser = require('@rollup/plugin-terser')
const { rollup, defineConfig } = require('rollup')
const cjs = require('rollup-plugin-cjs-es')

const { getModuleDirectories, getBabelConfig, extendBabelOptions, errorExit } = require('./utils')
const { getModuleDirectories, extendBabelOptions, errorExit, getEsnextBabelOptions } = require('./utils')

process.env.NODE_PATH = `${process.env.NODE_PATH || ''}:${path.resolve(__dirname, '..', 'node_modules')}`
require('module').Module._initPaths()
Expand Down Expand Up @@ -44,12 +44,19 @@ const createRollupConfigs = async ({
{
babelrc: false,
configFile: false,
browserslistConfigFile: false,
targets: format === 'es' ? undefined : { ie: 9 },
babelHelpers: 'bundled',
skipPreflightCheck: true,
extensions: ['.ts', '.tsx', '.js', '.jsx', '.vue'],
plugins: [require.resolve('@babel/plugin-transform-logical-assignment-operators')].filter(Boolean),
plugins: [
[
require.resolve('@babel/plugin-transform-runtime'),
{ helpers: false, regenerator: format !== 'es' },
],
],
},
getBabelConfig(),
getEsnextBabelOptions(format === 'es' ? { exclude: ['transform-regenerator'] } : {}),
)

return defineConfig({
Expand All @@ -69,7 +76,7 @@ const createRollupConfigs = async ({
preventAssignment: true,
values: Object.entries({
npm_package_version: process.env.npm_package_version,
IJS_BUNDLE: 'true',
IJS_BUNDLE: '1',
...env,
}).reduce((acc, [key, value]) => {
acc[`process.env.${key}`] = JSON.stringify(value)
Expand Down
30 changes: 14 additions & 16 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,30 @@ const getBuiltJsFiles = ({ cwd = process.cwd() } = {}) =>
nodir: true,
})

function getBabelConfig() {
let babelConfig

try {
babelConfig = require(path.join(process.cwd(), 'babel.config.js'))
} catch (e) {
babelConfig = require('../babel.config.js')
}

return babelConfig
}

function getEsnextBabelOptions() {
function getEsnextBabelOptions(presetEnvOptions) {
return {
babelrc: false,
configFile: false,
sourceMaps: true,
presets: [
[require.resolve('@babel/preset-typescript'), { allExtensions: true, allowDeclareFields: true }],
[require.resolve('@babel/preset-env'), presetEnvOptions],
[
require.resolve('@babel/preset-typescript'),
{ isTSX: false, onlyRemoveTypeImports: true, allExtensions: true, allowDeclareFields: true },
],
],
plugins: [
require.resolve('./babel/vue-sfc'),
require.resolve('@babel/plugin-proposal-optional-catch-binding'),
[require.resolve('@babel/plugin-proposal-optional-chaining'), { loose: true }],
require.resolve('@babel/plugin-proposal-optional-chaining'),
require.resolve('@babel/plugin-transform-nullish-coalescing-operator'),
require.resolve('@babel/plugin-transform-logical-assignment-operators'),
],
assumptions: {
iterableIsArray: true,
noDocumentAll: true,
noNewArrows: true,
},
}
}

Expand Down Expand Up @@ -202,7 +201,6 @@ module.exports = {
sourcesIgnoreGlobs,
lintIgnoreGlobs,
getBuiltJsFiles,
getBabelConfig,
getEsnextBabelOptions,
extendBabelOptions,
getDevPackageDir,
Expand Down
Loading

0 comments on commit 3bd1df6

Please sign in to comment.