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

Pass .posthtmlrc options to posthtml-parse #1316

Merged
merged 1 commit into from
May 28, 2018

Conversation

luikore
Copy link
Contributor

@luikore luikore commented May 7, 2018

This pull request makes HTML parsing options configurable, so HTMLAsset parsing / transform behavior can be more consistent.

With this change we can config .posthtmlrc with the following options (they are consumed by posthtml-parse, then htmlparser2. See also https://github.com/fb55/htmlparser2/wiki/Parser-options )

  • xmlMode: true
  • lowerCaseAttributeNames: false
  • lowerCaseTags: false
  • recognizeSelfClosing: true
  • ...

If we config recognizeSelfClosing: true in .posthtmlrc, we can also fix #1103

Allow setting false to lower case options maybe can also fix #1123 . (not tested yet)

@luikore luikore changed the title Pass options in posthtmlrc to posthtml-parse Pass .posthtmlrc options to posthtml-parse May 7, 2018
@codecov-io
Copy link

codecov-io commented May 7, 2018

Codecov Report

Merging #1316 into master will increase coverage by 1.7%.
The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1316     +/-   ##
=========================================
+ Coverage   86.93%   88.64%   +1.7%     
=========================================
  Files          80       80             
  Lines        4286     4341     +55     
=========================================
+ Hits         3726     3848    +122     
+ Misses        560      493     -67
Impacted Files Coverage Δ
src/transforms/posthtml.js 100% <100%> (+23.25%) ⬆️
src/assets/HTMLAsset.js 91.83% <80%> (+6.68%) ⬆️
src/utils/PromiseQueue.js 90.78% <0%> (-3.45%) ⬇️
src/workerfarm/child.js 95.08% <0%> (-0.79%) ⬇️
src/utils/localRequire.js 93.54% <0%> (-0.57%) ⬇️
src/assets/VueAsset.js 87.5% <0%> (-0.28%) ⬇️
src/Asset.js 99.1% <0%> (-0.08%) ⬇️
src/Bundler.js 93.35% <0%> (-0.08%) ⬇️
src/Bundle.js 99.21% <0%> (-0.03%) ⬇️
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 181a63f...0a44d1f. Read the comment docs.

@luikore
Copy link
Contributor Author

luikore commented May 24, 2018

@devongovett
The vue support of parcel is still basically unusable due to so many bugs.
I hope some one can really pay some time to have a review about this?
Or just say you prefer other way for the fix so I can change or close this?


module.exports = async function(asset) {
async function parse(code, asset) {
var config = await getConfig(asset);
Copy link
Member

Choose a reason for hiding this comment

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

Is the configuration format identical in parser and transform?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but different options are used. Do you prefer these configs to be different objects?

Copy link
Member

Choose a reason for hiding this comment

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

As long as they can’t conflict it should be fine but it sounds like they can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about putting these options into a new htmlparser2rc ?

Copy link
Member

@DeMoorJasper DeMoorJasper May 28, 2018

Choose a reason for hiding this comment

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

I was thinking more of something like this:

.posthtml

{ 
  ...posthtmlOptions,
  parser: {...parserOptions}
}

Copy link
Member

Choose a reason for hiding this comment

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

But as you said they won't conflict I think it's safe for now to just let this PR be as is

Copy link
Member

Choose a reason for hiding this comment

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

I think this will result in getting the config twice... once for parse, and once for transform. Maybe ok because of the cache? Just pointing that out.

return config
}

module.exports = {
Copy link
Member

Choose a reason for hiding this comment

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

this can be written as module.exports = {parse, transform};

{packageKey: 'posthtml'}
);
let config =
asset.getPackage().posthtml ||
Copy link
Contributor

@fathyb fathyb May 24, 2018

Choose a reason for hiding this comment

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

asset.getPackage() returns a Promise so asset.getPackage().posthtml always evaluates to undefined :

parcel/src/Asset.js

Lines 127 to 133 in 1614918

async getPackage() {
if (!this._package) {
this._package = await this.getConfig(['package.json']);
}
return this._package;
}

Use await :

(await asset.getPackage()).posthtml || ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

if (!config && !asset.options.minify) {
return;
}

config = Object.assign({}, config);
config.plugins = await loadPlugins(config.plugins, asset.name);
config.skipParse = true;
return config;
return config
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like Prettier did not format (--no-verify?), you can manually run it by running yarn format or npm run format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not know this before, updated

constructor(name, options) {
super(name, options);
constructor(name, pkg, options) {
super(name, pkg, options);
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't pass pkg to the constructor anymore for perf reasons :

constructor(name, options) {
  super(name, options)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@DeMoorJasper DeMoorJasper merged commit c600d44 into parcel-bundler:master May 28, 2018
Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

Can you follow up with a test for this?

'.posthtmlrc',
'.posthtmlrc.js',
'posthtml.config.js'
]));
Copy link
Member

Choose a reason for hiding this comment

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

Did packageKey not work?


module.exports = async function(asset) {
async function parse(code, asset) {
var config = await getConfig(asset);
Copy link
Member

Choose a reason for hiding this comment

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

I think this will result in getting the config twice... once for parse, and once for transform. Maybe ok because of the cache? Just pointing that out.

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.

Parcel lowercasing Vue attributes 🐛Vue self-closing tags broken on build but fine on dev
5 participants