Skip to content
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

Field type build tool #993

Merged
merged 76 commits into from Apr 18, 2019
Merged

Field type build tool #993

merged 76 commits into from Apr 18, 2019

Conversation

emmatown
Copy link
Member

@emmatown emmatown commented Apr 5, 2019

This is a continuation of things discussed in #927.

The tool is essentially a fork of preconstruct, there's a bunch of stuff I'm going to rip out though that this tool won't need so I wouldn't recommend reviewing the implementation of this right now.

Something that I would like to hear thoughts on is the API, I've converted @keystone-alpha/fields-wysiwyg-tinymce and it works. Below is essentially the most important part of the API, to import views, you call importView which you import from @keystone-alpha/build-field-types
https://github.com/keystonejs/keystone-5/blob/7eddd38ca4de25aca4f6754e99670e3ccb1c86ce/packages/fields-wysiwyg-tinymce/src/index.js#L1-L20

TODO

  • figure out how dev stuff should work inside and outside the monorepo
  • build ESM bundles and make chunks resolve to directories that are automatically created in the dist folder with the correct package.json files and bundles
  • probably a bunch of other stuff
  • get all the tests working

Controller: '@keystone-alpha/fields/types/Text/views/Controller',
Field: path.join(__dirname, './views/Field/Field'),
Filter: '@keystone-alpha/fields/types/Text/views/Filter',
Controller: Text.views.Controller,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really interesting, if it works 😍

@JedWatson
Copy link
Member

JedWatson commented Apr 5, 2019

I really like what this does to the Keystone field package structure.

Can you share what it would look like (in terms of file structure, screenshot or comment here would do) for the main fields package?

Also, do you think this changes anything for other views (e.g. for custom pages in the Admin UI)? There aren't any chances to the fields-loader, which we've talked about extending, just double-checking that's a separate thing.

Thoughts unrelated to the API:

  • The fields introduces flow for server-side code for the first time. I'm ... mixed on that? not sure what it's going to do to the dev loop. Probably fine since build-field-types is a CLI package, so the main Keystone experience isn't affected in any way 🤷‍♂️
  • The wysiwyg field's index.js also moves behind the build step... which I think is OK since that's now consistent with other packages like utils that preconstruct builds for universal use anyway. But it seems a bit weird, since there's a hard boundary between the server and client parts of each field. Is that change necessary?

@emmatown
Copy link
Member Author

emmatown commented Apr 5, 2019

Can you share what it would look like (in terms of file structure, screenshot or comment here would do) for the main fields package?

field structure

Also, do you think this changes anything for other views (e.g. for custom pages in the Admin UI)? There aren't any chances to the fields-loader, which we've talked about extending, just double-checking that's a separate thing.

It shouldn't change anything about that.

The wysiwyg field's index.js also moves behind the build step... which I think is OK since that's now consistent with other packages like utils that preconstruct builds for universal use anyway. But it seems a bit weird, since there's a hard boundary between the server and client parts of each field. Is that change necessary?

Having the server side parts of field types behind a build step is what enables importView so, yes, it's necessary.

👇 is an explanation of how importView will work which might answer any other questions you might have.

We have a file like this,

import { importView } from '@keystone-alpha/build-field-types';

export let Wysiwyg = {
  ...otherStuff
  views: {
    ...otherViewsStuff
    Field: importView('./views/Field'),
  },
};

It goes through a babel plugin which turns it into this

export let Wysiwyg = {
  ...otherStuff
  views: {
    ...otherViewsStuff
    Field: ___KS_BUILD_SYSTEM_INTERNAL___importView(import('./views/Field')),
  },
};

Rollup does its thing and we have this for CommonJS builds. (and a different thing for ESM but I'm going to ignore that for this explanation) It's going to be written to the dist folder.

exports.Wysiwyg = {
  ...otherStuff
  views: {
    ...otherViewsStuff
    Field: ___KS_BUILD_SYSTEM_INTERNAL___importView(Promise.resolve(require('./chunk-hash'))),
  },
};

We then transform it with another babel plugin into this

const _join = require('path').join

exports.Wysiwyg = {
  ...otherStuff
  views: {
    ...otherViewsStuff
    Field: _join(__dirname, './chunk-hash'),
  },
};

And rollup will write the ESM and CJS versions of that chunk to dist/chunk-hash/not-sure-about-the-filename-yet.cjs.js and dist/chunk-hash/not-sure-about-the-filename-yet.esm.js and build-field-types will write a package.json with main and module fields to dist/chunk-hash/package.json

@JedWatson
Copy link
Member

❤️ it @mitchellhamilton

'last 2 firefox versions',
'last 2 safari versions',
'last 2 edge versions',
],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to call out this change in case anyone has any concerns. From #214 it seems like we're okay with not supporting IE 11.

The reason I did this isn't really for smaller bundles but that's a nice benefit, I did this is because there's a bug in Babel which means Babel compiled classes can't extend native classes. (babel/babel#9367)

@emmatown emmatown marked this pull request as ready for review April 17, 2019 04:44
@emmatown emmatown assigned timleslie and unassigned emmatown Apr 17, 2019
Copy link
Contributor

@timleslie timleslie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To the future! 🚀

@timleslie timleslie merged commit 1a7b706 into master Apr 18, 2019
@timleslie timleslie deleted the field-type-build-tool branch April 18, 2019 01:15
Copy link
Contributor

@jesstelford jesstelford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

if (isHerokuEnv) return;
return require('preconstruct').aliases.webpack(path.join(__dirname, '..', '..', '..'));
} catch (e) {}
})(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -27,17 +30,17 @@ class CloudinaryBlock extends Block {
auxList = createAuxList(auxListKey, {
fields: {
// We perform the requires here to avoid circular dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// We perform the requires here to avoid circular dependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants