planttheidea / fast-copy

A blazing fast deep object copier
MIT License
1.13k stars 31 forks source link

Add `default` property as self-reference #38

Closed planttheidea closed 3 years ago

planttheidea commented 3 years ago

Reason for change

When using certain build systems (TSC, for example), transpilation of ESM to CommonJS will expect there to always be a default property.

import copy from 'fast-copy';
// becomes
const copy = require('fast-copy').default;

This causes it to fail because there is no default property with the CommonJS usage (it is simply module.exports = copy;). This was raised in #37 .

Change

Add a circular reference manually as the default property.

copy.default = copy;

This manual forging of an ESM-like module allows those transpilers to work as expected without forcing a breaking change of normal CommonJS usage of the library.