diff --git a/scripts/migrate-fx140/README.txt b/scripts/migrate-fx140/README.txt index f6f6f1b042..f031570d8d 100644 --- a/scripts/migrate-fx140/README.txt +++ b/scripts/migrate-fx140/README.txt @@ -12,3 +12,6 @@ Zotero modifications: Run: scripts/migrate-fx140/migrate.py [file_or_dir] + +Special notes for esmify: + - If the script you're running on is a window/XPCOM script, not an MJS/ESM, pass --imports diff --git a/scripts/migrate-fx140/bluebird-to-async.js b/scripts/migrate-fx140/bluebird-to-async.js index 7e78c63dcf..b812fc75f7 100755 --- a/scripts/migrate-fx140/bluebird-to-async.js +++ b/scripts/migrate-fx140/bluebird-to-async.js @@ -39,6 +39,7 @@ function doTranslate(inputFile, root) { 'race', 'reject', 'resolve', + 'try', ])) .forEach(path => { let callee = path.node.callee; diff --git a/scripts/migrate-fx140/import-to-import_esmodule.js b/scripts/migrate-fx140/import-to-import_esmodule.js index 38a716416e..efedc78032 100755 --- a/scripts/migrate-fx140/import-to-import_esmodule.js +++ b/scripts/migrate-fx140/import-to-import_esmodule.js @@ -29,6 +29,15 @@ const { module.exports = function (fileInfo, api) { const { jscodeshift } = api; + + // Cheap hack: + // Zotero usually calls Components.utils.import(), not Cu.import(). + // Those are the same thing, but this script can't rewrite the former + // to ChromeUtils.importESModule(), because it's unable to handle + // changing the number of property accesses in the chain. + // Just replace it in the text before parsing! + fileInfo.source = fileInfo.source.replace(/Components\.utils\.import\(/g, 'Cu.import('); + const root = jscodeshift(fileInfo.source); doTranslate(fileInfo.path, jscodeshift, root); return root.toSource({ useTabs: true, lineTerminator: "\n" }); @@ -61,10 +70,6 @@ const importCalls = [ from: ["Cu", "import"], to: ["ChromeUtils", "importESModule"], }, - { - from: ["Components", "utils", "import"], - to: ["ChromeUtils", "importESModule"], - }, { from: ["ChromeUtils", "import"], to: ["ChromeUtils", "importESModule"],