@thi.ng/tangle 0.2.16 → 0.2.18
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 +7 -1
- package/README.md +2 -2
- package/package.json +17 -17
- package/tangle.js +19 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-29T09:28:36Z
|
|
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,12 @@ 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
|
+
### [0.2.17](https://github.com/thi-ng/umbrella/tree/@thi.ng/tangle@0.2.17) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
17
|
+
|
|
12
18
|
## [0.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/tangle@0.2.0) (2024-03-07)
|
|
13
19
|
|
|
14
20
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 189 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -338,7 +338,7 @@ For Node.js REPL:
|
|
|
338
338
|
const tan = await import("@thi.ng/tangle");
|
|
339
339
|
```
|
|
340
340
|
|
|
341
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
341
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 2.00 KB
|
|
342
342
|
|
|
343
343
|
## Dependencies
|
|
344
344
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/tangle",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"description": "Literate programming code block tangling / codegen utility, inspired by org-mode & noweb",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://
|
|
14
|
+
"homepage": "https://thi.ng/tangle",
|
|
15
15
|
"funding": [
|
|
16
16
|
{
|
|
17
17
|
"type": "github",
|
|
@@ -37,23 +37,23 @@
|
|
|
37
37
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@thi.ng/api": "^8.11.
|
|
41
|
-
"@thi.ng/args": "^2.3.
|
|
42
|
-
"@thi.ng/checks": "^3.6.
|
|
43
|
-
"@thi.ng/compare": "^2.3.
|
|
44
|
-
"@thi.ng/date": "^2.7.
|
|
45
|
-
"@thi.ng/errors": "^2.5.
|
|
46
|
-
"@thi.ng/file-io": "^2.1.
|
|
47
|
-
"@thi.ng/logger": "^3.0.
|
|
48
|
-
"@thi.ng/strings": "^3.7.
|
|
49
|
-
"@thi.ng/transducers": "^9.0.
|
|
40
|
+
"@thi.ng/api": "^8.11.4",
|
|
41
|
+
"@thi.ng/args": "^2.3.35",
|
|
42
|
+
"@thi.ng/checks": "^3.6.6",
|
|
43
|
+
"@thi.ng/compare": "^2.3.7",
|
|
44
|
+
"@thi.ng/date": "^2.7.20",
|
|
45
|
+
"@thi.ng/errors": "^2.5.9",
|
|
46
|
+
"@thi.ng/file-io": "^2.1.4",
|
|
47
|
+
"@thi.ng/logger": "^3.0.14",
|
|
48
|
+
"@thi.ng/strings": "^3.7.35",
|
|
49
|
+
"@thi.ng/transducers": "^9.0.7"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@microsoft/api-extractor": "^7.
|
|
53
|
-
"@thi.ng/testament": "^0.4.
|
|
54
|
-
"esbuild": "^0.21.
|
|
52
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
53
|
+
"@thi.ng/testament": "^0.4.31",
|
|
54
|
+
"esbuild": "^0.21.5",
|
|
55
55
|
"typedoc": "^0.25.13",
|
|
56
|
-
"typescript": "^5.
|
|
56
|
+
"typescript": "^5.5.2"
|
|
57
57
|
},
|
|
58
58
|
"keywords": [
|
|
59
59
|
"codegen",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"status": "alpha",
|
|
94
94
|
"year": 2022
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\n"
|
|
97
97
|
}
|
package/tangle.js
CHANGED
|
@@ -15,7 +15,7 @@ const UnknownBlockError = defError(
|
|
|
15
15
|
(err) => `can't include unknown block ID: ${err[0]} (via ${err[1]})`,
|
|
16
16
|
() => ""
|
|
17
17
|
);
|
|
18
|
-
const
|
|
18
|
+
const __extractBlocks = (src, { format, logger }) => {
|
|
19
19
|
let nextID = 0;
|
|
20
20
|
const blocks = {};
|
|
21
21
|
const prefix = new RegExp(
|
|
@@ -25,7 +25,7 @@ const extractBlocks = (src, { format, logger }) => {
|
|
|
25
25
|
const suffix = isString(format.suffix) ? new RegExp(`${format.suffix.replace("+", "\\+")}`) : format.suffix;
|
|
26
26
|
let matchPrefix;
|
|
27
27
|
while (matchPrefix = prefix.exec(src)) {
|
|
28
|
-
let { id, tangle, noweb, publish } =
|
|
28
|
+
let { id, tangle, noweb, publish } = __parseBlockHeader(matchPrefix[2]);
|
|
29
29
|
!id && (id = `__block-${nextID++}`);
|
|
30
30
|
const matchStart = matchPrefix.index;
|
|
31
31
|
const start = src.indexOf("\n", matchStart + 1) + 1;
|
|
@@ -66,7 +66,7 @@ const extractBlocks = (src, { format, logger }) => {
|
|
|
66
66
|
}
|
|
67
67
|
return blocks;
|
|
68
68
|
};
|
|
69
|
-
const
|
|
69
|
+
const __resolveBlock = (block, ref, ctx) => {
|
|
70
70
|
if (block.resolved) return;
|
|
71
71
|
if (block.noweb === "no") {
|
|
72
72
|
block.resolved = true;
|
|
@@ -85,7 +85,7 @@ const resolveBlock = (block, ref, ctx) => {
|
|
|
85
85
|
let childBlock;
|
|
86
86
|
if (childID.indexOf("#") > 0) {
|
|
87
87
|
const [file, blockID] = childID.split("#");
|
|
88
|
-
childBlock =
|
|
88
|
+
childBlock = __loadAndResolveBlocks(
|
|
89
89
|
ctx.fs.resolve(ctx.fs.resolve(ref.path, ".."), file),
|
|
90
90
|
ctx
|
|
91
91
|
).blocks[blockID];
|
|
@@ -95,21 +95,21 @@ const resolveBlock = (block, ref, ctx) => {
|
|
|
95
95
|
childBlock = ref.blocks[childID];
|
|
96
96
|
}
|
|
97
97
|
if (!childBlock) throw new UnknownBlockError([childID, block.id]);
|
|
98
|
-
|
|
99
|
-
const newBody = isPlainObject(params) ?
|
|
98
|
+
__resolveBlock(childBlock, ref, ctx);
|
|
99
|
+
const newBody = isPlainObject(params) ? __parametricBody(childBlock.body, params) : childBlock.body;
|
|
100
100
|
block.body = block.body.replace(`<<${match[1]}>>`, newBody);
|
|
101
101
|
block.edited = true;
|
|
102
102
|
}
|
|
103
103
|
block.resolved = true;
|
|
104
104
|
block.body = block.body.replace(/\\</g, "<");
|
|
105
105
|
};
|
|
106
|
-
const
|
|
106
|
+
const __resolveBlocks = (ref, ctx) => {
|
|
107
107
|
for (let id in ref.blocks) {
|
|
108
|
-
|
|
108
|
+
__resolveBlock(ref.blocks[id], ref, ctx);
|
|
109
109
|
}
|
|
110
110
|
return ref;
|
|
111
111
|
};
|
|
112
|
-
const
|
|
112
|
+
const __parseFileMeta = (src) => {
|
|
113
113
|
if (!src.startsWith("---\n")) return {};
|
|
114
114
|
const res = {};
|
|
115
115
|
for (let line of split(src.substring(4))) {
|
|
@@ -119,26 +119,26 @@ const parseFileMeta = (src) => {
|
|
|
119
119
|
}
|
|
120
120
|
return res;
|
|
121
121
|
};
|
|
122
|
-
const
|
|
122
|
+
const __parseBlockHeader = (header) => transduce(
|
|
123
123
|
map((x) => x.split(":")),
|
|
124
124
|
assocObj(),
|
|
125
125
|
header.split(/\s+/)
|
|
126
126
|
);
|
|
127
|
-
const
|
|
127
|
+
const __parametricBody = (body, params) => body.replace(
|
|
128
128
|
/\{\{(\w+)\}\}/g,
|
|
129
129
|
(_, id) => params[id] != null ? params[id] : id
|
|
130
130
|
);
|
|
131
|
-
const
|
|
131
|
+
const __commentForLang = (lang, body) => {
|
|
132
132
|
const syntax = COMMENT_FORMATS[lang];
|
|
133
133
|
return isString(syntax) ? `${syntax} ${body}` : `${syntax[0]} ${body} ${syntax[1]}`;
|
|
134
134
|
};
|
|
135
|
-
const
|
|
135
|
+
const __loadAndResolveBlocks = (path, ctx) => {
|
|
136
136
|
path = ctx.fs.resolve(path);
|
|
137
137
|
if (!ctx.files[path]) {
|
|
138
138
|
const src = ctx.fs.read(path, ctx.logger);
|
|
139
|
-
const blocks =
|
|
139
|
+
const blocks = __extractBlocks(src, ctx);
|
|
140
140
|
const ref = ctx.files[path] = { path, src, blocks };
|
|
141
|
-
|
|
141
|
+
__resolveBlocks(ref, ctx);
|
|
142
142
|
}
|
|
143
143
|
return ctx.files[path];
|
|
144
144
|
};
|
|
@@ -161,9 +161,9 @@ const tangleFile = (path, ctx = {}) => {
|
|
|
161
161
|
...ctx.opts
|
|
162
162
|
}
|
|
163
163
|
};
|
|
164
|
-
const { path: $path, src, blocks } =
|
|
164
|
+
const { path: $path, src, blocks } = __loadAndResolveBlocks(path, $ctx);
|
|
165
165
|
const parentDir = $ctx.fs.resolve($path, "..");
|
|
166
|
-
const meta =
|
|
166
|
+
const meta = __parseFileMeta(src);
|
|
167
167
|
const sorted = Object.values(blocks).sort(compareByKey("start"));
|
|
168
168
|
let prev = 0;
|
|
169
169
|
let res = [];
|
|
@@ -188,11 +188,11 @@ ${fmt.suffix}
|
|
|
188
188
|
if (!$ctx.outputs[dest]) {
|
|
189
189
|
if ($ctx.opts.comments && COMMENT_FORMATS[block.lang]) {
|
|
190
190
|
body = [
|
|
191
|
-
|
|
191
|
+
__commentForLang(
|
|
192
192
|
block.lang,
|
|
193
193
|
`Tangled @ ${FMT_ISO_SHORT()} - DO NOT EDIT!`
|
|
194
194
|
),
|
|
195
|
-
|
|
195
|
+
__commentForLang(block.lang, `Source: ${$path}`),
|
|
196
196
|
"",
|
|
197
197
|
body
|
|
198
198
|
].join("\n");
|