Skip to content

Commit

Permalink
chore(rollup): migrate commonjs to esmodule (#1030)
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 87841c1 commit d0a26ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"test:types": "tsc --noEmit",
"test:lint": "eslint .",
"test: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,tests} && 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-old-ts": "shx touch dist/ts_version_4.5_and_above_is_required.d.ts",
"patch-esm-ts": "node -e \"require('shelljs').find('dist/esm/**/*.d.ts').forEach(f=>{var f2=f.replace(/\\.ts$/,'.mts');require('fs').renameSync(f,f2);require('shelljs').sed('-i',/ from '(\\.[^']+)';$/,' from \\'\\$1.mjs\\';',f2);require('shelljs').sed('-i',/^declare module '(\\.[^']+)'/,'declare module \\'\\$1.mjs\\'',f2)})\""
Expand Down
20 changes: 9 additions & 11 deletions rollup.config.js → rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable no-undef */
const path = require('path')
const alias = require('@rollup/plugin-alias')
const resolve = require('@rollup/plugin-node-resolve')
const replace = require('@rollup/plugin-replace')
const typescript = require('@rollup/plugin-typescript')
const { default: esbuild } = require('rollup-plugin-esbuild')
/*global process*/
import path from 'path'
import alias from '@rollup/plugin-alias'
import resolve from '@rollup/plugin-node-resolve'
import replace from '@rollup/plugin-replace'
import typescript from '@rollup/plugin-typescript'
import esbuild from 'rollup-plugin-esbuild'

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

module.exports = function (args) {
export default function (args) {
let c = Object.keys(args).find((key) => key.startsWith('config-'))
if (c) {
c = c.slice('config-'.length).replace(/_/g, '/')
Expand All @@ -100,5 +100,3 @@ module.exports = function (args) {
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`),
]
}

module.exports.entries = entries

0 comments on commit d0a26ba

Please sign in to comment.