@baseplate-dev/core-generators 0.4.4 → 0.5.1
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/dist/constants/core-packages.d.ts +2 -2
- package/dist/constants/core-packages.js +2 -2
- package/dist/constants/core-packages.js.map +1 -1
- package/dist/constants/node.d.ts +1 -1
- package/dist/constants/node.js +1 -1
- package/dist/generators/node/eslint/eslint.generator.d.ts +4 -0
- package/dist/generators/node/eslint/eslint.generator.d.ts.map +1 -1
- package/dist/generators/node/eslint/eslint.generator.js +9 -6
- package/dist/generators/node/eslint/eslint.generator.js.map +1 -1
- package/dist/generators/node/eslint/react-rules.d.ts.map +1 -1
- package/dist/generators/node/eslint/react-rules.js +0 -2
- package/dist/generators/node/eslint/react-rules.js.map +1 -1
- package/dist/generators/node/index.d.ts +1 -0
- package/dist/generators/node/index.d.ts.map +1 -1
- package/dist/generators/node/index.js +1 -0
- package/dist/generators/node/index.js.map +1 -1
- package/dist/generators/node/node-library/index.d.ts +2 -0
- package/dist/generators/node/node-library/index.d.ts.map +1 -0
- package/dist/generators/node/node-library/index.js +2 -0
- package/dist/generators/node/node-library/index.js.map +1 -0
- package/dist/generators/node/node-library/node-library.generator.d.ts +42 -0
- package/dist/generators/node/node-library/node-library.generator.d.ts.map +1 -0
- package/dist/generators/node/node-library/node-library.generator.js +108 -0
- package/dist/generators/node/node-library/node-library.generator.js.map +1 -0
- package/dist/generators/node/pnpm-workspace/pnpm-workspace.generator.d.ts.map +1 -1
- package/dist/generators/node/pnpm-workspace/pnpm-workspace.generator.js +9 -6
- package/dist/generators/node/pnpm-workspace/pnpm-workspace.generator.js.map +1 -1
- package/dist/generators/node/typescript/compiler-types.d.ts +3 -0
- package/dist/generators/node/typescript/compiler-types.d.ts.map +1 -1
- package/dist/generators/node/typescript/typescript.generator.d.ts +1 -0
- package/dist/generators/node/typescript/typescript.generator.d.ts.map +1 -1
- package/dist/generators/node/typescript/typescript.generator.js +4 -2
- package/dist/generators/node/typescript/typescript.generator.js.map +1 -1
- package/dist/generators/node/vitest/vitest.generator.d.ts +4 -1
- package/dist/generators/node/vitest/vitest.generator.d.ts.map +1 -1
- package/dist/generators/node/vitest/vitest.generator.js +10 -6
- package/dist/generators/node/vitest/vitest.generator.js.map +1 -1
- package/dist/renderers/typescript/extractor/build-ts-project-export-map.js +1 -1
- package/dist/renderers/typescript/extractor/build-ts-project-export-map.js.map +1 -1
- package/dist/renderers/typescript/extractor/render-ts-import-providers.js +1 -1
- package/dist/renderers/typescript/extractor/render-ts-import-providers.js.map +1 -1
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.d.ts.map +1 -1
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.js +85 -75
- package/dist/renderers/typescript/extractor/ts-template-file-extractor.js.map +1 -1
- package/dist/renderers/typescript/utils/ts-code-utils.d.ts +1 -1
- package/dist/renderers/typescript/utils/ts-code-utils.d.ts.map +1 -1
- package/dist/renderers/typescript/utils/ts-code-utils.js +4 -2
- package/dist/renderers/typescript/utils/ts-code-utils.js.map +1 -1
- package/dist/test-helpers/index.d.ts +2 -1
- package/dist/test-helpers/index.d.ts.map +1 -1
- package/dist/test-helpers/index.js +2 -0
- package/dist/test-helpers/index.js.map +1 -1
- package/dist/test-helpers/matchers.d.ts +1 -2
- package/dist/test-helpers/matchers.d.ts.map +1 -1
- package/dist/test-helpers/setup.d.ts +2 -2
- package/dist/test-helpers/setup.js +5 -3
- package/dist/test-helpers/setup.js.map +1 -1
- package/dist/test-helpers/snapshot-serializer.d.ts +53 -0
- package/dist/test-helpers/snapshot-serializer.d.ts.map +1 -0
- package/dist/test-helpers/snapshot-serializer.js +125 -0
- package/dist/test-helpers/snapshot-serializer.js.map +1 -0
- package/package.json +5 -13
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest snapshot serializer for TsCodeFragment
|
|
3
|
+
*
|
|
4
|
+
* Produces readable snapshots that look like actual TypeScript code output.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // In test setup file
|
|
9
|
+
* import { extendFragmentSerializer } from '@baseplate-dev/core-generators/test-helpers';
|
|
10
|
+
*
|
|
11
|
+
* extendFragmentSerializer();
|
|
12
|
+
*
|
|
13
|
+
* // In tests
|
|
14
|
+
* expect(fragment).toMatchSnapshot();
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import type { TsCodeFragment } from '../renderers/typescript/index.js';
|
|
20
|
+
/**
|
|
21
|
+
* Vitest snapshot serializer for TsCodeFragment
|
|
22
|
+
*
|
|
23
|
+
* Produces TypeScript-like snapshots showing:
|
|
24
|
+
* - Hoisted fragments (if any) as nested TsCodeFragment blocks
|
|
25
|
+
* - Import statements as actual TypeScript import syntax
|
|
26
|
+
* - Fragment contents as code
|
|
27
|
+
*/
|
|
28
|
+
export declare const tsFragmentSerializer: {
|
|
29
|
+
/**
|
|
30
|
+
* Tests if the value is a TsCodeFragment
|
|
31
|
+
*/
|
|
32
|
+
test(val: unknown): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Serializes a TsCodeFragment to a readable string format
|
|
35
|
+
*/
|
|
36
|
+
serialize(val: TsCodeFragment, config: {
|
|
37
|
+
indent: string;
|
|
38
|
+
}, indentation: string): string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Extends Vitest with the TsCodeFragment snapshot serializer
|
|
42
|
+
* Call this function once in your test setup to enable the serializer
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // In test setup file or at the top of test file
|
|
47
|
+
* import { extendFragmentSerializer } from '@baseplate-dev/core-generators/test-helpers';
|
|
48
|
+
*
|
|
49
|
+
* extendFragmentSerializer();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function extendFragmentSerializer(): void;
|
|
53
|
+
//# sourceMappingURL=snapshot-serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-serializer.d.ts","sourceRoot":"","sources":["../../src/test-helpers/snapshot-serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,kCAAkC,CAAC;AA6F1C;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB;IAC/B;;OAEG;cACO,OAAO,GAAG,OAAO;IAI3B;;OAEG;mBAEI,cAAc,UACX;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,eACb,MAAM,GAClB,MAAM;CAGV,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vitest snapshot serializer for TsCodeFragment
|
|
3
|
+
*
|
|
4
|
+
* Produces readable snapshots that look like actual TypeScript code output.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // In test setup file
|
|
9
|
+
* import { extendFragmentSerializer } from '@baseplate-dev/core-generators/test-helpers';
|
|
10
|
+
*
|
|
11
|
+
* extendFragmentSerializer();
|
|
12
|
+
*
|
|
13
|
+
* // In tests
|
|
14
|
+
* expect(fragment).toMatchSnapshot();
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { expect } from 'vitest';
|
|
20
|
+
import { normalizeFragment } from './utils.js';
|
|
21
|
+
/**
|
|
22
|
+
* Type guard to detect TsCodeFragment objects
|
|
23
|
+
*/
|
|
24
|
+
function isTsCodeFragment(val) {
|
|
25
|
+
return (val !== null &&
|
|
26
|
+
typeof val === 'object' &&
|
|
27
|
+
'contents' in val &&
|
|
28
|
+
typeof val.contents === 'string');
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Formats a single import declaration as a TypeScript import statement
|
|
32
|
+
*/
|
|
33
|
+
function formatImportStatement(imp) {
|
|
34
|
+
const parts = [];
|
|
35
|
+
if (imp.namespaceImport) {
|
|
36
|
+
parts.push(`* as ${imp.namespaceImport}`);
|
|
37
|
+
}
|
|
38
|
+
if (imp.defaultImport) {
|
|
39
|
+
parts.push(imp.defaultImport);
|
|
40
|
+
}
|
|
41
|
+
if (imp.namedImports && imp.namedImports.length > 0) {
|
|
42
|
+
const namedStr = imp.namedImports
|
|
43
|
+
.map((ni) => {
|
|
44
|
+
const name = ni.alias ? `${ni.name} as ${ni.alias}` : ni.name;
|
|
45
|
+
return ni.isTypeOnly ? `type ${name}` : name;
|
|
46
|
+
})
|
|
47
|
+
.join(', ');
|
|
48
|
+
parts.push(`{ ${namedStr} }`);
|
|
49
|
+
}
|
|
50
|
+
const importKeyword = imp.isTypeOnly ? 'import type' : 'import';
|
|
51
|
+
return `${importKeyword} ${parts.join(', ')} from '${imp.moduleSpecifier}';`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Indents all lines in a string
|
|
55
|
+
*/
|
|
56
|
+
function indentLines(text, indent) {
|
|
57
|
+
return text
|
|
58
|
+
.split('\n')
|
|
59
|
+
.map((line) => (line ? `${indent}${line}` : line))
|
|
60
|
+
.join('\n');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Serializes a TsCodeFragment to TypeScript-like output
|
|
64
|
+
*/
|
|
65
|
+
function serializeFragment(fragment, baseIndent, indentUnit) {
|
|
66
|
+
const normalized = normalizeFragment(fragment);
|
|
67
|
+
const lines = [];
|
|
68
|
+
// Hoisted fragments (if present) - each as "Hoisted [key]:"
|
|
69
|
+
if (normalized.hoistedFragments && normalized.hoistedFragments.length > 0) {
|
|
70
|
+
for (const frag of normalized.hoistedFragments) {
|
|
71
|
+
lines.push(`${baseIndent}Hoisted [${frag.key}]:`);
|
|
72
|
+
// Recursively serialize the hoisted fragment
|
|
73
|
+
const nestedOutput = serializeFragment(frag, baseIndent + indentUnit, indentUnit);
|
|
74
|
+
lines.push(nestedOutput, ''); // blank line between hoisted fragments
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Import statements (if present)
|
|
78
|
+
if (normalized.imports && normalized.imports.length > 0) {
|
|
79
|
+
for (const imp of normalized.imports) {
|
|
80
|
+
lines.push(`${baseIndent}${formatImportStatement(imp)}`);
|
|
81
|
+
}
|
|
82
|
+
lines.push(''); // blank line after imports
|
|
83
|
+
}
|
|
84
|
+
// Fragment contents
|
|
85
|
+
lines.push(indentLines(normalized.contents, baseIndent));
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Vitest snapshot serializer for TsCodeFragment
|
|
90
|
+
*
|
|
91
|
+
* Produces TypeScript-like snapshots showing:
|
|
92
|
+
* - Hoisted fragments (if any) as nested TsCodeFragment blocks
|
|
93
|
+
* - Import statements as actual TypeScript import syntax
|
|
94
|
+
* - Fragment contents as code
|
|
95
|
+
*/
|
|
96
|
+
export const tsFragmentSerializer = {
|
|
97
|
+
/**
|
|
98
|
+
* Tests if the value is a TsCodeFragment
|
|
99
|
+
*/
|
|
100
|
+
test(val) {
|
|
101
|
+
return isTsCodeFragment(val);
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* Serializes a TsCodeFragment to a readable string format
|
|
105
|
+
*/
|
|
106
|
+
serialize(val, config, indentation) {
|
|
107
|
+
return serializeFragment(val, indentation, config.indent);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Extends Vitest with the TsCodeFragment snapshot serializer
|
|
112
|
+
* Call this function once in your test setup to enable the serializer
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // In test setup file or at the top of test file
|
|
117
|
+
* import { extendFragmentSerializer } from '@baseplate-dev/core-generators/test-helpers';
|
|
118
|
+
*
|
|
119
|
+
* extendFragmentSerializer();
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function extendFragmentSerializer() {
|
|
123
|
+
expect.addSnapshotSerializer(tsFragmentSerializer);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=snapshot-serializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot-serializer.js","sourceRoot":"","sources":["../../src/test-helpers/snapshot-serializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOhC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AACH,SAAS,gBAAgB,CAAC,GAAY;IACpC,OAAO,CACL,GAAG,KAAK,IAAI;QACZ,OAAO,GAAG,KAAK,QAAQ;QACvB,UAAU,IAAI,GAAG;QACjB,OAAQ,GAAsB,CAAC,QAAQ,KAAK,QAAQ,CACrD,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,qBAAqB,CAAC,GAAwB;IACrD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,GAAG,CAAC,eAAe,EAAE,CAAC;QACxB,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,GAAG,CAAC,aAAa,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,GAAG,CAAC,YAAY;aAC9B,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;YACV,MAAM,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC,KAAK,E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0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Core generators for Baseplate",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -39,14 +39,6 @@
|
|
|
39
39
|
"./test-helpers": {
|
|
40
40
|
"types": "./dist/test-helpers/index.d.ts",
|
|
41
41
|
"default": "./dist/test-helpers/index.js"
|
|
42
|
-
},
|
|
43
|
-
"./test-helpers/setup": {
|
|
44
|
-
"types": "./dist/test-helpers/setup.d.ts",
|
|
45
|
-
"default": "./dist/test-helpers/setup.js"
|
|
46
|
-
},
|
|
47
|
-
"./test-helpers/vitest-types": {
|
|
48
|
-
"types": "./dist/test-helpers/vitest-types.d.ts",
|
|
49
|
-
"default": "./dist/test-helpers/vitest-types.js"
|
|
50
42
|
}
|
|
51
43
|
},
|
|
52
44
|
"main": "dist/index.js",
|
|
@@ -72,8 +64,8 @@
|
|
|
72
64
|
"ts-morph": "26.0.0",
|
|
73
65
|
"yaml": "2.8.1",
|
|
74
66
|
"zod": "^4.1.13",
|
|
75
|
-
"@baseplate-dev/sync": "0.
|
|
76
|
-
"@baseplate-dev/utils": "0.
|
|
67
|
+
"@baseplate-dev/sync": "0.5.1",
|
|
68
|
+
"@baseplate-dev/utils": "0.5.1"
|
|
77
69
|
},
|
|
78
70
|
"devDependencies": {
|
|
79
71
|
"@types/node": "^22.17.2",
|
|
@@ -83,8 +75,8 @@
|
|
|
83
75
|
"cpx2": "8.0.0",
|
|
84
76
|
"eslint": "9.32.0",
|
|
85
77
|
"typescript": "5.8.3",
|
|
86
|
-
"vitest": "
|
|
87
|
-
"@baseplate-dev/tools": "0.
|
|
78
|
+
"vitest": "4.0.16",
|
|
79
|
+
"@baseplate-dev/tools": "0.5.1"
|
|
88
80
|
},
|
|
89
81
|
"engines": {
|
|
90
82
|
"node": "^22.0.0"
|