PageSourceSearch

https://www.stiga.com/static/version1790224918/base/Magento/base/default/mage/requirejs/baseUrlResolver.js

js stiga.com collected 2026-09-24 09:35:48 UTC 5,204 bytes, 182 lines download raw bytes

1/**
2 * Copyright © Magento, Inc. All rights reserved.
3 * See COPYING.txt for license details.
4 */
5
6/**
7 * Sample configuration:
8 *
9 require.config({
10        "config": {
11            "baseUrlInterceptor": {
12                "Magento_Ui/js/lib/knockout/bindings/collapsible.js": "../../../../frontend/Magento/luma/en_US/"
13            }
14        }
15    });
16 */
17
18/* global jsSuffixRegExp */
19/* eslint-disable max-depth */
20define('baseUrlInterceptor', [
21    'module'
22], function (module) {
23    'use strict';
24
25    /**
26     * RequireJS Context object
27     */
28    var ctx = require.s.contexts._,
29
30        /**
31         * Original function
32         *
33         * @type {Function}
34         */
35        origNameToUrl = ctx.nameToUrl,
36
37        /**
38         * Original function
39         *
40         * @type {Function}
41         */
42        newContextConstr = require.s.newContext;
43
44    /**
45     * Remove dots from URL
46     *
47     * @param {Array} ary
48     */
49    function trimDots(ary) {
50        var i, part, length = ary.length;
51
52        for (i = 0; i < length; i++) {
53            part = ary[i];
54
55            if (part === '.') {
56                ary.splice(i, 1);
57                i -= 1;
58            } else if (part === '..') {
59                if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
60                    //End of the line. Keep at least one non-dot
61                    //path segment at the front so it can be mapped
62                    //correctly to disk. Otherwise, there is likely
63                    //no path mapping for a path starting with '..'.
64                    //This can still fail, but catches the most reasonable
65                    //uses of ..
66                    break;
67                } else if (i > 0) {
68                    ary.splice(i - 1, 2);
69                    i -= 2;
70                }
71            }
72        }
73    }
74
75    /**
76     * Normalize URL string (remove '/../')
77     *
78     * @param {String} name
79     * @param {String} baseName
80     * @param {Object} applyMap
81     * @param {Object} localContext
82     * @returns {*}
83     */
84    function normalize(name, baseName, applyMap, localContext) {
85        var lastIndex,
86            baseParts = baseName && baseName.split('/'),
87            normalizedBaseParts = baseParts;
88
89        //Adjust any relative paths.
90        if (name && name.charAt(0) === '.') {
91            //If have a base name, try to normalize against it,
92            //otherwise, assume it is a top-level require that will
93            //be relative to baseUrl in the end.
94            if (baseName) {
95                //Convert baseName to array, and lop off the last part,
96                //so that . matches that 'directory' and not name of the baseName's
97                //module. For instance, baseName of 'one/two/three', maps to
98                //'one/two/three.js', but we want the directory, 'one/two' for
99                //this normalization.
100                normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
101                name = name.split('/');
102                lastIndex = name.length - 1;
103
104                // If wanting node ID compatibility, strip .js from end
105                // of IDs. Have to do this here, and not in nameToUrl
106                // because node allows either .js or non .js to map
107                // to same file.
108                if (localContext.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
109                    name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
110                }
111
112                name = normalizedBaseParts.concat(name);
113                trimDots(name);
114                name = name.join('/');
115            } else if (name.indexOf('./') === 0) {
116                // No baseName, so this is ID is resolved relative
117                // to baseUrl, pull off the leading dot.
118                name = name.substring(2);
119            }
120        }
121
122        return name;
123    }
124
125    /**
126     * Get full url.
127     *
128     * @param {Object} context
129     * @param {String} url
130     * @return {String}
131     */
132    function getUrl(context, url) {
133        var baseUrl = context.config.baseUrl,
134            newConfig = context.config,
135            modulePath = url.replace(baseUrl, ''),
136            newBaseUrl,
137            rewrite = module.config()[modulePath];
138
139        if (!rewrite) {
140            return url;
141        }
142
143        newBaseUrl = normalize(rewrite, baseUrl, undefined, newConfig);
144
145        return newBaseUrl + modulePath;
146    }
147
148    /**
149     * Replace original function.
150     *
151     * @returns {*}
152     */
153    ctx.nameToUrl = function () {
154        return getUrl(ctx, origNameToUrl.apply(ctx, arguments));
155    };
156
157    /**
158     * Replace original function.
159     *
160     * @return {*}
161     */
162    require.s.newContext = function () {
163        var newCtx = newContextConstr.apply(require.s, arguments),
164            newOrigNameToUrl = newCtx.nameToUrl;
165
166        /**
167         * New implementation of native function.
168         *
169         * @returns {String}
170         */
171        newCtx.nameToUrl = function () {
172            return getUrl(newCtx, newOrigNameToUrl.apply(newCtx, arguments));
173        };
174
175        return newCtx;
176    };
177});
178
179require(['baseUrlInterceptor'], function () {
180    'use strict';
181
182});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.