@@ -7,10 +7,10 @@ const packageJson = require('../package.json');
77const packageTemplate = require ( './package.template.json' ) ;
88
99const { version } = packageJson ;
10- const distPath = path . resolve ( __dirname , '../dist' ) ;
10+ const getDistPath = ( subPath ) => path . resolve ( __dirname , subPath != null ? `../dist ${ subPath } ` : '../dist' ) ;
1111
1212function appendVersionToTypeDefn ( ) {
13- const indexDtsPath = path . resolve ( distPath , 'index.d.ts' ) ;
13+ const indexDtsPath = path . resolve ( getDistPath ( ) , 'index.d.ts' ) ;
1414 const indexDts = fs . readFileSync ( indexDtsPath , 'utf8' ) ;
1515 const indexDtsWithVersion = indexDts . replace (
1616 'Type Definitions for @sendbird/uikit-react@{{ version }}' ,
@@ -41,7 +41,7 @@ function cleanupPackageJSON(json) {
4141}
4242
4343function movePackageJSON ( ) {
44- const packageJSONDistPath = path . resolve ( distPath , 'package.json' ) ;
44+ const packageJSONDistPath = path . resolve ( getDistPath ( ) , 'package.json' ) ;
4545 const cleanedUpPackageJSON = cleanupPackageJSON ( packageJson ) ;
4646 fs . writeFileSync (
4747 packageJSONDistPath ,
@@ -50,7 +50,31 @@ function movePackageJSON() {
5050 ) ;
5151}
5252
53+ function copyCJSPackageJSON ( ) {
54+ const packageJSONDistPath = path . resolve ( getDistPath ( '/cjs' ) , 'package.json' ) ;
55+ const cleanedUpPackageJSON = cleanupPackageJSON ( packageJson ) ;
56+
57+ delete cleanedUpPackageJSON . files ;
58+ delete cleanedUpPackageJSON . scripts ;
59+ delete cleanedUpPackageJSON . devDependencies ;
60+ delete cleanedUpPackageJSON . module ;
61+
62+ fs . writeFileSync (
63+ packageJSONDistPath ,
64+ JSON . stringify ( {
65+ ...cleanedUpPackageJSON ,
66+ main : 'index.js' ,
67+ type : 'commonjs' ,
68+ typings : '../index.d.ts' ,
69+ } , null , 2 ) ,
70+ { flag : 'w' } ,
71+ ) ;
72+ }
73+
74+
5375/** Add version information to index.d.ts in dist */
5476appendVersionToTypeDefn ( ) ;
5577/** Copy content of package.json to dist, but remove unnecessary fields */
5678movePackageJSON ( ) ;
79+ /** Copy content of package.json to dist/cjs, to support cjs module separately */
80+ copyCJSPackageJSON ( ) ;
0 commit comments