@powerlines/plugin-unimport 0.1.123 → 0.1.125

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