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

Modernize manager template build workflow #15793

Merged
merged 3 commits into from
Sep 16, 2021

Conversation

smg6511
Copy link
Collaborator

@smg6511 smg6511 commented Aug 14, 2021

What does it do?

  • Replaces uglifyjs with terser to support the current javascript standard (ECMA2015/ES6) and support future stable standards
  • Bring other dev dependencies up to date
  • Add back in the copyright banner for compiled JS and CSS files (the current config uses an option that was removed from cssmin/clean-css many years ago)
  • Added new grunt task to just run the compile/minification routines for SASS/CSS
  • Removed imageoptim, as the only image used in the interface of any consequence (size-wise) is the login background
  • Made change to format of comments in the variables SASS file so they can be discarded during the build process
  • Removed reference to source map file in the popper.min.js file to remove the console error it was causing (due to the map file not existing)

Why is it needed?

Two reasons:

  1. Virtually every tutorial and page of official documentation you will find on the web today prefers ES6 methods and support is robust among modern and semi-modern browsers. It's safe and prudent for MODX to adopt this standard, as its many great features allow more efficient coding and better scope control.
  2. Dart SASS is the new and supported standard and the move to it will provide support for features that Node SASS will not (particularly moving into the future).

How to test

  1. Run npm update in the _build/templates/default directory and run the grunt build, style, and compress tasks to verify.
  2. Add a test method to the manager/assets/modext/util/utilities.js utilizing some ES6 syntax to verify it compiles correctly (running the compress or build task).
  3. Verify in various target browsers that the changes do not adversely affect the manager's operation and styling looks the same as before the change.

Note that a warning will appear when compiling the SASS files, as fontawesome and normalize-scss use the to-be deprecated "/" for division. This will be replaced my the math.div([numerator], [denominator]) method and be required for Dart Sass 2.0+ (which is a ways off, as its current version is 1.37.5). This issue is on the radar for both repos.

Related issue(s)/PR(s)

None

@cla-bot cla-bot bot added the cla-signed CLA confirmed for contributors to this PR. label Aug 14, 2021
@Ibochkarev Ibochkarev added the pr/review-needed Pull request requires review and testing. label Aug 25, 2021
@JoshuaLuckers
Copy link
Contributor

I'm getting the following error when running npm build/grunt build:

Loading "dart-sass.js" tasks...ERROR
>> Error: Cannot find module 'sass'
>> Require stack:
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt-dart-sass/tasks/dart-sass.js
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/lib/grunt/task.js
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/lib/grunt.js
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/node_modules/grunt-cli/bin/grunt
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/bin/grunt
Loading "terser.js" tasks...ERROR
>> Error: Cannot find module 'terser'
>> Require stack:
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt-terser/tasks/terser.js
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/lib/grunt/task.js
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/lib/grunt.js
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/node_modules/grunt-cli/bin/grunt
>> - /Users/joshua/Projects/modx-3x/_build/templates/default/node_modules/grunt/bin/grunt
Warning: Task "dart-sass:dist" not found. Use --force to continue.

Aborted due to warnings.

@smg6511
Copy link
Collaborator Author

smg6511 commented Aug 26, 2021

Joshua - may be a silly question, but did you run npm update before trying to build? If not, you'll need to do that to install the new dev dependencies.

@opengeek opengeek requested a review from matdave August 26, 2021 19:19
@opengeek
Copy link
Member

I am unable to get past step 1 of the "How to test" instructions…

opengeek@drumshaman  ~/www/revo   3.x-mgr-tpl-build-updates  git rebase 3.x
Successfully rebased and updated refs/heads/3.x-mgr-tpl-build-updates.
 opengeek@drumshaman  ~/www/revo   3.x-mgr-tpl-build-updates  cd _build/templates/default
 opengeek@drumshaman  ~/www/revo/_build/templates/default   3.x-mgr-tpl-build-updates  npm update

> @fortawesome/fontawesome-free@5.15.4 postinstall /Users/opengeek/www/revo/_build/templates/default/node_modules/@fortawesome/fontawesome-free
> node attribution.js

Font Awesome Free 5.15.4 by @fontawesome - https://fontawesome.com
License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)

npm WARN grunt-autoprefixer@3.0.4 requires a peer of grunt@>=0.4.2 but none is installed. You must install peer dependencies yourself.
npm WARN grunt-contrib-concat@1.0.1 requires a peer of grunt@>=0.4.0 but none is installed. You must install peer dependencies yourself.

+ @fortawesome/fontawesome-free@5.15.4
removed 366 packages, updated 1 package and audited 84 packages in 4.528s
found 6 vulnerabilities (1 moderate, 5 high)
  run `npm audit fix` to fix them, or `npm audit` for details

> node@14.17.4 preinstall /Users/opengeek/www/revo/_build/templates/default/node_modules/node
> node installArchSpecificPackage

+ node-darwin-x64@14.17.4
added 1 package in 2.727s
found 0 vulnerabilities

npm WARN grunt-autoprefixer@3.0.4 requires a peer of grunt@>=0.4.2 but none is installed. You must install peer dependencies yourself.
npm WARN grunt-contrib-concat@1.0.1 requires a peer of grunt@>=0.4.0 but none is installed. You must install peer dependencies yourself.

+ node@14.17.4
updated 1 package and audited 84 packages in 4.462s
found 6 vulnerabilities (1 moderate, 5 high)
  run `npm audit fix` to fix them, or `npm audit` for details
 opengeek@drumshaman  ~/www/revo/_build/templates/default   3.x-mgr-tpl-build-updates ●  git status
