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
npm package should not include .ts files #2393
Comments
Yeah, I agree that we are publishing the wrong stuff. It should be a simple fix: instead of publishing our Javascript source directory which is useless, we should publish the built files. Nobody here knows how to use node all that much so we haven't fixed it. |
For the record, to get something that actually works right now:
|
After some exploration, it seems that what will work is to copy Some issues:
|
@hoodmane , I normally use a combination of files1 (example), main2 (because I focus on Node.js packages, frontend has different requirements I'm a bit hazier on) (example), and types3 (when using TypeScript). The documentation on So you can use some value for Footnotes
|
Okay. Is there some standard way to say "if they try to |
Yes there is but I haven't used es6 modules myself. I believe you just include "main": "./dist/src/pyodide.js",
"module": "./dist/src/pyodide.mjs", in the package.json. When the npm package is loaded as common js the |
I don't find |
I'm not either 😅 I'm seeing
but googling is suspiciously quiet on this. I was reading this article just yesterday that also uses the |
Ok, I can help with this as I'm primarily a node / js user but have also used only python for several years. Typically, with typescript, you'd run The built js, package.json, and any wasm files need to be included in that dist folder. Then cd into dist and publish. I can open a pr to resolve some of that and you let me know if I miss anything. |
What about if our |
Also, our distribution is very large (200mb) but only 15mb is needed to run the interpreter and the rest are packages. It might be good to eventually add some way to split things up a bit so people don't have to download so much stuff if they won't use it. |
The package. Jason needs to be in the folder with the built js and you can execute publish from that location. Publish builds your archive in the cwd |
Okay, so roughly |
Some experimentation shows that |
Okay, after some trial and error, hoodmane-pyodide@0.20.0-g seems to work correctly. I used this branch: import { loadPyodide } from "hoodmane-pyodide/pyodide.mjs";
async function main(){
let pyodide = await loadPyodide();
pyodide.runPython("print(1+1)");
}
main(); and let {loadPyodide} = require("hoodmane-pyodide");
async function main(){
let pyodide = await loadPyodide();
pyodide.runPython("print(1+1)");
}
main(); work as expected. It seems like we only get one entrypoint, we can choose whether the commonjs or the es6 entrypoint is preferred, the other has to be imported like |
I know that works in a relatively straightforward way, but I think Besides we are already installing packages from PyPi anyway, so we won't be able to put all dependencies on npm anyway. |
I believe what you want is to use exports in the package.json to define what file to use depending on the module definition (common vs. esm). https://www.the-guild.dev/blog/support-nodejs-esm #package.json {
"main": "pyodide.js",
"exports": {
"require": "pyodide.js",
"import": "pyodide.mjs"
}
} The module and exports are not official sections yet. However, node looks at the exports field since v12 LTS. Module is used for bundlers like webpack - maybe rollup also looks at modules but I'm not as familiar with it. |
@rth the package @hoodmane published recently as a test contains roughly 18mb on disk and contains everything I understand is needed to execute pyodide. The wasm binary, pyodide js, asm.js, and web workers. Anything the user installs later via pyodide install or micropip should continue to work as it does currently (pull from pypi or pyodide cdn). One option could be to run a postinstall script that downloads larger files after the install from a CDN. However, some security focused organizations like to disable post install scripts which could make onboarding pyodide slightly harder. The onus is on those users to handle the post install themselves if they choose to disable it. I personally think 18mb is large but not massive for an npm packages total footprint. A typical react app is going to pull more than that down when you look at the size of all transient dependencies. |
Sounds good then, I read the discussion too fast :) |
And remember what you are doing here is installing Python using |
Just ran into this while trying to use the pyodide npm package as a dependency in my own package (alexmojaki/pyodide-worker-runner#8).
My intended environment is a browser, but I can't even run a webpack build. After fighting with configuration a bit, I hit an impasse because the
Ultimately I'd like to use the Pyodide npm package for the type declarations and to use |
BTW, the final package can still include the .ts source files in addition to the built .js files. This can be used for source maps, by the IDE, or just informally to look at source code in |
I think there's some risk of confusion between import { loadPackage } from "./pyodide"; in a typescript file, won't it use
I think we are including source maps. |
Well probably we should fix that too. It would be helpful if anyone who is better at node/webpack/typescript could contribute to #2397. Currently our mocha tests don't even run and I haven't figured out why. #2394 improves the situation a bit. Maybe we should deploy a release (maybe |
🐛 Bug
I just did an
npm i pyodide
wanting to use this as part of a projec for packaging AWS Lambda packages to support the Python Lambda Functions. I've been testing out pyodide and brython to see which one makes more sense. I am really liking pyodide. Up to now I've been including the file from a cdn and it's gone fine. However, the package on npm includes all of the typescript files.An npm package should include type definitions (.d.ts) files for typescript and javascript users for type definitions. The rest of the code, however, should all be javascript. When you publish .ts files I have to now configure whatever build system I'm using (webpack) to support typescript and to explicitly hand transpiling the code. This is not the common way to distribute a package on npm.
In addition there is no main file defined in package.json. I am unsure what the main file is that I should include in order to get the full source.
To Reproduce
npm i pyodide
Expected behavior
When I installed this I expected:
I believe all of these files should be included. This will make integration into other packages much easier.
Environment
Additional context
I am happy to work on this if you agree. Hopefully I didn't misinterpret the point of the package on npm.
I have recently been using esbuild which is written in go and distributes a wasm for bundling. That code is successfully on the develop branch of cdk-web https://github.com/3p3r/cdk-web/tree/develop. I am comparing my experience dealing with the package distributed on npm for esbuild-wasm vs. my experience with pyodide.
The text was updated successfully, but these errors were encountered: