file-type icon indicating copy to clipboard operation
file-type copied to clipboard

Add CommonJS entry points

Open Borewit opened this issue 1 year ago • 1 comments
trafficstars

Just out of curiosity, as there are so many issues with legacy CommonJS projects, trying to import this pure ESM module. Would this solution help a bit?

I added 2 CommonJS require entry points to the export:

  1. core.cjs, CommonJS default entry-point
  2. node.cjs, Node.js entry-points.

Each entry point provides a function to load (using loadFileType) the ESM module asynchronous for CommonJS use.

const { loadFileType } = require('file-type');

(async () => {
    const { fileTypeFromFile } = await loadFileType(); // Load the ESM file-type module async
    const type = await fileTypeFromFile('fixture.gif');
    console.log(type);
})();

Would this help?

Related to #661 and many more issues

Borewit avatar Aug 28 '24 10:08 Borewit