@skmtc/core 0.0.922 → 0.0.924
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/esm/context/RenderContext.d.ts +8 -9
- package/esm/context/RenderContext.d.ts.map +1 -1
- package/esm/context/RenderContext.js +76 -15
- package/package.json +2 -2
- package/script/context/RenderContext.d.ts +8 -9
- package/script/context/RenderContext.d.ts.map +1 -1
- package/script/context/RenderContext.js +76 -15
|
@@ -19,7 +19,7 @@ type ConstructorArgs = {
|
|
|
19
19
|
previews: Record<string, Record<string, Preview>>;
|
|
20
20
|
/** Mapping data for file relationships */
|
|
21
21
|
mappings: Record<string, Record<string, Mapping>>;
|
|
22
|
-
/** Optional
|
|
22
|
+
/** Optional formatter configuration (using Prettier format for compatibility) */
|
|
23
23
|
prettierConfig?: PrettierConfigType;
|
|
24
24
|
/** Base path for resolving file paths */
|
|
25
25
|
basePath: string | undefined;
|
|
@@ -35,7 +35,7 @@ type ConstructorArgs = {
|
|
|
35
35
|
*
|
|
36
36
|
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
37
37
|
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
38
|
-
* and file preparation. It handles code formatting via
|
|
38
|
+
* and file preparation. It handles code formatting via Biome, path normalization,
|
|
39
39
|
* and produces the final artifacts ready for writing to the filesystem.
|
|
40
40
|
*
|
|
41
41
|
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
@@ -43,7 +43,7 @@ type ConstructorArgs = {
|
|
|
43
43
|
*
|
|
44
44
|
* ## Key Features
|
|
45
45
|
*
|
|
46
|
-
* - **Code Formatting**: Automatic
|
|
46
|
+
* - **Code Formatting**: Automatic Biome formatting for generated TypeScript/JavaScript code
|
|
47
47
|
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
48
48
|
* - **Content Collation**: Combines all generated content into organized file structures
|
|
49
49
|
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
@@ -79,14 +79,13 @@ type ConstructorArgs = {
|
|
|
79
79
|
* });
|
|
80
80
|
* ```
|
|
81
81
|
*
|
|
82
|
-
* @example With custom
|
|
82
|
+
* @example With custom formatter configuration
|
|
83
83
|
* ```typescript
|
|
84
84
|
* const renderContext = new RenderContext({
|
|
85
85
|
* files: generatedFiles,
|
|
86
86
|
* previews: {},
|
|
87
87
|
* mappings: {},
|
|
88
88
|
* prettierConfig: {
|
|
89
|
-
* parser: 'typescript',
|
|
90
89
|
* printWidth: 120,
|
|
91
90
|
* tabWidth: 2,
|
|
92
91
|
* semi: true,
|
|
@@ -236,7 +235,7 @@ export declare class RenderContext {
|
|
|
236
235
|
* Renders all files in the context to their final formatted form.
|
|
237
236
|
*
|
|
238
237
|
* This is the main rendering method that orchestrates the collation and
|
|
239
|
-
* formatting of all generated files. It processes files through
|
|
238
|
+
* formatting of all generated files. It processes files through Biome
|
|
240
239
|
* formatting (if configured), resolves paths, and produces the final
|
|
241
240
|
* artifacts ready for writing to the filesystem.
|
|
242
241
|
*
|
|
@@ -271,11 +270,11 @@ export declare class RenderContext {
|
|
|
271
270
|
* Collates all files in the context into a unified render result.
|
|
272
271
|
*
|
|
273
272
|
* This method processes each file in the context through the rendering pipeline,
|
|
274
|
-
* applying
|
|
273
|
+
* applying Biome formatting and path resolution. It coordinates the parallel
|
|
275
274
|
* processing of all files and aggregates the results into a single output structure.
|
|
276
275
|
*
|
|
277
276
|
* The collation process includes:
|
|
278
|
-
* - File content rendering with optional
|
|
277
|
+
* - File content rendering with optional Biome formatting
|
|
279
278
|
* - Path resolution using base path configuration
|
|
280
279
|
* - Metadata calculation (line count, character count)
|
|
281
280
|
* - Result aggregation into artifacts and file metadata maps
|
|
@@ -310,7 +309,7 @@ export declare class RenderContext {
|
|
|
310
309
|
* @example
|
|
311
310
|
* ```typescript
|
|
312
311
|
* const result = renderContext.trace('format-file', () => {
|
|
313
|
-
* return
|
|
312
|
+
* return biome.formatContent(projectKey, content, { filePath: 'file.ts' });
|
|
314
313
|
* });
|
|
315
314
|
*
|
|
316
315
|
* // With hierarchical tracing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAGrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,KAAK,GAAG,MAAM,yCAAyC,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,uCAAuC;IACvC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAA;IACnC,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACjD,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACjD,iFAAi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,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAiBtD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAuC3C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAIlD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ;IAU1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS;CAO7D"}
|
|
@@ -10,19 +10,20 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _RenderContext_prettierConfig, _RenderContext_stackTrail;
|
|
13
|
+
import * as dntShim from "../_dnt.shims.js";
|
|
13
14
|
import * as Sentry from '@sentry/node';
|
|
14
15
|
import invariant from 'tiny-invariant';
|
|
15
16
|
import { normalize } from '../deps/jsr.io/@std/path/1.1.2/normalize.js';
|
|
16
17
|
import { toResolvedArtifactPath } from '../helpers/toResolvedArtifactPath.js';
|
|
17
18
|
import { tracer } from '../helpers/tracer.js';
|
|
18
19
|
import { File } from '../dsl/File.js';
|
|
19
|
-
import
|
|
20
|
+
import { Biome, Distribution } from '@biomejs/js-api';
|
|
20
21
|
/**
|
|
21
22
|
* The rendering context for the final phase of the SKMTC transformation pipeline.
|
|
22
23
|
*
|
|
23
24
|
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
24
25
|
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
25
|
-
* and file preparation. It handles code formatting via
|
|
26
|
+
* and file preparation. It handles code formatting via Biome, path normalization,
|
|
26
27
|
* and produces the final artifacts ready for writing to the filesystem.
|
|
27
28
|
*
|
|
28
29
|
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
@@ -30,7 +31,7 @@ import * as prettier from 'prettier';
|
|
|
30
31
|
*
|
|
31
32
|
* ## Key Features
|
|
32
33
|
*
|
|
33
|
-
* - **Code Formatting**: Automatic
|
|
34
|
+
* - **Code Formatting**: Automatic Biome formatting for generated TypeScript/JavaScript code
|
|
34
35
|
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
35
36
|
* - **Content Collation**: Combines all generated content into organized file structures
|
|
36
37
|
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
@@ -66,14 +67,13 @@ import * as prettier from 'prettier';
|
|
|
66
67
|
* });
|
|
67
68
|
* ```
|
|
68
69
|
*
|
|
69
|
-
* @example With custom
|
|
70
|
+
* @example With custom formatter configuration
|
|
70
71
|
* ```typescript
|
|
71
72
|
* const renderContext = new RenderContext({
|
|
72
73
|
* files: generatedFiles,
|
|
73
74
|
* previews: {},
|
|
74
75
|
* mappings: {},
|
|
75
76
|
* prettierConfig: {
|
|
76
|
-
* parser: 'typescript',
|
|
77
77
|
* printWidth: 120,
|
|
78
78
|
* tabWidth: 2,
|
|
79
79
|
* semi: true,
|
|
@@ -227,7 +227,7 @@ export class RenderContext {
|
|
|
227
227
|
writable: true,
|
|
228
228
|
value: void 0
|
|
229
229
|
});
|
|
230
|
-
/** Optional
|
|
230
|
+
/** Optional formatter configuration (using Prettier format for compatibility) */
|
|
231
231
|
_RenderContext_prettierConfig.set(this, void 0);
|
|
232
232
|
/** Base path for resolving file paths */
|
|
233
233
|
Object.defineProperty(this, "basePath", {
|
|
@@ -265,7 +265,7 @@ export class RenderContext {
|
|
|
265
265
|
* Renders all files in the context to their final formatted form.
|
|
266
266
|
*
|
|
267
267
|
* This is the main rendering method that orchestrates the collation and
|
|
268
|
-
* formatting of all generated files. It processes files through
|
|
268
|
+
* formatting of all generated files. It processes files through Biome
|
|
269
269
|
* formatting (if configured), resolves paths, and produces the final
|
|
270
270
|
* artifacts ready for writing to the filesystem.
|
|
271
271
|
*
|
|
@@ -313,11 +313,11 @@ export class RenderContext {
|
|
|
313
313
|
* Collates all files in the context into a unified render result.
|
|
314
314
|
*
|
|
315
315
|
* This method processes each file in the context through the rendering pipeline,
|
|
316
|
-
* applying
|
|
316
|
+
* applying Biome formatting and path resolution. It coordinates the parallel
|
|
317
317
|
* processing of all files and aggregates the results into a single output structure.
|
|
318
318
|
*
|
|
319
319
|
* The collation process includes:
|
|
320
|
-
* - File content rendering with optional
|
|
320
|
+
* - File content rendering with optional Biome formatting
|
|
321
321
|
* - Path resolution using base path configuration
|
|
322
322
|
* - Metadata calculation (line count, character count)
|
|
323
323
|
* - Result aggregation into artifacts and file metadata maps
|
|
@@ -382,7 +382,7 @@ export class RenderContext {
|
|
|
382
382
|
* @example
|
|
383
383
|
* ```typescript
|
|
384
384
|
* const result = renderContext.trace('format-file', () => {
|
|
385
|
-
* return
|
|
385
|
+
* return biome.formatContent(projectKey, content, { filePath: 'file.ts' });
|
|
386
386
|
* });
|
|
387
387
|
*
|
|
388
388
|
* // With hierarchical tracing
|
|
@@ -463,7 +463,7 @@ _RenderContext_prettierConfig = new WeakMap(), _RenderContext_stackTrail = new W
|
|
|
463
463
|
* Renders a single file with formatting and metadata calculation.
|
|
464
464
|
*
|
|
465
465
|
* This function processes a single file through the rendering pipeline,
|
|
466
|
-
* applying
|
|
466
|
+
* applying Biome formatting if configured and calculating file metadata
|
|
467
467
|
* such as line count and character count. It resolves the final path using
|
|
468
468
|
* the base path configuration.
|
|
469
469
|
*
|
|
@@ -496,14 +496,75 @@ const renderFile = async ({ content, destinationPath, basePath, prettierConfig }
|
|
|
496
496
|
characters: formatted.length
|
|
497
497
|
};
|
|
498
498
|
};
|
|
499
|
+
/**
|
|
500
|
+
* Maps Prettier configuration to Biome configuration format.
|
|
501
|
+
* Maintains backward compatibility with existing .prettierrc.json files.
|
|
502
|
+
*/
|
|
503
|
+
const toBiomeConfig = (prettierConfig) => {
|
|
504
|
+
return {
|
|
505
|
+
formatter: {
|
|
506
|
+
enabled: true,
|
|
507
|
+
formatWithErrors: false,
|
|
508
|
+
indentStyle: prettierConfig.useTabs ? 'tab' : 'space',
|
|
509
|
+
indentWidth: prettierConfig.tabWidth ?? 2,
|
|
510
|
+
lineWidth: prettierConfig.printWidth ?? 80,
|
|
511
|
+
lineEnding: prettierConfig.endOfLine === 'crlf' ? 'crlf' : 'lf'
|
|
512
|
+
},
|
|
513
|
+
javascript: {
|
|
514
|
+
formatter: {
|
|
515
|
+
enabled: true,
|
|
516
|
+
quoteStyle: prettierConfig.singleQuote ? 'single' : 'double',
|
|
517
|
+
jsxQuoteStyle: prettierConfig.jsxSingleQuote ? 'single' : 'double',
|
|
518
|
+
quoteProperties: 'asNeeded',
|
|
519
|
+
trailingCommas: prettierConfig.trailingComma === 'all'
|
|
520
|
+
? 'all'
|
|
521
|
+
: prettierConfig.trailingComma === 'es5'
|
|
522
|
+
? 'es5'
|
|
523
|
+
: 'none',
|
|
524
|
+
semicolons: prettierConfig.semi ? 'always' : 'asNeeded',
|
|
525
|
+
arrowParentheses: prettierConfig.arrowParens === 'always' ? 'always' : 'asNeeded',
|
|
526
|
+
bracketSpacing: prettierConfig.bracketSpacing ?? true,
|
|
527
|
+
bracketSameLine: prettierConfig.bracketSameLine ?? false
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
/**
|
|
533
|
+
* Biome instance cache to avoid recreating instances
|
|
534
|
+
*/
|
|
535
|
+
let biomeInstance = null;
|
|
536
|
+
let biomeProjectKey = null;
|
|
537
|
+
const getBiomeInstance = async () => {
|
|
538
|
+
if (!biomeInstance || biomeProjectKey === null) {
|
|
539
|
+
// Initialize Biome with the Node distribution
|
|
540
|
+
biomeInstance = await Biome.create({
|
|
541
|
+
distribution: Distribution.NODE
|
|
542
|
+
});
|
|
543
|
+
const { projectKey } = biomeInstance.openProject(dntShim.Deno.cwd());
|
|
544
|
+
biomeProjectKey = projectKey;
|
|
545
|
+
}
|
|
546
|
+
return { biome: biomeInstance, projectKey: biomeProjectKey };
|
|
547
|
+
};
|
|
499
548
|
const formatFile = async ({ content, prettierConfig }) => {
|
|
500
549
|
try {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
550
|
+
if (!prettierConfig) {
|
|
551
|
+
console.log('NO PRETTIER CONFIG');
|
|
552
|
+
return content;
|
|
553
|
+
}
|
|
554
|
+
const { biome, projectKey } = await getBiomeInstance();
|
|
555
|
+
// Apply configuration from Prettier config
|
|
556
|
+
const biomeConfig = toBiomeConfig(prettierConfig);
|
|
557
|
+
biome.applyConfiguration(projectKey, biomeConfig);
|
|
558
|
+
// Format content - using .ts extension for TypeScript parser
|
|
559
|
+
const result = biome.formatContent(projectKey, content, {
|
|
560
|
+
filePath: 'generated.ts'
|
|
561
|
+
});
|
|
562
|
+
console.log('FORMATTED', result.content);
|
|
563
|
+
return result.content;
|
|
504
564
|
}
|
|
505
565
|
catch (e) {
|
|
506
|
-
console.error(e);
|
|
566
|
+
console.error('Biome formatting error:', e);
|
|
567
|
+
// Fallback to unformatted content on error
|
|
507
568
|
return content;
|
|
508
569
|
}
|
|
509
570
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skmtc/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.924",
|
|
4
4
|
"description": "Skmtc is a declarative code generation framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -219,6 +219,7 @@
|
|
|
219
219
|
"dependencies": {
|
|
220
220
|
"@apiture/openapi-down-convert": "^0.14.0",
|
|
221
221
|
"@babel/helper-validator-identifier": "7.27.1",
|
|
222
|
+
"@biomejs/js-api": "^4.0.0",
|
|
222
223
|
"@sentry/node": "^10.8.0",
|
|
223
224
|
"@types/babel__helper-validator-identifier": "7.15.2",
|
|
224
225
|
"@types/lodash-es": "4.17.12",
|
|
@@ -226,7 +227,6 @@
|
|
|
226
227
|
"gpt-tokenizer": "^3.0.1",
|
|
227
228
|
"lodash-es": "4.17.21",
|
|
228
229
|
"openapi-types": "^12.1.3",
|
|
229
|
-
"prettier": "^3.6.2",
|
|
230
230
|
"swagger2openapi": "^7.0.8",
|
|
231
231
|
"tiny-invariant": "1.3.3",
|
|
232
232
|
"ts-pattern": "^5.8.0",
|
|
@@ -19,7 +19,7 @@ type ConstructorArgs = {
|
|
|
19
19
|
previews: Record<string, Record<string, Preview>>;
|
|
20
20
|
/** Mapping data for file relationships */
|
|
21
21
|
mappings: Record<string, Record<string, Mapping>>;
|
|
22
|
-
/** Optional
|
|
22
|
+
/** Optional formatter configuration (using Prettier format for compatibility) */
|
|
23
23
|
prettierConfig?: PrettierConfigType;
|
|
24
24
|
/** Base path for resolving file paths */
|
|
25
25
|
basePath: string | undefined;
|
|
@@ -35,7 +35,7 @@ type ConstructorArgs = {
|
|
|
35
35
|
*
|
|
36
36
|
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
37
37
|
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
38
|
-
* and file preparation. It handles code formatting via
|
|
38
|
+
* and file preparation. It handles code formatting via Biome, path normalization,
|
|
39
39
|
* and produces the final artifacts ready for writing to the filesystem.
|
|
40
40
|
*
|
|
41
41
|
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
@@ -43,7 +43,7 @@ type ConstructorArgs = {
|
|
|
43
43
|
*
|
|
44
44
|
* ## Key Features
|
|
45
45
|
*
|
|
46
|
-
* - **Code Formatting**: Automatic
|
|
46
|
+
* - **Code Formatting**: Automatic Biome formatting for generated TypeScript/JavaScript code
|
|
47
47
|
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
48
48
|
* - **Content Collation**: Combines all generated content into organized file structures
|
|
49
49
|
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
@@ -79,14 +79,13 @@ type ConstructorArgs = {
|
|
|
79
79
|
* });
|
|
80
80
|
* ```
|
|
81
81
|
*
|
|
82
|
-
* @example With custom
|
|
82
|
+
* @example With custom formatter configuration
|
|
83
83
|
* ```typescript
|
|
84
84
|
* const renderContext = new RenderContext({
|
|
85
85
|
* files: generatedFiles,
|
|
86
86
|
* previews: {},
|
|
87
87
|
* mappings: {},
|
|
88
88
|
* prettierConfig: {
|
|
89
|
-
* parser: 'typescript',
|
|
90
89
|
* printWidth: 120,
|
|
91
90
|
* tabWidth: 2,
|
|
92
91
|
* semi: true,
|
|
@@ -236,7 +235,7 @@ export declare class RenderContext {
|
|
|
236
235
|
* Renders all files in the context to their final formatted form.
|
|
237
236
|
*
|
|
238
237
|
* This is the main rendering method that orchestrates the collation and
|
|
239
|
-
* formatting of all generated files. It processes files through
|
|
238
|
+
* formatting of all generated files. It processes files through Biome
|
|
240
239
|
* formatting (if configured), resolves paths, and produces the final
|
|
241
240
|
* artifacts ready for writing to the filesystem.
|
|
242
241
|
*
|
|
@@ -271,11 +270,11 @@ export declare class RenderContext {
|
|
|
271
270
|
* Collates all files in the context into a unified render result.
|
|
272
271
|
*
|
|
273
272
|
* This method processes each file in the context through the rendering pipeline,
|
|
274
|
-
* applying
|
|
273
|
+
* applying Biome formatting and path resolution. It coordinates the parallel
|
|
275
274
|
* processing of all files and aggregates the results into a single output structure.
|
|
276
275
|
*
|
|
277
276
|
* The collation process includes:
|
|
278
|
-
* - File content rendering with optional
|
|
277
|
+
* - File content rendering with optional Biome formatting
|
|
279
278
|
* - Path resolution using base path configuration
|
|
280
279
|
* - Metadata calculation (line count, character count)
|
|
281
280
|
* - Result aggregation into artifacts and file metadata maps
|
|
@@ -310,7 +309,7 @@ export declare class RenderContext {
|
|
|
310
309
|
* @example
|
|
311
310
|
* ```typescript
|
|
312
311
|
* const result = renderContext.trace('format-file', () => {
|
|
313
|
-
* return
|
|
312
|
+
* return biome.formatContent(projectKey, content, { filePath: 'file.ts' });
|
|
314
313
|
* });
|
|
315
314
|
*
|
|
316
315
|
* // With hierarchical tracing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAGrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,KAAK,GAAG,MAAM,yCAAyC,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,uCAAuC;IACvC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAA;IACnC,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACjD,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC,M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lB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAiBtD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,OAAO,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAuC3C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAIlD;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ;IAU1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS;CAO7D"}
|
|
@@ -49,19 +49,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
49
49
|
var _RenderContext_prettierConfig, _RenderContext_stackTrail;
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
51
|
exports.RenderContext = void 0;
|
|
52
|
+
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
52
53
|
const Sentry = __importStar(require("@sentry/node"));
|
|
53
54
|
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
|
|
54
55
|
const normalize_js_1 = require("../deps/jsr.io/@std/path/1.1.2/normalize.js");
|
|
55
56
|
const toResolvedArtifactPath_js_1 = require("../helpers/toResolvedArtifactPath.js");
|
|
56
57
|
const tracer_js_1 = require("../helpers/tracer.js");
|
|
57
58
|
const File_js_1 = require("../dsl/File.js");
|
|
58
|
-
const
|
|
59
|
+
const js_api_1 = require("@biomejs/js-api");
|
|
59
60
|
/**
|
|
60
61
|
* The rendering context for the final phase of the SKMTC transformation pipeline.
|
|
61
62
|
*
|
|
62
63
|
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
63
64
|
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
64
|
-
* and file preparation. It handles code formatting via
|
|
65
|
+
* and file preparation. It handles code formatting via Biome, path normalization,
|
|
65
66
|
* and produces the final artifacts ready for writing to the filesystem.
|
|
66
67
|
*
|
|
67
68
|
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
@@ -69,7 +70,7 @@ const prettier = __importStar(require("prettier"));
|
|
|
69
70
|
*
|
|
70
71
|
* ## Key Features
|
|
71
72
|
*
|
|
72
|
-
* - **Code Formatting**: Automatic
|
|
73
|
+
* - **Code Formatting**: Automatic Biome formatting for generated TypeScript/JavaScript code
|
|
73
74
|
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
74
75
|
* - **Content Collation**: Combines all generated content into organized file structures
|
|
75
76
|
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
@@ -105,14 +106,13 @@ const prettier = __importStar(require("prettier"));
|
|
|
105
106
|
* });
|
|
106
107
|
* ```
|
|
107
108
|
*
|
|
108
|
-
* @example With custom
|
|
109
|
+
* @example With custom formatter configuration
|
|
109
110
|
* ```typescript
|
|
110
111
|
* const renderContext = new RenderContext({
|
|
111
112
|
* files: generatedFiles,
|
|
112
113
|
* previews: {},
|
|
113
114
|
* mappings: {},
|
|
114
115
|
* prettierConfig: {
|
|
115
|
-
* parser: 'typescript',
|
|
116
116
|
* printWidth: 120,
|
|
117
117
|
* tabWidth: 2,
|
|
118
118
|
* semi: true,
|
|
@@ -266,7 +266,7 @@ class RenderContext {
|
|
|
266
266
|
writable: true,
|
|
267
267
|
value: void 0
|
|
268
268
|
});
|
|
269
|
-
/** Optional
|
|
269
|
+
/** Optional formatter configuration (using Prettier format for compatibility) */
|
|
270
270
|
_RenderContext_prettierConfig.set(this, void 0);
|
|
271
271
|
/** Base path for resolving file paths */
|
|
272
272
|
Object.defineProperty(this, "basePath", {
|
|
@@ -304,7 +304,7 @@ class RenderContext {
|
|
|
304
304
|
* Renders all files in the context to their final formatted form.
|
|
305
305
|
*
|
|
306
306
|
* This is the main rendering method that orchestrates the collation and
|
|
307
|
-
* formatting of all generated files. It processes files through
|
|
307
|
+
* formatting of all generated files. It processes files through Biome
|
|
308
308
|
* formatting (if configured), resolves paths, and produces the final
|
|
309
309
|
* artifacts ready for writing to the filesystem.
|
|
310
310
|
*
|
|
@@ -352,11 +352,11 @@ class RenderContext {
|
|
|
352
352
|
* Collates all files in the context into a unified render result.
|
|
353
353
|
*
|
|
354
354
|
* This method processes each file in the context through the rendering pipeline,
|
|
355
|
-
* applying
|
|
355
|
+
* applying Biome formatting and path resolution. It coordinates the parallel
|
|
356
356
|
* processing of all files and aggregates the results into a single output structure.
|
|
357
357
|
*
|
|
358
358
|
* The collation process includes:
|
|
359
|
-
* - File content rendering with optional
|
|
359
|
+
* - File content rendering with optional Biome formatting
|
|
360
360
|
* - Path resolution using base path configuration
|
|
361
361
|
* - Metadata calculation (line count, character count)
|
|
362
362
|
* - Result aggregation into artifacts and file metadata maps
|
|
@@ -421,7 +421,7 @@ class RenderContext {
|
|
|
421
421
|
* @example
|
|
422
422
|
* ```typescript
|
|
423
423
|
* const result = renderContext.trace('format-file', () => {
|
|
424
|
-
* return
|
|
424
|
+
* return biome.formatContent(projectKey, content, { filePath: 'file.ts' });
|
|
425
425
|
* });
|
|
426
426
|
*
|
|
427
427
|
* // With hierarchical tracing
|
|
@@ -503,7 +503,7 @@ _RenderContext_prettierConfig = new WeakMap(), _RenderContext_stackTrail = new W
|
|
|
503
503
|
* Renders a single file with formatting and metadata calculation.
|
|
504
504
|
*
|
|
505
505
|
* This function processes a single file through the rendering pipeline,
|
|
506
|
-
* applying
|
|
506
|
+
* applying Biome formatting if configured and calculating file metadata
|
|
507
507
|
* such as line count and character count. It resolves the final path using
|
|
508
508
|
* the base path configuration.
|
|
509
509
|
*
|
|
@@ -536,14 +536,75 @@ const renderFile = async ({ content, destinationPath, basePath, prettierConfig }
|
|
|
536
536
|
characters: formatted.length
|
|
537
537
|
};
|
|
538
538
|
};
|
|
539
|
+
/**
|
|
540
|
+
* Maps Prettier configuration to Biome configuration format.
|
|
541
|
+
* Maintains backward compatibility with existing .prettierrc.json files.
|
|
542
|
+
*/
|
|
543
|
+
const toBiomeConfig = (prettierConfig) => {
|
|
544
|
+
return {
|
|
545
|
+
formatter: {
|
|
546
|
+
enabled: true,
|
|
547
|
+
formatWithErrors: false,
|
|
548
|
+
indentStyle: prettierConfig.useTabs ? 'tab' : 'space',
|
|
549
|
+
indentWidth: prettierConfig.tabWidth ?? 2,
|
|
550
|
+
lineWidth: prettierConfig.printWidth ?? 80,
|
|
551
|
+
lineEnding: prettierConfig.endOfLine === 'crlf' ? 'crlf' : 'lf'
|
|
552
|
+
},
|
|
553
|
+
javascript: {
|
|
554
|
+
formatter: {
|
|
555
|
+
enabled: true,
|
|
556
|
+
quoteStyle: prettierConfig.singleQuote ? 'single' : 'double',
|
|
557
|
+
jsxQuoteStyle: prettierConfig.jsxSingleQuote ? 'single' : 'double',
|
|
558
|
+
quoteProperties: 'asNeeded',
|
|
559
|
+
trailingCommas: prettierConfig.trailingComma === 'all'
|
|
560
|
+
? 'all'
|
|
561
|
+
: prettierConfig.trailingComma === 'es5'
|
|
562
|
+
? 'es5'
|
|
563
|
+
: 'none',
|
|
564
|
+
semicolons: prettierConfig.semi ? 'always' : 'asNeeded',
|
|
565
|
+
arrowParentheses: prettierConfig.arrowParens === 'always' ? 'always' : 'asNeeded',
|
|
566
|
+
bracketSpacing: prettierConfig.bracketSpacing ?? true,
|
|
567
|
+
bracketSameLine: prettierConfig.bracketSameLine ?? false
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
/**
|
|
573
|
+
* Biome instance cache to avoid recreating instances
|
|
574
|
+
*/
|
|
575
|
+
let biomeInstance = null;
|
|
576
|
+
let biomeProjectKey = null;
|
|
577
|
+
const getBiomeInstance = async () => {
|
|
578
|
+
if (!biomeInstance || biomeProjectKey === null) {
|
|
579
|
+
// Initialize Biome with the Node distribution
|
|
580
|
+
biomeInstance = await js_api_1.Biome.create({
|
|
581
|
+
distribution: js_api_1.Distribution.NODE
|
|
582
|
+
});
|
|
583
|
+
const { projectKey } = biomeInstance.openProject(dntShim.Deno.cwd());
|
|
584
|
+
biomeProjectKey = projectKey;
|
|
585
|
+
}
|
|
586
|
+
return { biome: biomeInstance, projectKey: biomeProjectKey };
|
|
587
|
+
};
|
|
539
588
|
const formatFile = async ({ content, prettierConfig }) => {
|
|
540
589
|
try {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
590
|
+
if (!prettierConfig) {
|
|
591
|
+
console.log('NO PRETTIER CONFIG');
|
|
592
|
+
return content;
|
|
593
|
+
}
|
|
594
|
+
const { biome, projectKey } = await getBiomeInstance();
|
|
595
|
+
// Apply configuration from Prettier config
|
|
596
|
+
const biomeConfig = toBiomeConfig(prettierConfig);
|
|
597
|
+
biome.applyConfiguration(projectKey, biomeConfig);
|
|
598
|
+
// Format content - using .ts extension for TypeScript parser
|
|
599
|
+
const result = biome.formatContent(projectKey, content, {
|
|
600
|
+
filePath: 'generated.ts'
|
|
601
|
+
});
|
|
602
|
+
console.log('FORMATTED', result.content);
|
|
603
|
+
return result.content;
|
|
544
604
|
}
|
|
545
605
|
catch (e) {
|
|
546
|
-
console.error(e);
|
|
606
|
+
console.error('Biome formatting error:', e);
|
|
607
|
+
// Fallback to unformatted content on error
|
|
547
608
|
return content;
|
|
548
609
|
}
|
|
549
610
|
};
|