tailwindcss 0.0.0-oxide-insiders.a7fe2fe → 0.0.0-oxide-insiders.7f555c4

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 (108) hide show
  1. package/lib/cli/build/deps.js +34 -18
  2. package/lib/cli/build/index.js +45 -12
  3. package/lib/cli/build/plugin.js +273 -90
  4. package/lib/cli/build/utils.js +56 -24
  5. package/lib/cli/build/watching.js +156 -38
  6. package/lib/cli/help/index.js +61 -16
  7. package/lib/cli/index.js +121 -62
  8. package/lib/cli/init/index.js +47 -23
  9. package/lib/cli-peer-dependencies.js +23 -13
  10. package/lib/cli.js +5 -1
  11. package/lib/corePluginList.js +7 -4
  12. package/lib/corePlugins.js +855 -386
  13. package/lib/featureFlags.js +43 -18
  14. package/lib/lib/cacheInvalidation.js +78 -30
  15. package/lib/lib/collapseAdjacentRules.js +46 -23
  16. package/lib/lib/collapseDuplicateDeclarations.js +70 -27
  17. package/lib/lib/content.js +134 -41
  18. package/lib/lib/defaultExtractor.js +201 -96
  19. package/lib/lib/detectNesting.js +38 -12
  20. package/lib/lib/evaluateTailwindFunctions.js +192 -103
  21. package/lib/lib/expandApplyAtRules.js +488 -181
  22. package/lib/lib/expandTailwindAtRules.js +240 -70
  23. package/lib/lib/findAtConfigPath.js +34 -15
  24. package/lib/lib/generateRules.js +775 -353
  25. package/lib/lib/getModuleDependencies.js +67 -29
  26. package/lib/lib/load-config.js +27 -17
  27. package/lib/lib/normalizeTailwindDirectives.js +73 -27
  28. package/lib/lib/offsets.js +227 -62
  29. package/lib/lib/partitionApplyAtRules.js +53 -29
  30. package/lib/lib/regex.js +50 -28
  31. package/lib/lib/remap-bitfield.js +86 -9
  32. package/lib/lib/resolveDefaultsAtRules.js +123 -53
  33. package/lib/lib/setupContextUtils.js +1117 -584
  34. package/lib/lib/setupTrackingContext.js +149 -58
  35. package/lib/lib/sharedState.js +71 -23
  36. package/lib/lib/substituteScreenAtRules.js +19 -9
  37. package/lib/oxide/cli/build/deps.js +46 -23
  38. package/lib/oxide/cli/build/index.js +44 -12
  39. package/lib/oxide/cli/build/plugin.js +271 -89
  40. package/lib/oxide/cli/build/utils.js +55 -24
  41. package/lib/oxide/cli/build/watching.js +153 -36
  42. package/lib/oxide/cli/help/index.js +60 -16
  43. package/lib/oxide/cli/index.js +128 -67
  44. package/lib/oxide/cli/init/index.js +40 -19
  45. package/lib/oxide/cli.js +3 -2
  46. package/lib/plugin.js +58 -31
  47. package/lib/postcss-plugins/nesting/index.js +13 -7
  48. package/lib/postcss-plugins/nesting/plugin.js +65 -20
  49. package/lib/processTailwindFeatures.js +41 -10
  50. package/lib/public/colors.js +25 -16
  51. package/lib/public/create-plugin.js +11 -6
  52. package/lib/public/default-config.js +12 -6
  53. package/lib/public/default-theme.js +12 -6
  54. package/lib/public/load-config.js +9 -5
  55. package/lib/public/resolve-config.js +10 -6
  56. package/lib/util/applyImportantSelector.js +28 -17
  57. package/lib/util/bigSign.js +9 -6
  58. package/lib/util/buildMediaQuery.js +19 -10
  59. package/lib/util/cloneDeep.js +19 -9
  60. package/lib/util/cloneNodes.js +29 -14
  61. package/lib/util/color.js +87 -47
  62. package/lib/util/colorNames.js +752 -0
  63. package/lib/util/configurePlugins.js +18 -9
  64. package/lib/util/createPlugin.js +17 -8
  65. package/lib/util/createUtilityPlugin.js +30 -16
  66. package/lib/util/dataTypes.js +189 -38
  67. package/lib/util/defaults.js +21 -9
  68. package/lib/util/escapeClassName.js +15 -9
  69. package/lib/util/escapeCommas.js +9 -6
  70. package/lib/util/flattenColorPalette.js +11 -7
  71. package/lib/util/formatVariantSelector.js +209 -60
  72. package/lib/util/getAllConfigs.js +44 -35
  73. package/lib/util/hashConfig.js +12 -8
  74. package/lib/util/isKeyframeRule.js +10 -7
  75. package/lib/util/isPlainObject.js +14 -9
  76. package/lib/util/isSyntacticallyValidPropertyValue.js +45 -14
  77. package/lib/util/log.js +20 -9
  78. package/lib/util/nameClass.js +31 -10
  79. package/lib/util/negateValue.js +28 -10
  80. package/lib/util/normalizeConfig.js +242 -63
  81. package/lib/util/normalizeScreens.js +145 -70
  82. package/lib/util/parseAnimationValue.js +64 -14
  83. package/lib/util/parseBoxShadowValue.js +63 -14
  84. package/lib/util/parseDependency.js +39 -13
  85. package/lib/util/parseGlob.js +25 -8
  86. package/lib/util/parseObjectStyles.js +29 -18
  87. package/lib/util/pluginUtils.js +196 -77
  88. package/lib/util/prefixSelector.js +31 -12
  89. package/lib/util/pseudoElements.js +116 -34
  90. package/lib/util/removeAlphaVariables.js +23 -8
  91. package/lib/util/resolveConfig.js +224 -105
  92. package/lib/util/resolveConfigPath.js +45 -15
  93. package/lib/util/responsive.js +10 -6
  94. package/lib/util/splitAtTopLevelOnly.js +46 -10
  95. package/lib/util/tap.js +11 -7
  96. package/lib/util/toColorValue.js +10 -7
  97. package/lib/util/toPath.js +28 -8
  98. package/lib/util/transformThemeValue.js +49 -14
  99. package/lib/util/validateConfig.js +25 -15
  100. package/lib/util/validateFormalSyntax.js +14 -6
  101. package/lib/util/withAlphaVariable.js +54 -30
  102. package/package.json +18 -22
  103. package/peers/index.js +57849 -43101
  104. package/src/lib/expandTailwindAtRules.js +1 -1
  105. package/src/lib/setupTrackingContext.js +1 -1
  106. package/src/util/color.js +1 -1
  107. package/src/util/colorNames.js +150 -0
  108. package/src/util/pseudoElements.js +4 -4
