Skip to content

Commit

Permalink
fix(build): prefix exports, to prevent overriding primitives (Such as…
Browse files Browse the repository at this point in the history
… Object for Guacamole.Object)
  • Loading branch information
DanielMcAssey committed Dec 1, 2024
1 parent 15af94a commit e4760a7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build-cjs.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs');
const fs = require('node:fs');
const srcDir = './src/';

const src = fs.readdirSync(srcDir)
Expand Down
9 changes: 4 additions & 5 deletions build-esm.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs');
const fs = require('node:fs');
const srcDir = './src/';

const src = fs.readdirSync(srcDir)
Expand All @@ -18,10 +18,9 @@ fs.writeFileSync('./lib/esm/guacamole.js', esm);

//Now that we've written the ESM file, import it so we can dynamically add named exports
import('./lib/esm/guacamole.js').then((Guac) => {

const namesToExport = Object.keys(Guac.default);
esm += namesToExport.map(n => `const ${n} = Guacamole.${n};`).join('\n'); //Generate separate variable for each key in `Guacamole`
esm += namesToExport.map((n) => `const exportGuac_${n} = Guacamole.${n};`).join('\n'); //Generate separate variable for each key in `Guacamole`

esm += `\nexport {\n${namesToExport.map(n => ` ${n},`).join('\n')}\n};`; //Export every key
esm += `\nexport {\n${namesToExport.map(n => ` exportGuac_${n} as ${n},`).join('\n')}\n};`; //Export every key
fs.writeFileSync('./lib/esm/guacamole.js', esm);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@glokon/guacamole-common-js",
"version": "1.5.22",
"version": "1.5.23",
"description": "Guacamole common js with typescript type definitions",
"type": "module",
"main": "lib/cjs/guacamole.js",
Expand Down

0 comments on commit e4760a7

Please sign in to comment.