@jsenv/sourcemap 1.0.10 → 1.1.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.
@@ -2,61 +2,61 @@
2
2
  * https://github.com/mozilla/source-map#sourcemapgenerator
3
3
  */
4
4
 
5
- import { requireSourcemap } from "./require_sourcemap.js"
5
+ import { requireSourcemap } from "./require_sourcemap.js";
6
6
 
7
- const { SourceMapConsumer, SourceMapGenerator } = requireSourcemap()
7
+ const { SourceMapConsumer, SourceMapGenerator } = requireSourcemap();
8
8
 
9
9
  export const composeTwoSourcemaps = (firstSourcemap, secondSourcemap) => {
10
10
  if (!firstSourcemap && !secondSourcemap) {
11
- return null
11
+ return null;
12
12
  }
13
13
  if (!firstSourcemap) {
14
- return secondSourcemap
14
+ return secondSourcemap;
15
15
  }
16
16
  if (!secondSourcemap) {
17
- return firstSourcemap
17
+ return firstSourcemap;
18
18
  }
19
- const sourcemapGenerator = new SourceMapGenerator()
20
- const firstSourcemapConsumer = new SourceMapConsumer(firstSourcemap)
21
- const secondSourcemapConsumer = new SourceMapConsumer(secondSourcemap)
22
- const firstMappings = readMappings(firstSourcemapConsumer)
19
+ const sourcemapGenerator = new SourceMapGenerator();
20
+ const firstSourcemapConsumer = new SourceMapConsumer(firstSourcemap);
21
+ const secondSourcemapConsumer = new SourceMapConsumer(secondSourcemap);
22
+ const firstMappings = readMappings(firstSourcemapConsumer);
23
23
  firstMappings.forEach((mapping) => {
24
- sourcemapGenerator.addMapping(mapping)
25
- })
26
- const secondMappings = readMappings(secondSourcemapConsumer)
24
+ sourcemapGenerator.addMapping(mapping);
25
+ });
26
+ const secondMappings = readMappings(secondSourcemapConsumer);
27
27
  secondMappings.forEach((mapping) => {
28
- sourcemapGenerator.addMapping(mapping)
29
- })
30
- const sourcemap = sourcemapGenerator.toJSON()
31
- const sources = []
32
- const sourcesContent = []
33
- const firstSourcesContent = firstSourcemap.sourcesContent
34
- const secondSourcesContent = secondSourcemap.sourcesContent
28
+ sourcemapGenerator.addMapping(mapping);
29
+ });
30
+ const sourcemap = sourcemapGenerator.toJSON();
31
+ const sources = [];
32
+ const sourcesContent = [];
33
+ const firstSourcesContent = firstSourcemap.sourcesContent;
34
+ const secondSourcesContent = secondSourcemap.sourcesContent;
35
35
  sourcemap.sources.forEach((source) => {
36
- sources.push(source)
36
+ sources.push(source);
37
37
  if (secondSourcesContent) {
38
- const secondSourceIndex = secondSourcemap.sources.indexOf(source)
38
+ const secondSourceIndex = secondSourcemap.sources.indexOf(source);
39
39
  if (secondSourceIndex > -1) {
40
- sourcesContent.push(secondSourcesContent[secondSourceIndex])
41
- return
40
+ sourcesContent.push(secondSourcesContent[secondSourceIndex]);
41
+ return;
42
42
  }
43
43
  }
44
44
  if (firstSourcesContent) {
45
- const firstSourceIndex = firstSourcemap.sources.indexOf(source)
45
+ const firstSourceIndex = firstSourcemap.sources.indexOf(source);
46
46
  if (firstSourceIndex > -1) {
47
- sourcesContent.push(firstSourcesContent[firstSourceIndex])
48
- return
47
+ sourcesContent.push(firstSourcesContent[firstSourceIndex]);
48
+ return;
49
49
  }
50
50
  }
51
- sourcesContent.push(null)
52
- })
53
- sourcemap.sources = sources
54
- sourcemap.sourcesContent = sourcesContent
55
- return sourcemap
56
- }
51
+ sourcesContent.push(null);
52
+ });
53
+ sourcemap.sources = sources;
54
+ sourcemap.sourcesContent = sourcesContent;
55
+ return sourcemap;
56
+ };
57
57
 
