Skip to content

Commit

Permalink
testing tweak for importing in nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Jul 14, 2022
1 parent 8fc7f01 commit 22cc5d1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions bin/tweetnacl-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ async function copyFromModulesDir(from: string, tail = ""): Promise<void> {
// deno-fmt-ignore-file
`;

const src = await Deno.readTextFile(
let src = await Deno.readTextFile(
`${Deno.cwd()}/node_modules/tweetnacl/${from}`,
);

src = src.replaceAll("self", "global")

await Deno.writeTextFile(
`${Deno.cwd()}/modules/esm/${from}`,
head + src + tail,
Expand All @@ -24,6 +26,6 @@ async function copyFromModulesDir(from: string, tail = ""): Promise<void> {

await copyFromModulesDir(
"nacl.js",
"\n//added by nkeys.js export it \nexport const nacl = self.nacl;\n",
"\n//added by nkeys.js export it \nexport const nacl = global.nacl;\n",
);
await copyFromModulesDir("nacl.d.ts");
6 changes: 3 additions & 3 deletions modules/esm/nacl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ nacl.setPRNG = function(fn) {
(function() {
// Initialize PRNG if environment provides CSPRNG.
// If not, methods calling randombytes will throw.
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
var crypto = typeof global !== 'undefined' ? (global.crypto || global.msCrypto) : null;
if (crypto && crypto.getRandomValues) {
// Browsers.
var QUOTA = 65536;
Expand All @@ -1179,7 +1179,7 @@ nacl.setPRNG = function(fn) {
}
})();

})(typeof module !== 'undefined' && module.exports ? module.exports : (self.nacl = self.nacl || {}));
})(typeof module !== 'undefined' && module.exports ? module.exports : (global.nacl = global.nacl || {}));

//added by nkeys.js export it
export const nacl = self.nacl;
export const nacl = global.nacl;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nkeys.js",
"version": "1.0.3-1",
"version": "1.0.3-2",
"description": "A public-key signature system based on Ed25519 for the NATS ecosystem in javascript",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down

0 comments on commit 22cc5d1

Please sign in to comment.