@1adybug/prettier 0.0.7 → 0.0.8

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 (2) hide show
  1. package/dist/index.js +114 -282
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,286 +1,118 @@
1
- import * as __rspack_external__1adybug_prettier_plugin_block_padding_14feff4b from "@1adybug/prettier-plugin-block-padding";
2
- import * as __rspack_external__1adybug_prettier_plugin_remove_braces_0ec3b1e6 from "@1adybug/prettier-plugin-remove-braces";
3
- import * as __rspack_external__1adybug_prettier_plugin_sort_imports_9b3eac38 from "@1adybug/prettier-plugin-sort-imports";
4
- import * as __rspack_external_fs from "fs";
5
- import * as __rspack_external_module from "module";
6
- import * as __rspack_external_path from "path";
1
+ import { existsSync, statSync } from "fs";
2
+ import { builtinModules, createRequire } from "module";
3
+ import { join, parse, resolve } from "path";
4
+ import prettier_plugin_block_padding from "@1adybug/prettier-plugin-block-padding";
5
+ import prettier_plugin_remove_braces from "@1adybug/prettier-plugin-remove-braces";
6
+ import { createPlugin } from "@1adybug/prettier-plugin-sort-imports";
7
+ import { createMatchPath, loadConfig } from "tsconfig-paths";
7
8
  import * as __rspack_external_prettier_plugin_tailwindcss_a3404f7e from "prettier-plugin-tailwindcss";
8
- import * as __rspack_external_tsconfig_paths_df62e9eb from "tsconfig-paths";
9
- var __webpack_modules__ = {
10
- "./src/index.ts": function(module, __webpack_exports__, __webpack_require__) {
11
- __webpack_require__.a(module, async function(__webpack_handle_async_dependencies__, __webpack_async_result__) {
12
- try {
13
- __webpack_require__.r(__webpack_exports__);
14
- __webpack_require__.d(__webpack_exports__, {
15
- default: ()=>__rspack_default_export,
16
- plugin: ()=>plugin
17
- });
18
- var fs__rspack_import_0 = __webpack_require__("fs");
19
- var module__rspack_import_1 = __webpack_require__("module");
20
- var path__rspack_import_2 = __webpack_require__("path");
21
- var _1adybug_prettier_plugin_block_padding__rspack_import_3 = __webpack_require__("@1adybug/prettier-plugin-block-padding");
22
- var _1adybug_prettier_plugin_remove_braces__rspack_import_4 = __webpack_require__("@1adybug/prettier-plugin-remove-braces");
23
- var _1adybug_prettier_plugin_sort_imports__rspack_import_5 = __webpack_require__("@1adybug/prettier-plugin-sort-imports");
24
- var prettier_plugin_tailwindcss__rspack_import_6 = __webpack_require__("prettier-plugin-tailwindcss");
25
- var tsconfig_paths__rspack_import_7 = __webpack_require__("tsconfig-paths");
26
- const extensions = [
27
- ".ts",
28
- ".tsx",
29
- ".js",
30
- ".jsx",
31
- ".mjs",
32
- ".cjs"
33
- ];
34
- function getResolveAlias(filepath) {
35
- try {
36
- filepath = (0, path__rspack_import_2.resolve)(filepath);
37
- let tsconfigPath;
38
- while(true){
39
- const { root, dir } = (0, path__rspack_import_2.parse)(filepath);
40
- tsconfigPath = (0, path__rspack_import_2.join)(dir, "tsconfig.json");
41
- if ((0, fs__rspack_import_0.existsSync)(tsconfigPath)) break;
42
- if (dir === root) break;
43
- filepath = dir;
44
- }
45
- if (!tsconfigPath) return;
46
- const tsconfig = (0, tsconfig_paths__rspack_import_7.loadConfig)(tsconfigPath);
47
- if ("failed" === tsconfig.resultType) return;
48
- const matchPath = (0, tsconfig_paths__rspack_import_7.createMatchPath)(tsconfig.absoluteBaseUrl, tsconfig.paths);
49
- return function(importPath) {
50
- return matchPath(importPath, void 0, void 0, extensions);
51
- };
52
- } catch (error) {
53
- return;
54
- }
55
- }
56
- async function hasDependency(dependency) {
57
- try {
58
- await import(dependency);
59
- return true;
60
- } catch (error) {
61
- return false;
62
- }
63
- }
64
- function isReact(path) {
65
- return /^(npm:)?react(-dom|-native)?(\/|$)/.test(path);
66
- }
67
- function isBuiltin(path) {
68
- return path.startsWith("node:") || module__rspack_import_1.builtinModules.includes(path);
69
- }
70
- function isAbsolute(path) {
71
- return !!resolveAlias?.(path);
72
- }
73
- function isRelative(path) {
74
- return path.startsWith("./") || path.startsWith("../");
75
- }
76
- function compareGroupName(a, b) {
77
- const orders = [
78
- "react",
79
- "builtin",
80
- "third-party",
81
- "absolute",
82
- "relative"
83
- ];
84
- const aInfo = JSON.parse(a);
85
- const bInfo = JSON.parse(b);
86
- return orders.indexOf(aInfo.type) - orders.indexOf(bInfo.type) || aInfo.dir.localeCompare(bInfo.dir);
87
- }
88
- function getModuleType(path) {
89
- if (isReact(path)) return "react";
90
- if (isBuiltin(path)) return "builtin";
91
- if (isAbsolute(path)) return "absolute";
92
- if (isRelative(path)) return "relative";
93
- return "third-party";
94
- }
95
- const hasTailwindcss = await hasDependency("tailwindcss");
96
- const otherPlugins = hasTailwindcss ? [
97
- _1adybug_prettier_plugin_block_padding__rspack_import_3["default"],
98
- prettier_plugin_tailwindcss__rspack_import_6,
99
- _1adybug_prettier_plugin_remove_braces__rspack_import_4["default"]
100
- ] : [
101
- _1adybug_prettier_plugin_block_padding__rspack_import_3["default"],
102
- _1adybug_prettier_plugin_remove_braces__rspack_import_4["default"]
103
- ];
104
- let resolveAlias;
105
- function getResolvedPathDir(resolvedPath) {
106
- if ((0, fs__rspack_import_0.existsSync)(resolvedPath) && (0, fs__rspack_import_0.statSync)(resolvedPath).isFile()) return (0, path__rspack_import_2.parse)(resolvedPath).dir;
107
- for (const extension of extensions){
108
- const importPath = resolvedPath + extension;
109
- if ((0, fs__rspack_import_0.existsSync)(importPath)) return (0, path__rspack_import_2.parse)(importPath).dir;
110
- }
111
- return resolvedPath;
112
- }
113
- const plugin = (0, _1adybug_prettier_plugin_sort_imports__rspack_import_5.createPlugin)({
114
- getGroup ({ path, filepath }) {
115
- if (filepath) resolveAlias ??= getResolveAlias(filepath);
116
- const type = getModuleType(path);
117
- let dir = "";
118
- if ("absolute" === type) dir = getResolvedPathDir(resolveAlias(path));
119
- if ("relative" === type && !!filepath) dir = getResolvedPathDir((0, path__rspack_import_2.resolve)(filepath, path));
120
- const info = {
121
- type,
122
- dir
123
- };
124
- return JSON.stringify(info);
125
- },
126
- sortGroup (a, b) {
127
- return Number(a.isSideEffect) - Number(b.isSideEffect) || compareGroupName(a.name, b.name);
128
- },
129
- separator: "",
130
- sortSideEffect: true,
131
- otherPlugins
132
- });
133
- const __rspack_default_export = plugin;
134
- __webpack_async_result__();
135
- } catch (e) {
136
- __webpack_async_result__(e);
137
- }
138
- }, 1);
139
- },
140
- "@1adybug/prettier-plugin-block-padding": function(module) {
141
- module.exports = __rspack_external__1adybug_prettier_plugin_block_padding_14feff4b;
142
- },
143
- "@1adybug/prettier-plugin-remove-braces": function(module) {
144
- module.exports = __rspack_external__1adybug_prettier_plugin_remove_braces_0ec3b1e6;
145
- },
146
- "@1adybug/prettier-plugin-sort-imports": function(module) {
147
- module.exports = __rspack_external__1adybug_prettier_plugin_sort_imports_9b3eac38;
148
- },
149
- fs: function(module) {
150
- module.exports = __rspack_external_fs;
151
- },
152
- module: function(module) {
153
- module.exports = __rspack_external_module;
154
- },
155
- path: function(module) {
156
- module.exports = __rspack_external_path;
157
- },
158
- "prettier-plugin-tailwindcss": function(module) {
159
- module.exports = __rspack_external_prettier_plugin_tailwindcss_a3404f7e;
160
- },
161
- "tsconfig-paths": function(module) {
162
- module.exports = __rspack_external_tsconfig_paths_df62e9eb;
163
- }
164
- };
165
- var __webpack_module_cache__ = {};
166
- function __webpack_require__(moduleId) {
167
- var cachedModule = __webpack_module_cache__[moduleId];
168
- if (void 0 !== cachedModule) return cachedModule.exports;
169
- var module = __webpack_module_cache__[moduleId] = {
170
- exports: {}
171
- };
172
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
173
- return module.exports;
174
- }
175
- (()=>{
176
- var hasSymbol = "function" == typeof Symbol;
177
- var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__";
178
- var webpackExports = __webpack_require__.aE = hasSymbol ? Symbol("webpack exports") : "__webpack_exports__";
179
- var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__";
180
- var webpackDone = hasSymbol ? Symbol("webpack done") : "__webpack_done__";
181
- var webpackDefer = __webpack_require__.zS = hasSymbol ? Symbol("webpack defer") : "__webpack_defer__";
182
- var resolveQueue = (queue)=>{
183
- if (queue && queue.d < 1) {
184
- queue.d = 1;
185
- queue.forEach((fn)=>fn.r--);
186
- queue.forEach((fn)=>fn.r-- ? fn.r++ : fn());
9
+ const src_require = createRequire(import.meta.url);
10
+ const extensions = [
11
+ ".ts",
12
+ ".tsx",
13
+ ".js",
14
+ ".jsx",
15
+ ".mjs",
16
+ ".cjs"
17
+ ];
18
+ function getResolveAlias(filepath) {
19
+ try {
20
+ filepath = resolve(filepath);
21
+ let tsconfigPath;
22
+ while(true){
23
+ const { root, dir } = parse(filepath);
24
+ tsconfigPath = join(dir, "tsconfig.json");
25
+ if (existsSync(tsconfigPath)) break;
26
+ if (dir === root) break;
27
+ filepath = dir;
187
28
  }
188
- };
189
- var wrapDeps = (deps)=>deps.map((dep)=>{
190
- if (null !== dep && "object" == typeof dep) {
191
- if (!dep[webpackQueues] && dep[webpackDefer]) {
192
- var asyncDeps = dep[webpackDefer];
193
- var hasUnresolvedAsyncSubgraph = asyncDeps.some((id)=>{
194
- var cache = __webpack_module_cache__[id];
195
- return !cache || false === cache[webpackDone];
196
- });
197
- if (!hasUnresolvedAsyncSubgraph) return dep;
198
- var d = dep;
199
- dep = {
200
- then (callback) {
201
- Promise.all(asyncDeps.map(__webpack_require__)).then(()=>callback(d));
202
- }
203
- };
204
- }
205
- if (dep[webpackQueues]) return dep;
206
- if (dep.then) {
207
- var queue = [];
208
- queue.d = 0;
209
- dep.then((r)=>{
210
- obj[webpackExports] = r;
211
- resolveQueue(queue);
212
- }, (e)=>{
213
- obj[webpackError] = e;
214
- resolveQueue(queue);
215
- });
216
- var obj = {};
217
- obj[webpackDefer] = false;
218
- obj[webpackQueues] = (fn)=>fn(queue);
219
- return obj;
220
- }
221
- }
222
- var ret = {};
223
- ret[webpackQueues] = ()=>{};
224
- ret[webpackExports] = dep;
225
- return ret;
226
- });
227
- __webpack_require__.a = (module, body, hasAwait)=>{
228
- var queue;
229
- hasAwait && ((queue = []).d = -1);
230
- var depQueues = new Set();
231
- var exports = module.exports;
232
- var currentDeps;
233
- var outerResolve;
234
- var reject;
235
- var promise = new Promise((resolve, rej)=>{
236
- reject = rej;
237
- outerResolve = resolve;
238
- });
239
- promise[webpackExports] = exports;
240
- promise[webpackQueues] = (fn)=>{
241
- queue && fn(queue), depQueues.forEach(fn), promise["catch"](()=>{});
29
+ if (!tsconfigPath) return;
30
+ const tsconfig = loadConfig(tsconfigPath);
31
+ if ("failed" === tsconfig.resultType) return;
32
+ const matchPath = createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths);
33
+ return function(importPath) {
34
+ return matchPath(importPath, void 0, void 0, extensions);
242
35
  };
243
- module.exports = promise;
244
- var handle = (deps)=>{
245
- currentDeps = wrapDeps(deps);
246
- var fn;
247
- var getResult = ()=>currentDeps.map((d)=>{
248
- if (d[webpackDefer]) return d;
249
- if (d[webpackError]) throw d[webpackError];
250
- return d[webpackExports];
251
- });
252
- var promise = new Promise((resolve)=>{
253
- fn = ()=>resolve(getResult);
254
- fn.r = 0;
255
- var fnQueue = (q)=>q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn)));
256
- currentDeps.map((dep)=>dep[webpackDefer] || dep[webpackQueues](fnQueue));
257
- });
258
- return fn.r ? promise : getResult();
36
+ } catch (error) {
37
+ return;
38
+ }
39
+ }
40
+ function hasDependency(dependency) {
41
+ try {
42
+ src_require.resolve(dependency);
43
+ return true;
44
+ } catch (error) {
45
+ return false;
46
+ }
47
+ }
48
+ function isReact(path) {
49
+ return /^(npm:)?react(-dom|-native)?(\/|$)/.test(path);
50
+ }
51
+ function isBuiltin(path) {
52
+ return path.startsWith("node:") || builtinModules.includes(path);
53
+ }
54
+ function isAbsolute(path) {
55
+ return !!src_resolveAlias?.(path);
56
+ }
57
+ function isRelative(path) {
58
+ return path.startsWith("./") || path.startsWith("../");
59
+ }
60
+ function compareGroupName(a, b) {
61
+ const orders = [
62
+ "react",
63
+ "builtin",
64
+ "third-party",
65
+ "absolute",
66
+ "relative"
67
+ ];
68
+ const aInfo = JSON.parse(a);
69
+ const bInfo = JSON.parse(b);
70
+ return orders.indexOf(aInfo.type) - orders.indexOf(bInfo.type) || aInfo.dir.localeCompare(bInfo.dir);
71
+ }
72
+ function getModuleType(path) {
73
+ if (isReact(path)) return "react";
74
+ if (isBuiltin(path)) return "builtin";
75
+ if (isAbsolute(path)) return "absolute";
76
+ if (isRelative(path)) return "relative";
77
+ return "third-party";
78
+ }
79
+ const hasTailwindcss = hasDependency("tailwindcss");
80
+ const otherPlugins = hasTailwindcss ? [
81
+ prettier_plugin_block_padding,
82
+ __rspack_external_prettier_plugin_tailwindcss_a3404f7e,
83
+ prettier_plugin_remove_braces
84
+ ] : [
85
+ prettier_plugin_block_padding,
86
+ prettier_plugin_remove_braces
87
+ ];
88
+ let src_resolveAlias;
89
+ function getResolvedPathDir(resolvedPath) {
90
+ if (existsSync(resolvedPath) && statSync(resolvedPath).isFile()) return parse(resolvedPath).dir;
91
+ for (const extension of extensions){
92
+ const importPath = resolvedPath + extension;
93
+ if (existsSync(importPath)) return parse(importPath).dir;
94
+ }
95
+ return resolvedPath;
96
+ }
97
+ const src_plugin = createPlugin({
98
+ getGroup ({ path, filepath }) {
99
+ if (filepath) src_resolveAlias ??= getResolveAlias(filepath);
100
+ const type = getModuleType(path);
101
+ let dir = "";
102
+ if ("absolute" === type) dir = getResolvedPathDir(src_resolveAlias(path));
103
+ if ("relative" === type && !!filepath) dir = getResolvedPathDir(resolve(filepath, path));
104
+ const info = {
105
+ type,
106
+ dir
259
107
  };
260
- var done = (err)=>(err ? reject(promise[webpackError] = err) : outerResolve(exports), resolveQueue(queue), promise[webpackDone] = true);
261
- body(handle, done);
262
- queue && queue.d < 0 && (queue.d = 0);
263
- };
264
- })();
265
- (()=>{
266
- __webpack_require__.d = (exports, definition)=>{
267
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
268
- enumerable: true,
269
- get: definition[key]
270
- });
271
- };
272
- })();
273
- (()=>{
274
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
275
- })();
276
- (()=>{
277
- __webpack_require__.r = (exports)=>{
278
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
279
- value: 'Module'
280
- });
281
- Object.defineProperty(exports, '__esModule', {
282
- value: true
283
- });
284
- };
285
- })();
286
- __webpack_require__("./src/index.ts");
108
+ return JSON.stringify(info);
109
+ },
110
+ sortGroup (a, b) {
111
+ return Number(a.isSideEffect) - Number(b.isSideEffect) || compareGroupName(a.name, b.name);
112
+ },
113
+ separator: "",
114
+ sortSideEffect: true,
115
+ otherPlugins
116
+ });
117
+ const src = src_plugin;
118
+ export { src as default, src_plugin as plugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1adybug/prettier",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "推荐的 Prettier 配置",
5
5
  "keywords": [
6
6
  "prettier",
@@ -38,8 +38,8 @@
38
38
  "dependencies": {
39
39
  "prettier-plugin-tailwindcss": "^0.7.1",
40
40
  "tsconfig-paths": "^4.2.0",
41
- "@1adybug/prettier-plugin-sort-imports": "0.0.19",
42
41
  "@1adybug/prettier-plugin-block-padding": "0.0.11",
42
+ "@1adybug/prettier-plugin-sort-imports": "0.0.19",
43
43
  "@1adybug/prettier-plugin-remove-braces": "0.0.5"
44
44
  },
45
45
  "devDependencies": {