@powerlines/plugin-unbuild 0.5.36 → 0.5.38

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.
@@ -3,15 +3,18 @@ import { EnvPaths } from '@stryke/env/get-env-paths';
3
3
  import { MaybePromise, NonUndefined, FunctionLike } from '@stryke/types/base';
4
4
  import { PackageJson } from '@stryke/types/package-json';
5
5
  import { Jiti } from 'jiti';
6
+ import { SourceMap } from 'magic-string';
6
7
  import { Range } from 'semver';
7
- import { UnpluginMessage, UnpluginContext, UnpluginBuildContext, TransformResult, ExternalIdResult, HookFilter, UnpluginOptions } from 'unplugin';
8
+ import { Project } from 'ts-morph';
9
+ import { UnpluginMessage, ExternalIdResult, UnpluginContext, UnpluginBuildContext, TransformResult as TransformResult$1, HookFilter, UnpluginOptions } from 'unplugin';
8
10
  import { Format } from '@storm-software/build-tools/types';
9
11
  import { LogLevelLabel } from '@storm-software/config-tools/types';
10
12
  import { StormWorkspaceConfig } from '@storm-software/config/types';
11
13
  import { TypeDefinitionParameter, TypeDefinition } from '@stryke/types/configuration';
12
14
  import { AssetGlob } from '@stryke/types/file';
13
15
  import { PreviewOptions, ResolvedPreviewOptions } from 'vite';
14
- import { PathLike, StatSyncOptions, Stats, RmDirOptions, RmOptions, Mode, MakeDirectoryOptions as MakeDirectoryOptions$1, PathOrFileDescriptor, WriteFileOptions as WriteFileOptions$1 } from 'node:fs';
16
+ import { ResolveOptions as ResolveOptions$1 } from '@stryke/fs/resolve';
17
+ import { StatSyncOptions, Stats, RmDirOptions, RmOptions, Mode, MakeDirectoryOptions as MakeDirectoryOptions$1, WriteFileOptions as WriteFileOptions$1 } from 'node:fs';
15
18
  import { ArrayValues } from '@stryke/types/array';
16
19
  import { TsConfigJson, CompilerOptions } from '@stryke/types/tsconfig';
17
20
  import ts from 'typescript';
