less 4.9.1 → 5.0.0-alpha.10

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.
Files changed (134) hide show
  1. package/README.md +23 -5
  2. package/V5-STATUS.md +71 -0
  3. package/bin/lessc +302 -626
  4. package/dist/less-browser-dev.js +2550 -0
  5. package/dist/less-node.cjs +480 -14561
  6. package/index.cjs +5 -2
  7. package/lib/browser-dev.js +86 -0
  8. package/lib/index.js +164 -0
  9. package/lib/lessc-helper.js +64 -0
  10. package/lib/logger.js +76 -0
  11. package/lib/options.d.ts +82 -0
  12. package/lib/options.js +227 -0
  13. package/lib/types.js +20 -0
  14. package/lib/version.js +19 -0
  15. package/package.json +36 -40
  16. package/dist/less.cjs +0 -15218
  17. package/dist/less.js +0 -15218
  18. package/dist/less.min.js +0 -11
  19. package/dist/less.min.js.map +0 -1
  20. package/lib/less/constants.js +0 -13
  21. package/lib/less/contexts.js +0 -165
  22. package/lib/less/data/colors.js +0 -150
  23. package/lib/less/data/index.js +0 -4
  24. package/lib/less/data/unit-conversions.js +0 -21
  25. package/lib/less/default-options.js +0 -89
  26. package/lib/less/deprecation.js +0 -82
  27. package/lib/less/environment/abstract-file-manager.js +0 -140
  28. package/lib/less/environment/abstract-plugin-loader.js +0 -185
  29. package/lib/less/environment/environment-api.ts +0 -21
  30. package/lib/less/environment/environment.js +0 -59
  31. package/lib/less/environment/file-manager-api.ts +0 -77
  32. package/lib/less/functions/boolean.js +0 -29
  33. package/lib/less/functions/color-blending.js +0 -85
  34. package/lib/less/functions/color.js +0 -452
  35. package/lib/less/functions/data-uri.js +0 -74
  36. package/lib/less/functions/default.js +0 -26
  37. package/lib/less/functions/function-caller.js +0 -55
  38. package/lib/less/functions/function-registry.js +0 -36
  39. package/lib/less/functions/index.js +0 -35
  40. package/lib/less/functions/list.js +0 -158
  41. package/lib/less/functions/math-helper.js +0 -22
  42. package/lib/less/functions/math.js +0 -30
  43. package/lib/less/functions/number.js +0 -95
  44. package/lib/less/functions/string.js +0 -39
  45. package/lib/less/functions/style.js +0 -29
  46. package/lib/less/functions/svg.js +0 -87
  47. package/lib/less/functions/types.js +0 -70
  48. package/lib/less/import-manager.js +0 -183
  49. package/lib/less/index.js +0 -95
  50. package/lib/less/less-error.js +0 -166
  51. package/lib/less/logger.js +0 -34
  52. package/lib/less/parse-tree.js +0 -124
  53. package/lib/less/parse.js +0 -87
  54. package/lib/less/parser/lookup-pattern.js +0 -26
  55. package/lib/less/parser/parser-input.js +0 -400
  56. package/lib/less/parser/parser.js +0 -2998
  57. package/lib/less/plugin-manager.js +0 -168
  58. package/lib/less/render.js +0 -41
  59. package/lib/less/source-map-builder.js +0 -82
  60. package/lib/less/source-map-output.js +0 -151
  61. package/lib/less/transform-tree.js +0 -102
  62. package/lib/less/tree/anonymous.js +0 -61
  63. package/lib/less/tree/assignment.js +0 -48
  64. package/lib/less/tree/atrule-syntax.js +0 -8
  65. package/lib/less/tree/atrule.js +0 -340
  66. package/lib/less/tree/attribute.js +0 -63
  67. package/lib/less/tree/call.js +0 -132
  68. package/lib/less/tree/color.js +0 -285
  69. package/lib/less/tree/combinator.js +0 -38
  70. package/lib/less/tree/comment.js +0 -48
  71. package/lib/less/tree/condition.js +0 -65
  72. package/lib/less/tree/container.js +0 -104
  73. package/lib/less/tree/debug-info.js +0 -80
  74. package/lib/less/tree/declaration.js +0 -142
  75. package/lib/less/tree/detached-ruleset.js +0 -45
  76. package/lib/less/tree/dimension.js +0 -215
  77. package/lib/less/tree/element.js +0 -93
  78. package/lib/less/tree/expression.js +0 -100
  79. package/lib/less/tree/extend.js +0 -88
  80. package/lib/less/tree/import.js +0 -299
  81. package/lib/less/tree/index.js +0 -56
  82. package/lib/less/tree/interpolated-variable.js +0 -106
  83. package/lib/less/tree/javascript.js +0 -45
  84. package/lib/less/tree/js-eval-node.js +0 -80
  85. package/lib/less/tree/keyword.js +0 -28
  86. package/lib/less/tree/media.js +0 -90
  87. package/lib/less/tree/merge-rules.js +0 -47
  88. package/lib/less/tree/mixin-call.js +0 -283
  89. package/lib/less/tree/mixin-definition.js +0 -319
  90. package/lib/less/tree/namespace-value.js +0 -95
  91. package/lib/less/tree/negative.js +0 -37
  92. package/lib/less/tree/nested-at-rule.js +0 -239
  93. package/lib/less/tree/node.js +0 -310
  94. package/lib/less/tree/operation.js +0 -81
  95. package/lib/less/tree/paren.js +0 -41
  96. package/lib/less/tree/property.js +0 -96
  97. package/lib/less/tree/query-in-parens.js +0 -64
  98. package/lib/less/tree/quoted.js +0 -131
  99. package/lib/less/tree/ruleset.js +0 -1068
  100. package/lib/less/tree/selector.js +0 -201
  101. package/lib/less/tree/unicode-descriptor.js +0 -14
  102. package/lib/less/tree/unit.js +0 -170
  103. package/lib/less/tree/url.js +0 -83
  104. package/lib/less/tree/value.js +0 -60
  105. package/lib/less/tree/variable-call.js +0 -60
  106. package/lib/less/tree/variable.js +0 -85
  107. package/lib/less/utils.js +0 -126
  108. package/lib/less/visitors/extend-visitor.js +0 -505
  109. package/lib/less/visitors/import-sequencer.js +0 -56
  110. package/lib/less/visitors/import-visitor.js +0 -203
  111. package/lib/less/visitors/index.js +0 -15
  112. package/lib/less/visitors/join-selector-visitor.js +0 -65
  113. package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
  114. package/lib/less/visitors/to-css-visitor.js +0 -332
  115. package/lib/less/visitors/visitor.js +0 -165
  116. package/lib/less-browser/add-default-options.js +0 -53
  117. package/lib/less-browser/bootstrap.js +0 -67
  118. package/lib/less-browser/browser.js +0 -65
  119. package/lib/less-browser/cache.js +0 -43
  120. package/lib/less-browser/error-reporting.js +0 -170
  121. package/lib/less-browser/file-manager.js +0 -112
  122. package/lib/less-browser/image-size.js +0 -28
  123. package/lib/less-browser/index.js +0 -284
  124. package/lib/less-browser/log-listener.js +0 -42
  125. package/lib/less-browser/plugin-loader.js +0 -24
  126. package/lib/less-browser/utils.js +0 -30
  127. package/lib/less-node/environment.js +0 -43
  128. package/lib/less-node/file-manager.js +0 -156
  129. package/lib/less-node/fs.js +0 -14
  130. package/lib/less-node/image-size.js +0 -78
  131. package/lib/less-node/index.js +0 -31
  132. package/lib/less-node/lessc-helper.js +0 -95
  133. package/lib/less-node/plugin-loader.js +0 -62
  134. package/lib/less-node/url-file-manager.js +0 -60
@@ -1,28 +0,0 @@
1
-
2
- import functionRegistry from './../less/functions/function-registry.js';
3
-
4
- export default () => {
5
- function imageSize() {
6
- throw {
7
- type: 'Runtime',
8
- message: 'Image size functions are not supported in browser version of less'
9
- };
10
- }
11
-
12
- const imageFunctions = {
13
- 'image-size': function(filePathNode) {
14
- imageSize(this, filePathNode);
15
- return -1;
16
- },
17
- 'image-width': function(filePathNode) {
18
- imageSize(this, filePathNode);
19
- return -1;
20
- },
21
- 'image-height': function(filePathNode) {
22
- imageSize(this, filePathNode);
23
- return -1;
24
- }
25
- };
26
-
27
- functionRegistry.addMultiple(imageFunctions);
28
- };
@@ -1,284 +0,0 @@
1
- //
2
- // index.js
3
- // Should expose the additional browser functions on to the less object
4
- //
5
- import {addDataAttr} from './utils.js';
6
- import lessRoot from '../less/index.js';
7
- import browser from './browser.js';
8
- import FM from './file-manager.js';
9
- import PluginLoader from './plugin-loader.js';
10
- import LogListener from './log-listener.js';
11
- import ErrorReporting from './error-reporting.js';
12
- import Cache from './cache.js';
13
- import ImageSize from './image-size.js';
14
- import pkg from '../../package.json';
15
-
16
- /**
17
- * @param {Window} window
18
- * @param {Object} options
19
- */
20
- export default (window, options) => {
21
- const document = window.document;
22
- const less = lessRoot(undefined, undefined, pkg.version);
23
-
24
- less.options = options;
25
- const environment = less.environment;
26
- const FileManager = FM(options, less.logger);
27
- const fileManager = new FileManager();
28
- environment.addFileManager(fileManager);
29
- less.FileManager = FileManager;
30
- less.PluginLoader = PluginLoader;
31
-
32
- LogListener(less, options);
33
- const errors = ErrorReporting(window, less, options);
34
- const cache = less.cache = options.cache || Cache(window, options, less.logger);
35
- ImageSize(less.environment);
36
-
37
- // Setup user functions - Deprecate?
38
- if (options.functions) {
39
- less.functions.functionRegistry.addMultiple(options.functions);
40
- }
41
-
42
- const typePattern = /^text\/(x-)?less$/;
43
-
44
- function clone(obj) {
45
- const cloned = {};
46
- for (const prop in obj) {
47
- if (Object.prototype.hasOwnProperty.call(obj, prop)) {
48
- cloned[prop] = obj[prop];
49
- }
50
- }
51
- return cloned;
52
- }
53
-
54
- function loadStyles(modifyVars) {
55
- const styles = document.getElementsByTagName('style');
56
-
57
- for (let style of styles) {
58
- if (style.type.match(typePattern)) {
59
- const instanceOptions = {
60
- ...clone(options),
61
- modifyVars,
62
- filename: document.location.href.replace(/#.*$/, '')
63
- }
64
-
65
- const lessText = style.innerHTML || '';
66
-
67
- /* jshint loopfunc:true */
68
- less.render(lessText, instanceOptions, (err, result) => {
69
- if (err) {
70
- errors.add(err, 'inline');
71
- } else {
72
- style.type = 'text/css';
73
- if (style.styleSheet) {
74
- style.styleSheet.cssText = result.css;
75
- } else {
76
- style.innerHTML = result.css;
77
- }
78
- }
79
- });
80
- }
81
- }
82
- }
83
-
84
- function loadStyleSheet(sheet, callback, reload, remaining, modifyVars) {
85
-
86
- const instanceOptions = clone(options);
87
- addDataAttr(instanceOptions, sheet);
88
- instanceOptions.mime = sheet.type;
89
-
90
- if (modifyVars) {
91
- instanceOptions.modifyVars = modifyVars;
92
- }
93
-
94
- function loadInitialFileCallback(loadedFile) {
95
- const data = loadedFile.contents;
96
- const path = loadedFile.filename;
97
- const webInfo = loadedFile.webInfo;
98
-
99
- const newFileInfo = {
100
- currentDirectory: fileManager.getPath(path),
101
- filename: path,
102
- rootFilename: path,
103
- rewriteUrls: instanceOptions.rewriteUrls
104
- };
105
-
106
- newFileInfo.entryPath = newFileInfo.currentDirectory;
107
- newFileInfo.rootpath = instanceOptions.rootpath || newFileInfo.currentDirectory;
108
-
109
- if (webInfo) {
110
- webInfo.remaining = remaining;
111
-
112
- const css = cache.getCSS(path, webInfo, instanceOptions.modifyVars);
113
- if (!reload && css) {
114
- webInfo.local = true;
115
- callback(null, css, data, sheet, webInfo, path);
116
- return;
117
- }
118
-
119
- }
120
-
121
- // TODO add tests around how this behaves when reloading
122
- errors.remove(path);
123
-
124
- instanceOptions.rootFileInfo = newFileInfo;
125
- less.render(data, instanceOptions, (e, result) => {
126
- if (e) {
127
- e.href = path;
128
- callback(e);
129
- } else {
130
- cache.setCSS(sheet.href, webInfo.lastModified, instanceOptions.modifyVars, result.css);
131
- callback(null, result.css, data, sheet, webInfo, path);
132
- }
133
- });
134
- }
135
-
136
- fileManager.loadFile(sheet.href, null, instanceOptions, environment)
137
- .then(loadedFile => {
138
- loadInitialFileCallback(loadedFile);
139
- }).catch(err => {
140
- console.log(err);
141
- callback(err);
142
- });
143
-
144
- }
145
-
146
- function loadStyleSheets(callback, reload, modifyVars) {
147
- for (let i = 0; i < less.sheets.length; i++) {
148
- loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), modifyVars);
149
- }
150
- }
151
-
152
- function initRunningMode() {
153
- if (less.env === 'development') {
154
- less.watchTimer = setInterval(() => {
155
- if (less.watchMode) {
156
- fileManager.clearFileCache();
157
- /**
158
- * @todo remove when this is typed with JSDoc
159
- */
160
- // eslint-disable-next-line no-unused-vars
161
- loadStyleSheets((e, css, _, sheet, webInfo) => {
162
- if (e) {
163
- errors.add(e, e.href || sheet.href);
164
- } else if (css) {
165
- browser.createCSS(window.document, css, sheet);
166
- }
167
- });
168
- }
169
- }, options.poll);
170
- }
171
- }
172
-
173
- //
174
- // Watch mode
175
- //
176
- less.watch = function () {
177
- if (!less.watchMode ) {
178
- less.env = 'development';
179
- initRunningMode();
180
- }
181
- this.watchMode = true;
182
- return true;
183
- };
184
-
185
- less.unwatch = function () {clearInterval(less.watchTimer); this.watchMode = false; return false; };
186
-
187
- //
188
- // Synchronously get all <link> tags with the 'rel' attribute set to
189
- // "stylesheet/less".
190
- //
191
- less.registerStylesheetsImmediately = () => {
192
- const links = document.getElementsByTagName('link');
193
- less.sheets = [];
194
-
195
- for (let i = 0; i < links.length; i++) {
196
- if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
197
- (links[i].type.match(typePattern)))) {
198
- less.sheets.push(links[i]);
199
- }
200
- }
201
- };
202
-
203
- //
204
- // Asynchronously get all <link> tags with the 'rel' attribute set to
205
- // "stylesheet/less", returning a Promise.
206
- //
207
- less.registerStylesheets = () => new Promise((resolve) => {
208
- less.registerStylesheetsImmediately();
209
- resolve();
210
- });
211
-
212
- //
213
- // With this function, it's possible to alter variables and re-render
214
- // CSS without reloading less-files
215
- //
216
- less.modifyVars = record => less.refresh(true, record, false);
217
-
218
- less.refresh = (reload, modifyVars, clearFileCache) => {
219
- if ((reload || clearFileCache) && clearFileCache !== false) {
220
- fileManager.clearFileCache();
221
- }
222
- return new Promise((resolve, reject) => {
223
- let startTime;
224
- let endTime;
225
- let totalMilliseconds;
226
- let remainingSheets;
227
- startTime = endTime = new Date();
228
-
229
- // Set counter for remaining unprocessed sheets
230
- remainingSheets = less.sheets.length;
231
-
232
- if (remainingSheets === 0) {
233
-
234
- endTime = new Date();
235
- totalMilliseconds = endTime - startTime;
236
- less.logger.info('Less has finished and no sheets were loaded.');
237
- resolve({
238
- startTime,
239
- endTime,
240
- totalMilliseconds,
241
- sheets: less.sheets.length
242
- });
243
-
244
- } else {
245
- // Relies on less.sheets array, callback seems to be guaranteed to be called for every element of the array
246
- loadStyleSheets((e, css, _, sheet, webInfo) => {
247
- if (e) {
248
- errors.add(e, e.href || sheet.href);
249
- reject(e);
250
- return;
251
- }
252
- if (webInfo.local) {
253
- less.logger.info(`Loading ${sheet.href} from cache.`);
254
- } else {
255
- less.logger.info(`Rendered ${sheet.href} successfully.`);
256
- }
257
- browser.createCSS(window.document, css, sheet);
258
- less.logger.info(`CSS for ${sheet.href} generated in ${new Date() - endTime}ms`);
259
-
260
- // Count completed sheet
261
- remainingSheets--;
262
-
263
- // Check if the last remaining sheet was processed and then call the promise
264
- if (remainingSheets === 0) {
265
- totalMilliseconds = new Date() - startTime;
266
- less.logger.info(`Less has finished. CSS generated in ${totalMilliseconds}ms`);
267
- resolve({
268
- startTime,
269
- endTime,
270
- totalMilliseconds,
271
- sheets: less.sheets.length
272
- });
273
- }
274
- endTime = new Date();
275
- }, reload, modifyVars);
276
- }
277
-
278
- loadStyles(modifyVars);
279
- });
280
- };
281
-
282
- less.refreshStyles = loadStyles;
283
- return less;
284
- };
@@ -1,42 +0,0 @@
1
- export default (less, options) => {
2
- const logLevel_debug = 4;
3
- const logLevel_info = 3;
4
- const logLevel_warn = 2;
5
- const logLevel_error = 1;
6
-
7
- // The amount of logging in the javascript console.
8
- // 3 - Debug, information and errors
9
- // 2 - Information and errors
10
- // 1 - Errors
11
- // 0 - None
12
- // Defaults to 2
13
- options.logLevel = typeof options.logLevel !== 'undefined' ? options.logLevel : (options.env === 'development' ? logLevel_info : logLevel_error);
14
-
15
- if (!options.loggers) {
16
- options.loggers = [{
17
- debug: function(msg) {
18
- if (options.logLevel >= logLevel_debug) {
19
- console.log(msg);
20
- }
21
- },
22
- info: function(msg) {
23
- if (options.logLevel >= logLevel_info) {
24
- console.log(msg);
25
- }
26
- },
27
- warn: function(msg) {
28
- if (options.logLevel >= logLevel_warn) {
29
- console.warn(msg);
30
- }
31
- },
32
- error: function(msg) {
33
- if (options.logLevel >= logLevel_error) {
34
- console.error(msg);
35
- }
36
- }
37
- }];
38
- }
39
- for (let i = 0; i < options.loggers.length; i++) {
40
- less.logger.addListener(options.loggers[i]);
41
- }
42
- };
@@ -1,24 +0,0 @@
1
- /**
2
- * @todo Add tests for browser `@plugin`
3
- */
4
- import AbstractPluginLoader from '../less/environment/abstract-plugin-loader.js';
5
-
6
- /**
7
- * Browser Plugin Loader
8
- */
9
- const PluginLoader = function(less) {
10
- this.less = less;
11
- // Should we shim this.require for browser? Probably not?
12
- };
13
-
14
- PluginLoader.prototype = Object.assign(new AbstractPluginLoader(), {
15
- loadPlugin(filename, basePath, context, environment, fileManager) {
16
- return new Promise((fulfill, reject) => {
17
- fileManager.loadFile(filename, basePath, context, environment)
18
- .then(fulfill).catch(reject);
19
- });
20
- }
21
- });
22
-
23
- export default PluginLoader;
24
-
@@ -1,30 +0,0 @@
1
-
2
- /** @param {string} href */
3
- export function extractId(href) {
4
- return href.replace(/^[a-z-]+:\/+?[^/]+/, '') // Remove protocol & domain
5
- .replace(/[?&]livereload=\w+/, '') // Remove LiveReload cachebuster
6
- .replace(/^\//, '') // Remove root /
7
- .replace(/\.[a-zA-Z]+$/, '') // Remove simple extension
8
- .replace(/[^.\w-]+/g, '-') // Replace illegal characters
9
- .replace(/\./g, ':'); // Replace dots with colons(for valid id)
10
- }
11
-
12
- /**
13
- * @param {Record<string, *>} options
14
- * @param {HTMLElement | null} tag
15
- */
16
- export function addDataAttr(options, tag) {
17
- if (!tag) {return;} // in case of tag is null or undefined
18
- for (const opt in tag.dataset) {
19
- if (Object.prototype.hasOwnProperty.call(tag.dataset, opt)) {
20
- if (opt === 'env' || opt === 'dumpLineNumbers' || opt === 'rootpath' || opt === 'errorReporting') {
21
- options[opt] = tag.dataset[opt];
22
- } else {
23
- try {
24
- options[opt] = JSON.parse(tag.dataset[opt]);
25
- }
26
- catch (_) {}
27
- }
28
- }
29
- }
30
- }
@@ -1,43 +0,0 @@
1
- import { createRequire } from 'module';
2
-
3
- const require = createRequire(import.meta.url);
4
-
5
- class SourceMapGeneratorFallback {
6
- addMapping(){}
7
- setSourceContent(){}
8
- toJSON(){
9
- return null;
10
- }
11
- }
12
-
13
- export default {
14
- encodeBase64: function encodeBase64(str) {
15
- // Avoid Buffer constructor on newer versions of Node.js.
16
- const buffer = (Buffer.from ? Buffer.from(str) : (new Buffer(str)));
17
- return buffer.toString('base64');
18
- },
19
- mimeLookup: function (filename) {
20
- try {
21
- const mimeModule = require('mime');
22
- return mimeModule ? mimeModule.lookup(filename) : 'application/octet-stream';
23
- } catch (e) {
24
- return 'application/octet-stream';
25
- }
26
- },
27
- charsetLookup: function (mime) {
28
- try {
29
- const mimeModule = require('mime');
30
- return mimeModule ? mimeModule.charsets.lookup(mime) : undefined;
31
- } catch (e) {
32
- return undefined;
33
- }
34
- },
35
- getSourceMapGenerator: function getSourceMapGenerator() {
36
- try {
37
- const sourceMapModule = require('source-map');
38
- return sourceMapModule ? sourceMapModule.SourceMapGenerator : SourceMapGeneratorFallback;
39
- } catch (e) {
40
- return SourceMapGeneratorFallback;
41
- }
42
- }
43
- };
@@ -1,156 +0,0 @@
1
- import path from 'path';
2
- import { createRequire } from 'module';
3
- import fs from './fs.js';
4
- import AbstractFileManager from '../less/environment/abstract-file-manager.js';
5
-
6
- const require = createRequire(import.meta.url);
7
-
8
- const FileManager = function() {}
9
- FileManager.prototype = Object.assign(new AbstractFileManager(), {
10
- supports() {
11
- return true;
12
- },
13
-
14
- supportsSync() {
15
- return true;
16
- },
17
-
18
- loadFile(filename, currentDirectory, options, environment, callback) {
19
- let fullFilename;
20
- const isAbsoluteFilename = this.isPathAbsolute(filename);
21
- const filenamesTried = [];
22
- const self = this;
23
- const prefix = filename.slice(0, 1);
24
- const explicit = prefix === '.' || prefix === '/';
25
- let result = null;
26
- let isNodeModule = false;
27
- const npmPrefix = 'npm://';
28
-
29
- options = options || {};
30
-
31
- const paths = isAbsoluteFilename ? [''] : [currentDirectory];
32
-
33
- if (options.paths) { paths.push.apply(paths, options.paths); }
34
-
35
- if (!isAbsoluteFilename && paths.indexOf('.') === -1) { paths.push('.'); }
36
-
37
- const prefixes = options.prefixes || [''];
38
- const fileParts = this.extractUrlParts(filename);
39
-
40
- if (options.syncImport) {
41
- getFileData(returnData, returnData);
42
- if (callback) {
43
- callback(result.error, result);
44
- }
45
- else {
46
- return result;
47
- }
48
- }
49
- else {
50
- // promise is guaranteed to be asyncronous
51
- // which helps as it allows the file handle
52
- // to be closed before it continues with the next file
53
- return new Promise(getFileData);
54
- }
55
-
56
- function returnData(data) {
57
- if (!data.filename) {
58
- result = { error: data };
59
- }
60
- else {
61
- result = data;
62
- }
63
- }
64
-
65
- function getFileData(fulfill, reject) {
66
- (function tryPathIndex(i) {
67
- function tryWithExtension() {
68
- const extFilename = options.ext ? self.tryAppendExtension(fullFilename, options.ext) : fullFilename;
69
-
70
- if (extFilename !== fullFilename && !explicit && paths[i] === '.') {
71
- try {
72
- fullFilename = require.resolve(extFilename);
73
- isNodeModule = true;
74
- }
75
- catch (e) {
76
- filenamesTried.push(npmPrefix + extFilename);
77
- fullFilename = extFilename;
78
- }
79
- }
80
- else {
81
- fullFilename = extFilename;
82
- }
83
- }
84
- if (i < paths.length) {
85
- (function tryPrefix(j) {
86
- if (j < prefixes.length) {
87
- isNodeModule = false;
88
- fullFilename = fileParts.rawPath + prefixes[j] + fileParts.filename;
89
-
90
- if (paths[i]) {
91
- if (paths[i].startsWith('#')) {
92
- // Handling paths starting with '#'
93
- fullFilename = paths[i].substr(1) + fullFilename;
94
- }else{
95
- fullFilename = path.join(paths[i], fullFilename);
96
- }
97
- }
98
-
99
- if (!explicit && paths[i] === '.') {
100
- try {
101
- fullFilename = require.resolve(fullFilename);
102
- isNodeModule = true;
103
- }
104
- catch (e) {
105
- filenamesTried.push(npmPrefix + fullFilename);
106
- tryWithExtension();
107
- }
108
- }
109
- else {
110
- tryWithExtension();
111
- }
112
-
113
- const readFileArgs = [fullFilename];
114
- if (!options.rawBuffer) {
115
- readFileArgs.push('utf-8');
116
- }
117
- if (options.syncImport) {
118
- try {
119
- const data = fs.readFileSync.apply(this, readFileArgs);
120
- fulfill({ contents: data, filename: fullFilename});
121
- }
122
- catch (e) {
123
- filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
124
- return tryPrefix(j + 1);
125
- }
126
- }
127
- else {
128
- readFileArgs.push(function(e, data) {
129
- if (e) {
130
- filenamesTried.push(isNodeModule ? npmPrefix + fullFilename : fullFilename);
131
- return tryPrefix(j + 1);
132
- }
133
- fulfill({ contents: data, filename: fullFilename});
134
- });
135
- fs.readFile.apply(this, readFileArgs);
136
- }
137
-
138
- }
139
- else {
140
- tryPathIndex(i + 1);
141
- }
142
- })(0);
143
- } else {
144
- reject({ type: 'File', message: `'${filename}' wasn't found. Tried - ${filenamesTried.join(',')}` });
145
- }
146
- }(0));
147
- }
148
- },
149
-
150
- loadFileSync(filename, currentDirectory, options, environment) {
151
- options.syncImport = true;
152
- return this.loadFile(filename, currentDirectory, options, environment);
153
- }
154
- });
155
-
156
- export default FileManager;
@@ -1,14 +0,0 @@
1
- /** @typedef {import('fs')} FS */
2
- import nodeFs from 'fs';
3
- import { createRequire } from 'module';
4
-
5
- const require = createRequire(import.meta.url);
6
-
7
- /** @type {FS} */
8
- let fs;
9
- try {
10
- fs = require('graceful-fs');
11
- } catch (e) {
12
- fs = nodeFs;
13
- }
14
- export default fs;