@weapp-tailwindcss/init 1.0.11 → 1.0.12-next.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/README.md CHANGED
@@ -15,7 +15,6 @@
15
15
 
16
16
  ![star](https://badgen.net/github/stars/sonofmagic/weapp-tailwindcss)
17
17
  ![dm0](https://badgen.net/npm/dm/weapp-tailwindcss)
18
- ![dm1](https://badgen.net/npm/dm/weapp-tailwindcss-webpack-plugin)
19
18
  ![license](https://badgen.net/npm/license/weapp-tailwindcss)
20
19
  [![test](https://github.com/sonofmagic/weapp-tailwindcss/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/sonofmagic/weapp-tailwindcss/actions/workflows/test.yml)
21
20
  [![codecov](https://codecov.io/gh/sonofmagic/weapp-tailwindcss/branch/main/graph/badge.svg?token=zn05qXYznt)](https://codecov.io/gh/sonofmagic/weapp-tailwindcss)
@@ -55,12 +54,12 @@
55
54
 
56
55
  ## 版本对应
57
56
 
58
- 目前,`weapp-tailwindcss` 的 `4.x` 版本
57
+ 目前,`weapp-tailwindcss` 的 `5.x` 版本
59
58
 
60
- - 支持最新版本的 `tailwindcss v4` 和 `v3` 还有 `v2 jit` 版本。
61
- - 支持 `webpack5`,`webpack4`, `vite` 和 `gulp` 这些打包工具,也支持纯 `Nodejs` API 的方式,集成到你自己的构建工具中。
59
+ - 支持最新版本的 `tailwindcss v4` 和 `v3`。
60
+ - 支持 `webpack5`、`vite`、`rspack`、`rollup`、`rolldown` 和 `gulp` 这些打包工具,也支持纯 `Nodejs` API 的方式,集成到你自己的构建工具中。
62
61
 
63
- > 如果你还在使用 `tailwindcss@2` 版本,那你应该使用从 `weapp-tailwindcss/webpack4` 导出的本插件的 `postcss7` `webpack4` 版本。另外请确保你的 `nodejs` 版本 `>=16.6.0`。目前低于 `16` 的长期维护版本(`偶数版本`) 都已经结束了生命周期,建议安装 `nodejs` 的 `LTS` 版本,详见 [nodejs/release](https://github.com/nodejs/release)
62
+ > `weapp-tailwindcss@5` 面向 Tailwind CSS v3/v4 和现代构建链路,不再内置 Webpack4、PostCSS7、Tailwind CSS v2 兼容入口。`weapp-tailwindcss@5` 需要 `nodejs` 版本 `^20.19.0 || >=22.12.0`,建议安装 `nodejs` 的 `LTS` 版本,详见 [nodejs/release](https://github.com/nodejs/release)
64
63
 
65
64
  ## [安装与使用方式](https://tw.icebreaker.top/docs/quick-start/install)
66
65
 
package/dist/index.d.ts CHANGED
@@ -1,39 +1,344 @@
1
- import { PackageJson } from 'pkg-types';
2
- import { Options } from 'npm-registry-fetch';
1
+ import { Options } from "npm-registry-fetch";
3
2
 
3
+ //#region ../../node_modules/.pnpm/pkg-types@2.3.1/node_modules/pkg-types/dist/index.d.mts
4
+ //#endregion
5
+ //#region src/packagejson/types.d.ts
6
+ interface PackageJson {
7
+ /**
8
+ * The name is what your thing is called.
9
+ * Some rules:
10
+ * - The name must be less than or equal to 214 characters. This includes the scope for scoped packages.
11
+ * - The name can’t start with a dot or an underscore.
12
+ * - New packages must not have uppercase letters in the name.
13
+ * - The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can’t contain any non-URL-safe characters.
14
+ */
15
+ name?: string;
16
+ /**
17
+ * Version must be parseable by `node-semver`, which is bundled with npm as a dependency. (`npm install semver` to use it yourself.)
18
+ */
19
+ version?: string;
20
+ /**
21
+ * Put a description in it. It’s a string. This helps people discover your package, as it’s listed in `npm search`.
22
+ */
23
+ description?: string;
24
+ /**
25
+ * Put keywords in it. It’s an array of strings. This helps people discover your package as it’s listed in `npm search`.
26
+ */
27
+ keywords?: string[];
28
+ /**
29
+ * The url to the project homepage.
30
+ */
31
+ homepage?: string;
32
+ /**
33
+ * The url to your project’s issue tracker and / or the email address to which issues should be reported. These are helpful for people who encounter issues with your package.
34
+ */
35
+ bugs?: string | {
36
+ url?: string;
37
+ email?: string;
38
+ };
39
+ /**
40
+ * You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you’re placing on it.
41
+ */
42
+ license?: string;
43
+ /**
44
+ * Specify the place where your code lives. This is helpful for people who want to contribute. If the git repo is on GitHub, then the `npm docs` command will be able to find you.
45
+ * For GitHub, GitHub gist, Bitbucket, or GitLab repositories you can use the same shortcut syntax you use for npm install:
46
+ */
47
+ repository?: string | {
48
+ type: string;
49
+ url: string;
50
+ /**
51
+ * If the `package.json` for your package is not in the root directory (for example if it is part of a monorepo), you can specify the directory in which it lives:
52
+ */
53
+ directory?: string;
54
+ };
55
+ /**
56
+ * The `scripts` field is a dictionary containing script commands that are run at various times in the lifecycle of your package.
57
+ */
58
+ scripts?: PackageJsonScripts;
59
+ /**
60
+ * If you set `"private": true` in your package.json, then npm will refuse to publish it.
61
+ */
62
+ private?: boolean;
63
+ /**
64
+ * The “author” is one person.
65
+ */
66
+ author?: PackageJsonPerson;
67
+ /**
68
+ * “contributors” is an array of people.
69
+ */
70
+ contributors?: PackageJsonPerson[];
71
+ /**
72
+ * An object containing a URL that provides up-to-date information
73
+ * about ways to help fund development of your package,
74
+ * a string URL, or an array of objects and string URLs
75
+ */
76
+ funding?: PackageJsonFunding | PackageJsonFunding[];
77
+ /**
78
+ * The optional `files` field is an array of file patterns that describes the entries to be included when your package is installed as a dependency. File patterns follow a similar syntax to `.gitignore`, but reversed: including a file, directory, or glob pattern (`*`, `**\/*`, and such) will make it so that file is included in the tarball when it’s packed. Omitting the field will make it default to `["*"]`, which means it will include all files.
79
+ */
80
+ files?: string[];
81
+ /**
82
+ * The main field is a module ID that is the primary entry point to your program. That is, if your package is named `foo`, and a user installs it, and then does `require("foo")`, then your main module’s exports object will be returned.
83
+ * This should be a module ID relative to the root of your package folder.
84
+ * For most modules, it makes the most sense to have a main script and often not much else.
85
+ */
86
+ main?: string;
87
+ /**
88
+ * If your module is meant to be used client-side the browser field should be used instead of the main field. This is helpful to hint users that it might rely on primitives that aren’t available in Node.js modules. (e.g. window)
89
+ */
90
+ browser?: string | Record<string, string | false>;
91
+ /**
92
+ * The `unpkg` field is used to specify the URL to a UMD module for your package. This is used by default in the unpkg.com CDN service.
93
+ */
94
+ unpkg?: string;
95
+ /**
96
+ * A map of command name to local file name. On install, npm will symlink that file into `prefix/bin` for global installs, or `./node_modules/.bin/` for local installs.
97
+ */
98
+ bin?: string | Record<string, string>;
99
+ /**
100
+ * Specify either a single file or an array of filenames to put in place for the `man` program to find.
101
+ */
102
+ man?: string | string[];
103
+ /**
104
+ * Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.
105
+ */
106
+ dependencies?: Record<string, string>;
107
+ /**
108
+ * If someone is planning on downloading and using your module in their program, then they probably don’t want or need to download and build the external test or documentation framework that you use.
109
+ * In this case, it’s best to map these additional items in a `devDependencies` object.
110
+ */
111
+ devDependencies?: Record<string, string>;
112
+ /**
113
+ * If a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the `optionalDependencies` object. This is a map of package name to version or url, just like the `dependencies` object. The difference is that build failures do not cause installation to fail.
114
+ */
115
+ optionalDependencies?: Record<string, string>;
116
+ /**
117
+ * In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a `require` of this host. This is usually referred to as a plugin. Notably, your module may be exposing a specific interface, expected and specified by the host documentation.
118
+ */
119
+ peerDependencies?: Record<string, string>;
120
+ /**
121
+ * TypeScript typings, typically ending by `.d.ts`.
122
+ */
123
+ types?: string;
124
+ /**
125
+ * This field is synonymous with `types`.
126
+ */
127
+ typings?: string;
128
+ /**
129
+ * Non-Standard Node.js alternate entry-point to main.
130
+ * An initial implementation for supporting CJS packages (from main), and use module for ESM modules.
131
+ */
132
+ module?: string;
133
+ /**
134
+ * Make main entry-point be loaded as an ESM module, support "export" syntax instead of "require"
135
+ *
136
+ * Docs:
137
+ * - https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_package_json_type_field
138
+ *
139
+ * @default 'commonjs'
140
+ * @since Node.js v14
141
+ */
142
+ type?: "module" | "commonjs";
143
+ /**
144
+ * Alternate and extensible alternative to "main" entry point.
145
+ *
146
+ * When using `{type: "module"}`, any ESM module file MUST end with `.mjs` extension.
147
+ *
148
+ * Docs:
149
+ * - https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_exports_sugar
150
+ *
151
+ * @since Node.js v12.7
152
+ */
153
+ exports?: PackageJsonExports;
154
+ /**
155
+ * Docs:
156
+ * - https://nodejs.org/api/packages.html#imports
157
+ */
158
+ imports?: Record<string, string | Record<string, string>>;
159
+ /**
160
+ * The field is used to define a set of sub-packages (or workspaces) within a monorepo.
161
+ *
162
+ * This field is an array of glob patterns or an object with specific configurations for managing
163
+ * multiple packages in a single repository.
164
+ */
165
+ workspaces?: string[] | {
166
+ /**
167
+ * Workspace package paths. Glob patterns are supported.
168
+ */
169
+ packages?: string[];
170
+ /**
171
+ * Packages to block from hoisting to the workspace root.
172
+ * Uses glob patterns to match module paths in the dependency tree.
173
+ *
174
+ * Docs:
175
+ * - https://classic.yarnpkg.com/blog/2018/02/15/nohoist/
176
+ */
177
+ nohoist?: string[];
178
+ };
179
+ /**
180
+ * The field is used to specify different TypeScript declaration files for
181
+ * different versions of TypeScript, allowing for version-specific type definitions.
182
+ */
183
+ typesVersions?: Record<string, Record<string, string[]>>;
184
+ /**
185
+ * You can specify which operating systems your module will run on:
186
+ * ```json
187
+ * {
188
+ * "os": ["darwin", "linux"]
189
+ * }
190
+ * ```
191
+ * You can also block instead of allowing operating systems, just prepend the blocked os with a '!':
192
+ * ```json
193
+ * {
194
+ * "os": ["!win32"]
195
+ * }
196
+ * ```
197
+ * The host operating system is determined by `process.platform`
198
+ * It is allowed to both block and allow an item, although there isn't any good reason to do this.
199
+ */
200
+ os?: string[];
201
+ /**
202
+ * If your code only runs on certain cpu architectures, you can specify which ones.
203
+ * ```json
204
+ * {
205
+ * "cpu": ["x64", "ia32"]
206
+ * }
207
+ * ```
208
+ * Like the `os` option, you can also block architectures:
209
+ * ```json
210
+ * {
211
+ * "cpu": ["!arm", "!mips"]
212
+ * }
213
+ * ```
214
+ * The host architecture is determined by `process.arch`
215
+ */
216
+ cpu?: string[];
217
+ /**
218
+ * This is a set of config values that will be used at publish-time.
219
+ */
220
+ publishConfig?: {
221
+ /**
222
+ * The registry that will be used if the package is published.
223
+ */
224
+ registry?: string;
225
+ /**
226
+ * The tag that will be used if the package is published.
227
+ */
228
+ tag?: string;
229
+ /**
230
+ * The access level that will be used if the package is published.
231
+ */
232
+ access?: "public" | "restricted";
233
+ /**
234
+ * **pnpm-only**
235
+ *
236
+ * By default, for portability reasons, no files except those listed in
237
+ * the bin field will be marked as executable in the resulting package
238
+ * archive. The executableFiles field lets you declare additional fields
239
+ * that must have the executable flag (+x) set even if
240
+ * they aren't directly accessible through the bin field.
241
+ */
242
+ executableFiles?: string[];
243
+ /**
244
+ * **pnpm-only**
245
+ *
246
+ * You also can use the field `publishConfig.directory` to customize
247
+ * the published subdirectory relative to the current `package.json`.
248
+ *
249
+ * It is expected to have a modified version of the current package in
250
+ * the specified directory (usually using third party build tools).
251
+ */
252
+ directory?: string;
253
+ /**
254
+ * **pnpm-only**
255
+ *
256
+ * When set to `true`, the project will be symlinked from the
257
+ * `publishConfig.directory` location during local development.
258
+ * @default true
259
+ */
260
+ linkDirectory?: boolean;
261
+ } & Pick<PackageJson, "bin" | "main" | "exports" | "types" | "typings" | "module" | "browser" | "unpkg" | "typesVersions" | "os" | "cpu">;
262
+ /**
263
+ * See: https://nodejs.org/api/packages.html#packagemanager
264
+ * This field defines which package manager is expected to be used when working on the current project.
265
+ * Should be of the format: `<name>@<version>[#hash]`
266
+ */
267
+ packageManager?: string;
268
+ [key: string]: any;
269
+ }
270
+ /**
271
+ * See: https://docs.npmjs.com/cli/v11/using-npm/scripts#pre--post-scripts
272
+ */
273
+ type PackageJsonScriptWithPreAndPost<S extends string> = S | `${"pre" | "post"}${S}`;
274
+ /**
275
+ * See: https://docs.npmjs.com/cli/v11/using-npm/scripts#life-cycle-operation-order
276
+ */
277
+ type PackageJsonNpmLifeCycleScripts = "dependencies" | "prepublishOnly" | PackageJsonScriptWithPreAndPost<"install" | "pack" | "prepare" | "publish" | "restart" | "start" | "stop" | "test" | "version">;
278
+ /**
279
+ * See: https://pnpm.io/scripts#lifecycle-scripts
280
+ */
281
+ type PackageJsonPnpmLifeCycleScripts = "pnpm:devPreinstall";
282
+ type PackageJsonCommonScripts = "build" | "coverage" | "deploy" | "dev" | "format" | "lint" | "preview" | "release" | "typecheck" | "watch";
283
+ type PackageJsonScriptName = PackageJsonCommonScripts | PackageJsonNpmLifeCycleScripts | PackageJsonPnpmLifeCycleScripts | (string & {});
284
+ type PackageJsonScripts = { [P in PackageJsonScriptName]?: string };
285
+ /**
286
+ * A “person” is an object with a “name” field and optionally “url” and “email”. Or you can shorten that all into a single string, and npm will parse it for you.
287
+ */
288
+ type PackageJsonPerson = string | {
289
+ name: string;
290
+ email?: string;
291
+ url?: string;
292
+ };
293
+ type PackageJsonFunding = string | {
294
+ url: string;
295
+ type?: string;
296
+ };
297
+ type PackageJsonExportKey = "." | "import" | "require" | "types" | "node" | "browser" | "default" | (string & {});
298
+ type PackageJsonExportsObject = { [P in PackageJsonExportKey]?: string | PackageJsonExportsObject | Array<string | PackageJsonExportsObject> };
299
+ type PackageJsonExports = string | PackageJsonExportsObject | Array<string | PackageJsonExportsObject>; //#endregion
300
+ //#region src/packagejson/utils.d.ts
301
+ /**
302
+ * Defines a PackageJson structure.
303
+ * @param pkg - The `package.json` content as an object. See {@link PackageJson}.
304
+ * @returns the same `package.json` object.
305
+ */
306
+ //#endregion
307
+ //#region src/npm.d.ts
4
308
  type FetchOptions = Options;
5
-
309
+ //#endregion
310
+ //#region src/index.d.ts
6
311
  interface CreateContextOptions {
7
- cwd: string;
8
- pkgJsonBasename?: string;
9
- postcssConfigBasename?: string;
10
- tailwindConfigBasename?: string;
11
- fetchOptions?: FetchOptions;
312
+ cwd: string;
313
+ pkgJsonBasename?: string;
314
+ postcssConfigBasename?: string;
315
+ tailwindConfigBasename?: string;
316
+ fetchOptions?: FetchOptions;
12
317
  }
13
318
  declare function createContext(options: Required<CreateContextOptions>): Promise<{
14
- pkgJson: PackageJson;
15
- pkgJsonPath: string;
16
- cwd: string;
17
- versions: {
18
- tailwindcss: string;
19
- postcss: string;
20
- autoprefixer: string;
21
- 'weapp-tailwindcss': string;
22
- };
23
- postcssConfigBasename: string;
24
- tailwindConfigBasename: string;
25
- readonly type: "module" | "commonjs" | undefined;
319
+ pkgJson: PackageJson;
320
+ pkgJsonPath: string;
321
+ cwd: string;
322
+ versions: {
323
+ tailwindcss: string;
324
+ postcss: string;
325
+ autoprefixer: string;
326
+ 'weapp-tailwindcss': string;
327
+ };
328
+ postcssConfigBasename: string;
329
+ tailwindConfigBasename: string;
330
+ readonly type: "module" | "commonjs" | undefined;
26
331
  } | undefined>;
27
332
  type Context = Exclude<Awaited<ReturnType<typeof createContext>>, undefined>;
28
333
  declare function updatePackageJson(ctx: Context): Promise<void>;
29
334
  declare function touchPostcssConfig(ctx: Context): Promise<void>;
30
335
  declare function touchTailwindConfig(ctx: Context): Promise<void>;
31
336
  declare function getInitDefaults(): {
32
- cwd: string;
33
- postcssConfigBasename: string;
34
- tailwindConfigBasename: string;
35
- pkgJsonBasename: string;
337
+ cwd: string;
338
+ postcssConfigBasename: string;
339
+ tailwindConfigBasename: string;
340
+ pkgJsonBasename: string;
36
341
  };
37
342
  declare function init(options?: CreateContextOptions): Promise<void>;
38
-
39
- export { type Context, type CreateContextOptions, createContext, getInitDefaults, init, touchPostcssConfig, touchTailwindConfig, updatePackageJson };
343
+ //#endregion
344
+ export { Context, CreateContextOptions, createContext, getInitDefaults, init, touchPostcssConfig, touchTailwindConfig, updatePackageJson };
package/dist/index.js CHANGED
@@ -1,126 +1,136 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/index.ts
2
- var _process = require('process'); var _process2 = _interopRequireDefault(_process);
3
- var _logger = require('@weapp-tailwindcss/logger');
4
- var _shared = require('@weapp-tailwindcss/shared');
5
- var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
6
- var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
7
-
8
- // src/npm.ts
9
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let node_process = require("node:process");
25
+ node_process = __toESM(node_process);
26
+ let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
27
+ let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
28
+ let fs_extra = require("fs-extra");
29
+ fs_extra = __toESM(fs_extra);
30
+ let pathe = require("pathe");
31
+ pathe = __toESM(pathe);
32
+ //#region src/npm.ts
33
+ /**
34
+ * @example 'https://registry.npmjs.org'
35
+ * @example 'https://registry.npmmirror.com'
36
+ */
10
37
  function fetchPackage(packageName, options) {
11
- const opts = _shared.defu.call(void 0, options, {
12
- // 默认使用国内镜像地址
13
- registry: "https://registry.npmmirror.com"
14
- });
15
- return Promise.resolve().then(() => _interopRequireWildcard(require("npm-registry-fetch"))).then(({ json }) => {
16
- return json(`/${packageName}`, opts);
17
- });
38
+ const opts = (0, _weapp_tailwindcss_shared.defu)(options, { registry: "https://registry.npmmirror.com" });
39
+ return import("npm-registry-fetch").then(({ json }) => {
40
+ return json(`/${packageName}`, opts);
41
+ });
18
42
  }
19
43
  async function getLatestVersionInRange(packageName, versionRange, options) {
20
- const response = await fetchPackage(packageName, options);
21
- const versions = Object.keys(response.versions);
22
- const filteredVersions = versions.filter((version) => version.startsWith(versionRange));
23
- return filteredVersions.at(-1);
44
+ const response = await fetchPackage(packageName, options);
45
+ return Object.keys(response.versions).filter((version) => version.startsWith(versionRange)).at(-1);
24
46
  }
25
- var defaultDevDeps = {
26
- "tailwindcss": "3",
27
- "postcss": "8",
28
- "autoprefixer": "10",
29
- "weapp-tailwindcss": "3"
47
+ const defaultDevDeps = {
48
+ "tailwindcss": "3",
49
+ "postcss": "8",
50
+ "autoprefixer": "10",
51
+ "weapp-tailwindcss": "3"
30
52
  };
31
53
  async function getDevDepsVersions(options) {
32
- return Object.fromEntries(await Promise.all(
33
- Object.entries(defaultDevDeps).map(
34
- async (x) => {
35
- return [x[0], `^${await getLatestVersionInRange(...x, options)}`];
36
- }
37
- )
38
- ));
54
+ return Object.fromEntries(await Promise.all(Object.entries(defaultDevDeps).map(async (x) => {
55
+ return [x[0], `^${await getLatestVersionInRange(...x, options)}`];
56
+ })));
39
57
  }
40
-
41
- // src/index.ts
58
+ //#endregion
59
+ //#region src/index.ts
42
60
  async function createContext(options) {
43
- const { cwd, pkgJsonBasename, postcssConfigBasename, tailwindConfigBasename, fetchOptions } = options;
44
- const pkgJsonPath = _pathe2.default.resolve(cwd, pkgJsonBasename);
45
- if (await _fsextra2.default.exists(pkgJsonPath)) {
46
- const pkgJson = await _fsextra2.default.readJson(pkgJsonPath);
47
- const versions = await getDevDepsVersions(fetchOptions);
48
- return {
49
- pkgJson,
50
- pkgJsonPath,
51
- cwd,
52
- versions,
53
- postcssConfigBasename,
54
- tailwindConfigBasename,
55
- get type() {
56
- return pkgJson.type;
57
- }
58
- };
59
- } else {
60
- _logger.logger.warn("\u5F53\u524D\u76EE\u5F55\u4E0B\u4E0D\u5B58\u5728 `package.json` \u6587\u4EF6\uFF0C\u521D\u59CB\u5316\u811A\u672C\u5C06\u88AB\u8DF3\u8FC7\uFF0C\u8BF7\u6267\u884C `npm init` \u6216\u624B\u52A8\u521B\u5EFA `package.json` \u540E\u91CD\u8BD5 ");
61
- }
61
+ const { cwd, pkgJsonBasename, postcssConfigBasename, tailwindConfigBasename, fetchOptions } = options;
62
+ const pkgJsonPath = pathe.default.resolve(cwd, pkgJsonBasename);
63
+ if (await fs_extra.default.exists(pkgJsonPath)) {
64
+ const pkgJson = await fs_extra.default.readJson(pkgJsonPath);
65
+ return {
66
+ pkgJson,
67
+ pkgJsonPath,
68
+ cwd,
69
+ versions: await getDevDepsVersions(fetchOptions),
70
+ postcssConfigBasename,
71
+ tailwindConfigBasename,
72
+ get type() {
73
+ return pkgJson.type;
74
+ }
75
+ };
76
+ } else _weapp_tailwindcss_logger.logger.warn("当前目录下不存在 `package.json` 文件,初始化脚本将被跳过,请执行 `npm init` 或手动创建 `package.json` 后重试 ");
62
77
  }
63
78
  async function updatePackageJson(ctx) {
64
- _shared.setValue.call(void 0, ctx.pkgJson, "scripts.postinstall", "weapp-tw patch");
65
- for (const [key, value] of Object.entries(ctx.versions)) {
66
- _shared.setValue.call(void 0, ctx.pkgJson, `devDependencies.${key}`, value);
67
- }
68
- await _fsextra2.default.writeJSON(ctx.pkgJsonPath, ctx.pkgJson, { spaces: 2 });
79
+ for (const [key, value] of Object.entries(ctx.versions)) (0, _weapp_tailwindcss_shared.setValue)(ctx.pkgJson, `devDependencies.${key}`, value);
80
+ await fs_extra.default.writeJSON(ctx.pkgJsonPath, ctx.pkgJson, { spaces: 2 });
69
81
  }
70
82
  async function touchPostcssConfig(ctx) {
71
- const data = `${ctx.type === "module" ? "export default " : "module.exports = "}{
83
+ const data = `${ctx.type === "module" ? "export default " : "module.exports = "}{
72
84
  plugins: {
73
- tailwindcss: {},
74
- // \u5047\u5982\u6846\u67B6\u5DF2\u7ECF\u5185\u7F6E\u4E86 \`autoprefixer\`\uFF0C\u53EF\u4EE5\u53BB\u9664\u4E0B\u4E00\u884C
85
+ // Tailwind CSS 由 weapp-tailwindcss 生成模式接管,这里不要再注册 tailwindcss
86
+ // 假如框架已经内置了 \`autoprefixer\`,可以去除下一行
75
87
  autoprefixer: {},
76
88
  },
77
89
  }
78
90
  `;
79
- await _fsextra2.default.writeFile(_pathe2.default.resolve(ctx.cwd, ctx.postcssConfigBasename), data);
91
+ await fs_extra.default.writeFile(pathe.default.resolve(ctx.cwd, ctx.postcssConfigBasename), data);
80
92
  }
81
93
  async function touchTailwindConfig(ctx) {
82
- const data = `/** @type {import('tailwindcss').Config} */
94
+ const data = `/** @type {import('tailwindcss').Config} */
83
95
  ${ctx.type === "module" ? "export default " : "module.exports = "}{
84
- // \u8FD9\u91CC\u7ED9\u51FA\u4E86\u4E00\u4EFD uni-app /taro \u901A\u7528\u793A\u4F8B\uFF0C\u5177\u4F53\u8981\u6839\u636E\u4F60\u81EA\u5DF1\u9879\u76EE\u7684\u76EE\u5F55\u7ED3\u6784\u8FDB\u884C\u914D\u7F6E
85
- // \u4E0D\u5728 content \u5305\u62EC\u7684\u6587\u4EF6\u5185\uFF0C\u4F60\u7F16\u5199\u7684 class\uFF0C\u662F\u4E0D\u4F1A\u751F\u6210\u5BF9\u5E94\u7684css\u5DE5\u5177\u7C7B\u7684
96
+ // 这里给出了一份 uni-app /taro 通用示例,具体要根据你自己项目的目录结构进行配置
97
+ // 不在 content 包括的文件内,你编写的 class,是不会生成对应的css工具类的
86
98
  content: ['./public/index.html', './src/**/*.{wxml,html,js,ts,jsx,tsx,vue}'],
87
- // \u5176\u4ED6\u914D\u7F6E\u9879
99
+ // 其他配置项
88
100
  // ...
89
101
  corePlugins: {
90
- // \u5C0F\u7A0B\u5E8F\u4E0D\u9700\u8981 preflight \u548C container\uFF0C\u56E0\u4E3A\u8FD9\u4E3B\u8981\u662F\u7ED9 h5 \u7684\uFF0C\u5982\u679C\u4F60\u8981\u540C\u65F6\u5F00\u53D1\u5C0F\u7A0B\u5E8F\u548C h5 \u7AEF\uFF0C\u4F60\u5E94\u8BE5\u4F7F\u7528\u73AF\u5883\u53D8\u91CF\u6765\u63A7\u5236\u5B83
102
+ // 小程序不需要 preflight 和 container,因为这主要是给 h5 的,如果你要同时开发小程序和 h5 端,你应该使用环境变量来控制它
91
103
  preflight: false,
92
104
  container: false,
93
105
  },
94
106
  }
95
107
  `;
96
- await _fsextra2.default.writeFile(_pathe2.default.resolve(ctx.cwd, ctx.tailwindConfigBasename), data);
108
+ await fs_extra.default.writeFile(pathe.default.resolve(ctx.cwd, ctx.tailwindConfigBasename), data);
97
109
  }
98
110
  function getInitDefaults() {
99
- return {
100
- cwd: _process2.default.cwd(),
101
- postcssConfigBasename: "postcss.config.js",
102
- tailwindConfigBasename: "tailwind.config.js",
103
- pkgJsonBasename: "package.json"
104
- };
111
+ return {
112
+ cwd: node_process.default.cwd(),
113
+ postcssConfigBasename: "postcss.config.js",
114
+ tailwindConfigBasename: "tailwind.config.js",
115
+ pkgJsonBasename: "package.json"
116
+ };
105
117
  }
106
118
  async function init(options) {
107
- const opts = _shared.defu.call(void 0, options, getInitDefaults());
108
- const ctx = await createContext(opts);
109
- if (ctx) {
110
- await updatePackageJson(ctx);
111
- _logger.logger.success("`package.json` \u6587\u4EF6\u4FEE\u6539\u5B8C\u6210\uFF01");
112
- await touchPostcssConfig(ctx);
113
- _logger.logger.success("`postcss.config.js` \u6587\u4EF6\u521B\u5EFA\u5B8C\u6210\uFF01");
114
- await touchTailwindConfig(ctx);
115
- _logger.logger.success("`tailwind.config.js` \u6587\u4EF6\u521B\u5EFA\u5B8C\u6210\uFF01");
116
- _logger.logger.success("`weapp-tailwindcss` \u521D\u59CB\u5316\u5B8C\u6210\uFF01\u8BF7\u6839\u636E\u4F60\u81EA\u5B9A\u4E49\u7684\u9700\u6C42\uFF0C\u66F4\u6539\u5BF9\u5E94\u7684\u914D\u7F6E\u6587\u4EF6(\u6BD4\u5982 `tailwind.config.js` \u4E2D\u7684 `content` \u914D\u7F6E)");
117
- }
119
+ const ctx = await createContext((0, _weapp_tailwindcss_shared.defu)(options, getInitDefaults()));
120
+ if (ctx) {
121
+ await updatePackageJson(ctx);
122
+ _weapp_tailwindcss_logger.logger.success("`package.json` 文件修改完成!");
123
+ await touchPostcssConfig(ctx);
124
+ _weapp_tailwindcss_logger.logger.success("`postcss.config.js` 文件创建完成!");
125
+ await touchTailwindConfig(ctx);
126
+ _weapp_tailwindcss_logger.logger.success("`tailwind.config.js` 文件创建完成!");
127
+ _weapp_tailwindcss_logger.logger.success("`weapp-tailwindcss` 初始化完成!请根据你自定义的需求,更改对应的配置文件(比如 `tailwind.config.js` 中的 `content` 配置)");
128
+ }
118
129
  }
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
- exports.createContext = createContext; exports.getInitDefaults = getInitDefaults; exports.init = init; exports.touchPostcssConfig = touchPostcssConfig; exports.touchTailwindConfig = touchTailwindConfig; exports.updatePackageJson = updatePackageJson;
130
+ //#endregion
131
+ exports.createContext = createContext;
132
+ exports.getInitDefaults = getInitDefaults;
133
+ exports.init = init;
134
+ exports.touchPostcssConfig = touchPostcssConfig;
135
+ exports.touchTailwindConfig = touchTailwindConfig;
136
+ exports.updatePackageJson = updatePackageJson;
package/dist/index.mjs CHANGED
@@ -1,126 +1,105 @@
1
- // src/index.ts
2
- import process from "process";
1
+ import process from "node:process";
3
2
  import { logger } from "@weapp-tailwindcss/logger";
4
- import { defu as defu2, setValue } from "@weapp-tailwindcss/shared";
3
+ import { defu, setValue } from "@weapp-tailwindcss/shared";
5
4
  import fs from "fs-extra";
6
5
  import path from "pathe";
7
-
8
- // src/npm.ts
9
- import { defu } from "@weapp-tailwindcss/shared";
6
+ //#region src/npm.ts
7
+ /**
8
+ * @example 'https://registry.npmjs.org'
9
+ * @example 'https://registry.npmmirror.com'
10
+ */
10
11
  function fetchPackage(packageName, options) {
11
- const opts = defu(options, {
12
- // 默认使用国内镜像地址
13
- registry: "https://registry.npmmirror.com"
14
- });
15
- return import("npm-registry-fetch").then(({ json }) => {
16
- return json(`/${packageName}`, opts);
17
- });
12
+ const opts = defu(options, { registry: "https://registry.npmmirror.com" });
13
+ return import("npm-registry-fetch").then(({ json }) => {
14
+ return json(`/${packageName}`, opts);
15
+ });
18
16
  }
19
17
  async function getLatestVersionInRange(packageName, versionRange, options) {
20
- const response = await fetchPackage(packageName, options);
21
- const versions = Object.keys(response.versions);
22
- const filteredVersions = versions.filter((version) => version.startsWith(versionRange));
23
- return filteredVersions.at(-1);
18
+ const response = await fetchPackage(packageName, options);
19
+ return Object.keys(response.versions).filter((version) => version.startsWith(versionRange)).at(-1);
24
20
  }
25
- var defaultDevDeps = {
26
- "tailwindcss": "3",
27
- "postcss": "8",
28
- "autoprefixer": "10",
29
- "weapp-tailwindcss": "3"
21
+ const defaultDevDeps = {
22
+ "tailwindcss": "3",
23
+ "postcss": "8",
24
+ "autoprefixer": "10",
25
+ "weapp-tailwindcss": "3"
30
26
  };
31
27
  async function getDevDepsVersions(options) {
32
- return Object.fromEntries(await Promise.all(
33
- Object.entries(defaultDevDeps).map(
34
- async (x) => {
35
- return [x[0], `^${await getLatestVersionInRange(...x, options)}`];
36
- }
37
- )
38
- ));
28
+ return Object.fromEntries(await Promise.all(Object.entries(defaultDevDeps).map(async (x) => {
29
+ return [x[0], `^${await getLatestVersionInRange(...x, options)}`];
30
+ })));
39
31
  }
40
-
41
- // src/index.ts
32
+ //#endregion
33
+ //#region src/index.ts
42
34
  async function createContext(options) {
43
- const { cwd, pkgJsonBasename, postcssConfigBasename, tailwindConfigBasename, fetchOptions } = options;
44
- const pkgJsonPath = path.resolve(cwd, pkgJsonBasename);
45
- if (await fs.exists(pkgJsonPath)) {
46
- const pkgJson = await fs.readJson(pkgJsonPath);
47
- const versions = await getDevDepsVersions(fetchOptions);
48
- return {
49
- pkgJson,
50
- pkgJsonPath,
51
- cwd,
52
- versions,
53
- postcssConfigBasename,
54
- tailwindConfigBasename,
55
- get type() {
56
- return pkgJson.type;
57
- }
58
- };
59
- } else {
60
- logger.warn("\u5F53\u524D\u76EE\u5F55\u4E0B\u4E0D\u5B58\u5728 `package.json` \u6587\u4EF6\uFF0C\u521D\u59CB\u5316\u811A\u672C\u5C06\u88AB\u8DF3\u8FC7\uFF0C\u8BF7\u6267\u884C `npm init` \u6216\u624B\u52A8\u521B\u5EFA `package.json` \u540E\u91CD\u8BD5 ");
61
- }
35
+ const { cwd, pkgJsonBasename, postcssConfigBasename, tailwindConfigBasename, fetchOptions } = options;
36
+ const pkgJsonPath = path.resolve(cwd, pkgJsonBasename);
37
+ if (await fs.exists(pkgJsonPath)) {
38
+ const pkgJson = await fs.readJson(pkgJsonPath);
39
+ return {
40
+ pkgJson,
41
+ pkgJsonPath,
42
+ cwd,
43
+ versions: await getDevDepsVersions(fetchOptions),
44
+ postcssConfigBasename,
45
+ tailwindConfigBasename,
46
+ get type() {
47
+ return pkgJson.type;
48
+ }
49
+ };
50
+ } else logger.warn("当前目录下不存在 `package.json` 文件,初始化脚本将被跳过,请执行 `npm init` 或手动创建 `package.json` 后重试 ");
62
51
  }
63
52
  async function updatePackageJson(ctx) {
64
- setValue(ctx.pkgJson, "scripts.postinstall", "weapp-tw patch");
65
- for (const [key, value] of Object.entries(ctx.versions)) {
66
- setValue(ctx.pkgJson, `devDependencies.${key}`, value);
67
- }
68
- await fs.writeJSON(ctx.pkgJsonPath, ctx.pkgJson, { spaces: 2 });
53
+ for (const [key, value] of Object.entries(ctx.versions)) setValue(ctx.pkgJson, `devDependencies.${key}`, value);
54
+ await fs.writeJSON(ctx.pkgJsonPath, ctx.pkgJson, { spaces: 2 });
69
55
  }
70
56
  async function touchPostcssConfig(ctx) {
71
- const data = `${ctx.type === "module" ? "export default " : "module.exports = "}{
57
+ const data = `${ctx.type === "module" ? "export default " : "module.exports = "}{
72
58
  plugins: {
73
- tailwindcss: {},
74
- // \u5047\u5982\u6846\u67B6\u5DF2\u7ECF\u5185\u7F6E\u4E86 \`autoprefixer\`\uFF0C\u53EF\u4EE5\u53BB\u9664\u4E0B\u4E00\u884C
59
+ // Tailwind CSS 由 weapp-tailwindcss 生成模式接管,这里不要再注册 tailwindcss
60
+ // 假如框架已经内置了 \`autoprefixer\`,可以去除下一行
75
61
  autoprefixer: {},
76
62
  },
77
63
  }
78
64
  `;
79
- await fs.writeFile(path.resolve(ctx.cwd, ctx.postcssConfigBasename), data);
65
+ await fs.writeFile(path.resolve(ctx.cwd, ctx.postcssConfigBasename), data);
80
66
  }
81
67
  async function touchTailwindConfig(ctx) {
82
- const data = `/** @type {import('tailwindcss').Config} */
68
+ const data = `/** @type {import('tailwindcss').Config} */
83
69
  ${ctx.type === "module" ? "export default " : "module.exports = "}{
84
- // \u8FD9\u91CC\u7ED9\u51FA\u4E86\u4E00\u4EFD uni-app /taro \u901A\u7528\u793A\u4F8B\uFF0C\u5177\u4F53\u8981\u6839\u636E\u4F60\u81EA\u5DF1\u9879\u76EE\u7684\u76EE\u5F55\u7ED3\u6784\u8FDB\u884C\u914D\u7F6E
85
- // \u4E0D\u5728 content \u5305\u62EC\u7684\u6587\u4EF6\u5185\uFF0C\u4F60\u7F16\u5199\u7684 class\uFF0C\u662F\u4E0D\u4F1A\u751F\u6210\u5BF9\u5E94\u7684css\u5DE5\u5177\u7C7B\u7684
70
+ // 这里给出了一份 uni-app /taro 通用示例,具体要根据你自己项目的目录结构进行配置
71
+ // 不在 content 包括的文件内,你编写的 class,是不会生成对应的css工具类的
86
72
  content: ['./public/index.html', './src/**/*.{wxml,html,js,ts,jsx,tsx,vue}'],
87
- // \u5176\u4ED6\u914D\u7F6E\u9879
73
+ // 其他配置项
88
74
  // ...
89
75
  corePlugins: {
90
- // \u5C0F\u7A0B\u5E8F\u4E0D\u9700\u8981 preflight \u548C container\uFF0C\u56E0\u4E3A\u8FD9\u4E3B\u8981\u662F\u7ED9 h5 \u7684\uFF0C\u5982\u679C\u4F60\u8981\u540C\u65F6\u5F00\u53D1\u5C0F\u7A0B\u5E8F\u548C h5 \u7AEF\uFF0C\u4F60\u5E94\u8BE5\u4F7F\u7528\u73AF\u5883\u53D8\u91CF\u6765\u63A7\u5236\u5B83
76
+ // 小程序不需要 preflight 和 container,因为这主要是给 h5 的,如果你要同时开发小程序和 h5 端,你应该使用环境变量来控制它
91
77
  preflight: false,
92
78
  container: false,
93
79
  },
94
80
  }
95
81
  `;
96
- await fs.writeFile(path.resolve(ctx.cwd, ctx.tailwindConfigBasename), data);
82
+ await fs.writeFile(path.resolve(ctx.cwd, ctx.tailwindConfigBasename), data);
97
83
  }
98
84
  function getInitDefaults() {
99
- return {
100
- cwd: process.cwd(),
101
- postcssConfigBasename: "postcss.config.js",
102
- tailwindConfigBasename: "tailwind.config.js",
103
- pkgJsonBasename: "package.json"
104
- };
85
+ return {
86
+ cwd: process.cwd(),
87
+ postcssConfigBasename: "postcss.config.js",
88
+ tailwindConfigBasename: "tailwind.config.js",
89
+ pkgJsonBasename: "package.json"
90
+ };
105
91
  }
106
92
  async function init(options) {
107
- const opts = defu2(options, getInitDefaults());
108
- const ctx = await createContext(opts);
109
- if (ctx) {
110
- await updatePackageJson(ctx);
111
- logger.success("`package.json` \u6587\u4EF6\u4FEE\u6539\u5B8C\u6210\uFF01");
112
- await touchPostcssConfig(ctx);
113
- logger.success("`postcss.config.js` \u6587\u4EF6\u521B\u5EFA\u5B8C\u6210\uFF01");
114
- await touchTailwindConfig(ctx);
115
- logger.success("`tailwind.config.js` \u6587\u4EF6\u521B\u5EFA\u5B8C\u6210\uFF01");
116
- logger.success("`weapp-tailwindcss` \u521D\u59CB\u5316\u5B8C\u6210\uFF01\u8BF7\u6839\u636E\u4F60\u81EA\u5B9A\u4E49\u7684\u9700\u6C42\uFF0C\u66F4\u6539\u5BF9\u5E94\u7684\u914D\u7F6E\u6587\u4EF6(\u6BD4\u5982 `tailwind.config.js` \u4E2D\u7684 `content` \u914D\u7F6E)");
117
- }
93
+ const ctx = await createContext(defu(options, getInitDefaults()));
94
+ if (ctx) {
95
+ await updatePackageJson(ctx);
96
+ logger.success("`package.json` 文件修改完成!");
97
+ await touchPostcssConfig(ctx);
98
+ logger.success("`postcss.config.js` 文件创建完成!");
99
+ await touchTailwindConfig(ctx);
100
+ logger.success("`tailwind.config.js` 文件创建完成!");
101
+ logger.success("`weapp-tailwindcss` 初始化完成!请根据你自定义的需求,更改对应的配置文件(比如 `tailwind.config.js` 中的 `content` 配置)");
102
+ }
118
103
  }
119
- export {
120
- createContext,
121
- getInitDefaults,
122
- init,
123
- touchPostcssConfig,
124
- touchTailwindConfig,
125
- updatePackageJson
126
- };
104
+ //#endregion
105
+ export { createContext, getInitDefaults, init, touchPostcssConfig, touchTailwindConfig, updatePackageJson };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/init",
3
- "version": "1.0.11",
3
+ "version": "1.0.12-next.2",
4
4
  "description": "@weapp-tailwindcss/init",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -31,15 +31,15 @@
31
31
  "node": "^20.19.0 || >=22.12.0"
32
32
  },
33
33
  "dependencies": {
34
- "fs-extra": "^11.3.4",
35
- "npm-registry-fetch": "^19.1.1",
34
+ "fs-extra": "^11.3.5",
35
+ "npm-registry-fetch": "^20.0.0",
36
36
  "pathe": "^2.0.3",
37
37
  "@weapp-tailwindcss/logger": "1.1.0",
38
38
  "@weapp-tailwindcss/shared": "1.1.3"
39
39
  },
40
40
  "scripts": {
41
- "dev": "tsup --watch --sourcemap",
42
- "build": "tsup",
41
+ "dev": "tsdown --watch --sourcemap",
42
+ "build": "tsdown",
43
43
  "test": "vitest run",
44
44
  "test:dev": "vitest",
45
45
  "release": "pnpm publish",
package/dist/index.d.mts DELETED
@@ -1,39 +0,0 @@
1
- import { PackageJson } from 'pkg-types';
2
- import { Options } from 'npm-registry-fetch';
3
-
4
- type FetchOptions = Options;
5
-
6
- interface CreateContextOptions {
7
- cwd: string;
8
- pkgJsonBasename?: string;
9
- postcssConfigBasename?: string;
10
- tailwindConfigBasename?: string;
11
- fetchOptions?: FetchOptions;
12
- }
13
- declare function createContext(options: Required<CreateContextOptions>): Promise<{
14
- pkgJson: PackageJson;
15
- pkgJsonPath: string;
16
- cwd: string;
17
- versions: {
18
- tailwindcss: string;
19
- postcss: string;
20
- autoprefixer: string;
21
- 'weapp-tailwindcss': string;
22
- };
23
- postcssConfigBasename: string;
24
- tailwindConfigBasename: string;
25
- readonly type: "module" | "commonjs" | undefined;
26
- } | undefined>;
27
- type Context = Exclude<Awaited<ReturnType<typeof createContext>>, undefined>;
28
- declare function updatePackageJson(ctx: Context): Promise<void>;
29
- declare function touchPostcssConfig(ctx: Context): Promise<void>;
30
- declare function touchTailwindConfig(ctx: Context): Promise<void>;
31
- declare function getInitDefaults(): {
32
- cwd: string;
33
- postcssConfigBasename: string;
34
- tailwindConfigBasename: string;
35
- pkgJsonBasename: string;
36
- };
37
- declare function init(options?: CreateContextOptions): Promise<void>;
38
-
39
- export { type Context, type CreateContextOptions, createContext, getInitDefaults, init, touchPostcssConfig, touchTailwindConfig, updatePackageJson };