Upgrade: v7 convert to ESM lets Disscuse the API
See original GitHub issueI have forked this repo long time ago i would love to merge back as i think there are good improvements but i found out that we need maybe to incremental adopt changes as this gets used so often.
First things first
at present we got a export of the async del version under the name del and then we assign to that the sync version this would result into really bad ESM code i would vote for renaming the named Exports in this CJS version as also in the new ESM version to deprecate the old import and require behaviors and get better static analyzeable code.
del() gets delAsync() and del.sync gets delSync() while we add a deprecated default import so that the patterns that are in the section below still work while we deprecate them.
when we transpil that code to cjs with the following rollup config we can create a del.cjs inside the node_modules folder that has the old api from v6.0.0 the only thing changes is that you require(‘del/del.cjs’)
this pattern is the best for the future i guess i am from the NodeJS Package Maintainance Group and i was working on a Gold Standard for Packaging since then.
People will generate CJS files when they need them.
{
input: ['del.js'],
external: () => true, //
output: [
{
preferConst: true,
format: 'es',
entryFileNames: `[name].cjs`,
dir: `./node_modules/del`,
interop: 'esModule',
exports: 'named',
}
]
}
i have the following readme snippet prepared
Deprecated Usage and How to Transpile to CJS
This usage mode resulted out of the fact that we wanted to support the old CJS patterns from v6.0.0
When you transpile this Module With Rollup to CJS
const del = require('./del.cjs'); // deprecated version but will work
// Replaced by Async/Await DynamicImport, DynamicImport as Promise use
const { delAsync, delSync } = require('./del.cjs')
import del, { sync } from 'del';
del(patterns, delOptions); // is now delAsync { delAsync } from 'del'; delAsync();
del.sync(patterns, delOptions); // is now delSync import { delSync } from 'del'; delSync();
Short Following up
i want to do the deprecation set already in this CJS version so that we can more smoth transition to esm
so long story short can we add module.exports.delAsync and exports.delSync as also translate everything away from module.exports to directly exports also drop exports default aka module.exports and communicate to do
const { delSync, delAsync} = require('del');
if yes i could create some pull requests for example i got this fully typed with automatic typegenration working as js with JSDOC Annotations
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
No. The TS mention is about TS not being able to handle ESM until TS 4.7.
I plan to move directly to ESM without any CommonJS support. I’m just waiting for TypeScript 4.7 (which will have full ESM support), so I don’t have to deal with too many TS support issues.
The API will be two named exports:
deleteanddeleteSync.It’s probably easier if I do the migration myself as there’s a lot of details to get right.
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c