@powerlines/unplugin 0.0.4

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 (119) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +305 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +45 -0
  4. package/dist/_virtual/_rolldown/runtime.mjs +36 -0
  5. package/dist/astro.cjs +37 -0
  6. package/dist/astro.d.cts +27 -0
  7. package/dist/astro.d.cts.map +1 -0
  8. package/dist/astro.d.mts +27 -0
  9. package/dist/astro.d.mts.map +1 -0
  10. package/dist/astro.mjs +36 -0
  11. package/dist/astro.mjs.map +1 -0
  12. package/dist/esbuild.cjs +155 -0
  13. package/dist/esbuild.d.cts +69 -0
  14. package/dist/esbuild.d.cts.map +1 -0
  15. package/dist/esbuild.d.mts +69 -0
  16. package/dist/esbuild.d.mts.map +1 -0
  17. package/dist/esbuild.mjs +149 -0
  18. package/dist/esbuild.mjs.map +1 -0
  19. package/dist/farm.cjs +56 -0
  20. package/dist/farm.d.cts +51 -0
  21. package/dist/farm.d.cts.map +1 -0
  22. package/dist/farm.d.mts +51 -0
  23. package/dist/farm.d.mts.map +1 -0
  24. package/dist/farm.mjs +54 -0
  25. package/dist/farm.mjs.map +1 -0
  26. package/dist/index.cjs +46 -0
  27. package/dist/index.d.cts +37 -0
  28. package/dist/index.d.cts.map +1 -0
  29. package/dist/index.d.mts +37 -0
  30. package/dist/index.d.mts.map +1 -0
  31. package/dist/index.mjs +39 -0
  32. package/dist/index.mjs.map +1 -0
  33. package/dist/next.cjs +37 -0
  34. package/dist/next.d.cts +25 -0
  35. package/dist/next.d.cts.map +1 -0
  36. package/dist/next.d.mts +25 -0
  37. package/dist/next.d.mts.map +1 -0
  38. package/dist/next.mjs +36 -0
  39. package/dist/next.mjs.map +1 -0
  40. package/dist/nuxt.cjs +44 -0
  41. package/dist/nuxt.d.cts +28 -0
  42. package/dist/nuxt.d.cts.map +1 -0
  43. package/dist/nuxt.d.mts +29 -0
  44. package/dist/nuxt.d.mts.map +1 -0
  45. package/dist/nuxt.mjs +44 -0
  46. package/dist/nuxt.mjs.map +1 -0
  47. package/dist/package.cjs +18 -0
  48. package/dist/package.mjs +7 -0
  49. package/dist/package.mjs.map +1 -0
  50. package/dist/rolldown.cjs +161 -0
  51. package/dist/rolldown.d.cts +65 -0
  52. package/dist/rolldown.d.cts.map +1 -0
  53. package/dist/rolldown.d.mts +65 -0
  54. package/dist/rolldown.d.mts.map +1 -0
  55. package/dist/rolldown.mjs +153 -0
  56. package/dist/rolldown.mjs.map +1 -0
  57. package/dist/rollup.cjs +159 -0
  58. package/dist/rollup.d.cts +64 -0
  59. package/dist/rollup.d.cts.map +1 -0
  60. package/dist/rollup.d.mts +64 -0
  61. package/dist/rollup.d.mts.map +1 -0
  62. package/dist/rollup.mjs +149 -0
  63. package/dist/rollup.mjs.map +1 -0
  64. package/dist/rspack.cjs +95 -0
  65. package/dist/rspack.d.cts +58 -0
  66. package/dist/rspack.d.cts.map +1 -0
  67. package/dist/rspack.d.mts +58 -0
  68. package/dist/rspack.d.mts.map +1 -0
  69. package/dist/rspack.mjs +90 -0
  70. package/dist/rspack.mjs.map +1 -0
  71. package/dist/tsdown.cjs +217 -0
  72. package/dist/tsdown.d.cts +63 -0
  73. package/dist/tsdown.d.cts.map +1 -0
  74. package/dist/tsdown.d.mts +63 -0
  75. package/dist/tsdown.d.mts.map +1 -0
  76. package/dist/tsdown.mjs +209 -0
  77. package/dist/tsdown.mjs.map +1 -0
  78. package/dist/tsup.cjs +116 -0
  79. package/dist/tsup.d.cts +49 -0
  80. package/dist/tsup.d.cts.map +1 -0
  81. package/dist/tsup.d.mts +49 -0
  82. package/dist/tsup.d.mts.map +1 -0
  83. package/dist/tsup.mjs +110 -0
  84. package/dist/tsup.mjs.map +1 -0
  85. package/dist/types.cjs +0 -0
  86. package/dist/types.d.cts +12 -0
  87. package/dist/types.d.cts.map +1 -0
  88. package/dist/types.d.mts +12 -0
  89. package/dist/types.d.mts.map +1 -0
  90. package/dist/types.mjs +1 -0
  91. package/dist/unloader.cjs +52 -0
  92. package/dist/unloader.d.cts +46 -0
  93. package/dist/unloader.d.cts.map +1 -0
  94. package/dist/unloader.d.mts +46 -0
  95. package/dist/unloader.d.mts.map +1 -0
  96. package/dist/unloader.mjs +49 -0
  97. package/dist/unloader.mjs.map +1 -0
  98. package/dist/unplugin.cjs +239 -0
  99. package/dist/unplugin.d.cts +60 -0
  100. package/dist/unplugin.d.cts.map +1 -0
  101. package/dist/unplugin.d.mts +60 -0
  102. package/dist/unplugin.d.mts.map +1 -0
  103. package/dist/unplugin.mjs +234 -0
  104. package/dist/unplugin.mjs.map +1 -0
  105. package/dist/vite.cjs +161 -0
  106. package/dist/vite.d.cts +59 -0
  107. package/dist/vite.d.cts.map +1 -0
  108. package/dist/vite.d.mts +59 -0
  109. package/dist/vite.d.mts.map +1 -0
  110. package/dist/vite.mjs +155 -0
  111. package/dist/vite.mjs.map +1 -0
  112. package/dist/webpack.cjs +94 -0
  113. package/dist/webpack.d.cts +58 -0
  114. package/dist/webpack.d.cts.map +1 -0
  115. package/dist/webpack.d.mts +58 -0
  116. package/dist/webpack.d.mts.map +1 -0
  117. package/dist/webpack.mjs +89 -0
  118. package/dist/webpack.mjs.map +1 -0
  119. package/package.json +163 -0