@@ -1,104 +1,274 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
- value: !0
4
- }), Object.defineProperty(exports, "default", {
5
- enumerable: !0,
6
- get: ()=>expandTailwindAtRules
7
- }), require("fs"), require("quick-lru");
8
- const _sharedState = function(obj, nodeInterop) {
9
- if (!nodeInterop && obj && obj.__esModule) return obj;
10
- if (null === obj || "object" != typeof obj && "function" != typeof obj) return {
11
- default: obj
12
- };
13
- var cache = _getRequireWildcardCache(nodeInterop);
14
- if (cache && cache.has(obj)) return cache.get(obj);
15
- var newObj = {}, hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
16
- for(var key in obj)if ("default" !== key && Object.prototype.hasOwnProperty.call(obj, key)) {
17
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
18
- desc && (desc.get || desc.set) ? Object.defineProperty(newObj, key, desc) : newObj[key] = obj[key];
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return expandTailwindAtRules;
19
9
  }
20
- return newObj.default = obj, cache && cache.set(obj, newObj), newObj;
21
- }(require("./sharedState")), _generateRules = require("./generateRules"), _log = _interopRequireDefault(require("../util/log")), _cloneNodes = _interopRequireDefault(require("../util/cloneNodes")), _defaultExtractor = require("./defaultExtractor");
22
- function _interopRequireDefault(obj) {
10
+ });
11
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
+ const _quicklru = /*#__PURE__*/ _interop_require_default(require("@alloc/quick-lru"));
13
+ const _sharedState = /*#__PURE__*/ _interop_require_wildcard(require("./sharedState"));
14
+ const _generateRules = require("./generateRules");
15
+ const _log = /*#__PURE__*/ _interop_require_default(require("../util/log"));
16
+ const _cloneNodes = /*#__PURE__*/ _interop_require_default(require("../util/cloneNodes"));
17
+ const _defaultExtractor = require("./defaultExtractor");
18
+ function _interop_require_default(obj) {
23
19
  return obj && obj.__esModule ? obj : {
24
20
  default: obj
25
21
  };
26
22
  }
27
23
  function _getRequireWildcardCache(nodeInterop) {
28
- if ("function" != typeof WeakMap) return null;
29
- var cacheBabelInterop = new WeakMap(), cacheNodeInterop = new WeakMap();
24
+ if (typeof WeakMap !== "function") return null;
25
+ var cacheBabelInterop = new WeakMap();
26
+ var cacheNodeInterop = new WeakMap();
30
27
  return (_getRequireWildcardCache = function(nodeInterop) {
31
28
  return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
32
29
  })(nodeInterop);
33
30
  }
31
+ function _interop_require_wildcard(obj, nodeInterop) {
32
+ if (!nodeInterop && obj && obj.__esModule) {
33
+ return obj;
34
+ }
35
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
36
+ return {
37
+ default: obj
38
+ };
39
+ }
40
+ var cache = _getRequireWildcardCache(nodeInterop);
41
+ if (cache && cache.has(obj)) {
42
+ return cache.get(obj);
43
+ }
44
+ var newObj = {};
45
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
46
+ for(var key in obj){
47
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
48
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
49
+ if (desc && (desc.get || desc.set)) {
50
+ Object.defineProperty(newObj, key, desc);
51
+ } else {
52
+ newObj[key] = obj[key];
53
+ }
54
+ }
55
+ }
56
+ newObj.default = obj;
57
+ if (cache) {
58
+ cache.set(obj, newObj);
59
+ }
60
+ return newObj;
61
+ }
34
62
  let env = _sharedState.env;
63
+ const builtInExtractors = {
64
+ DEFAULT: _defaultExtractor.defaultExtractor
65
+ };
66
+ const builtInTransformers = {
67
+ DEFAULT: (content)=>content,
68
+ svelte: (content)=>content.replace(/(?:^|\s)class:/g, " ")
69
+ };
70
+ function getExtractor(context, fileExtension) {
71
+ let extractors = context.tailwindConfig.content.extract;
72
+ return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT(context);
73
+ }
74
+ function getTransformer(tailwindConfig, fileExtension) {
75
+ let transformers = tailwindConfig.content.transform;
76
+ return transformers[fileExtension] || transformers.DEFAULT || builtInTransformers[fileExtension] || builtInTransformers.DEFAULT;
77
+ }
78
+ let extractorCache = new WeakMap();
79
+ // Scans template contents for possible classes. This is a hot path on initial build but
80
+ // not too important for subsequent builds. The faster the better though — if we can speed
81
+ // up these regexes by 50% that could cut initial build time by like 20%.
82
+ function getClassCandidates(content, extractor, candidates, seen) {
83
+ if (!extractorCache.has(extractor)) {
84
+ extractorCache.set(extractor, new _quicklru.default({
85
+ maxSize: 25000
86
+ }));
87
+ }
88
+ for (let line of content.split("\n")){
89
+ line = line.trim();
90
+ if (seen.has(line)) {
91
+ continue;
92
+ }
93
+ seen.add(line);
94
+ if (extractorCache.get(extractor).has(line)) {
95
+ for (let match of extractorCache.get(extractor).get(line)){
96
+ candidates.add(match);
97
+ }
98
+ } else {
99
+ let extractorMatches = extractor(line).filter((s)=>s !== "!*");
100
+ let lineMatchesSet = new Set(extractorMatches);
101
+ for (let match of lineMatchesSet){
102
+ candidates.add(match);
103
+ }
104
+ extractorCache.get(extractor).set(line, lineMatchesSet);
105
+ }
106
+ }
107
+ }
108
+ /**
109
+ *
110
+ * @param {[import('./offsets.js').RuleOffset, import('postcss').Node][]} rules
111
+ * @param {*} context
112
+ */ function buildStylesheet(rules, context) {
113
+ let sortedRules = context.offsets.sort(rules);
114
+ let returnValue = {
115
+ base: new Set(),
116
+ defaults: new Set(),
117
+ components: new Set(),
118
+ utilities: new Set(),
119
+ variants: new Set()
120
+ };
121
+ for (let [sort, rule] of sortedRules){
122
+ returnValue[sort.layer].add(rule);
123
+ }
124
+ return returnValue;
125
+ }
35
126
  function expandTailwindAtRules(context) {
36
127
  return (root)=>{
37
- var _context_candidates;
38
128
  let layerNodes = {
39
129
  base: null,
40
130
  components: null,
41
131
  utilities: null,
42
132
  variants: null
43
133
  };
44
- if (root.walkAtRules((rule)=>{
45
- "tailwind" === rule.name && Object.keys(layerNodes).includes(rule.params) && (layerNodes[rule.params] = rule);
46
- }), Object.values(layerNodes).every((n)=>null === n)) return root;
134
+ root.walkAtRules((rule)=>{
135
+ // Make sure this file contains Tailwind directives. If not, we can save
136
+ // a lot of work and bail early. Also we don't have to register our touch
137
+ // file as a dependency since the output of this CSS does not depend on
138
+ // the source of any templates. Think Vue <style> blocks for example.
139
+ if (rule.name === "tailwind") {
140
+ if (Object.keys(layerNodes).includes(rule.params)) {
141
+ layerNodes[rule.params] = rule;
142
+ }
143
+ }
144
+ });
145
+ if (Object.values(layerNodes).every((n)=>n === null)) {
146
+ return root;
147
+ }
148
+ var _context_candidates;
149
+ // ---
150
+ // Find potential rules in changed files
47
151
  let candidates = new Set([
48
- ...null !== (_context_candidates = context.candidates) && void 0 !== _context_candidates ? _context_candidates : [],
152
+ ...(_context_candidates = context.candidates) !== null && _context_candidates !== void 0 ? _context_candidates : [],
49
153
  _sharedState.NOT_ON_DEMAND
50
154
  ]);
51
- for (let candidate of (env.DEBUG && console.time("Reading changed files"), require("@tailwindcss/oxide").parseCandidateStringsFromFiles(context.changedContent)))candidates.add(candidate);
155
+ let seen = new Set();
156
+ env.DEBUG && console.time("Reading changed files");
157
+ if (true) {
158
+ // TODO: Pass through or implement `extractor`
159
+ for (let candidate of require("@tailwindcss/oxide").parseCandidateStringsFromFiles(context.changedContent)){
160
+ candidates.add(candidate);
161
+ }
162
+ // for (let { file, content, extension } of context.changedContent) {
163
+ // let transformer = getTransformer(context.tailwindConfig, extension)
164
+ // let extractor = getExtractor(context, extension)
165
+ // getClassCandidatesOxide(file, transformer(content), extractor, candidates, seen)
166
+ // }
167
+ } else {
168
+ for (let { file , content , extension } of context.changedContent){
169
+ let transformer = getTransformer(context.tailwindConfig, extension);
170
+ let extractor = getExtractor(context, extension);
171
+ content = file ? _fs.default.readFileSync(file, "utf8") : content;
172
+ getClassCandidates(transformer(content), extractor, candidates, seen);
173
+ }
174
+ }
52
175
  env.DEBUG && console.timeEnd("Reading changed files");
176
+ // ---
177
+ // Generate the actual CSS
53
178
  let classCacheCount = context.classCache.size;
54
- env.DEBUG && console.time("Generate rules"), env.DEBUG && console.time("Sorting candidates"), env.DEBUG && console.timeEnd("Sorting candidates"), (0, _generateRules.generateRules)(candidates, context), env.DEBUG && console.timeEnd("Generate rules"), env.DEBUG && console.time("Build stylesheet"), (null === context.stylesheetCache || context.classCache.size !== classCacheCount) && (context.stylesheetCache = function(rules, context) {
55
- let sortedRules = context.offsets.sort(rules), returnValue = {
56
- base: new Set(),
57
- defaults: new Set(),
58
- components: new Set(),
59
- utilities: new Set(),
60
- variants: new Set()
61
- };
62
- for (let [sort, rule] of sortedRules)returnValue[sort.layer].add(rule);
63
- return returnValue;
64
- }([
65
- ...context.ruleCache
66
- ], context)), env.DEBUG && console.timeEnd("Build stylesheet");
179
+ env.DEBUG && console.time("Generate rules");
180
+ env.DEBUG && console.time("Sorting candidates");
181
+ let sortedCandidates = true ? candidates : new Set([
182
+ ...candidates
183
+ ].sort((a, z)=>{
184
+ if (a === z) return 0;
185
+ if (a < z) return -1;
186
+ return 1;
187
+ }));
188
+ env.DEBUG && console.timeEnd("Sorting candidates");
189
+ (0, _generateRules.generateRules)(sortedCandidates, context);
190
+ env.DEBUG && console.timeEnd("Generate rules");
191
+ // We only ever add to the classCache, so if it didn't grow, there is nothing new.
192
+ env.DEBUG && console.time("Build stylesheet");
193
+ if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
194
+ context.stylesheetCache = buildStylesheet([
195
+ ...context.ruleCache
196
+ ], context);
197
+ }
198
+ env.DEBUG && console.timeEnd("Build stylesheet");
67
199
  let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes } = context.stylesheetCache;
68
- layerNodes.base && (layerNodes.base.before((0, _cloneNodes.default)([
69
- ...baseNodes,
70
- ...defaultNodes
71
- ], layerNodes.base.source, {
72
- layer: "base"
73
- })), layerNodes.base.remove()), layerNodes.components && (layerNodes.components.before((0, _cloneNodes.default)([
74
- ...componentNodes
75
- ], layerNodes.components.source, {
76
- layer: "components"
77
- })), layerNodes.components.remove()), layerNodes.utilities && (layerNodes.utilities.before((0, _cloneNodes.default)([
78
- ...utilityNodes
79
- ], layerNodes.utilities.source, {
80
- layer: "utilities"
81
- })), layerNodes.utilities.remove());
82
- let variantNodes = Array.from(screenNodes).filter((node)=>{
200
+ // ---
201
+ // Replace any Tailwind directives with generated CSS
202
+ if (layerNodes.base) {
203
+ layerNodes.base.before((0, _cloneNodes.default)([
204
+ ...baseNodes,
205
+ ...defaultNodes
206
+ ], layerNodes.base.source, {
207
+ layer: "base"
208
+ }));
209
+ layerNodes.base.remove();
210
+ }
211
+ if (layerNodes.components) {
212
+ layerNodes.components.before((0, _cloneNodes.default)([
213
+ ...componentNodes
214
+ ], layerNodes.components.source, {
215
+ layer: "components"
216
+ }));
217
+ layerNodes.components.remove();
218
+ }
219
+ if (layerNodes.utilities) {
220
+ layerNodes.utilities.before((0, _cloneNodes.default)([
221
+ ...utilityNodes
222
+ ], layerNodes.utilities.source, {
223
+ layer: "utilities"
224
+ }));
225
+ layerNodes.utilities.remove();
226
+ }
227
+ // We do post-filtering to not alter the emitted order of the variants
228
+ const variantNodes = Array.from(screenNodes).filter((node)=>{
83
229
  var _node_raws_tailwind;
84
- let parentLayer = null === (_node_raws_tailwind = node.raws.tailwind) || void 0 === _node_raws_tailwind ? void 0 : _node_raws_tailwind.parentLayer;
85
- return "components" === parentLayer ? null !== layerNodes.components : "utilities" !== parentLayer || null !== layerNodes.utilities;
230
+ const parentLayer = (_node_raws_tailwind = node.raws.tailwind) === null || _node_raws_tailwind === void 0 ? void 0 : _node_raws_tailwind.parentLayer;
231
+ if (parentLayer === "components") {
232
+ return layerNodes.components !== null;
233
+ }
234
+ if (parentLayer === "utilities") {
235
+ return layerNodes.utilities !== null;
236
+ }
237
+ return true;
86
238
  });
87
- layerNodes.variants ? (layerNodes.variants.before((0, _cloneNodes.default)(variantNodes, layerNodes.variants.source, {
88
- layer: "variants"
89
- })), layerNodes.variants.remove()) : variantNodes.length > 0 && root.append((0, _cloneNodes.default)(variantNodes, root.source, {
90
- layer: "variants"
91
- }));
92
- let hasUtilityVariants = variantNodes.some((node)=>{
239
+ if (layerNodes.variants) {
240
+ layerNodes.variants.before((0, _cloneNodes.default)(variantNodes, layerNodes.variants.source, {
241
+ layer: "variants"
242
+ }));
243
+ layerNodes.variants.remove();
244
+ } else if (variantNodes.length > 0) {
245
+ root.append((0, _cloneNodes.default)(variantNodes, root.source, {
246
+ layer: "variants"
247
+ }));
248
+ }
249
+ // If we've got a utility layer and no utilities are generated there's likely something wrong
250
+ const hasUtilityVariants = variantNodes.some((node)=>{
93
251
  var _node_raws_tailwind;
94
- return (null === (_node_raws_tailwind = node.raws.tailwind) || void 0 === _node_raws_tailwind ? void 0 : _node_raws_tailwind.parentLayer) === "utilities";
252
+ return ((_node_raws_tailwind = node.raws.tailwind) === null || _node_raws_tailwind === void 0 ? void 0 : _node_raws_tailwind.parentLayer) === "utilities";
95
253
  });
96
- layerNodes.utilities && 0 === utilityNodes.size && !hasUtilityVariants && _log.default.warn("content-problems", [
97
- "No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
98
- "https://tailwindcss.com/docs/content-configuration"
99
- ]), env.DEBUG && (console.log("Potential classes: ", candidates.size), console.log("Active contexts: ", _sharedState.contextSourcesMap.size)), context.changedContent = [], root.walkAtRules("layer", (rule)=>{
100
- Object.keys(layerNodes).includes(rule.params) && rule.remove();
254
+ if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
255
+ _log.default.warn("content-problems", [
256
+ "No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
257
+ "https://tailwindcss.com/docs/content-configuration"
258
+ ]);
259
+ }
260
+ // ---
261
+ if (env.DEBUG) {
262
+ console.log("Potential classes: ", candidates.size);
263
+ console.log("Active contexts: ", _sharedState.contextSourcesMap.size);
264
+ }
265
+ // Clear the cache for the changed files
266
+ context.changedContent = [];
267
+ // Cleanup any leftover @layer atrules
268
+ root.walkAtRules("layer", (rule)=>{
269
+ if (Object.keys(layerNodes).includes(rule.params)) {
270
+ rule.remove();
271
+ }
101
272
  });
102
273
  };
103
274
  }
104
- _defaultExtractor.defaultExtractor, new WeakMap();
@@ -1,27 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
- value: !0
4
- }), Object.defineProperty(exports, "findAtConfigPath", {
5
- enumerable: !0,
6
- get: ()=>findAtConfigPath
3
+ value: true
7
4
  });
8
- const _fs = _interopRequireDefault(require("fs")), _path = _interopRequireDefault(require("path"));
9
- function _interopRequireDefault(obj) {
5
+ Object.defineProperty(exports, "findAtConfigPath", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return findAtConfigPath;
9
+ }
10
+ });
11
+ const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
12
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
13
+ function _interop_require_default(obj) {
10
14
  return obj && obj.__esModule ? obj : {
11
15
  default: obj
12
16
  };
13
17
  }
