Closed Bug 1766099 Opened 2 years ago Closed 2 years ago

Can we drop modules.json dependency of importScript ?

Categories

(Developer Infrastructure :: Lint and Formatting, task)

Tracking

(firefox101 fixed)

RESOLVED FIXED
101 Branch
Tracking Status
firefox101 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(12 files, 1 obsolete file)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

modules.json is used for the following 3 purpose:

  1. ChromeUtils.import, importing into this or globalThis
  2. Cu.import (Components.utils.import), importing into this or globalThis
  3. importScripts, except for the file in the same directory

The first 2 are going to be solved by bug 1758481 and bug 1765167,
but importScripts doesn't have a way to explicitly import variables, and still depends on modules.json to get the list of exported globals.

As pointed out in bug 1548308, modules.json tends to become out of date,
and indeed, it's already very inconsistent with the actual symbols exported by each module,
that means the linting doesn't guarantee the correct result.

Then, given the other 2 cases are going away, and the number of importScripts that requires modules.json isn't too much, we could revisit the design here.

Possible solutions are:

  • (a) Instead of listing the exported symbols for each module, provide a map between the path (e.g. resource:// URI) to the in-tree path, and load globals from the file, in the same way as the filename-only case
  • (b) Require import-globals-from above each importScripts
  • (c) Require global above each importScripts

(a) is similar to the current situation, but more robust against the change to the imported script.

(b) is already used in some case, and it works well if the imported script is from the same component

(c) is almost same as what ChromeUtils.import requires. each importScripts consumer needs to list symbols they want to import.

Tried the combination of (a) and (b), and that looks reasonably small change

I'm fine with a combination of (a) and (b). I wouldn't really want to do (c) as that may require updating/checking every time we change the exports of a script.

At one time, :Mossop was discussing changing our resource/chrome URIs to be based on the source tree directories rather than "random" locations - which would make this easier to look up files, but I don't see that happening in the short term.

(In reply to Tooru Fujisawa [:arai] from comment #1)

Tried the combination of (a) and (b), and that looks reasonably small change

Sorry, my comment was wrong.

what I've tried was:

  • the combination of (a) and (c) (map file + global)
  • the combination of (b) and (c) (import-globals-from + global)

both seems to be reasonably small.

(c) was required mostly for the case that the current globals.js file cannot figure out the exported symbols, such as require.js and worker helper.js, that indirectly defines the global variable.

I'll check if that can be replaced with other directive (maybe global and exported in those files?)

(In reply to Mark Banner (:standard8) from comment #2)

I wouldn't really want to do (c) as that may require updating/checking every time we change the exports of a script.

Just to make sure, I'm thinking about listing symbols that's imported and actually used in the file, instead of listing all symbols exported by the file.
So, in the situation that the change requires update to the global comment, it means the JS code itself should also be updated.
But I agree that it's better if that can automatically be done by linter.
will try addressing the issue about require.js etc above.

(In reply to Mark Banner (:standard8) from comment #2)

At one time, :Mossop was discussing changing our resource/chrome URIs to be based on the source tree directories rather than "random" locations - which would make this easier to look up files, but I don't see that happening in the short term.

That sounds really good in the long term solution :)
Figuring out the relation between the resource:// URI and the real path is always tedious ;)

Attached file option (b) : import-globals-from (obsolete) —

Here's WIP patch for option (b).
(actually 11 patches locally, for each directory https://treeherder.mozilla.org/jobs?repo=try&revision=21e48e3eacfcbe2a9a1e6f06bfd8b856cdc7e1d3
).

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

Yeah, I think that's reasonable given our current infrastructure.

Attachment #9273546 - Attachment is obsolete: true

Forgot to mention. the linter errors are expected for Parts 1-10, given the rule is fixed in Part 11, and until then both the modules.json and import-globals-from have effect.
If necessary, I'll fold them into single patch.

Attachment #9273778 - Attachment description: Bug 1766099 - Part 8: Explicitly specify import or imported symbol for importScripts in toolkit/components/reader/. r=Standard8 → Bug 1766099 - Part 8: Explicitly specify import or imported symbol for importScripts in toolkit/components/reader/. r=Standard8!
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/5a158d8879ba
Part 1: Explicitly specify import or imported symbol for importScripts in browser/components/newtab/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/9b8506f0f227
Part 2: Explicitly specify import or imported symbol for importScripts in devtools/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/82dba376abff
Part 3: Explicitly specify import or imported symbol for importScripts in dom/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/f4899b6d4da4
Part 4: Explicitly specify import or imported symbol for importScripts in services/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/8018efd4ab2a
Part 5: Explicitly specify import or imported symbol for importScripts in toolkit/components/lz4/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/4b5d4a6e045b
Part 6: Explicitly specify import or imported symbol for importScripts in toolkit/components/osfile/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/0ad5df800908
Part 7: Explicitly specify import or imported symbol for importScripts in toolkit/components/promiseworker/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/980aae0780e9
Part 8: Explicitly specify import or imported symbol for importScripts in toolkit/components/reader/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/bdcc533f8928
Part 9: Explicitly specify import or imported symbol for importScripts in toolkit/components/thumbnails/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/abc4b50ba8f1
Part 10: Explicitly specify import or imported symbol for importScripts in toolkit/components/workerloader/. r=Standard8
https://hg.mozilla.org/integration/autoland/rev/c7c865812f8f
Part 11: Do not use modules.json for importScripts. r=Standard8
Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/ea09f89c7e0f
explicitly specify import or imported sybmol for importScripts in DNS.jsm. r=#thunderbird-reviewers,rjl
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: