@webhandle/external-resource-manager 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,6 +39,11 @@ export default class ExternalResourceManager {
39
39
  * of the URLs we've already rendered here.
40
40
  */
41
41
  alreadyRenderedUrls = new Set()
42
+
43
+ /**
44
+ * To make sure we don't provide a resource twice, track which ones we've already provided.
45
+ */
46
+ alreadyProvidedNames = new Set()
42
47
 
43
48
  constructor(options) {
44
49
  Object.assign(this, options)
@@ -53,6 +58,26 @@ export default class ExternalResourceManager {
53
58
  }
54
59
  }
55
60
 
61
+ expandURLList(resource) {
62
+ let urls
63
+ if(typeof resource.url === 'string') {
64
+ urls = resource.url.split('\n').map(line => line.trim()).filter(line => !!line)
65
+ }
66
+ else if(Array.isArray(resource.url)) {
67
+ urls = resource.url
68
+ }
69
+
70
+ if(!urls) {
71
+ return [resource]
72
+ }
73
+ if(urls.length === 1) {
74
+ return [resource]
75
+ }
76
+
77
+
78
+
79
+ }
80
+
56
81
  includeResource(resource) {
57
82
  if(!resource) {
58
83
  return
@@ -60,24 +85,27 @@ export default class ExternalResourceManager {
60
85
  if(typeof resource === 'object' && resource instanceof Resource === false) {
61
86
  resource = new Resource(resource)
62
87
  }
63
- this._noteSatisfies(resource)
64
- if(this.alreadySatisfied.has(resource.url)) {
65
- // We've already got a resource which satisfies this url
66
- this.differentlySatisfiedResource.push(resource)
67
- return
68
- }
69
- if(resource.satisfies && Array.isArray(resource.satisfies)) {
70
- // We're going to remove any previously included resource which is satisfied
71
- // by this resource
72
- for(let included of this.includedResources) {
73
- if(resource.satisfies.includes(included.url)) {
74
- this.includedResources.delete(included)
75
- this.differentlySatisfiedResource.push(resource)
88
+ let resources = this.expandURLList(resource)
89
+ for(let resource of resources) {
90
+ this._noteSatisfies(resource)
91
+ if(this.alreadySatisfied.has(resource.url)) {
92
+ // We've already got a resource which satisfies this url
93
+ this.differentlySatisfiedResource.push(resource)
94
+ return
95
+ }
96
+ if(resource.satisfies && Array.isArray(resource.satisfies)) {
97
+ // We're going to remove any previously included resource which is satisfied
98
+ // by this resource
99
+ for(let included of this.includedResources) {
100
+ if(resource.satisfies.includes(included.url)) {
101
+ this.includedResources.delete(included)
102
+ this.differentlySatisfiedResource.push(resource)
103
+ }
76
104
  }
105
+ this._noteSatisfies(resource)
77
106
  }
78
- this._noteSatisfies(resource)
107
+ this.includedResources.add(resource)
79
108
  }
80
- this.includedResources.add(resource)
81
109
  }
82
110
 
83
111
  provideResource(resource) {
@@ -9,8 +9,13 @@ export default function createImportmapGenerator(webhandle) {
9
9
  if(resource.rendered) {
10
10
  continue
11
11
  }
12
- found = true
13
12
 
13
+ if(manager.alreadyProvidedNames.has('module:' + resource.name)) {
14
+ resource.rendered = true
15
+ continue
16
+ }
17
+
18
+ found = true
14
19
  if(resource.data && !resource.url) {
15
20
  let content = `export default ${JSON.stringify(resource.data)}`
16
21
  let url = `data:text/javascript,${content}`
@@ -28,6 +33,7 @@ export default function createImportmapGenerator(webhandle) {
28
33
  }
29
34
  if (resource.mimeType === 'application/javascript' && resource.resourceType === 'module') {
30
35
  imports[resource.name] = vrsc + resource.url
36
+ manager.alreadyProvidedNames.add('module:' + resource.name)
31
37
  }
32
38
  }
33
39
 
@@ -16,6 +16,7 @@ initializeWebhandleComponent.templatePaths = ['views']
16
16
 
17
17
  initializeWebhandleComponent.setup = async function (webhandle, config) {
18
18
  let compmanager = new ComponentManager()
19
+ compmanager.config = config
19
20
 
20
21
  let generator = createImportmapGenerator(webhandle)
21
22
  let cssRender = createTextCssRenderer(webhandle)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webhandle/external-resource-manager",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "external-resource-manager.js",
6
6
  "scripts": {