@theholocron/rollup-plugin-transform-template 3.48.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 +44 -0
- package/client.d.ts +9 -0
- package/dist/index.d.mts +39 -0
- package/dist/index.mjs +37 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Newton Koumantzelis
|
|
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,44 @@
|
|
|
1
|
+
# `@theholocron/rollup-plugin-transform-template`
|
|
2
|
+
|
|
3
|
+
Rollup plugin for Vite/Rolldown/tsdown that transforms template files into default-exported string literals so they can be imported directly in TypeScript/JavaScript.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D @theholocron/rollup-plugin-transform-template
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// vite.config.ts / vitest.config.ts / tsdown.config.ts
|
|
15
|
+
import { transformTemplate } from "@theholocron/rollup-plugin-transform-template";
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
plugins: [transformTemplate({ dirs: ["/src/commands/setup/templates/"] })],
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then import template files directly:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import editorconfigBody from "./editorconfig";
|
|
26
|
+
import labelerBody from "./github-labeler.yml";
|
|
27
|
+
// Both resolve to plain strings at runtime
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What gets transformed
|
|
31
|
+
|
|
32
|
+
| File type | Condition | Result |
|
|
33
|
+
| ---------------------- | ---------------------------------- | ---------------------------------------------------------------- |
|
|
34
|
+
| `.yml` | Always | Default-exported string |
|
|
35
|
+
| `.md` | Always | Default-exported string |
|
|
36
|
+
| Any non-JSON extension | Path contains a string from `dirs` | Default-exported string |
|
|
37
|
+
| `.json` | Even inside `dirs` | Not transformed — bundlers handle JSON natively as typed objects |
|
|
38
|
+
| `.ts` / `.tsx` | Even inside `dirs` | Not transformed — source files, not templates |
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
| Option | Type | Default | Description |
|
|
43
|
+
| ------ | ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `dirs` | `string[]` | `[]` | Path substrings — any file whose resolved id contains one of these strings (and isn't `.json`/`.ts`/`.tsx`) is transformed |
|
package/client.d.ts
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
interface TransformTemplateOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Additional directory path segments. Any file whose resolved id contains
|
|
5
|
+
* one of these strings is transformed into a default-exported string,
|
|
6
|
+
* regardless of extension (except .json, which is handled natively by most
|
|
7
|
+
* bundlers and should not be double-transformed).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* transformTemplate({ dirs: ["/commands/setup/templates/"] })
|
|
11
|
+
*/
|
|
12
|
+
dirs?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Rollup/Vite/Rolldown plugin that transforms text files into
|
|
16
|
+
* default-exported string literals so they can be imported directly in code.
|
|
17
|
+
*
|
|
18
|
+
* Two categories of files are transformed:
|
|
19
|
+
* 1. `.yml` and `.md` files — always, regardless of location.
|
|
20
|
+
* 2. Any non-JSON file whose resolved path contains a string listed in `dirs`.
|
|
21
|
+
*
|
|
22
|
+
* JSON files in `dirs` are intentionally excluded: bundlers handle `.json`
|
|
23
|
+
* imports natively as typed objects, which is more useful than a raw string.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // vite.config.ts / vitest.config.ts / tsdown.config.ts
|
|
27
|
+
* import { transformTemplate } from "@theholocron/rollup-plugin-transform-template";
|
|
28
|
+
*
|
|
29
|
+
* plugins: [transformTemplate({ dirs: ["/src/commands/setup/templates/"] })]
|
|
30
|
+
*/
|
|
31
|
+
declare function transformTemplate(options?: TransformTemplateOptions): {
|
|
32
|
+
name: string;
|
|
33
|
+
transform(_code: string, id: string): {
|
|
34
|
+
code: string;
|
|
35
|
+
map: null;
|
|
36
|
+
} | null;
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { TransformTemplateOptions, transformTemplate };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
//#region src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Rollup/Vite/Rolldown plugin that transforms text files into
|
|
5
|
+
* default-exported string literals so they can be imported directly in code.
|
|
6
|
+
*
|
|
7
|
+
* Two categories of files are transformed:
|
|
8
|
+
* 1. `.yml` and `.md` files — always, regardless of location.
|
|
9
|
+
* 2. Any non-JSON file whose resolved path contains a string listed in `dirs`.
|
|
10
|
+
*
|
|
11
|
+
* JSON files in `dirs` are intentionally excluded: bundlers handle `.json`
|
|
12
|
+
* imports natively as typed objects, which is more useful than a raw string.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // vite.config.ts / vitest.config.ts / tsdown.config.ts
|
|
16
|
+
* import { transformTemplate } from "@theholocron/rollup-plugin-transform-template";
|
|
17
|
+
*
|
|
18
|
+
* plugins: [transformTemplate({ dirs: ["/src/commands/setup/templates/"] })]
|
|
19
|
+
*/
|
|
20
|
+
function transformTemplate(options = {}) {
|
|
21
|
+
const { dirs = [] } = options;
|
|
22
|
+
return {
|
|
23
|
+
name: "rollup-plugin-transform-template",
|
|
24
|
+
transform(_code, id) {
|
|
25
|
+
const isYmlOrMd = id.endsWith(".yml") || id.endsWith(".md");
|
|
26
|
+
const isNativeOrSource = id.endsWith(".json") || id.endsWith(".ts") || id.endsWith(".tsx");
|
|
27
|
+
const isTemplateDir = dirs.length > 0 && dirs.some((dir) => id.includes(dir)) && !isNativeOrSource;
|
|
28
|
+
if (!isYmlOrMd && !isTemplateDir) return null;
|
|
29
|
+
return {
|
|
30
|
+
code: `export default ${JSON.stringify(readFileSync(id, "utf8"))};`,
|
|
31
|
+
map: null
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { transformTemplate };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@theholocron/rollup-plugin-transform-template",
|
|
3
|
+
"version": "3.48.0",
|
|
4
|
+
"description": "Rollup/Vite/Rolldown plugin that transforms template files into default-exported strings.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rollup",
|
|
7
|
+
"plugin",
|
|
8
|
+
"rollup-plugin",
|
|
9
|
+
"vite",
|
|
10
|
+
"rolldown",
|
|
11
|
+
"template",
|
|
12
|
+
"transform"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/theholocron/holocron/tree/main/packages/rollup-plugin-transform-template#readme",
|
|
15
|
+
"bugs": "https://github.com/theholocron/holocron/issues",
|
|
16
|
+
"repository": "theholocron/holocron",
|
|
17
|
+
"license": "GPL-3.0",
|
|
18
|
+
"author": "Newton Koumantzelis",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"default": "./dist/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./client": {
|
|
28
|
+
"types": "./client.d.ts",
|
|
29
|
+
"default": "./client.d.ts"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"client.d.ts",
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@theholocron/eslint-config": "^7.32.1",
|
|
38
|
+
"@theholocron/tsconfig": "^7.32.1",
|
|
39
|
+
"@theholocron/tsdown-config": "^7.32.1",
|
|
40
|
+
"@theholocron/vitest-config": "^7.32.1",
|
|
41
|
+
"@types/node": "^26",
|
|
42
|
+
"vitest": "^4.1.11"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=22.0.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"lint": "eslint src",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"test:coverage": "vitest run --coverage"
|
|
54
|
+
}
|
|
55
|
+
}
|