diff --git a/pubky/pkg/.gitignore b/pubky/pkg/.gitignore index d2a005f..3a61269 100644 --- a/pubky/pkg/.gitignore +++ b/pubky/pkg/.gitignore @@ -1,5 +1,8 @@ -browser.js coverage node_modules package-lock.json -pubky* +pubky.d.ts +pubky_bg.wasm +nodejs/ +index.js +index.cjs diff --git a/pubky/pkg/index.cjs b/pubky/pkg/node-header.cjs similarity index 76% rename from pubky/pkg/index.cjs rename to pubky/pkg/node-header.cjs index bd8a6a2..07de852 100644 --- a/pubky/pkg/index.cjs +++ b/pubky/pkg/node-header.cjs @@ -2,5 +2,3 @@ const makeFetchCookie = require("fetch-cookie").default; let originalFetch = globalThis.fetch; globalThis.fetch = makeFetchCookie(originalFetch); - -module.exports = require('./nodejs/pubky') diff --git a/pubky/pkg/package.json b/pubky/pkg/package.json index c0a06de..87459b5 100644 --- a/pubky/pkg/package.json +++ b/pubky/pkg/package.json @@ -2,7 +2,7 @@ "name": "@synonymdev/pubky", "type": "module", "description": "Pubky client", - "version": "0.2.0", + "version": "0.2.1", "license": "MIT", "repository": { "type": "git", @@ -18,12 +18,12 @@ }, "files": [ "index.cjs", - "browser.js", + "index.js", "pubky.d.ts", "pubky_bg.wasm" ], "main": "index.cjs", - "browser": "browser.js", + "browser": "index.js", "types": "pubky.d.ts", "keywords": [ "web", diff --git a/pubky/pkg/test/http.js b/pubky/pkg/test/http.js index a11a63d..e861f26 100644 --- a/pubky/pkg/test/http.js +++ b/pubky/pkg/test/http.js @@ -6,7 +6,7 @@ const TLD = '8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo'; // TODO: test HTTPs too somehow. -test("basic fetch", async (t) => { +test.skip("basic fetch", async (t) => { let client = PubkyClient.testnet(); // Normal TLD diff --git a/pubky/src/bin/patch.mjs b/pubky/src/bin/patch.mjs index 86983b6..1760bff 100644 --- a/pubky/src/bin/patch.mjs +++ b/pubky/src/bin/patch.mjs @@ -54,4 +54,22 @@ const bytes = __toBinary(${JSON.stringify(await readFile(path.join(__dirname, `. `, ); -await writeFile(path.join(__dirname, `../../pkg/browser.js`), patched + "\nglobalThis['pubky'] = imports"); +await writeFile(path.join(__dirname, `../../pkg/index.js`), patched + "\nglobalThis['pubky'] = imports"); + +// Move outside of nodejs + +await Promise.all([".js", ".d.ts", "_bg.wasm"].map(suffix => + rename( + path.join(__dirname, `../../pkg/nodejs/${name}${suffix}`), + path.join(__dirname, `../../pkg/${suffix === '.js' ? "index.cjs" : (name + suffix)}`), + )) +) + +// Add index.cjs headers + +const indexcjsPath = path.join(__dirname, `../../pkg/index.cjs`); + +const headerContent = await readFile(path.join(__dirname, `../../pkg/node-header.cjs`), 'utf8'); +const indexcjsContent = await readFile(indexcjsPath, 'utf8'); + +await writeFile(indexcjsPath, headerContent + '\n' + indexcjsContent, 'utf8')