Skip to content

Re-write Rollup Build Scripts - #3712

Closed
azz wants to merge 6 commits into
prettier:masterfrom
azz:redo-build
Closed

azz wants to merge 6 commits into
prettier:masterfrom
azz:redo-build

Conversation

@azz

@azz azz commented Jan 11, 2018 •

Copy link
Copy Markdown
Member

Idea is to remove all the eval("require") calls, and replace them with Rollup paths/externals.

Currently the dist/ directory looks like this:

Details
$ tree dist
dist
├── README.md
├── bin
│   └── prettier.js
├── externals
│   ├── babylon.js
│   ├── cosmiconfig.js
│   ├── flow-parser.js
│   ├── get-stream.js
│   ├── glimmer-syntax.js
│   ├── graphql-language.js
│   ├── parse5.js
│   ├── postcss-less.js
│   ├── postcss-media-query-parser.js
│   ├── postcss-scss.js
│   ├── postcss-selector-parser.js
│   ├── postcss-values-parser.js
│   ├── read-pkg-up.js
│   ├── remark-parse.js
│   └── typescript-eslint-parser.js
├── index.js
├── package.json
└── src
    ├── cli
    │   ├── constant.js
    │   ├── index.js
    │   ├── logger.js
    │   ├── util.js
    │   └── validator.js
    ├── common
    │   ├── clean-ast.js
    │   ├── errors.js
    │   ├── fast-path.js
    │   ├── load-plugins.js
    │   ├── parser-create-error.js
    │   ├── parser-include-shebang.js
    │   ├── support.js
    │   └── util.js
    ├── config
    │   ├── resolve-config-editorconfig.js
    │   └── resolve-config.js
    ├── doc
    │   ├── doc-builders.js
    │   ├── doc-debug.js
    │   ├── doc-printer.js
    │   ├── doc-utils.js
    │   └── index.js
    ├── language-css
    │   ├── clean.js
    │   ├── index.js
    │   ├── options.js
    │   ├── parser-postcss.js
    │   └── printer-postcss.js
    ├── language-graphql
    │   ├── index.js
    │   ├── options.js
    │   ├── parser-graphql.js
    │   └── printer-graphql.js
    ├── language-handlebars
    │   ├── index.js
    │   ├── parser-glimmer.js
    │   └── printer-glimmer.js
    ├── language-html
    │   ├── embed.js
    │   ├── index.js
    │   ├── parser-parse5.js
    │   └── printer-htmlparser2.js
    ├── language-js
    │   ├── clean.js
    │   ├── embed.js
    │   ├── index.js
    │   ├── options.js
    │   ├── parser-babylon.js
    │   ├── parser-flow.js
    │   ├── parser-typescript.js
    │   └── printer-estree.js
    ├── language-markdown
    │   ├── embed.js
    │   ├── index.js
    │   ├── options.js
    │   ├── parser-markdown.js
    │   └── printer-markdown.js
    ├── language-vue
    │   ├── embed.js
    │   ├── index.js
    │   ├── parser-vue.js
    │   └── printer-vue.js
    └── main
        ├── ast-to-doc.js
        ├── comments.js
        ├── deprecated.js
        ├── get-printer.js
        ├── multiparser.js
        ├── options.js
        └── parser.js

15 directories, 79 files

At the moment the dynamic requires are not being preserved by Rollup. I wonder if it is even possible to preserve them due to the nature of Rollup. Maybe Webpack might be a better for the index.js file.

❓I wanted to get some feedback on whether this approach makes sense before sinking too much time into it.

Fixes #3574
Fixes #3698

@azz azz added the status:wip Pull requests that are a work in progress and should not be merged label Jan 11, 2018
@azz

azz commented Jan 11, 2018

Copy link
Copy Markdown
Member Author

Another option is to ship the src/ files as-is (but minified), then string replace require("babylon") with require("./externals/babylon"), etc.

@duailibe

duailibe commented Jan 11, 2018 •

Copy link
Copy Markdown
Collaborator

Well I guess it comes down to testing if this is a performance regression or not.

@suchipi

suchipi commented Jan 11, 2018

Copy link
Copy Markdown
Member

I would advise against using webpack for the bundle, because I've seen some strange issues occur when nesting webpack module wrappers (which is what happens when you pull a webpack-ified file into a webpack build). That could cause some pain for people using prettier in the browser.

@azz

azz commented Jan 12, 2018 •

Copy link
Copy Markdown
Member Author

I'm thinking maybe:

  • Use rollup for individual external bundles.
  • Use babel to copy all the internal files, using babel-plugin-module-resolver to alias the requires to externals.

This way we could support:

  • NodeJS v4 viayarn add prettier (npm)
  • NodeJS v6+ via yarn add prettier/prettier (GitHub)

@azz

azz commented Jan 12, 2018

Copy link
Copy Markdown
Member Author

I think I like this approach so far. Implementation looks much cleaner than before.

@azz

azz commented Jan 12, 2018

Copy link
Copy Markdown
Member Author

Has anyone used bundledDependencies before? I find the docs very confusing. Is it supposed to pack the bundled dependencies for you? Do you still list the dependency in dependencies?

@j-f1

j-f1 commented Jan 12, 2018

Copy link
Copy Markdown
Member

Is it supposed to pack the bundled dependencies for you?

It seems like it includes them when you run npm pack.

Do you still list the dependency in dependencies?

I’d assume so — bundledDependencies looks like it’s only used when you run npm pack. Also, since you can’t specify a version, there would be no way for npm to know which version to install.

@azz azz self-assigned this Jan 22, 2018
@azz azz mentioned this pull request Jan 29, 2018
@azz

azz commented Feb 24, 2018

Copy link
Copy Markdown
Member Author

I'm doing a clean up of stale PRs, closing this one.

I didn't get where I wanted to get to with this and ran out of steam. Maybe I'll try again soon but the current system works ok for the moment.

@azz azz closed this Feb 24, 2018
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:wip Pull requests that are a work in progress and should not be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve distribution tests Revamp Build System

4 participants