@jsenv/plugin-supervisor 1.3.9 → 1.4.0

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.
@@ -465,11 +465,11 @@ const replaceSourceMappingUrl = (source, regexp, callback) => {
465
465
  */
466
466
 
467
467
  const injectSupervisorIntoJs = async ({
468
- webServer,
469
468
  content,
470
469
  url,
471
470
  type,
472
- inlineSrc
471
+ inlineSrc,
472
+ sourcemaps
473
473
  }) => {
474
474
  const babelPluginJsSupervisor = type === "js_module" ? babelPluginJsModuleSupervisor : babelPluginJsClassicSupervisor;
475
475
  const result = await applyBabelPlugins({
@@ -481,14 +481,16 @@ const injectSupervisorIntoJs = async ({
481
481
  inputUrl: url
482
482
  });
483
483
  let code = result.code;
484
- let map = result.map;
485
- const sourcemapDataUrl = generateSourcemapDataUrl(map);
486
- code = SOURCEMAP.writeComment({
487
- contentType: "text/javascript",
488
- content: code,
489
- specifier: sourcemapDataUrl
490
- });
491
- code = "".concat(code, "\n//# sourceURL=").concat(urlToRelativeUrl(url, webServer.rootDirectoryUrl));
484
+ if (sourcemaps === "inline") {
485
+ const map = result.map;
486
+ const sourcemapDataUrl = generateSourcemapDataUrl(map);
487
+ code = SOURCEMAP.writeComment({
488
+ contentType: "text/javascript",
489
+ content: code,
490
+ specifier: sourcemapDataUrl
491
+ });
492
+ }
493
+ code = "".concat(code, "\n//# sourceURL=").concat(inlineSrc);
492
494
  return code;
493
495
  };
494
496
  const babelPluginJsModuleSupervisor = babel => {
@@ -702,7 +704,8 @@ const injectSupervisorIntoHTML = async ({
702
704
  generateInlineScriptSrc = ({
703
705
  inlineScriptUrl
704
706
  }) => urlToRelativeUrl(inlineScriptUrl, webServer.rootDirectoryUrl),
705
- inlineAsRemote
707
+ inlineAsRemote,
708
+ sourcemaps = "inline"
706
709
  }) => {
707
710
  const htmlAst = parseHtml({
708
711
  html: content,
@@ -777,7 +780,8 @@ const injectSupervisorIntoHTML = async ({
777
780
  content: textContent,
778
781
  url: inlineScriptUrl,
779
782
  type,
780
- inlineSrc: inlineScriptSrc
783
+ inlineSrc: inlineScriptSrc,
784
+ sourcemaps
781
785
  });
782
786
  mutations.push(() => {
783
787
  setHtmlNodeText(scriptNode, inlineJsSupervised, {
@@ -873,7 +877,7 @@ const injectSupervisorIntoHTML = async ({
873
877
  }, " ");
874
878
  injectHtmlNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
875
879
  tagName: "script",
876
- textContent: "window.__supervisor__.setup({".concat(setupParamsSource, "})")
880
+ textContent: "window.__supervisor__.setup({\n ".concat(setupParamsSource, "\n});")
877
881
  }), "jsenv:supervisor");
878
882
  injectHtmlNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
879
883
  tagName: "script",
@@ -1106,7 +1110,8 @@ const jsenvPluginSupervisor = ({
1106
1110
  content: textContent
1107
1111
  });
1108
1112
  return inlineScriptReference.generatedSpecifier;
1109
- }
1113
+ },
1114
+ sourcemaps: htmlUrlInfo.kitchen.context.sourcemaps
1110
1115
  });
1111
1116
  }
1112
1117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.3.9",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -78,6 +78,7 @@ export const injectSupervisorIntoHTML = async (
78
78
  generateInlineScriptSrc = ({ inlineScriptUrl }) =>
79
79
  urlToRelativeUrl(inlineScriptUrl, webServer.rootDirectoryUrl),
80
80
  inlineAsRemote,
81
+ sourcemaps = "inline",
81
82
  },
82
83
  ) => {
83
84
  const htmlAst = parseHtml({ html: content, url });
@@ -113,7 +114,10 @@ export const injectSupervisorIntoHTML = async (
113
114
  });
114
115
  if (inlineAsRemote) {
115
116
  // prefere la version src
116
- scriptInfos.push({ type, src: inlineScriptSrc });
117
+ scriptInfos.push({
118
+ type,
119
+ src: inlineScriptSrc,
120
+ });
117
121
  const remoteJsSupervised = generateCodeToSuperviseScriptWithSrc({
118
122
  type,
119
123
  src: inlineScriptSrc,
@@ -129,7 +133,11 @@ export const injectSupervisorIntoHTML = async (
129
133
  });
130
134
  });
131
135
  } else {
132
- scriptInfos.push({ type, src: inlineScriptSrc, isInline: true });
136
+ scriptInfos.push({
137
+ type,
138
+ src: inlineScriptSrc,
139
+ isInline: true,
140
+ });
133
141
  actions.push(async () => {
134
142
  try {
135
143
  const inlineJsSupervised = await injectSupervisorIntoJs({
@@ -138,6 +146,7 @@ export const injectSupervisorIntoHTML = async (
138
146
  url: inlineScriptUrl,
139
147
  type,
140
148
  inlineSrc: inlineScriptSrc,
149
+ sourcemaps,
141
150
  });
142
151
  mutations.push(() => {
143
152
  setHtmlNodeText(scriptNode, inlineJsSupervised, {
@@ -228,7 +237,9 @@ export const injectSupervisorIntoHTML = async (
228
237
  htmlAst,
229
238
  createHtmlNode({
230
239
  tagName: "script",
231
- textContent: `window.__supervisor__.setup({${setupParamsSource}})`,
240
+ textContent: `window.__supervisor__.setup({
241
+ ${setupParamsSource}
242
+ });`,
232
243
  }),
233
244
  "jsenv:supervisor",
234
245
  );
@@ -36,16 +36,15 @@
36
36
  * and create a variable named "undefined"
37
37
  */
38
38
 
39
- import { urlToRelativeUrl } from "@jsenv/urls";
40
39
  import { applyBabelPlugins } from "@jsenv/ast";
41
40
  import { SOURCEMAP, generateSourcemapDataUrl } from "@jsenv/sourcemap";
42
41
 
43
42
  export const injectSupervisorIntoJs = async ({
44
- webServer,
45
43
  content,
46
44
  url,
47
45
  type,
48
46
  inlineSrc,
47
+ sourcemaps,
49
48
  }) => {
50
49
  const babelPluginJsSupervisor =
51
50
  type === "js_module"
@@ -58,15 +57,17 @@ export const injectSupervisorIntoJs = async ({
58
57
  inputUrl: url,
59
58
  });
60
59
  let code = result.code;
61
- let map = result.map;
62
- const sourcemapDataUrl = generateSourcemapDataUrl(map);
63
- code = SOURCEMAP.writeComment({
64
- contentType: "text/javascript",
65
- content: code,
66
- specifier: sourcemapDataUrl,
67
- });
60
+ if (sourcemaps === "inline") {
61
+ const map = result.map;
62
+ const sourcemapDataUrl = generateSourcemapDataUrl(map);
63
+ code = SOURCEMAP.writeComment({
64
+ contentType: "text/javascript",
65
+ content: code,
66
+ specifier: sourcemapDataUrl,
67
+ });
68
+ }
68
69
  code = `${code}
69
- //# sourceURL=${urlToRelativeUrl(url, webServer.rootDirectoryUrl)}`;
70
+ //# sourceURL=${inlineSrc}`;
70
71
  return code;
71
72
  };
72
73
 
@@ -216,6 +216,7 @@ export const jsenvPluginSupervisor = ({
216
216
  });
217
217
  return inlineScriptReference.generatedSpecifier;
218
218
  },
219
+ sourcemaps: htmlUrlInfo.kitchen.context.sourcemaps,
219
220
  },
220
221
  );
221
222
  },