tailwindcss-injector 0.1.4 → 0.1.5
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.
- package/dist/postcss.cjs +28 -4
- package/dist/postcss.d.cts +1 -0
- package/dist/postcss.d.ts +1 -0
- package/dist/postcss.js +28 -4
- package/package.json +1 -1
package/dist/postcss.cjs
CHANGED
|
@@ -323,6 +323,27 @@ function md5(input) {
|
|
|
323
323
|
hash.update(input);
|
|
324
324
|
return hash.digest("hex");
|
|
325
325
|
}
|
|
326
|
+
function isRegexp(value) {
|
|
327
|
+
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
328
|
+
}
|
|
329
|
+
function regExpTest(arr = [], str) {
|
|
330
|
+
if (Array.isArray(arr)) {
|
|
331
|
+
for (const item of arr) {
|
|
332
|
+
if (typeof item === "string") {
|
|
333
|
+
if (str.includes(item)) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
} else if (isRegexp(item)) {
|
|
337
|
+
item.lastIndex = 0;
|
|
338
|
+
if (item.test(str)) {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
throw new TypeError("paramater 'arr' should be a Array of Regexp | String !");
|
|
346
|
+
}
|
|
326
347
|
|
|
327
348
|
// src/config.ts
|
|
328
349
|
function getDefaultConfig() {
|
|
@@ -334,7 +355,8 @@ function getDefaultConfig() {
|
|
|
334
355
|
cwd: _process2.default.cwd(),
|
|
335
356
|
extensions: ["wxml", "js", "ts"],
|
|
336
357
|
// @import and @use (scss)
|
|
337
|
-
insertAfterAtRulesNames: ["import", "use"]
|
|
358
|
+
insertAfterAtRulesNames: ["import", "use"],
|
|
359
|
+
insertAfterComments: ["@import"]
|
|
338
360
|
};
|
|
339
361
|
}
|
|
340
362
|
function getConfig(options) {
|
|
@@ -443,7 +465,7 @@ async function getDepFiles(file) {
|
|
|
443
465
|
|
|
444
466
|
// src/postcss.ts
|
|
445
467
|
var creator = (options) => {
|
|
446
|
-
const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames } = getConfig(options);
|
|
468
|
+
const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames, insertAfterComments } = getConfig(options);
|
|
447
469
|
const extensionsGlob = `{${extensions.join(",")}}`;
|
|
448
470
|
return {
|
|
449
471
|
postcssPlugin,
|
|
@@ -452,7 +474,9 @@ var creator = (options) => {
|
|
|
452
474
|
postcssPlugin: `${postcssPlugin}:post`,
|
|
453
475
|
async Once(root, helpers) {
|
|
454
476
|
if (filter(_optionalChain([root, 'access', _ => _.source, 'optionalAccess', _2 => _2.input]))) {
|
|
455
|
-
const
|
|
477
|
+
const atruleLastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
|
|
478
|
+
const commentLastIndex = root.nodes.findLastIndex((x) => x.type === "comment" && regExpTest(insertAfterComments, x.text));
|
|
479
|
+
const lastIndex = Math.max(atruleLastIndex, commentLastIndex);
|
|
456
480
|
for (const params of directiveParams) {
|
|
457
481
|
const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
|
|
458
482
|
if (!node) {
|
|
@@ -491,7 +515,7 @@ var creator = (options) => {
|
|
|
491
515
|
_tailwindcss2.default.call(void 0, tailwindcssConfig)
|
|
492
516
|
]).process(root, {
|
|
493
517
|
from: root.source.input.file
|
|
494
|
-
});
|
|
518
|
+
}).async();
|
|
495
519
|
}
|
|
496
520
|
}
|
|
497
521
|
}
|
package/dist/postcss.d.cts
CHANGED
|
@@ -9,6 +9,7 @@ interface Options {
|
|
|
9
9
|
directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
|
|
10
10
|
extensions: string[];
|
|
11
11
|
insertAfterAtRulesNames: string[];
|
|
12
|
+
insertAfterComments: (string | RegExp)[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
declare const creator: PluginCreator<Partial<Options>>;
|
package/dist/postcss.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface Options {
|
|
|
9
9
|
directiveParams: ('base' | 'components' | 'utilities' | 'variants')[];
|
|
10
10
|
extensions: string[];
|
|
11
11
|
insertAfterAtRulesNames: string[];
|
|
12
|
+
insertAfterComments: (string | RegExp)[];
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
declare const creator: PluginCreator<Partial<Options>>;
|
package/dist/postcss.js
CHANGED
|
@@ -323,6 +323,27 @@ function md5(input) {
|
|
|
323
323
|
hash.update(input);
|
|
324
324
|
return hash.digest("hex");
|
|
325
325
|
}
|
|
326
|
+
function isRegexp(value) {
|
|
327
|
+
return Object.prototype.toString.call(value) === "[object RegExp]";
|
|
328
|
+
}
|
|
329
|
+
function regExpTest(arr = [], str) {
|
|
330
|
+
if (Array.isArray(arr)) {
|
|
331
|
+
for (const item of arr) {
|
|
332
|
+
if (typeof item === "string") {
|
|
333
|
+
if (str.includes(item)) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
} else if (isRegexp(item)) {
|
|
337
|
+
item.lastIndex = 0;
|
|
338
|
+
if (item.test(str)) {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
throw new TypeError("paramater 'arr' should be a Array of Regexp | String !");
|
|
346
|
+
}
|
|
326
347
|
|
|
327
348
|
// src/config.ts
|
|
328
349
|
function getDefaultConfig() {
|
|
@@ -334,7 +355,8 @@ function getDefaultConfig() {
|
|
|
334
355
|
cwd: process.cwd(),
|
|
335
356
|
extensions: ["wxml", "js", "ts"],
|
|
336
357
|
// @import and @use (scss)
|
|
337
|
-
insertAfterAtRulesNames: ["import", "use"]
|
|
358
|
+
insertAfterAtRulesNames: ["import", "use"],
|
|
359
|
+
insertAfterComments: ["@import"]
|
|
338
360
|
};
|
|
339
361
|
}
|
|
340
362
|
function getConfig(options) {
|
|
@@ -443,7 +465,7 @@ async function getDepFiles(file) {
|
|
|
443
465
|
|
|
444
466
|
// src/postcss.ts
|
|
445
467
|
var creator = (options) => {
|
|
446
|
-
const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames } = getConfig(options);
|
|
468
|
+
const { config, filter, directiveParams, cwd, extensions, insertAfterAtRulesNames, insertAfterComments } = getConfig(options);
|
|
447
469
|
const extensionsGlob = `{${extensions.join(",")}}`;
|
|
448
470
|
return {
|
|
449
471
|
postcssPlugin,
|
|
@@ -452,7 +474,9 @@ var creator = (options) => {
|
|
|
452
474
|
postcssPlugin: `${postcssPlugin}:post`,
|
|
453
475
|
async Once(root, helpers) {
|
|
454
476
|
if (filter(root.source?.input)) {
|
|
455
|
-
const
|
|
477
|
+
const atruleLastIndex = root.nodes.findLastIndex((x) => x.type === "atrule" && insertAfterAtRulesNames.includes(x.name));
|
|
478
|
+
const commentLastIndex = root.nodes.findLastIndex((x) => x.type === "comment" && regExpTest(insertAfterComments, x.text));
|
|
479
|
+
const lastIndex = Math.max(atruleLastIndex, commentLastIndex);
|
|
456
480
|
for (const params of directiveParams) {
|
|
457
481
|
const node = root.nodes.find((x) => x.type === "atrule" && x.params === params);
|
|
458
482
|
if (!node) {
|
|
@@ -491,7 +515,7 @@ var creator = (options) => {
|
|
|
491
515
|
tailwindcss(tailwindcssConfig)
|
|
492
516
|
]).process(root, {
|
|
493
517
|
from: root.source.input.file
|
|
494
|
-
});
|
|
518
|
+
}).async();
|
|
495
519
|
}
|
|
496
520
|
}
|
|
497
521
|
}
|