|
| 1 | +import * as fs from 'node:fs'; |
| 2 | +import * as path from 'node:path'; |
| 3 | +import * as url from 'node:url'; |
| 4 | + |
| 5 | +import {babel} from '@rollup/plugin-babel'; |
| 6 | +import {nodeResolve} from '@rollup/plugin-node-resolve'; |
| 7 | +import commonjs from '@rollup/plugin-commonjs'; |
| 8 | +import json from '@rollup/plugin-json'; |
| 9 | +import globby from 'globby'; |
| 10 | + |
| 11 | +const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); |
| 12 | +const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'))); |
| 13 | + |
| 14 | +const extensions = ['.js', '.jsx', '.ts', '.tsx']; |
| 15 | + |
| 16 | +const migrationPaths = globby.sync('./src/migrations/*!(tests)/*.ts'); |
| 17 | + |
| 18 | +/** @type {import('rollup').RollupOptions} */ |
| 19 | +export default { |
| 20 | + input: ['src/index.ts', ...migrationPaths], |
| 21 | + output: [ |
| 22 | + { |
| 23 | + format: /** @type {const} */ ('cjs'), |
| 24 | + entryFileNames: '[name][assetExtname].js', |
| 25 | + dir: path.dirname(pkg.main), |
| 26 | + preserveModules: true, |
| 27 | + exports: 'auto', |
| 28 | + }, |
| 29 | + ], |
| 30 | + plugins: [ |
| 31 | + // Allows node_modules resolution |
| 32 | + nodeResolve({extensions, preferBuiltins: true}), |
| 33 | + // Allow bundling cjs modules. Rollup doesn't understand cjs |
| 34 | + commonjs(), |
| 35 | + // Compile TypeScript/JavaScript files |
| 36 | + babel({ |
| 37 | + extensions, |
| 38 | + rootMode: 'upward', |
| 39 | + include: ['src/**/*'], |
| 40 | + babelHelpers: 'bundled', |
| 41 | + envName: 'production', |
| 42 | + targets: 'node 14.13', |
| 43 | + }), |
| 44 | + json({compact: true}), |
| 45 | + ], |
| 46 | + external: [ |
| 47 | + ...Object.keys(pkg.dependencies ?? {}), |
| 48 | + ...Object.keys(pkg.peerDependencies ?? {}), |
| 49 | + 'jscodeshift/src/Runner', |
| 50 | + ], |
| 51 | +}; |
0 commit comments