You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(BREAKING): Replace mapFileDir argument with a function for reading the source map (#76)
fix(BREAKING): Remove the nodejs fs and path imports
feat(BREAKING): Require a function for reading the source map content to be passed as a parameter
feat: Support reading source maps sync or async
chore(BREAKING): Throw if a string directory path is passed to fromMapFileComment or fromMapFileSource
chore: Add Upgrading section to the README
Co-authored-by: Blaine Bublitz <[email protected]>
Prior to v2.0.0, the `fromMapFileComment` and `fromMapFileSource` functions took a String directory path and used that to resolve & read the source map file from the filesystem. However, this made the library limited to nodejs environments and broke on sources with querystrings.
29
+
30
+
In v2.0.0, you now need to pass a function that does the file reading. It will receive the source filename as a String that you can resolve to a filesystem path, URL, or anything else.
31
+
32
+
If you are using `convert-source-map` in nodejs and want the previous behavior, you'll use a function like such:
33
+
34
+
```diff
35
+
+ var fs = require('fs'); // Import the fs module to read a file
36
+
+ var path = require('path'); // Import the path module to resolve a path against your directory
37
+
- var conv = convert.fromMapFileSource(css, '../my-dir');
38
+
+ var conv = convert.fromMapFileSource(css, function (filename) {
@@ -45,24 +62,78 @@ Returns source map converter from given base64 encoded json string.
45
62
46
63
Returns source map converter from given base64 or uri encoded json string prefixed with `//# sourceMappingURL=...`.
47
64
48
-
### fromMapFileComment(comment, mapFileDir)
65
+
### fromMapFileComment(comment, readMap)
49
66
50
67
Returns source map converter from given `filename` by parsing `//# sourceMappingURL=filename`.
51
68
52
-
`filename` must point to a file that is found inside the `mapFileDir`. Most tools store this file right next to the
53
-
generated file, i.e. the one containing the source map.
69
+
`readMap` must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a `Promise` containing a String or Buffer of the source map (if read asynchronously).
70
+
71
+
If `readMap` doesn't return a `Promise`, `fromMapFileComment` will return a source map converter synchronously.
72
+
73
+
If `readMap` returns a `Promise`, `fromMapFileComment` will also return `Promise`. The `Promise` will be either resolved with the source map converter or rejected with an error.
Finds last sourcemap comment in file and returns source map converter or returns `null` if no source map comment was found.
58
127
59
-
### fromMapFileSource(source, mapFileDir)
128
+
### fromMapFileSource(source, readMap)
129
+
130
+
Finds last sourcemap comment in file and returns source map converter or returns `null` if no source map comment was found.
131
+
132
+
`readMap` must be a function which receives the source map filename and returns either a String or Buffer of the source map (if read synchronously), or a `Promise` containing a String or Buffer of the source map (if read asynchronously).
60
133
61
-
Finds last sourcemap comment in file and returns source map converter or returns `null` if no source map comment was
62
-
found.
134
+
If `readMap` doesn't return a `Promise`, `fromMapFileSource` will return a source map converter synchronously.
63
135
64
-
The sourcemap will be read from the map file found by parsing `# sourceMappingURL=file` comment. For more info see
65
-
fromMapFileComment.
136
+
If `readMap` returns a `Promise`, `fromMapFileSource` will also return `Promise`. The `Promise` will be either resolved with the source map converter or rejected with an error.
0 commit comments