On branch 3.x-mgr-tpl-build-updates
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   package-lock.json
	modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")
 opengeek@drumshaman  ~/www/revo/_build/templates/default   3.x-mgr-tpl-build-updates ●  git diff
 ✘ opengeek@drumshaman  ~/www/revo/_build/templates/default   3.x-mgr-tpl-build-updates ●  grunt build
grunt-cli: The grunt command line interface (v1.3.2)

Fatal error: Unable to find local grunt.

If you're seeing this message, grunt hasn't been installed locally to
your project. For more information about installing and configuring grunt,
please see the Getting Started guide:

https://gruntjs.com/getting-started

Copy link
Member

@opengeek opengeek left a comment

Choose a reason for hiding this comment

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

This is not working as described.

@smg6511
Copy link
Collaborator Author

smg6511 commented Aug 26, 2021

Sorry about that, guys. Let me update the package.json to get the correct grunt locally. I had no problems, but must have been running against my globally installed grunt module. Be back...

@smg6511
Copy link
Collaborator Author

smg6511 commented Aug 27, 2021

After researching a bit I suspect you may be running a version of npm between v3 and v6, which do not automatically resolve peer dependencies. If so, upgrading to the current stable version (7.x) will hopefully clear up the issue (npm install -g npm@latest).

@JoshuaLuckers
Copy link
Contributor

After researching a bit I suspect you may be running a version of npm between v3 and v6, which do not automatically resolve peer dependencies. If so, upgrading to the current stable version (7.x) will hopefully clear up the issue (npm install -g npm@latest).

That might be the case, I'll try it again soon!

@JoshuaLuckers
Copy link
Contributor

Upgrading npm to 7.x solved my issue. I was running 6.x.

@opengeek opengeek dismissed their stale review August 27, 2021 19:56

I got it working

@opengeek opengeek self-requested a review August 27, 2021 19:56
Copy link
Contributor

@matdave matdave left a comment

Choose a reason for hiding this comment

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

Seems to work for me.

@Ibochkarev Ibochkarev added pr/ready-for-merging Pull request reviewed and tested and ready for merging. and removed pr/review-needed Pull request requires review and testing. labels Sep 3, 2021
@Ibochkarev Ibochkarev added this to the v3.0.0-alpha3 milestone Sep 3, 2021
Jim Graham and others added 3 commits September 16, 2021 13:42
Updates to dev packages and the grunt config primarily to support ES6 javascript and replace the deprecated node sass implementation with dart sass.
Provides a more streamlined config for autoprefixing and minification via postCSS module and its plugins and removes issues with grunt-autoprefixer dependency vulnerabilities
@opengeek opengeek force-pushed the 3.x-mgr-tpl-build-updates branch from 0612ce1 to fbcd42e Compare September 16, 2021 19:45
@opengeek opengeek changed the title Modernization of Template Build Workflow Modernize Template Build Workflow Sep 16, 2021
@opengeek opengeek changed the title Modernize Template Build Workflow Modernize manager template build workflow Sep 16, 2021
@opengeek opengeek merged commit ccaf7a5 into modxcms:3.x Sep 16, 2021
@rthrash rthrash removed the pr/ready-for-merging Pull request reviewed and tested and ready for merging. label Sep 16, 2021
"grunt-terser": "^2.0.0",
"node": "^14.15.0",
"normalize-scss": "^7.0.1",
"postcss": "^8.3.6"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why you use postcss and sass both?

Copy link
Collaborator Author

@smg6511 smg6511 Sep 27, 2021

Choose a reason for hiding this comment

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

postcss is being used as a base for cssnano and autoprefixer. I'm not using the postcss scss plugin to parse scss because it's not entirely standard sass.

"grunt-dart-sass": "^2.0.1",
"grunt-notify": "^0.4.5",
"grunt-terser": "^2.0.0",
"node": "^14.15.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

windows 7 is not supported by node.js 14 :( Windows 7 still be more popular than 8, at least in Russia.
Is this dependency is necessary?

Copy link
Collaborator Author

@smg6511 smg6511 Sep 27, 2021

Choose a reason for hiding this comment

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

Windows 7, as you probably know, has been unsupported by Microsoft for more that a year and a half now. That said, I've seen that people on 7 have been able to get node 14+ running. See nodejs/node#33000 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for link, I'll try it.
Anyway, I would ask again: for what purpose is this dependency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's the base software needed to use npm and the modules it manages. Are you intending on doing some development on the manager interface? Note that this same dependency has existed in 2.x for quite a while now.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's very strange to have the npm installed and not have the nodejs installed, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mishantrop yes it is. I assume you're running Windows 7?

Copy link
Contributor

@mishanthrop mishanthrop Oct 2, 2021

Choose a reason for hiding this comment

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

Yes, including. Also I use Fedora and Mac OS. Dependings on tasks.

Copy link
Contributor

@mishanthrop mishanthrop Oct 2, 2021

Choose a reason for hiding this comment

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

Also there are better ways to limit the version of the application (anyway, I dont see any reasons for it in MODX):

package.json

{
  "name": "modx",
  "version": "3.0.0",
  "engines": {
   "node": ">=12.0.0"
  }
}

.npmrc

engine-strict=true

I have not personally tested it as it was never necessary.

Source: https://stackoverflow.com/a/68653111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed CLA confirmed for contributors to this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants