Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-78400

Building JS modules with Grunt places build files in src folder on Windows

    XMLWordPrintable

Details

    • MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE
    • wip_MDL-78400_m41
    • wip_MDL-78400_m42
    • wip_MDL-78400_master
    • Hide

      destPath = srcPath.replace(`amd/src`, `amd/build`);

      Show
      destPath = srcPath.replace(`amd/src`, `amd/build`);
    • Hide
      1. On Windows with a Moodle install, Node JS being the correct version as mandated by 'package.json' in the Moodle root folder and having initialised with 'npm install'.
      2. Edit '.eslintrc' and disable linebreak style with 'linebreak-style': ['off', 'unix']
      3. Build the 'accessreview' block (or any other core module with AMD JS and adapt the command) AMD JS with the command 'grunt amd --root=blocks\accessreview' in the Node.JS Command prompt in the Moodle root.
      4. Observe the minfied file and map have been created / updated in the blocks\accessreview\amd\build folder.
      Show
      On Windows with a Moodle install, Node JS being the correct version as mandated by 'package.json' in the Moodle root folder and having initialised with 'npm install'. Edit '.eslintrc' and disable linebreak style with 'linebreak-style': ['off', 'unix'] Build the 'accessreview' block (or any other core module with AMD JS and adapt the command) AMD JS with the command 'grunt amd --root=blocks\accessreview' in the Node.JS Command prompt in the Moodle root. Observe the minfied file and map have been created / updated in the blocks\accessreview\amd\build folder.

    Description

      On MDL-77995, the functon 'babelRename' was changed to:

      {{
      const babelRename = function(destPath, srcPath) {
      const path = require('path');
      destPath = srcPath.replace(`amd${path.sep}src`, `amd${path.sep}build`);
      destPath = destPath.replace(/\.js$/, '.min.js');
      return destPath;
      };
      }}

      However, 'grunt' always uses the forward slash and so on Windows that uses a backslash (as would be seen in the path separator variable) then the 'build' files end up in the 'src' folder and not the 'build' folder.

      This can be evidenced by changing the code to:

      {{
      const babelRename = function(destPath, srcPath) {
      const path = require('path');
      console.log(srcPath);
      destPath = srcPath.replace(`amd${path.sep}src`, `amd${path.sep}build`);
      console.log(destPath);
      destPath = destPath.replace(/\.js$/, '.min.js');
      return destPath;
      };
      }}

      then with the Adaptable theme installed (on Windows) - https://moodle.org/plugins/theme_adaptable/401.1.5/29152 - run the command (either in cmd.exe (right in screenshot) or the Node.js Command Prompt(left in screenshot)) in the Moodle root -> 'grunt amd --root=theme\adaptable' and observe what the code sees in its strings and the resulting build files in the src folder:

      The fix / workaround is simply:

      destPath = srcPath.replace(`amd/src`, `amd/build`);

      Attachments

        Issue Links

          Activity

            People

              gb2048 Gareth J Barnard
              gb2048 Gareth J Barnard
              Paul Holden Paul Holden
              Andrew Lyons Andrew Lyons
              Jun Pataleta Jun Pataleta
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour, 50 minutes
                  1h 50m

                  Clockify

                    Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.