| | |
| | | const { isAbsolute, join } = require("./fs"); |
| | | |
| | | /** @typedef {import("./fs").InputFileSystem} InputFileSystem */ |
| | | |
| | | /** |
| | | * @typedef {(input: string | Buffer<ArrayBufferLike>, resourcePath: string, fs: InputFileSystem) => Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[]}>} SourceMapExtractorFunction |
| | | */ |
| | | |
| | | /** @typedef {string | Buffer<ArrayBufferLike>} StringOrBuffer */ |
| | | /** @typedef {(input: StringOrBuffer, resourcePath: string, fs: InputFileSystem) => Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined, fileDependencies: string[] }>} SourceMapExtractorFunction */ |
| | | /** @typedef {import("webpack-sources").RawSourceMap} RawSourceMap */ |
| | | /** @typedef {(resourcePath: string) => Promise<StringOrBuffer>} ReadResource */ |
| | | |
| | | /** |
| | | * @typedef {(resourcePath: string) => Promise<string | Buffer<ArrayBufferLike>>} ReadResource |
| | | */ |
| | | |
| | | /** |
| | | * Defines the source mapping url type used by this module. |
| | | * @typedef {object} SourceMappingURL |
| | | * @property {string} sourceMappingURL |
| | | * @property {string} replacementString |
| | |
| | | */ |
| | | function getSourceMappingURL(code) { |
| | | const lines = code.split(/^/m); |
| | | /** @type {RegExpMatchArray | null | undefined} */ |
| | | let match; |
| | | |
| | | for (let i = lines.length - 1; i >= 0; i--) { |
| | |
| | | * @param {ReadResource} readResource read resource function |
| | | * @param {string[]} possibleRequests array of possible file paths |
| | | * @param {string} errorsAccumulator accumulated error messages |
| | | * @returns {Promise<{path: string, data?: string}>} source content promise |
| | | * @returns {Promise<{ path: string, data?: string }>} source content promise |
| | | */ |
| | | async function fetchPathsFromURL( |
| | | readResource, |
| | | possibleRequests, |
| | | errorsAccumulator = "" |
| | | ) { |
| | | /** @type {StringOrBuffer} */ |
| | | let result; |
| | | |
| | | try { |
| | |
| | | * @param {string} url source URL |
| | | * @param {string=} sourceRoot source root directory |
| | | * @param {boolean=} skipReading whether to skip reading file content |
| | | * @returns {Promise<{sourceURL: string, sourceContent?: string | Buffer<ArrayBufferLike>}>} source content promise |
| | | * @returns {Promise<{ sourceURL: string, sourceContent?: StringOrBuffer }>} source content promise |
| | | */ |
| | | async function fetchFromURL( |
| | | readResource, |
| | |
| | | if (isAbsolute(url)) { |
| | | let sourceURL = path.normalize(url); |
| | | |
| | | /** @type {undefined | StringOrBuffer} */ |
| | | let sourceContent; |
| | | |
| | | if (!skipReading) { |
| | | /** @type {string[]} */ |
| | | const possibleRequests = [sourceURL]; |
| | | |
| | | if (url.startsWith("/")) { |
| | |
| | | |
| | | // 4. Relative path |
| | | const sourceURL = getAbsolutePath(context, url, sourceRoot || ""); |
| | | /** @type {undefined | StringOrBuffer} */ |
| | | let sourceContent; |
| | | |
| | | if (!skipReading) { |
| | |
| | | |
| | | /** |
| | | * Extract source map from code content |
| | | * @param {string | Buffer<ArrayBufferLike>} stringOrBuffer The input code content as string or buffer |
| | | * @param {StringOrBuffer} stringOrBuffer The input code content as string or buffer |
| | | * @param {string} resourcePath The path to the resource file |
| | | * @param {ReadResource} readResource The read resource function |
| | | * @returns {Promise<{source: string | Buffer<ArrayBufferLike>, sourceMap: string | RawSourceMap | undefined}>} Promise resolving to extracted source map information |
| | | * @returns {Promise<{ source: StringOrBuffer, sourceMap: string | RawSourceMap | undefined }>} Promise resolving to extracted source map information |
| | | */ |
| | | async function extractSourceMap(stringOrBuffer, resourcePath, readResource) { |
| | | const input = |