@thi.ng/transclude 1.0.4 → 1.1.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/CHANGELOG.md +10 -1
- package/README.md +2 -1
- package/package.json +9 -8
- package/tpl/file.d.ts +7 -3
- package/tpl/file.js +26 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2025-01-
|
|
3
|
+
- **Last updated**: 2025-01-21T15:46:52Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,15 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [1.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/transclude@1.1.0) (2025-01-21)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- support recursive includes (w/ cycle detection) ([923d968](https://github.com/thi-ng/umbrella/commit/923d968))
|
|
17
|
+
- update `preincludeFile()` transform to support recursive includes
|
|
18
|
+
- add tests/assets
|
|
19
|
+
- update deps
|
|
20
|
+
|
|
12
21
|
### [0.1.91](https://github.com/thi-ng/umbrella/tree/@thi.ng/transclude@0.1.91) (2024-06-21)
|
|
13
22
|
|
|
14
23
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -66,12 +66,13 @@ For Node.js REPL:
|
|
|
66
66
|
const tra = await import("@thi.ng/transclude");
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Package sizes (brotli'd, pre-treeshake): ESM: 1.
|
|
69
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 1.96 KB
|
|
70
70
|
|
|
71
71
|
## Dependencies
|
|
72
72
|
|
|
73
73
|
- [@thi.ng/api](https://github.com/thi-ng/umbrella/tree/develop/packages/api)
|
|
74
74
|
- [@thi.ng/checks](https://github.com/thi-ng/umbrella/tree/develop/packages/checks)
|
|
75
|
+
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
|
|
75
76
|
- [@thi.ng/file-io](https://github.com/thi-ng/umbrella/tree/develop/packages/file-io)
|
|
76
77
|
- [@thi.ng/logger](https://github.com/thi-ng/umbrella/tree/develop/packages/logger)
|
|
77
78
|
- [@thi.ng/strings](https://github.com/thi-ng/umbrella/tree/develop/packages/strings)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/transclude",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Extensible functional template engine for text document generation, incl. various high-level Markdown features",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,12 +40,13 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/api": "^8.11.
|
|
44
|
-
"@thi.ng/checks": "^3.6.
|
|
45
|
-
"@thi.ng/
|
|
46
|
-
"@thi.ng/
|
|
47
|
-
"@thi.ng/
|
|
48
|
-
"@thi.ng/
|
|
43
|
+
"@thi.ng/api": "^8.11.17",
|
|
44
|
+
"@thi.ng/checks": "^3.6.20",
|
|
45
|
+
"@thi.ng/errors": "^2.5.23",
|
|
46
|
+
"@thi.ng/file-io": "^2.1.23",
|
|
47
|
+
"@thi.ng/logger": "^3.0.28",
|
|
48
|
+
"@thi.ng/strings": "^3.9.2",
|
|
49
|
+
"@thi.ng/transducers": "^9.2.15"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@microsoft/api-extractor": "^7.48.1",
|
|
@@ -115,5 +116,5 @@
|
|
|
115
116
|
],
|
|
116
117
|
"year": 2022
|
|
117
118
|
},
|
|
118
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "22f6d518aed5951bb37b406c8ae85a6c3e6be517\n"
|
|
119
120
|
}
|
package/tpl/file.d.ts
CHANGED
|
@@ -3,18 +3,22 @@ import type { TemplateFn } from "../api.js";
|
|
|
3
3
|
* Parametric template function. Includes file given as template argument:
|
|
4
4
|
* `{{include header.md}}`
|
|
5
5
|
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Does NOT support recursive inclusion. Use {@link preincludeFile} (given as
|
|
8
|
+
* {@link TranscludeCtx.pre} transform) as alternative.
|
|
9
|
+
*
|
|
6
10
|
* @param ctx
|
|
7
11
|
* @param args
|
|
8
12
|
* @param currPath
|
|
9
13
|
*/
|
|
10
14
|
export declare const includeFile: TemplateFn;
|
|
11
15
|
/**
|
|
12
|
-
* Pre-processing stage parametric template function.
|
|
13
|
-
* template argument: `<!-- include header.md -->`.
|
|
16
|
+
* Pre-processing stage parametric template function. Recursively includes file
|
|
17
|
+
* given as template argument: `<!-- include header.md -->`.
|
|
14
18
|
*
|
|
15
19
|
* @param ctx
|
|
16
20
|
* @param args
|
|
17
|
-
* @param
|
|
21
|
+
* @param initialPath
|
|
18
22
|
*/
|
|
19
23
|
export declare const preincludeFile: TemplateFn;
|
|
20
24
|
//# sourceMappingURL=file.d.ts.map
|
package/tpl/file.js
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
|
|
2
|
+
import { readText } from "@thi.ng/file-io/text";
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
3
4
|
const includeFile = ({ logger }, args, currPath) => readText(resolve(resolve(currPath, ".."), args[2].trim()), logger);
|
|
4
|
-
const preincludeFile = ({ logger }, [src],
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
)
|
|
5
|
+
const preincludeFile = ({ logger }, [src], initialPath) => {
|
|
6
|
+
const pattern = /<!-- include (.+) -->/g;
|
|
7
|
+
const fileCache = {};
|
|
8
|
+
const replaceImport = (includePath, currPath, route) => {
|
|
9
|
+
includePath = resolve(resolve(currPath, ".."), includePath.trim());
|
|
10
|
+
if (fileCache[includePath]) return fileCache[includePath];
|
|
11
|
+
if (route.includes(includePath))
|
|
12
|
+
illegalArgs(
|
|
13
|
+
`include cycle detected: ${basename(currPath)} -> ${basename(
|
|
14
|
+
includePath
|
|
15
|
+
)}`
|
|
16
|
+
);
|
|
17
|
+
src = readText(includePath, logger).replace(
|
|
18
|
+
pattern,
|
|
19
|
+
(_, path) => replaceImport(path, includePath, [...route, path])
|
|
20
|
+
);
|
|
21
|
+
return fileCache[includePath] = src;
|
|
22
|
+
};
|
|
23
|
+
return src.replace(
|
|
24
|
+
pattern,
|
|
25
|
+
(_, path) => replaceImport(path, initialPath, [initialPath])
|
|
26
|
+
);
|
|
27
|
+
};
|
|
8
28
|
export {
|
|
9
29
|
includeFile,
|
|
10
30
|
preincludeFile
|