Skip to content

Commit

Permalink
Dual ESM/CJS Demo (Concept)
Browse files Browse the repository at this point in the history
Looking into whether this is something that NBTify would actually be neat in having. I'm not completely sure it's necessary yet. (In terms of what I think this package is meant to be used for. No doubt do I think dual-build packages are amazing in their own right!)

I think I'm trying to decide whether the complexity of supporting both is worth the hassle in terms of it splintering into multiple ways of potentially using the package. I don't know if I fully like that concept. It reminds me of the divide between Java and Bedrock as well.

I'm not sure about the bundle-related things yet either, from a package perspective. Should I bundle dependencies for use in Node? Should it be minified? If things are bundled for the browser anyways, people have mentioned that you should let the users of your package decide how they want to handle the build of your package, not to have you do it for them. I can understand that as well.

https://antfu.me/posts/publish-esm-and-cjs
https://medium.com/swlh/npm-new-package-json-exports-field-1a7d1f489ccf
https://nodejs.org/api/packages.html#package-entry-points
https://nodejs.org/api/packages.html#dual-commonjses-module-packages
  • Loading branch information
Offroaders123 committed Feb 15, 2024
1 parent b41d57f commit 806915a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
"version": "1.85.0",
"description": "A library to read and write NBT files on the web!",
"type": "module",
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"bin": {
"nbtify": "dist/bin/index.js"
"nbtify": "dist/bin/index.cjs"
},
"scripts": {
"build": "pkgroll",
Expand Down
6 changes: 5 additions & 1 deletion src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { file, nbt, snbt, format, space } from "./args.js";

import type { RootTag } from "../index.js";

(async () => {

if (file === undefined){
file satisfies never;
throw new TypeError("Missing argument 'input'");
Expand Down Expand Up @@ -51,4 +53,6 @@ if (!nbt && !snbt){
const result: string | Uint8Array = snbt
? `${stringify(output,{ space: space ?? 2 })}\n`
: await write(output);
await promisify(process.stdout.write.bind(process.stdout))(result);
await promisify(process.stdout.write.bind(process.stdout))(result);

})();

0 comments on commit 806915a

Please sign in to comment.