作用域


使用清单的 "scopes" 字段一次设置多个资源的配置。 "scopes" 字段的工作原理是按片段匹配资源。 如果范围或资源包含 "cascade": true,则将在其包含范围内搜索未知说明符。 通过删除特殊方案的片段、保留尾随 "/" 后缀、以及删除查询和哈希片段来递归地减少资源 URL,可以找到级联的包含范围。 这导致 URL 最终减少到其来源。 如果 URL 是非特殊的,则范围将由 URL 的来源定位。 如果没有找到源的范围或在不透明源的情况下,可以使用协议字符串作为范围。 如果没有找到 URL 协议的范围,将使用最终的空字符串 "" 范围。

注意,blob: URL 采用它们包含的路径的来源,因此 "blob:https://nodejs.org" 的范围将无效,因为没有 URL 可以具有 blob:https://nodejs.org 的来源;以 blob:https://nodejs.org/ 开头的 URL 将使用 https://nodejs.org 作为其来源,因此 https: 作为其协议范围。 对于不透明的来源 blob: URL,它们的协议范围将具有 blob:,因为它们不采用来源。

Use the "scopes" field of a manifest to set configuration for many resources at once. The "scopes" field works by matching resources by their segments. If a scope or resource includes "cascade": true, unknown specifiers will be searched for in their containing scope. The containing scope for cascading is found by recursively reducing the resource URL by removing segments for special schemes, keeping trailing "/" suffixes, and removing the query and hash fragment. This leads to the eventual reduction of the URL to its origin. If the URL is non-special the scope will be located by the URL's origin. If no scope is found for the origin or in the case of opaque origins, a protocol string can be used as a scope. If no scope is found for the URL's protocol, a final empty string "" scope will be used.

Note, blob: URLs adopt their origin from the path they contain, and so a scope of "blob:https://nodejs.org" will have no effect since no URL can have an origin of blob:https://nodejs.org; URLs starting with blob:https://nodejs.org/ will use https://nodejs.org for its origin and thus https: for its protocol scope. For opaque origin blob: URLs they will have blob: for their protocol scope since they do not adopt origins.