Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BigInt bundle #167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@
"default": "./dist/index.cjs"
},
"./dist/index.cjs"
]
],
"./bigint": "./dist/bigint/index.esm.js"
},
"types": "./index.d.ts",
"typesVersions": {
"*": {
"bigint": [
"./index.d.ts"
]
}
},
"scripts": {
"test": "npm run build && node --no-warnings --experimental-modules --experimental-specifier-resolution=node --icu-data-dir node_modules/full-icu --loader ./test/resolve.source.mjs ./test/all.mjs",
"test262": "TEST262=1 npm run build && ./test/test262.sh",
Expand Down Expand Up @@ -90,6 +98,7 @@
"@rollup/plugin-typescript": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"babel-plugin-transform-jsbi-to-bigint": "^1.4.0",
"eslint": "^8.4.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
Expand Down
20 changes: 11 additions & 9 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import babel, { getBabelOutputPlugin } from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';
import { env } from 'process';
Expand Down Expand Up @@ -57,16 +57,21 @@ const external = [
...Object.keys(pkg.peerDependencies || {})
].map((dep) => new RegExp(dep + '*'));

function outputEntry(file, format) {
function outputEntry(file, format, plugins = []) {
return {
name: libName,
file,
format,
exports: 'named',
sourcemap: true
sourcemap: true,
plugins
};
}

const bigintBabelConfig = {
plugins: ['transform-jsbi-to-bigint']
};

const es5BundleBabelConfig = {
babelHelpers: 'bundled',
presets: [
Expand Down Expand Up @@ -130,16 +135,13 @@ if (isTest262Build) {
// CJS bundle.
// Note that because package.json specifies "type":"module", the name of
// this file MUST end in ".cjs" in order to be treated as a CommonJS file.
outputEntry(pkg.main, 'cjs')
outputEntry(pkg.main, 'cjs'),
// BigInt bundle
outputEntry(pkg.exports['./bigint'], 'es', [getBabelOutputPlugin(bigintBabelConfig)])
],
plugins: withPlugins({
debugBuild: !isProduction,
optimize: isProduction
// Here is where we could insert the JSBI -> native BigInt plugin if we
// could find a way to provide a separate bundle for modern browsers
// that can use native BigInt.
// Maybe use node's exports + a user-defined condition?
// https://nodejs.org/api/packages.html#resolving-user-conditions
})
};
// A legacy build that
Expand Down