版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 1 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var require$$0 = require('module');
  4. var require$$1 = require('path');
  5. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  6. var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
  7. var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
  8. function windi(strings) {
  9. var values = [];
  10. for (var _i = 1; _i < arguments.length; _i++) {
  11. values[_i - 1] = arguments[_i];
  12. }
  13. // windi template literal
  14. return strings.reduce(function (query, queryPart, i) {
  15. var valueExists = i < values.length;
  16. var text = query + queryPart;
  17. return valueExists ? text + values[i] : text;
  18. }, '');
  19. }
  20. var lib = {exports: {}};
  21. (function (module, exports) {
  22. Object.defineProperty(exports, "__esModule", {
  23. value: true
  24. });
  25. exports.addHook = addHook;
  26. var _module = _interopRequireDefault(require$$0__default["default"]);
  27. var _path = _interopRequireDefault(require$$1__default["default"]);
  28. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29. /* (c) 2015 Ari Porad (@ariporad) <http://ariporad.com>. License: ariporad.mit-license.org */
  30. const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/; // Guard against poorly mocked module constructors.
  31. const Module = module.constructor.length > 1 ? module.constructor : _module.default;
  32. const HOOK_RETURNED_NOTHING_ERROR_MESSAGE = '[Pirates] A hook returned a non-string, or nothing at all! This is a' + ' violation of intergalactic law!\n' + '--------------------\n' + 'If you have no idea what this means or what Pirates is, let me explain: ' + 'Pirates is a module that makes is easy to implement require hooks. One of' + " the require hooks you're using uses it. One of these require hooks" + " didn't return anything from it's handler, so we don't know what to" + ' do. You might want to debug this.';
  33. /**
  34. * @param {string} filename The filename to check.
  35. * @param {string[]} exts The extensions to hook. Should start with '.' (ex. ['.js']).
  36. * @param {Matcher|null} matcher A matcher function, will be called with path to a file. Should return truthy if the file should be hooked, falsy otherwise.
  37. * @param {boolean} ignoreNodeModules Auto-ignore node_modules. Independent of any matcher.
  38. */
  39. function shouldCompile(filename, exts, matcher, ignoreNodeModules) {
  40. if (typeof filename !== 'string') {
  41. return false;
  42. }
  43. if (exts.indexOf(_path.default.extname(filename)) === -1) {
  44. return false;
  45. }
  46. const resolvedFilename = _path.default.resolve(filename);
  47. if (ignoreNodeModules && nodeModulesRegex.test(resolvedFilename)) {
  48. return false;
  49. }
  50. if (matcher && typeof matcher === 'function') {
  51. return !!matcher(resolvedFilename);
  52. }
  53. return true;
  54. }
  55. /**
  56. * @callback Hook The hook. Accepts the code of the module and the filename.
  57. * @param {string} code
  58. * @param {string} filename
  59. * @returns {string}
  60. */
  61. /**
  62. * @callback Matcher A matcher function, will be called with path to a file.
  63. *
  64. * Should return truthy if the file should be hooked, falsy otherwise.
  65. * @param {string} path
  66. * @returns {boolean}
  67. */
  68. /**
  69. * @callback RevertFunction Reverts the hook when called.
  70. * @returns {void}
  71. */
  72. /**
  73. * @typedef {object} Options
  74. * @property {Matcher|null} [matcher=null] A matcher function, will be called with path to a file.
  75. *
  76. * Should return truthy if the file should be hooked, falsy otherwise.
  77. *
  78. * @property {string[]} [extensions=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
  79. * @property {string[]} [exts=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
  80. *
  81. * @property {string[]} [extension=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
  82. * @property {string[]} [ext=['.js']] The extensions to hook. Should start with '.' (ex. ['.js']).
  83. *
  84. * @property {boolean} [ignoreNodeModules=true] Auto-ignore node_modules. Independent of any matcher.
  85. */
  86. /**
  87. * Add a require hook.
  88. *
  89. * @param {Hook} hook The hook. Accepts the code of the module and the filename. Required.
  90. * @param {Options} [opts] Options
  91. * @returns {RevertFunction} The `revert` function. Reverts the hook when called.
  92. */
  93. function addHook(hook, opts = {}) {
  94. let reverted = false;
  95. const loaders = [];
  96. const oldLoaders = [];
  97. let exts; // We need to do this to fix #15. Basically, if you use a non-standard extension (ie. .jsx), then
  98. // We modify the .js loader, then use the modified .js loader for as the base for .jsx.
  99. // This prevents that.
  100. const originalJSLoader = Module._extensions['.js'];
  101. const matcher = opts.matcher || null;
  102. const ignoreNodeModules = opts.ignoreNodeModules !== false;
  103. exts = opts.extensions || opts.exts || opts.extension || opts.ext || ['.js'];
  104. if (!Array.isArray(exts)) {
  105. exts = [exts];
  106. }
  107. exts.forEach(ext => {
  108. if (typeof ext !== 'string') {
  109. throw new TypeError(`Invalid Extension: ${ext}`);
  110. }
  111. const oldLoader = Module._extensions[ext] || originalJSLoader;
  112. oldLoaders[ext] = Module._extensions[ext];
  113. loaders[ext] = Module._extensions[ext] = function newLoader(mod, filename) {
  114. let compile;
  115. if (!reverted) {
  116. if (shouldCompile(filename, exts, matcher, ignoreNodeModules)) {
  117. compile = mod._compile;
  118. mod._compile = function _compile(code) {
  119. // reset the compile immediately as otherwise we end up having the
  120. // compile function being changed even though this loader might be reverted
  121. // Not reverting it here leads to long useless compile chains when doing
  122. // addHook -> revert -> addHook -> revert -> ...
  123. // The compile function is also anyway created new when the loader is called a second time.
  124. mod._compile = compile;
  125. const newCode = hook(code, filename);
  126. if (typeof newCode !== 'string') {
  127. throw new Error(HOOK_RETURNED_NOTHING_ERROR_MESSAGE);
  128. }
  129. return mod._compile(newCode, filename);
  130. };
  131. }
  132. }
  133. oldLoader(mod, filename);
  134. };
  135. });
  136. return function revert() {
  137. if (reverted) return;
  138. reverted = true;
  139. exts.forEach(ext => {
  140. // if the current loader for the extension is our loader then unregister it and set the oldLoader again
  141. // if not we can not do anything as we cannot remove a loader from within the loader-chain
  142. if (Module._extensions[ext] === loaders[ext]) {
  143. Module._extensions[ext] = oldLoaders[ext];
  144. }
  145. });
  146. };
  147. }
  148. }(lib, lib.exports));
  149. function convert(code) {
  150. var map = {
  151. '@tailwindcss\\/typography': 'windicss/plugin/typography',
  152. '@tailwindcss\\/forms': 'windicss/plugin/forms',
  153. '@tailwindcss\\/aspect-ratio': 'windicss/plugin/aspect-ratio',
  154. '@tailwindcss\\/line-clamp': 'windicss/plugin/line-clamp',
  155. 'tailwindcss\\/plugin': 'windicss/plugin',
  156. 'tailwindcss\\/colors': 'windicss/colors',
  157. 'tailwindcss\\/resolveConfig': 'windicss/resolveConfig',
  158. 'tailwindcss\\/defaultConfig': 'windicss/defaultConfig',
  159. 'tailwindcss\\/defaultTheme': 'windicss/defaultTheme',
  160. };
  161. for (var _i = 0, _a = Object.entries(map); _i < _a.length; _i++) {
  162. var _b = _a[_i], key = _b[0], value = _b[1];
  163. code = code.replace(new RegExp(key, 'g'), value);
  164. }
  165. return code;
  166. }
  167. function transform(path) {
  168. var require$1 = require$$0.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href)));
  169. var matcher = function (filename) { return !/\/windicss\//.test(filename); };
  170. var revert = lib.exports.addHook(function (code) { return convert(code); }, { exts: ['.js'], matcher: matcher, ignoreNodeModules: false });
  171. var mod = require$1(path);
  172. revert();
  173. return mod;
  174. }
  175. function defineConfig(config) {
  176. return config;
  177. }
  178. exports.convert = convert;
  179. exports.defineConfig = defineConfig;
  180. exports.transform = transform;
  181. exports.windi = windi;