@ryanatkn/gro 0.156.0 → 0.157.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.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -0
- package/dist/esbuild_plugin_svelte.d.ts.map +1 -1
- package/dist/esbuild_plugin_svelte.js +1 -2
- package/dist/gro_plugin_sveltekit_app.js +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +1 -2
- package/dist/package.d.ts +44 -13
- package/dist/package.d.ts.map +1 -1
- package/dist/package.gen.js +1 -1
- package/dist/package.js +44 -22
- package/dist/parse_exports.d.ts +20 -0
- package/dist/parse_exports.d.ts.map +1 -0
- package/dist/parse_exports.js +65 -0
- package/dist/parse_exports_context.d.ts +21 -0
- package/dist/parse_exports_context.d.ts.map +1 -0
- package/dist/parse_exports_context.js +332 -0
- package/dist/parse_imports.d.ts.map +1 -1
- package/dist/parse_imports.js +1 -2
- package/dist/paths.d.ts +8 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +6 -3
- package/dist/src_json.d.ts +68 -66
- package/dist/src_json.d.ts.map +1 -1
- package/dist/src_json.js +58 -55
- package/dist/test_helpers.d.ts +21 -0
- package/dist/test_helpers.d.ts.map +1 -0
- package/dist/test_helpers.js +122 -0
- package/package.json +21 -13
- package/src/lib/constants.ts +6 -0
- package/src/lib/esbuild_plugin_svelte.ts +1 -2
- package/src/lib/gro_plugin_sveltekit_app.ts +1 -1
- package/src/lib/loader.ts +6 -2
- package/src/lib/package.gen.ts +1 -1
- package/src/lib/package.ts +44 -22
- package/src/lib/parse_exports.ts +108 -0
- package/src/lib/parse_exports_context.ts +394 -0
- package/src/lib/parse_imports.ts +1 -2
- package/src/lib/paths.ts +13 -3
- package/src/lib/src_json.ts +80 -68
- package/src/lib/test_helpers.ts +159 -0
- package/dist/svelte_helpers.d.ts +0 -3
- package/dist/svelte_helpers.d.ts.map +0 -1
- package/dist/svelte_helpers.js +0 -2
- package/src/lib/svelte_helpers.ts +0 -2
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
/**
|
|
3
|
+
* A class to track export context and determine export kinds.
|
|
4
|
+
*/
|
|
5
|
+
export class Parse_Exports_Context {
|
|
6
|
+
#checker;
|
|
7
|
+
// Map of source file paths to their symbols
|
|
8
|
+
#file_symbols = new Map();
|
|
9
|
+
// Cache for resolved symbols to avoid repeated resolution
|
|
10
|
+
#symbol_kind_cache = new Map();
|
|
11
|
+
log;
|
|
12
|
+
debug = process.env.DEBUG_EXPORTS === 'true';
|
|
13
|
+
constructor(program, log) {
|
|
14
|
+
this.log = log;
|
|
15
|
+
this.#checker = program.getTypeChecker();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Log a debug message if debug mode is enabled.
|
|
19
|
+
*/
|
|
20
|
+
#log(...args) {
|
|
21
|
+
if (this.debug && this.log) {
|
|
22
|
+
this.log.info(...args);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Analyze a source file to prepare for export processing.
|
|
27
|
+
*/
|
|
28
|
+
analyze_source_file(source_file) {
|
|
29
|
+
const file_path = source_file.fileName;
|
|
30
|
+
// Skip if we've already analyzed this file
|
|
31
|
+
if (this.#file_symbols.has(file_path)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Get the source file symbol and cache it
|
|
35
|
+
const symbol = this.#checker.getSymbolAtLocation(source_file);
|
|
36
|
+
if (symbol) {
|
|
37
|
+
this.#file_symbols.set(file_path, symbol);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Process a list of exported symbols and identify their kinds.
|
|
42
|
+
*/
|
|
43
|
+
process_exports(source_file, exports, declarations = []) {
|
|
44
|
+
for (const export_symbol of exports) {
|
|
45
|
+
const name = export_symbol.name;
|
|
46
|
+
this.#log(`Determining kind for export: ${name}`);
|
|
47
|
+
const kind = this.#determine_export_kind(source_file, export_symbol);
|
|
48
|
+
declarations.push({
|
|
49
|
+
name,
|
|
50
|
+
kind,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return declarations;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Determine the kind of an export based on its symbol.
|
|
57
|
+
*/
|
|
58
|
+
#determine_export_kind(source_file, symbol) {
|
|
59
|
+
// Check if this is a type-only export (no value export)
|
|
60
|
+
if (this.#is_type_only_export(source_file, symbol)) {
|
|
61
|
+
return 'type';
|
|
62
|
+
}
|
|
63
|
+
// Get the true symbol by resolving aliases
|
|
64
|
+
const resolved_symbol = this.#resolve_symbol(symbol);
|
|
65
|
+
// Check if we've already determined this symbol's kind
|
|
66
|
+
if (this.#symbol_kind_cache.has(resolved_symbol)) {
|
|
67
|
+
return this.#symbol_kind_cache.get(resolved_symbol);
|
|
68
|
+
}
|
|
69
|
+
// Determine the kind based on declaration and type information
|
|
70
|
+
const kind = this.#infer_declaration_kind(resolved_symbol);
|
|
71
|
+
// Cache the result for future lookups
|
|
72
|
+
this.#symbol_kind_cache.set(resolved_symbol, kind);
|
|
73
|
+
return kind;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve a symbol through aliases to its original declaration.
|
|
77
|
+
*/
|
|
78
|
+
#resolve_symbol(symbol) {
|
|
79
|
+
try {
|
|
80
|
+
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
81
|
+
return this.#checker.getAliasedSymbol(symbol);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// If resolution fails, return the original symbol
|
|
86
|
+
}
|
|
87
|
+
return symbol;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Infer the declaration kind from a symbol's declaration and type information.
|
|
91
|
+
*/
|
|
92
|
+
#infer_declaration_kind(symbol) {
|
|
93
|
+
// Check symbol flags first for direct type matching
|
|
94
|
+
if (this.#is_class_symbol(symbol)) {
|
|
95
|
+
return 'class';
|
|
96
|
+
}
|
|
97
|
+
if (this.#is_function_symbol(symbol)) {
|
|
98
|
+
return 'function';
|
|
99
|
+
}
|
|
100
|
+
// If no direct match from flags, look at declarations
|
|
101
|
+
if (symbol.declarations && symbol.declarations.length > 0) {
|
|
102
|
+
const decl = symbol.declarations[0];
|
|
103
|
+
const kind_from_decl = this.#infer_kind_from_declaration(decl);
|
|
104
|
+
if (kind_from_decl) {
|
|
105
|
+
return kind_from_decl;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Check for callable type as a fallback for functions
|
|
109
|
+
if (this.#is_callable(symbol)) {
|
|
110
|
+
return 'function';
|
|
111
|
+
}
|
|
112
|
+
// Default to variable if no other type can be determined
|
|
113
|
+
return 'variable';
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if a symbol represents a callable type (function-like).
|
|
117
|
+
*/
|
|
118
|
+
#is_callable(symbol) {
|
|
119
|
+
try {
|
|
120
|
+
// Try to get valid declaration node
|
|
121
|
+
const declaration = this.#get_valid_declaration(symbol);
|
|
122
|
+
if (!declaration) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
// Get the type at the declaration location
|
|
126
|
+
const type = this.#checker.getTypeOfSymbolAtLocation(symbol, declaration);
|
|
127
|
+
// Check if the type has call signatures (making it function-like)
|
|
128
|
+
return type.getCallSignatures().length > 0;
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get a valid declaration for a symbol, preferring valueDeclaration.
|
|
136
|
+
*/
|
|
137
|
+
#get_valid_declaration(symbol) {
|
|
138
|
+
if (symbol.valueDeclaration) {
|
|
139
|
+
return symbol.valueDeclaration;
|
|
140
|
+
}
|
|
141
|
+
if (symbol.declarations && symbol.declarations.length > 0) {
|
|
142
|
+
return symbol.declarations[0];
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Infer the declaration kind from a specific declaration node.
|
|
148
|
+
*/
|
|
149
|
+
#infer_kind_from_declaration(decl) {
|
|
150
|
+
if (ts.isFunctionDeclaration(decl)) {
|
|
151
|
+
return 'function';
|
|
152
|
+
}
|
|
153
|
+
if (ts.isClassDeclaration(decl)) {
|
|
154
|
+
return 'class';
|
|
155
|
+
}
|
|
156
|
+
if (ts.isInterfaceDeclaration(decl) || ts.isTypeAliasDeclaration(decl)) {
|
|
157
|
+
return 'type';
|
|
158
|
+
}
|
|
159
|
+
if (ts.isVariableDeclaration(decl)) {
|
|
160
|
+
// Handle initializers for variable declarations
|
|
161
|
+
if (decl.initializer) {
|
|
162
|
+
if (ts.isFunctionExpression(decl.initializer) || ts.isArrowFunction(decl.initializer)) {
|
|
163
|
+
return 'function';
|
|
164
|
+
}
|
|
165
|
+
if (ts.isClassExpression(decl.initializer)) {
|
|
166
|
+
return 'class';
|
|
167
|
+
}
|
|
168
|
+
// Handle identifiers pointing to other declarations
|
|
169
|
+
if (ts.isIdentifier(decl.initializer)) {
|
|
170
|
+
try {
|
|
171
|
+
const referred_symbol = this.#checker.getSymbolAtLocation(decl.initializer);
|
|
172
|
+
if (referred_symbol) {
|
|
173
|
+
// Avoid infinite recursion by not resolving symbols here
|
|
174
|
+
if (this.#is_function_symbol(referred_symbol)) {
|
|
175
|
+
return 'function';
|
|
176
|
+
}
|
|
177
|
+
if (this.#is_class_symbol(referred_symbol)) {
|
|
178
|
+
return 'class';
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
// Ignore failures to resolve identifiers
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// As a fallback, check if the variable's type is callable
|
|
188
|
+
try {
|
|
189
|
+
const symbol = this.#checker.getSymbolAtLocation(decl.name);
|
|
190
|
+
if (symbol && this.#is_callable(symbol)) {
|
|
191
|
+
return 'function';
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Ignore errors in type checking
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if a symbol is exported as a type-only export.
|
|
202
|
+
* A type-only export means it's ONLY exported as a type with no value export.
|
|
203
|
+
*/
|
|
204
|
+
#is_type_only_export(source_file, symbol) {
|
|
205
|
+
// First, check if the symbol has an explicit type-only export
|
|
206
|
+
let has_type_only_export = false;
|
|
207
|
+
// Check if it has a corresponding value export
|
|
208
|
+
const has_value_export = this.#has_value_export(source_file, symbol);
|
|
209
|
+
// If it has both type and value exports (dual purpose), it's not type-only
|
|
210
|
+
if (has_value_export) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
// Check export declarations for explicit type-only exports
|
|
214
|
+
ts.forEachChild(source_file, (node) => {
|
|
215
|
+
if (ts.isExportDeclaration(node) &&
|
|
216
|
+
node.exportClause &&
|
|
217
|
+
ts.isNamedExports(node.exportClause)) {
|
|
218
|
+
// Check if it's a type-only export declaration (export type {...})
|
|
219
|
+
if (node.isTypeOnly) {
|
|
220
|
+
for (const specifier of node.exportClause.elements) {
|
|
221
|
+
if (specifier.name.text === symbol.name) {
|
|
222
|
+
has_type_only_export = true;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
// Check if it's a specific type export (export {type X})
|
|
228
|
+
for (const specifier of node.exportClause.elements) {
|
|
229
|
+
if (specifier.name.text === symbol.name && specifier.isTypeOnly) {
|
|
230
|
+
has_type_only_export = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
// If explicitly marked as a type-only export, use that
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
238
|
+
if (has_type_only_export) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
// If not explicitly marked as type-only, check if the symbol itself is a type
|
|
242
|
+
// AND there's no value export for it
|
|
243
|
+
const resolved_symbol = this.#resolve_symbol(symbol);
|
|
244
|
+
return this.#is_type_symbol(resolved_symbol) && !has_value_export;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Check if a symbol has a value export in the source file.
|
|
248
|
+
*/
|
|
249
|
+
#has_value_export(source_file, symbol) {
|
|
250
|
+
let has_value_export = false;
|
|
251
|
+
// Check export declarations
|
|
252
|
+
ts.forEachChild(source_file, (node) => {
|
|
253
|
+
if (ts.isExportDeclaration(node) &&
|
|
254
|
+
node.exportClause &&
|
|
255
|
+
ts.isNamedExports(node.exportClause)) {
|
|
256
|
+
// Skip type-only exports
|
|
257
|
+
if (node.isTypeOnly)
|
|
258
|
+
return;
|
|
259
|
+
// Check if it's a regular export (not type-only)
|
|
260
|
+
for (const specifier of node.exportClause.elements) {
|
|
261
|
+
if (specifier.name.text === symbol.name && !specifier.isTypeOnly) {
|
|
262
|
+
has_value_export = true;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Check for default export
|
|
267
|
+
else if (ts.isExportAssignment(node) && symbol.name === 'default') {
|
|
268
|
+
has_value_export = true;
|
|
269
|
+
}
|
|
270
|
+
// Check for direct exports (export const x = ...)
|
|
271
|
+
else if (this.#is_direct_export(node) && this.#get_export_name(node) === symbol.name) {
|
|
272
|
+
has_value_export = true;
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
return has_value_export;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Check if a node is a direct export (export const/function/class).
|
|
279
|
+
*/
|
|
280
|
+
#is_direct_export(node) {
|
|
281
|
+
return ((ts.isVariableStatement(node) ||
|
|
282
|
+
ts.isFunctionDeclaration(node) ||
|
|
283
|
+
ts.isClassDeclaration(node)) &&
|
|
284
|
+
this.#has_export_modifier(node));
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Get the export name from a direct export node.
|
|
288
|
+
*/
|
|
289
|
+
#get_export_name(node) {
|
|
290
|
+
if (ts.isVariableStatement(node) && node.declarationList.declarations.length > 0) {
|
|
291
|
+
const decl = node.declarationList.declarations[0];
|
|
292
|
+
if (ts.isIdentifier(decl.name)) {
|
|
293
|
+
return decl.name.text;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
else if (ts.isFunctionDeclaration(node) && node.name) {
|
|
297
|
+
return node.name.text;
|
|
298
|
+
}
|
|
299
|
+
else if (ts.isClassDeclaration(node) && node.name) {
|
|
300
|
+
return node.name.text;
|
|
301
|
+
}
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Check if a node has an export modifier.
|
|
306
|
+
*/
|
|
307
|
+
#has_export_modifier(node) {
|
|
308
|
+
return ((ts.canHaveModifiers(node) &&
|
|
309
|
+
ts.getModifiers(node)?.some((mod) => mod.kind === ts.SyntaxKind.ExportKeyword)) ||
|
|
310
|
+
false);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Check if a symbol is a function symbol.
|
|
314
|
+
*/
|
|
315
|
+
#is_function_symbol(symbol) {
|
|
316
|
+
return !!(symbol.flags & ts.SymbolFlags.Function || symbol.flags & ts.SymbolFlags.Method);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Check if a symbol is a class symbol.
|
|
320
|
+
*/
|
|
321
|
+
#is_class_symbol(symbol) {
|
|
322
|
+
return !!(symbol.flags & ts.SymbolFlags.Class);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Check if a symbol is a type-only symbol (interface, type alias, etc.).
|
|
326
|
+
*/
|
|
327
|
+
#is_type_symbol(symbol) {
|
|
328
|
+
return !!(symbol.flags & ts.SymbolFlags.Interface ||
|
|
329
|
+
symbol.flags & ts.SymbolFlags.TypeAlias ||
|
|
330
|
+
symbol.flags & ts.SymbolFlags.TypeParameter);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse_imports.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/parse_imports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"parse_imports.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/parse_imports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;AAGtD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAGvC,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAyBpE,eAAO,MAAM,aAAa,GACzB,IAAI,OAAO,EACX,UAAU,MAAM,EAChB,sBAAmB,KACjB,KAAK,CAAC,gBAAgB,CA+IxB,CAAC"}
|
package/dist/parse_imports.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parseSync } from 'oxc-parser';
|
|
2
2
|
import { Unreachable_Error } from '@ryanatkn/belt/error.js';
|
|
3
|
-
import { SVELTE_MATCHER } from "./
|
|
4
|
-
import { JS_MATCHER, TS_MATCHER, SVELTE_SCRIPT_MATCHER } from "./constants.js";
|
|
3
|
+
import { JS_MATCHER, TS_MATCHER, SVELTE_MATCHER, SVELTE_SCRIPT_MATCHER } from "./constants.js";
|
|
5
4
|
// TODO this is probably way more complicated that it should be, maybe report the issues upstream unless I made a mistake here
|
|
6
5
|
/**
|
|
7
6
|
* Extracts the string value from a module request, handling different quote styles.
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { Path_Id } from './path.ts';
|
|
2
2
|
export declare const LIB_DIRNAME: string;
|
|
3
3
|
export declare const LIB_PATH: string;
|
|
4
|
+
/** @trailing_slash */
|
|
4
5
|
export declare const LIB_DIR: string;
|
|
5
6
|
export declare const ROUTES_DIRNAME: string;
|
|
6
7
|
export interface Paths {
|
|
8
|
+
/** @trailing_slash */
|
|
7
9
|
root: string;
|
|
10
|
+
/** @trailing_slash */
|
|
8
11
|
source: string;
|
|
12
|
+
/** @trailing_slash */
|
|
9
13
|
lib: string;
|
|
14
|
+
/** @trailing_slash */
|
|
10
15
|
build: string;
|
|
16
|
+
/** @trailing_slash */
|
|
11
17
|
build_dev: string;
|
|
12
18
|
config: string;
|
|
13
19
|
}
|
|
@@ -23,11 +29,13 @@ export declare const replace_extension: (path: string, new_extension: string) =>
|
|
|
23
29
|
* Paths for the user repo.
|
|
24
30
|
*/
|
|
25
31
|
export declare const paths: Paths;
|
|
32
|
+
/** @trailing_slash */
|
|
26
33
|
export declare const GRO_PACKAGE_DIR = "gro/";
|
|
27
34
|
export declare const IS_THIS_GRO: boolean;
|
|
28
35
|
/**
|
|
29
36
|
* Paths for the Gro package being used by the user repo.
|
|
30
37
|
*/
|
|
31
38
|
export declare const gro_paths: Paths;
|
|
39
|
+
/** @trailing_slash */
|
|
32
40
|
export declare const GRO_DIST_DIR: string;
|
|
33
41
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/paths.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AASvC,eAAO,MAAM,WAAW,QAA2C,CAAC;AACpE,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,eAAO,MAAM,OAAO,QAAiB,CAAC;AACtC,eAAO,MAAM,cAAc,QAA8C,CAAC;AAE1E,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,KAW/C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,IAAI,OAAO,KAAG,KAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/paths.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AASvC,eAAO,MAAM,WAAW,QAA2C,CAAC;AACpE,eAAO,MAAM,QAAQ,QAA2B,CAAC;AACjD,sBAAsB;AACtB,eAAO,MAAM,OAAO,QAAiB,CAAC;AACtC,eAAO,MAAM,cAAc,QAA8C,CAAC;AAE1E,MAAM,WAAW,KAAK;IACrB,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,sBAAsB;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,KAW/C,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,IAAI,OAAO,KAAG,KAA4C,CAAC;AAEvF,eAAO,MAAM,SAAS,GAAI,IAAI,OAAO,KAAG,OACgC,CAAC;AAGzE,eAAO,MAAM,YAAY,GAAI,IAAI,OAAO,EAAE,SAAmB,KAAG,MACnC,CAAC;AAG9B,eAAO,MAAM,oBAAoB,GAAI,SAAS,OAAO,EAAE,SAAwB,KAAG,MACtD,CAAC;AAI7B,eAAO,MAAM,oBAAoB,GAAI,WAAW,MAAM,EAAE,SAA0B,KAAG,OAC3D,CAAC;AAE3B,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,SAAqB,KAAG,MAMhE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,eAAe,MAAM,KAAG,MAGvE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,KAAK,OAA8B,CAAC;AAEjD,sBAAsB;AACtB,eAAO,MAAM,eAAe,SAAS,CAAC;AAYtC,eAAO,MAAM,WAAW,SAAsC,CAAC;AAC/D;;GAEG;AACH,eAAO,MAAM,SAAS,OAA2D,CAAC;AAClF,sBAAsB;AACtB,eAAO,MAAM,YAAY,QAAgD,CAAC"}
|
package/dist/paths.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join, extname, relative, basename } from 'node:path';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { strip_end } from '@ryanatkn/belt/string.js';
|
|
3
|
+
import { ensure_end, strip_end } from '@ryanatkn/belt/string.js';
|
|
4
4
|
import { styleText as st } from 'node:util';
|
|
5
5
|
import { GRO_CONFIG_PATH, GRO_DEV_DIR, GRO_DIR, SOURCE_DIR, SVELTEKIT_DIST_DIRNAME, } from "./constants.js";
|
|
6
6
|
import { default_svelte_config } from "./svelte_config.js";
|
|
@@ -12,11 +12,12 @@ It's the same name that Rollup uses.
|
|
|
12
12
|
*/
|
|
13
13
|
export const LIB_DIRNAME = basename(default_svelte_config.lib_path);
|
|
14
14
|
export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
|
|
15
|
+
/** @trailing_slash */
|
|
15
16
|
export const LIB_DIR = LIB_PATH + '/';
|
|
16
17
|
export const ROUTES_DIRNAME = basename(default_svelte_config.routes_path);
|
|
17
18
|
export const create_paths = (root_dir) => {
|
|
18
19
|
// TODO remove reliance on trailing slash towards windows support
|
|
19
|
-
const root =
|
|
20
|
+
const root = ensure_end(root_dir, '/');
|
|
20
21
|
return {
|
|
21
22
|
root,
|
|
22
23
|
source: root + SOURCE_DIR,
|
|
@@ -27,7 +28,7 @@ export const create_paths = (root_dir) => {
|
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
30
|
export const infer_paths = (id) => (is_gro_id(id) ? gro_paths : paths);
|
|
30
|
-
export const is_gro_id = (id) => id.startsWith(
|
|
31
|
+
export const is_gro_id = (id) => id.startsWith(gro_paths.root) || gro_paths.root === ensure_end(id, '/');
|
|
31
32
|
// '/home/me/app/src/foo/bar/baz.ts' → 'src/foo/bar/baz.ts'
|
|
32
33
|
export const to_root_path = (id, p = infer_paths(id)) => relative(p.root, id) || './';
|
|
33
34
|
// '/home/me/app/src/foo/bar/baz.ts' → 'foo/bar/baz.ts'
|
|
@@ -49,6 +50,7 @@ export const replace_extension = (path, new_extension) => {
|
|
|
49
50
|
* Paths for the user repo.
|
|
50
51
|
*/
|
|
51
52
|
export const paths = create_paths(process.cwd());
|
|
53
|
+
/** @trailing_slash */
|
|
52
54
|
export const GRO_PACKAGE_DIR = 'gro/';
|
|
53
55
|
// TODO document these conditions with comments
|
|
54
56
|
// TODO there's probably a more robust way to do this
|
|
@@ -63,4 +65,5 @@ export const IS_THIS_GRO = gro_package_dir_path === paths.root;
|
|
|
63
65
|
* Paths for the Gro package being used by the user repo.
|
|
64
66
|
*/
|
|
65
67
|
export const gro_paths = IS_THIS_GRO ? paths : create_paths(gro_package_dir_path);
|
|
68
|
+
/** @trailing_slash */
|
|
66
69
|
export const GRO_DIST_DIR = gro_paths.root + SVELTEKIT_DIST_DIRNAME + '/';
|