@powerlines/plugin-unimport 0.1.124 → 0.1.126

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.
Files changed (40) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  2. package/dist/index.cjs +2 -30
  3. package/dist/index.d.cts +2 -2
  4. package/dist/index.d.mts +3 -2
  5. package/dist/index.mjs +0 -2
  6. package/dist/powerlines/src/types/babel.d.mts +2 -0
  7. package/dist/powerlines/src/types/build.d.cts +145 -0
  8. package/dist/powerlines/src/types/build.d.mts +145 -0
  9. package/dist/powerlines/src/types/commands.d.cts +8 -0
  10. package/dist/powerlines/src/types/commands.d.mts +9 -0
  11. package/dist/powerlines/src/types/config.d.cts +376 -0
  12. package/dist/powerlines/src/types/config.d.mts +376 -0
  13. package/dist/powerlines/src/types/context.d.cts +404 -0
  14. package/dist/powerlines/src/types/context.d.mts +406 -0
  15. package/dist/powerlines/src/types/fs.d.cts +486 -0
  16. package/dist/powerlines/src/types/fs.d.mts +486 -0
  17. package/dist/powerlines/src/types/hooks.d.mts +2 -0
  18. package/dist/powerlines/src/types/plugin.d.cts +231 -0
  19. package/dist/powerlines/src/types/plugin.d.mts +231 -0
  20. package/dist/powerlines/src/types/resolved.d.cts +81 -0
  21. package/dist/powerlines/src/types/resolved.d.mts +81 -0
  22. package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
  23. package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
  24. package/dist/types/index.cjs +0 -2
  25. package/dist/types/index.d.cts +1 -2
  26. package/dist/types/index.d.mts +1 -2
  27. package/dist/types/index.mjs +0 -3
  28. package/dist/types/plugin.cjs +0 -1
  29. package/dist/types/plugin.d.cts +39 -1
  30. package/dist/types/plugin.d.mts +39 -1
  31. package/dist/types/plugin.mjs +0 -2
  32. package/package.json +5 -5
  33. package/dist/index-BgAdqTbb.d.mts +0 -1
  34. package/dist/index-CEgs-Dz2.d.cts +0 -1
  35. package/dist/plugin-Bd14rstC.d.cts +0 -1791
  36. package/dist/plugin-C3MaN5jp.mjs +0 -1
  37. package/dist/plugin-CcOjUruZ.d.mts +0 -1791
  38. package/dist/plugin-DHXHjv16.cjs +0 -0
  39. package/dist/types-CTUnla4x.mjs +0 -1
  40. package/dist/types-DHkg7xmX.cjs +0 -0
