@knapsack/rendering-utils 4.102.1--canary.8143.f3630f4.0 → 4.102.1--canary.7823.8675e86.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/.lintstagedrc.mjs +2 -2
- package/.turbo/turbo-test.log +34 -14
- package/dist/blocks-to-html.d.ts +0 -10
- package/dist/blocks-to-html.d.ts.map +1 -1
- package/dist/blocks-to-html.js +1 -39
- package/dist/blocks-to-html.js.map +1 -1
- package/package.json +11 -11
- package/src/blocks-to-html.ts +1 -40
- package/tsconfig.json +1 -8
package/.lintstagedrc.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { dirname } from 'node:path';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
|
|
4
|
-
import defaultConfig
|
|
4
|
+
import defaultConfig from '../../.lintstagedrc.mjs';
|
|
5
5
|
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
|
|
8
8
|
export default {
|
|
9
|
-
'*.{ts,tsx,js,jsx,cjs,mjs,mts,cts}':
|
|
9
|
+
'*.{ts,tsx,js,jsx,cjs,mjs,mts,cts}': `cd ${__dirname} && ./node_modules/.bin/eslint`,
|
|
10
10
|
...defaultConfig,
|
|
11
11
|
};
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
|
-
$
|
|
1
|
+
$ vitest run
|
|
2
2
|
|
|
3
|
-
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.
|
|
3
|
+
[1m[30m[46m RUN [49m[39m[22m [36mv4.1.9 [39m[90m/home/runner/work/app-monorepo/app-monorepo/libs/rendering-utils[39m
|
|
4
|
+
|
|
5
|
+
[90mstderr[2m | src/blocks-to-html.test.ts[2m > [22m[2mblocksToHtml - single markdown-block with string
|
|
6
|
+
[22m[39mmarked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
7
|
+
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
8
|
+
|
|
9
|
+
[90mstderr[2m | src/blocks-to-html.test.ts[2m > [22m[2mblocksToHtml - single markdown-block with array
|
|
10
|
+
[22m[39mmarked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
11
|
+
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
12
|
+
|
|
13
|
+
[90mstderr[2m | src/blocks-to-html.test.ts[2m > [22m[2mblocksToHtml - single markdown-block with empty string
|
|
14
|
+
[22m[39mmarked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
15
|
+
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
16
|
+
|
|
17
|
+
[90mstderr[2m | src/blocks-to-html.test.ts[2m > [22m[2mblocksToHtml - single markdown-block with undefined md
|
|
18
|
+
[22m[39mmarked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
19
|
+
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
4
20
|
|
|
5
21
|
[90mstderr[2m | src/blocks-to-html.test.ts[2m > [22m[2mblocksToHtml - text-editor with unknown TipTap node type does not throw
|
|
6
22
|
[22m[39m[blocks-to-html] TipTap render failed for block "test-1" (text-editor): RangeError: Unknown node type: this-node-type-does-not-exist
|
|
7
|
-
at Schema.nodeType (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.
|
|
8
|
-
at Node.fromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.
|
|
9
|
-
at Schema.nodeFromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.
|
|
23
|
+
at Schema.nodeType (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.7/node_modules/[4mprosemirror-model[24m/dist/index.js:2490:19)
|
|
24
|
+
at Node.fromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.7/node_modules/[4mprosemirror-model[24m/dist/index.js:1530:27)
|
|
25
|
+
at Schema.nodeFromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.7/node_modules/[4mprosemirror-model[24m/dist/index.js:2448:42)
|
|
10
26
|
at Array.map (<anonymous>)
|
|
11
|
-
at Fragment.fromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.
|
|
12
|
-
at Node.fromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.
|
|
13
|
-
at generateHTML (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/@tiptap+html@3.
|
|
27
|
+
at Fragment.fromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.7/node_modules/[4mprosemirror-model[24m/dist/index.js:314:41)
|
|
28
|
+
at Node.fromJSON (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/prosemirror-model@1.25.7/node_modules/[4mprosemirror-model[24m/dist/index.js:1529:32)
|
|
29
|
+
at generateHTML (file:///home/runner/work/app-monorepo/app-monorepo/node_modules/[4m.pnpm[24m/@tiptap+html@3.24.0_@tiptap+core@3.24.0_@tiptap+pm@3.24.0__@tiptap+pm@3.24.0_happy-dom@_5581d52037c54da583424e26a68fd3a3/node_modules/[4m@tiptap/html[24m/dist/server/index.js:54:28)
|
|
14
30
|
at convertTipTapJsonToHtml (/home/runner/work/app-monorepo/app-monorepo/libs/tiptap-utils/src/tiptap-utils.ts:27:22)
|
|
15
|
-
at tiptapToHtmlSafe [90m(/home/runner/work/app-monorepo/app-monorepo/libs/rendering-utils/[39msrc/blocks-to-html.ts:
|
|
16
|
-
at blockToHtml [90m(/home/runner/work/app-monorepo/app-monorepo/libs/rendering-utils/[39msrc/blocks-to-html.ts:
|
|
31
|
+
at tiptapToHtmlSafe [90m(/home/runner/work/app-monorepo/app-monorepo/libs/rendering-utils/[39msrc/blocks-to-html.ts:43:12[90m)[39m
|
|
32
|
+
at blockToHtml [90m(/home/runner/work/app-monorepo/app-monorepo/libs/rendering-utils/[39msrc/blocks-to-html.ts:65:14[90m)[39m
|
|
33
|
+
|
|
34
|
+
[90mstderr[2m | src/blocks-to-html.test.ts[2m > [22m[2mblocksToHtml - multiple different block types
|
|
35
|
+
[22m[39mmarked(): mangle parameter is enabled by default, but is deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-mangle, or disable by setting `{mangle: false}`.
|
|
36
|
+
marked(): headerIds and headerPrefix parameters enabled by default, but are deprecated since version 5.0.0, and will be removed in the future. To clear this warning, install https://www.npmjs.com/package/marked-gfm-heading-id, or disable by setting `{headerIds: false}`.
|
|
17
37
|
|
|
18
|
-
[32m✓[39m src/blocks-to-html.test.ts [2m([22m[
|
|
38
|
+
[32m✓[39m src/blocks-to-html.test.ts [2m([22m[2m34 tests[22m[2m)[22m[32m 214[2mms[22m[39m
|
|
19
39
|
|
|
20
40
|
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
21
|
-
[2m Tests [22m [1m[
|
|
22
|
-
[2m Start at [22m
|
|
23
|
-
[2m Duration [22m
|
|
41
|
+
[2m Tests [22m [1m[32m34 passed[39m[22m[90m (34)[39m
|
|
42
|
+
[2m Start at [22m 20:40:01
|
|
43
|
+
[2m Duration [22m 1.86s[2m (transform 242ms, setup 0ms, import 1.43s, tests 214ms, environment 0ms)[22m
|
|
24
44
|
|
package/dist/blocks-to-html.d.ts
CHANGED
|
@@ -4,15 +4,5 @@
|
|
|
4
4
|
* @description Convert Knapsack Blocks to html
|
|
5
5
|
*/
|
|
6
6
|
import { type BlockConfig } from '@knapsack/types';
|
|
7
|
-
/**
|
|
8
|
-
* Whether an empty render of this block means author content was lost.
|
|
9
|
-
*
|
|
10
|
-
* Many block types render nothing server-side by design (they render in the
|
|
11
|
-
* browser or embed a live source), so `''` from `blocksToHtml` is only a
|
|
12
|
-
* loss signal for TipTap-backed blocks that hold renderable content — the
|
|
13
|
-
* blocks where `tiptapToHtmlSafe` can swallow a render error into `''`.
|
|
14
|
-
* Every render-comparison tool judges empties by this one rule.
|
|
15
|
-
*/
|
|
16
|
-
export declare function mustRenderNonEmpty(block: BlockConfig): boolean;
|
|
17
7
|
export declare function blocksToHtml(blocks: BlockConfig[]): Promise<string>;
|
|
18
8
|
//# sourceMappingURL=blocks-to-html.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks-to-html.d.ts","sourceRoot":"","sources":["../src/blocks-to-html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"blocks-to-html.d.ts","sourceRoot":"","sources":["../src/blocks-to-html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAuKnD,wBAAsB,YAAY,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAMzE"}
|
package/dist/blocks-to-html.js
CHANGED
|
@@ -9,16 +9,7 @@ import domPurify from 'isomorphic-dompurify';
|
|
|
9
9
|
const EOL = os.EOL || '\n';
|
|
10
10
|
async function mdToHtml(md) {
|
|
11
11
|
const { marked } = await import('marked');
|
|
12
|
-
|
|
13
|
-
// hashed for render-parity comparisons. headerIds and mangle default to
|
|
14
|
-
// on in marked 6 and warn on every call. Disabling them DOES change what
|
|
15
|
-
// gets rendered here — headerIds stops emitting auto-generated heading id
|
|
16
|
-
// attributes, and nothing here consumes heading anchors or benefits from
|
|
17
|
-
// mangled mailto text, so that's an acceptable, deliberate change. It's
|
|
18
|
-
// still safe for i7-render-equivalence: gate.ts compares a before/after
|
|
19
|
-
// signature that both go through this same mdToHtml, so both sides drop
|
|
20
|
-
// the ids identically and the signatures move together, not apart.
|
|
21
|
-
return marked.parse(md, { headerIds: false, mangle: false });
|
|
12
|
+
return marked.parse(md);
|
|
22
13
|
}
|
|
23
14
|
// Utility to escape HTML attribute values
|
|
24
15
|
function escapeAttr(val = '') {
|
|
@@ -35,11 +26,6 @@ function escapeAttr(val = '') {
|
|
|
35
26
|
// guard below and degrade to empty content so the rest of the document
|
|
36
27
|
// still renders.
|
|
37
28
|
function tiptapToHtmlSafe(content, blockId, blockType) {
|
|
38
|
-
// Stored content with no root `type` (e.g. `{}` from an author never
|
|
39
|
-
// typing into the block) carries nothing to render — return empty without
|
|
40
|
-
// the error log, which is reserved for real schema drift.
|
|
41
|
-
if (!content?.type)
|
|
42
|
-
return '';
|
|
43
29
|
try {
|
|
44
30
|
return convertTipTapJsonToHtml(content);
|
|
45
31
|
}
|
|
@@ -153,30 +139,6 @@ async function blockToHtml(b) {
|
|
|
153
139
|
}
|
|
154
140
|
}
|
|
155
141
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Whether an empty render of this block means author content was lost.
|
|
158
|
-
*
|
|
159
|
-
* Many block types render nothing server-side by design (they render in the
|
|
160
|
-
* browser or embed a live source), so `''` from `blocksToHtml` is only a
|
|
161
|
-
* loss signal for TipTap-backed blocks that hold renderable content — the
|
|
162
|
-
* blocks where `tiptapToHtmlSafe` can swallow a render error into `''`.
|
|
163
|
-
* Every render-comparison tool judges empties by this one rule.
|
|
164
|
-
*/
|
|
165
|
-
export function mustRenderNonEmpty(block) {
|
|
166
|
-
if (!block.data)
|
|
167
|
-
return false;
|
|
168
|
-
switch (block.blockType) {
|
|
169
|
-
case 'text-editor':
|
|
170
|
-
case 'code-snippet':
|
|
171
|
-
case 'table':
|
|
172
|
-
case 'callout':
|
|
173
|
-
return (block.data.content?.content?.length ?? 0) > 0;
|
|
174
|
-
case 'guidelines':
|
|
175
|
-
return (block.data.guidelines ?? []).some((g) => (g.content?.content?.length ?? 0) > 0 || Boolean(g.image?.src));
|
|
176
|
-
default:
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
142
|
export async function blocksToHtml(blocks) {
|
|
181
143
|
// Sanitize each block's HTML output individually before joining
|
|
182
144
|
const htmls = await Promise.all(blocks.map(async (block) => domPurify.sanitize(await blockToHtml(block))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks-to-html.js","sourceRoot":"","sources":["../src/blocks-to-html.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,uBAAuB,GAExB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAE7C,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC;AAE3B,KAAK,UAAU,QAAQ,CAAC,EAAU;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,C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AAK,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAC1E,CAAC;IACF,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knapsack/rendering-utils",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "4.102.1--canary.
|
|
4
|
+
"version": "4.102.1--canary.7823.8675e86.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -22,23 +22,23 @@
|
|
|
22
22
|
"build": "tsc",
|
|
23
23
|
"clean": "rm -rf ./dist",
|
|
24
24
|
"lint": "eslint ./",
|
|
25
|
-
"test": "
|
|
25
|
+
"test": "vitest run"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@knapsack/tiptap-utils": "4.102.1--canary.
|
|
29
|
-
"@knapsack/utils": "4.102.1--canary.
|
|
28
|
+
"@knapsack/tiptap-utils": "4.102.1--canary.7823.8675e86.0",
|
|
29
|
+
"@knapsack/utils": "4.102.1--canary.7823.8675e86.0",
|
|
30
30
|
"isomorphic-dompurify": "^1.13.0",
|
|
31
31
|
"marked": "^6.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@knapsack/eslint-config-starter": "4.102.1--canary.
|
|
35
|
-
"@knapsack/prettier-config": "4.102.1--canary.
|
|
36
|
-
"@knapsack/types": "4.102.1--canary.
|
|
37
|
-
"@knapsack/typescript-config-starter": "4.102.1--canary.
|
|
34
|
+
"@knapsack/eslint-config-starter": "4.102.1--canary.7823.8675e86.0",
|
|
35
|
+
"@knapsack/prettier-config": "4.102.1--canary.7823.8675e86.0",
|
|
36
|
+
"@knapsack/types": "4.102.1--canary.7823.8675e86.0",
|
|
37
|
+
"@knapsack/typescript-config-starter": "4.102.1--canary.7823.8675e86.0",
|
|
38
38
|
"@types/node": "^24.13.2",
|
|
39
39
|
"eslint": "^9.20.0",
|
|
40
|
-
"typescript": "^
|
|
41
|
-
"vitest": "^4.1.
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"vitest": "^4.1.9"
|
|
42
42
|
},
|
|
43
43
|
"license": "GPL-2.0-or-later",
|
|
44
44
|
"publishConfig": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"directory": "libs/rendering-utils",
|
|
50
50
|
"type": "git"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "8675e860d101d7de6c09e39317ac00ba5e8639a4"
|
|
53
53
|
}
|
package/src/blocks-to-html.ts
CHANGED
|
@@ -16,16 +16,7 @@ const EOL = os.EOL || '\n';
|
|
|
16
16
|
|
|
17
17
|
async function mdToHtml(md: string): Promise<string> {
|
|
18
18
|
const { marked } = await import('marked');
|
|
19
|
-
|
|
20
|
-
// hashed for render-parity comparisons. headerIds and mangle default to
|
|
21
|
-
// on in marked 6 and warn on every call. Disabling them DOES change what
|
|
22
|
-
// gets rendered here — headerIds stops emitting auto-generated heading id
|
|
23
|
-
// attributes, and nothing here consumes heading anchors or benefits from
|
|
24
|
-
// mangled mailto text, so that's an acceptable, deliberate change. It's
|
|
25
|
-
// still safe for i7-render-equivalence: gate.ts compares a before/after
|
|
26
|
-
// signature that both go through this same mdToHtml, so both sides drop
|
|
27
|
-
// the ids identically and the signatures move together, not apart.
|
|
28
|
-
return marked.parse(md, { headerIds: false, mangle: false });
|
|
19
|
+
return marked.parse(md);
|
|
29
20
|
}
|
|
30
21
|
|
|
31
22
|
// Utility to escape HTML attribute values
|
|
@@ -48,10 +39,6 @@ function tiptapToHtmlSafe(
|
|
|
48
39
|
blockId: string,
|
|
49
40
|
blockType: string,
|
|
50
41
|
): string {
|
|
51
|
-
// Stored content with no root `type` (e.g. `{}` from an author never
|
|
52
|
-
// typing into the block) carries nothing to render — return empty without
|
|
53
|
-
// the error log, which is reserved for real schema drift.
|
|
54
|
-
if (!content?.type) return '';
|
|
55
42
|
try {
|
|
56
43
|
return convertTipTapJsonToHtml(content);
|
|
57
44
|
} catch (err) {
|
|
@@ -184,32 +171,6 @@ async function blockToHtml(b: BlockConfig): Promise<string> {
|
|
|
184
171
|
}
|
|
185
172
|
}
|
|
186
173
|
|
|
187
|
-
/**
|
|
188
|
-
* Whether an empty render of this block means author content was lost.
|
|
189
|
-
*
|
|
190
|
-
* Many block types render nothing server-side by design (they render in the
|
|
191
|
-
* browser or embed a live source), so `''` from `blocksToHtml` is only a
|
|
192
|
-
* loss signal for TipTap-backed blocks that hold renderable content — the
|
|
193
|
-
* blocks where `tiptapToHtmlSafe` can swallow a render error into `''`.
|
|
194
|
-
* Every render-comparison tool judges empties by this one rule.
|
|
195
|
-
*/
|
|
196
|
-
export function mustRenderNonEmpty(block: BlockConfig): boolean {
|
|
197
|
-
if (!block.data) return false;
|
|
198
|
-
switch (block.blockType) {
|
|
199
|
-
case 'text-editor':
|
|
200
|
-
case 'code-snippet':
|
|
201
|
-
case 'table':
|
|
202
|
-
case 'callout':
|
|
203
|
-
return (block.data.content?.content?.length ?? 0) > 0;
|
|
204
|
-
case 'guidelines':
|
|
205
|
-
return (block.data.guidelines ?? []).some(
|
|
206
|
-
(g) => (g.content?.content?.length ?? 0) > 0 || Boolean(g.image?.src),
|
|
207
|
-
);
|
|
208
|
-
default:
|
|
209
|
-
return false;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
174
|
export async function blocksToHtml(blocks: BlockConfig[]): Promise<string> {
|
|
214
175
|
// Sanitize each block's HTML output individually before joining
|
|
215
176
|
const htmls = await Promise.all(
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "@knapsack/typescript-config-starter/tsconfig.build.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"rootDir": "./src",
|
|
5
4
|
"noImplicitAny": true,
|
|
6
5
|
"strict": true,
|
|
7
6
|
"outDir": "./dist"
|
|
8
7
|
},
|
|
9
|
-
"include": ["./src"]
|
|
10
|
-
"exclude": [
|
|
11
|
-
"src/**/*.test.ts",
|
|
12
|
-
"src/**/*.test.tsx",
|
|
13
|
-
"src/**/*.spec.ts",
|
|
14
|
-
"src/**/*.spec.tsx"
|
|
15
|
-
]
|
|
8
|
+
"include": ["./src"]
|
|
16
9
|
}
|