rolldown-plugin-prettier 0.0.0-a
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 +23 -0
- package/README.md +54 -0
- package/default.d.ts +31 -0
- package/default.js +34 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mickael Jeanroy
|
|
4
|
+
Copyright (c) 2026 @pastelmind (https://github.com/pastelmind)
|
|
5
|
+
Copyright (c) 2026 Samual Norman <me@samual.uk> (https://samual.uk/)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Rolldown Plugin Prettier
|
|
2
|
+
Rolldown plugin that can be used to run [Prettier](https://prettier.io/) on the final bundle.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
Add the plugin `npm install --save-dev rolldown-plugin-prettier`, then add it to your `rolldown.config.js`, for
|
|
6
|
+
example:
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
import prettier from "rolldown-plugin-prettier"
|
|
10
|
+
// …
|
|
11
|
+
export default {
|
|
12
|
+
// …
|
|
13
|
+
plugins: [
|
|
14
|
+
// …
|
|
15
|
+
prettier({
|
|
16
|
+
printWidth: 120,
|
|
17
|
+
tabWidth: 4,
|
|
18
|
+
useTabs: true,
|
|
19
|
+
semi: false,
|
|
20
|
+
trailingComma: "none",
|
|
21
|
+
arrowParens: "avoid",
|
|
22
|
+
experimentalTernaries: true
|
|
23
|
+
})
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Plugin Options
|
|
29
|
+
### `cwd`
|
|
30
|
+
- default: `process.cwd()`
|
|
31
|
+
- type: `string`
|
|
32
|
+
- example: `prettier({ cwd: "path/to/dir" })`
|
|
33
|
+
- purpose: The directory prettier will use to find the local config
|
|
34
|
+
|
|
35
|
+
### `sourcemap`
|
|
36
|
+
- default: `undefined`
|
|
37
|
+
- type: `"silent"`
|
|
38
|
+
- example: `prettier({ sourcemap: "silent" })`
|
|
39
|
+
- purpose: Set to `"silent"` to suppress warnings.
|
|
40
|
+
|
|
41
|
+
If source map is enabled in the global rolldown options, then a source map will be generated on the formatted bundle.
|
|
42
|
+
|
|
43
|
+
Note that this may take some time since `prettier` package is not able to generate a sourcemap and this plugin must
|
|
44
|
+
compute the diff between the original bundle and the formatted result and generate the corresponding sourcemap.
|
|
45
|
+
|
|
46
|
+
## Contributing
|
|
47
|
+
If you find a bug or think about enhancement, feel free to contribute and submit an issue or a pull request. See
|
|
48
|
+
`CONTRIBUTING.md`.
|
|
49
|
+
|
|
50
|
+
## Credit
|
|
51
|
+
Thank you [Mickael Jeanroy](https://github.com/mjeanroy) for making the version of this plugin that this was forked from
|
|
52
|
+
[`rollup-plugin-prettier`](https://github.com/mjeanroy/rollup-plugin-prettier).
|
|
53
|
+
|
|
54
|
+
Please see `LICENSE`.
|
package/default.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Options as Options$1 } from "prettier"
|
|
2
|
+
import { Plugin } from "rolldown"
|
|
3
|
+
|
|
4
|
+
//#region src/default.d.ts
|
|
5
|
+
interface Options extends Options$1 {
|
|
6
|
+
/**
|
|
7
|
+
* Directory to look for a Prettier config file.
|
|
8
|
+
*
|
|
9
|
+
* @default process.cwd()
|
|
10
|
+
*/
|
|
11
|
+
cwd?: string
|
|
12
|
+
/**
|
|
13
|
+
* Silence sourcemap warnings.
|
|
14
|
+
*
|
|
15
|
+
* Doesn't do anything if set to a boolean as Rolldown's own `output.sourcemap` decides if a sourcemap is generated.
|
|
16
|
+
* This behaviour matches [`rollup-plugin-prettier`](https://github.com/mjeanroy/rollup-plugin-prettier).
|
|
17
|
+
*/
|
|
18
|
+
sourcemap?: boolean | "silent"
|
|
19
|
+
}
|
|
20
|
+
declare namespace rolldownPluginPrettier {
|
|
21
|
+
export { Options }
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create rolldown plugin
|
|
25
|
+
*
|
|
26
|
+
* @param options Plugin options.
|
|
27
|
+
* @return Plugin instance.
|
|
28
|
+
*/
|
|
29
|
+
declare const rolldownPluginPrettier: (options: Options) => Plugin
|
|
30
|
+
//#endregion
|
|
31
|
+
export { Options, rolldownPluginPrettier as default, rolldownPluginPrettier as prettier, rolldownPluginPrettier }
|
package/default.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { diffChars } from "diff";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import * as prettier from "prettier";
|
|
5
|
+
const NAME = "rolldown-plugin-prettier", rolldownPluginPrettier = (options) => ({
|
|
6
|
+
name: NAME,
|
|
7
|
+
async renderChunk(source, _chunkInfo, outputOptions) {
|
|
8
|
+
const prettierConfig = await prettier.resolveConfig(path.join(options.cwd ?? process.cwd())), { sourcemap, cwd, ...prettierOptions } = options, mergedOptions = {
|
|
9
|
+
...prettierConfig,
|
|
10
|
+
...prettierOptions
|
|
11
|
+
}, output = await prettier.format(source, Reflect.ownKeys(mergedOptions).length ? mergedOptions : void 0);
|
|
12
|
+
if (!outputOptions.sourcemap) return { code: output };
|
|
13
|
+
if ("silent" != options.sourcemap) {
|
|
14
|
+
console.warn(`[${NAME}] Sourcemap is enabled, computing diff is required`);
|
|
15
|
+
console.warn(`[${NAME}] This may take a moment (depends on the size of your bundle)`);
|
|
16
|
+
}
|
|
17
|
+
const magicString = new MagicString(source), changes = diffChars(source, output);
|
|
18
|
+
if (changes.length) {
|
|
19
|
+
let idx = 0;
|
|
20
|
+
changes.forEach((part) => {
|
|
21
|
+
if (part.added) {
|
|
22
|
+
magicString.prependLeft(idx, part.value);
|
|
23
|
+
idx -= part.count;
|
|
24
|
+
} else part.removed && magicString.remove(idx, idx + part.count);
|
|
25
|
+
idx += part.count;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
code: magicString.toString(),
|
|
30
|
+
map: magicString.generateMap({ hires: !0 })
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
export { rolldownPluginPrettier as default, rolldownPluginPrettier as prettier, rolldownPluginPrettier };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rolldown-plugin-prettier",
|
|
3
|
+
"version": "0.0.0-a+0fcaf9c",
|
|
4
|
+
"description": "Rolldown plugin for code formatting using Prettier",
|
|
5
|
+
"author": "Mickael Jeanroy <mickael.jeanroy@gmail.com>",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"@pastelmind (https://github.com/pastelmind)",
|
|
8
|
+
"Samual Norman <me@samual.uk> (https://samual.uk/)"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"homepage": "https://github.com/samualtnorman/rolldown-plugin-prettier#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/samualtnorman/rolldown-plugin-prettier/issues",
|
|
14
|
+
"email": "me@samual.uk"
|
|
15
|
+
},
|
|
16
|
+
"repository": "github:samualtnorman/rolldown-plugin-prettier",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"rolldown",
|
|
19
|
+
"rolldown-plugin",
|
|
20
|
+
"plugin",
|
|
21
|
+
"prettier"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./default.js"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": "^20.10 || ^22 || >=24"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"diff": "^8",
|
|
32
|
+
"magic-string": "0.30.21",
|
|
33
|
+
"prettier": "^3",
|
|
34
|
+
"rolldown": "1.0.0-rc.10"
|
|
35
|
+
}
|
|
36
|
+
}
|