Skip to content
This repository was archived by the owner on Mar 30, 2020. It is now read-only.

Conversation

@bennypowers
Copy link
Contributor

see #1 (comment)
in order to match with the original package, i think this should only output esm, not system

crocks/helpers/compose fails to load, it has to be crocks/esm/helpers/compose, which breaks compatibility

@internettrans
Copy link

I disagree. System.register modules are an emulation of ESM modules. I maintain systemjs and the esm-bundle organization exists partially because the systemjs community uses it.

@bennypowers
Copy link
Contributor Author

That's fair. you should update the docs to specify that any package that uses deep module reference cannot be published using this technique.

This module should be deprecated on npm.

@internettrans
Copy link

This module should be deprecated on npm.

Are you referring to the @esm-bundle/crocks package? Why should it be deprecated?

@bennypowers
Copy link
Contributor Author

This module should be deprecated on npm.

Are you referring to the @esm-bundle/crocks package? Why should it be deprecated?

Yes. @esm-bundle/crocks should be deprecated.

The reason why is that @esm-bundle breakscrocks' API.

crocks exposes deep modules

import compose from 'crocks/helpers/compose';

@esm-bundle does not and will not support deep module references

If a user implements crocks according to the published docs under @esm-bundle/crocks, and that user utilizes crocks' deep module API, their app will break.

so @esm-bundle is incompatible with this package

TL;DR: in order not to break crocks' API contract with users, @esm-bundle should be deprecated.

@internettrans
Copy link

@esm-bundle does not and will not support deep module references

You have completely misunderstood what I've been saying. I am okay with supporting deep module references. However, I have a strong preference towards doing so with babel instead of bash. See related #18 where I explain how this can be done.

@bennypowers
Copy link
Contributor Author

bennypowers commented Mar 25, 2020

You have completely misunderstood what I've been saying

I'm happy to be corrected

Will the approach in #18 produce

/esm and /system ?

And I'm supposed to tell users to install a babel plugin that transforms their import specifiers?

@internettrans
Copy link

internettrans commented Mar 25, 2020

And I'm supposed to tell users to install a babel plugin that transforms their import specifiers?

No - babel would be run instead of rollup as part of the build process for @esm-bundle/crocks.

Will the approach in #18 produce /esm and /system ?

Yes, the approach in 18 can produce both /esm and /system

  1. yarn add --dev cross-env concurrently @babel/cli babel-esm-plugin @babel/plugin-transform-modules-systemjs
  2. Create .babelrc
{
  "env": {
    "esm": {
      "plugins": ["babel-esm-plugin"]
    },
    "system": {
      "plugins": ["@babel/plugin-transform-modules-systemjs"]
    }
  }
}
  1. Change package.json:
{
  "scripts": {
    "build": "concurrently -n w: 'build:*'",
    "build:esm": "cross-env BABEL_ENV=esm babel src --out-dir esm --source-maps",
    "build:system": "cross-env BABEL_ENV=system babel src --out-dir system --source-maps"
  }
}
  1. yarn build

@bennypowers
Copy link
Contributor Author

Yes, the approach in 18 can produce both /esm and /system

forgive my persistence, but this is the part I'm having trouble understanding

If the build process produces /esm and /system, then how am I supposed to

import compose from 'https://unpkg.com/@esm-bundle/crocks/helpers/compose?module';

Instead, wouldn't I have to

// potentially breaks because of internal deep references
import compose from 'https://unpkg.com/@esm-bundle/crocks/esm/helpers/compose?module';

@internettrans
Copy link

Yes you'd have to use https://unpkg.com/@esm-bundle/crocks/esm/helpers/compose. Why is that a problem?

I don't think you'd need unpkg's ?module flag, either. The imports between files should be relative.

@bennypowers
Copy link
Contributor Author

Yes you'd have to use https://unpkg.com/@esm-bundle/crocks/esm/helpers/compose. Why is that a problem?

Right. This will break apps.

System.js is fine-and-dandy, but I want JavaScript modules that come-as-they-are.

Please deprecate the package I'll have to find another way for this library.

@internettrans
Copy link

internettrans commented Mar 26, 2020

You seem upset / disappointed. I’m open to making changes, but need to understand why before doing so. Thus far you have insisted that my approach will break things, but you have not offered an explanation why. I don’t think that making dramatic statements (“deprecate the package”) is helpful in communicating. If there’s a valid use case for removing the esm directory, I’m open to doing so. But I need an explanation why.

I think the main reason why we’re struggling to communicate effectively is because we use ES modules differently. Here is how I use ES modules:

I use the esm-bundle packages within the browser, not in a bundler. I use import maps to control the url to the directory of the package (which includes the /esm/ directory). Then I can do things like import “crocks/Thing.js” and it works.

How are you importing the modules? As in-browser modules? Or are you using a bundler like webpack / rollup? Or maybe are you using the nodejs implementation of modules? Something else?

@bennypowers
Copy link
Contributor Author

bennypowers commented Mar 27, 2020

You seem upset / disappointed.

Not gonna lie, I had hoped to make a home here :) I have lots of ideas for packages that would benefit from this treatment.

I don’t think that making dramatic statements (“deprecate the package”) is helpful in communicating.

True, I apologize for the charge in the words. it's a stressful time and you don't need me adding to that.

If there’s a valid use case for removing the esm directory, I’m open to doing so. But I need an explanation why.

I think the main reason why we’re struggling to communicate effectively is because we use ES modules differently. Here is how I use ES modules:

