tailwindcss-config 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 ice breaker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # `tailwindcss-config`
2
+
3
+ A lightweight utility for dynamically loading Tailwind CSS configuration files. It supports multiple formats and provides a seamless way to work with Tailwind configuration in your projects.
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ - **Multi-format support**: Handles `.js`, `.cjs`, `.mjs`, `.ts`, `.cts`, and `.mts` configuration files.
10
+ - **Automatic discovery**: Searches for configuration files in the current working directory or a specified path.
11
+ - **Graceful fallback**: Returns `undefined` if no configuration is found, ensuring compatibility with dynamic setups.
12
+ - **TypeScript support**: Fully typed for use in TypeScript projects.
13
+
14
+ ---
15
+
16
+ ## Installation
17
+
18
+ Install the package via npm:
19
+
20
+ ```bash
21
+ npm i -D tailwindcss-config
22
+ ```
23
+
24
+ Or using Yarn:
25
+
26
+ ```bash
27
+ yarn add -D tailwindcss-config
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Usage
33
+
34
+ ### Import the Function
35
+
36
+ ```typescript
37
+ import { loadConfig } from 'tailwindcss-config'
38
+ ```
39
+
40
+ ### Examples
41
+
42
+ #### 1. Default Usage
43
+
44
+ The function searches for Tailwind CSS configuration files in the current working directory:
45
+
46
+ ```typescript
47
+ (async () => {
48
+ const config = await loadConfig()
49
+ console.log(config)
50
+ })()
51
+ ```
52
+
53
+ #### 2. Specify a Configuration File
54
+
55
+ Explicitly specify a path to a Tailwind CSS configuration file:
56
+
57
+ ```typescript
58
+ (async () => {
59
+ const config = await loadConfig({ config: './tailwind.config.ts' })
60
+ console.log(config)
61
+ })()
62
+ ```
63
+
64
+ #### 3. Change the Working Directory
65
+
66
+ Set a custom working directory to search for Tailwind configuration files:
67
+
68
+ ```typescript
69
+ (async () => {
70
+ const config = await loadConfig({ cwd: '/my/project/directory' })
71
+ console.log(config)
72
+ })()
73
+ ```
74
+
75
+ ---
76
+
77
+ ## Supported Configuration Formats
78
+
79
+ The utility supports the following file types:
80
+
81
+ - `tailwind.config.js`
82
+ - `tailwind.config.cjs`
83
+ - `tailwind.config.mjs`
84
+ - `tailwind.config.ts`
85
+ - `tailwind.config.cts`
86
+ - `tailwind.config.mts`
87
+
88
+ Dynamic imports are powered by [`jiti`](https://github.com/unjs/jiti), allowing the utility to handle various file types seamlessly.
89
+
90
+ ---
91
+
92
+ ## API Reference
93
+
94
+ ### `loadConfig(options?: Partial<LoadConfigOptions>)`
95
+
96
+ #### Parameters
97
+
98
+ | Parameter | Type | Description | Default |
99
+ | ---------------- | ---------------------------- | ----------------------------------------------- | --------------- |
100
+ | `options` | `Partial<LoadConfigOptions>` | Options to customize configuration loading. | `{}` |
101
+ | `options.cwd` | `string` | Directory to search for configuration files. | `process.cwd()` |
102
+ | `options.config` | `string` | Path to a specific Tailwind configuration file. | `undefined` |
103
+
104
+ #### Returns
105
+
106
+ A `Promise` that resolves to a `Config` object or `undefined` if no configuration file is found.
107
+
108
+ ---
109
+
110
+ ## File Search Order
111
+
112
+ The utility uses [`lilconfig`](https://github.com/antonk52/lilconfig) to locate configuration files. It searches for the following files (in order):
113
+
114
+ 1. `tailwind.config.js`
115
+ 2. `tailwind.config.cjs`
116
+ 3. `tailwind.config.mjs`
117
+ 4. `tailwind.config.ts`
118
+ 5. `tailwind.config.cts`
119
+ 6. `tailwind.config.mts`
120
+
121
+ ---
122
+
123
+ ## Example Project Structure
124
+
125
+ ```plaintext
126
+ my-project/
127
+ ├── src/
128
+ │ └── index.ts
129
+ ├── tailwind.config.ts
130
+ └── tailwind.config.js
131
+ ```
132
+
133
+ ### Loading Configuration
134
+
135
+ ```typescript
136
+ (async () => {
137
+ const config = await loadConfig({ cwd: './my-project' })
138
+ console.log(config)
139
+ })()
140
+ ```
141
+
142
+ ---
143
+
144
+ ## Error Handling
145
+
146
+ The `loadConfig` function does not throw an error if no configuration is found. Instead, it resolves to `undefined`. This ensures compatibility with projects where Tailwind configuration is optional or dynamically generated.
147
+
148
+ ---
149
+
150
+ ## Contributing
151
+
152
+ Contributions are welcome! To get started:
153
+
154
+ 1. Fork this repository.
155
+ 2. Create a new branch for your feature or bug fix.
156
+ 3. Submit a pull request with a clear description of your changes.
157
+
158
+ ---
159
+
160
+ ## License
161
+
162
+ This project is licensed under the [MIT License](../../LICENSE).
package/dist/index.cjs ADDED
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ loadConfig: () => loadConfig
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // ../../node_modules/.pnpm/tsup@8.3.5_jiti@2.4.1_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/cjs_shims.js
38
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
39
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+
41
+ // src/index.ts
42
+ var import_node_path = __toESM(require("path"), 1);
43
+ var import_node_process = __toESM(require("process"), 1);
44
+ var import_jiti = require("jiti");
45
+ var import_lilconfig = require("lilconfig");
46
+
47
+ // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
48
+ function isPlainObject(value) {
49
+ if (value === null || typeof value !== "object") {
50
+ return false;
51
+ }
52
+ const prototype = Object.getPrototypeOf(value);
53
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
54
+ return false;
55
+ }
56
+ if (Symbol.iterator in value) {
57
+ return false;
58
+ }
59
+ if (Symbol.toStringTag in value) {
60
+ return Object.prototype.toString.call(value) === "[object Module]";
61
+ }
62
+ return true;
63
+ }
64
+ function _defu(baseObject, defaults, namespace = ".", merger) {
65
+ if (!isPlainObject(defaults)) {
66
+ return _defu(baseObject, {}, namespace, merger);
67
+ }
68
+ const object = Object.assign({}, defaults);
69
+ for (const key in baseObject) {
70
+ if (key === "__proto__" || key === "constructor") {
71
+ continue;
72
+ }
73
+ const value = baseObject[key];
74
+ if (value === null || value === void 0) {
75
+ continue;
76
+ }
77
+ if (merger && merger(object, key, value, namespace)) {
78
+ continue;
79
+ }
80
+ if (Array.isArray(value) && Array.isArray(object[key])) {
81
+ object[key] = [...value, ...object[key]];
82
+ } else if (isPlainObject(value) && isPlainObject(object[key])) {
83
+ object[key] = _defu(
84
+ value,
85
+ object[key],
86
+ (namespace ? `${namespace}.` : "") + key.toString(),
87
+ merger
88
+ );
89
+ } else {
90
+ object[key] = value;
91
+ }
92
+ }
93
+ return object;
94
+ }
95
+ function createDefu(merger) {
96
+ return (...arguments_) => (
97
+ // eslint-disable-next-line unicorn/no-array-reduce
98
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
99
+ );
100
+ }
101
+ var defu = createDefu();
102
+ var defuFn = createDefu((object, key, currentValue) => {
103
+ if (object[key] !== void 0 && typeof currentValue === "function") {
104
+ object[key] = currentValue(object[key]);
105
+ return true;
106
+ }
107
+ });
108
+ var defuArrayFn = createDefu((object, key, currentValue) => {
109
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
110
+ object[key] = currentValue(object[key]);
111
+ return true;
112
+ }
113
+ });
114
+
115
+ // src/utils.ts
116
+ var defuOverrideArray = createDefu((obj, key, value) => {
117
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
118
+ obj[key] = value;
119
+ return true;
120
+ }
121
+ });
122
+
123
+ // src/index.ts
124
+ var jiti = (0, import_jiti.createJiti)(importMetaUrl);
125
+ var moduleName = "tailwind";
126
+ async function loadConfig(options) {
127
+ const { config, cwd } = defuOverrideArray(options, {
128
+ cwd: import_node_process.default.cwd()
129
+ });
130
+ const searcher = (0, import_lilconfig.lilconfig)("tailwindcss", {
131
+ searchPlaces: [
132
+ `${moduleName}.config.js`,
133
+ `${moduleName}.config.cjs`,
134
+ `${moduleName}.config.mjs`,
135
+ `${moduleName}.config.ts`,
136
+ `${moduleName}.config.cts`,
137
+ `${moduleName}.config.mts`
138
+ ],
139
+ loaders: {
140
+ ".js": jiti,
141
+ ".cjs": jiti,
142
+ ".mjs": jiti,
143
+ ".ts": jiti,
144
+ ".cts": jiti,
145
+ ".mts": jiti
146
+ }
147
+ });
148
+ if (typeof config === "string" && config) {
149
+ const configPath = import_node_path.default.isAbsolute(config) ? config : import_node_path.default.resolve(cwd, config);
150
+ const result = await searcher.load(configPath);
151
+ return result?.config;
152
+ } else {
153
+ const result = await searcher.search(cwd);
154
+ return result?.config;
155
+ }
156
+ }
157
+ // Annotate the CommonJS export names for ESM import in node:
158
+ 0 && (module.exports = {
159
+ loadConfig
160
+ });
@@ -0,0 +1,9 @@
1
+ import * as tailwindcss_types_config from 'tailwindcss/types/config';
2
+
3
+ interface LoadConfigOptions {
4
+ cwd: string;
5
+ config: string;
6
+ }
7
+ declare function loadConfig(options?: Partial<LoadConfigOptions>): Promise<tailwindcss_types_config.Config | undefined>;
8
+
9
+ export { type LoadConfigOptions, loadConfig };
@@ -0,0 +1,9 @@
1
+ import * as tailwindcss_types_config from 'tailwindcss/types/config';
2
+
3
+ interface LoadConfigOptions {
4
+ cwd: string;
5
+ config: string;
6
+ }
7
+ declare function loadConfig(options?: Partial<LoadConfigOptions>): Promise<tailwindcss_types_config.Config | undefined>;
8
+
9
+ export { type LoadConfigOptions, loadConfig };
package/dist/index.js ADDED
@@ -0,0 +1,119 @@
1
+ // src/index.ts
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ import { createJiti } from "jiti";
5
+ import { lilconfig } from "lilconfig";
6
+
7
+ // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
8
+ function isPlainObject(value) {
9
+ if (value === null || typeof value !== "object") {
10
+ return false;
11
+ }
12
+ const prototype = Object.getPrototypeOf(value);
13
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
14
+ return false;
15
+ }
16
+ if (Symbol.iterator in value) {
17
+ return false;
18
+ }
19
+ if (Symbol.toStringTag in value) {
20
+ return Object.prototype.toString.call(value) === "[object Module]";
21
+ }
22
+ return true;
23
+ }
24
+ function _defu(baseObject, defaults, namespace = ".", merger) {
25
+ if (!isPlainObject(defaults)) {
26
+ return _defu(baseObject, {}, namespace, merger);
27
+ }
28
+ const object = Object.assign({}, defaults);
29
+ for (const key in baseObject) {
30
+ if (key === "__proto__" || key === "constructor") {
31
+ continue;
32
+ }
33
+ const value = baseObject[key];
34
+ if (value === null || value === void 0) {
35
+ continue;
36
+ }
37
+ if (merger && merger(object, key, value, namespace)) {
38
+ continue;
39
+ }
40
+ if (Array.isArray(value) && Array.isArray(object[key])) {
41
+ object[key] = [...value, ...object[key]];
42
+ } else if (isPlainObject(value) && isPlainObject(object[key])) {
43
+ object[key] = _defu(
44
+ value,
45
+ object[key],
46
+ (namespace ? `${namespace}.` : "") + key.toString(),
47
+ merger
48
+ );
49
+ } else {
50
+ object[key] = value;
51
+ }
52
+ }
53
+ return object;
54
+ }
55
+ function createDefu(merger) {
56
+ return (...arguments_) => (
57
+ // eslint-disable-next-line unicorn/no-array-reduce
58
+ arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
59
+ );
60
+ }
61
+ var defu = createDefu();
62
+ var defuFn = createDefu((object, key, currentValue) => {
63
+ if (object[key] !== void 0 && typeof currentValue === "function") {
64
+ object[key] = currentValue(object[key]);
65
+ return true;
66
+ }
67
+ });
68
+ var defuArrayFn = createDefu((object, key, currentValue) => {
69
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
70
+ object[key] = currentValue(object[key]);
71
+ return true;
72
+ }
73
+ });
74
+
75
+ // src/utils.ts
76
+ var defuOverrideArray = createDefu((obj, key, value) => {
77
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
78
+ obj[key] = value;
79
+ return true;
80
+ }
81
+ });
82
+
83
+ // src/index.ts
84
+ var jiti = createJiti(import.meta.url);
85
+ var moduleName = "tailwind";
86
+ async function loadConfig(options) {
87
+ const { config, cwd } = defuOverrideArray(options, {
88
+ cwd: process.cwd()
89
+ });
90
+ const searcher = lilconfig("tailwindcss", {
91
+ searchPlaces: [
92
+ `${moduleName}.config.js`,
93
+ `${moduleName}.config.cjs`,
94
+ `${moduleName}.config.mjs`,
95
+ `${moduleName}.config.ts`,
96
+ `${moduleName}.config.cts`,
97
+ `${moduleName}.config.mts`
98
+ ],
99
+ loaders: {
100
+ ".js": jiti,
101
+ ".cjs": jiti,
102
+ ".mjs": jiti,
103
+ ".ts": jiti,
104
+ ".cts": jiti,
105
+ ".mts": jiti
106
+ }
107
+ });
108
+ if (typeof config === "string" && config) {
109
+ const configPath = path.isAbsolute(config) ? config : path.resolve(cwd, config);
110
+ const result = await searcher.load(configPath);
111
+ return result?.config;
112
+ } else {
113
+ const result = await searcher.search(cwd);
114
+ return result?.config;
115
+ }
116
+ }
117
+ export {
118
+ loadConfig
119
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "tailwindcss-config",
3
+ "type": "module",
4
+ "version": "0.0.0",
5
+ "description": "load tailwindcss config function",
6
+ "author": "ice breaker <1324318532@qq.com>",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/sonofmagic/weapp-tailwindcss.git",
11
+ "directory": "packages/tailwindcss-config"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/sonofmagic/weapp-tailwindcss/issues"
15
+ },
16
+ "keywords": [
17
+ "tailwindcss",
18
+ "config",
19
+ "loader"
20
+ ],
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "dependencies": {
33
+ "jiti": "^2.4.1",
34
+ "lilconfig": "^3.1.3"
35
+ },
36
+ "scripts": {
37
+ "dev": "tsup --watch --sourcemap",
38
+ "build": "tsup",
39
+ "test": "vitest run",
40
+ "test:dev": "vitest",
41
+ "release": "pnpm publish",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint . --fix"
44
+ },
45
+ "main": "./dist/index.cjs",
46
+ "module": "./dist/index.js",
47
+ "types": "./dist/index.d.ts"
48
+ }