58
58
  const readMappings = (consumer) => {
59
- const mappings = []
59
+ const mappings = [];
60
60
  consumer.eachMapping(
61
61
  ({
62
62
  originalColumn,
@@ -80,8 +80,8 @@ const readMappings = (consumer) => {
80
80
  },
81
81
  source: typeof originalColumn === "number" ? source : undefined,
82
82
  name,
83
- })
83
+ });
84
84
  },
85
- )
86
- return mappings
87
- }
85
+ );
86
+ return mappings;
87
+ };
@@ -2,23 +2,23 @@ import {
2
2
  isFileSystemPath,
3
3
  fileSystemPathToUrl,
4
4
  urlToFileSystemPath,
5
- } from "@jsenv/urls"
5
+ } from "@jsenv/urls";
6
6
 
7
7
  export const sourcemapConverter = {
8
8
  toFileUrls: (sourcemap) => {
9
9
  return {
10
10
  ...sourcemap,
11
11
  sources: sourcemap.sources.map((source) => {
12
- return isFileSystemPath(source) ? fileSystemPathToUrl(source) : source
12
+ return isFileSystemPath(source) ? fileSystemPathToUrl(source) : source;
13
13
  }),
14
- }
14
+ };
15
15
  },
16
16
  toFilePaths: (sourcemap) => {
17
17
  return {
18
18
  ...sourcemap,
19
19
  sources: sourcemap.sources.map((source) => {
20
- return urlToFileSystemPath(source)
20
+ return urlToFileSystemPath(source);
21
21
  }),
22
- }
22
+ };
23
23
  },
24
- }
24
+ };
@@ -1,15 +1,15 @@
1
1
  export const generateSourcemapFileUrl = (url) => {
2
- const urlObject = new URL(url)
3
- let { origin, pathname, search, hash } = urlObject
2
+ const urlObject = new URL(url);
3
+ let { origin, pathname, search, hash } = urlObject;
4
4
  // origin is "null" for "file://" urls with Node.js
5
5
  if (origin === "null" && urlObject.href.startsWith("file:")) {
6
- origin = "file://"
6
+ origin = "file://";
7
7
  }
8
- const sourcemapUrl = `${origin}${pathname}.map${search}${hash}`
9
- return sourcemapUrl
10
- }
8
+ const sourcemapUrl = `${origin}${pathname}.map${search}${hash}`;
9
+ return sourcemapUrl;
10
+ };
11
11
 
12
12
  export const generateSourcemapDataUrl = (sourcemap) => {
13
- const asBase64 = Buffer.from(JSON.stringify(sourcemap)).toString("base64")
14
- return `data:application/json;charset=utf-8;base64,${asBase64}`
15
- }
13
+ const asBase64 = Buffer.from(JSON.stringify(sourcemap)).toString("base64");
14
+ return `data:application/json;charset=utf-8;base64,${asBase64}`;
15
+ };
@@ -1,13 +1,13 @@
1
- import { createMagicSource } from "@jsenv/sourcemap"
1
+ import { createMagicSource } from "@jsenv/sourcemap";
2
2
 
3
3
  const content = `import { inferContextFrom, createUrlContext } from "../url_context.js";
4
4
  // toto
5
- `
6
- const magic = createMagicSource(content)
5
+ `;
6
+ const magic = createMagicSource(content);
7
7
  magic.replace({
8
8
  start: 51,
9
9
  end: 70,
10
- replacement: `"/@fs/Users/d.maillard/dev/jsenv/jsenv-core/src/internal/url_context.js"`,
11
- })
12
- const ret = magic.toContentAndSourcemap()
13
- console.log(ret)
10
+ replacement: `"/@fs/Users/d.maillard/dev/jsenv/core/src/internal/url_context.js"`,
11
+ });
12
+ const ret = magic.toContentAndSourcemap();
13
+ console.log(ret);