@jsrepo/transform-prettier 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +42 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 jsrepo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @jsrepo/transform-prettier
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.com/package/@jsrepo/transform-prettier)
|
|
4
|
+
[](https://npmjs.com/package/@jsrepo/transform-prettier)
|
|
5
|
+
|
|
6
|
+
A transform plugin for formatting registry items with Prettier using your local Prettier configuration before they are added to your project.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
Run the following command to install and add the transform to your config:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
jsrepo config transform @jsrepo/transform-prettier
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Manual Configuration
|
|
17
|
+
|
|
18
|
+
Install the transform plugin:
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm install @jsrepo/transform-prettier -D
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Add the transform to your config:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { defineConfig } from "jsrepo";
|
|
28
|
+
import prettier from "@jsrepo/transform-prettier";
|
|
29
|
+
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
transforms: [prettier()],
|
|
32
|
+
});
|
|
33
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Transform } from "jsrepo";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type Options = {
|
|
5
|
+
/** The name of the prettier config file to use. @default ".prettierrc" */
|
|
6
|
+
configFile?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A transform plugin for jsrepo to format code with prettier.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { defineConfig } from "jsrepo";
|
|
13
|
+
* import prettier from "@jsrepo/transform-prettier";
|
|
14
|
+
*
|
|
15
|
+
* export default defineConfig({
|
|
16
|
+
* // ...
|
|
17
|
+
* transforms: [prettier()],
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param options - The options for the transform plugin.
|
|
22
|
+
*/
|
|
23
|
+
declare function export_default(options?: Options): Transform;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Options, export_default as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import * as prettier from "prettier";
|
|
3
|
+
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* A transform plugin for jsrepo to format code with prettier.
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { defineConfig } from "jsrepo";
|
|
10
|
+
* import prettier from "@jsrepo/transform-prettier";
|
|
11
|
+
*
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* // ...
|
|
14
|
+
* transforms: [prettier()],
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param options - The options for the transform plugin.
|
|
19
|
+
*/
|
|
20
|
+
function src_default(options = {}) {
|
|
21
|
+
const configPromise = prettier.resolveConfig(path.join(process.cwd(), options.configFile ?? ".prettierrc"));
|
|
22
|
+
return { transform: async (code, opts) => {
|
|
23
|
+
const config = await configPromise;
|
|
24
|
+
return { code: await tryFormat(code, {
|
|
25
|
+
fileName: opts.fileName,
|
|
26
|
+
config
|
|
27
|
+
}) };
|
|
28
|
+
} };
|
|
29
|
+
}
|
|
30
|
+
function tryFormat(code, { fileName, config }) {
|
|
31
|
+
try {
|
|
32
|
+
return prettier.format(code, {
|
|
33
|
+
...config,
|
|
34
|
+
filepath: fileName
|
|
35
|
+
});
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { src_default as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsrepo/transform-prettier",
|
|
3
|
+
"description": "A transform plugin for jsrepo to format code with prettier.",
|
|
4
|
+
"version": "0.0.1-beta.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://jsrepo.dev",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Aidan Bleser",
|
|
9
|
+
"url": "https://github.com/ieedan"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/jsrepojs/jsrepo"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/jsrepojs/jsrepo/issues"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"jsrepo",
|
|
20
|
+
"transform",
|
|
21
|
+
"prettier",
|
|
22
|
+
"plugin"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"main": "./dist/index.js",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/**/*"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"prettier": "3.x",
|
|
37
|
+
"jsrepo": "3.0.0-beta.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"tsdown": "^0.15.9",
|
|
41
|
+
"@types/node": "^24.9.1"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsdown",
|
|
45
|
+
"dev": "tsdown --watch",
|
|
46
|
+
"check": "tsc --noEmit"
|
|
47
|
+
}
|
|
48
|
+
}
|