@@ -0,0 +1,404 @@
1
+ import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.cjs";
2
+ import { ParsedTypeScriptConfig } from "./tsconfig.cjs";
3
+ import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.cjs";
4
+ import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.cjs";
5
+ import { NonUndefined } from "@stryke/types/base";
6
+ import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
7
+ import { EnvPaths } from "@stryke/env/get-env-paths";
8
+ import { FetchRequestOptions } from "@stryke/http/fetch";
9
+ import { PackageJson } from "@stryke/types/package-json";
10
+ import { Jiti } from "jiti";
11
+ import { SourceMap } from "magic-string";
12
+ import { ParseResult, ParserOptions } from "oxc-parser";
13
+ import { Range } from "semver";
14
+ import { Project } from "ts-morph";
15
+ import { RequestInfo, Response } from "undici";
16
+ import { Unimport } from "unimport";
17
+
18
+ //#region ../powerlines/src/types/context.d.ts
19
+
20
+ interface MetaInfo {
21
+ /**
22
+ * The checksum generated from the resolved options
23
+ */
24
+ checksum: string;
25
+ /**
26
+ * The build id
27
+ */
28
+ buildId: string;
29
+ /**
30
+ * The release id
31
+ */
32
+ releaseId: string;
33
+ /**
34
+ * The build timestamp
35
+ */
36
+ timestamp: number;
37
+ /**
38
+ * A hash that represents the path to the project root directory
39
+ */
40
+ projectRootHash: string;
41
+ /**
42
+ * A hash that represents the path to the project root directory
43
+ */
44
+ configHash: string;
45
+ }
46
+ interface Resolver extends Jiti {
47
+ plugin: Jiti;
48
+ }
49
+ interface TransformResult$1 {
50
+ code: string;
51
+ map: SourceMap | null;
52
+ }
53
+ /**
54
+ * Options for initializing or updating the context with new configuration values
55
+ */
56
+ interface InitContextOptions {
57
+ /**
58
+ * If false, the plugin will be loaded after all other plugins.
59
+ *
60
+ * @defaultValue true
61
+ */
62
+ isHighPriority: boolean;
63
+ }
64
+ /**
65
+ * Options for fetch requests made via the context's {@link Context.fetch} method
66
+ */
67
+ interface FetchOptions extends FetchRequestOptions {
68
+ /**
69
+ * An indicator specifying that the request should bypass any caching
70
+ */
71
+ skipCache?: boolean;
72
+ }
73
+ /**
74
+ * Options for parsing code using [Oxc-Parser](https://github.com/oxc/oxc)
75
+ */
76
+ interface ParseOptions extends ParserOptions {
77
+ /**
78
+ * When true this allows return statements to be outside functions to e.g. support parsing CommonJS code.
79
+ */
80
+ allowReturnOutsideFunction?: boolean;
81
+ }
82
+ interface EmitOptions extends WriteOptions {
83
+ /**
84
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
85
+ */
86
+ emitWithBundler?: boolean;
87
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
88
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
89
+ }
90
+ /**
91
+ * Options for emitting entry virtual files
92
+ */
93
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
94
+ /**
95
+ * The unresolved Powerlines context.
96
+ *
97
+ * @remarks
98
+ * This context is used before the user configuration has been fully resolved after the `config`.
99
+ */
100
+ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
101
+ /**
102
+ * The Storm workspace configuration
103
+ */
104
+ workspaceConfig: WorkspaceConfig;
105
+ /**
106
+ * An object containing the options provided to Powerlines
107
+ */
108
+ config: Omit<TResolvedConfig["userConfig"], "build" | "output"> & Required<Pick<TResolvedConfig["userConfig"], "build" | "output">> & {
109
+ projectRoot: NonUndefined<TResolvedConfig["userConfig"]["root"]>;
110
+ sourceRoot: NonUndefined<TResolvedConfig["userConfig"]["sourceRoot"]>;
111
+ output: TResolvedConfig["output"];
112
+ };
113
+ /**
114
+ * A logging function for the Powerlines engine
115
+ */
116
+ log: LogFn;
117
+ /**
118
+ * A logging function for fatal messages
119
+ */
120
+ fatal: (message: string | UnpluginMessage) => void;
121
+ /**
122
+ * A logging function for error messages
123
+ */
124
+ error: (message: string | UnpluginMessage) => void;
125
+ /**
126
+ * A logging function for warning messages
127
+ */
128
+ warn: (message: string | UnpluginMessage) => void;
129
+ /**
130
+ * A logging function for informational messages
131
+ */
132
+ info: (message: string | UnpluginMessage) => void;
133
+ /**
134
+ * A logging function for debug messages
135
+ */
136
+ debug: (message: string | UnpluginMessage) => void;
137
+ /**
138
+ * A logging function for trace messages
139
+ */
140
+ trace: (message: string | UnpluginMessage) => void;
141
+ /**
142
+ * The metadata information
143
+ */
144
+ meta: MetaInfo;
145
+ /**
146
+ * The metadata information currently written to disk
147
+ */
148
+ persistedMeta?: MetaInfo;
149
+ /**
150
+ * The Powerlines artifacts directory
151
+ */
152
+ artifactsPath: string;
153
+ /**
154
+ * The path to the Powerlines builtin runtime modules directory
155
+ */
156
+ builtinsPath: string;
157
+ /**
158
+ * The path to the Powerlines entry modules directory
159
+ */
160
+ entryPath: string;
161
+ /**
162
+ * The path to the Powerlines TypeScript declaration files directory
163
+ */
164
+ dtsPath: string;
165
+ /**
166
+ * The path to a directory where the reflection data buffers (used by the build processes) are stored
167
+ */
168
+ dataPath: string;
169
+ /**
170
+ * The path to a directory where the project cache (used by the build processes) is stored
171
+ */
172
+ cachePath: string;
173
+ /**
174
+ * The Powerlines environment paths
175
+ */
176
+ envPaths: EnvPaths;
177
+ /**
178
+ * The file system path to the Powerlines package installation
179
+ */
180
+ powerlinesPath: string;
181
+ /**
182
+ * The relative path to the Powerlines workspace root directory
183
+ */
184
+ relativeToWorkspaceRoot: string;
185
+ /**
186
+ * The project's `package.json` file content
187
+ */
188
+ packageJson: PackageJson & Record<string, any>;
189
+ /**
190
+ * The project's `project.json` file content
191
+ */
192
+ projectJson?: Record<string, any>;
193
+ /**
194
+ * The dependency installations required by the project
195
+ */
196
+ dependencies: Record<string, string | Range>;
197
+ /**
198
+ * The development dependency installations required by the project
199
+ */
200
+ devDependencies: Record<string, string | Range>;
201
+ /**
202
+ * The parsed TypeScript configuration from the `tsconfig.json` file
203
+ */
204
+ tsconfig: ParsedTypeScriptConfig;
205
+ /**
206
+ * The entry points of the source code
207
+ */
208
+ entry: ResolvedEntryTypeDefinition[];
209
+ /**
210
+ * The virtual file system manager used during the build process to reference generated runtime files
211
+ */
212
+ fs: VirtualFileSystemInterface;
213
+ /**
214
+ * The Jiti module resolver
215
+ */
216
+ resolver: Resolver;
217
+ /**
218
+ * The builtin module id that exist in the Powerlines virtual file system
219
+ */
220
+ builtins: string[];
221
+ /**
222
+ * The {@link Project} instance used for type reflection and module manipulation
223
+ *
224
+ * @see https://ts-morph.com/
225
+ *
226
+ * @remarks
227
+ * This instance is created lazily on first access.
228
+ */
229
+ program: Project;
230
+ /**
231
+ * A function to perform HTTP fetch requests
232
+ *
233
+ * @remarks
234
+ * This function uses a caching layer to avoid duplicate requests during the Powerlines process.
235
+ *
236
+ * @example
237
+ * ```ts
238
+ * const response = await context.fetch("https://api.example.com/data");
239
+ * const data = await response.json();
240
+ * ```
241
+ *
242
+ * @see https://github.com/nodejs/undici
243
+ *
244
+ * @param input - The URL to fetch.
245
+ * @param options - The fetch request options.
246
+ * @returns A promise that resolves to a response returned by the fetch.
247
+ */
248
+ fetch: (input: RequestInfo, options?: FetchOptions) => Promise<Response>;
249
+ /**
250
+ * Parse code using [Oxc-Parser](https://github.com/oxc/oxc) into an (ESTree-compatible)[https://github.com/estree/estree] AST object.
251
+ *
252
+ * @remarks
253
+ * This function can be used to parse TypeScript code into an AST for further analysis or transformation.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const ast = context.parse("const x: number = 42;");
258
+ * ```
259
+ *
260
+ * @see https://rollupjs.org/plugin-development/#this-parse
261
+ * @see https://github.com/oxc/oxc
262
+ *
263
+ * @param code - The source code to parse.
264
+ * @param options - The options to pass to the parser.
265
+ * @returns An (ESTree-compatible)[https://github.com/estree/estree] AST object.
266
+ */
267
+ parse: (code: string, options?: ParseOptions) => Promise<ParseResult>;
268
+ /**
269
+ * A helper function to resolve modules using the Jiti resolver
270
+ *
271
+ * @remarks
272
+ * This function can be used to resolve modules relative to the project root directory.
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
277
+ * ```
278
+ *
279
+ * @param id - The module to resolve.
280
+ * @param importer - An optional path to the importer module.
281
+ * @param options - Additional resolution options.
282
+ * @returns A promise that resolves to the resolved module path.
283
+ */
284
+ resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<ExternalIdResult | undefined>;
285
+ /**
286
+ * A helper function to load modules using the Jiti resolver
287
+ *
288
+ * @remarks
289
+ * This function can be used to load modules relative to the project root directory.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * const module = await context.load("some-module", "/path/to/importer");
294
+ * ```
295
+ *
296
+ * @param id - The module to load.
297
+ * @returns A promise that resolves to the loaded module.
298
+ */
299
+ load: (id: string) => Promise<TransformResult$1 | undefined>;
300
+ /**
301
+ * The Powerlines builtin virtual files
302
+ */
303
+ getBuiltins: () => Promise<VirtualFile[]>;
304
+ /**
305
+ * Resolves a file and writes it to the VFS if it does not already exist
306
+ *
307
+ * @param code - The source code of the file
308
+ * @param path - The path to write the file to
309
+ * @param options - Additional options for writing the file
310
+ */
311
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
312
+ /**
313
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
314
+ *
315
+ * @param code - The source code of the file
316
+ * @param path - The path to write the file to
317
+ * @param options - Additional options for writing the file
318
+ */
319
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
320
+ /**
321
+ * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
322
+ *
323
+ * @param code - The source code of the builtin file
324
+ * @param id - The unique identifier of the builtin file
325
+ * @param path - An optional path to write the builtin file to
326
+ * @param options - Additional options for writing the builtin file
327
+ */
328
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
329
+ /**
330
+ * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
331
+ *
332
+ * @param code - The source code of the builtin file
333
+ * @param id - The unique identifier of the builtin file
334
+ * @param path - An optional path to write the builtin file to
335
+ * @param options - Additional options for writing the builtin file
336
+ */
337
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
338
+ /**
339
+ * Resolves a entry virtual file and writes it to the VFS if it does not already exist
340
+ *
341
+ * @param code - The source code of the entry file
342
+ * @param path - An optional path to write the entry file to
343
+ * @param options - Additional options for writing the entry file
344
+ */
345
+ emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
346
+ /**
347
+ * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
348
+ *
349
+ * @param code - The source code of the entry file
350
+ * @param path - An optional path to write the entry file to
351
+ * @param options - Additional options for writing the entry file
352
+ */
353
+ emitEntrySync: (code: string, path: string, options?: EmitEntryOptions) => void;
354
+ /**
355
+ * A function to update the context fields using a new user configuration options
356
+ */
357
+ withUserConfig: (userConfig: UserConfig, options?: InitContextOptions) => Promise<void>;
358
+ /**
359
+ * A function to update the context fields using inline configuration options
360
+ */
361
+ withInlineConfig: (inlineConfig: InlineConfig, options?: InitContextOptions) => Promise<void>;
362
+ /**
363
+ * Create a new logger instance
364
+ *
365
+ * @param name - The name to use for the logger instance
366
+ * @returns A logger function
367
+ */
368
+ createLog: (name: string | null) => LogFn;
369
+ /**
370
+ * Extend the current logger instance with a new name
371
+ *
372
+ * @param name - The name to use for the extended logger instance
373
+ * @returns A logger function
374
+ */
375
+ extendLog: (name: string) => LogFn;
376
+ /**
377
+ * Generates a checksum representing the current context state
378
+ *
379
+ * @returns A promise that resolves to a string representing the checksum
380
+ */
381
+ generateChecksum: () => Promise<string>;
382
+ }
383
+ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<UnresolvedContext<TResolvedConfig>, "config"> & {
384
+ /**
385
+ * The fully resolved Powerlines configuration
386
+ */
387
+ config: TResolvedConfig;
388
+ };
389
+ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
390
+ /**
391
+ * The environment specific resolved configuration
392
+ */
393
+ environment: EnvironmentResolvedConfig;
394
+ /**
395
+ * An alternative property name for the {@link log} property
396
+ *
397
+ * @remarks
398
+ * This is provided for compatibility with other logging libraries that expect a `logger` property.
399
+ */
400
+ logger: LogFn;
401
+ }
402
+ type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
403
+ //#endregion
404
+ export { BuildPluginContext, PluginContext, UnresolvedContext };