14
18
  function findAtConfigPath(root, result) {
15
- let configPath = null, relativeTo = null;
16
- return root.walkAtRules("config", (rule)=>{
17
- var _rule_source, _rule_source_input_file, _ref;
18
- if (null === (relativeTo = null !== (_ref = null !== (_rule_source_input_file = null === (_rule_source = rule.source) || void 0 === _rule_source ? void 0 : _rule_source.input.file) && void 0 !== _rule_source_input_file ? _rule_source_input_file : result.opts.from) && void 0 !== _ref ? _ref : null)) throw rule.error("The `@config` directive cannot be used without setting `from` in your PostCSS config.");
19
- if (configPath) throw rule.error("Only one `@config` directive is allowed per file.");
19
+ let configPath = null;
20
+ let relativeTo = null;
21
+ root.walkAtRules("config", (rule)=>{
22
+ var _rule_source;
23
+ var _rule_source_input_file, _ref;
24
+ relativeTo = (_ref = (_rule_source_input_file = (_rule_source = rule.source) === null || _rule_source === void 0 ? void 0 : _rule_source.input.file) !== null && _rule_source_input_file !== void 0 ? _rule_source_input_file : result.opts.from) !== null && _ref !== void 0 ? _ref : null;
25
+ if (relativeTo === null) {
26
+ throw rule.error("The `@config` directive cannot be used without setting `from` in your PostCSS config.");
27
+ }
28
+ if (configPath) {
29
+ throw rule.error("Only one `@config` directive is allowed per file.");
30
+ }
20
31
  let matches = rule.params.match(/(['"])(.*?)\1/);
21
- if (!matches) throw rule.error("A path is required when using the `@config` directive.");
32
+ if (!matches) {
33
+ throw rule.error("A path is required when using the `@config` directive.");
34
+ }
22
35
  let inputPath = matches[2];
23
- if (_path.default.isAbsolute(inputPath)) throw rule.error("The `@config` directive cannot be used with an absolute path.");
24
- if (configPath = _path.default.resolve(_path.default.dirname(relativeTo), inputPath), !_fs.default.existsSync(configPath)) throw rule.error(`The config file at "${inputPath}" does not exist. Make sure the path is correct and the file exists.`);
36
+ if (_path.default.isAbsolute(inputPath)) {
37
+ throw rule.error("The `@config` directive cannot be used with an absolute path.");
38
+ }
39
+ configPath = _path.default.resolve(_path.default.dirname(relativeTo), inputPath);
40
+ if (!_fs.default.existsSync(configPath)) {
41
+ throw rule.error(`The config file at "${inputPath}" does not exist. Make sure the path is correct and the file exists.`);
42
+ }
25
43
  rule.remove();
26
- }), configPath || null;
44
+ });
45
+ return configPath ? configPath : null;
27
46
  }