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

gulp: JSON formatting for partly generated files #1933

Merged
merged 9 commits into from
Jun 8, 2019

Conversation

RunDevelopment
Copy link
Member

I got tired of getting merge conflicts from prism-autoloader.js and prism-show-language.js when components.json changed.

The new formatting of generated objects will make git able to merge these files automatically.

@mAAdhaTTah
Copy link
Member

This won't solve merge conflicts in the built files, so you're still going to have to resolve conflicts. Might as well leave it as is, imo, because this adds a lot of visual clutter to anyone trying to debug this plugin.

@RunDevelopment
Copy link
Member Author

It will help against conflicts. While it's true that the generated minified files of the plugins are still going to conflict, the unminified version will not.
This makes resolving conflicts easier because you just have to run gulp instead of also having to edit the source of two plugins before.


Personally, I don't mind the "visual clutter" because you can have code folding in virtually every editor.

@mAAdhaTTah
Copy link
Member

This makes resolving conflicts easier because you just have to run gulp instead of also having to edit the source of two plugins before.

Do you have to edit the source of the autoloader? Why can't you run gulp and get both built for you?

@RunDevelopment
Copy link
Member Author

Because of the git merge conflict format. I will explain with the example for resolving the conflicts of #1892.

Just merging master and running gulp will give the following output:

[22:51:27] Using gulpfile ~\Documents\Git\prism\gulpfile.js
[22:51:27] Starting 'default'...
[22:51:27] Starting 'minifyComponents'...
[22:51:27] Starting 'componentsJsonToJs'...
[22:51:27] Starting 'build'...
[22:51:27] Starting 'languagePlugins'...
[22:51:27] Finished 'componentsJsonToJs' after 196 ms
[22:51:27] Finished 'languagePlugins' after 228 ms
[22:51:27] Starting 'minifyPlugins'...
[22:51:28] Finished 'build' after 437 ms
[22:51:28] 'minifyPlugins' errored after 882 ms
[22:51:28] GulpUglifyError: unable to minify JavaScript
Caused by: SyntaxError: Unexpected token: operator «<<»
File: ~\Documents\Git\prism\plugins\show-language\prism-show-language.js
Line: 14
[22:51:28] 'default' errored after 1.13 s
[22:51:28] The following tasks did not complete: minifyComponents
[22:51:28] Did you forget to signal async completion?

Please note that languagePlugins (which inserts the JSON into autoloader and show language) succeeded. After gulp, the relevant part of show language looks like this:
(The unminified autoloader didn't conflict this time.)

<<<<<<< HEAD
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","js":"JavaScript","abap":"ABAP","abnf":"Augmented Backus–Naur form","apacheconf":"Apache Configuration","apl":"APL","arff":"ARFF","asciidoc":"AsciiDoc","adoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Bash","basic":"BASIC","bnf":"Backus–Naur form","rbnf":"Routing Backus–Naur form","csharp":"C#","cs":"C#","dotnet":"C#","cpp":"C++","cil":"CIL","coffee":"CoffeeScript","cmake":"CMake","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","jinja2":"Django/Jinja2","dockerfile":"Docker","ebnf":"Extended Backus–Naur form","ejs":"EJS","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","gamemakerlanguage":"GameMaker Language","graphql":"GraphQL","hs":"Haskell","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javadoc":"JavaDoc","javadoclike":"JavaDoc-like","javastacktrace":"Java stack trace","jq":"JQ","jsdoc":"JSDoc","js-extras":"JS Extras","json":"JSON","jsonp":"JSONP","json5":"JSON5","latex":"LaTeX","tex":"TeX","context":"ConTeXt","emacs":"Lisp","elisp":"Lisp","emacs-lisp":"Lisp","lolcode":"LOLCODE","md":"Markdown","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","n4jsd":"N4JS","nand2tetris-hdl":"Nand To Tetris HDL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","phpdoc":"PHPDoc","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","py":"Python","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","rb":"Ruby","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","shell-session":"Shell session","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","ts":"TypeScript","t4-cs":"T4 Text Templates (C#)","t4":"T4 Text Templates (C#)","t4-vb":"T4 Text Templates (VB)","t4-templating":"T4 templating","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","vb":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML","yml":"YAML"}/*]*/;
=======
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","js":"JavaScript","abap":"ABAP","abnf":"Augmented Backus–Naur form","apacheconf":"Apache Configuration","apl":"APL","arff":"ARFF","asciidoc":"AsciiDoc","adoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Bash","basic":"BASIC","bnf":"Backus–Naur form","rbnf":"Routing Backus–Naur form","csharp":"C#","cs":"C#","dotnet":"C#","cpp":"C++","cil":"CIL","coffee":"CoffeeScript","cmake":"CMake","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","jinja2":"Django/Jinja2","dockerfile":"Docker","ebnf":"Extended Backus–Naur form","ejs":"EJS","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","gamemakerlanguage":"GameMaker Language","graphql":"GraphQL","hs":"Haskell","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javadoc":"JavaDoc","javadoclike":"JavaDoc-like","javastacktrace":"Java stack trace","jq":"JQ","jsdoc":"JSDoc","js-extras":"JS Extras","json":"JSON","jsonp":"JSONP","json5":"JSON5","latex":"LaTeX","tex":"TeX","context":"ConTeXt","emacs":"Lisp","elisp":"Lisp","emacs-lisp":"Lisp","lolcode":"LOLCODE","md":"Markdown","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","n4jsd":"N4JS","nand2tetris-hdl":"Nand To Tetris HDL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","phpdoc":"PHPDoc","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","py":"Python","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","rb":"Ruby","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","shell-session":"Shell session","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","ts":"TypeScript","t4-cs":"T4 Text Templates (C#)","t4":"T4 Text Templates (C#)","t4-vb":"T4 Text Templates (VB)","t4-templating":"T4 templating","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","vb":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML","yml":"YAML"}/*]*/;
>>>>>>> master

Note that both HEAD and master are identical because of languagePlugins.

At this point, I have to edit the source of show language and run gulp again.
Using my usual workflow is to first choose either the HEAD or master version (which one doesn't matter) for autoloader and show language and then run gulp.

This PR makes the "choose either HEAD or master" unnecessary because git will be able to merge the unminified versions (in most cases). Gulp will then do the rest.

Copy link
Member

@mAAdhaTTah mAAdhaTTah left a comment

Choose a reason for hiding this comment

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

Fair.

@RunDevelopment
Copy link
Member Author

Thanks!

@RunDevelopment RunDevelopment merged commit d4373f3 into PrismJS:master Jun 8, 2019
@RunDevelopment RunDevelopment deleted the json-formatting branch June 8, 2019 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants