source: trip-planner-front/node_modules/style-loader/dist/utils.js@ 84d0fbb

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

initial commit

  • Property mode set to 100644
File size: 10.7 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.stringifyRequest = stringifyRequest;
7exports.getImportInsertStyleElementCode = getImportInsertStyleElementCode;
8exports.getImportInsertBySelectorCode = getImportInsertBySelectorCode;
9exports.getImportStyleContentCode = getImportStyleContentCode;
10exports.getImportStyleDomAPICode = getImportStyleDomAPICode;
11exports.getImportStyleAPICode = getImportStyleAPICode;
12exports.getImportLinkContentCode = getImportLinkContentCode;
13exports.getImportLinkAPICode = getImportLinkAPICode;
14exports.getStyleHmrCode = getStyleHmrCode;
15exports.getLinkHmrCode = getLinkHmrCode;
16exports.getdomAPI = getdomAPI;
17exports.getImportIsOldIECode = getImportIsOldIECode;
18exports.getStyleTagTransformFn = getStyleTagTransformFn;
19exports.getExportStyleCode = getExportStyleCode;
20exports.getExportLazyStyleCode = getExportLazyStyleCode;
21exports.getSetAttributesCode = getSetAttributesCode;
22exports.getInsertOptionCode = getInsertOptionCode;
23exports.getStyleTagTransformFnCode = getStyleTagTransformFnCode;
24
25var _path = _interopRequireDefault(require("path"));
26
27var _isEqualLocals = _interopRequireDefault(require("./runtime/isEqualLocals"));
28
29function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
31const matchRelativePath = /^\.\.?[/\\]/;
32
33function isAbsolutePath(str) {
34 return _path.default.posix.isAbsolute(str) || _path.default.win32.isAbsolute(str);
35}
36
37function isRelativePath(str) {
38 return matchRelativePath.test(str);
39}
40
41function stringifyRequest(loaderContext, request) {
42 const splitted = request.split("!");
43 const {
44 context
45 } = loaderContext;
46 return JSON.stringify(splitted.map(part => {
47 // First, separate singlePath from query, because the query might contain paths again
48 const splittedPart = part.match(/^(.*?)(\?.*)/);
49 const query = splittedPart ? splittedPart[2] : "";
50 let singlePath = splittedPart ? splittedPart[1] : part;
51
52 if (isAbsolutePath(singlePath) && context) {
53 singlePath = _path.default.relative(context, singlePath);
54
55 if (isAbsolutePath(singlePath)) {
56 // If singlePath still matches an absolute path, singlePath was on a different drive than context.
57 // In this case, we leave the path platform-specific without replacing any separators.
58 // @see https://github.com/webpack/loader-utils/pull/14
59 return singlePath + query;
60 }
61
62 if (isRelativePath(singlePath) === false) {
63 // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
64 singlePath = `./${singlePath}`;
65 }
66 }
67
68 return singlePath.replace(/\\/g, "/") + query;
69 }).join("!"));
70}
71
72function getImportLinkAPICode(esModule, loaderContext) {
73 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/injectStylesIntoLinkTag.js")}`);
74 return esModule ? `import API from ${modulePath};` : `var API = require(${modulePath});`;
75}
76
77function getImportLinkContentCode(esModule, loaderContext, request) {
78 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
79 return esModule ? `import content from ${modulePath};` : `var content = require(${modulePath});`;
80}
81
82function getImportStyleAPICode(esModule, loaderContext) {
83 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/injectStylesIntoStyleTag.js")}`);
84 return esModule ? `import API from ${modulePath};` : `var API = require(${modulePath});`;
85}
86
87function getImportStyleDomAPICode(esModule, loaderContext, isSingleton, isAuto) {
88 const styleAPI = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/styleDomAPI.js")}`);
89 const singletonAPI = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/singletonStyleDomAPI.js")}`);
90
91 if (isAuto) {
92 return esModule ? `import domAPI from ${styleAPI};
93 import domAPISingleton from ${singletonAPI};` : `var domAPI = require(${styleAPI});
94 var domAPISingleton = require(${singletonAPI});`;
95 }
96
97 return esModule ? `import domAPI from ${isSingleton ? singletonAPI : styleAPI};` : `var domAPI = require(${isSingleton ? singletonAPI : styleAPI});`;
98}
99
100function getImportStyleContentCode(esModule, loaderContext, request) {
101 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
102 return esModule ? `import content, * as namedExport from ${modulePath};` : `var content = require(${modulePath});`;
103}
104
105function getImportInsertBySelectorCode(esModule, loaderContext, insertType, options) {
106 if (insertType === "selector") {
107 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/insertBySelector.js")}`);
108 return esModule ? `import insertFn from ${modulePath};` : `var insertFn = require(${modulePath});`;
109 }
110
111 if (insertType === "module-path") {
112 const modulePath = stringifyRequest(loaderContext, `${options.insert}`);
113 loaderContext.addBuildDependency(options.insert);
114 return esModule ? `import insertFn from ${modulePath};` : `var insertFn = require(${modulePath});`;
115 }
116
117 return "";
118}
119
120function getInsertOptionCode(insertType, options) {
121 if (insertType === "selector") {
122 const insert = options.insert ? JSON.stringify(options.insert) : '"head"';
123 return `
124 options.insert = insertFn.bind(null, ${insert});
125 `;
126 }
127
128 if (insertType === "module-path") {
129 return `options.insert = insertFn;`;
130 } // Todo remove "function" type for insert option in next major release, because code duplication occurs. Leave require.resolve()
131
132
133 return `options.insert = ${options.insert.toString()};`;
134}
135
136function getImportInsertStyleElementCode(esModule, loaderContext) {
137 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/insertStyleElement.js")}`);
138 return esModule ? `import insertStyleElement from ${modulePath};` : `var insertStyleElement = require(${modulePath});`;
139}
140
141function getStyleHmrCode(esModule, loaderContext, request, lazy) {
142 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
143 return `
144if (module.hot) {
145 if (!content.locals || module.hot.invalidate) {
146 var isEqualLocals = ${_isEqualLocals.default.toString()};
147 var isNamedExport = ${esModule ? "!content.locals" : false};
148 var oldLocals = isNamedExport ? namedExport : content.locals;
149
150 module.hot.accept(
151 ${modulePath},
152 function () {
153 ${esModule ? `if (!isEqualLocals(oldLocals, isNamedExport ? namedExport : content.locals, isNamedExport)) {
154 module.hot.invalidate();
155
156 return;
157 }
158
159 oldLocals = isNamedExport ? namedExport : content.locals;
160
161 ${lazy ? `if (update && refs > 0) {
162 update(content);
163 }` : `update(content);`}` : `content = require(${modulePath});
164
165 content = content.__esModule ? content.default : content;
166
167 ${lazy ? "" : `if (typeof content === 'string') {
168 content = [[module.id, content, '']];
169 }`}
170
171 if (!isEqualLocals(oldLocals, content.locals)) {
172 module.hot.invalidate();
173
174 return;
175 }
176
177 oldLocals = content.locals;
178
179 ${lazy ? `if (update && refs > 0) {
180 update(content);
181 }` : `update(content);`}`}
182 }
183 )
184 }
185
186 module.hot.dispose(function() {
187 ${lazy ? `if (update) {
188 update();
189 }` : `update();`}
190 });
191}
192`;
193}
194
195function getLinkHmrCode(esModule, loaderContext, request) {
196 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
197 return `
198if (module.hot) {
199 module.hot.accept(
200 ${modulePath},
201 function() {
202 ${esModule ? "update(content);" : `content = require(${modulePath});
203
204 content = content.__esModule ? content.default : content;
205
206 update(content);`}
207 }
208 );
209
210 module.hot.dispose(function() {
211 update();
212 });
213}`;
214}
215
216function getdomAPI(isAuto) {
217 return isAuto ? "isOldIE() ? domAPISingleton : domAPI" : "domAPI";
218}
219
220function getImportIsOldIECode(esModule, loaderContext) {
221 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/isOldIE.js")}`);
222 return esModule ? `import isOldIE from ${modulePath};` : `var isOldIE = require(${modulePath});`;
223}
224
225function getStyleTagTransformFnCode(esModule, loaderContext, options, isSingleton, styleTagTransformType) {
226 if (isSingleton) {
227 return "";
228 }
229
230 if (styleTagTransformType === "default") {
231 const modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/styleTagTransform.js")}`);
232 return esModule ? `import styleTagTransformFn from ${modulePath};` : `var styleTagTransformFn = require(${modulePath});`;
233 }
234
235 if (styleTagTransformType === "module-path") {
236 const modulePath = stringifyRequest(loaderContext, `${options.styleTagTransform}`);
237 loaderContext.addBuildDependency(options.styleTagTransform);
238 return esModule ? `import styleTagTransformFn from ${modulePath};` : `var styleTagTransformFn = require(${modulePath});`;
239 }
240
241 return "";
242}
243
244function getStyleTagTransformFn(options, isSingleton) {
245 // Todo remove "function" type for styleTagTransform option in next major release, because code duplication occurs. Leave require.resolve()
246 return isSingleton ? "" : typeof options.styleTagTransform === "function" ? `options.styleTagTransform = ${options.styleTagTransform.toString()}` : `options.styleTagTransform = styleTagTransformFn`;
247}
248
249function getExportStyleCode(esModule, loaderContext, request) {
250 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
251 return esModule ? `export * from ${modulePath};
252 export default content && content.locals ? content.locals : undefined;` : "module.exports = content && content.locals || {};";
253}
254
255function getExportLazyStyleCode(esModule, loaderContext, request) {
256 const modulePath = stringifyRequest(loaderContext, `!!${request}`);
257 return esModule ? `export * from ${modulePath};
258 export default exported;` : "module.exports = exported;";
259}
260
261function getSetAttributesCode(esModule, loaderContext, options) {
262 let modulePath;
263
264 if (typeof options.attributes !== "undefined") {
265 modulePath = options.attributes.nonce !== "undefined" ? stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/setAttributesWithAttributesAndNonce.js")}`) : stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/setAttributesWithAttributes.js")}`);
266 } else {
267 modulePath = stringifyRequest(loaderContext, `!${_path.default.join(__dirname, "runtime/setAttributesWithoutAttributes.js")}`);
268 }
269
270 return esModule ? `import setAttributes from ${modulePath};` : `var setAttributes = require(${modulePath});`;
271} // eslint-disable-next-line import/prefer-default-export
Note: See TracBrowser for help on using the repository browser.