Skip to content

Commit

Permalink
chore(rollup): migrate commonjs to esmodule (#2913)
Browse files Browse the repository at this point in the history
* chore(rollup): migrate commonjs to esmodule

* chore(package.json): change commonjs to esmodule style in 'patch-d-ts' script
  • Loading branch information
sukvvon authored Jan 7, 2025
1 parent 20cc2a8 commit 5ff8f63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"test:lint": "eslint .",
"test:spec": "vitest run",
"test-build:spec": "vitest run",
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
"patch-d-ts": "node --input-type=module -e \"import { entries } from './rollup.config.mjs'; import shelljs from 'shelljs'; const { find, sed } = shelljs; find('dist/**/*.d.ts').forEach(f => { entries.forEach(({ find, replacement }) => sed('-i', new RegExp(' from \\'' + find.source.slice(0, -1) + '\\';$'), ' from \\'' + replacement + '\\';', f)); sed('-i', / from '(\\.[^']+)\\.ts';$/, ' from \\'\\$1\\';', f); });\"",
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/src && shx rm -rf dist/{src,tests} && downlevel-dts dist dist/ts3.8 --to=3.8 && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
"patch-ts3.8": "node -e \"require('shelljs').find('dist/ts3.8/**/*.d.ts').forEach(f=>require('fs').appendFileSync(f,'declare type Awaited<T> = T extends Promise<infer V> ? V : T;'))\"",
"patch-old-ts": "shx touch dist/ts_version_3.8_and_above_is_required.d.ts",
Expand Down
26 changes: 12 additions & 14 deletions rollup.config.js → rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable no-undef */
const path = require('path')
const alias = require('@rollup/plugin-alias')
const babelPlugin = require('@rollup/plugin-babel')
const resolve = require('@rollup/plugin-node-resolve')
const replace = require('@rollup/plugin-replace')
const terser = require('@rollup/plugin-terser')
const typescript = require('@rollup/plugin-typescript')
const banner2 = require('rollup-plugin-banner2')
const { default: esbuild } = require('rollup-plugin-esbuild')
const createBabelConfig = require('./babel.config.js')
import path from 'path'
import alias from '@rollup/plugin-alias'
import babelPlugin from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import banner2 from 'rollup-plugin-banner2'
import esbuild from 'rollup-plugin-esbuild'
import createBabelConfig from './babel.config.js'

const extensions = ['.js', '.ts', '.tsx']
const { root } = path.parse(process.cwd())
const entries = [
export const entries = [
{ find: /.*\/vanilla\/utils\.ts$/, replacement: 'jotai/vanilla/utils' },
{ find: /.*\/react\/utils\.ts$/, replacement: 'jotai/react/utils' },
{ find: /.*\/vanilla\.ts$/, replacement: 'jotai/vanilla' },
Expand Down Expand Up @@ -165,7 +165,7 @@ function createSystemConfig(input, output, env, clientOnly) {
}
}

module.exports = function (args) {
export default function (args) {
let c = Object.keys(args).find((key) => key.startsWith('config-'))
const clientOnly = Object.keys(args).some((key) => key === 'client-only')
if (c) {
Expand Down Expand Up @@ -193,5 +193,3 @@ module.exports = function (args) {
),
]
}

module.exports.entries = entries

0 comments on commit 5ff8f63

Please sign in to comment.