srcdir-resolver.js (709B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 const path = require("path"); 6 const fs = require("fs"); 7 8 const PREFIX = "moz-src:///"; 9 10 exports.interfaceVersion = 2; 11 exports.resolve = source => { 12 if (!source.startsWith(PREFIX)) { 13 return { found: false }; 14 } 15 16 let result = path.resolve( 17 __dirname, 18 ...source.substring(PREFIX.length).split("/") 19 ); 20 let stats = fs.statSync(result, { throwIfNoEntry: false }); 21 if (!stats || !stats.isFile()) { 22 return { found: false }; 23 } 24 25 return { 26 found: true, 27 path: result, 28 }; 29 };