@skmtc/core 0.0.792 → 0.0.794
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/dsl/GeneratedValueList.d.ts +158 -0
- package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
- package/esm/dsl/GeneratedValueList.js +158 -0
- package/esm/dsl/Stringable.d.ts +76 -0
- package/esm/dsl/Stringable.d.ts.map +1 -1
- package/esm/dsl/Stringable.js +75 -0
- package/esm/helpers/ResultsLog.d.ts +193 -0
- package/esm/helpers/ResultsLog.d.ts.map +1 -1
- package/esm/helpers/ResultsLog.js +213 -0
- package/esm/helpers/collateExamples.d.ts +150 -0
- package/esm/helpers/collateExamples.d.ts.map +1 -1
- package/esm/helpers/collateExamples.js +145 -0
- package/esm/helpers/formatNumber.d.ts +95 -0
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +95 -0
- package/esm/helpers/generationStats.d.ts +287 -1
- package/esm/helpers/generationStats.d.ts.map +1 -1
- package/esm/helpers/generationStats.js +266 -0
- package/esm/helpers/isEmpty.d.ts +62 -0
- package/esm/helpers/isEmpty.d.ts.map +1 -1
- package/esm/helpers/isEmpty.js +62 -0
- package/esm/helpers/isImported.d.ts +80 -0
- package/esm/helpers/isImported.d.ts.map +1 -1
- package/esm/helpers/isImported.js +80 -0
- package/esm/helpers/parseModuleName.d.ts +175 -0
- package/esm/helpers/parseModuleName.d.ts.map +1 -1
- package/esm/helpers/parseModuleName.js +153 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/esm/helpers/toResolvedArtifactPath.js +140 -0
- package/esm/helpers/tracer.d.ts +124 -0
- package/esm/helpers/tracer.d.ts.map +1 -1
- package/esm/helpers/tracer.js +124 -0
- package/esm/oas/schema/Schema.d.ts +117 -0
- package/esm/oas/schema/Schema.d.ts.map +1 -1
- package/esm/typescript/PathParams.d.ts +198 -0
- package/esm/typescript/PathParams.d.ts.map +1 -1
- package/esm/typescript/PathParams.js +190 -0
- package/esm/typescript/ReactRouterPathParams.d.ts +190 -0
- package/esm/typescript/ReactRouterPathParams.d.ts.map +1 -1
- package/esm/typescript/ReactRouterPathParams.js +183 -0
- package/esm/typescript/identifiers.d.ts +159 -0
- package/esm/typescript/identifiers.d.ts.map +1 -1
- package/esm/typescript/identifiers.js +159 -0
- package/esm/typescript/keyValues.d.ts +125 -0
- package/esm/typescript/keyValues.d.ts.map +1 -1
- package/esm/typescript/keyValues.js +125 -1
- package/esm/typescript/toPathParams.d.ts +179 -0
- package/esm/typescript/toPathParams.d.ts.map +1 -1
- package/esm/typescript/toPathParams.js +179 -0
- package/esm/typescript/toPathTemplate.d.ts +114 -0
- package/esm/typescript/toPathTemplate.d.ts.map +1 -1
- package/esm/typescript/toPathTemplate.js +114 -0
- package/esm/typescript/withDescription.d.ts +119 -0
- package/esm/typescript/withDescription.d.ts.map +1 -1
- package/esm/typescript/withDescription.js +119 -0
- package/package.json +1 -1
- package/script/dsl/GeneratedValueList.d.ts +158 -0
- package/script/dsl/GeneratedValueList.d.ts.map +1 -1
- package/script/dsl/GeneratedValueList.js +158 -0
- package/script/dsl/Stringable.d.ts +76 -0
- package/script/dsl/Stringable.d.ts.map +1 -1
- package/script/dsl/Stringable.js +75 -0
- package/script/helpers/ResultsLog.d.ts +193 -0
- package/script/helpers/ResultsLog.d.ts.map +1 -1
- package/script/helpers/ResultsLog.js +213 -0
- package/script/helpers/collateExamples.d.ts +150 -0
- package/script/helpers/collateExamples.d.ts.map +1 -1
- package/script/helpers/collateExamples.js +145 -0
- package/script/helpers/formatNumber.d.ts +95 -0
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +95 -0
- package/script/helpers/generationStats.d.ts +287 -1
- package/script/helpers/generationStats.d.ts.map +1 -1
- package/script/helpers/generationStats.js +266 -0
- package/script/helpers/isEmpty.d.ts +62 -0
- package/script/helpers/isEmpty.d.ts.map +1 -1
- package/script/helpers/isEmpty.js +62 -0
- package/script/helpers/isImported.d.ts +80 -0
- package/script/helpers/isImported.d.ts.map +1 -1
- package/script/helpers/isImported.js +80 -0
- package/script/helpers/parseModuleName.d.ts +175 -0
- package/script/helpers/parseModuleName.d.ts.map +1 -1
- package/script/helpers/parseModuleName.js +153 -0
- package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/script/helpers/toResolvedArtifactPath.js +140 -0
- package/script/helpers/tracer.d.ts +124 -0
- package/script/helpers/tracer.d.ts.map +1 -1
- package/script/helpers/tracer.js +124 -0
- package/script/oas/schema/Schema.d.ts +117 -0
- package/script/oas/schema/Schema.d.ts.map +1 -1
- package/script/typescript/PathParams.d.ts +198 -0
- package/script/typescript/PathParams.d.ts.map +1 -1
- package/script/typescript/PathParams.js +190 -0
- package/script/typescript/ReactRouterPathParams.d.ts +190 -0
- package/script/typescript/ReactRouterPathParams.d.ts.map +1 -1
- package/script/typescript/ReactRouterPathParams.js +183 -0
- package/script/typescript/identifiers.d.ts +159 -0
- package/script/typescript/identifiers.d.ts.map +1 -1
- package/script/typescript/identifiers.js +159 -0
- package/script/typescript/keyValues.d.ts +125 -0
- package/script/typescript/keyValues.d.ts.map +1 -1
- package/script/typescript/keyValues.js +125 -1
- package/script/typescript/toPathParams.d.ts +179 -0
- package/script/typescript/toPathParams.d.ts.map +1 -1
- package/script/typescript/toPathParams.js +179 -0
- package/script/typescript/toPathTemplate.d.ts +114 -0
- package/script/typescript/toPathTemplate.d.ts.map +1 -1
- package/script/typescript/toPathTemplate.js +114 -0
- package/script/typescript/withDescription.d.ts +119 -0
- package/script/typescript/withDescription.d.ts.map +1 -1
- package/script/typescript/withDescription.js +119 -0
|
@@ -1,8 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the parsed components of a module name.
|
|
3
|
+
*
|
|
4
|
+
* This type breaks down a module name into its constituent parts,
|
|
5
|
+
* supporting various formats used in different package managers
|
|
6
|
+
* and registries (npm, JSR, Deno, etc.).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // For 'jsr:@std/path@1.0.0'
|
|
11
|
+
* const parsed: ParsedModuleName = {
|
|
12
|
+
* scheme: 'jsr',
|
|
13
|
+
* scopeName: '@std',
|
|
14
|
+
* packageName: 'path',
|
|
15
|
+
* version: '1.0.0'
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
1
19
|
export type ParsedModuleName = {
|
|
20
|
+
/** The module scheme (e.g., 'npm', 'jsr', 'https') */
|
|
2
21
|
scheme: string | null;
|
|
22
|
+
/** The scope name for scoped packages (e.g., '@std', '@company') */
|
|
3
23
|
scopeName: string | null;
|
|
24
|
+
/** The package name (the main identifier) */
|
|
4
25
|
packageName: string;
|
|
26
|
+
/** The version specifier (e.g., '1.0.0', '^2.3.4') */
|
|
5
27
|
version: string | null;
|
|
6
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Parses a module name string into its component parts.
|
|
31
|
+
*
|
|
32
|
+
* This utility function decomposes module names from various formats into
|
|
33
|
+
* structured components, handling schemes, scopes, versions, and package names.
|
|
34
|
+
* It supports formats used by npm, JSR, Deno, and other package managers.
|
|
35
|
+
*
|
|
36
|
+
* The parser handles complex module name patterns including:
|
|
37
|
+
* - Scheme prefixes (jsr:, npm:, https:)
|
|
38
|
+
* - Scoped packages (@scope/package)
|
|
39
|
+
* - Version specifiers (@version)
|
|
40
|
+
* - Combinations of the above
|
|
41
|
+
*
|
|
42
|
+
* @param moduleName - The module name string to parse
|
|
43
|
+
* @returns Parsed components of the module name
|
|
44
|
+
*
|
|
45
|
+
* @example Basic package names
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { parseModuleName } from '@skmtc/core';
|
|
48
|
+
*
|
|
49
|
+
* // Simple package name
|
|
50
|
+
* const simple = parseModuleName('lodash');
|
|
51
|
+
* // {
|
|
52
|
+
* // scheme: null,
|
|
53
|
+
* // scopeName: null,
|
|
54
|
+
* // packageName: 'lodash',
|
|
55
|
+
* // version: null
|
|
56
|
+
* // }
|
|
57
|
+
*
|
|
58
|
+
* // Package with version
|
|
59
|
+
* const versioned = parseModuleName('lodash@4.17.21');
|
|
60
|
+
* // {
|
|
61
|
+
* // scheme: null,
|
|
62
|
+
* // scopeName: null,
|
|
63
|
+
* // packageName: 'lodash',
|
|
64
|
+
* // version: '4.17.21'
|
|
65
|
+
* // }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example Scoped packages
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Scoped package
|
|
71
|
+
* const scoped = parseModuleName('@company/utils');
|
|
72
|
+
* // {
|
|
73
|
+
* // scheme: null,
|
|
74
|
+
* // scopeName: '@company',
|
|
75
|
+
* // packageName: 'utils',
|
|
76
|
+
* // version: null
|
|
77
|
+
* // }
|
|
78
|
+
*
|
|
79
|
+
* // Scoped package with version
|
|
80
|
+
* const scopedVersioned = parseModuleName('@company/utils@2.0.0');
|
|
81
|
+
* // {
|
|
82
|
+
* // scheme: null,
|
|
83
|
+
* // scopeName: '@company',
|
|
84
|
+
* // packageName: 'utils',
|
|
85
|
+
* // version: '2.0.0'
|
|
86
|
+
* // }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example Scheme-prefixed modules
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // JSR module
|
|
92
|
+
* const jsrModule = parseModuleName('jsr:@std/path@1.0.0');
|
|
93
|
+
* // {
|
|
94
|
+
* // scheme: 'jsr',
|
|
95
|
+
* // scopeName: '@std',
|
|
96
|
+
* // packageName: 'path',
|
|
97
|
+
* // version: '1.0.0'
|
|
98
|
+
* // }
|
|
99
|
+
*
|
|
100
|
+
* // npm module with scheme
|
|
101
|
+
* const npmModule = parseModuleName('npm:lodash@^4.17.0');
|
|
102
|
+
* // {
|
|
103
|
+
* // scheme: 'npm',
|
|
104
|
+
* // scopeName: null,
|
|
105
|
+
* // packageName: 'lodash',
|
|
106
|
+
* // version: '^4.17.0'
|
|
107
|
+
* // }
|
|
108
|
+
*
|
|
109
|
+
* // HTTPS module
|
|
110
|
+
* const httpsModule = parseModuleName('https:example.com/package@v1.2.3');
|
|
111
|
+
* // {
|
|
112
|
+
* // scheme: 'https',
|
|
113
|
+
* // scopeName: null,
|
|
114
|
+
* // packageName: 'example.com/package',
|
|
115
|
+
* // version: 'v1.2.3'
|
|
116
|
+
* // }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Complex parsing scenarios
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Multiple levels in package name
|
|
122
|
+
* const nested = parseModuleName('npm:@babel/plugin-transform-runtime@^7.0.0');
|
|
123
|
+
* // {
|
|
124
|
+
* // scheme: 'npm',
|
|
125
|
+
* // scopeName: '@babel',
|
|
126
|
+
* // packageName: 'plugin-transform-runtime',
|
|
127
|
+
* // version: '^7.0.0'
|
|
128
|
+
* // }
|
|
129
|
+
*
|
|
130
|
+
* // Version ranges and pre-release versions
|
|
131
|
+
* const prerelease = parseModuleName('jsr:@deno/std@1.0.0-rc.1');
|
|
132
|
+
* // {
|
|
133
|
+
* // scheme: 'jsr',
|
|
134
|
+
* // scopeName: '@deno',
|
|
135
|
+
* // packageName: 'std',
|
|
136
|
+
* // version: '1.0.0-rc.1'
|
|
137
|
+
* // }
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example Usage in dependency management
|
|
141
|
+
* ```typescript
|
|
142
|
+
* class DependencyManager {
|
|
143
|
+
* processDependency(moduleSpec: string) {
|
|
144
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
145
|
+
*
|
|
146
|
+
* console.log(`Processing ${parsed.packageName}`);
|
|
147
|
+
*
|
|
148
|
+
* if (parsed.scheme) {
|
|
149
|
+
* console.log(`Using ${parsed.scheme} registry`);
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* if (parsed.scopeName) {
|
|
153
|
+
* console.log(`Scoped package: ${parsed.scopeName}/${parsed.packageName}`);
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* if (parsed.version) {
|
|
157
|
+
* console.log(`Version constraint: ${parsed.version}`);
|
|
158
|
+
* }
|
|
159
|
+
*
|
|
160
|
+
* return this.resolvePackage(parsed);
|
|
161
|
+
* }
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example Building module URLs
|
|
166
|
+
* ```typescript
|
|
167
|
+
* function buildModuleUrl(moduleSpec: string): string {
|
|
168
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
169
|
+
*
|
|
170
|
+
* switch (parsed.scheme) {
|
|
171
|
+
* case 'jsr':
|
|
172
|
+
* return `https://jsr.io/${parsed.scopeName}/${parsed.packageName}`;
|
|
173
|
+
* case 'npm':
|
|
174
|
+
* const scope = parsed.scopeName ? `${parsed.scopeName}/` : '';
|
|
175
|
+
* return `https://npmjs.com/package/${scope}${parsed.packageName}`;
|
|
176
|
+
* default:
|
|
177
|
+
* return `https://deno.land/x/${parsed.packageName}`;
|
|
178
|
+
* }
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
7
182
|
export declare const parseModuleName: (moduleName: string) => ParsedModuleName;
|
|
8
183
|
//# sourceMappingURL=parseModuleName.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseModuleName.d.ts","sourceRoot":"","sources":["../../src/helpers/parseModuleName.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,KAAG,gBAgCpD,CAAA"}
|
|
1
|
+
{"version":3,"file":"parseModuleName.d.ts","sourceRoot":"","sources":["../../src/helpers/parseModuleName.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,sDAAsD;IACtD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,oEAAoE;IACpE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAA;IACnB,sDAAsD;IACtD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwJG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,KAAG,gBAgCpD,CAAA"}
|
|
@@ -1,3 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a module name string into its component parts.
|
|
3
|
+
*
|
|
4
|
+
* This utility function decomposes module names from various formats into
|
|
5
|
+
* structured components, handling schemes, scopes, versions, and package names.
|
|
6
|
+
* It supports formats used by npm, JSR, Deno, and other package managers.
|
|
7
|
+
*
|
|
8
|
+
* The parser handles complex module name patterns including:
|
|
9
|
+
* - Scheme prefixes (jsr:, npm:, https:)
|
|
10
|
+
* - Scoped packages (@scope/package)
|
|
11
|
+
* - Version specifiers (@version)
|
|
12
|
+
* - Combinations of the above
|
|
13
|
+
*
|
|
14
|
+
* @param moduleName - The module name string to parse
|
|
15
|
+
* @returns Parsed components of the module name
|
|
16
|
+
*
|
|
17
|
+
* @example Basic package names
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { parseModuleName } from '@skmtc/core';
|
|
20
|
+
*
|
|
21
|
+
* // Simple package name
|
|
22
|
+
* const simple = parseModuleName('lodash');
|
|
23
|
+
* // {
|
|
24
|
+
* // scheme: null,
|
|
25
|
+
* // scopeName: null,
|
|
26
|
+
* // packageName: 'lodash',
|
|
27
|
+
* // version: null
|
|
28
|
+
* // }
|
|
29
|
+
*
|
|
30
|
+
* // Package with version
|
|
31
|
+
* const versioned = parseModuleName('lodash@4.17.21');
|
|
32
|
+
* // {
|
|
33
|
+
* // scheme: null,
|
|
34
|
+
* // scopeName: null,
|
|
35
|
+
* // packageName: 'lodash',
|
|
36
|
+
* // version: '4.17.21'
|
|
37
|
+
* // }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Scoped packages
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // Scoped package
|
|
43
|
+
* const scoped = parseModuleName('@company/utils');
|
|
44
|
+
* // {
|
|
45
|
+
* // scheme: null,
|
|
46
|
+
* // scopeName: '@company',
|
|
47
|
+
* // packageName: 'utils',
|
|
48
|
+
* // version: null
|
|
49
|
+
* // }
|
|
50
|
+
*
|
|
51
|
+
* // Scoped package with version
|
|
52
|
+
* const scopedVersioned = parseModuleName('@company/utils@2.0.0');
|
|
53
|
+
* // {
|
|
54
|
+
* // scheme: null,
|
|
55
|
+
* // scopeName: '@company',
|
|
56
|
+
* // packageName: 'utils',
|
|
57
|
+
* // version: '2.0.0'
|
|
58
|
+
* // }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Scheme-prefixed modules
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // JSR module
|
|
64
|
+
* const jsrModule = parseModuleName('jsr:@std/path@1.0.0');
|
|
65
|
+
* // {
|
|
66
|
+
* // scheme: 'jsr',
|
|
67
|
+
* // scopeName: '@std',
|
|
68
|
+
* // packageName: 'path',
|
|
69
|
+
* // version: '1.0.0'
|
|
70
|
+
* // }
|
|
71
|
+
*
|
|
72
|
+
* // npm module with scheme
|
|
73
|
+
* const npmModule = parseModuleName('npm:lodash@^4.17.0');
|
|
74
|
+
* // {
|
|
75
|
+
* // scheme: 'npm',
|
|
76
|
+
* // scopeName: null,
|
|
77
|
+
* // packageName: 'lodash',
|
|
78
|
+
* // version: '^4.17.0'
|
|
79
|
+
* // }
|
|
80
|
+
*
|
|
81
|
+
* // HTTPS module
|
|
82
|
+
* const httpsModule = parseModuleName('https:example.com/package@v1.2.3');
|
|
83
|
+
* // {
|
|
84
|
+
* // scheme: 'https',
|
|
85
|
+
* // scopeName: null,
|
|
86
|
+
* // packageName: 'example.com/package',
|
|
87
|
+
* // version: 'v1.2.3'
|
|
88
|
+
* // }
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Complex parsing scenarios
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Multiple levels in package name
|
|
94
|
+
* const nested = parseModuleName('npm:@babel/plugin-transform-runtime@^7.0.0');
|
|
95
|
+
* // {
|
|
96
|
+
* // scheme: 'npm',
|
|
97
|
+
* // scopeName: '@babel',
|
|
98
|
+
* // packageName: 'plugin-transform-runtime',
|
|
99
|
+
* // version: '^7.0.0'
|
|
100
|
+
* // }
|
|
101
|
+
*
|
|
102
|
+
* // Version ranges and pre-release versions
|
|
103
|
+
* const prerelease = parseModuleName('jsr:@deno/std@1.0.0-rc.1');
|
|
104
|
+
* // {
|
|
105
|
+
* // scheme: 'jsr',
|
|
106
|
+
* // scopeName: '@deno',
|
|
107
|
+
* // packageName: 'std',
|
|
108
|
+
* // version: '1.0.0-rc.1'
|
|
109
|
+
* // }
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Usage in dependency management
|
|
113
|
+
* ```typescript
|
|
114
|
+
* class DependencyManager {
|
|
115
|
+
* processDependency(moduleSpec: string) {
|
|
116
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
117
|
+
*
|
|
118
|
+
* console.log(`Processing ${parsed.packageName}`);
|
|
119
|
+
*
|
|
120
|
+
* if (parsed.scheme) {
|
|
121
|
+
* console.log(`Using ${parsed.scheme} registry`);
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* if (parsed.scopeName) {
|
|
125
|
+
* console.log(`Scoped package: ${parsed.scopeName}/${parsed.packageName}`);
|
|
126
|
+
* }
|
|
127
|
+
*
|
|
128
|
+
* if (parsed.version) {
|
|
129
|
+
* console.log(`Version constraint: ${parsed.version}`);
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* return this.resolvePackage(parsed);
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example Building module URLs
|
|
138
|
+
* ```typescript
|
|
139
|
+
* function buildModuleUrl(moduleSpec: string): string {
|
|
140
|
+
* const parsed = parseModuleName(moduleSpec);
|
|
141
|
+
*
|
|
142
|
+
* switch (parsed.scheme) {
|
|
143
|
+
* case 'jsr':
|
|
144
|
+
* return `https://jsr.io/${parsed.scopeName}/${parsed.packageName}`;
|
|
145
|
+
* case 'npm':
|
|
146
|
+
* const scope = parsed.scopeName ? `${parsed.scopeName}/` : '';
|
|
147
|
+
* return `https://npmjs.com/package/${scope}${parsed.packageName}`;
|
|
148
|
+
* default:
|
|
149
|
+
* return `https://deno.land/x/${parsed.packageName}`;
|
|
150
|
+
* }
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
1
154
|
export const parseModuleName = (moduleName) => {
|
|
2
155
|
const result = {
|
|
3
156
|
scheme: null,
|
|
@@ -1,8 +1,153 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
|
+
/**
|
|
3
|
+
* Arguments for resolving artifact file paths.
|
|
4
|
+
*/
|
|
2
5
|
type ToResolvedArtifactPathArgs = {
|
|
6
|
+
/** The base directory path for resolving relative paths */
|
|
3
7
|
basePath: string | undefined;
|
|
8
|
+
/** The destination path for the artifact file */
|
|
4
9
|
destinationPath: string;
|
|
5
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Resolves artifact destination paths relative to a base directory.
|
|
13
|
+
*
|
|
14
|
+
* This utility function combines a base path with a destination path to create
|
|
15
|
+
* the final resolved file path for generated artifacts. It handles special path
|
|
16
|
+
* prefixes (like '@/') and provides sensible defaults when no base path is specified.
|
|
17
|
+
*
|
|
18
|
+
* The function is used throughout the rendering pipeline to determine the final
|
|
19
|
+
* file system locations for generated code artifacts, ensuring consistent path
|
|
20
|
+
* resolution across different operating systems and deployment scenarios.
|
|
21
|
+
*
|
|
22
|
+
* @param args - Path resolution configuration
|
|
23
|
+
* @param args.basePath - Base directory path (defaults to './' if undefined)
|
|
24
|
+
* @param args.destinationPath - Destination path for the artifact
|
|
25
|
+
* @returns The resolved absolute or relative path for the artifact
|
|
26
|
+
*
|
|
27
|
+
* @example Basic path resolution
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { toResolvedArtifactPath } from '@skmtc/core';
|
|
30
|
+
*
|
|
31
|
+
* // With explicit base path
|
|
32
|
+
* const resolved1 = toResolvedArtifactPath({
|
|
33
|
+
* basePath: './src/generated',
|
|
34
|
+
* destinationPath: 'models/User.ts'
|
|
35
|
+
* });
|
|
36
|
+
* console.log(resolved1); // './src/generated/models/User.ts'
|
|
37
|
+
*
|
|
38
|
+
* // With undefined base path (uses default)
|
|
39
|
+
* const resolved2 = toResolvedArtifactPath({
|
|
40
|
+
* basePath: undefined,
|
|
41
|
+
* destinationPath: 'types.ts'
|
|
42
|
+
* });
|
|
43
|
+
* console.log(resolved2); // './types.ts'
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Special path prefix handling
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // '@/' prefix gets stripped and resolved relative to base
|
|
49
|
+
* const resolved = toResolvedArtifactPath({
|
|
50
|
+
* basePath: './output',
|
|
51
|
+
* destinationPath: '@/api/models.ts'
|
|
52
|
+
* });
|
|
53
|
+
* console.log(resolved); // './output/api/models.ts'
|
|
54
|
+
*
|
|
55
|
+
* // Regular paths work normally
|
|
56
|
+
* const normal = toResolvedArtifactPath({
|
|
57
|
+
* basePath: './build',
|
|
58
|
+
* destinationPath: 'components/Button.tsx'
|
|
59
|
+
* });
|
|
60
|
+
* console.log(normal); // './build/components/Button.tsx'
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example Cross-platform path resolution
|
|
64
|
+
* ```typescript
|
|
65
|
+
* // Works consistently across platforms
|
|
66
|
+
* const windowsPath = toResolvedArtifactPath({
|
|
67
|
+
* basePath: 'C:\\projects\\app\\dist',
|
|
68
|
+
* destinationPath: 'utils/helpers.js'
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* const unixPath = toResolvedArtifactPath({
|
|
72
|
+
* basePath: '/home/user/projects/app/dist',
|
|
73
|
+
* destinationPath: 'utils/helpers.js'
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example Usage in file generation
|
|
78
|
+
* ```typescript
|
|
79
|
+
* class ArtifactWriter {
|
|
80
|
+
* writeArtifact(
|
|
81
|
+
* content: string,
|
|
82
|
+
* destination: string,
|
|
83
|
+
* baseDir?: string
|
|
84
|
+
* ) {
|
|
85
|
+
* const resolvedPath = toResolvedArtifactPath({
|
|
86
|
+
* basePath: baseDir,
|
|
87
|
+
* destinationPath: destination
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* console.log(`Writing to: ${resolvedPath}`);
|
|
91
|
+
* return Deno.writeTextFile(resolvedPath, content);
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* const writer = new ArtifactWriter();
|
|
96
|
+
* await writer.writeArtifact(
|
|
97
|
+
* 'export const greeting = "Hello";',
|
|
98
|
+
* '@/constants.ts',
|
|
99
|
+
* './src/generated'
|
|
100
|
+
* );
|
|
101
|
+
* // Writes to: ./src/generated/constants.ts
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example Integration with rendering pipeline
|
|
105
|
+
* ```typescript
|
|
106
|
+
* class FileRenderer {
|
|
107
|
+
* renderFiles(
|
|
108
|
+
* files: Map<string, File>,
|
|
109
|
+
* outputDir: string
|
|
110
|
+
* ): Record<string, string> {
|
|
111
|
+
* const artifacts: Record<string, string> = {};
|
|
112
|
+
*
|
|
113
|
+
* for (const [destPath, file] of files) {
|
|
114
|
+
* const resolvedPath = toResolvedArtifactPath({
|
|
115
|
+
* basePath: outputDir,
|
|
116
|
+
* destinationPath: destPath
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* artifacts[resolvedPath] = file.toString();
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* return artifacts;
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @example Dynamic base path resolution
|
|
128
|
+
* ```typescript
|
|
129
|
+
* function resolveForEnvironment(
|
|
130
|
+
* destination: string,
|
|
131
|
+
* env: 'development' | 'production'
|
|
132
|
+
* ): string {
|
|
133
|
+
* const basePaths = {
|
|
134
|
+
* development: './dev-output',
|
|
135
|
+
* production: './dist'
|
|
136
|
+
* };
|
|
137
|
+
*
|
|
138
|
+
* return toResolvedArtifactPath({
|
|
139
|
+
* basePath: basePaths[env],
|
|
140
|
+
* destinationPath: destination
|
|
141
|
+
* });
|
|
142
|
+
* }
|
|
143
|
+
*
|
|
144
|
+
* const devPath = resolveForEnvironment('api.ts', 'development');
|
|
145
|
+
* const prodPath = resolveForEnvironment('api.ts', 'production');
|
|
146
|
+
*
|
|
147
|
+
* console.log(devPath); // './dev-output/api.ts'
|
|
148
|
+
* console.log(prodPath); // './dist/api.ts'
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
6
151
|
export declare const toResolvedArtifactPath: ({ basePath, destinationPath }: ToResolvedArtifactPathArgs) => string;
|
|
7
152
|
export {};
|
|
8
153
|
//# sourceMappingURL=toResolvedArtifactPath.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toResolvedArtifactPath.d.ts","sourceRoot":"","sources":["../../src/helpers/toResolvedArtifactPath.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"toResolvedArtifactPath.d.ts","sourceRoot":"","sources":["../../src/helpers/toResolvedArtifactPath.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAG9B;;GAEG;AACH,KAAK,0BAA0B,GAAG;IAChC,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,iDAAiD;IACjD,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2IG;AACH,eAAO,MAAM,sBAAsB,GAAI,+BAGpC,0BAA0B,KAAG,MAE/B,CAAA"}
|
|
@@ -1,5 +1,145 @@
|
|
|
1
1
|
import "../_dnt.polyfills.js";
|
|
2
2
|
import { join } from '../deps/jsr.io/@std/path/1.1.2/join.js';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves artifact destination paths relative to a base directory.
|
|
5
|
+
*
|
|
6
|
+
* This utility function combines a base path with a destination path to create
|
|
7
|
+
* the final resolved file path for generated artifacts. It handles special path
|
|
8
|
+
* prefixes (like '@/') and provides sensible defaults when no base path is specified.
|
|
9
|
+
*
|
|
10
|
+
* The function is used throughout the rendering pipeline to determine the final
|
|
11
|
+
* file system locations for generated code artifacts, ensuring consistent path
|
|
12
|
+
* resolution across different operating systems and deployment scenarios.
|
|
13
|
+
*
|
|
14
|
+
* @param args - Path resolution configuration
|
|
15
|
+
* @param args.basePath - Base directory path (defaults to './' if undefined)
|
|
16
|
+
* @param args.destinationPath - Destination path for the artifact
|
|
17
|
+
* @returns The resolved absolute or relative path for the artifact
|
|
18
|
+
*
|
|
19
|
+
* @example Basic path resolution
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { toResolvedArtifactPath } from '@skmtc/core';
|
|
22
|
+
*
|
|
23
|
+
* // With explicit base path
|
|
24
|
+
* const resolved1 = toResolvedArtifactPath({
|
|
25
|
+
* basePath: './src/generated',
|
|
26
|
+
* destinationPath: 'models/User.ts'
|
|
27
|
+
* });
|
|
28
|
+
* console.log(resolved1); // './src/generated/models/User.ts'
|
|
29
|
+
*
|
|
30
|
+
* // With undefined base path (uses default)
|
|
31
|
+
* const resolved2 = toResolvedArtifactPath({
|
|
32
|
+
* basePath: undefined,
|
|
33
|
+
* destinationPath: 'types.ts'
|
|
34
|
+
* });
|
|
35
|
+
* console.log(resolved2); // './types.ts'
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Special path prefix handling
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // '@/' prefix gets stripped and resolved relative to base
|
|
41
|
+
* const resolved = toResolvedArtifactPath({
|
|
42
|
+
* basePath: './output',
|
|
43
|
+
* destinationPath: '@/api/models.ts'
|
|
44
|
+
* });
|
|
45
|
+
* console.log(resolved); // './output/api/models.ts'
|
|
46
|
+
*
|
|
47
|
+
* // Regular paths work normally
|
|
48
|
+
* const normal = toResolvedArtifactPath({
|
|
49
|
+
* basePath: './build',
|
|
50
|
+
* destinationPath: 'components/Button.tsx'
|
|
51
|
+
* });
|
|
52
|
+
* console.log(normal); // './build/components/Button.tsx'
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example Cross-platform path resolution
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Works consistently across platforms
|
|
58
|
+
* const windowsPath = toResolvedArtifactPath({
|
|
59
|
+
* basePath: 'C:\\projects\\app\\dist',
|
|
60
|
+
* destinationPath: 'utils/helpers.js'
|
|
61
|
+
* });
|
|
62
|
+
*
|
|
63
|
+
* const unixPath = toResolvedArtifactPath({
|
|
64
|
+
* basePath: '/home/user/projects/app/dist',
|
|
65
|
+
* destinationPath: 'utils/helpers.js'
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Usage in file generation
|
|
70
|
+
* ```typescript
|
|
71
|
+
* class ArtifactWriter {
|
|
72
|
+
* writeArtifact(
|
|
73
|
+
* content: string,
|
|
74
|
+
* destination: string,
|
|
75
|
+
* baseDir?: string
|
|
76
|
+
* ) {
|
|
77
|
+
* const resolvedPath = toResolvedArtifactPath({
|
|
78
|
+
* basePath: baseDir,
|
|
79
|
+
* destinationPath: destination
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* console.log(`Writing to: ${resolvedPath}`);
|
|
83
|
+
* return Deno.writeTextFile(resolvedPath, content);
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* const writer = new ArtifactWriter();
|
|
88
|
+
* await writer.writeArtifact(
|
|
89
|
+
* 'export const greeting = "Hello";',
|
|
90
|
+
* '@/constants.ts',
|
|
91
|
+
* './src/generated'
|
|
92
|
+
* );
|
|
93
|
+
* // Writes to: ./src/generated/constants.ts
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example Integration with rendering pipeline
|
|
97
|
+
* ```typescript
|
|
98
|
+
* class FileRenderer {
|
|
99
|
+
* renderFiles(
|
|
100
|
+
* files: Map<string, File>,
|
|
101
|
+
* outputDir: string
|
|
102
|
+
* ): Record<string, string> {
|
|
103
|
+
* const artifacts: Record<string, string> = {};
|
|
104
|
+
*
|
|
105
|
+
* for (const [destPath, file] of files) {
|
|
106
|
+
* const resolvedPath = toResolvedArtifactPath({
|
|
107
|
+
* basePath: outputDir,
|
|
108
|
+
* destinationPath: destPath
|
|
109
|
+
* });
|
|
110
|
+
*
|
|
111
|
+
* artifacts[resolvedPath] = file.toString();
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* return artifacts;
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Dynamic base path resolution
|
|
120
|
+
* ```typescript
|
|
121
|
+
* function resolveForEnvironment(
|
|
122
|
+
* destination: string,
|
|
123
|
+
* env: 'development' | 'production'
|
|
124
|
+
* ): string {
|
|
125
|
+
* const basePaths = {
|
|
126
|
+
* development: './dev-output',
|
|
127
|
+
* production: './dist'
|
|
128
|
+
* };
|
|
129
|
+
*
|
|
130
|
+
* return toResolvedArtifactPath({
|
|
131
|
+
* basePath: basePaths[env],
|
|
132
|
+
* destinationPath: destination
|
|
133
|
+
* });
|
|
134
|
+
* }
|
|
135
|
+
*
|
|
136
|
+
* const devPath = resolveForEnvironment('api.ts', 'development');
|
|
137
|
+
* const prodPath = resolveForEnvironment('api.ts', 'production');
|
|
138
|
+
*
|
|
139
|
+
* console.log(devPath); // './dev-output/api.ts'
|
|
140
|
+
* console.log(prodPath); // './dist/api.ts'
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
3
143
|
export const toResolvedArtifactPath = ({ basePath, destinationPath }) => {
|
|
4
144
|
return join(basePath ?? './', destinationPath.replace(/^@\//, ''));
|
|
5
145
|
};
|