Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transpile: feature: add a package.json to generated output? #341

Open
jcbhmr opened this issue Jan 16, 2024 · 4 comments
Open

transpile: feature: add a package.json to generated output? #341

jcbhmr opened this issue Jan 16, 2024 · 4 comments

Comments

@jcbhmr
Copy link

jcbhmr commented Jan 16, 2024

To clarify: I'm not necessarily asking for this to be the default behavior, just an additional option.

When I use jco, I often find myself needing to add a package.json so that:

  1. I can rely upon the generated JavaScript to install its own dependencies {"dependencies":{"@bytecodealliance/preview2-shim":"$VERSION"}}
  2. I can tell Node.js to interpret the .js files as "type": "module" files

Essentially my scripts end up looking like this:

jco transpile target/wasm32-wasi/my_lib.wasm -o ./somewhere
echo '{
  "type": "module",
  "dependencies": {
    "@bytecodealliance/preview2-shim": "~0.14.2"
  }
}' > ./somewhere/package.json
npm install
// my main package.json
{
  "workspaces": ["./somewhere"]
}

Instead, I suggest adding a feature to allow generation of a package.json file when using jco transpile. Something like a --package-json or --generate-package or --package or --manifest idk.

Why this would be good:

  1. Be able to specify a specific version of @bytecodealliance/preview2-shim that jco is generating code for
  2. Allow Node.js users to use the code via Node.js' REPL without having a package.json with {"type":"module"} somewhere.

Note that I'm not suggesting anything relating to package naming, versioning, exports, main, author, or any other "I want to publish this package.json to the npm registry" fields. The package.json I want is strictly to allow it to integrate with my existing npm projects as a "sub-thing" (not sure how to describe it) that's specific to my project (with a bunch of --map "the:component/thing=./thing.js") NOT to generate a publishable npm package -- that's a separate discussion i think

@jcbhmr jcbhmr changed the title Feature: Add a package.json to generated output? transpile: feature: add a package.json to generated output? Jan 16, 2024
@yoshuawuyts
Copy link
Member

If I'm not mistaken, the wasmpack tool built support for exactly this feature. As well as auto-generating README.md files with API descriptions, as is customary when uploading packages to npm. It should be possible to reuse some of the code and add this directly to jco.

@jcbhmr
Copy link
Author

jcbhmr commented Jan 23, 2024

I don't necessarily want a publish-ready package.json; all I'm looking for is something that tells Node.js that the .js files in the --out-dir folder are ESM JavaScript files instead of the default CommonJS that Node.js assumes.

The dependencies: {} was just an added bonus idea that works well with npm workspaces.

tl;dr: i just wanted {type:"module"} lol -- i dont really care one way or the other about publish-ready package.json generation

@guybedford
Copy link
Collaborator

If all goes to plan, Node.js should be defaulting to type detection in the April release, so in future we likely won't need that property (although for Node.js package publishing it will continue to be recommended).

@jcbhmr
Copy link
Author

jcbhmr commented Jan 23, 2024

Node.js should be defaulting to type detection in the April release

🤩 amazing! that's still 3 months away tho lol. and idk what the nodejs backporting situation is but who knows if that'll trickle down to v18 or whatever 🤷‍♀️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants