Skip to content
Snippets Groups Projects

Issue #3227125: Produce a sourcemap for aggregated JS

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
9 9 "require": {
10 10 "drupal/core": "9.3.x-dev",
11 11 "asm89/stack-cors": "1.3.0",
12 "axy/backtrace": "1.0.7",
13 "axy/codecs-base64vlq": "1.0.1",
14 "axy/errors": "1.0.5",
15 "axy/sourcemap": "0.1.5",
  • Wim Leers
  • 92 93 // grouping, optimizing and dumping, but change the strategy that is used to
    93 94 // determine when the aggregate should be rebuilt (e.g. mtime, HTTPS …).
    94 95 $map = $this->state->get('system.js_cache_files', []);
    96
    97 $generate_sourcemaps = \Drupal::config('system.performance')->get('js.sourcemaps');
  • Wim Leers
  • 7914 8106 "platform-overrides": {
    7915 8107 "php": "7.3.0"
    7916 8108 },
    7917 "plugin-api-version": "2.1.0"
    8109 "plugin-api-version": "2.0.0"
  • Wim Leers
  • 125 'sections' => [],
    126 ];
    120 127 foreach ($js_group['items'] as $js_asset) {
    121 128 // Optimize this JS file, but only if it's not yet minified.
    122 129 if (isset($js_asset['minified']) && $js_asset['minified']) {
    123 $data .= file_get_contents($js_asset['data']);
    130 $file_content = file_get_contents($js_asset['data']);
    124 131 }
    125 132 else {
    126 $data .= $this->optimizer->optimize($js_asset);
    133 $file_content = $this->optimizer->optimize($js_asset);
    134 }
    135 if ($generate_sourcemaps) {
    136 $js_map = FALSE;
    137 // pick up map files automatically, even if they're not declared
    138 // in the source (looking at you jquery)
  • 145 $js_map = json_decode(file_get_contents($js_asset['data'] . '.map'));
    146 }
    147 elseif (preg_match('~//[#@]\s(?:source(?:Mapping)?URL)=\s*(\S+)\s*~', $file_content, $matches)) {
    148 if (str_contains($matches[1], 'data:application/json;')) {
    149 $base64 = str_replace('data:application/json;charset=utf-8;base64,', '', $matches[1]);
    150 $js_map = json_decode(base64_decode($base64));
    151 }
    152 else {
    153 $map_file = pathinfo($js_asset['data'], PATHINFO_DIRNAME) . '/' . $matches[1];
    154 if (file_exists($map_file)) {
    155 $js_map = json_decode(file_get_contents($map_file));
    156 }
    157 }
    158 }
    159 $sourcesRoot = \Drupal::service('file_url_generator')
    160 ->generateAbsoluteString(pathinfo($js_asset['data'], PATHINFO_DIRNAME));
  • 159 $sourcesRoot = \Drupal::service('file_url_generator')
    160 ->generateAbsoluteString(pathinfo($js_asset['data'], PATHINFO_DIRNAME));
    161 if ($js_map) {
    162 // Make sure the source shows up in the right place.
    163 $js_map->sourceRoot = $sourcesRoot;
    164 $section = [
    165 'offset' => [
    166 'line' => substr_count($data, "\n"),
    167 'column' => 0,
    168 ],
    169 'map' => $js_map,
    170 ];
    171 }
    172 // if there are not sourcemap create one to avoid problems when
    173 // setting breakpoints. This happens when core js has not been
    174 // generated with yarn build:js-dev
  • Wim Leers
  • Théodore Biadala added 41 commits

    added 41 commits

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading