@utoo/web 1.2.0-rc.2 → 1.2.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,217 +0,0 @@
1
- "use strict";
2
- const { type } = require("os");
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.errorFactory = errorFactory;
7
- exports.getLessImplementation = getLessImplementation;
8
- exports.getLessOptions = getLessOptions;
9
- exports.isUnsupportedUrl = isUnsupportedUrl;
10
- exports.normalizeSourceMap = normalizeSourceMap;
11
- var _path = _interopRequireDefault(require("path"));
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
- /* eslint-disable class-methods-use-this */
14
- const trailingSlash = /[/\\]$/;
15
- // This somewhat changed in Less 3.x. Now the file name comes without the
16
- // automatically added extension whereas the extension is passed in as `options.ext`.
17
- // So, if the file name matches this regexp, we simply ignore the proposed extension.
18
- const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/;
19
- // `[drive_letter]:\` + `\\[server]\[share_name]\`
20
- const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
21
- // Examples:
22
- // - ~package
23
- // - ~package/
24
- // - ~@org
25
- // - ~@org/
26
- // - ~@org/package
27
- // - ~@org/package/
28
- const IS_MODULE_IMPORT = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/;
29
- const MODULE_REQUEST_REGEX = /^[^?]*~/;
30
- /**
31
- * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext.
32
- *
33
- * @param {LoaderContext} loaderContext
34
- * @param {object} implementation
35
- * @returns {LessPlugin}
36
- */
37
- function createWebpackLessPlugin(loaderContext, implementation) {
38
- const lessOptions = loaderContext.getOptions();
39
- const resolve = loaderContext.getResolve({
40
- dependencyType: "less",
41
- conditionNames: ["less", "style", "..."],
42
- mainFields: ["less", "style", "main", "..."],
43
- mainFiles: ["index", "..."],
44
- extensions: [".less", ".css"],
45
- preferRelative: true
46
- });
47
- class WebpackFileManager extends implementation.FileManager {
48
- supports(filename) {
49
- if (filename[0] === "/" || IS_NATIVE_WIN32_PATH.test(filename)) {
50
- return true;
51
- }
52
- if (this.isPathAbsolute(filename)) {
53
- return false;
54
- }
55
- return true;
56
- }
57
- // Sync resolving is used at least by the `data-uri` function.
58
- // This file manager doesn't know how to do it, so let's delegate it
59
- // to the default file manager of Less.
60
- // We could probably use loaderContext.resolveSync, but it's deprecated,
61
- // see https://webpack.js.org/api/loaders/#this-resolvesync
62
- supportsSync() {
63
- return false;
64
- }
65
- async resolveFilename(filename, currentDirectory) {
66
- // Less is giving us trailing slashes, but the context should have no trailing slash
67
- const context = currentDirectory.replace(trailingSlash, "");
68
- let request = filename;
69
- // A `~` makes the url an module
70
- if (MODULE_REQUEST_REGEX.test(filename)) {
71
- request = request.replace(MODULE_REQUEST_REGEX, "");
72
- }
73
- if (IS_MODULE_IMPORT.test(filename)) {
74
- request = request[request.length - 1] === "/" ? request : `${request}/`;
75
- }
76
- return this.resolveRequests(context, [...new Set([request, filename])]);
77
- }
78
- async resolveRequests(context, possibleRequests) {
79
- if (possibleRequests.length === 0) {
80
- return Promise.reject();
81
- }
82
- let result;
83
- try {
84
- result = await resolve(context, possibleRequests[0]);
85
- }
86
- catch (error) {
87
- const [, ...tailPossibleRequests] = possibleRequests;
88
- if (tailPossibleRequests.length === 0) {
89
- throw error;
90
- }
91
- result = await this.resolveRequests(context, tailPossibleRequests);
92
- }
93
- return result;
94
- }
95
- async loadFile(filename, ...args) {
96
- let result;
97
- try {
98
- if (IS_SPECIAL_MODULE_IMPORT.test(filename) || lessOptions.webpackImporter === "only") {
99
- const error = new Error();
100
- error.type = "Next";
101
- throw error;
102
- }
103
- result = await super.loadFile(filename, ...args);
104
- }
105
- catch (error) {
106
- if (error.type !== "File" && error.type !== "Next") {
107
- return Promise.reject(error);
108
- }
109
- try {
110
- result = await this.resolveFilename(filename, ...args);
111
- }
112
- catch (webpackResolveError) {
113
- error.message = `Less resolver error:\n${error.message}\n\n` + `Webpack resolver error details:\n${webpackResolveError.details}\n\n` + `Webpack resolver error missing:\n${webpackResolveError.missing}\n\n`;
114
- return Promise.reject(error);
115
- }
116
- loaderContext.addDependency(result);
117
- return super.loadFile(result, ...args);
118
- }
119
- const absoluteFilename = _path.default.isAbsolute(result.filename) ? result.filename : _path.default.resolve(".", result.filename);
120
- loaderContext.addDependency(_path.default.normalize(absoluteFilename));
121
- return result;
122
- }
123
- }
124
- return {
125
- install(lessInstance, pluginManager) {
126
- pluginManager.addFileManager(new WebpackFileManager());
127
- },
128
- minVersion: [3, 0, 0]
129
- };
130
- }
131
- /**
132
- * Get the `less` options from the loader context and normalizes its values
133
- *
134
- * @param {object} loaderContext
135
- * @param {object} loaderOptions
136
- * @param {object} implementation
137
- * @returns {Object}
138
- */
139
- function getLessOptions(loaderContext, loaderOptions, implementation) {
140
- const options = typeof loaderOptions.lessOptions === "function" ? loaderOptions.lessOptions(loaderContext) || {} : loaderOptions.lessOptions || {};
141
- const lessOptions = {
142
- plugins: [],
143
- relativeUrls: true,
144
- // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
145
- filename: loaderContext.resourcePath,
146
- ...options
147
- };
148
- const plugins = lessOptions.plugins.slice();
149
- const shouldUseWebpackImporter = typeof loaderOptions.webpackImporter === "boolean" || loaderOptions.webpackImporter === "only" ? loaderOptions.webpackImporter : true;
150
- if (shouldUseWebpackImporter) {
151
- plugins.unshift(createWebpackLessPlugin(loaderContext, implementation));
152
- }
153
- plugins.unshift({
154
- install(lessProcessor, pluginManager) {
155
- // eslint-disable-next-line no-param-reassign
156
- pluginManager.webpackLoaderContext = loaderContext;
157
- lessOptions.pluginManager = pluginManager;
158
- }
159
- });
160
- lessOptions.plugins = plugins;
161
- return lessOptions;
162
- }
163
- function isUnsupportedUrl(url) {
164
- // Is Windows path
165
- if (IS_NATIVE_WIN32_PATH.test(url)) {
166
- return false;
167
- }
168
- // Scheme: https://tools.ietf.org/html/rfc3986#section-3.1
169
- // Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3
170
- return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url);
171
- }
172
- function normalizeSourceMap(map) {
173
- const newMap = map;
174
- // map.file is an optional property that provides the output filename.
175
- // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
176
- // eslint-disable-next-line no-param-reassign
177
- delete newMap.file;
178
- // eslint-disable-next-line no-param-reassign
179
- newMap.sourceRoot = "";
180
- // `less` returns POSIX paths, that's why we need to transform them back to native paths.
181
- // eslint-disable-next-line no-param-reassign
182
- newMap.sources = newMap.sources.map(source => _path.default.normalize(source));
183
- return newMap;
184
- }
185
- function getLessImplementation(loaderContext, implementation) {
186
- let resolvedImplementation = implementation;
187
- if (!implementation) {
188
- // eslint-disable-next-line import/no-dynamic-require, global-require
189
- resolvedImplementation = require("less/lib/less-node/index.js").default;
190
- }
191
- else if (typeof implementation === "string") {
192
- // eslint-disable-next-line import/no-dynamic-require, global-require
193
- resolvedImplementation = require(implementation);
194
- }
195
- // eslint-disable-next-line consistent-return
196
- return resolvedImplementation;
197
- }
198
- function getFileExcerptIfPossible(error) {
199
- if (typeof error.extract === "undefined") {
200
- return [];
201
- }
202
- const excerpt = error.extract.slice(0, 2);
203
- const column = Math.max(error.column - 1, 0);
204
- if (typeof excerpt[0] === "undefined") {
205
- excerpt.shift();
206
- }
207
- excerpt.push(`${new Array(column).join(" ")}^`);
208
- return excerpt;
209
- }
210
- function errorFactory(error) {
211
- const message = ["\n", ...getFileExcerptIfPossible(error), error.message.charAt(0).toUpperCase() + error.message.slice(1), error.filename ? ` Error in ${_path.default.normalize(error.filename)} (line ${error.line}, column ${error.column})` : ""].join("\n");
212
- const obj = new Error(message, {
213
- cause: error
214
- });
215
- obj.stack = null;
216
- return obj;
217
- }
@@ -1,2 +0,0 @@
1
- declare const fastGlob: any;
2
- export default fastGlob;
@@ -1,48 +0,0 @@
1
- import micromatch from "micromatch";
2
- import * as path from "path";
3
- import * as fs from "./fsPolyfill";
4
- const walkSync = (currentDir, rootDir, entries) => {
5
- let list;
6
- try {
7
- list = fs.readdirSync(currentDir, { withFileTypes: true });
8
- }
9
- catch (e) {
10
- return;
11
- }
12
- for (const entry of list) {
13
- const fullPath = path.join(currentDir, entry.name);
14
- const relativePath = path.relative(rootDir, fullPath);
15
- if (entry.isDirectory()) {
16
- walkSync(fullPath, rootDir, entries);
17
- }
18
- else if (entry.isFile()) {
19
- entries.push(relativePath);
20
- }
21
- }
22
- };
23
- const fastGlob = (patterns, options = {}) => {
24
- return Promise.resolve(fastGlob.sync(patterns, options));
25
- };
26
- fastGlob.sync = (patterns, options = {}) => {
27
- const cwd = options.cwd || "/";
28
- const ignore = options.ignore || [];
29
- const allFiles = [];
30
- walkSync(cwd, cwd, allFiles);
31
- const matched = micromatch(allFiles, patterns, {
32
- ignore: ignore,
33
- dot: options.dot,
34
- cwd: cwd,
35
- });
36
- if (options.absolute) {
37
- return matched.map((p) => path.join(cwd, p));
38
- }
39
- return matched;
40
- };
41
- fastGlob.stream = (patterns, options = {}) => {
42
- throw new Error("fastGlob.stream is not implemented in polyfill");
43
- };
44
- fastGlob.async = fastGlob;
45
- fastGlob.generateTasks = () => [];
46
- fastGlob.isDynamicPattern = (p) => micromatch.scan(p).isGlob;
47
- fastGlob.escapePath = (p) => p.replace(/([*?|(){}[\]])/g, "\\$1");
48
- export default fastGlob;