@jsenv/core 39.3.10 → 39.3.11

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.
@@ -17104,20 +17104,44 @@ const jsenvPluginInlineContentFetcher = () => {
17104
17104
  if (!urlInfo.isInline) {
17105
17105
  return null;
17106
17106
  }
17107
- // - we must use last reference because
17108
- // when updating the file, first reference is the previous version
17109
- // - we cannot use urlInfo.lastReference because it can be the reference created by "http_request"
17107
+ let isDirectRequestToFile;
17108
+ if (urlInfo.context.request) {
17109
+ const requestedUrl = new URL(
17110
+ urlInfo.context.request.resource.slice(1),
17111
+ urlInfo.context.rootDirectoryUrl,
17112
+ ).href;
17113
+ isDirectRequestToFile = requestedUrl === urlInfo.url;
17114
+ }
17115
+ /*
17116
+ * We want to find inline content but it's not straightforward
17117
+ *
17118
+ * For some reason (that would be great to investigate)
17119
+ * urlInfo corresponding to inline content has several referenceFromOthersSet
17120
+ * so the latest version is the last reference
17121
+ * BUT the last reference is the "http_request"
17122
+ * so it's more likely the before last reference that contains the latest version
17123
+ *
17124
+ * BUT the is an exception when using supervisor as the before last reference
17125
+ * is the one fetched by the browser that is already cooked
17126
+ * we must re-cook from the original content, not from the already cooked content
17127
+ * Otherwise references are already resolved and
17128
+ * - "/node_modules/package/file.js" instead of "package/file.js"
17129
+ * - meaning we would not create the implicit dependency to package.json
17130
+ * - resulting in a reload of the browser (as implicit reference to package.json is gone)
17131
+ * -> can create infinite loop of reloads
17132
+ */
17110
17133
  let lastInlineReference;
17111
17134
  let originalContent = urlInfo.originalContent;
17112
17135
  for (const reference of urlInfo.referenceFromOthersSet) {
17113
- if (reference.isInline) {
17114
- if (
17115
- urlInfo.originalContent === undefined &&
17116
- originalContent === undefined
17117
- ) {
17118
- originalContent = reference.content;
17119
- }
17120
- lastInlineReference = reference;
17136
+ if (!reference.isInline) {
17137
+ continue;
17138
+ }
17139
+ if (urlInfo.originalContent === undefined) {
17140
+ originalContent = reference.content;
17141
+ }
17142
+ lastInlineReference = reference;
17143
+ if (isDirectRequestToFile) {
17144
+ break;
17121
17145
  }
17122
17146
  }
17123
17147
  const { prev } = lastInlineReference;
@@ -17139,12 +17163,6 @@ const jsenvPluginInlineContentFetcher = () => {
17139
17163
  return {
17140
17164
  originalContent,
17141
17165
  content:
17142
- // we must favor original content to re-apply the same plugin logic
17143
- // so that the same references are generated
17144
- // without this we would try to resolve references like
17145
- // "/node_modules/package/file.js" instead of "package/file.js"
17146
- // meaning we would not create the implicit dependency to package.json
17147
- // resulting in a reload of the browser (as implicit reference to package.json is gone)
17148
17166
  originalContent === undefined
17149
17167
  ? lastInlineReference.content
17150
17168
  : originalContent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "39.3.10",
3
+ "version": "39.3.11",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -41,20 +41,44 @@ const jsenvPluginInlineContentFetcher = () => {
41
41
  if (!urlInfo.isInline) {
42
42
  return null;
43
43
  }
44
- // - we must use last reference because
45
- // when updating the file, first reference is the previous version
46
- // - we cannot use urlInfo.lastReference because it can be the reference created by "http_request"
44
+ let isDirectRequestToFile;
45
+ if (urlInfo.context.request) {
46
+ const requestedUrl = new URL(
47
+ urlInfo.context.request.resource.slice(1),
48
+ urlInfo.context.rootDirectoryUrl,
49
+ ).href;
50
+ isDirectRequestToFile = requestedUrl === urlInfo.url;
51
+ }
52
+ /*
53
+ * We want to find inline content but it's not straightforward
54
+ *
55
+ * For some reason (that would be great to investigate)
56
+ * urlInfo corresponding to inline content has several referenceFromOthersSet
57
+ * so the latest version is the last reference
58
+ * BUT the last reference is the "http_request"
59
+ * so it's more likely the before last reference that contains the latest version
60
+ *
61
+ * BUT the is an exception when using supervisor as the before last reference
62
+ * is the one fetched by the browser that is already cooked
63
+ * we must re-cook from the original content, not from the already cooked content
64
+ * Otherwise references are already resolved and
65
+ * - "/node_modules/package/file.js" instead of "package/file.js"
66
+ * - meaning we would not create the implicit dependency to package.json
67
+ * - resulting in a reload of the browser (as implicit reference to package.json is gone)
68
+ * -> can create infinite loop of reloads
69
+ */
47
70
  let lastInlineReference;
48
71
  let originalContent = urlInfo.originalContent;
49
72
  for (const reference of urlInfo.referenceFromOthersSet) {
50
- if (reference.isInline) {
51
- if (
52
- urlInfo.originalContent === undefined &&
53
- originalContent === undefined
54
- ) {
55
- originalContent = reference.content;
56
- }
57
- lastInlineReference = reference;
73
+ if (!reference.isInline) {
74
+ continue;
75
+ }
76
+ if (urlInfo.originalContent === undefined) {
77
+ originalContent = reference.content;
78
+ }
79
+ lastInlineReference = reference;
80
+ if (isDirectRequestToFile) {
81
+ break;
58
82
  }
59
83
  }
60
84
  const { prev } = lastInlineReference;
@@ -76,12 +100,6 @@ const jsenvPluginInlineContentFetcher = () => {
76
100
  return {
77
101
  originalContent,
78
102
  content:
79
- // we must favor original content to re-apply the same plugin logic
80
- // so that the same references are generated
81
- // without this we would try to resolve references like
82
- // "/node_modules/package/file.js" instead of "package/file.js"
83
- // meaning we would not create the implicit dependency to package.json
84
- // resulting in a reload of the browser (as implicit reference to package.json is gone)
85
103
  originalContent === undefined
86
104
  ? lastInlineReference.content
87
105
  : originalContent,