@samual/rolldown-plugin-prettier 0.0.1-c72ee2f → 0.0.1-c78e3fe

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/index.d.ts CHANGED
@@ -5,23 +5,25 @@
5
5
  import type { Options as PrettierOptions } from 'prettier';
6
6
  import type { Plugin } from 'rolldown';
7
7
 
8
- declare namespace prettier {
9
- interface Options extends PrettierOptions {
10
- /**
11
- * Directory to look for a Prettier config file.
12
- *
13
- * If omitted, defaults to `process.cwd()`.
14
- */
15
- cwd?: string;
8
+ export interface Options extends PrettierOptions {
9
+ /**
10
+ * Directory to look for a Prettier config file.
11
+ *
12
+ * If omitted, defaults to `process.cwd()`.
13
+ */
14
+ cwd?: string;
15
+
16
+ /**
17
+ * Whether to generate a sourcemap.
18
+ *
19
+ * Note: This may take some time because rollup-plugin-prettier diffs the
20
+ * output to manually generate a sourcemap.
21
+ */
22
+ sourcemap?: boolean | 'silent';
23
+ }
16
24
 
17
- /**
18
- * Whether to generate a sourcemap.
19
- *
20
- * Note: This may take some time because rollup-plugin-prettier diffs the
21
- * output to manually generate a sourcemap.
22
- */
23
- sourcemap?: boolean | 'silent';
24
- }
25
+ declare namespace prettier {
26
+ export { Options }
25
27
  }
26
28
 
27
29
  declare function prettier(options?: prettier.Options): Plugin;
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { RollupPluginPrettier } from "./rollup-plugin-prettier.js"
1
+ import { t as RollupPluginPrettier } from "./rollup-plugin-prettier-Do8e9vYR.js"
2
2
  function rollupPluginPrettier(options) {
3
3
  const plugin = new RollupPluginPrettier(options)
4
4
  return {
5
5
  name: plugin.name,
6
- renderChunk: (source, chunkInfo, outputOptions) =>
7
- plugin.reformat(source, { sourcemap: outputOptions.sourcemap })
6
+ renderChunk: (source, _chunkInfo, outputOptions) =>
7
+ plugin.reformat(source, { sourcemap: !!outputOptions.sourcemap })
8
8
  }
9
9
  }
10
10
  export { rollupPluginPrettier as default }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samual/rolldown-plugin-prettier",
3
- "version": "0.0.1-c72ee2f",
3
+ "version": "0.0.1-c78e3fe",
4
4
  "description": "Rolldown plugin for code formatting using Prettier",
5
5
  "author": "Mickael Jeanroy <mickael.jeanroy@gmail.com>",
6
6
  "contributors": [
@@ -29,10 +29,6 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "diff": "^8",
32
- "lodash.hasin": "^4",
33
- "lodash.isempty": "^4",
34
- "lodash.isnil": "^4",
35
- "lodash.omitby": "^4",
36
32
  "magic-string": "0.30.21",
37
33
  "prettier": "^3",
38
34
  "rolldown": "1.0.0-rc.6"
@@ -0,0 +1,673 @@
1
+ import { assert } from "@samual/assert"
2
+ import * as diff from "diff"
3
+ import MagicString from "magic-string"
4
+ import path from "node:path"
5
+ import prettier from "prettier"
6
+ function isArrayLike(value) {
7
+ return (
8
+ null != value &&
9
+ "function" != typeof value &&
10
+ (function (value) {
11
+ return Number.isSafeInteger(value) && value >= 0
12
+ })(value.length)
13
+ )
14
+ }
15
+ function identity$1(x) {
16
+ return x
17
+ }
18
+ function isUnsafeProperty(key) {
19
+ return "__proto__" === key
20
+ }
21
+ function isDeepKey(key) {
22
+ switch (typeof key) {
23
+ case "number":
24
+ case "symbol":
25
+ return !1
26
+ case "string":
27
+ return key.includes(".") || key.includes("[") || key.includes("]")
28
+ }
29
+ }
30
+ function toKey(value) {
31
+ return "string" == typeof value || "symbol" == typeof value
32
+ ? value
33
+ : Object.is(value?.valueOf?.(), -0)
34
+ ? "-0"
35
+ : value + ""
36
+ }
37
+ function toString(value) {
38
+ if (null == value) return ""
39
+ if ("string" == typeof value) return value
40
+ if (Array.isArray(value)) return value.map(toString).join(",")
41
+ const result = value + ""
42
+ return "0" === result && Object.is(Number(value), -0) ? "-0" : result
43
+ }
44
+ function toPath(deepKey) {
45
+ if (Array.isArray(deepKey)) return deepKey.map(toKey)
46
+ if ("symbol" == typeof deepKey) return [deepKey]
47
+ const result = [],
48
+ length = (deepKey = toString(deepKey)).length
49
+ if (0 === length) return result
50
+ let index = 0,
51
+ key = "",
52
+ quoteChar = "",
53
+ bracket = !1
54
+ if (46 === deepKey.charCodeAt(0)) {
55
+ result.push("")
56
+ index++
57
+ }
58
+ for (; index < length; ) {
59
+ const char = deepKey[index]
60
+ if (quoteChar)
61
+ if ("\\" === char && index + 1 < length) {
62
+ index++
63
+ key += deepKey[index]
64
+ } else char === quoteChar ? (quoteChar = "") : (key += char)
65
+ else if (bracket)
66
+ if ('"' === char || "'" === char) quoteChar = char
67
+ else if ("]" === char) {
68
+ bracket = !1
69
+ result.push(key)
70
+ key = ""
71
+ } else key += char
72
+ else if ("[" === char) {
73
+ bracket = !0
74
+ if (key) {
75
+ result.push(key)
76
+ key = ""
77
+ }
78
+ } else if ("." === char) {
79
+ if (key) {
80
+ result.push(key)
81
+ key = ""
82
+ }
83
+ } else key += char
84
+ index++
85
+ }
86
+ key && result.push(key)
87
+ return result
88
+ }
89
+ function get(object, path, defaultValue) {
90
+ if (null == object) return defaultValue
91
+ switch (typeof path) {
92
+ case "string": {
93
+ if (isUnsafeProperty(path)) return defaultValue
94
+ const result = object[path]
95
+ return void 0 === result
96
+ ? isDeepKey(path)
97
+ ? get(object, toPath(path), defaultValue)
98
+ : defaultValue
99
+ : result
100
+ }
101
+ case "number":
102
+ case "symbol": {
103
+ "number" == typeof path && (path = toKey(path))
104
+ const result = object[path]
105
+ return void 0 === result ? defaultValue : result
106
+ }
107
+ default: {
108
+ if (Array.isArray(path))
109
+ return (function (object, path, defaultValue) {
110
+ if (0 === path.length) return defaultValue
111
+ let current = object
112
+ for (let index = 0; index < path.length; index++) {
113
+ if (null == current) return defaultValue
114
+ if (isUnsafeProperty(path[index])) return defaultValue
115
+ current = current[path[index]]
116
+ }
117
+ return void 0 === current ? defaultValue : current
118
+ })(object, path, defaultValue)
119
+ Object.is(path?.valueOf(), -0) ? (path = "-0") : (path += "")
120
+ if (isUnsafeProperty(path)) return defaultValue
121
+ const result = object[path]
122
+ return void 0 === result ? defaultValue : result
123
+ }
124
+ }
125
+ }
126
+ function isPrimitive(value) {
127
+ return null == value || ("object" != typeof value && "function" != typeof value)
128
+ }
129
+ function isEqualsSameValueZero(value, other) {
130
+ return value === other || (Number.isNaN(value) && Number.isNaN(other))
131
+ }
132
+ function isMatchWith(target, source, compare) {
133
+ return "function" != typeof compare
134
+ ? isMatchWith(target, source, () => {})
135
+ : isMatchWithInternal(
136
+ target,
137
+ source,
138
+ function doesMatch(objValue, srcValue, key, object, source, stack) {
139
+ const isEqual = compare(objValue, srcValue, key, object, source, stack)
140
+ return void 0 !== isEqual ? !!isEqual : isMatchWithInternal(objValue, srcValue, doesMatch, stack)
141
+ },
142
+ new Map()
143
+ )
144
+ }
145
+ function isMatchWithInternal(target, source, compare, stack) {
146
+ if (source === target) return !0
147
+ switch (typeof source) {
148
+ case "object":
149
+ return (function (target, source, compare, stack) {
150
+ if (null == source) return !0
151
+ if (Array.isArray(source)) return isArrayMatch(target, source, compare, stack)
152
+ if (source instanceof Map)
153
+ return (function (target, source, compare, stack) {
154
+ if (0 === source.size) return !0
155
+ if (!(target instanceof Map)) return !1
156
+ for (const [key, sourceValue] of source.entries())
157
+ if (!1 === compare(target.get(key), sourceValue, key, target, source, stack)) return !1
158
+ return !0
159
+ })(target, source, compare, stack)
160
+ if (source instanceof Set)
161
+ return (function (target, source, compare, stack) {
162
+ return (
163
+ 0 === source.size ||
164
+ (target instanceof Set && isArrayMatch([...target], [...source], compare, stack))
165
+ )
166
+ })(target, source, compare, stack)
167
+ const keys = Object.keys(source)
168
+ if (null == target || isPrimitive(target)) return 0 === keys.length
169
+ if (0 === keys.length) return !0
170
+ if (stack?.has(source)) return stack.get(source) === target
171
+ stack?.set(source, target)
172
+ try {
173
+ for (let i = 0; i < keys.length; i++) {
174
+ const key = keys[i]
175
+ if (!isPrimitive(target) && !(key in target)) return !1
176
+ if (void 0 === source[key] && void 0 !== target[key]) return !1
177
+ if (null === source[key] && null !== target[key]) return !1
178
+ if (!compare(target[key], source[key], key, target, source, stack)) return !1
179
+ }
180
+ return !0
181
+ } finally {
182
+ stack?.delete(source)
183
+ }
184
+ })(target, source, compare, stack)
185
+ case "function":
186
+ return Object.keys(source).length > 0
187
+ ? isMatchWithInternal(target, { ...source }, compare, stack)
188
+ : isEqualsSameValueZero(target, source)
189
+ default:
190
+ return null === (value = target) || ("object" != typeof value && "function" != typeof value)
191
+ ? isEqualsSameValueZero(target, source)
192
+ : "string" != typeof source || "" === source
193
+ }
194
+ var value
195
+ }
196
+ function isArrayMatch(target, source, compare, stack) {
197
+ if (0 === source.length) return !0
198
+ if (!Array.isArray(target)) return !1
199
+ const countedIndex = new Set()
200
+ for (let i = 0; i < source.length; i++) {
201
+ const sourceItem = source[i]
202
+ let found = !1
203
+ for (let j = 0; j < target.length; j++) {
204
+ if (countedIndex.has(j)) continue
205
+ let matches = !1
206
+ compare(target[j], sourceItem, i, target, source, stack) && (matches = !0)
207
+ if (matches) {
208
+ countedIndex.add(j)
209
+ found = !0
210
+ break
211
+ }
212
+ }
213
+ if (!found) return !1
214
+ }
215
+ return !0
216
+ }
217
+ function isMatch(target, source) {
218
+ return isMatchWith(target, source, () => {})
219
+ }
220
+ function getSymbols(object) {
221
+ return Object.getOwnPropertySymbols(object).filter(symbol =>
222
+ Object.prototype.propertyIsEnumerable.call(object, symbol)
223
+ )
224
+ }
225
+ function getTag(value) {
226
+ return null == value
227
+ ? void 0 === value
228
+ ? "[object Undefined]"
229
+ : "[object Null]"
230
+ : Object.prototype.toString.call(value)
231
+ }
232
+ function isTypedArray$1(x) {
233
+ return ArrayBuffer.isView(x) && !(x instanceof DataView)
234
+ }
235
+ function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = new Map(), cloneValue = void 0) {
236
+ const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack)
237
+ if (void 0 !== cloned) return cloned
238
+ if (isPrimitive(valueToClone)) return valueToClone
239
+ if (stack.has(valueToClone)) return stack.get(valueToClone)
240
+ if (Array.isArray(valueToClone)) {
241
+ const result = Array(valueToClone.length)
242
+ stack.set(valueToClone, result)
243
+ for (let i = 0; i < valueToClone.length; i++)
244
+ result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue)
245
+ Object.hasOwn(valueToClone, "index") && (result.index = valueToClone.index)
246
+ Object.hasOwn(valueToClone, "input") && (result.input = valueToClone.input)
247
+ return result
248
+ }
249
+ if (valueToClone instanceof Date) return new Date(valueToClone.getTime())
250
+ if (valueToClone instanceof RegExp) {
251
+ const result = RegExp(valueToClone.source, valueToClone.flags)
252
+ result.lastIndex = valueToClone.lastIndex
253
+ return result
254
+ }
255
+ if (valueToClone instanceof Map) {
256
+ const result = new Map()
257
+ stack.set(valueToClone, result)
258
+ for (const [key, value] of valueToClone)
259
+ result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue))
260
+ return result
261
+ }
262
+ if (valueToClone instanceof Set) {
263
+ const result = new Set()
264
+ stack.set(valueToClone, result)
265
+ for (const value of valueToClone) result.add(cloneDeepWithImpl(value, void 0, objectToClone, stack, cloneValue))
266
+ return result
267
+ }
268
+ if ("undefined" != typeof Buffer && Buffer.isBuffer(valueToClone)) return valueToClone.subarray()
269
+ if (isTypedArray$1(valueToClone)) {
270
+ const result = new (Object.getPrototypeOf(valueToClone).constructor)(valueToClone.length)
271
+ stack.set(valueToClone, result)
272
+ for (let i = 0; i < valueToClone.length; i++)
273
+ result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue)
274
+ return result
275
+ }
276
+ if (
277
+ valueToClone instanceof ArrayBuffer ||
278
+ ("undefined" != typeof SharedArrayBuffer && valueToClone instanceof SharedArrayBuffer)
279
+ )
280
+ return valueToClone.slice(0)
281
+ if (valueToClone instanceof DataView) {
282
+ const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength)
283
+ stack.set(valueToClone, result)
284
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
285
+ return result
286
+ }
287
+ if ("undefined" != typeof File && valueToClone instanceof File) {
288
+ const result = new File([valueToClone], valueToClone.name, { type: valueToClone.type })
289
+ stack.set(valueToClone, result)
290
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
291
+ return result
292
+ }
293
+ if ("undefined" != typeof Blob && valueToClone instanceof Blob) {
294
+ const result = new Blob([valueToClone], { type: valueToClone.type })
295
+ stack.set(valueToClone, result)
296
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
297
+ return result
298
+ }
299
+ if (valueToClone instanceof Error) {
300
+ const result = new valueToClone.constructor()
301
+ stack.set(valueToClone, result)
302
+ result.message = valueToClone.message
303
+ result.name = valueToClone.name
304
+ result.stack = valueToClone.stack
305
+ result.cause = valueToClone.cause
306
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
307
+ return result
308
+ }
309
+ if (valueToClone instanceof Boolean) {
310
+ const result = new Boolean(valueToClone.valueOf())
311
+ stack.set(valueToClone, result)
312
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
313
+ return result
314
+ }
315
+ if (valueToClone instanceof Number) {
316
+ const result = new Number(valueToClone.valueOf())
317
+ stack.set(valueToClone, result)
318
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
319
+ return result
320
+ }
321
+ if (valueToClone instanceof String) {
322
+ const result = new String(valueToClone.valueOf())
323
+ stack.set(valueToClone, result)
324
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
325
+ return result
326
+ }
327
+ if (
328
+ "object" == typeof valueToClone &&
329
+ (function (object) {
330
+ switch (getTag(object)) {
331
+ case "[object Arguments]":
332
+ case "[object Array]":
333
+ case "[object ArrayBuffer]":
334
+ case "[object DataView]":
335
+ case "[object Boolean]":
336
+ case "[object Date]":
337
+ case "[object Float32Array]":
338
+ case "[object Float64Array]":
339
+ case "[object Int8Array]":
340
+ case "[object Int16Array]":
341
+ case "[object Int32Array]":
342
+ case "[object Map]":
343
+ case "[object Number]":
344
+ case "[object Object]":
345
+ case "[object RegExp]":
346
+ case "[object Set]":
347
+ case "[object String]":
348
+ case "[object Symbol]":
349
+ case "[object Uint8Array]":
350
+ case "[object Uint8ClampedArray]":
351
+ case "[object Uint16Array]":
352
+ case "[object Uint32Array]":
353
+ return !0
354
+ default:
355
+ return !1
356
+ }
357
+ })(valueToClone)
358
+ ) {
359
+ const result = Object.create(Object.getPrototypeOf(valueToClone))
360
+ stack.set(valueToClone, result)
361
+ copyProperties(result, valueToClone, objectToClone, stack, cloneValue)
362
+ return result
363
+ }
364
+ return valueToClone
365
+ }
366
+ function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
367
+ const keys = [...Object.keys(source), ...getSymbols(source)]
368
+ for (let i = 0; i < keys.length; i++) {
369
+ const key = keys[i],
370
+ descriptor = Object.getOwnPropertyDescriptor(target, key)
371
+ ;(null == descriptor || descriptor.writable) &&
372
+ (target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue))
373
+ }
374
+ }
375
+ const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/
376
+ function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
377
+ switch (typeof value) {
378
+ case "number":
379
+ return Number.isInteger(value) && value >= 0 && value < length
380
+ case "symbol":
381
+ return !1
382
+ case "string":
383
+ return IS_UNSIGNED_INTEGER.test(value)
384
+ }
385
+ }
386
+ function isArguments(value) {
387
+ return null !== value && "object" == typeof value && "[object Arguments]" === getTag(value)
388
+ }
389
+ function isSymbol(value) {
390
+ return "symbol" == typeof value || value instanceof Symbol
391
+ }
392
+ function identity(x) {
393
+ return x
394
+ }
395
+ function isPrototype(value) {
396
+ const constructor = value?.constructor
397
+ return value === ("function" == typeof constructor ? constructor.prototype : Object.prototype)
398
+ }
399
+ function isTypedArray(x) {
400
+ return isTypedArray$1(x)
401
+ }
402
+ function keysIn(object) {
403
+ if (null == object) return []
404
+ switch (typeof object) {
405
+ case "object":
406
+ case "function":
407
+ return isArrayLike(object)
408
+ ? (function (object) {
409
+ const indices = (function (n, getValue) {
410
+ if (
411
+ (n = (function (value) {
412
+ const finite = (function (value) {
413
+ return value
414
+ ? Infinity ===
415
+ (value = (function (value) {
416
+ return isSymbol(value) ? NaN : Number(value)
417
+ })(value)) || -Infinity === value
418
+ ? (value < 0 ? -1 : 1) * Number.MAX_VALUE
419
+ : value == value
420
+ ? value
421
+ : 0
422
+ : 0 === value
423
+ ? value
424
+ : 0
425
+ })(value),
426
+ remainder = finite % 1
427
+ return remainder ? finite - remainder : finite
428
+ })(n)) < 1 ||
429
+ !Number.isSafeInteger(n)
430
+ )
431
+ return []
432
+ const result = Array(n)
433
+ for (let i = 0; i < n; i++) result[i] = getValue(i)
434
+ return result
435
+ })(object.length, index => "" + index),
436
+ filteredKeys = new Set(indices)
437
+ if (((x = object), "undefined" != typeof Buffer && Buffer.isBuffer(x))) {
438
+ filteredKeys.add("offset")
439
+ filteredKeys.add("parent")
440
+ }
441
+ var x
442
+ if (isTypedArray(object)) {
443
+ filteredKeys.add("buffer")
444
+ filteredKeys.add("byteLength")
445
+ filteredKeys.add("byteOffset")
446
+ }
447
+ const inheritedKeys = keysInImpl(object).filter(key => !filteredKeys.has(key))
448
+ return Array.isArray(object)
449
+ ? [...indices, ...inheritedKeys]
450
+ : [...indices.filter(index => Object.hasOwn(object, index)), ...inheritedKeys]
451
+ })(object)
452
+ : isPrototype(object)
453
+ ? (function (object) {
454
+ return keysInImpl(object).filter(key => "constructor" !== key)
455
+ })(object)
456
+ : keysInImpl(object)
457
+ default:
458
+ return keysInImpl(Object(object))
459
+ }
460
+ }
461
+ function keysInImpl(object) {
462
+ const result = []
463
+ for (const key in object) result.push(key)
464
+ return result
465
+ }
466
+ function getSymbolsIn(object) {
467
+ const result = []
468
+ for (; object; ) {
469
+ result.push(...getSymbols(object))
470
+ object = Object.getPrototypeOf(object)
471
+ }
472
+ return result
473
+ }
474
+ const OPTIONS = new Set(["sourcemap", "cwd"])
475
+ function resolvePrettierConfig(cwd) {
476
+ const fromFile = path.join(cwd, "__noop__.js")
477
+ return prettier.resolveConfig ? prettier.resolveConfig(fromFile) : Promise.resolve(null)
478
+ }
479
+ var RollupPluginPrettier = class {
480
+ _options
481
+ _sourcemap
482
+ constructor(options = {}) {
483
+ this._options = Promise.resolve(
484
+ (function (object) {
485
+ if (null == object) return {}
486
+ const result = {},
487
+ predicate = (function (value) {
488
+ if (null == value) return identity$1
489
+ switch (typeof value) {
490
+ case "function":
491
+ return value
492
+ case "object":
493
+ return Array.isArray(value) && 2 === value.length
494
+ ? (function (property, source) {
495
+ switch (typeof property) {
496
+ case "object":
497
+ Object.is(property?.valueOf(), -0) && (property = "-0")
498
+ break
499
+ case "number":
500
+ property = toKey(property)
501
+ }
502
+ source = (function (obj, cloneValue) {
503
+ return cloneDeepWithImpl(obj, void 0, obj, new Map(), cloneValue)
504
+ })((obj = source), (value, key, object, stack) => {
505
+ if ("object" == typeof obj) {
506
+ if (
507
+ "[object Object]" === getTag(obj) &&
508
+ "function" != typeof obj.constructor
509
+ ) {
510
+ const result = {}
511
+ stack.set(obj, result)
512
+ copyProperties(result, obj, object, stack)
513
+ return result
514
+ }
515
+ switch (Object.prototype.toString.call(obj)) {
516
+ case "[object Number]":
517
+ case "[object String]":
518
+ case "[object Boolean]": {
519
+ const result = new obj.constructor(obj?.valueOf())
520
+ copyProperties(result, obj)
521
+ return result
522
+ }
523
+ case "[object Arguments]": {
524
+ const result = {}
525
+ copyProperties(result, obj)
526
+ result.length = obj.length
527
+ result[Symbol.iterator] = obj[Symbol.iterator]
528
+ return result
529
+ }
530
+ default:
531
+ return
532
+ }
533
+ }
534
+ })
535
+ var obj
536
+ return function (target) {
537
+ const result = get(target, property)
538
+ return void 0 === result
539
+ ? (function (object, path) {
540
+ let resolvedPath
541
+ resolvedPath = Array.isArray(path)
542
+ ? path
543
+ : "string" == typeof path &&
544
+ isDeepKey(path) &&
545
+ null == object?.[path]
546
+ ? toPath(path)
547
+ : [path]
548
+ if (0 === resolvedPath.length) return !1
549
+ let current = object
550
+ for (let i = 0; i < resolvedPath.length; i++) {
551
+ const key = resolvedPath[i]
552
+ if (
553
+ !(
554
+ (null != current &&
555
+ Object.hasOwn(current, key)) ||
556
+ ((Array.isArray(current) ||
557
+ isArguments(current)) &&
558
+ isIndex(key) &&
559
+ key < current.length)
560
+ )
561
+ )
562
+ return !1
563
+ current = current[key]
564
+ }
565
+ return !0
566
+ })(target, property)
567
+ : void 0 === source
568
+ ? void 0 === result
569
+ : isMatch(result, source)
570
+ }
571
+ })(value[0], value[1])
572
+ : (function (source) {
573
+ source = cloneDeepWithImpl((obj = source), void 0, obj, new Map(), void 0)
574
+ var obj
575
+ return target => isMatch(target, source)
576
+ })(value)
577
+ case "string":
578
+ case "symbol":
579
+ case "number":
580
+ return (function (path) {
581
+ return function (object) {
582
+ return get(object, path)
583
+ }
584
+ })(value)
585
+ }
586
+ })(((_value, key) => OPTIONS.has(key)) ?? identity),
587
+ keys = isArrayLike(object)
588
+ ? (function (start, end, step = 1) {
589
+ if (null == end) {
590
+ end = start
591
+ start = 0
592
+ }
593
+ if (!Number.isInteger(step) || 0 === step)
594
+ throw Error("The step value must be a non-zero integer.")
595
+ const length = Math.max(Math.ceil((end - start) / step), 0),
596
+ result = Array(length)
597
+ for (let i = 0; i < length; i++) result[i] = start + i * step
598
+ return result
599
+ })(0, object.length)
600
+ : [...keysIn(object), ...getSymbolsIn(object)]
601
+ for (let i = 0; i < keys.length; i++) {
602
+ const key = isSymbol(keys[i]) ? keys[i] : keys[i].toString(),
603
+ value = object[key]
604
+ predicate(value, key, object) || (result[key] = value)
605
+ }
606
+ return result
607
+ })(options)
608
+ )
609
+ const cwd = "cwd" in options ? options.cwd : process.cwd()
610
+ this._options = Promise.all([resolvePrettierConfig(cwd), this._options]).then(results =>
611
+ Object.assign({}, ...results.map(result => result || {}))
612
+ )
613
+ this._options = this._options.then(opts =>
614
+ (function (value) {
615
+ if (null == value) return !0
616
+ if (isArrayLike(value))
617
+ return (
618
+ !!(
619
+ "function" == typeof value.splice ||
620
+ "string" == typeof value ||
621
+ ("undefined" != typeof Buffer && Buffer.isBuffer(value)) ||
622
+ isTypedArray(value) ||
623
+ isArguments(value)
624
+ ) && 0 === value.length
625
+ )
626
+ if ("object" == typeof value) {
627
+ if (value instanceof Map || value instanceof Set) return 0 === value.size
628
+ const keys = Object.keys(value)
629
+ return isPrototype(value) ? 0 === keys.filter(x => "constructor" !== x).length : 0 === keys.length
630
+ }
631
+ return !0
632
+ })(opts)
633
+ ? void 0
634
+ : opts
635
+ )
636
+ this._sourcemap = "sourcemap" in options ? options.sourcemap : null
637
+ }
638
+ getSourcemap() {
639
+ return this._sourcemap
640
+ }
641
+ enableSourcemap() {
642
+ this._sourcemap = !0
643
+ }
644
+ async reformat(source, outputOptions) {
645
+ return this._reformat(source, outputOptions, await this._options)
646
+ }
647
+ async _reformat(source, outputOptions, options) {
648
+ return this._processOutput(source, outputOptions?.sourcemap, await prettier.format(source, options))
649
+ }
650
+ _processOutput(source, sourcemap, output) {
651
+ const defaultSourcemap = null != this._sourcemap && this._sourcemap
652
+ if (!(sourcemap ?? defaultSourcemap)) return { code: output }
653
+ if ("silent" !== defaultSourcemap) {
654
+ console.warn(`[${this.name}] Sourcemap is enabled, computing diff is required`)
655
+ console.warn(`[${this.name}] This may take a moment (depends on the size of your bundle)`)
656
+ }
657
+ const magicString = new MagicString(source),
658
+ changes = diff.diffChars(source, output)
659
+ if (changes && changes.length > 0) {
660
+ let idx = 0
661
+ changes.forEach(part => {
662
+ if (part.added) {
663
+ magicString.prependLeft(idx, part.value)
664
+ idx -= part.count
665
+ } else part.removed && magicString.remove(idx, idx + part.count)
666
+ idx += part.count
667
+ })
668
+ }
669
+ return { code: magicString.toString(), map: magicString.generateMap({ hires: !0 }) }
670
+ }
671
+ }
672
+ assert(Reflect.defineProperty(RollupPluginPrettier, "name", { value: "rolldown-plugin-prettier" }))
673
+ export { RollupPluginPrettier as t }
@@ -1,66 +1,2 @@
1
- import path from "node:path"
2
- import hasIn from "lodash.hasin"
3
- import isEmpty from "lodash.isempty"
4
- import isNil from "lodash.isnil"
5
- import omitBy from "lodash.omitby"
6
- import MagicString from "magic-string"
7
- import * as diff from "diff"
8
- import prettier from "prettier"
9
- const OPTIONS = new Set(["sourcemap", "cwd"])
10
- function resolvePrettierConfig(cwd) {
11
- const fromFile = path.join(cwd, "__noop__.js")
12
- return prettier.resolveConfig
13
- ? prettier.resolveConfig(fromFile)
14
- : prettier.resolveConfigSync
15
- ? Promise.resolve(prettier.resolveConfigSync(cwd))
16
- : Promise.resolve(null)
17
- }
18
- var RollupPluginPrettier = class {
19
- constructor(options = {}) {
20
- this.name = "rollup-plugin-prettier"
21
- this._options = Promise.resolve(omitBy(options, (value, key) => OPTIONS.has(key)))
22
- const cwd = hasIn(options, "cwd") ? options.cwd : process.cwd()
23
- this._options = Promise.all([resolvePrettierConfig(cwd), this._options]).then(results =>
24
- Object.assign({}, ...results.map(result => result || {}))
25
- )
26
- this._options = this._options.then(opts => (isEmpty(opts) ? void 0 : opts))
27
- this._sourcemap = hasIn(options, "sourcemap") ? options.sourcemap : null
28
- }
29
- getSourcemap() {
30
- return this._sourcemap
31
- }
32
- enableSourcemap() {
33
- this._sourcemap = !0
34
- }
35
- reformat(source, outputOptions) {
36
- return this._options.then(options => this._reformat(source, outputOptions, options))
37
- }
38
- _reformat(source, outputOptions, options) {
39
- const { sourcemap } = outputOptions || {}
40
- return Promise.resolve(prettier.format(source, options)).then(output =>
41
- this._processOutput(source, sourcemap, output)
42
- )
43
- }
44
- _processOutput(source, sourcemap, output) {
45
- const defaultSourcemap = !isNil(this._sourcemap) && this._sourcemap
46
- if (!(isNil(sourcemap) ? defaultSourcemap : sourcemap)) return { code: output }
47
- if ("silent" !== defaultSourcemap) {
48
- console.warn(`[${this.name}] Sourcemap is enabled, computing diff is required`)
49
- console.warn(`[${this.name}] This may take a moment (depends on the size of your bundle)`)
50
- }
51
- const magicString = new MagicString(source),
52
- changes = diff.diffChars(source, output)
53
- if (changes && changes.length > 0) {
54
- let idx = 0
55
- changes.forEach(part => {
56
- if (part.added) {
57
- magicString.prependLeft(idx, part.value)
58
- idx -= part.count
59
- } else part.removed && magicString.remove(idx, idx + part.count)
60
- idx += part.count
61
- })
62
- }
63
- return { code: magicString.toString(), map: magicString.generateMap({ hires: !0 }) }
64
- }
65
- }
1
+ import { t as RollupPluginPrettier } from "./rollup-plugin-prettier-Do8e9vYR.js"
66
2
  export { RollupPluginPrettier }