@@ -241,21 +244,27 @@ interface PowerlinesWriteFileOptions extends ResolveFSOptions {
241
244
  type NodeWriteFileOptions = WriteFileOptions$1;
242
245
  type WriteFileOptions = NodeWriteFileOptions | PowerlinesWriteFileOptions;
243
246
  type WriteFileData = string | NodeJS.ArrayBufferView | VirtualFileData;
244
- interface ResolvePathOptions extends ResolveFSOptions {
247
+ interface ResolveOptions extends ResolveOptions$1 {
245
248
  /**
246
- * Should the resolved path include the file extension?
247
- *
248
- * @defaultValue true
249
+ * If true, the module is being resolved as an entry point.
250
+ */
251
+ isEntry?: boolean;
252
+ /**
253
+ * If true, the resolver will skip using the cache when resolving modules.
254
+ */
255
+ skipCache?: boolean;
256
+ /**
257
+ * An array of external modules or patterns to exclude from resolution.
249
258
  */
250
- withExtension?: boolean;
259
+ external?: (string | RegExp)[];
251
260
  /**
252
- * The paths to search for the file.
261
+ * An array of modules or patterns to include in the resolution, even if they are marked as external.
253
262
  */
254
- paths?: string[];
263
+ noExternal?: (string | RegExp)[];
255
264
  /**
256
- * The type of the path to resolve.
265
+ * An array of patterns to match when resolving modules.
257
266
  */
258
- pathType?: "file" | "directory";
267
+ skipNodeModulesBundle?: boolean;
259
268
  }
260
269
  interface VirtualFileSystemInterface {
261
270
  /**
@@ -269,27 +278,33 @@ interface VirtualFileSystemInterface {
269
278
  /**
270
279
  * The underlying file metadata.
271
280
  */
272
- metadata: Record<string, VirtualFileMetadata | undefined>;
281
+ metadata: Readonly<Record<string, VirtualFileMetadata>>;
282
+ /**
283
+ * A map of file paths to their module ids.
284
+ */
285
+ ids: Readonly<Record<string, string>>;
273
286
  /**
274
287
  * A map of module ids to their file paths.
275
288
  */
276
- ids: Record<string, string>;
289
+ paths: Readonly<Record<string, string>>;
277
290
  /**
278
291
  * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
279
292
  *
280
293
  * @param pathOrId - The path or id to check.
294
+ * @param importer - The importer path, if any.
281
295
  * @param options - Optional parameters for resolving the path.
282
296
  * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
283
297
  */
284
- isVirtual: (pathOrId: string, options?: ResolvePathOptions) => boolean;
298
+ isVirtual: (pathOrId: string, importer?: string, options?: ResolveOptions) => boolean;
285
299
  /**
286
300
  * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
287
301
  *
288
302
  * @param pathOrId - The path or id to check.
303
+ * @param importer - The importer path, if any.
289
304
  * @param options - Optional parameters for resolving the path.
290
305
  * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
291
306
  */
292
- isPhysical: (pathOrId: string, options?: ResolvePathOptions) => boolean;
307
+ isPhysical: (pathOrId: string, importer?: string, options?: ResolveOptions) => boolean;
293
308
  /**
294
309
  * Checks if a file exists in the virtual file system (VFS).
295
310
  *
@@ -317,7 +332,7 @@ interface VirtualFileSystemInterface {
317
332
  * @param pathOrId - The path or id of the file.
318
333
  * @returns The metadata of the file if it exists, otherwise undefined.
319
334
  */
320
- getMetadata: (pathOrId: PathLike) => VirtualFileMetadata | undefined;
335
+ getMetadata: (pathOrId: string) => VirtualFileMetadata | undefined;
321
336
  /**
322
337
  * Gets the stats of a file in the virtual file system (VFS).
323
338
  *
@@ -390,7 +405,7 @@ interface VirtualFileSystemInterface {
390
405
  * @param path - The path to the file to remove.
391
406
  * @returns A promise that resolves when the file is removed.
392
407
  */
393
- unlinkSync: (path: PathLike, options?: ResolveFSOptions) => void;
408
+ unlinkSync: (path: string, options?: ResolveFSOptions) => void;
394
409
  /**
395
410
  * Asynchronously removes a file or symbolic link in the virtual file system (VFS).
396
411
  *
@@ -404,7 +419,7 @@ interface VirtualFileSystemInterface {
404
419
  * @param path - The path to create the directory at.
405
420
  * @param options - Options for creating the directory.
406
421
  */
407
- rmdirSync: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => any;
422
+ rmdirSync: (path: string, options?: RmDirOptions & ResolveFSOptions) => any;
408
423
  /**
409
424
  * Removes a directory in the virtual file system (VFS).
410
425
  *
@@ -412,7 +427,7 @@ interface VirtualFileSystemInterface {
412
427
  * @param options - Options for creating the directory.
413
428
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
414
429
  */
415
- rmdir: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => Promise<void>;
430
+ rmdir: (path: string, options?: RmDirOptions & ResolveFSOptions) => Promise<void>;
416
431
  /**
417
432
  * Removes a file or directory in the virtual file system (VFS).
418
433
  *
@@ -420,14 +435,14 @@ interface VirtualFileSystemInterface {
420
435
  * @param options - Options for removing the file or directory.
421
436
  * @returns A promise that resolves when the file or directory is removed.
422
437
  */
423
- rm: (path: PathLike, options?: RmOptions & ResolveFSOptions) => Promise<void>;
438
+ rm: (path: string, options?: RmOptions & ResolveFSOptions) => Promise<void>;
424
439
  /**
425
440
  * Synchronously removes a file or directory in the virtual file system (VFS).
426
441
  *
427
442
  * @param path - The path to the file or directory to remove.
428
443
  * @param options - Options for removing the file or directory.
429
444
  */
430
- rmSync: (path: PathLike, options?: RmOptions & ResolveFSOptions) => void;
445
+ rmSync: (path: string, options?: RmOptions & ResolveFSOptions) => void;
431
446
  /**
432
447
  * Creates a directory in the virtual file system (VFS).
433
448
  *
@@ -435,7 +450,7 @@ interface VirtualFileSystemInterface {
435
450
  * @param options - Options for creating the directory.
436
451
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
437
452
  */
438
- mkdirSync: (path: PathLike, options?: MakeDirectoryOptions) => string | undefined;
453
+ mkdirSync: (path: string, options?: MakeDirectoryOptions) => string | undefined;
439
454
  /**
440
455
  * Creates a directory in the virtual file system (VFS).
441
456
  *
@@ -443,7 +458,7 @@ interface VirtualFileSystemInterface {
443
458
  * @param options - Options for creating the directory.
444
459
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
445
460
  */
446
- mkdir: (path: PathLike, options?: MakeDirectoryOptions) => Promise<string | undefined>;
461
+ mkdir: (path: string, options?: MakeDirectoryOptions) => Promise<string | undefined>;
447
462
  /**
448
463
  * Reads a file from the virtual file system (VFS).
449
464
  *
@@ -465,7 +480,7 @@ interface VirtualFileSystemInterface {
465
480
  * @param options - Optional parameters for writing the file.
466
481
  * @returns A promise that resolves when the file is written.
467
482
  */
468
- writeFile: (path: PathOrFileDescriptor, data?: WriteFileData, options?: WriteFileOptions) => Promise<void>;
483
+ writeFile: (path: string, data?: WriteFileData, options?: WriteFileOptions) => Promise<void>;
469
484
  /**
470
485
  * Writes a file to the virtual file system (VFS).
471
486
  *
@@ -473,7 +488,7 @@ interface VirtualFileSystemInterface {
473
488
  * @param data - The contents of the file.
474
489
  * @param options - Optional parameters for writing the file.
475
490
  */
476
- writeFileSync: (path: PathOrFileDescriptor, data?: WriteFileData, options?: WriteFileOptions) => void;
491
+ writeFileSync: (path: string, data?: WriteFileData, options?: WriteFileOptions) => void;
477
492
  /**
478
493
  * Moves a file from one path to another in the virtual file system (VFS).
479
494
  *
@@ -520,24 +535,43 @@ interface VirtualFileSystemInterface {
520
535
  * Resolves a path or id to a file path in the virtual file system.
521
536
  *
522
537
  * @param pathOrId - The path or id of the file to resolve.
523
- * @param options - Optional parameters for resolving the path.
524
538
  * @returns The resolved path of the file if it exists, otherwise false.
525
539
  */
526
- resolve: (pathOrId: string, options?: ResolvePathOptions) => string | false;
540
+ realpathSync: (pathOrId: string) => string;
527
541
  /**
528
- * Formats a path to match the virtual file system (VFS) structure.
542
+ * A helper function to resolve modules using the Jiti resolver
529
543
  *
530
- * @param path - The path to format.
531
- * @returns The formatted path.
544
+ * @remarks
545
+ * This function can be used to resolve modules relative to the project root directory.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
550
+ * ```
551
+ *
552
+ * @param id - The module to resolve.
553
+ * @param importer - An optional path to the importer module.
554
+ * @param options - Additional resolution options.
555
+ * @returns A promise that resolves to the resolved module path.
532
556
  */
533
- formatPath: (path: string) => string;
557
+ resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<string | undefined>;
534
558
  /**
535
- * Resolves a path or id to a file path in the virtual file system.
559
+ * A synchronous helper function to resolve modules using the Jiti resolver
536
560
  *
537
- * @param pathOrId - The path or id of the file to resolve.
538
- * @returns The resolved path of the file if it exists, otherwise false.
561
+ * @remarks
562
+ * This function can be used to resolve modules relative to the project root directory.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
567
+ * ```
568
+ *
569
+ * @param id - The module to resolve.
570
+ * @param importer - An optional path to the importer module.
571
+ * @param options - Additional resolution options.
572
+ * @returns The resolved module path.
539
573
  */
540
- realpathSync: (pathOrId: string) => string;
574
+ resolveSync: (id: string, importer?: string, options?: ResolveOptions) => string | undefined;
541
575
  /**
542
576
  * Disposes of the virtual file system (VFS), writes any virtual file changes to disk, and releases any associated resources.
543
577
  */
@@ -1011,6 +1045,10 @@ interface MetaInfo {
1011
1045
  interface Resolver extends Jiti {
1012
1046
  plugin: Jiti;
1013
1047
  }
1048
+ interface TransformResult {
1049
+ code: string;
1050
+ map: SourceMap | null;
1051
+ }
1014
1052
  interface InitContextOptions {
1015
1053
  /**
1016
1054
  * If false, the plugin will be loaded after all other plugins.
@@ -1145,6 +1183,47 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
1145
1183
  * The builtin module id that exist in the Powerlines virtual file system
1146
1184
  */
1147
1185
  builtins: string[];
1186
+ /**
1187
+ * The {@link Project} instance used for type reflection and module manipulation
1188
+ *
1189
+ * @see https://ts-morph.com/
1190
+ *
1191
+ * @remarks
1192
+ * This instance is created lazily on first access.
1193
+ */
1194
+ program: Project;
1195
+ /**
1196
+ * A helper function to resolve modules using the Jiti resolver
1197
+ *
1198
+ * @remarks
1199
+ * This function can be used to resolve modules relative to the project root directory.
1200
+ *
1201
+ * @example
1202
+ * ```ts
1203
+ * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
1204
+ * ```
1205
+ *
1206
+ * @param id - The module to resolve.
1207
+ * @param importer - An optional path to the importer module.
1208
+ * @param options - Additional resolution options.
1209
+ * @returns A promise that resolves to the resolved module path.
1210
+ */
1211
+ resolveId: (id: string, importer?: string, options?: ResolveOptions) => Promise<ExternalIdResult | undefined>;
1212
+ /**
1213
+ * A helper function to load modules using the Jiti resolver
1214
+ *
1215
+ * @remarks
1216
+ * This function can be used to load modules relative to the project root directory.
1217
+ *
1218
+ * @example
1219
+ * ```ts
1220
+ * const module = await context.load("some-module", "/path/to/importer");
1221
+ * ```
1222
+ *
1223
+ * @param id - The module to load.
1224
+ * @returns A promise that resolves to the loaded module.
1225
+ */
1226
+ load: (id: string) => Promise<TransformResult | undefined>;
1148
1227
  /**
1149
1228
  * The Powerlines builtin virtual files
1150
1229
  */
@@ -1314,7 +1393,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1314
1393
  * @param id - The identifier of the source code.
1315
1394
  * @returns A promise that resolves when the hook is complete.
1316
1395
  */
1317
- transform: (this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>;
1396
+ transform: (this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult$1>;
1318
1397
  /**
1319
1398
  * A hook that is called to load the source code.
1320
1399
  *
@@ -1322,7 +1401,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1322
1401
  * @param id - The identifier of the source code.
1323
1402
  * @returns A promise that resolves when the hook is complete.
1324
1403
  */
1325
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
1404
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult$1>;
1326
1405
  /**
1327
1406
  * A hook that is called to resolve the identifier of the source code.
1328
1407
  *
@@ -1372,7 +1451,7 @@ type PluginHooks<TContext extends PluginContext = PluginContext> = {
1372
1451
  * @param id - The identifier of the source code.
1373
1452
  * @returns A promise that resolves when the hook is complete.
1374
1453
  */
1375
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
1454
+ transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult$1>, "code" | "id">;
1376
1455
  /**
1377
1456
  * A hook that is called to load the source code.
1378
1457
  *
@@ -1380,7 +1459,7 @@ type PluginHooks<TContext extends PluginContext = PluginContext> = {
1380
1459
  * @param id - The identifier of the source code.
1381
1460
  * @returns A promise that resolves when the hook is complete.
1382
1461
  */
1383
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
1462
+ load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult$1>, "id">;
1384
1463
  /**
1385
1464
  * A hook that is called to resolve the identifier of the source code.
1386
1465
  *
@@ -3,15 +3,18 @@ import { EnvPaths } from '@stryke/env/get-env-paths';
3
3
  import { MaybePromise, NonUndefined, FunctionLike } from '@stryke/types/base';
4
4
  import { PackageJson } from '@stryke/types/package-json';
5
5
  import { Jiti } from 'jiti';
6
+ import { SourceMap } from 'magic-string';
6
7
  import { Range } from 'semver';
7
- import { UnpluginMessage, UnpluginContext, UnpluginBuildContext, TransformResult, ExternalIdResult, HookFilter, UnpluginOptions } from 'unplugin';
8
+ import { Project } from 'ts-morph';
9
+ import { UnpluginMessage, ExternalIdResult, UnpluginContext, UnpluginBuildContext, TransformResult as TransformResult$1, HookFilter, UnpluginOptions } from 'unplugin';
8
10
  import { Format } from '@storm-software/build-tools/types';
9
11
  import { LogLevelLabel } from '@storm-software/config-tools/types';
10
12
  import { StormWorkspaceConfig } from '@storm-software/config/types';
11
13
  import { TypeDefinitionParameter, TypeDefinition } from '@stryke/types/configuration';
12
14
  import { AssetGlob } from '@stryke/types/file';
13
15
  import { PreviewOptions, ResolvedPreviewOptions } from 'vite';
14
- import { PathLike, StatSyncOptions, Stats, RmDirOptions, RmOptions, Mode, MakeDirectoryOptions as MakeDirectoryOptions$1, PathOrFileDescriptor, WriteFileOptions as WriteFileOptions$1 } from 'node:fs';
16
+ import { ResolveOptions as ResolveOptions$1 } from '@stryke/fs/resolve';
17
+ import { StatSyncOptions, Stats, RmDirOptions, RmOptions, Mode, MakeDirectoryOptions as MakeDirectoryOptions$1, WriteFileOptions as WriteFileOptions$1 } from 'node:fs';
15
18
  import { ArrayValues } from '@stryke/types/array';
16
19
  import { TsConfigJson, CompilerOptions } from '@stryke/types/tsconfig';
17
20
  import ts from 'typescript';
@@ -241,21 +244,27 @@ interface PowerlinesWriteFileOptions extends ResolveFSOptions {
241
244
  type NodeWriteFileOptions = WriteFileOptions$1;
242
245
  type WriteFileOptions = NodeWriteFileOptions | PowerlinesWriteFileOptions;
243
246
  type WriteFileData = string | NodeJS.ArrayBufferView | VirtualFileData;
244
- interface ResolvePathOptions extends ResolveFSOptions {
247
+ interface ResolveOptions extends ResolveOptions$1 {
245
248
  /**
246
- * Should the resolved path include the file extension?
247
- *
248
- * @defaultValue true
249
+ * If true, the module is being resolved as an entry point.
250
+ */
251
+ isEntry?: boolean;
252
+ /**
253
+ * If true, the resolver will skip using the cache when resolving modules.
254
+ */
255
+ skipCache?: boolean;
256
+ /**
257
+ * An array of external modules or patterns to exclude from resolution.
249
258
  */
250
- withExtension?: boolean;
259
+ external?: (string | RegExp)[];
251
260
  /**
252
- * The paths to search for the file.
261
+ * An array of modules or patterns to include in the resolution, even if they are marked as external.
253
262
  */
254
- paths?: string[];
263
+ noExternal?: (string | RegExp)[];
255
264
  /**
256
- * The type of the path to resolve.
265
+ * An array of patterns to match when resolving modules.
257
266
  */
258
- pathType?: "file" | "directory";
267
+ skipNodeModulesBundle?: boolean;
259
268
  }
260
269
  interface VirtualFileSystemInterface {
261
270
  /**
@@ -269,27 +278,33 @@ interface VirtualFileSystemInterface {
269
278
  /**
270
279
  * The underlying file metadata.
271
280
  */
272
- metadata: Record<string, VirtualFileMetadata | undefined>;
281
+ metadata: Readonly<Record<string, VirtualFileMetadata>>;
282
+ /**
283
+ * A map of file paths to their module ids.
284
+ */
285
+ ids: Readonly<Record<string, string>>;
273
286
  /**
274
287
  * A map of module ids to their file paths.
275
288
  */
276
- ids: Record<string, string>;
289
+ paths: Readonly<Record<string, string>>;
277
290
  /**
278
291
  * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
279
292
  *
280
293
  * @param pathOrId - The path or id to check.
294
+ * @param importer - The importer path, if any.
281
295
  * @param options - Optional parameters for resolving the path.
282
296
  * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
283
297
  */
284
- isVirtual: (pathOrId: string, options?: ResolvePathOptions) => boolean;
298
+ isVirtual: (pathOrId: string, importer?: string, options?: ResolveOptions) => boolean;
285
299
  /**
286
300
  * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
287
301
  *
288
302
  * @param pathOrId - The path or id to check.
303
+ * @param importer - The importer path, if any.
289
304
  * @param options - Optional parameters for resolving the path.
290
305
  * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
291
306
  */
292
- isPhysical: (pathOrId: string, options?: ResolvePathOptions) => boolean;
307
+ isPhysical: (pathOrId: string, importer?: string, options?: ResolveOptions) => boolean;
293
308
  /**
294
309
  * Checks if a file exists in the virtual file system (VFS).
295
310
  *
@@ -317,7 +332,7 @@ interface VirtualFileSystemInterface {
317
332
  * @param pathOrId - The path or id of the file.
318
333
  * @returns The metadata of the file if it exists, otherwise undefined.
319
334
  */
320
- getMetadata: (pathOrId: PathLike) => VirtualFileMetadata | undefined;
335
+ getMetadata: (pathOrId: string) => VirtualFileMetadata | undefined;
321
336
  /**
322
337
  * Gets the stats of a file in the virtual file system (VFS).
323
338
  *
@@ -390,7 +405,7 @@ interface VirtualFileSystemInterface {
390
405
  * @param path - The path to the file to remove.
391
406
  * @returns A promise that resolves when the file is removed.
392
407
  */
393
- unlinkSync: (path: PathLike, options?: ResolveFSOptions) => void;
408
+ unlinkSync: (path: string, options?: ResolveFSOptions) => void;
394
409
  /**
395
410
  * Asynchronously removes a file or symbolic link in the virtual file system (VFS).
396
411
  *
@@ -404,7 +419,7 @@ interface VirtualFileSystemInterface {
404
419
  * @param path - The path to create the directory at.
405
420
  * @param options - Options for creating the directory.
406
421
  */
407
- rmdirSync: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => any;
422
+ rmdirSync: (path: string, options?: RmDirOptions & ResolveFSOptions) => any;
408
423
  /**
409
424
  * Removes a directory in the virtual file system (VFS).
410
425
  *
@@ -412,7 +427,7 @@ interface VirtualFileSystemInterface {
412
427
  * @param options - Options for creating the directory.
413
428
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
414
429
  */
415
- rmdir: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => Promise<void>;
430
+ rmdir: (path: string, options?: RmDirOptions & ResolveFSOptions) => Promise<void>;
416
431
  /**
417
432
  * Removes a file or directory in the virtual file system (VFS).
418
433
  *
@@ -420,14 +435,14 @@ interface VirtualFileSystemInterface {
420
435
  * @param options - Options for removing the file or directory.
421
436
  * @returns A promise that resolves when the file or directory is removed.
422
437
  */
423
- rm: (path: PathLike, options?: RmOptions & ResolveFSOptions) => Promise<void>;
438
+ rm: (path: string, options?: RmOptions & ResolveFSOptions) => Promise<void>;
424
439
  /**
425
440
  * Synchronously removes a file or directory in the virtual file system (VFS).
426
441
  *
427
442
  * @param path - The path to the file or directory to remove.
428
443
  * @param options - Options for removing the file or directory.
429
444
  */
430
- rmSync: (path: PathLike, options?: RmOptions & ResolveFSOptions) => void;
445
+ rmSync: (path: string, options?: RmOptions & ResolveFSOptions) => void;
431
446
  /**
432
447
  * Creates a directory in the virtual file system (VFS).
433
448
  *
@@ -435,7 +450,7 @@ interface VirtualFileSystemInterface {
435
450
  * @param options - Options for creating the directory.
436
451
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
437
452
  */
438
- mkdirSync: (path: PathLike, options?: MakeDirectoryOptions) => string | undefined;
453
+ mkdirSync: (path: string, options?: MakeDirectoryOptions) => string | undefined;
439
454
  /**
440
455
  * Creates a directory in the virtual file system (VFS).
441
456
  *
@@ -443,7 +458,7 @@ interface VirtualFileSystemInterface {
443
458
  * @param options - Options for creating the directory.
444
459
  * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
445
460
  */
446
- mkdir: (path: PathLike, options?: MakeDirectoryOptions) => Promise<string | undefined>;
461
+ mkdir: (path: string, options?: MakeDirectoryOptions) => Promise<string | undefined>;
447
462
  /**
448
463
  * Reads a file from the virtual file system (VFS).
449
464
  *
@@ -465,7 +480,7 @@ interface VirtualFileSystemInterface {
465
480
  * @param options - Optional parameters for writing the file.
466
481
  * @returns A promise that resolves when the file is written.
467
482
  */
468
- writeFile: (path: PathOrFileDescriptor, data?: WriteFileData, options?: WriteFileOptions) => Promise<void>;
483
+ writeFile: (path: string, data?: WriteFileData, options?: WriteFileOptions) => Promise<void>;
469
484
  /**
470
485
  * Writes a file to the virtual file system (VFS).
471
486
  *
@@ -473,7 +488,7 @@ interface VirtualFileSystemInterface {
473
488
  * @param data - The contents of the file.
474
489
  * @param options - Optional parameters for writing the file.
475
490
  */
476
- writeFileSync: (path: PathOrFileDescriptor, data?: WriteFileData, options?: WriteFileOptions) => void;
491
+ writeFileSync: (path: string, data?: WriteFileData, options?: WriteFileOptions) => void;
477
492
  /**
478
493
  * Moves a file from one path to another in the virtual file system (VFS).
479
494
  *
@@ -520,24 +535,43 @@ interface VirtualFileSystemInterface {
520
535
  * Resolves a path or id to a file path in the virtual file system.
521
536
  *
522
537
  * @param pathOrId - The path or id of the file to resolve.
523
- * @param options - Optional parameters for resolving the path.
524
538
  * @returns The resolved path of the file if it exists, otherwise false.
525
539
  */
526
- resolve: (pathOrId: string, options?: ResolvePathOptions) => string | false;
540
+ realpathSync: (pathOrId: string) => string;
527
541
  /**
528
- * Formats a path to match the virtual file system (VFS) structure.
542
+ * A helper function to resolve modules using the Jiti resolver
529
543
  *
530
- * @param path - The path to format.
531
- * @returns The formatted path.
544
+ * @remarks
545
+ * This function can be used to resolve modules relative to the project root directory.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
550
+ * ```
551
+ *
552
+ * @param id - The module to resolve.
553
+ * @param importer - An optional path to the importer module.
554
+ * @param options - Additional resolution options.
555
+ * @returns A promise that resolves to the resolved module path.
532
556
  */
533
- formatPath: (path: string) => string;
557
+ resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<string | undefined>;
534
558
  /**
535
- * Resolves a path or id to a file path in the virtual file system.
559
+ * A synchronous helper function to resolve modules using the Jiti resolver
536
560
  *
537
- * @param pathOrId - The path or id of the file to resolve.
538
- * @returns The resolved path of the file if it exists, otherwise false.
561
+ * @remarks
562
+ * This function can be used to resolve modules relative to the project root directory.
563
+ *
564
+ * @example
565
+ * ```ts
566
+ * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
567
+ * ```
568
+ *
569
+ * @param id - The module to resolve.
570
+ * @param importer - An optional path to the importer module.
571
+ * @param options - Additional resolution options.
572
+ * @returns The resolved module path.
539
573
  */
540
- realpathSync: (pathOrId: string) => string;
574
+ resolveSync: (id: string, importer?: string, options?: ResolveOptions) => string | undefined;
541
575
  /**
542
576
  * Disposes of the virtual file system (VFS), writes any virtual file changes to disk, and releases any associated resources.
543
577
  */
@@ -1011,6 +1045,10 @@ interface MetaInfo {
1011
1045
  interface Resolver extends Jiti {
1012
1046
  plugin: Jiti;
1013
1047
  }
1048
+ interface TransformResult {
1049
+ code: string;
1050
+ map: SourceMap | null;
1051
+ }
1014
1052
  interface InitContextOptions {
1015
1053
  /**
1016
1054
  * If false, the plugin will be loaded after all other plugins.
@@ -1145,6 +1183,47 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
1145
1183
  * The builtin module id that exist in the Powerlines virtual file system
1146
1184
  */
1147
1185
  builtins: string[];
1186
+ /**
1187
+ * The {@link Project} instance used for type reflection and module manipulation
1188
+ *
1189
+ * @see https://ts-morph.com/
1190
+ *
1191
+ * @remarks
1192
+ * This instance is created lazily on first access.
1193
+ */
1194
+ program: Project;
1195
+ /**
1196
+ * A helper function to resolve modules using the Jiti resolver
1197
+ *
1198
+ * @remarks
1199
+ * This function can be used to resolve modules relative to the project root directory.
1200
+ *
1201
+ * @example
1202
+ * ```ts
1203
+ * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
1204
+ * ```
1205
+ *
1206
+ * @param id - The module to resolve.
1207
+ * @param importer - An optional path to the importer module.
1208
+ * @param options - Additional resolution options.
1209
+ * @returns A promise that resolves to the resolved module path.
1210
+ */
1211
+ resolveId: (id: string, importer?: string, options?: ResolveOptions) => Promise<ExternalIdResult | undefined>;
1212
+ /**
1213
+ * A helper function to load modules using the Jiti resolver
1214
+ *
1215
+ * @remarks
1216
+ * This function can be used to load modules relative to the project root directory.
1217
+ *
1218
+ * @example
1219
+ * ```ts
1220
+ * const module = await context.load("some-module", "/path/to/importer");
1221
+ * ```
1222
+ *
1223
+ * @param id - The module to load.
1224
+ * @returns A promise that resolves to the loaded module.
1225
+ */
1226
+ load: (id: string) => Promise<TransformResult | undefined>;
1148
1227
  /**
1149
1228
  * The Powerlines builtin virtual files
1150
1229
  */
@@ -1314,7 +1393,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1314
1393
  * @param id - The identifier of the source code.
1315
1394
  * @returns A promise that resolves when the hook is complete.
1316
1395
  */
1317
- transform: (this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>;
1396
+ transform: (this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult$1>;
1318
1397
  /**
1319
1398
  * A hook that is called to load the source code.
1320
1399
  *
@@ -1322,7 +1401,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1322
1401
  * @param id - The identifier of the source code.
1323
1402
  * @returns A promise that resolves when the hook is complete.
1324
1403
  */
1325
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
1404
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult$1>;
1326
1405
  /**
1327
1406
  * A hook that is called to resolve the identifier of the source code.
1328
1407
  *
@@ -1372,7 +1451,7 @@ type PluginHooks<TContext extends PluginContext = PluginContext> = {
1372
1451
  * @param id - The identifier of the source code.
1373
1452
  * @returns A promise that resolves when the hook is complete.
1374
1453
  */
1375
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
1454
+ transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult$1>, "code" | "id">;
1376
1455
  /**
1377
1456
  * A hook that is called to load the source code.
1378
1457
  *
@@ -1380,7 +1459,7 @@ type PluginHooks<TContext extends PluginContext = PluginContext> = {
1380
1459
  * @param id - The identifier of the source code.
1381
1460
  * @returns A promise that resolves when the hook is complete.
1382
1461
  */
1383
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
1462
+ load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult$1>, "id">;
1384
1463
  /**
1385
1464
  * A hook that is called to resolve the identifier of the source code.
1386
1465
  *
package/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
- import { U as UnbuildPluginContext, a as UnbuildPluginOptions, P as Plugin } from './index-DJ4XjbiZ.cjs';
2
- export { b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from './index-DJ4XjbiZ.cjs';
1
+ import { U as UnbuildPluginContext, a as UnbuildPluginOptions, P as Plugin } from './index-CLa0ll-K.cjs';
2
+ export { b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from './index-CLa0ll-K.cjs';
3
3
  import '@storm-software/unbuild/types';
4
4
  import '@stryke/env/get-env-paths';
5
5
  import '@stryke/types/base';
6
6
  import '@stryke/types/package-json';
7
7
  import 'jiti';
8
+ import 'magic-string';
8
9
  import 'semver';
10
+ import 'ts-morph';
9
11
  import 'unplugin';
10
12
  import '@storm-software/build-tools/types';
11
13
  import '@storm-software/config-tools/types';
@@ -13,6 +15,7 @@ import '@storm-software/config/types';
13
15
  import '@stryke/types/configuration';
14
16
  import '@stryke/types/file';
15
17
  import 'vite';
18
+ import '@stryke/fs/resolve';
16
19
  import 'node:fs';
17
20
  import '@stryke/types/array';
18
21
  import '@stryke/types/tsconfig';
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { U as UnbuildPluginContext, a as UnbuildPluginOptions, P as Plugin } from './index-DJ4XjbiZ.js';
2
- export { b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from './index-DJ4XjbiZ.js';
1
+ import { U as UnbuildPluginContext, a as UnbuildPluginOptions, P as Plugin } from './index-CLa0ll-K.js';
2
+ export { b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from './index-CLa0ll-K.js';
3
3
  import '@storm-software/unbuild/types';
4
4
  import '@stryke/env/get-env-paths';
5
5
  import '@stryke/types/base';
6
6
  import '@stryke/types/package-json';
7
7
  import 'jiti';
8
+ import 'magic-string';
8
9
  import 'semver';
10
+ import 'ts-morph';
9
11
  import 'unplugin';
10
12
  import '@storm-software/build-tools/types';
11
13
  import '@storm-software/config-tools/types';
@@ -13,6 +15,7 @@ import '@storm-software/config/types';
13
15
  import '@stryke/types/configuration';
14
16
  import '@stryke/types/file';
15
17
  import 'vite';
18
+ import '@stryke/fs/resolve';
16
19
  import 'node:fs';
17
20
  import '@stryke/types/array';
18
21
  import '@stryke/types/tsconfig';
@@ -1,10 +1,12 @@
1
- export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-DJ4XjbiZ.cjs';
1
+ export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-CLa0ll-K.cjs';
2
2
  import '@storm-software/unbuild/types';
3
3
  import '@stryke/env/get-env-paths';
4
4
  import '@stryke/types/base';
5
5
  import '@stryke/types/package-json';
6
6
  import 'jiti';
7
+ import 'magic-string';
7
8
  import 'semver';
9
+ import 'ts-morph';
8
10
  import 'unplugin';
9
11
  import '@storm-software/build-tools/types';
10
12
  import '@storm-software/config-tools/types';
@@ -12,6 +14,7 @@ import '@storm-software/config/types';
12
14
  import '@stryke/types/configuration';
13
15
  import '@stryke/types/file';
14
16
  import 'vite';
17
+ import '@stryke/fs/resolve';
15
18
  import 'node:fs';
16
19
  import '@stryke/types/array';
17
20
  import '@stryke/types/tsconfig';
@@ -1,10 +1,12 @@
1
- export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-DJ4XjbiZ.js';
1
+ export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-CLa0ll-K.js';
2
2
  import '@storm-software/unbuild/types';
3
3
  import '@stryke/env/get-env-paths';
4
4
  import '@stryke/types/base';
5
5
  import '@stryke/types/package-json';
6
6
  import 'jiti';
7
+ import 'magic-string';
7
8
  import 'semver';
9
+ import 'ts-morph';
8
10
  import 'unplugin';
9
11
  import '@storm-software/build-tools/types';
10
12
  import '@storm-software/config-tools/types';
@@ -12,6 +14,7 @@ import '@storm-software/config/types';
12
14
  import '@stryke/types/configuration';
13
15
  import '@stryke/types/file';
14
16
  import 'vite';
17
+ import '@stryke/fs/resolve';
15
18
  import 'node:fs';
16
19
  import '@stryke/types/array';
17
20
  import '@stryke/types/tsconfig';
@@ -1,10 +1,12 @@
1
- export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-DJ4XjbiZ.cjs';
1
+ export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-CLa0ll-K.cjs';
2
2
  import '@storm-software/unbuild/types';
3
3
  import '@stryke/env/get-env-paths';
4
4
  import '@stryke/types/base';
5
5
  import '@stryke/types/package-json';
6
6
  import 'jiti';
7
+ import 'magic-string';
7
8
  import 'semver';
9
+ import 'ts-morph';
8
10
  import 'unplugin';
9
11
  import '@storm-software/build-tools/types';
10
12
  import '@storm-software/config-tools/types';
@@ -12,6 +14,7 @@ import '@storm-software/config/types';
12
14
  import '@stryke/types/configuration';
13
15
  import '@stryke/types/file';
14
16
  import 'vite';
17
+ import '@stryke/fs/resolve';
15
18
  import 'node:fs';
16
19
  import '@stryke/types/array';
17
20
  import '@stryke/types/tsconfig';
@@ -1,10 +1,12 @@
1
- export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-DJ4XjbiZ.js';
1
+ export { U as UnbuildPluginContext, a as UnbuildPluginOptions, b as UnbuildPluginResolvedConfig, d as __ΩUnbuildPluginContext, _ as __ΩUnbuildPluginOptions, c as __ΩUnbuildPluginResolvedConfig } from '../index-CLa0ll-K.js';
2
2
  import '@storm-software/unbuild/types';
3
3
  import '@stryke/env/get-env-paths';
4
4
  import '@stryke/types/base';
5
5
  import '@stryke/types/package-json';
6
6
  import 'jiti';
7
+ import 'magic-string';
7
8
  import 'semver';
9
+ import 'ts-morph';
8
10
  import 'unplugin';
9
11
  import '@storm-software/build-tools/types';
10
12
  import '@storm-software/config-tools/types';
@@ -12,6 +14,7 @@ import '@storm-software/config/types';
12
14
  import '@stryke/types/configuration';
13
15
  import '@stryke/types/file';
14
16
  import 'vite';
17
+ import '@stryke/fs/resolve';
15
18
  import 'node:fs';
16
19
  import '@stryke/types/array';
17
20
  import '@stryke/types/tsconfig';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-unbuild",
3
- "version": "0.5.36",
3
+ "version": "0.5.38",
4
4
  "type": "module",
5
5
  "description": "A package containing a Powerlines plugin to build projects using Unbuild.",
6
6
  "repository": {
@@ -128,20 +128,20 @@
128
128
  "keywords": ["unbuild", "powerlines", "storm-software", "powerlines-plugin"],
129
129
  "dependencies": {
130
130
  "@storm-software/unbuild": "^0.57.48",
131
- "@stryke/fs": "^0.32.13",
132
- "@stryke/path": "^0.19.2",
133
- "@stryke/type-checks": "^0.3.12",
134
- "@stryke/types": "^0.10.2",
131
+ "@stryke/fs": "^0.33.0",
132
+ "@stryke/path": "^0.20.0",
133
+ "@stryke/type-checks": "^0.3.15",
134
+ "@stryke/types": "^0.10.5",
135
135
  "defu": "^6.1.4",
136
136
  "jiti": "^2.6.1",
137
- "powerlines": "^0.23.10",
137
+ "powerlines": "^0.24.1",
138
138
  "unplugin": "^2.3.10"
139
139
  },
140
140
  "devDependencies": {
141
- "@powerlines/nx": "^0.10.27",
142
- "@powerlines/plugin-plugin": "^0.11.35",
141
+ "@powerlines/nx": "^0.10.29",
142
+ "@powerlines/plugin-plugin": "^0.11.37",
143
143
  "@types/node": "^24.10.1"
144
144
  },
145
145
  "publishConfig": { "access": "public" },
146
- "gitHead": "5a6b8349dc29bf9e496ed5dee32c6cfb8d9bff4e"
146
+ "gitHead": "424d900c34fbbdf943895648419a6467d8eb4a8d"
147
147
  }