@powerlines/plugin-oxc-transform 0.5.66 → 0.5.68
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/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/powerlines/src/types/build.d.cts +139 -0
- package/dist/powerlines/src/types/build.d.mts +139 -0
- package/dist/powerlines/src/types/commands.d.cts +8 -0
- package/dist/powerlines/src/types/commands.d.mts +8 -0
- package/dist/powerlines/src/types/config.d.cts +345 -0
- package/dist/powerlines/src/types/config.d.mts +345 -0
- package/dist/powerlines/src/types/context.d.cts +347 -0
- package/dist/powerlines/src/types/context.d.mts +347 -0
- package/dist/powerlines/src/types/fs.d.cts +458 -0
- package/dist/powerlines/src/types/fs.d.mts +458 -0
- package/dist/powerlines/src/types/plugin.d.cts +232 -0
- package/dist/powerlines/src/types/plugin.d.mts +232 -0
- package/dist/powerlines/src/types/resolved.d.cts +81 -0
- package/dist/powerlines/src/types/resolved.d.mts +81 -0
- package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
- package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
- package/dist/types/index.cjs +0 -1
- package/dist/types/index.d.cts +1 -2
- package/dist/types/index.d.mts +1 -2
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.d.cts +23 -1
- package/dist/types/plugin.d.mts +23 -1
- package/dist/types/plugin.mjs +1 -1
- package/package.json +6 -6
- package/dist/index-BgAdqTbb.d.mts +0 -1
- package/dist/index-CEgs-Dz2.d.cts +0 -1
- package/dist/plugin-B35rxU7P.d.mts +0 -1658
- package/dist/plugin-Bvn-he2n.mjs +0 -1
- package/dist/plugin-DHXHjv16.cjs +0 -0
- package/dist/plugin-OhO2G9mw.d.cts +0 -1658
- package/dist/types-B7VYa_Pp.mjs +0 -1
- package/dist/types-DHkg7xmX.cjs +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { BuildConfig, BuildResolvedConfig } from "./build.mjs";
|
|
2
|
+
import { StoragePort, StoragePreset } from "./fs.mjs";
|
|
3
|
+
import { TSConfig } from "./tsconfig.mjs";
|
|
4
|
+
import { PluginContext } from "./context.mjs";
|
|
5
|
+
import { Plugin } from "./plugin.mjs";
|
|
6
|
+
import { MaybePromise } from "@stryke/types/base";
|
|
7
|
+
import { PreviewOptions } from "vite";
|
|
8
|
+
import { Format } from "@storm-software/build-tools/types";
|
|
9
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
10
|
+
import { StormWorkspaceConfig } from "@storm-software/config/types";
|
|
11
|
+
import { TypeDefinitionParameter } from "@stryke/types/configuration";
|
|
12
|
+
import { AssetGlob } from "@stryke/types/file";
|
|
13
|
+
|
|
14
|
+
//#region ../powerlines/src/types/config.d.ts
|
|
15
|
+
|
|
16
|
+
type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
|
|
17
|
+
/**
|
|
18
|
+
* The {@link StormWorkspaceConfig | configuration} object for an entire Powerlines workspace
|
|
19
|
+
*/
|
|
20
|
+
type WorkspaceConfig = Partial<StormWorkspaceConfig> & Required<Pick<StormWorkspaceConfig, "workspaceRoot">>;
|
|
21
|
+
type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext>>;
|
|
22
|
+
/**
|
|
23
|
+
* A configuration tuple for a Powerlines plugin.
|
|
24
|
+
*/
|
|
25
|
+
type PluginConfigTuple<TContext extends PluginContext = PluginContext, TOptions = any> = [string | PluginFactory<TContext, TOptions>, TOptions] | [Plugin<TContext>];
|
|
26
|
+
/**
|
|
27
|
+
* A configuration object for a Powerlines plugin.
|
|
28
|
+
*/
|
|
29
|
+
type PluginConfigObject<TContext extends PluginContext = PluginContext, TOptions = any> = {
|
|
30
|
+
plugin: string | PluginFactory<TContext, TOptions>;
|
|
31
|
+
options: TOptions;
|
|
32
|
+
} | {
|
|
33
|
+
plugin: Plugin<TContext>;
|
|
34
|
+
options?: never;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A configuration tuple for a Powerlines plugin.
|
|
38
|
+
*/
|
|
39
|
+
type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Promise<Plugin<TContext>> | PluginConfigTuple<TContext> | PluginConfigObject<TContext>;
|
|
40
|
+
type ProjectType = "application" | "library";
|
|
41
|
+
interface DeployConfig {
|
|
42
|
+
/**
|
|
43
|
+
* The deployment variant being used by the Powerlines engine.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* export default defineConfig({
|
|
48
|
+
* deploy: {
|
|
49
|
+
* variant: "cloudflare"
|
|
50
|
+
* }
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
variant?: string;
|
|
56
|
+
}
|
|
57
|
+
interface OutputConfig {
|
|
58
|
+
/**
|
|
59
|
+
* The path to output the final compiled files to
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* If a value is not provided, Powerlines will attempt to:
|
|
63
|
+
* 1. Use the `outDir` value in the `tsconfig.json` file.
|
|
64
|
+
* 2. Use the `dist` directory in the project root directory.
|
|
65
|
+
*
|
|
66
|
+
* @defaultValue "dist/\{projectRoot\}"
|
|
67
|
+
*/
|
|
68
|
+
outputPath?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The output directory path for the project build.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* This path is used to determine where the built files will be placed after the build process completes. This will be used in scenarios where the monorepo uses TSConfig paths to link packages together.
|
|
74
|
+
*
|
|
75
|
+
* @defaultValue "\{projectRoot\}/dist"
|
|
76
|
+
*/
|
|
77
|
+
buildPath?: string;
|
|
78
|
+
/**
|
|
79
|
+
* The folder where the generated runtime artifacts will be located
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* This folder will contain all runtime artifacts and builtins generated during the "prepare" phase.
|
|
83
|
+
*
|
|
84
|
+
* @defaultValue "\{projectRoot\}/.powerlines"
|
|
85
|
+
*/
|
|
86
|
+
artifactsPath?: string;
|
|
87
|
+
/**
|
|
88
|
+
* The path of the generated runtime declaration file relative to the workspace root.
|
|
89
|
+
*
|
|
90
|
+
* @defaultValue "\{projectRoot\}/powerlines.d.ts"
|
|
91
|
+
*/
|
|
92
|
+
dts?: string | false;
|
|
93
|
+
/**
|
|
94
|
+
* A prefix to use for identifying builtin modules
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* This prefix will be used to identify all builtin modules generated during the "prepare" phase. An example builtin ID for a module called `"utils"` would be `"{builtinPrefix}:utils"`.
|
|
98
|
+
*
|
|
99
|
+
* @defaultValue "powerlines"
|
|
100
|
+
*/
|
|
101
|
+
builtinPrefix?: string;
|
|
102
|
+
/**
|
|
103
|
+
* The module format of the output files
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* This option can be a single format or an array of formats. If an array is provided, multiple builds will be generated for each format.
|
|
107
|
+
*
|
|
108
|
+
* @defaultValue "esm"
|
|
109
|
+
*/
|
|
110
|
+
format?: Format | Format[];
|
|
111
|
+
/**
|
|
112
|
+
* A list of assets to copy to the output directory
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* The assets can be specified as a string (path to the asset) or as an object with a `glob` property (to match multiple files). The paths are relative to the project root directory.
|
|
116
|
+
*/
|
|
117
|
+
assets?: Array<string | AssetGlob>;
|
|
118
|
+
/**
|
|
119
|
+
* A string preset or a custom {@link StoragePort} to provide fine-grained control over generated/output file storage.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* If a string preset is provided, it must be one of the following values:
|
|
123
|
+
* - `"virtual"`: Uses the local file system for storage.
|
|
124
|
+
* - `"fs"`: Uses an in-memory virtual file system for storage.
|
|
125
|
+
*
|
|
126
|
+
* If a custom {@link StoragePort} is provided, it will be used for all file storage operations during the build process.
|
|
127
|
+
*
|
|
128
|
+
* @defaultValue "virtual"
|
|
129
|
+
*/
|
|
130
|
+
storage?: StoragePort | StoragePreset;
|
|
131
|
+
}
|
|
132
|
+
interface BaseConfig {
|
|
133
|
+
/**
|
|
134
|
+
* The entry point(s) for the application
|
|
135
|
+
*/
|
|
136
|
+
entry?: TypeDefinitionParameter | TypeDefinitionParameter[];
|
|
137
|
+
/**
|
|
138
|
+
* Configuration for the output of the build process
|
|
139
|
+
*/
|
|
140
|
+
output?: OutputConfig;
|
|
141
|
+
/**
|
|
142
|
+
* Configuration for cleaning the build artifacts
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* If set to `false`, the cleaning process will be disabled.
|
|
146
|
+
*/
|
|
147
|
+
clean?: Record<string, any> | false;
|
|
148
|
+
/**
|
|
149
|
+
* Configuration for linting the source code
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* If set to `false`, linting will be disabled.
|
|
153
|
+
*/
|
|
154
|
+
lint?: Record<string, any> | false;
|
|
155
|
+
/**
|
|
156
|
+
* Configuration for testing the source code
|
|
157
|
+
*
|
|
158
|
+
* @remarks
|
|
159
|
+
* If set to `false`, testing will be disabled.
|
|
160
|
+
*/
|
|
161
|
+
test?: Record<string, any> | false;
|
|
162
|
+
/**
|
|
163
|
+
* Configuration for the transformation of the source code
|
|
164
|
+
*/
|
|
165
|
+
transform?: Record<string, any>;
|
|
166
|
+
/**
|
|
167
|
+
* Configuration provided to build processes
|
|
168
|
+
*
|
|
169
|
+
* @remarks
|
|
170
|
+
* This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuildVariant | build variant}.
|
|
171
|
+
*/
|
|
172
|
+
build?: BuildConfig;
|
|
173
|
+
/**
|
|
174
|
+
* Configuration for documentation generation
|
|
175
|
+
*
|
|
176
|
+
* @remarks
|
|
177
|
+
* This configuration will be used by the documentation generation plugins during the `docs` command.
|
|
178
|
+
*/
|
|
179
|
+
docs?: Record<string, any>;
|
|
180
|
+
/**
|
|
181
|
+
* Configuration for deploying the source code
|
|
182
|
+
*
|
|
183
|
+
* @remarks
|
|
184
|
+
* If set to `false`, the deployment will be disabled.
|
|
185
|
+
*/
|
|
186
|
+
deploy?: DeployConfig | false;
|
|
187
|
+
/**
|
|
188
|
+
* The path to the tsconfig file to be used by the compiler
|
|
189
|
+
*
|
|
190
|
+
* @remarks
|
|
191
|
+
* If a value is not provided, the plugin will attempt to find the `tsconfig.json` file in the project root directory. The parsed tsconfig compiler options will be merged with the {@link Options.tsconfigRaw} value (if provided).
|
|
192
|
+
*
|
|
193
|
+
* @defaultValue "\{projectRoot\}/tsconfig.json"
|
|
194
|
+
*/
|
|
195
|
+
tsconfig?: string;
|
|
196
|
+
/**
|
|
197
|
+
* The raw {@link TSConfig} object to be used by the compiler. This object will be merged with the `tsconfig.json` file.
|
|
198
|
+
*
|
|
199
|
+
* @see https://www.typescriptlang.org/tsconfig
|
|
200
|
+
*
|
|
201
|
+
* @remarks
|
|
202
|
+
* If populated, this option takes higher priority than `tsconfig`
|
|
203
|
+
*/
|
|
204
|
+
tsconfigRaw?: TSConfig;
|
|
205
|
+
}
|
|
206
|
+
interface EnvironmentConfig extends BaseConfig {
|
|
207
|
+
/**
|
|
208
|
+
* Configuration options for the preview server
|
|
209
|
+
*/
|
|
210
|
+
preview?: PreviewOptions;
|
|
211
|
+
/**
|
|
212
|
+
* A flag indicating whether the build is for a Server-Side Rendering environment.
|
|
213
|
+
*/
|
|
214
|
+
ssr?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Define if this environment is used for Server-Side Rendering
|
|
217
|
+
*
|
|
218
|
+
* @defaultValue "server" (if it isn't the client environment)
|
|
219
|
+
*/
|
|
220
|
+
consumer?: "client" | "server";
|
|
221
|
+
}
|
|
222
|
+
interface CommonUserConfig extends BaseConfig {
|
|
223
|
+
/**
|
|
224
|
+
* The name of the project
|
|
225
|
+
*/
|
|
226
|
+
name?: string;
|
|
227
|
+
/**
|
|
228
|
+
* The project display title
|
|
229
|
+
*
|
|
230
|
+
* @remarks
|
|
231
|
+
* This option is used in documentation generation and other places where a human-readable title is needed.
|
|
232
|
+
*/
|
|
233
|
+
title?: string;
|
|
234
|
+
/**
|
|
235
|
+
* A description of the project
|
|
236
|
+
*
|
|
237
|
+
* @remarks
|
|
238
|
+
* If this option is not provided, the build process will try to use the \`description\` value from the `\package.json\` file.
|
|
239
|
+
*/
|
|
240
|
+
description?: string;
|
|
241
|
+
/**
|
|
242
|
+
* The log level to use for the Powerlines processes.
|
|
243
|
+
*
|
|
244
|
+
* @defaultValue "info"
|
|
245
|
+
*/
|
|
246
|
+
logLevel?: LogLevelLabel | null;
|
|
247
|
+
/**
|
|
248
|
+
* A custom logger function to use for logging messages
|
|
249
|
+
*/
|
|
250
|
+
customLogger?: LogFn;
|
|
251
|
+
/**
|
|
252
|
+
* Explicitly set a mode to run in. This mode will be used at various points throughout the Powerlines processes, such as when compiling the source code.
|
|
253
|
+
*
|
|
254
|
+
* @defaultValue "production"
|
|
255
|
+
*/
|
|
256
|
+
mode?: "development" | "test" | "production";
|
|
257
|
+
/**
|
|
258
|
+
* The type of project being built
|
|
259
|
+
*
|
|
260
|
+
* @defaultValue "application"
|
|
261
|
+
*/
|
|
262
|
+
type?: ProjectType;
|
|
263
|
+
/**
|
|
264
|
+
* The root directory of the project
|
|
265
|
+
*/
|
|
266
|
+
root: string;
|
|
267
|
+
/**
|
|
268
|
+
* The root directory of the project's source code
|
|
269
|
+
*
|
|
270
|
+
* @defaultValue "\{root\}/src"
|
|
271
|
+
*/
|
|
272
|
+
sourceRoot?: string;
|
|
273
|
+
/**
|
|
274
|
+
* A path to a custom configuration file to be used instead of the default `storm.json`, `powerlines.config.js`, or `powerlines.config.ts` files.
|
|
275
|
+
*
|
|
276
|
+
* @remarks
|
|
277
|
+
* This option is useful for running Powerlines commands with different configuration files, such as in CI/CD environments or when testing different configurations.
|
|
278
|
+
*/
|
|
279
|
+
configFile?: string;
|
|
280
|
+
/**
|
|
281
|
+
* Should the Powerlines CLI processes skip installing missing packages?
|
|
282
|
+
*
|
|
283
|
+
* @remarks
|
|
284
|
+
* This option is useful for CI/CD environments where the installation of packages is handled by a different process.
|
|
285
|
+
*
|
|
286
|
+
* @defaultValue false
|
|
287
|
+
*/
|
|
288
|
+
skipInstalls?: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* Should the compiler processes skip any improvements that make use of cache?
|
|
291
|
+
*
|
|
292
|
+
* @defaultValue false
|
|
293
|
+
*/
|
|
294
|
+
skipCache?: boolean;
|
|
295
|
+
/**
|
|
296
|
+
* A list of resolvable paths to plugins used during the build process
|
|
297
|
+
*/
|
|
298
|
+
plugins?: PluginConfig<PluginContext<any>>[];
|
|
299
|
+
/**
|
|
300
|
+
* Environment-specific configurations
|
|
301
|
+
*/
|
|
302
|
+
environments?: Record<string, EnvironmentConfig>;
|
|
303
|
+
/**
|
|
304
|
+
* A string identifier that allows a child framework or tool to identify itself when using Powerlines.
|
|
305
|
+
*
|
|
306
|
+
* @remarks
|
|
307
|
+
* If no values are provided for {@link OutputConfig.dts | output.dts}, {@link OutputConfig.builtinPrefix | output.builtinPrefix}, or {@link OutputConfig.artifactsPath | output.artifactsFolder}, this value will be used as the default.
|
|
308
|
+
*
|
|
309
|
+
* @defaultValue "powerlines"
|
|
310
|
+
*/
|
|
311
|
+
framework?: string;
|
|
312
|
+
}
|
|
313
|
+
interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
|
|
314
|
+
/**
|
|
315
|
+
* Configuration provided to build processes
|
|
316
|
+
*
|
|
317
|
+
* @remarks
|
|
318
|
+
* This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuildVariant | build variant}.
|
|
319
|
+
*/
|
|
320
|
+
build: Omit<TBuildConfig, "override"> & {
|
|
321
|
+
/**
|
|
322
|
+
* The build variant being used by the Powerlines engine.
|
|
323
|
+
*/
|
|
324
|
+
variant?: TBuildVariant;
|
|
325
|
+
/**
|
|
326
|
+
* An optional set of override options to apply to the selected build variant.
|
|
327
|
+
*
|
|
328
|
+
* @remarks
|
|
329
|
+
* This option allows you to provide configuration options with the guarantee that they will **not** be overridden and will take precedence over other build configurations.
|
|
330
|
+
*/
|
|
331
|
+
override?: Partial<TBuildResolvedConfig>;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
|
|
335
|
+
/**
|
|
336
|
+
* The configuration provided while executing Powerlines commands.
|
|
337
|
+
*/
|
|
338
|
+
type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
|
|
339
|
+
/**
|
|
340
|
+
* A string identifier for the Powerlines command being executed
|
|
341
|
+
*/
|
|
342
|
+
command: PowerlinesCommand;
|
|
343
|
+
};
|
|
344
|
+
//#endregion
|
|
345
|
+
export { EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig, WorkspaceConfig };
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { ResolveOptions, VirtualFile, VirtualFileSystemInterface } 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
|
+
|
|
17
|
+
//#region ../powerlines/src/types/context.d.ts
|
|
18
|
+
|
|
19
|
+
interface MetaInfo {
|
|
20
|
+
/**
|
|
21
|
+
* The checksum generated from the resolved options
|
|
22
|
+
*/
|
|
23
|
+
checksum: string;
|
|
24
|
+
/**
|
|
25
|
+
* The build id
|
|
26
|
+
*/
|
|
27
|
+
buildId: string;
|
|
28
|
+
/**
|
|
29
|
+
* The release id
|
|
30
|
+
*/
|
|
31
|
+
releaseId: string;
|
|
32
|
+
/**
|
|
33
|
+
* The build timestamp
|
|
34
|
+
*/
|
|
35
|
+
timestamp: number;
|
|
36
|
+
/**
|
|
37
|
+
* A hash that represents the path to the project root directory
|
|
38
|
+
*/
|
|
39
|
+
projectRootHash: string;
|
|
40
|
+
/**
|
|
41
|
+
* A hash that represents the path to the project root directory
|
|
42
|
+
*/
|
|
43
|
+
configHash: string;
|
|
44
|
+
}
|
|
45
|
+
interface Resolver extends Jiti {
|
|
46
|
+
plugin: Jiti;
|
|
47
|
+
}
|
|
48
|
+
interface TransformResult$1 {
|
|
49
|
+
code: string;
|
|
50
|
+
map: SourceMap | null;
|
|
51
|
+
}
|
|
52
|
+
interface InitContextOptions {
|
|
53
|
+
/**
|
|
54
|
+
* If false, the plugin will be loaded after all other plugins.
|
|
55
|
+
*
|
|
56
|
+
* @defaultValue true
|
|
57
|
+
*/
|
|
58
|
+
isHighPriority: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface FetchOptions extends FetchRequestOptions {
|
|
61
|
+
/**
|
|
62
|
+
* An indicator specifying that the request should bypass any caching
|
|
63
|
+
*/
|
|
64
|
+
skipCache?: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface ParseOptions extends ParserOptions {
|
|
67
|
+
/**
|
|
68
|
+
* When true this allows return statements to be outside functions to e.g. support parsing CommonJS code.
|
|
69
|
+
*/
|
|
70
|
+
allowReturnOutsideFunction?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The unresolved Powerlines context.
|
|
74
|
+
*
|
|
75
|
+
* @remarks
|
|
76
|
+
* This context is used before the user configuration has been fully resolved after the `config`.
|
|
77
|
+
*/
|
|
78
|
+
interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
|
|
79
|
+
/**
|
|
80
|
+
* The Storm workspace configuration
|
|
81
|
+
*/
|
|
82
|
+
workspaceConfig: WorkspaceConfig;
|
|
83
|
+
/**
|
|
84
|
+
* An object containing the options provided to Powerlines
|
|
85
|
+
*/
|
|
86
|
+
config: Omit<TResolvedConfig["userConfig"], "build" | "output"> & Required<Pick<TResolvedConfig["userConfig"], "build" | "output">> & {
|
|
87
|
+
projectRoot: NonUndefined<TResolvedConfig["userConfig"]["root"]>;
|
|
88
|
+
sourceRoot: NonUndefined<TResolvedConfig["userConfig"]["sourceRoot"]>;
|
|
89
|
+
output: TResolvedConfig["output"];
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A logging function for the Powerlines engine
|
|
93
|
+
*/
|
|
94
|
+
log: LogFn;
|
|
95
|
+
/**
|
|
96
|
+
* A logging function for fatal messages
|
|
97
|
+
*/
|
|
98
|
+
fatal: (message: string | UnpluginMessage) => void;
|
|
99
|
+
/**
|
|
100
|
+
* A logging function for error messages
|
|
101
|
+
*/
|
|
102
|
+
error: (message: string | UnpluginMessage) => void;
|
|
103
|
+
/**
|
|
104
|
+
* A logging function for warning messages
|
|
105
|
+
*/
|
|
106
|
+
warn: (message: string | UnpluginMessage) => void;
|
|
107
|
+
/**
|
|
108
|
+
* A logging function for informational messages
|
|
109
|
+
*/
|
|
110
|
+
info: (message: string | UnpluginMessage) => void;
|
|
111
|
+
/**
|
|
112
|
+
* A logging function for debug messages
|
|
113
|
+
*/
|
|
114
|
+
debug: (message: string | UnpluginMessage) => void;
|
|
115
|
+
/**
|
|
116
|
+
* A logging function for trace messages
|
|
117
|
+
*/
|
|
118
|
+
trace: (message: string | UnpluginMessage) => void;
|
|
119
|
+
/**
|
|
120
|
+
* The metadata information
|
|
121
|
+
*/
|
|
122
|
+
meta: MetaInfo;
|
|
123
|
+
/**
|
|
124
|
+
* The metadata information currently written to disk
|
|
125
|
+
*/
|
|
126
|
+
persistedMeta?: MetaInfo;
|
|
127
|
+
/**
|
|
128
|
+
* The Powerlines artifacts directory
|
|
129
|
+
*/
|
|
130
|
+
artifactsPath: string;
|
|
131
|
+
/**
|
|
132
|
+
* The path to the Powerlines builtin runtime modules directory
|
|
133
|
+
*/
|
|
134
|
+
builtinsPath: string;
|
|
135
|
+
/**
|
|
136
|
+
* The path to the Powerlines entry modules directory
|
|
137
|
+
*/
|
|
138
|
+
entryPath: string;
|
|
139
|
+
/**
|
|
140
|
+
* The path to the Powerlines TypeScript declaration files directory
|
|
141
|
+
*/
|
|
142
|
+
dtsPath: string;
|
|
143
|
+
/**
|
|
144
|
+
* The path to a directory where the reflection data buffers (used by the build processes) are stored
|
|
145
|
+
*/
|
|
146
|
+
dataPath: string;
|
|
147
|
+
/**
|
|
148
|
+
* The path to a directory where the project cache (used by the build processes) is stored
|
|
149
|
+
*/
|
|
150
|
+
cachePath: string;
|
|
151
|
+
/**
|
|
152
|
+
* The Powerlines environment paths
|
|
153
|
+
*/
|
|
154
|
+
envPaths: EnvPaths;
|
|
155
|
+
/**
|
|
156
|
+
* The file system path to the Powerlines package installation
|
|
157
|
+
*/
|
|
158
|
+
powerlinesPath: string;
|
|
159
|
+
/**
|
|
160
|
+
* The relative path to the Powerlines workspace root directory
|
|
161
|
+
*/
|
|
162
|
+
relativeToWorkspaceRoot: string;
|
|
163
|
+
/**
|
|
164
|
+
* The project's `package.json` file content
|
|
165
|
+
*/
|
|
166
|
+
packageJson: PackageJson & Record<string, any>;
|
|
167
|
+
/**
|
|
168
|
+
* The project's `project.json` file content
|
|
169
|
+
*/
|
|
170
|
+
projectJson?: Record<string, any>;
|
|
171
|
+
/**
|
|
172
|
+
* The dependency installations required by the project
|
|
173
|
+
*/
|
|
174
|
+
dependencies: Record<string, string | Range>;
|
|
175
|
+
/**
|
|
176
|
+
* The development dependency installations required by the project
|
|
177
|
+
*/
|
|
178
|
+
devDependencies: Record<string, string | Range>;
|
|
179
|
+
/**
|
|
180
|
+
* The parsed TypeScript configuration from the `tsconfig.json` file
|
|
181
|
+
*/
|
|
182
|
+
tsconfig: ParsedTypeScriptConfig;
|
|
183
|
+
/**
|
|
184
|
+
* The entry points of the source code
|
|
185
|
+
*/
|
|
186
|
+
entry: ResolvedEntryTypeDefinition[];
|
|
187
|
+
/**
|
|
188
|
+
* The virtual file system manager used during the build process to reference generated runtime files
|
|
189
|
+
*/
|
|
190
|
+
fs: VirtualFileSystemInterface;
|
|
191
|
+
/**
|
|
192
|
+
* The Jiti module resolver
|
|
193
|
+
*/
|
|
194
|
+
resolver: Resolver;
|
|
195
|
+
/**
|
|
196
|
+
* The builtin module id that exist in the Powerlines virtual file system
|
|
197
|
+
*/
|
|
198
|
+
builtins: string[];
|
|
199
|
+
/**
|
|
200
|
+
* The {@link Project} instance used for type reflection and module manipulation
|
|
201
|
+
*
|
|
202
|
+
* @see https://ts-morph.com/
|
|
203
|
+
*
|
|
204
|
+
* @remarks
|
|
205
|
+
* This instance is created lazily on first access.
|
|
206
|
+
*/
|
|
207
|
+
program: Project;
|
|
208
|
+
/**
|
|
209
|
+
* A function to perform HTTP fetch requests
|
|
210
|
+
*
|
|
211
|
+
* @remarks
|
|
212
|
+
* This function uses a caching layer to avoid duplicate requests during the Powerlines process.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* const response = await context.fetch("https://api.example.com/data");
|
|
217
|
+
* const data = await response.json();
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* @see https://github.com/nodejs/undici
|
|
221
|
+
*
|
|
222
|
+
* @param input - The URL to fetch.
|
|
223
|
+
* @param options - The fetch request options.
|
|
224
|
+
* @returns A promise that resolves to a response returned by the fetch.
|
|
225
|
+
*/
|
|
226
|
+
fetch: (input: RequestInfo, options?: FetchOptions) => Promise<Response>;
|
|
227
|
+
/**
|
|
228
|
+
* Parse code using [Oxc-Parser](https://github.com/oxc/oxc) into an (ESTree-compatible)[https://github.com/estree/estree] AST object.
|
|
229
|
+
*
|
|
230
|
+
* @remarks
|
|
231
|
+
* This function can be used to parse TypeScript code into an AST for further analysis or transformation.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const ast = context.parse("const x: number = 42;");
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @see https://rollupjs.org/plugin-development/#this-parse
|
|
239
|
+
* @see https://github.com/oxc/oxc
|
|
240
|
+
*
|
|
241
|
+
* @param code - The source code to parse.
|
|
242
|
+
* @param options - The options to pass to the parser.
|
|
243
|
+
* @returns An (ESTree-compatible)[https://github.com/estree/estree] AST object.
|
|
244
|
+
*/
|
|
245
|
+
parse: (code: string, options?: ParseOptions) => Promise<ParseResult>;
|
|
246
|
+
/**
|
|
247
|
+
* A helper function to resolve modules using the Jiti resolver
|
|
248
|
+
*
|
|
249
|
+
* @remarks
|
|
250
|
+
* This function can be used to resolve modules relative to the project root directory.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const resolvedPath = await context.resolve("some-module", "/path/to/importer");
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* @param id - The module to resolve.
|
|
258
|
+
* @param importer - An optional path to the importer module.
|
|
259
|
+
* @param options - Additional resolution options.
|
|
260
|
+
* @returns A promise that resolves to the resolved module path.
|
|
261
|
+
*/
|
|
262
|
+
resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<ExternalIdResult | undefined>;
|
|
263
|
+
/**
|
|
264
|
+
* A helper function to load modules using the Jiti resolver
|
|
265
|
+
*
|
|
266
|
+
* @remarks
|
|
267
|
+
* This function can be used to load modules relative to the project root directory.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* const module = await context.load("some-module", "/path/to/importer");
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* @param id - The module to load.
|
|
275
|
+
* @returns A promise that resolves to the loaded module.
|
|
276
|
+
*/
|
|
277
|
+
load: (id: string) => Promise<TransformResult$1 | undefined>;
|
|
278
|
+
/**
|
|
279
|
+
* The Powerlines builtin virtual files
|
|
280
|
+
*/
|
|
281
|
+
getBuiltins: () => Promise<VirtualFile[]>;
|
|
282
|
+
/**
|
|
283
|
+
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
284
|
+
*
|
|
285
|
+
* @param code - The source code of the builtin file
|
|
286
|
+
* @param id - The unique identifier of the builtin file
|
|
287
|
+
* @param path - An optional path to write the builtin file to
|
|
288
|
+
*/
|
|
289
|
+
emitBuiltin: (code: string, id: string, path?: string) => Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
292
|
+
*
|
|
293
|
+
* @param code - The source code of the entry file
|
|
294
|
+
* @param path - An optional path to write the entry file to
|
|
295
|
+
*/
|
|
296
|
+
emitEntry: (code: string, path: string) => Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* A function to update the context fields using a new user configuration options
|
|
299
|
+
*/
|
|
300
|
+
withUserConfig: (userConfig: UserConfig, options?: InitContextOptions) => Promise<void>;
|
|
301
|
+
/**
|
|
302
|
+
* A function to update the context fields using inline configuration options
|
|
303
|
+
*/
|
|
304
|
+
withInlineConfig: (inlineConfig: InlineConfig, options?: InitContextOptions) => Promise<void>;
|
|
305
|
+
/**
|
|
306
|
+
* Create a new logger instance
|
|
307
|
+
*
|
|
308
|
+
* @param name - The name to use for the logger instance
|
|
309
|
+
* @returns A logger function
|
|
310
|
+
*/
|
|
311
|
+
createLog: (name: string | null) => LogFn;
|
|
312
|
+
/**
|
|
313
|
+
* Extend the current logger instance with a new name
|
|
314
|
+
*
|
|
315
|
+
* @param name - The name to use for the extended logger instance
|
|
316
|
+
* @returns A logger function
|
|
317
|
+
*/
|
|
318
|
+
extendLog: (name: string) => LogFn;
|
|
319
|
+
/**
|
|
320
|
+
* Generates a checksum representing the current context state
|
|
321
|
+
*
|
|
322
|
+
* @returns A promise that resolves to a string representing the checksum
|
|
323
|
+
*/
|
|
324
|
+
generateChecksum: () => Promise<string>;
|
|
325
|
+
}
|
|
326
|
+
type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<UnresolvedContext<TResolvedConfig>, "config"> & {
|
|
327
|
+
/**
|
|
328
|
+
* The fully resolved Powerlines configuration
|
|
329
|
+
*/
|
|
330
|
+
config: TResolvedConfig;
|
|
331
|
+
};
|
|
332
|
+
interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
|
|
333
|
+
/**
|
|
334
|
+
* The environment specific resolved configuration
|
|
335
|
+
*/
|
|
336
|
+
environment: EnvironmentResolvedConfig;
|
|
337
|
+
/**
|
|
338
|
+
* An alternative property name for the {@link log} property
|
|
339
|
+
*
|
|
340
|
+
* @remarks
|
|
341
|
+
* This is provided for compatibility with other logging libraries that expect a `logger` property.
|
|
342
|
+
*/
|
|
343
|
+
logger: LogFn;
|
|
344
|
+
}
|
|
345
|
+
type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
|
|
346
|
+
//#endregion
|
|
347
|
+
export { BuildPluginContext, PluginContext, UnresolvedContext };
|