@jsenv/plugin-supervisor 1.6.13 → 1.6.15

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.
@@ -1,5 +1,5 @@
1
1
  import { applyBabelPlugins, parseHtml, visitHtmlNodes, analyzeScriptNode, getHtmlNodeAttribute, getHtmlNodeText, injectJsenvScript, stringifyHtmlAst, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeText, setHtmlNodeAttributes } from "@jsenv/ast";
2
- import { createRequire } from "node:module";
2
+ import { generateSourcemapDataUrl, SOURCEMAP, getOriginalPosition } from "@jsenv/sourcemap";
3
3
 
4
4
  const formatDefault = v => v;
5
5
  const generateContentFrame = ({
@@ -273,160 +273,6 @@ const pathnameToParentPathname = pathname => {
273
273
  return pathname.slice(0, slashLastIndex + 1);
274
274
  };
275
275
 
276
- const require = createRequire(import.meta.url);
277
- // consider using https://github.com/7rulnik/source-map-js
278
-
279
- const requireSourcemap = () => {
280
- const namespace = require("source-map-js");
281
- return namespace;
282
- };
283
-
284
- // https://github.com/mozilla/source-map#sourcemapconsumerprototypeoriginalpositionforgeneratedposition
285
- const getOriginalPosition = ({
286
- sourcemap,
287
- line,
288
- column,
289
- bias
290
- }) => {
291
- const {
292
- SourceMapConsumer
293
- } = requireSourcemap();
294
- const sourceMapConsumer = new SourceMapConsumer(sourcemap);
295
- const originalPosition = sourceMapConsumer.originalPositionFor({
296
- line,
297
- column,
298
- bias
299
- });
300
- return originalPosition;
301
- };
302
-
303
- const generateSourcemapDataUrl = sourcemap => {
304
- const asBase64 = Buffer.from(JSON.stringify(sourcemap)).toString("base64");
305
- return "data:application/json;charset=utf-8;base64,".concat(asBase64);
306
- };
307
-
308
- const SOURCEMAP = {
309
- enabledOnContentType: contentType => {
310
- return ["text/javascript", "text/css"].includes(contentType);
311
- },
312
- readComment: ({
313
- contentType,
314
- content
315
- }) => {
316
- const read = {
317
- "text/javascript": parseJavaScriptSourcemapComment,
318
- "text/css": parseCssSourcemapComment
319
- }[contentType];
320
- return read ? read(content) : null;
321
- },
322
- removeComment: ({
323
- contentType,
324
- content
325
- }) => {
326
- return SOURCEMAP.writeComment({
327
- contentType,
328
- content,
329
- specifier: ""
330
- });
331
- },
332
- writeComment: ({
333
- contentType,
334
- content,
335
- specifier
336
- }) => {
337
- const write = {
338
- "text/javascript": setJavaScriptSourceMappingUrl,
339
- "text/css": setCssSourceMappingUrl
340
- }[contentType];
341
- return write ? write(content, specifier) : content;
342
- }
343
- };
344
- const parseJavaScriptSourcemapComment = javaScriptSource => {
345
- let sourceMappingUrl;
346
- replaceSourceMappingUrl(javaScriptSource, javascriptSourceMappingUrlCommentRegexp, value => {
347
- sourceMappingUrl = value;
348
- });
349
- if (!sourceMappingUrl) {
350
- return null;
351
- }
352
- return {
353
- type: "sourcemap_comment",
354
- subtype: "js",
355
- // we assume it's on last line
356
- line: javaScriptSource.split(/\r?\n/).length,
357
- // ${"//#"} is to avoid static analysis to think there is a sourceMappingUrl for this file
358
- column: "//#".concat(" sourceMappingURL=").length + 1,
359
- specifier: sourceMappingUrl
360
- };
361
- };
362
- const setJavaScriptSourceMappingUrl = (javaScriptSource, sourceMappingFileUrl) => {
363
- let replaced;
364
- const sourceAfterReplace = replaceSourceMappingUrl(javaScriptSource, javascriptSourceMappingUrlCommentRegexp, () => {
365
- replaced = true;
366
- return sourceMappingFileUrl ? writeJavaScriptSourceMappingURL(sourceMappingFileUrl) : "";
367
- });
368
- if (replaced) {
369
- return sourceAfterReplace;
370
- }
371
- return sourceMappingFileUrl ? "".concat(javaScriptSource, "\n").concat(writeJavaScriptSourceMappingURL(sourceMappingFileUrl), "\n") : javaScriptSource;
372
- };
373
- const parseCssSourcemapComment = cssSource => {
374
- let sourceMappingUrl;
375
- replaceSourceMappingUrl(cssSource, cssSourceMappingUrlCommentRegExp, value => {
376
- sourceMappingUrl = value;
377
- });
378
- if (!sourceMappingUrl) {
379
- return null;
380
- }
381
- return {
382
- type: "sourcemap_comment",
383
- subtype: "css",
384
- // we assume it's on last line
385
- line: cssSource.split(/\r?\n/).length - 1,
386
- // ${"//*#"} is to avoid static analysis to think there is a sourceMappingUrl for this file
387
- column: "//*#".concat(" sourceMappingURL=").length + 1,
388
- specifier: sourceMappingUrl
389
- };
390
- };
391
- const setCssSourceMappingUrl = (cssSource, sourceMappingFileUrl) => {
392
- let replaced;
393
- const sourceAfterReplace = replaceSourceMappingUrl(cssSource, cssSourceMappingUrlCommentRegExp, () => {
394
- replaced = true;
395
- return sourceMappingFileUrl ? writeCssSourceMappingUrl(sourceMappingFileUrl) : "";
396
- });
397
- if (replaced) {
398
- return sourceAfterReplace;
399
- }
400
- return sourceMappingFileUrl ? "".concat(cssSource, "\n").concat(writeCssSourceMappingUrl(sourceMappingFileUrl), "\n") : cssSource;
401
- };
402
- const javascriptSourceMappingUrlCommentRegexp = /\/\/ ?# ?sourceMappingURL=([^\s'"]+)/g;
403
- const cssSourceMappingUrlCommentRegExp = /\/\*# ?sourceMappingURL=([^\s'"]+) \*\//g;
404
-
405
- // ${"//#"} is to avoid a parser thinking there is a sourceMappingUrl for this file
406
- const writeJavaScriptSourceMappingURL = value => {
407
- return "//#".concat(" sourceMappingURL=", value);
408
- };
409
- const writeCssSourceMappingUrl = value => {
410
- return "/*# sourceMappingURL=".concat(value, " */");
411
- };
412
- const replaceSourceMappingUrl = (source, regexp, callback) => {
413
- let lastSourceMappingUrl;
414
- let matchSourceMappingUrl;
415
- while (matchSourceMappingUrl = regexp.exec(source)) {
416
- lastSourceMappingUrl = matchSourceMappingUrl;
417
- }
418
- if (lastSourceMappingUrl) {
419
- const index = lastSourceMappingUrl.index;
420
- const before = source.slice(0, index);
421
- const after = source.slice(index);
422
- const mappedAfter = after.replace(regexp, (match, firstGroup) => {
423
- return callback(firstGroup);
424
- });
425
- return "".concat(before).concat(mappedAfter);
426
- }
427
- return source;
428
- };
429
-
430
276
  /*
431
277
  * ```js
432
278
  * console.log(42)
@@ -994,6 +840,7 @@ const jsenvPluginSupervisor = ({
994
840
  if (sourcemap) {
995
841
  const original = getOriginalPosition({
996
842
  sourcemap,
843
+ url: file,
997
844
  line,
998
845
  column
999
846
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-supervisor",
3
- "version": "1.6.13",
3
+ "version": "1.6.15",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": {
17
- "development": "./src/main.js",
17
+ "dev:jsenv": "./src/main.js",
18
18
  "default": "./dist/jsenv_plugin_supervisor.js"
19
19
  }
20
20
  },
@@ -29,13 +29,15 @@
29
29
  "./src/client/supervisor.js",
30
30
  "./dist/js/supervisor.js"
31
31
  ],
32
- "dependencies": {
33
- "@jsenv/ast": "6.6.9",
34
- "@jsenv/urls": "2.7.2",
35
- "@jsenv/sourcemap": "1.3.5"
36
- },
37
32
  "scripts": {
38
33
  "build": "node ./scripts/build.mjs",
39
34
  "prepublishOnly": "npm run build"
35
+ },
36
+ "dependencies": {
37
+ "@jsenv/ast": "6.6.11",
38
+ "@jsenv/sourcemap": "1.3.7"
39
+ },
40
+ "devDependencies": {
41
+ "@jsenv/urls": "2.7.4"
40
42
  }
41
43
  }