diff --git a/package-lock.json b/package-lock.json index 20d75064..fd306ef1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@js-temporal/polyfill", - "version": "0.3.0", + "version": "0.4.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@js-temporal/polyfill", - "version": "0.3.0", + "version": "0.4.1", "license": "ISC", "dependencies": { "jsbi": "^4.1.0", @@ -25,6 +25,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", @@ -2270,6 +2271,15 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/babel-plugin-transform-jsbi-to-bigint": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-jsbi-to-bigint/-/babel-plugin-transform-jsbi-to-bigint-1.4.0.tgz", + "integrity": "sha512-59f6ClwQBY/SKMVwKV/xoAqH/gnyZ6C5gSSPsEUCLPvvZULCDSE5Y3T62wjNTbpBcFzh0ReYz2mIe3u44mW9UQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", @@ -7067,6 +7077,12 @@ "@babel/helper-define-polyfill-provider": "^0.3.0" } }, + "babel-plugin-transform-jsbi-to-bigint": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-jsbi-to-bigint/-/babel-plugin-transform-jsbi-to-bigint-1.4.0.tgz", + "integrity": "sha512-59f6ClwQBY/SKMVwKV/xoAqH/gnyZ6C5gSSPsEUCLPvvZULCDSE5Y3T62wjNTbpBcFzh0ReYz2mIe3u44mW9UQ==", + "dev": true + }, "backo2": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", diff --git a/package.json b/package.json index 2bcc9949..37786c76 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/rollup.config.js b/rollup.config.js index 67f4e072..f84f8d8f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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'; @@ -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: [ @@ -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