comment-block-replacer 0.1.18 → 0.1.20
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 +19 -0
- package/package.json +3 -3
- package/src/index.js +5 -4
- package/test/index.test.js +7 -9
- package/types/index.d.ts +0 -69
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.20](https://github.com/DavidWells/markdown-magic/compare/comment-block-replacer@0.1.19...comment-block-replacer@0.1.20) (2026-06-23)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package comment-block-replacer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.1.19](https://github.com/DavidWells/markdown-magic/compare/comment-block-replacer@0.1.18...comment-block-replacer@0.1.19) (2026-05-30)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **block-replacer:** update test to reflect preloaded-content behavior ([f1394c4](https://github.com/DavidWells/markdown-magic/commit/f1394c44a174101aac8e5972f0734c3011ca17fa))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.1.18](https://github.com/DavidWells/markdown-magic/compare/comment-block-replacer@0.1.17...comment-block-replacer@0.1.18) (2026-01-19)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package comment-block-replacer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comment-block-replacer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Process files with comment block replacements",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"release:major": "pnpm run build && pnpm version major && pnpm publish"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"comment-block-transformer": "0.
|
|
18
|
+
"comment-block-transformer": "0.8.1",
|
|
19
19
|
"is-valid-path": "^0.1.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "2a9f186dc8de21560157805b95c9d2ef28bdb71b"
|
|
29
29
|
}
|
package/src/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const { blockTransformer } = require('comment-block-transformer')
|
|
|
16
16
|
* @typedef {ProcessContentConfig & {
|
|
17
17
|
* content?: string
|
|
18
18
|
* srcPath?: string
|
|
19
|
+
* parsedBlocks?: import('comment-block-parser').ParseBlocksResult
|
|
19
20
|
* outputPath?: string
|
|
20
21
|
* dryRun?: boolean
|
|
21
22
|
* patterns?: {
|
|
@@ -82,11 +83,11 @@ async function processFile(opts = {}) {
|
|
|
82
83
|
const outputDir = output.directory || opts.outputDir
|
|
83
84
|
|
|
84
85
|
let srcPath = opts.srcPath
|
|
85
|
-
if (srcPath && content) {
|
|
86
|
-
throw new Error(`Can't set both "srcPath" & "content"`)
|
|
87
|
-
}
|
|
88
86
|
let fileContents
|
|
89
|
-
if (content) {
|
|
87
|
+
if (typeof content === 'string' && srcPath) {
|
|
88
|
+
// Allow callers to provide preloaded content for srcPath files
|
|
89
|
+
fileContents = content
|
|
90
|
+
} else if (content) {
|
|
90
91
|
const isFile = isValidFile(content) && content.indexOf('\n') === -1
|
|
91
92
|
srcPath = (isFile) ? content : undefined
|
|
92
93
|
fileContents = (!isFile) ? content : undefined
|
package/test/index.test.js
CHANGED
|
@@ -192,20 +192,18 @@ test content
|
|
|
192
192
|
assert.is(result.isChanged, false)
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
-
test('should handle both srcPath and content
|
|
195
|
+
test('should handle both srcPath and content using preloaded content', async () => {
|
|
196
196
|
/** @type {ProcessFileOptions} */
|
|
197
197
|
const options = {
|
|
198
|
-
srcPath: '/some/path',
|
|
199
|
-
content: '
|
|
198
|
+
srcPath: '/some/nonexistent/path',
|
|
199
|
+
content: 'preloaded content',
|
|
200
200
|
dryRun: true
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
assert.ok(error.message.includes('Can\'t set both "srcPath" & "content"'))
|
|
208
|
-
}
|
|
203
|
+
// When both srcPath and content are provided, content is used as preloaded
|
|
204
|
+
// file contents (caching optimization) — no error should be thrown.
|
|
205
|
+
const result = await processFile(options)
|
|
206
|
+
assert.ok(result, 'Should return a result without throwing')
|
|
209
207
|
})
|
|
210
208
|
|
|
211
209
|
test('should handle file with output directory', async () => {
|
package/types/index.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export type ProcessContentConfig = import("comment-block-transformer").ProcessContentConfig;
|
|
2
|
-
export type ProcessContentResult = import("comment-block-transformer").ProcessContentResult;
|
|
3
|
-
/**
|
|
4
|
-
* Extended configuration for processing files with additional file-specific options
|
|
5
|
-
*/
|
|
6
|
-
export type ProcessFileOptions = ProcessContentConfig & {
|
|
7
|
-
content?: string;
|
|
8
|
-
srcPath?: string;
|
|
9
|
-
outputPath?: string;
|
|
10
|
-
dryRun?: boolean;
|
|
11
|
-
patterns?: {
|
|
12
|
-
openPattern?: RegExp;
|
|
13
|
-
closePattern?: RegExp;
|
|
14
|
-
};
|
|
15
|
-
output?: {
|
|
16
|
-
directory?: string;
|
|
17
|
-
};
|
|
18
|
-
outputDir?: string;
|
|
19
|
-
applyTransformsToSource?: boolean;
|
|
20
|
-
open?: string;
|
|
21
|
-
close?: string;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Result of processing a file with comment block replacements
|
|
25
|
-
*/
|
|
26
|
-
export type ProcessFileResult = {
|
|
27
|
-
/**
|
|
28
|
-
* - Whether the content was modified
|
|
29
|
-
*/
|
|
30
|
-
isChanged: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* - Whether srcPath differs from outputPath
|
|
33
|
-
*/
|
|
34
|
-
isNewPath: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* - Whether comments should be stripped from output
|
|
37
|
-
*/
|
|
38
|
-
stripComments: boolean;
|
|
39
|
-
/**
|
|
40
|
-
* - Source file path used
|
|
41
|
-
*/
|
|
42
|
-
srcPath?: string;
|
|
43
|
-
/**
|
|
44
|
-
* - Output file path used
|
|
45
|
-
*/
|
|
46
|
-
outputPath?: string;
|
|
47
|
-
/**
|
|
48
|
-
* - Array of transforms that were applied
|
|
49
|
-
*/
|
|
50
|
-
transforms: any[];
|
|
51
|
-
/**
|
|
52
|
-
* - Array of transforms that were not found
|
|
53
|
-
*/
|
|
54
|
-
missingTransforms: any[];
|
|
55
|
-
/**
|
|
56
|
-
* - Original input content
|
|
57
|
-
*/
|
|
58
|
-
originalContents: string;
|
|
59
|
-
/**
|
|
60
|
-
* - Processed output content
|
|
61
|
-
*/
|
|
62
|
-
updatedContents: string;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Process a file with comment block replacements using configured transforms
|
|
66
|
-
* @param {ProcessFileOptions} [opts={}] - Processing options
|
|
67
|
-
* @returns {Promise<ProcessContentResult>} Result object with processed content and metadata
|
|
68
|
-
*/
|
|
69
|
-
export function processFile(opts?: ProcessFileOptions): Promise<ProcessContentResult>;
|