@@ -0,0 +1,64 @@
1
+ import { UnpluginExecutionOptions, UnpluginFactory } from "./types.cjs";
2
+ import { UnpluginFactoryDecorator, UnpluginFactoryOptions } from "./unplugin.cjs";
3
+ import * as _$_powerlines_core0 from "@powerlines/core";
4
+ import { Context, ExecutionContext } from "@powerlines/core";
5
+ import { Plugin, RollupOptions } from "rollup";
6
+
7
+ //#region src/rollup.d.ts
8
+ /**
9
+ * A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
10
+ *
11
+ * @remarks
12
+ * This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
13
+ */
14
+ declare const dtsBundlePlugin: Plugin;
15
+ /**
16
+ * Resolves the options for [rollup](https://rollupjs.org).
17
+ *
18
+ * @param context - The build context.
19
+ * @returns The resolved options.
20
+ */
21
+ declare function resolveOptions(context: Context): RollupOptions;
22
+ /**
23
+ * Creates a Rollup plugin factory that generates a plugin instance.
24
+ *
25
+ * @see https://rollupjs.org/guide/en/#plugins-overview
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // rollup.config.ts
30
+ * import { createRollupFactory } from "@powerlines/unplugin/rollup";
31
+ *
32
+ * const powerlinesPlugin = createRollupFactory({ name: "example-app", ... });
33
+ *
34
+ * export default defineConfig({
35
+ * plugins: [powerlinesPlugin()],
36
+ * });
37
+ *
38
+ * ```
39
+ *
40
+ * @param options - The options to create the plugin factory with.
41
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
42
+ * @returns A function that generates a Rollup plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rollup build.
43
+ */
44
+ declare function createRollupFactory<TContext extends ExecutionContext>(options?: Omit<UnpluginFactoryOptions, "variant">, decorate?: UnpluginFactoryDecorator<TContext>): UnpluginFactory<ExecutionContext<_$_powerlines_core0.ResolvedConfig, unknown>>;
45
+ /**
46
+ * A Rollup plugin that will invoke the Powerlines API hooks during the build process.
47
+ *
48
+ * @see https://rollupjs.org/guide/en/#plugins-overview
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // rollup.config.ts
53
+ *
54
+ * import powerlines from "@powerlines/unplugin/rollup";
55
+ *
56
+ * export default defineConfig({
57
+ * plugins: [powerlines({ name: "example-app", ... })],
58
+ * })
59
+ * ```
60
+ */
61
+ declare const plugin: (options?: UnpluginExecutionOptions | undefined) => Plugin<any> | Plugin<any>[];
62
+ //#endregion
63
+ export { createRollupFactory, plugin as default, plugin, dtsBundlePlugin, resolveOptions };
64
+ //# sourceMappingURL=rollup.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.d.cts","names":[],"sources":["../src/rollup.ts"],"mappings":";;;;;;;;;;AA+CA;;;cAAa,eAAA,EAAiB,MAAA;;AAuC9B;;;;;iBAAgB,cAAA,CAAe,OAAA,EAAS,OAAA,GAAU,aAAA;;;;AAuHlD;;;;;;;;;;;;;;;;;;;iBAAgB,mBAAA,kBAAqC,gBAAA,CAAA,CACnD,OAAA,GAAS,IAAA,CAAK,sBAAA,cACd,QAAA,GAAU,wBAAA,CAAyB,QAAA,IAA8B,eAAA,CAAA,gBAAA,CAA/B,mBAAA,CAA+B,cAAA;;;;;;;AAwCnE;;;;;;;;;;cAAa,MAAA,GAAM,OAAA,GAA4C,wBAAA,iBAA5C,MAAA,QAAA,MAAA"}
@@ -0,0 +1,64 @@
1
+ import { UnpluginExecutionOptions, UnpluginFactory } from "./types.mjs";
2
+ import { UnpluginFactoryDecorator, UnpluginFactoryOptions } from "./unplugin.mjs";
3
+ import * as _$_powerlines_core0 from "@powerlines/core";
4
+ import { Context, ExecutionContext } from "@powerlines/core";
5
+ import { Plugin, RollupOptions } from "rollup";
6
+
7
+ //#region src/rollup.d.ts
8
+ /**
9
+ * A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
10
+ *
11
+ * @remarks
12
+ * This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
13
+ */
14
+ declare const dtsBundlePlugin: Plugin;
15
+ /**
16
+ * Resolves the options for [rollup](https://rollupjs.org).
17
+ *
18
+ * @param context - The build context.
19
+ * @returns The resolved options.
20
+ */
21
+ declare function resolveOptions(context: Context): RollupOptions;
22
+ /**
23
+ * Creates a Rollup plugin factory that generates a plugin instance.
24
+ *
25
+ * @see https://rollupjs.org/guide/en/#plugins-overview
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * // rollup.config.ts
30
+ * import { createRollupFactory } from "@powerlines/unplugin/rollup";
31
+ *
32
+ * const powerlinesPlugin = createRollupFactory({ name: "example-app", ... });
33
+ *
34
+ * export default defineConfig({
35
+ * plugins: [powerlinesPlugin()],
36
+ * });
37
+ *
38
+ * ```
39
+ *
40
+ * @param options - The options to create the plugin factory with.
41
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
42
+ * @returns A function that generates a Rollup plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rollup build.
43
+ */
44
+ declare function createRollupFactory<TContext extends ExecutionContext>(options?: Omit<UnpluginFactoryOptions, "variant">, decorate?: UnpluginFactoryDecorator<TContext>): UnpluginFactory<ExecutionContext<_$_powerlines_core0.ResolvedConfig, unknown>>;
45
+ /**
46
+ * A Rollup plugin that will invoke the Powerlines API hooks during the build process.
47
+ *
48
+ * @see https://rollupjs.org/guide/en/#plugins-overview
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * // rollup.config.ts
53
+ *
54
+ * import powerlines from "@powerlines/unplugin/rollup";
55
+ *
56
+ * export default defineConfig({
57
+ * plugins: [powerlines({ name: "example-app", ... })],
58
+ * })
59
+ * ```
60
+ */
61
+ declare const plugin: (options?: UnpluginExecutionOptions | undefined) => Plugin<any> | Plugin<any>[];
62
+ //#endregion
63
+ export { createRollupFactory, plugin as default, plugin, dtsBundlePlugin, resolveOptions };
64
+ //# sourceMappingURL=rollup.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.d.mts","names":[],"sources":["../src/rollup.ts"],"mappings":";;;;;;;;;;AA+CA;;;cAAa,eAAA,EAAiB,MAAA;;AAuC9B;;;;;iBAAgB,cAAA,CAAe,OAAA,EAAS,OAAA,GAAU,aAAA;;;;AAuHlD;;;;;;;;;;;;;;;;;;;iBAAgB,mBAAA,kBAAqC,gBAAA,CAAA,CACnD,OAAA,GAAS,IAAA,CAAK,sBAAA,cACd,QAAA,GAAU,wBAAA,CAAyB,QAAA,IAA8B,eAAA,CAAA,gBAAA,CAA/B,mBAAA,CAA+B,cAAA;;;;;;;AAwCnE;;;;;;;;;;cAAa,MAAA,GAAM,OAAA,GAA4C,wBAAA,iBAA5C,MAAA,QAAA,MAAA"}
@@ -0,0 +1,149 @@
1
+ import { createUnpluginFactory } from "./unplugin.mjs";
2
+ import { defu as defu$1 } from "defu";
3
+ import { createRollupPlugin } from "unplugin";
4
+ import { isString } from "@stryke/type-checks/is-string";
5
+ import { toArray } from "@stryke/convert/to-array";
6
+ import inject from "@rollup/plugin-inject";
7
+ import resolve from "@rollup/plugin-node-resolve";
8
+ import replace from "@rollup/plugin-replace";
9
+ import typescriptPlugin from "rollup-plugin-typescript2";
10
+ import alias from "@rollup/plugin-alias";
11
+ import { globSync } from "node:fs";
12
+
13
+ //#region src/rollup.ts
14
+ /**
15
+ * A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
16
+ *
17
+ * @remarks
18
+ * This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
19
+ */
20
+ const dtsBundlePlugin = {
21
+ name: "powerlines:dts-bundle",
22
+ async generateBundle(_opts, bundle) {
23
+ for (const [, file] of Object.entries(bundle)) {
24
+ if (file.type === "asset" || !file.isEntry || file.facadeModuleId == null) continue;
25
+ const dtsFileName = file.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/, ".d.ts");
26
+ const relativeSourceDtsName = JSON.stringify(`./${file.facadeModuleId.replace(/\.[cm]?[jt]sx?$/, "")}`);
27
+ this.emitFile({
28
+ type: "asset",
29
+ fileName: dtsFileName,
30
+ source: file.exports.includes("default") ? `export * from ${relativeSourceDtsName};\nexport { default } from ${relativeSourceDtsName};\n` : `export * from ${relativeSourceDtsName};\n`
31
+ });
32
+ }
33
+ }
34
+ };
35
+ /**
36
+ * Resolves the options for [rollup](https://rollupjs.org).
37
+ *
38
+ * @param context - The build context.
39
+ * @returns The resolved options.
40
+ */
41
+ function resolveOptions(context) {
42
+ return {
43
+ input: globSync(toArray(context.entry).map((entry) => isString(entry) ? entry : entry.file)).flat(),
44
+ external: (source) => {
45
+ if (context.config.resolve.external && toArray(context.config.resolve.external).includes(source)) return true;
46
+ if (context.config.resolve.noExternal && toArray(context.config.resolve.noExternal).includes(source)) return false;
47
+ if (context.builtins.includes(source)) return context.config.projectType !== "application";
48
+ return !context.config.resolve.skipNodeModulesBundle;
49
+ },
50
+ plugins: [
51
+ typescriptPlugin({
52
+ check: false,
53
+ tsconfig: context.tsconfig.tsconfigFilePath
54
+ }),
55
+ context.config.define && Object.keys(context.config.define).length > 0 && replace({
56
+ sourceMap: context.config.mode === "development",
57
+ preventAssignment: true,
58
+ ...context.config.define ?? {}
59
+ }),
60
+ context.config.inject && Object.keys(context.config.inject).length > 0 && inject({
61
+ sourceMap: context.config.mode === "development",
62
+ ...context.config.inject
63
+ }),
64
+ alias({ entries: Object.entries(context.alias).reduce((ret, [id, path]) => {
65
+ if (!ret.find((e) => e.find === id)) ret.push({
66
+ find: id,
67
+ replacement: path
68
+ });
69
+ else context.warn(`Duplicate alias entry for '${id}' detected. The first entry will be used.`);
70
+ return ret;
71
+ }, []) }),
72
+ resolve({
73
+ moduleDirectories: ["node_modules"],
74
+ preferBuiltins: true
75
+ }),
76
+ dtsBundlePlugin
77
+ ].filter(Boolean),
78
+ cache: !context.config.skipCache ? void 0 : false,
79
+ logLevel: context.config.logLevel.general === "trace" ? "debug" : context.config.logLevel.general === "debug" ? "warn" : "silent",
80
+ output: [{
81
+ dir: context.config.output.path,
82
+ format: "es",
83
+ entryFileNames: "[name].js",
84
+ preserveModules: true,
85
+ sourcemap: context.config.output.sourceMap
86
+ }, {
87
+ dir: context.config.output.path,
88
+ format: "cjs",
89
+ entryFileNames: "[name].cjs",
90
+ preserveModules: true,
91
+ sourcemap: context.config.output.sourceMap
92
+ }]
93
+ };
94
+ }
95
+ /**
96
+ * Creates a Rollup plugin factory that generates a plugin instance.
97
+ *
98
+ * @see https://rollupjs.org/guide/en/#plugins-overview
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * // rollup.config.ts
103
+ * import { createRollupFactory } from "@powerlines/unplugin/rollup";
104
+ *
105
+ * const powerlinesPlugin = createRollupFactory({ name: "example-app", ... });
106
+ *
107
+ * export default defineConfig({
108
+ * plugins: [powerlinesPlugin()],
109
+ * });
110
+ *
111
+ * ```
112
+ *
113
+ * @param options - The options to create the plugin factory with.
114
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
115
+ * @returns A function that generates a Rollup plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rollup build.
116
+ */
117
+ function createRollupFactory(options = {}, decorate = (options) => options) {
118
+ return createUnpluginFactory({
119
+ ...options,
120
+ variant: "rollup"
121
+ }, (unplugin) => decorate({
122
+ ...unplugin,
123
+ rollup: { async options(opts) {
124
+ const environment = await unplugin.context.getEnvironment();
125
+ return defu$1(resolveOptions(environment), opts, unplugin.context.callHook("rollup:options", { environment }, opts) ?? {});
126
+ } }
127
+ }));
128
+ }
129
+ /**
130
+ * A Rollup plugin that will invoke the Powerlines API hooks during the build process.
131
+ *
132
+ * @see https://rollupjs.org/guide/en/#plugins-overview
133
+ *
134
+ * @example
135
+ * ```ts
136
+ * // rollup.config.ts
137
+ *
138
+ * import powerlines from "@powerlines/unplugin/rollup";
139
+ *
140
+ * export default defineConfig({
141
+ * plugins: [powerlines({ name: "example-app", ... })],
142
+ * })
143
+ * ```
144
+ */
145
+ const plugin = createRollupPlugin(createRollupFactory());
146
+
147
+ //#endregion
148
+ export { createRollupFactory, plugin as default, plugin, dtsBundlePlugin, resolveOptions };
149
+ //# sourceMappingURL=rollup.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rollup.mjs","names":["defu"],"sources":["../src/rollup.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n Context,\n ExecutionContext,\n UnpluginOptions\n} from \"@powerlines/core\";\nimport alias from \"@rollup/plugin-alias\";\nimport inject from \"@rollup/plugin-inject\";\nimport resolve from \"@rollup/plugin-node-resolve\";\nimport replace from \"@rollup/plugin-replace\";\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { defu } from \"defu\";\nimport { globSync } from \"node:fs\";\nimport type { InputOptions, RollupOptions } from \"rollup\";\nimport { Plugin } from \"rollup\";\nimport typescriptPlugin from \"rollup-plugin-typescript2\";\nimport { createRollupPlugin } from \"unplugin\";\nimport {\n createUnpluginFactory,\n UnpluginFactoryDecorator,\n UnpluginFactoryOptions\n} from \"./unplugin\";\n\n/**\n * A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.\n *\n * @remarks\n * This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.\n */\nexport const dtsBundlePlugin: Plugin = {\n name: \"powerlines:dts-bundle\",\n async generateBundle(_opts, bundle) {\n for (const [, file] of Object.entries(bundle)) {\n if (\n file.type === \"asset\" ||\n !file.isEntry ||\n file.facadeModuleId == null\n ) {\n continue;\n }\n\n // Replace various JavaScript file extensions (e.g., .js, .cjs, .mjs, .cjs.js, .mjs.js) with .d.ts for generating type definition file names.\n const dtsFileName = file.fileName.replace(\n /(?:\\.cjs|\\.mjs|\\.esm\\.js|\\.cjs\\.js|\\.mjs\\.js|\\.js)$/,\n \".d.ts\"\n );\n\n const relativeSourceDtsName = JSON.stringify(\n `./${file.facadeModuleId.replace(/\\.[cm]?[jt]sx?$/, \"\")}`\n );\n\n this.emitFile({\n type: \"asset\",\n fileName: dtsFileName,\n source: file.exports.includes(\"default\")\n ? `export * from ${relativeSourceDtsName};\\nexport { default } from ${relativeSourceDtsName};\\n`\n : `export * from ${relativeSourceDtsName};\\n`\n });\n }\n }\n};\n\n/**\n * Resolves the options for [rollup](https://rollupjs.org).\n *\n * @param context - The build context.\n * @returns The resolved options.\n */\nexport function resolveOptions(context: Context): RollupOptions {\n return {\n input: globSync(\n toArray(context.entry).map(entry =>\n isString(entry) ? entry : entry.file\n )\n ).flat(),\n external: (source: string) => {\n if (\n context.config.resolve.external &&\n toArray(context.config.resolve.external).includes(source)\n ) {\n return true;\n }\n\n if (\n context.config.resolve.noExternal &&\n toArray(context.config.resolve.noExternal).includes(source)\n ) {\n return false;\n }\n\n if (context.builtins.includes(source)) {\n return context.config.projectType !== \"application\";\n }\n\n return !context.config.resolve.skipNodeModulesBundle;\n },\n plugins: [\n typescriptPlugin({\n check: false,\n tsconfig: context.tsconfig.tsconfigFilePath\n }),\n context.config.define &&\n Object.keys(context.config.define).length > 0 &&\n replace({\n sourceMap: context.config.mode === \"development\",\n preventAssignment: true,\n ...(context.config.define ?? {})\n }),\n context.config.inject &&\n Object.keys(context.config.inject).length > 0 &&\n inject({\n sourceMap: context.config.mode === \"development\",\n ...context.config.inject\n }),\n alias({\n entries: Object.entries(context.alias).reduce(\n (ret, [id, path]) => {\n if (!ret.find(e => e.find === id)) {\n ret.push({\n find: id,\n replacement: path\n });\n } else {\n context.warn(\n `Duplicate alias entry for '${id}' detected. The first entry will be used.`\n );\n }\n\n return ret;\n },\n [] as { find: string; replacement: string }[]\n )\n }),\n resolve({\n moduleDirectories: [\"node_modules\"],\n preferBuiltins: true\n }),\n dtsBundlePlugin\n ].filter(Boolean) as Plugin[],\n cache: !context.config.skipCache ? undefined : false,\n logLevel:\n context.config.logLevel.general === \"trace\"\n ? \"debug\"\n : context.config.logLevel.general === \"debug\"\n ? \"warn\"\n : \"silent\",\n output: [\n {\n dir: context.config.output.path,\n format: \"es\",\n entryFileNames: \"[name].js\",\n preserveModules: true,\n sourcemap: context.config.output.sourceMap\n },\n {\n dir: context.config.output.path,\n format: \"cjs\",\n entryFileNames: \"[name].cjs\",\n preserveModules: true,\n sourcemap: context.config.output.sourceMap\n }\n ]\n };\n}\n\n/**\n * Creates a Rollup plugin factory that generates a plugin instance.\n *\n * @see https://rollupjs.org/guide/en/#plugins-overview\n *\n * @example\n * ```ts\n * // rollup.config.ts\n * import { createRollupFactory } from \"@powerlines/unplugin/rollup\";\n *\n * const powerlinesPlugin = createRollupFactory({ name: \"example-app\", ... });\n *\n * export default defineConfig({\n * plugins: [powerlinesPlugin()],\n * });\n *\n * ```\n *\n * @param options - The options to create the plugin factory with.\n * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.\n * @returns A function that generates a Rollup plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rollup build.\n */\nexport function createRollupFactory<TContext extends ExecutionContext>(\n options: Omit<UnpluginFactoryOptions, \"variant\"> = {},\n decorate: UnpluginFactoryDecorator<TContext> = options => options\n) {\n return createUnpluginFactory({ ...options, variant: \"rollup\" }, unplugin =>\n decorate({\n ...(unplugin as UnpluginOptions<TContext>),\n rollup: {\n async options(opts: InputOptions) {\n const environment = await unplugin.context.getEnvironment();\n\n return defu(\n resolveOptions(environment),\n opts,\n unplugin.context.callHook(\n \"rollup:options\",\n { environment },\n opts\n ) ?? {}\n );\n }\n }\n })\n );\n}\n\n/**\n * A Rollup plugin that will invoke the Powerlines API hooks during the build process.\n *\n * @see https://rollupjs.org/guide/en/#plugins-overview\n *\n * @example\n * ```ts\n * // rollup.config.ts\n *\n * import powerlines from \"@powerlines/unplugin/rollup\";\n *\n * export default defineConfig({\n * plugins: [powerlines({ name: \"example-app\", ... })],\n * })\n * ```\n */\nexport const plugin = createRollupPlugin(createRollupFactory());\n\nexport { plugin as default };\n"],"mappings":"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"}
@@ -0,0 +1,95 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_unplugin = require('./unplugin.cjs');
4
+ let _stryke_path_join_paths = require("@stryke/path/join-paths");
5
+ let defu = require("defu");
6
+ defu = require_runtime.__toESM(defu, 1);
7
+ let unplugin = require("unplugin");
8
+
9
+ //#region src/rspack.ts
10
+ /**
11
+ * Resolves the options for [rspack](https://rspack.rs/).
12
+ *
13
+ * @param context - The build context.
14
+ * @returns The resolved options.
15
+ */
16
+ function resolveOptions(context) {
17
+ return {
18
+ output: { path: context.config.output.path },
19
+ name: context.config.name,
20
+ resolve: { alias: context.alias },
21
+ external: context.config.resolve.external,
22
+ noExternal: [...context.config.resolve.noExternal ?? [], ...context.builtins ?? []],
23
+ skipNodeModulesBundle: context.config.resolve.skipNodeModulesBundle,
24
+ node: context.config.platform === "node" ? {
25
+ __dirname: true,
26
+ __filename: true,
27
+ global: true
28
+ } : false,
29
+ mode: context.config.mode === "development" ? "development" : "production",
30
+ recordsInputPath: (0, _stryke_path_join_paths.joinPaths)(context.cachePath, "rspack", ".rspack-records.json"),
31
+ recordsOutputPath: (0, _stryke_path_join_paths.joinPaths)(context.cachePath, "rspack", ".rspack-records.json"),
32
+ context: (0, _stryke_path_join_paths.joinPaths)(context.config.cwd, context.config.root),
33
+ cache: context.config.mode === "development",
34
+ devtool: context.config.output.sourceMap ? "source-map" : false,
35
+ optimization: { minimize: context.config.output.minify }
36
+ };
37
+ }
38
+ /**
39
+ * Creates a Rspack plugin factory that generates a plugin instance.
40
+ *
41
+ * @see https://rspack.dev/concepts/plugins
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // rspack.config.ts
46
+ * import { createRspackFactory } from "@powerlines/unplugin/rspack";
47
+ *
48
+ * const powerlinesPlugin = createRspackFactory({ name: "example-app", ... });
49
+ *
50
+ * export default defineConfig({
51
+ * plugins: [powerlinesPlugin()],
52
+ * });
53
+ *
54
+ * ```
55
+ *
56
+ * @param options - The options to create the plugin factory with.
57
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
58
+ * @returns A function that generates a Rspack plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rspack build.
59
+ */
60
+ function createRspackFactory(options = {}, decorate = (options) => options) {
61
+ return require_unplugin.createUnpluginFactory({
62
+ ...options,
63
+ variant: "rspack"
64
+ }, (unplugin$1) => decorate({
65
+ ...unplugin$1,
66
+ rspack(compiler) {
67
+ compiler.hooks.beforeRun.tap("PowerlinesRspackPlugin", (compiler) => {
68
+ compiler.options = (0, defu.default)(resolveOptions(unplugin$1.context), compiler.options);
69
+ });
70
+ }
71
+ }));
72
+ }
73
+ /**
74
+ * An Rspack plugin that will invoke the Powerlines API hooks during the build process.
75
+ *
76
+ * @see https://rspack.dev/concepts/plugins
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * // rspack.config.ts
81
+ *
82
+ * import powerlines from "@powerlines/unplugin/rspack";
83
+ *
84
+ * export default {
85
+ * plugins: [powerlines({ name: "example-app", ... })],
86
+ * }
87
+ * ```
88
+ */
89
+ const plugin = (0, unplugin.createRspackPlugin)(createRspackFactory());
90
+
91
+ //#endregion
92
+ exports.createRspackFactory = createRspackFactory;
93
+ exports.default = plugin;
94
+ exports.plugin = plugin;
95
+ exports.resolveOptions = resolveOptions;
@@ -0,0 +1,58 @@
1
+ import { UnpluginExecutionOptions, UnpluginFactory } from "./types.cjs";
2
+ import { UnpluginFactoryDecorator, UnpluginFactoryOptions } from "./unplugin.cjs";
3
+ import * as _$_powerlines_core0 from "@powerlines/core";
4
+ import { Context, ExecutionContext } from "@powerlines/core";
5
+ import * as _$unplugin from "unplugin";
6
+ import { RspackOptionsNormalized } from "@rspack/core";
7
+
8
+ //#region src/rspack.d.ts
9
+ /**
10
+ * Resolves the options for [rspack](https://rspack.rs/).
11
+ *
12
+ * @param context - The build context.
13
+ * @returns The resolved options.
14
+ */
15
+ declare function resolveOptions(context: Context): Partial<RspackOptionsNormalized>;
16
+ /**
17
+ * Creates a Rspack plugin factory that generates a plugin instance.
18
+ *
19
+ * @see https://rspack.dev/concepts/plugins
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // rspack.config.ts
24
+ * import { createRspackFactory } from "@powerlines/unplugin/rspack";
25
+ *
26
+ * const powerlinesPlugin = createRspackFactory({ name: "example-app", ... });
27
+ *
28
+ * export default defineConfig({
29
+ * plugins: [powerlinesPlugin()],
30
+ * });
31
+ *
32
+ * ```
33
+ *
34
+ * @param options - The options to create the plugin factory with.
35
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
36
+ * @returns A function that generates a Rspack plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rspack build.
37
+ */
38
+ declare function createRspackFactory<TContext extends ExecutionContext>(options?: Omit<UnpluginFactoryOptions, "variant">, decorate?: UnpluginFactoryDecorator<TContext>): UnpluginFactory<ExecutionContext<_$_powerlines_core0.ResolvedConfig, unknown>>;
39
+ /**
40
+ * An Rspack plugin that will invoke the Powerlines API hooks during the build process.
41
+ *
42
+ * @see https://rspack.dev/concepts/plugins
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // rspack.config.ts
47
+ *
48
+ * import powerlines from "@powerlines/unplugin/rspack";
49
+ *
50
+ * export default {
51
+ * plugins: [powerlines({ name: "example-app", ... })],
52
+ * }
53
+ * ```
54
+ */
55
+ declare const plugin: (options?: UnpluginExecutionOptions | undefined) => _$unplugin.RspackPluginInstance;
56
+ //#endregion
57
+ export { createRspackFactory, plugin as default, plugin, resolveOptions };
58
+ //# sourceMappingURL=rspack.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.d.cts","names":[],"sources":["../src/rspack.ts"],"mappings":";;;;;;;;;;;;;AAmCA;iBAAgB,cAAA,CACd,OAAA,EAAS,OAAA,GACR,OAAA,CAAQ,uBAAA;;;;;;;;;;;;;AAoEX;;;;;;;;;;iBAAgB,mBAAA,kBAAqC,gBAAA,CAAA,CACnD,OAAA,GAAS,IAAA,CAAK,sBAAA,cACd,QAAA,GAAU,wBAAA,CAAyB,QAAA,IAA8B,eAAA,CAAA,gBAAA,CAA/B,mBAAA,CAA+B,cAAA;;;;;;;;;;;;;;;;AAiCnE;cAAa,MAAA,GAAM,OAAA,GAA4C,wBAAA,iBAA5C,UAAA,CAAA,oBAAA"}
@@ -0,0 +1,58 @@
1
+ import { UnpluginExecutionOptions, UnpluginFactory } from "./types.mjs";
2
+ import { UnpluginFactoryDecorator, UnpluginFactoryOptions } from "./unplugin.mjs";
3
+ import * as _$unplugin from "unplugin";
4
+ import * as _$_powerlines_core0 from "@powerlines/core";
5
+ import { Context, ExecutionContext } from "@powerlines/core";
6
+ import { RspackOptionsNormalized } from "@rspack/core";
7
+
8
+ //#region src/rspack.d.ts
9
+ /**
10
+ * Resolves the options for [rspack](https://rspack.rs/).
11
+ *
12
+ * @param context - The build context.
13
+ * @returns The resolved options.
14
+ */
15
+ declare function resolveOptions(context: Context): Partial<RspackOptionsNormalized>;
16
+ /**
17
+ * Creates a Rspack plugin factory that generates a plugin instance.
18
+ *
19
+ * @see https://rspack.dev/concepts/plugins
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // rspack.config.ts
24
+ * import { createRspackFactory } from "@powerlines/unplugin/rspack";
25
+ *
26
+ * const powerlinesPlugin = createRspackFactory({ name: "example-app", ... });
27
+ *
28
+ * export default defineConfig({
29
+ * plugins: [powerlinesPlugin()],
30
+ * });
31
+ *
32
+ * ```
33
+ *
34
+ * @param options - The options to create the plugin factory with.
35
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
36
+ * @returns A function that generates a Rspack plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rspack build.
37
+ */
38
+ declare function createRspackFactory<TContext extends ExecutionContext>(options?: Omit<UnpluginFactoryOptions, "variant">, decorate?: UnpluginFactoryDecorator<TContext>): UnpluginFactory<ExecutionContext<_$_powerlines_core0.ResolvedConfig, unknown>>;
39
+ /**
40
+ * An Rspack plugin that will invoke the Powerlines API hooks during the build process.
41
+ *
42
+ * @see https://rspack.dev/concepts/plugins
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // rspack.config.ts
47
+ *
48
+ * import powerlines from "@powerlines/unplugin/rspack";
49
+ *
50
+ * export default {
51
+ * plugins: [powerlines({ name: "example-app", ... })],
52
+ * }
53
+ * ```
54
+ */
55
+ declare const plugin: (options?: UnpluginExecutionOptions | undefined) => _$unplugin.RspackPluginInstance;
56
+ //#endregion
57
+ export { createRspackFactory, plugin as default, plugin, resolveOptions };
58
+ //# sourceMappingURL=rspack.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.d.mts","names":[],"sources":["../src/rspack.ts"],"mappings":";;;;;;;;;;;;;AAmCA;iBAAgB,cAAA,CACd,OAAA,EAAS,OAAA,GACR,OAAA,CAAQ,uBAAA;;;;;;;;;;;;;AAoEX;;;;;;;;;;iBAAgB,mBAAA,kBAAqC,gBAAA,CAAA,CACnD,OAAA,GAAS,IAAA,CAAK,sBAAA,cACd,QAAA,GAAU,wBAAA,CAAyB,QAAA,IAA8B,eAAA,CAAA,gBAAA,CAA/B,mBAAA,CAA+B,cAAA;;;;;;;;;;;;;;;;AAiCnE;cAAa,MAAA,GAAM,OAAA,GAA4C,wBAAA,iBAA5C,UAAA,CAAA,oBAAA"}
@@ -0,0 +1,90 @@
1
+ import { createUnpluginFactory } from "./unplugin.mjs";
2
+ import { joinPaths } from "@stryke/path/join-paths";
3
+ import defu from "defu";
4
+ import { createRspackPlugin } from "unplugin";
5
+
6
+ //#region src/rspack.ts
7
+ /**
8
+ * Resolves the options for [rspack](https://rspack.rs/).
9
+ *
10
+ * @param context - The build context.
11
+ * @returns The resolved options.
12
+ */
13
+ function resolveOptions(context) {
14
+ return {
15
+ output: { path: context.config.output.path },
16
+ name: context.config.name,
17
+ resolve: { alias: context.alias },
18
+ external: context.config.resolve.external,
19
+ noExternal: [...context.config.resolve.noExternal ?? [], ...context.builtins ?? []],
20
+ skipNodeModulesBundle: context.config.resolve.skipNodeModulesBundle,
21
+ node: context.config.platform === "node" ? {
22
+ __dirname: true,
23
+ __filename: true,
24
+ global: true
25
+ } : false,
26
+ mode: context.config.mode === "development" ? "development" : "production",
27
+ recordsInputPath: joinPaths(context.cachePath, "rspack", ".rspack-records.json"),
28
+ recordsOutputPath: joinPaths(context.cachePath, "rspack", ".rspack-records.json"),
29
+ context: joinPaths(context.config.cwd, context.config.root),
30
+ cache: context.config.mode === "development",
31
+ devtool: context.config.output.sourceMap ? "source-map" : false,
32
+ optimization: { minimize: context.config.output.minify }
33
+ };
34
+ }
35
+ /**
36
+ * Creates a Rspack plugin factory that generates a plugin instance.
37
+ *
38
+ * @see https://rspack.dev/concepts/plugins
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * // rspack.config.ts
43
+ * import { createRspackFactory } from "@powerlines/unplugin/rspack";
44
+ *
45
+ * const powerlinesPlugin = createRspackFactory({ name: "example-app", ... });
46
+ *
47
+ * export default defineConfig({
48
+ * plugins: [powerlinesPlugin()],
49
+ * });
50
+ *
51
+ * ```
52
+ *
53
+ * @param options - The options to create the plugin factory with.
54
+ * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.
55
+ * @returns A function that generates a Rspack plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rspack build.
56
+ */
57
+ function createRspackFactory(options = {}, decorate = (options) => options) {
58
+ return createUnpluginFactory({
59
+ ...options,
60
+ variant: "rspack"
61
+ }, (unplugin) => decorate({
62
+ ...unplugin,
63
+ rspack(compiler) {
64
+ compiler.hooks.beforeRun.tap("PowerlinesRspackPlugin", (compiler) => {
65
+ compiler.options = defu(resolveOptions(unplugin.context), compiler.options);
66
+ });
67
+ }
68
+ }));
69
+ }
70
+ /**
71
+ * An Rspack plugin that will invoke the Powerlines API hooks during the build process.
72
+ *
73
+ * @see https://rspack.dev/concepts/plugins
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * // rspack.config.ts
78
+ *
79
+ * import powerlines from "@powerlines/unplugin/rspack";
80
+ *
81
+ * export default {
82
+ * plugins: [powerlines({ name: "example-app", ... })],
83
+ * }
84
+ * ```
85
+ */
86
+ const plugin = createRspackPlugin(createRspackFactory());
87
+
88
+ //#endregion
89
+ export { createRspackFactory, plugin as default, plugin, resolveOptions };
90
+ //# sourceMappingURL=rspack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.mjs","names":[],"sources":["../src/rspack.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Context, ExecutionContext, UnpluginOptions } from \"@powerlines/core\";\nimport { RspackOptionsNormalized } from \"@rspack/core\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport defu from \"defu\";\nimport { createRspackPlugin, RspackCompiler } from \"unplugin\";\nimport {\n createUnpluginFactory,\n UnpluginFactoryDecorator,\n UnpluginFactoryOptions\n} from \"./unplugin\";\n\n/**\n * Resolves the options for [rspack](https://rspack.rs/).\n *\n * @param context - The build context.\n * @returns The resolved options.\n */\nexport function resolveOptions(\n context: Context\n): Partial<RspackOptionsNormalized> {\n return {\n output: {\n path: context.config.output.path\n },\n name: context.config.name,\n resolve: {\n alias: context.alias\n },\n external: context.config.resolve.external,\n noExternal: [\n ...(context.config.resolve.noExternal ?? []),\n ...(context.builtins ?? [])\n ],\n skipNodeModulesBundle: context.config.resolve.skipNodeModulesBundle,\n node:\n context.config.platform === \"node\"\n ? {\n __dirname: true,\n __filename: true,\n global: true\n }\n : false,\n mode:\n context.config.mode === \"development\"\n ? (\"development\" as const)\n : (\"production\" as const),\n recordsInputPath: joinPaths(\n context.cachePath,\n \"rspack\",\n \".rspack-records.json\"\n ),\n recordsOutputPath: joinPaths(\n context.cachePath,\n \"rspack\",\n \".rspack-records.json\"\n ),\n context: joinPaths(context.config.cwd, context.config.root),\n cache: context.config.mode === \"development\",\n devtool: context.config.output.sourceMap ? \"source-map\" : false,\n optimization: {\n minimize: context.config.output.minify\n }\n } as Partial<RspackOptionsNormalized>;\n}\n\n/**\n * Creates a Rspack plugin factory that generates a plugin instance.\n *\n * @see https://rspack.dev/concepts/plugins\n *\n * @example\n * ```ts\n * // rspack.config.ts\n * import { createRspackFactory } from \"@powerlines/unplugin/rspack\";\n *\n * const powerlinesPlugin = createRspackFactory({ name: \"example-app\", ... });\n *\n * export default defineConfig({\n * plugins: [powerlinesPlugin()],\n * });\n *\n * ```\n *\n * @param options - The options to create the plugin factory with.\n * @param decorate - A function to decorate the plugin options with additional properties or hooks. This can be used to add custom behavior to the plugin instance, such as additional hooks or configuration options. The function receives the generated plugin options and should return an object containing any additional properties or hooks to be merged into the final plugin options.\n * @returns A function that generates a Rspack plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rspack build.\n */\nexport function createRspackFactory<TContext extends ExecutionContext>(\n options: Omit<UnpluginFactoryOptions, \"variant\"> = {},\n decorate: UnpluginFactoryDecorator<TContext> = options => options\n) {\n return createUnpluginFactory({ ...options, variant: \"rspack\" }, unplugin =>\n decorate({\n ...(unplugin as UnpluginOptions<TContext>),\n rspack(compiler: RspackCompiler) {\n compiler.hooks.beforeRun.tap(\"PowerlinesRspackPlugin\", compiler => {\n compiler.options = defu(\n resolveOptions(unplugin.context),\n compiler.options\n ) as RspackOptionsNormalized;\n });\n }\n })\n );\n}\n\n/**\n * An Rspack plugin that will invoke the Powerlines API hooks during the build process.\n *\n * @see https://rspack.dev/concepts/plugins\n *\n * @example\n * ```ts\n * // rspack.config.ts\n *\n * import powerlines from \"@powerlines/unplugin/rspack\";\n *\n * export default {\n * plugins: [powerlines({ name: \"example-app\", ... })],\n * }\n * ```\n */\nexport const plugin = createRspackPlugin(createRspackFactory());\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;AAmCA,SAAgB,eACd,SACkC;CAClC,OAAO;EACL,QAAQ,EACN,MAAM,QAAQ,OAAO,OAAO,MAC7B;EACD,MAAM,QAAQ,OAAO;EACrB,SAAS,EACP,OAAO,QAAQ,OAChB;EACD,UAAU,QAAQ,OAAO,QAAQ;EACjC,YAAY,CACV,GAAI,QAAQ,OAAO,QAAQ,cAAc,EAAE,EAC3C,GAAI,QAAQ,YAAY,EAAE,CAC3B;EACD,uBAAuB,QAAQ,OAAO,QAAQ;EAC9C,MACE,QAAQ,OAAO,aAAa,SACxB;GACE,WAAW;GACX,YAAY;GACZ,QAAQ;GACT,GACD;EACN,MACE,QAAQ,OAAO,SAAS,gBACnB,gBACA;EACP,kBAAkB,UAChB,QAAQ,WACR,UACA,uBACD;EACD,mBAAmB,UACjB,QAAQ,WACR,UACA,uBACD;EACD,SAAS,UAAU,QAAQ,OAAO,KAAK,QAAQ,OAAO,KAAK;EAC3D,OAAO,QAAQ,OAAO,SAAS;EAC/B,SAAS,QAAQ,OAAO,OAAO,YAAY,eAAe;EAC1D,cAAc,EACZ,UAAU,QAAQ,OAAO,OAAO,QACjC;EACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBH,SAAgB,oBACd,UAAmD,EAAE,EACrD,YAA+C,YAAW,SAC1D;CACA,OAAO,sBAAsB;EAAE,GAAG;EAAS,SAAS;EAAU,GAAE,aAC9D,SAAS;EACP,GAAI;EACJ,OAAO,UAA0B;GAC/B,SAAS,MAAM,UAAU,IAAI,2BAA0B,aAAY;IACjE,SAAS,UAAU,KACjB,eAAe,SAAS,QAAQ,EAChC,SAAS,QACV;KACD;;EAEL,CAAC,CACH;;;;;;;;;;;;;;;;;;AAmBH,MAAa,SAAS,mBAAmB,qBAAqB,CAAC"}