MCPcopy Create free account
hub / github.com/SAP/ui5-builder / getSourceMapFromUrl

Function getSourceMapFromUrl

lib/processors/minifier.js:86–122  ·  view source on GitHub ↗
({sourceMappingUrl, resourcePath, readFile})

Source from the content-addressed store, hash-verified

84}
85
86async function getSourceMapFromUrl({sourceMappingUrl, resourcePath, readFile}) {
87 // =======================================================================
88 // This code is almost identical to code located in lbt/bundle/Builder.js
89 // Please try to update both places when making changes
90 // =======================================================================
91 if (sourceMappingUrl.startsWith("data:")) {
92 // Data-URI indicates an inline source map
93 const expectedTypeAndEncoding = "data:application/json;charset=utf-8;base64,";
94 if (sourceMappingUrl.startsWith(expectedTypeAndEncoding)) {
95 const base64Content = sourceMappingUrl.slice(expectedTypeAndEncoding.length);
96 // Create a resource with a path suggesting it's the source map for the resource
97 // (which it is but inlined)
98 return Buffer.from(base64Content, "base64").toString();
99 } else {
100 log.warn(
101 `Source map reference in resource ${resourcePath} is a data URI but has an unexpected` +
102 `encoding: ${sourceMappingUrl}. Expected it to start with ` +
103 `"data:application/json;charset=utf-8;base64,"`);
104 }
105 } else if (httpPattern.test(sourceMappingUrl)) {
106 log.warn(`Source map reference in resource ${resourcePath} is an absolute URL. ` +
107 `Currently, only relative URLs are supported.`);
108 } else if (posixPath.isAbsolute(sourceMappingUrl)) {
109 log.warn(`Source map reference in resource ${resourcePath} is an absolute path. ` +
110 `Currently, only relative paths are supported.`);
111 } else {
112 const sourceMapPath = posixPath.join(posixPath.dirname(resourcePath), sourceMappingUrl);
113
114 try {
115 const sourceMapContent = await readFile(sourceMapPath);
116 return sourceMapContent.toString();
117 } catch (e) {
118 // No input source map
119 log.warn(`Unable to read source map for resource ${resourcePath}: ${e.message}`);
120 }
121 }
122}
123
124/**
125 * @public

Callers 2

minifier.jsFile · 0.85
minifier.jsFile · 0.85

Calls 2

fromMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected