Comments (5)
Yeah I was thinking there would be an opt-in option to tell publint that this package, by default, works with bundlers/node/browser only. And if the option is not specified, it would mention something like "this entrypoint works with bundlers only".
Thanks for the tip about using TS! I might try that as a last resort since it increases the package size quite a bit, and it'd have to work in the browser too. I've got a good base to start with (https://github.com/bluwy/fmu) so I'll probably work from there. (I saw you were working something similar on Twitter too)
from publint.
Yeah, TS will indeed increase bundlesize by quite a bit. It does run in the browser however, which is nice (here's an example of a tool I built that uses TS compiler to create an AST and analyze it, it runs fully in the browser: https://custom-elements-manifest.netlify.app/) 🙂 It does require some build magic to bundle it correctly for the browser, however. If you do end up going down that road I'd be happy to share some findings, but it seems like fmu
will probably do the trick 😄 (Thanks for linking that btw! Im currently learning Rust, so its very helpful to take a look at different implementations)
from publint.
Piggy backing off of this discussion on twitter: https://twitter.com/passle_/status/1626222241091579904?s=20
It could be good to also flag other non-standard imports, like:
import css from './styles.css';
import data from './data.json';
and potentially even other non-standard, conventional-ey, magic-ey imports?
Additionally, it seems like this feature would be a great usecase for es-module-lexer 🙂
from publint.
Yeah that would be good to check too. I'm not sure if it needs to be flagged always as a package/entrypoint can be advertised to only work with bundlers. It goes a bit in hand with #19, but I have some ideas to conditionally raise this forward.
Re es-module-lexer
, I'd also like to lex CJS require()
(best effort) but cjs-module-lexer
doesn't do that. Might be time to yak shave one.
from publint.
Perhaps it should be made configurable then, imo (and this is where the tool becomes opinionated 😄 ) packages shouldn't publish non-standard imports by default. If a package advertises to be used with a bundler, that should be opt-in behavior.
Good point regarding es-module-lexer
. I've previously used TS for collecting the imports/exports in a file:
https://github.com/open-wc/custom-elements-manifest/blob/master/packages/analyzer/src/features/collect-phase/collect-imports.js
https://github.com/open-wc/custom-elements-manifest/blob/master/packages/analyzer/src/features/analyse-phase/exports.js
It could be made to work with commonjs/require, too.
The benefit of using TS (over for example acorn or babel) to do the static code analysis for imports/exports is that it's pretty forgiving and doesn't error on unexpected syntax. This is nice, because it means less maintenance work whenever new syntax is introduced to the language. (This is something that unpkg.com currently struggles with, it uses babel to transform module specifiers on the fly, but that errors on new syntax, like optional chaining, and causes unpkg to just break for packages that use unsupported syntax)
from publint.
Related Issues (20)
- Suggest avoiding UMD for CJS only packages HOT 1
- Warning message displays error HOT 2
- "module": true -- crash
- "module": "" -- "All good!" from publint HOT 4
- Incorrect pkg.main ESM detection
- [bug] .cjsx is not okay. Error message says it should be renamed to .cjsx HOT 5
- Suggest using pkg.files HOT 2
- Suggest "internal resolution error" for types wrongly declared from a TS point-of-view (node native esm) HOT 1
- wrong error for "main" HOT 6
- suggest "npmignore or files" instead of just files HOT 4
- Skip "The package publishes internal tests or config files" check? HOT 8
- Suggest adding `"type"` field to all packages HOT 3
- Monorepo support HOT 1
- Check if root is exported through mainFields but not exports
- API endpoint to analyse remote packages HOT 2
- Warn on the usage of fallback arrays in the `exports`/`imports` field
- feature requerst: badges like shields.io HOT 1
- Upgrade warning to error HOT 1
- File existence checks does not work on exports of non-js files HOT 5
- [NEW RULE] Check "repository.url" value HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from publint.