News for hackers. Stuff that matters.
Re:Deno 1.6 supports compiling TypeScript to a single execut... by mark_and_sweep on Wednesday December 09, 2020 @09:15PM (#25368761)
> The difference is that NPM as an org has a lot more to lose if they mess up everyones packages

How is that important? Most Deno packages are imported from GitHub (or deno.land). Neither NPM nor GitHub want to lose your code.

> Left pad was promptly fixed! That's an argument for a centralized package manager, not against.

This is not an argument for a central package manager, but an argument for a central package repository.

Deno is already a "central package manager". Similar to NPM in Node development, Deno is the default tool to download code in Deno development. Both with Node or Deno, you can download code in other ways, too. Nobody forces you to load code from URLs via import statements or NPM packages via npm install and commonjs require. (Also, when it comes to executing random code from the internet, Deno has a sandbox. Node doesn't.)

And yes, well maintained package repositories are great. Whether centrally or decentrally managed repos are better is up for debate, though.

In any case, if you want to use NPM packages in Deno, I'd recommend https://www.skypack.dev/. It's "NPM packages from a URL", so, as we have established earlier, it's just as much reliant on trust and potentially unstable as anything in life, but at least their left-pad is patched...

Re:Deno 1.6 supports compiling TypeScript to a single execut... by nikisweeting on Wednesday December 09, 2020 @09:27PM (#25368856)
I am not proposing that Deno remove URL support, I think it's great that they allow importing from URL as an option. I just wish they also supported importing from local npm packages installed in node_modules without needing to specify a URL/full path. This would allow full inter-compatibility with the existing packaging ecosystem and allow people to continue using whatever packaging method they prefer.
Re:Deno 1.6 supports compiling TypeScript to a single execut... by mark_and_sweep on Wednesday December 09, 2020 @09:36PM (#25368943)
> I just wish they also supported importing from local npm packages installed in node_modules without needing to specify a URL/full path.

Import maps allow you to do that, see: https://deno.land/manual/linking_to_external_code/import_map...

Re:Deno 1.6 supports compiling TypeScript to a single execut... by nikisweeting on Wednesday December 09, 2020 @09:45PM (#25369008)
Ah cool, that helps a ton. The existence of this feature as the linchpin for compatibility with npm is not clear from the rest of the Deno docs though. Perhaps it could be linked to from this page: https://deno.land/[email protected]/examples/import_export.

Also, it seems as though ./node_modules/ being the default could be assumed automatically though, no?

    "imports": {
        "moment": "/node_modules/moment/src/moment.js",
        "lodash": "/node_modules/lodash-es/lodash.js"
    }
Considering it's the default in all other JS environments, wouldn't that save the hassle of the dev having to define this for their entire tree of JS dependencies? Then Deno would be a drop-in replacement and we could move our whole codebase over to it overnight (once the Node APIs are up to par).
Re:Deno 1.6 supports compiling TypeScript to a single execut... by mark_and_sweep on Thursday December 10, 2020 @03:22AM (#25371213)
> Also, it seems as though ./node_modules/ being the default could be assumed automatically though, no?

No, there is no magic node_modules directory in any other JS environment, other than Node. Deno aims to be compatible with web standards. Import and import maps are web standards, require and node_modules aren't.

> Deno would be a drop-in replacement and we could move our whole codebase over to it overnight

The reason that you cannot move your existing codebase to Deno tonight is essentially the poor web compat of the existing Node ecosystem.

Re:Deno 1.6 supports compiling TypeScript to a single execut... by nikisweeting on Thursday December 10, 2020 @06:28AM (#25372518)
Node is the standard web environment, even frontend code is built 90% of the time using Webpack or another bundler running in a node environment and pulling from node_modules.

I don't think you can blame the incumbent tool with complete market dominance for "poor compatibility"...

I really like the direction of the Node compatibility layer though https://deno.land/[email protected]/node, I suspect it will be enough to make Deno a drop in replacement soon. Now it just needs support for normal `import` statements from node_modules instead of just `require()`.

Re:Deno 1.6 supports compiling TypeScript to a single execut... by mark_and_sweep on Thursday December 10, 2020 @07:52AM (#25373146)
Last time I checked jQuery was used on 9 out of 10 websites using JS with 8 out of 10 websites being powered by PHP.

How dare Node not be compatible with the market dominating jQuery! Silly server-runtime not having a browser window object!

> Now it just needs support for normal `import` statements from node_modules

Deno will never ever do that (other than by using standardized import maps) since that's not normal (normal meaning standardized).

Re:Deno 1.6 supports compiling TypeScript to a single execut... by nikisweeting on Thursday December 10, 2020 @08:29AM (#25373460)
I don't understand, jQuery works fine in node-built environments. Obviously any DOM mutation stuff stuff needs to happen in the frontend when it runs in the browser, but you can absolutely import jquery and use parts of it during server-side compiling or rendering steps in node.

    import $ from "jquery"
> Deno will never ever do that

Why would Deno take such an antagonistic approach to supporting the most common setup that everyone uses with npm? Wouldn't it be trivial to just fall back to checking node_modules for named packages? I want to use Deno! This seems like it's deliberately making transitions difficult for anyone using npm.

Re:Deno 1.6 supports compiling TypeScript to a single execut... by mark_and_sweep on Thursday December 10, 2020 @09:25AM (#25373973)
Sorry, jQuery was a bad example - I remember jQuery not working in Node at all, but that was roughly 10 years ago. Things have improved.

The fact remains that the most popular JS env is the browser. It has APIs such as window which are not compatible with Node and Node has APIs which are not compatible with the browser like __dirname or require. That's why tools such as browserify and webpack exist to bridge the gap.

In Deno the gap is much closer. Obviously, the Deno namespace is not available in the browser (but there's a shim for most APIs, e.g. Deno.writeFile and readFile are implemented with a virtual FS) and some web APIs are not available in Deno (yet), but the compat story is much better.

This is no surprise since web compat is a core goal of Deno. Node compat is not.

> Wouldn't it be trivial to just fall back to checking node_modules for named packages?

No, the resolution algo is not trivial (nor performant). Also, it's not necessary: There is already a standard for how to import code in JS; it's import statements. Import statements do not allow named packages, e.g. import $ from "jquery" does not work in the browser. Except, again, import maps.

Re:Deno 1.6 supports compiling TypeScript to a single execut... by nikisweeting on Thursday December 10, 2020 @09:37AM (#25374086)
> Node compat is not.

:'( That's a shame, it would make such a good node replacement with a great stdlib and Typescript support. I hope they reconsider in the future.

Re:Deno 1.6 supports compiling TypeScript to a single execut... by mark_and_sweep on Thursday December 10, 2020 @12:40PM (#25376202)
If Deno was only "Add TypeScript support", "Add security capabilities", and "Add URL imports", etc. it would simply be a new version (or multiple new versions) of Node.

These (and other) disruptive breaking changes are about fixing mistakes that cannot be fixed (or at least, are hard to fix) in Node.

Maybe, in a few years, you'll say something like "Oh, I wish legacy Node would be more Deno compatible" because Deno will be the de-facto server-side JS scripting runtime. Equally, it's possible that Deno will fail, but that many good ideas will be incorporated into Node as breaking changes.

Node and Deno as well as their environments can grow further together or further apart. I think it's too early to tell which future is more likely.

Re:Deno 1.6 supports compiling TypeScript to a single execut... by wperron on Thursday December 10, 2020 @10:47AM (#25374917)
_If_ the node library uses explicit file imports, and ESM instead of CJS, it _is_ already possible to just do `npm install` and import from "./node_modules" -- again the problem is that Node's import resolution algorithm is horribly complex and not very explicit, but it's possible to be explicit using Node, and that would make it compatible in Deno
Re:Deno 1.6 supports compiling TypeScript to a single execut... by nikisweeting on Friday December 11, 2020 @06:02PM (#25392785)
Considering you can generate the import maps from a given npm/yarn lockfile (https://www.npmjs.com/package/@import-maps/generate/v/0.1.0) wouldn't it be possible for Deno to provide a command to do this and get the benefits of both backward npm/yarn compatibility and forward web compatibility with import-maps?