diff --git a/package.json b/package.json index ce840facbc..2ce6da688c 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,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 && 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)})\"" diff --git a/rollup.config.js b/rollup.config.mjs similarity index 81% rename from rollup.config.js rename to rollup.config.mjs index acbb0946bf..6b7296eec8 100644 --- a/rollup.config.js +++ b/rollup.config.mjs @@ -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\/shallow\.ts$/, replacement: 'zustand/vanilla/shallow' }, { find: /.*\/react\/shallow\.ts$/, replacement: 'zustand/react/shallow' }, { find: /.*\/vanilla\.ts$/, replacement: 'zustand/vanilla' }, @@ -50,7 +50,9 @@ function createESMConfig(input, output) { output: { file: output, format: 'esm' }, external, plugins: [ - alias({ entries: entries.filter((e) => !e.find.test(input)) }), + alias({ + entries: entries.filter((entry) => !entry.find.test(input)), + }), resolve({ extensions }), replace({ ...(output.endsWith('.js') @@ -78,7 +80,9 @@ function createCommonJSConfig(input, output) { output: { file: output, format: 'cjs' }, external, plugins: [ - alias({ entries: entries.filter((e) => !e.find.test(input)) }), + alias({ + entries: entries.filter((entry) => !entry.find.test(input)), + }), resolve({ extensions }), replace({ 'import.meta.env?.MODE': 'process.env.NODE_ENV', @@ -90,7 +94,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, '/') @@ -103,5 +107,3 @@ module.exports = function (args) { createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`), ] } - -module.exports.entries = []