-
Notifications
You must be signed in to change notification settings - Fork 75
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
build stuff #108
build stuff #108
Conversation
why jest |
5ea452c
to
328408e
Compare
Changes the github command to only test against 13. @ryhinchey Is this okay? There’s nothing about Crank which makes testing it against different node versions necessary and I don’t feel like having two jest config files for the CI. Why does node have to be like this though. |
This PR fixes #87 and it fixes #89 in Node 13.2+. It doesn't/can't fix #89 in Node 12, but the only way to fix #89 in Node 12 would be to turn the root
I think this PR in particular absolutely does benefit from testing various Node versions, but hopefully PRs like this will be rare. I note that the PR also adds a UMD build. I have a bug to report in the UMD build, and I think this bug will annoy you, so please wear peril sensitive sunglasses before reading the bug report. UMD bugThe UMD build currently doesn't work in Node, any version, because it's using a
This is happening because rollup-generated UMD scripts are meant to be interpreted as CJS scripts in Node. See the preamble definition in (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.Crank = {}));
}(this, (function (exports) { 'use strict'; The preamble function first attempts to detect CJS, then falls back to AMD (but who uses that anymore?) and finally defaults to setting a global in an IIFE. The problem is that it's trying to use I believe the easiest fix would be to use the |
Tested on node 10, 11, 12, 13 and 14. It all still seems to work. Parcel and webpack seem to work too. In node12 you have to explicitly require the cjs directory, but that’s something I don’t care about. @dfabulich I actually turned the umd build into a single file umd in the root, because there isn’t really a point in doing multiple umd files anyways, given that everything has to be exported as a single object. This was mainly to satisfy an exotic environment requirement by @fritx (#45) and I assume if they’re using node they can just use the cjs files. I also moved the esm files directly to the root. This should make working with all the new npm to esmodules bundlers a little happier. |
Also rollup-plugin-ts by @wessburg is likely the first build plugin that hasn’t required a half-day to install and configure. It just worked! It’s so rare to see this in build tooling just wanted to give a shoutout. |
FYI, moving the files out of the IMO, the UMD build should go back in the |
@dfabulich Ahhh I guess I just misunderstood the nature of the snowpack bugs. Having the files built directly into the root of the package just feels a little cleaner to me, as opposed to having dummy files in the root which link to the esm builds. Not having to do that extra hop from index.js to esm/index.js is nice for stack traces and unpkg and such. What do we have to do for snowpack integration? Did you get any response from those people? I’m feeling frisky so I might, maybe, just maybe be willing to create dummy directories and package.json files to get dom and html to work. Thank you for all the feedback on this stuff. I literally did not have the patience to try and figure it out on my own so this is incredibly helpful 🧡 |
FINNEEEEEEEEEEEEEEE |
Merge this! |
@dfabulich Are you confirming it all works? I want to do one last 0.1 release with the performance fixes so 0.1 dependents don’t all perform like ass, and then have this merged for the first 0.2 release. At the same time, I’m also thinking what if we just don’t consider this stuff a breaking change. It is a beta after all. Probably best to make it 0.2 to be responsible. |
Yes, it all looks good to me, and I agree that calling it 0.2 is wise. It's definitely some kinda breaking change, because it's no longer possible to |
@brainkim do the tests only run in CI in node 13? That doesn’t make sense to me but I’d say right now it’s not a big deal. The yaml file can be updated to only run certain commands in a specified node env so we’ll want to do that at some point in the future |
@ryhinchey the problem is that turning type into "module" then requires us to have jest.config.js be an esmodule. |
I see. I don’t have the knowledge or time right now to propose an alternative. The only thing that truly needs to be tested on different node versions is the String renderer and that can be done in a separate PR. I’ll need to research what other packages that have type:module do for their config files. |
This is the error I see on node 12 with the module.exports config file.
|
Oh wait, we can make jest.config.js a cjs file and have everything work. Will lift the ban on cjs file extensions just for jest. |
Yah. It all just feels so hacky. |
Not trying to throw a wrench in here but what’s the push to support esmodules in node in the first place? It seems to add a lot of complexity for little gain. There are clear examples out there to support treeshaking with bundlers via esmodules and if that’s the goal, we can simplify all of this. |
@ryhinchey At the end of the day, all of the complexity is scoped to the rollup build and package.json, thanks to some copying of package.json files. I refuse to use mjs/cjs files on principle, and I’m very glad we found a way to not have to use them (besides the jest config) The exports map in package.json is definitely a huge footgun but we can just be careful about adding submodules. |
The goal was to get the package to work in node 12/13/14 without throwing cryptic errors. Treeshaking is a complex topic and I don’t actually think any code in Crank can or should be treeshaken. |
I kicked this off because I wanted to fix #87, which seems like a worthy goal to me. An alternate approach would be to put the ESM scripts back in the ESM folder, set the project type back to CJS, and drop a |
Agreed. I think we should look to the future, and the future is probably ESModules everywhere. I want to see if we can get Crank working with Deno soon. I think Crank’s usage of generators and async generators meshes really nicely with Deno’s philosophy and feature set. The last question I have before merging. Can we get away with not transpiling modules at all, for all the output formats? The justifications are:
|
I think no transpilation is a great idea. Not worth the perf penalties and bundle size implications |
What do you mean by "no transpilation"? Some kind of transpilation has to happen for TypeScript, right? (Or would you switch to JSDoc TypeScript?) https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html "There are significant performance penalties to transpiling generators and async functions" … I assume you're referring to transpiling these to non-generator/non-async functions? Today's build doesn't do that, does it? |
Ah yes, to clarify, I mean using "target": "ESNEXT" in our tsconfig. Removes all the typescript types, but leaves generator functions and async functions untranspiled. So if you look at the build artifacts from previous releases they have code like: HostNode.prototype[Symbol.iterator] = function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!!this.unmounted) return [3 /*break*/, 2];
if (this.iterating) {
throw new Error("You must yield for each iteration of this.");
}
this.iterating = true;
return [4 /*yield*/, __assign(__assign({}, this.props), { children: this.childValues })];
case 1:
_a.sent();
return [3 /*break*/, 0];
case 2: return [2 /*return*/];
}
});
}; I thought we would do esnext for esm and es5 or es6 for the cjs and umd builds, but my current thinking is to do esnext for all environments. |
Did some thinking and I think it wouldn’t hurt to try leaving modules untranspiled. If people have trouble with this for their specific environments we can figure out on a case by case basis whether we should make them transpile or if we have to transpile the lib, and then even if we do have to make the change it wouldn’t be a breaking change anyways. |
Didn't follow the entire discussion and don't know how relevant will be, but if you need to modify package.js (or adding/removing/generaing files) during build/pack process could take a look to small package I did. (It's not production ready so no self promotion here ;) ) https://github.com/treedys/postpack Piping and modifying the content of npm pack archive is a bit gray area and was a bit tricky to properly handle. Again - if the comment is not relevant feel free to remove to avoid adding noise here. |
Pushing out the release of 0.2 to at latest Friday so I can implement some features and do some more performance experiments, this time with breaking changes to the undocumented renderer API. Let me know if there’s a specific reason you want it sooner. |
Fixes #87 #89
This PR changes the build outputs slightly so the package supports more environments. It is scheduled for the first 0.2 release.