source: trip-planner-front/node_modules/adjust-sourcemap-loader/codec/npm-module.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 997 bytes
Line 
1'use strict';
2
3var path = require('path'),
4 fs = require('fs');
5
6var loaderUtils = require('loader-utils');
7
8var getContextDirectory = require('./utility/get-context-directory');
9
10/**
11 * Codec for relative paths with respect to the context directory.
12 * @type {{name:string, decode: function}}
13 */
14module.exports = {
15 name : 'npmModule',
16 decode: decode
17};
18
19/**
20 * Decode the given uri.
21 * Include only module paths containing `~`.
22 * @this {{options: object}} A loader or compilation
23 * @param {string} uri A source uri to decode
24 * @returns {boolean|string} False where unmatched else the decoded path
25 */
26function decode(uri) {
27 /* jshint validthis:true */
28 if (/~/.test(uri)) {
29 var relative = loaderUtils.urlToRequest(uri),
30 base = getContextDirectory.call(this),
31 absFile = path.normalize(path.join(base, 'node_modules', relative)),
32 isValid = !!absFile && fs.existsSync(absFile) && fs.statSync(absFile).isFile();
33 return isValid && absFile;
34 }
35}
Note: See TracBrowser for help on using the repository browser.