by zkldi · 5y ago · 0 comments
The standard practice of deps.ts/dev_deps.ts as described in the docs[1] just seems absolutely asinine to me. Importing everything into one scope and then re-exporting from one file just seems like an awful hack.
What do you do if two libraries have functions with the same name? Do you namespace them yourself, or export an object under the name of the library (and therefore give up destructuring?)
The URL thing seems similarly cumbersome and unecessary. Is there something wrong with a configuration file that would map 'package names' to the urls to get them from?, and then import { foo } from "packagename"?
[1]https://deno.land/manual@v1.9.0/examples/manage_dependencies
You can only import a single file per import statement.
Developers create "barrel" files that allow them to re-export all of the important stuff in a folder externally. This allows for namespacing
// foo/index.ts
export * from './foobar'
// main.ts
import * as foo from './foo/index'
new foo.Foobar()
Or use destructured imports to help with static analysis tool that trace imports removing unused references from the final build // main.ts
import { Foobar } from './foo/index'
Node has non standard behaviour where it appends `/index` to the import path if it's a folder allowing you to shorten imports to import {} from './foo'It would be much easier if it was one namespace like in Node.js require. eg. var Foo = await requires("foo", {fs: "/home/user"})
Node.js modules are pretty much perfect besides the security flaws.
You can get around this with a double barrel. In the outer barrel, export your individual things
// index.barrel.js
export * from './foo.js'
Then in your main barrel re-export them under a namespace // index.js
export * as foobar from './index.barrel.js'
Then from you application you are forced to have a named import with the namespace defined // main.js
import { foobar } from './foobar/index.js'
foobar.foo()
You can submit a proposal to introduce namespacing to ES6 importsThis feels to me a bit like if a new browser came around and said "DNS is the root of all evil" and only allowed you to directly type in the IP address of websites.
You can make all kinds of excuses, like "oh, but you can keep a list of your own!" or "hey, you can install this plugin that gives you DNS lookups back", but ultimately as a user I'm gonna say "No thanks, I'll keep using a browser that doesn't needlessly complicate my day."
I'm usually an early adopter for this kind of stuff, and I really like a lot about Deno, which is why this situation just makes me very sad.
export * as Oak from "https://deno.land/x/oak/mod.ts";
export * as Postgres from "https://deno.land/x/postgres/mod.ts";
Then you do this: import { Oak, Postgres } from "./deps.ts";I know you can do this, but then you can't do
import { Function1, Function2 } from "oak";
You could do import { Oak } from "./deps.ts";
const { Function1, Function2 } = Oak;
But that is still an awful workaround. import { Function1, Function2} from "https://deno.land/x/oak/mod.ts";
In the file that needs them? Though then you have a lot of redundant URLs everywhere and god knows how auto-imports could work.Or perhaps you could do
// deps/oak.ts
export * from "https://deno.land/x/oak/mod.ts";
and then you'd do import { Function1, Function2 } from './deps/oak';
I am not a fan of any of these.It updates your dependencies. https://github.com/hayd/deno-udd
There are one or two more feature rich ones. The need for deps.ts can be eliminated with management tools which work with your imports directly.
If something like that is needed, then I think deno should attempt to come with something for managing dependencies.
Eventually, developer convinience will win, and everyone will settle on some sort of package manager for deno. It'd probably be for the best if deno made it official as, personally, I think this is heading towards a second NPM.
If a server gets hacked those TS can be replaced with malicious versions.
In npm we at least know that a package is immutable once published, someone could publish a malicious version as a newer release but a current release.
Does demo generate some type of file that keeps a hash of all downloaded imports to verify against the next time those imports are downloaded?
The same problem (and solution: package-lock.json or yarn.lock) exists in npm if you use semver version specifiers, or npm itself could be hacked, it’s just a bit more acute in Deno since it’s easy and common to load files from arbitrary hosts that don’t enforce immutable versions.
This is only true as long as you trust NPM. If they were hacked or taken over by a malicious actor, packages could be modified unbeknownst to you.
(If your project only has one module, then you don’t have this problem and don’t need this solution.)
Why not instead create a deps directory, and keep in it one file per dependency? Inside each file, you re-export the library from URL.
This way you can import from files rather than URLs elsewhere in your code, and it should be clear which dependency is being imported from the file name itself.
Perhaps you should be less quick to label anything about it "asinine" or even "awful hack".
No one is infallible. That said, creating Deno after Node doesn't imply that Node was a fail or that Deno will be perfect. Obviously not.
Consider that someone really smart has reasons for doing (or trying to do) things a certain way. Be humble!
Example of the "common caterpillar" genus of node quirks and the awful antagonistic responses by the dev team: https://github.com/nodejs/node/issues/25857
Just take a look at a random stdlib source file: https://github.com/nodejs/node/blob/master/lib/readline.js
``` if (input && input.input) { // An options object was given output = input.output; completer = input.completer; terminal = input.terminal; history = input.history; historySize = input.historySize; signal = input.signal; ```
It's junior-level code writing all over the project. That is a failure in my mind, especially when I know the library backing my project has to import all that junk hidden from view.
See (wontfix) fs.promises.readFile is 40% slower than fs.readFile: https://news.ycombinator.com/item?id=26332774
Not to mention the awkward political nature. There is a BLM banner on their front page: https://nodejs.org .The founder of BLM, Patrisse Cullors, just bought 4 mansions, the last for $1.4 Million USD: https://news.yahoo.com/blm-official-calls-investigation-foun...
Node's dev team is not interesting in supporting the community. They are amateurs who are trying to be woke and add "top Node contributor" to their toolbelt of proverbial ego items. Prove me wrong.
I do not understand why deno has gone for this route. It seems primed to produce a package manager eventually, and it seems like a bad idea to leave package manager creation down to whoever makes the first decent tool (which is mostly why npm is the standard for node.)