Review main Abandoned

72629[WIP][TASK] Avoid relative imports in TypeScript

Benjamin Franzke CR 0 V 0 Hard +454 −454 updated 01/05/22, 12:05

Commit message

Refactor for ES6 to allow importmaps
to handle mapping module specifiers
to filenames.

All changes have been automated with the following script,
no manual adaptions:

  # Note: For rebase use following prefix commands
  #rm -rf Build/Sources/TypeScript/
  #git checkout HEAD^ -- Build/Sources/TypeScript/

  sed -i 's:../../DateTimePicker:TYPO3/CMS/Backend/DateTimePicker:g' \
      Build/Sources/TypeScript/backend/Resources/Public/TypeScript/FormEngine/Element/InputDateTimeElement.ts

  find Build/Sources/TypeScript/ -name '*.ts' | while read filepath
  do
      filename=$(echo "${filepath}" | sed 's/Build\/Sources\/TypeScript\///')
      extname=$(echo "${filename}" | sed 's/\([^\/]*\)\/.*/\1/')
      packagename=$(echo "${extname}" | sed -r 's/(^|_)([a-z])/\U\2/g')
      dirname=$(echo ${filename} | sed -e 's/Resources\/Public\/TypeScript//' -e 's/^[^\/]*\/\(.*\)\/[^\/][^\/]*/\1/')

      basename="TYPO3/CMS/${packagename}${dirname}"

      sed -i "s:^\(import.*'\)\\.:\1${basename}\\/.:" "${filepath}"

      sed -i '/^import/s/\/.\//\//' "${filepath}"
      sed -i '/^import/s/\/\([^\/]*\)\/..\//\//' "${filepath}"
      sed -i '/^import/s/\/\([^\/]*\)\/..\//\//' "${filepath}"
      sed -i '/^import/s/\/\([^\/]*\)\/..\//\//' "${filepath}"
  done

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 240

Show 220 more files

Review log 913

  1. Benjamin Franzke uploaded patch set 1 12/10/21, 20:53

  2. Benjamin Franzke wrote 12/10/21, 20:55

    Topic set to esm
  3. core-ci voted on patch set 1 V -1 12/10/21, 21:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/20957

  4. Benjamin Franzke rebased onto patch set 2 12/10/21, 22:02

  5. core-ci voted on patch set 2 V +1 12/10/21, 22:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/20968

  6. Oliver Hader commented on patch set 2 12/14/21, 10:06

    I guess IDE are still using relative imports when writing/modifying code. Do you know about any setting/functionality that would enforce using the full module-names?
  7. Benjamin Franzke commented on patch set 2 12/14/21, 14:27

    Reply

    As a vim user I don't know about IDEs, sorry. …but there is at least a plugin for eslint available: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-relative-packages.md Anyway, I'm not yet sure whether we want this. This is only useful for "full" importmaps (an importmap containing all modules mapped to corresponding filenames). We first need to decide whether we want that (taking security and overhead/bloat into account). I'll post a comparsion between absolute aproach ('importmap') vs relative (without importmap) separately, via #es6-migration slack channel. BTW: That's the reason why I marked it WIP, as I don't want to rush this change in, in case we don't actually want to use importmaps this way. (After all: absolute identifiers often cost some more bytes than relative ones)
  8. Benjamin Franzke commented on patch set 2 12/14/21, 14:37

    Reply

    Seems vscode has typescript.preferences.importmodulespecifier = non-relative
  9. Benjamin Franzke uploaded patch set 3 12/14/21, 14:55

  10. core-ci voted on patch set 3 V +1 12/14/21, 15:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21089

  11. Benjamin Franzke uploaded patch set 4 12/20/21, 22:37

  12. core-ci voted on patch set 4 V +1 12/20/21, 22:52 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21322

  13. Benjamin Franzke abandoned the change 01/05/22, 12:05

    Will solve in a build-postprocessing step instead. (mapping relative tbare imports via static code analysis) See https://review.typo3.org/c/Packages/TYPO3.CMS/+/72637/17/Build/util/map-import.js#21