postcss-import-glob 0.1.0 → 0.1.2
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/lib/utils.js +31 -0
- package/package.json +7 -2
package/lib/utils.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "node:fs/promises"
|
|
2
|
+
import { parse, format, join } from "node:path"
|
|
3
|
+
|
|
4
|
+
export const readFile = path => fs.readFile(path, new TextDecoder)
|
|
5
|
+
|
|
6
|
+
export const raw = string =>
|
|
7
|
+
string.match(/^(?:url\()?["']?(.+\.css)["')]/)?.at(1)
|
|
8
|
+
|
|
9
|
+
export function basedir(path) {
|
|
10
|
+
if (path == null) return process.cwd()
|
|
11
|
+
const { dir, base, name } = parse(path)
|
|
12
|
+
return base === name ? dir.length ? join(dir, name) : name : dir
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function glob(pattern, options, method) {
|
|
16
|
+
options ??= {}
|
|
17
|
+
const patterns = [pattern].flat()
|
|
18
|
+
|
|
19
|
+
if (options.dot)
|
|
20
|
+
pattern = patterns.flatMap(pattern => {
|
|
21
|
+
const path = parse(pattern)
|
|
22
|
+
path.base = `.${path.base}`
|
|
23
|
+
return [format(path), pattern]
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if (options.globstar)
|
|
27
|
+
pattern = patterns.map(pattern => pattern.replace(/\*{2}(?=\.)/, "$&/*"))
|
|
28
|
+
|
|
29
|
+
const matches = fs.glob(pattern, options)
|
|
30
|
+
return Array.fromAsync(matches, method)
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.2",
|
|
3
3
|
"name": "postcss-import-glob",
|
|
4
4
|
"description": "PostCSS plugin to inline CSS @imports, with support for glob patterns.",
|
|
5
5
|
"keywords": [
|
|
@@ -25,9 +25,14 @@
|
|
|
25
25
|
"funding": "https://github.com/danielbayley/postcss-import-glob?sponsor=1",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"type": "module",
|
|
28
|
+
"imports": {
|
|
29
|
+
"#utils": "./lib/utils.js",
|
|
30
|
+
"#test": "./lib/test.js"
|
|
31
|
+
},
|
|
28
32
|
"exports": "./index.js",
|
|
29
33
|
"files": [
|
|
30
|
-
"./index.js"
|
|
34
|
+
"./index.js",
|
|
35
|
+
"./lib/utils.js"
|
|
31
36
|
],
|
|
32
37
|
"publishConfig": {
|
|
33
38
|
"access": "public"
|