I use the esm-bundle packages within the browser, not in a bundler. I use import maps to control the url to the directory of the package (which includes the /esm/ directory). Then I can do things like import “crocks/Thing.js” and it works.

How are you importing the modules? As in-browser modules? Or are you using a bundler like webpack / rollup? Or maybe are you using the nodejs implementation of modules? Something else?

This library can be used in node (native or with esm polyfill or babel-register) or on the browser, and it uses the es module spec that includes deep module references. e.g. crocks/helpers/compose.js

Really, my hope here is that anyone can take any CJS package, transform it to ESM as I've proposed to do (implementation of that transform is irrelevant, only the outputs concern me), and then use that package exactly as they would have the cjs modules in other circumstances

So in the specific case of crocks, I use @rollup/plugin-commonjs to import those deeply referenced modules (crocks/logic/when) in to my (a) library packages and (b) app code

This closed PR is therefore a blocker for apollo-elements/apollo-elements#57

TL;DR: I use es modules as es modules. Not as modules with import maps, or as modules with build-time usage caveats.

It's my hope that I'll be able to use this project to convert any CJS package to esm, and use it without changing anything about the consumer asides from the npm package reference in package.json. Requiring an additional step like import maps or build-time aliasing kind of defeats the purpose for me.

So if I have to change the bundler to alias imports to the-pkg/esm/$1, then I'm not covered.

Communication, Nomenclature, and the Purpose of this Project

I think import maps and build-time aliasing are good and worthy tools, I just wouldn't want this project to require them, given this project's "pitch".

I think part of my confusion and disappointment here stems from the name of this project. @esm-bundle indicated to me that I'd be getting exactly that, ECMAScript modules. If the goal of this project is to provide SystemJS, maybe a name that reflects that would be appropriate. If the goal is to provide all-but-N features of ECMAScript modules, maybe I've misunderstood the purpose of this project.

I think SystemJS is great. I use it, think everyone should use it for nomodule, and I think this project should also serve SystemJS users.

I also think that the way this project should do that is by providing es modules as es modules, and that includes deep module references, which necessitates preserving directory structure.

I hope I've done a good job expressing my view without projecting anger. If I've failed at either of those conditions please let me know (I'm not angry)

And please take care of yourself during this general quarantine ❤️

@internettrans
Copy link

internettrans commented Mar 27, 2020

I think part of my confusion and disappointment here stems from the name of this project. @esm-bundle indicated to me that I'd be getting exactly that, ECMAScript modules. If the goal of this project is to provide SystemJS, maybe a name that reflects that would be appropriate.

My very first sentence in the initial esm-bundle blog post says that esm-bundle provides System.register modules:

If you’re looking for an up-to-date, published version of an npm package in ESM (javascript module) or System.register format, search for it on https://github.com/esm-bundle

Since you've challenged the name of the project, I will point out that a bundle is a concatenation of files, which is not what your code does. The project is called esm-bundle, but your proposal is to not bundle at all, so as to allow for deep module references. Which is in direct contradiction to the stated purpose, existing code, and even the name of this project.

I am open to the purpose evolving over time, but I don't think telling me that I haven't explained my idea well is useful. I wrote a blog post, documentation, and a template repo. You have deviated from that by 1) not bundling, and 2) not outputting System.register modules. You are the one who is proposing change to the purpose of the project, not me.

It's my hope that I'll be able to use this project to convert any CJS package to esm, and use it without changing anything about the consumer asides from the npm package reference in package.json.

What benefit is there to server-side node code using ESM instead of CJS? The existing CJS packages work perfectly fine. I agree that using ESM in Node is desireable and likely the future for npm packages, but I don't see any reason to forcibly convert older packages to it. I write ESM for new node packages, and cjs for existing ones where I don't want to rewrite them. The nodejs team has done a good job of packages interop-ing with each other regardless of module format.

In contrast, browser-side javascript simply cannot use CJS, but can use ESM. That is the inspiration for the esm-bundle project.

One benefit of ESM is tree-shaking, but since nodejs projects often don't bundle their dependencies into their published tarball, I don't see how that would help in NodeJS either. Are there benefits I am missing?

@bennypowers
Copy link
Contributor Author

Look, I don't really mind if you don't want to support the whole spec, I just think that it would be better not to publish a package that says in the README that it's a drop-in replacement

npm install --save crocks@npm:@esm-bundle/crocks

when doing so would actually break examples from that package's documentation:

https://crocks.dev/docs/getting-started.html#single-entities-js-modules

So that's why I think it would be best to deprecate this package. That way I can find a better way to publish crocks as esm, and you can continue to do what you really want with this project, which is provide single-file systemjs bundles alongside modules.

It was a mistake to publish this package under this scope. I clearly misunderstood your purpose here.

@internettrans
Copy link

internettrans commented Mar 28, 2020

I just think that it would be better not to publish a package that says in the README that it's a drop-in replacement

Again, you are critiquing my work. I did not say that this was a "drop-in replacement for any package." I said that this provides esm bundles of packages.

Look, I don't really mind if you don't want to support the whole spec,

What spec are you referring to? A package's documentation is not a spec. esm-bundle is for browser bundles.

What benefit is there to server-side node code using ESM instead of CJS?

You did not answer this question - instead you just critiqued my work and referenced a spec that doesn't exist

@internettrans
Copy link

internettrans commented Mar 28, 2020

I am no longer going to engage with you on this - every one of your comments blames me for you not reading the blog post and docs.

You are unable to explain why the esm directory breaks anything, and blame me for things that I and my documentation doesn't say.

esm-bundle is not intended for nodejs usage, since ESM has no advantages in Node over CJS.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants