@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.
- package/LICENSE +201 -0
- package/README.md +305 -0
- package/dist/_virtual/_rolldown/runtime.cjs +45 -0
- package/dist/_virtual/_rolldown/runtime.mjs +36 -0
- package/dist/astro.cjs +37 -0
- package/dist/astro.d.cts +27 -0
- package/dist/astro.d.cts.map +1 -0
- package/dist/astro.d.mts +27 -0
- package/dist/astro.d.mts.map +1 -0
- package/dist/astro.mjs +36 -0
- package/dist/astro.mjs.map +1 -0
- package/dist/esbuild.cjs +155 -0
- package/dist/esbuild.d.cts +69 -0
- package/dist/esbuild.d.cts.map +1 -0
- package/dist/esbuild.d.mts +69 -0
- package/dist/esbuild.d.mts.map +1 -0
- package/dist/esbuild.mjs +149 -0
- package/dist/esbuild.mjs.map +1 -0
- package/dist/farm.cjs +56 -0
- package/dist/farm.d.cts +51 -0
- package/dist/farm.d.cts.map +1 -0
- package/dist/farm.d.mts +51 -0
- package/dist/farm.d.mts.map +1 -0
- package/dist/farm.mjs +54 -0
- package/dist/farm.mjs.map +1 -0
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +37 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +37 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +39 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next.cjs +37 -0
- package/dist/next.d.cts +25 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.mts +25 -0
- package/dist/next.d.mts.map +1 -0
- package/dist/next.mjs +36 -0
- package/dist/next.mjs.map +1 -0
- package/dist/nuxt.cjs +44 -0
- package/dist/nuxt.d.cts +28 -0
- package/dist/nuxt.d.cts.map +1 -0
- package/dist/nuxt.d.mts +29 -0
- package/dist/nuxt.d.mts.map +1 -0
- package/dist/nuxt.mjs +44 -0
- package/dist/nuxt.mjs.map +1 -0
- package/dist/package.cjs +18 -0
- package/dist/package.mjs +7 -0
- package/dist/package.mjs.map +1 -0
- package/dist/rolldown.cjs +161 -0
- package/dist/rolldown.d.cts +65 -0
- package/dist/rolldown.d.cts.map +1 -0
- package/dist/rolldown.d.mts +65 -0
- package/dist/rolldown.d.mts.map +1 -0
- package/dist/rolldown.mjs +153 -0
- package/dist/rolldown.mjs.map +1 -0
- package/dist/rollup.cjs +159 -0
- package/dist/rollup.d.cts +64 -0
- package/dist/rollup.d.cts.map +1 -0
- package/dist/rollup.d.mts +64 -0
- package/dist/rollup.d.mts.map +1 -0
- package/dist/rollup.mjs +149 -0
- package/dist/rollup.mjs.map +1 -0
- package/dist/rspack.cjs +95 -0
- package/dist/rspack.d.cts +58 -0
- package/dist/rspack.d.cts.map +1 -0
- package/dist/rspack.d.mts +58 -0
- package/dist/rspack.d.mts.map +1 -0
- package/dist/rspack.mjs +90 -0
- package/dist/rspack.mjs.map +1 -0
- package/dist/tsdown.cjs +217 -0
- package/dist/tsdown.d.cts +63 -0
- package/dist/tsdown.d.cts.map +1 -0
- package/dist/tsdown.d.mts +63 -0
- package/dist/tsdown.d.mts.map +1 -0
- package/dist/tsdown.mjs +209 -0
- package/dist/tsdown.mjs.map +1 -0
- package/dist/tsup.cjs +116 -0
- package/dist/tsup.d.cts +49 -0
- package/dist/tsup.d.cts.map +1 -0
- package/dist/tsup.d.mts +49 -0
- package/dist/tsup.d.mts.map +1 -0
- package/dist/tsup.mjs +110 -0
- package/dist/tsup.mjs.map +1 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +12 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +12 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +1 -0
- package/dist/unloader.cjs +52 -0
- package/dist/unloader.d.cts +46 -0
- package/dist/unloader.d.cts.map +1 -0
- package/dist/unloader.d.mts +46 -0
- package/dist/unloader.d.mts.map +1 -0
- package/dist/unloader.mjs +49 -0
- package/dist/unloader.mjs.map +1 -0
- package/dist/unplugin.cjs +239 -0
- package/dist/unplugin.d.cts +60 -0
- package/dist/unplugin.d.cts.map +1 -0
- package/dist/unplugin.d.mts +60 -0
- package/dist/unplugin.d.mts.map +1 -0
- package/dist/unplugin.mjs +234 -0
- package/dist/unplugin.mjs.map +1 -0
- package/dist/vite.cjs +161 -0
- package/dist/vite.d.cts +59 -0
- package/dist/vite.d.cts.map +1 -0
- package/dist/vite.d.mts +59 -0
- package/dist/vite.d.mts.map +1 -0
- package/dist/vite.mjs +155 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/webpack.cjs +94 -0
- package/dist/webpack.d.cts +58 -0
- package/dist/webpack.d.cts.map +1 -0
- package/dist/webpack.d.mts +58 -0
- package/dist/webpack.d.mts.map +1 -0
- package/dist/webpack.mjs +89 -0
- package/dist/webpack.mjs.map +1 -0
- package/package.json +163 -0
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
const require_rollup = require('./rollup.cjs');
|
|
5
|
+
let _stryke_path_append = require("@stryke/path/append");
|
|
6
|
+
let _stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
7
|
+
let defu = require("defu");
|
|
8
|
+
let unplugin = require("unplugin");
|
|
9
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
10
|
+
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
11
|
+
let _rollup_plugin_inject = require("@rollup/plugin-inject");
|
|
12
|
+
_rollup_plugin_inject = require_runtime.__toESM(_rollup_plugin_inject, 1);
|
|
13
|
+
let _rollup_plugin_node_resolve = require("@rollup/plugin-node-resolve");
|
|
14
|
+
_rollup_plugin_node_resolve = require_runtime.__toESM(_rollup_plugin_node_resolve, 1);
|
|
15
|
+
let _rollup_plugin_replace = require("@rollup/plugin-replace");
|
|
16
|
+
_rollup_plugin_replace = require_runtime.__toESM(_rollup_plugin_replace, 1);
|
|
17
|
+
let glob = require("glob");
|
|
18
|
+
let rolldown_experimental = require("rolldown/experimental");
|
|
19
|
+
let rollup_plugin_typescript2 = require("rollup-plugin-typescript2");
|
|
20
|
+
rollup_plugin_typescript2 = require_runtime.__toESM(rollup_plugin_typescript2, 1);
|
|
21
|
+
|
|
22
|
+
//#region src/rolldown.ts
|
|
23
|
+
const DEFAULT_OPTIONS = {
|
|
24
|
+
keepNames: true,
|
|
25
|
+
treeshake: true,
|
|
26
|
+
shimMissingExports: true,
|
|
27
|
+
transform: { target: "esnext" }
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the options for [rolldown](https://rolldown.rs).
|
|
31
|
+
*
|
|
32
|
+
* @param context - The build context.
|
|
33
|
+
* @returns The resolved options.
|
|
34
|
+
*/
|
|
35
|
+
function resolveOptions(context) {
|
|
36
|
+
return (0, defu.defu)({
|
|
37
|
+
input: (0, glob.globSync)((0, _stryke_convert_to_array.toArray)(context.entry).map((entry) => (0, _stryke_type_checks_is_string.isString)(entry) ? entry : entry.file)).flat(),
|
|
38
|
+
external: (source) => {
|
|
39
|
+
if (context.config.resolve.external && (0, _stryke_convert_to_array.toArray)(context.config.resolve.external).includes(source)) return true;
|
|
40
|
+
if (context.config.resolve.noExternal && (0, _stryke_convert_to_array.toArray)(context.config.resolve.noExternal).includes(source)) return false;
|
|
41
|
+
if (context.builtins.includes(source)) return context.config.projectType !== "application";
|
|
42
|
+
return !context.config.resolve.skipNodeModulesBundle;
|
|
43
|
+
},
|
|
44
|
+
plugins: [
|
|
45
|
+
(0, rollup_plugin_typescript2.default)({
|
|
46
|
+
check: false,
|
|
47
|
+
tsconfig: context.tsconfig.tsconfigFilePath
|
|
48
|
+
}),
|
|
49
|
+
context.config.define && Object.keys(context.config.define).length > 0 && (0, _rollup_plugin_replace.default)({
|
|
50
|
+
sourceMap: context.config.mode === "development",
|
|
51
|
+
preventAssignment: true,
|
|
52
|
+
...context.config.define ?? {}
|
|
53
|
+
}),
|
|
54
|
+
context.config.inject && Object.keys(context.config.inject).length > 0 && (0, _rollup_plugin_inject.default)({
|
|
55
|
+
sourceMap: context.config.mode === "development",
|
|
56
|
+
...context.config.inject
|
|
57
|
+
}),
|
|
58
|
+
(0, rolldown_experimental.viteAliasPlugin)({ entries: Object.entries(context.alias).reduce((ret, [id, path]) => {
|
|
59
|
+
if (!ret.find((e) => e.find === id)) ret.push({
|
|
60
|
+
find: id,
|
|
61
|
+
replacement: path
|
|
62
|
+
});
|
|
63
|
+
else context.warn(`Duplicate alias entry for '${id}' detected. The first entry will be used.`);
|
|
64
|
+
return ret;
|
|
65
|
+
}, []) }),
|
|
66
|
+
(0, _rollup_plugin_node_resolve.default)({
|
|
67
|
+
moduleDirectories: ["node_modules"],
|
|
68
|
+
preferBuiltins: true
|
|
69
|
+
}),
|
|
70
|
+
require_rollup.dtsBundlePlugin
|
|
71
|
+
],
|
|
72
|
+
resolve: {
|
|
73
|
+
alias: context.alias,
|
|
74
|
+
mainFields: context.config.resolve.mainFields,
|
|
75
|
+
conditions: context.config.resolve.conditions,
|
|
76
|
+
define: context.config.define,
|
|
77
|
+
extensions: context.config.resolve.extensions
|
|
78
|
+
},
|
|
79
|
+
transform: {
|
|
80
|
+
define: context.config.define,
|
|
81
|
+
inject: context.config.inject,
|
|
82
|
+
typescript: { target: context.tsconfig.tsconfigJson?.compilerOptions?.target }
|
|
83
|
+
},
|
|
84
|
+
platform: context.config.platform,
|
|
85
|
+
tsconfig: (0, _stryke_path_append.appendPath)(context.tsconfig.tsconfigFilePath, context.config.cwd),
|
|
86
|
+
cache: !context.config.skipCache ? (0, _stryke_path_join_paths.joinPaths)(context.cachePath, "rolldown") : false,
|
|
87
|
+
logLevel: context.config.logLevel.general === "trace" ? "debug" : context.config.logLevel.general === "debug" ? "warn" : "error",
|
|
88
|
+
onLog(level, log) {
|
|
89
|
+
if (log.message?.trim()) if (level === "info") context.logger.debug(log.message?.trim() ?? "");
|
|
90
|
+
else context.logger.log(level, log.message?.trim() ?? "");
|
|
91
|
+
},
|
|
92
|
+
minify: context.config.output.minify,
|
|
93
|
+
output: [{
|
|
94
|
+
dir: context.config.output.path,
|
|
95
|
+
format: "es",
|
|
96
|
+
preserveModules: true,
|
|
97
|
+
sourcemap: context.config.output.sourceMap
|
|
98
|
+
}, {
|
|
99
|
+
dir: context.config.output.path,
|
|
100
|
+
format: "cjs",
|
|
101
|
+
preserveModules: true,
|
|
102
|
+
sourcemap: context.config.output.sourceMap
|
|
103
|
+
}]
|
|
104
|
+
}, DEFAULT_OPTIONS);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates a Rolldown plugin factory that generates a plugin instance.
|
|
108
|
+
*
|
|
109
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* // rolldown.config.ts
|
|
114
|
+
* import { createRolldownFactory } from "@powerlines/unplugin/rolldown";
|
|
115
|
+
*
|
|
116
|
+
* const powerlinesPlugin = createRolldownFactory({ name: "example-app", ... });
|
|
117
|
+
*
|
|
118
|
+
* export default defineConfig({
|
|
119
|
+
* plugins: [powerlinesPlugin()],
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @param options - The options to create the plugin factory with.
|
|
125
|
+
* @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.
|
|
126
|
+
* @returns A function that generates a Rolldown plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rolldown build.
|
|
127
|
+
*/
|
|
128
|
+
function createRolldownFactory(options = {}, decorate = (options) => options) {
|
|
129
|
+
return require_unplugin.createUnpluginFactory({
|
|
130
|
+
...options,
|
|
131
|
+
variant: "rolldown"
|
|
132
|
+
}, (unplugin$1) => decorate({
|
|
133
|
+
...unplugin$1,
|
|
134
|
+
rolldown: { async options(options) {
|
|
135
|
+
const environment = await unplugin$1.context.getEnvironment();
|
|
136
|
+
return (0, defu.defu)(resolveOptions(environment), options, unplugin$1.context.callHook("rolldown:options", { environment }, options) ?? {});
|
|
137
|
+
} }
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A Rolldown plugin that will invoke the Powerlines API hooks during the build process.
|
|
142
|
+
*
|
|
143
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* // rolldown.config.ts
|
|
148
|
+
* import powerlines from "@powerlines/unplugin/rolldown";
|
|
149
|
+
*
|
|
150
|
+
* export default defineConfig({
|
|
151
|
+
* plugins: [powerlines({ name: "example-app", ... })],
|
|
152
|
+
* })
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
const plugin = (0, unplugin.createRolldownPlugin)(createRolldownFactory());
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS;
|
|
159
|
+
exports.createRolldownFactory = createRolldownFactory;
|
|
160
|
+
exports.default = plugin;
|
|
161
|
+
exports.resolveOptions = resolveOptions;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 _$rolldown from "rolldown";
|
|
6
|
+
import { RolldownOptions } from "rolldown";
|
|
7
|
+
|
|
8
|
+
//#region src/rolldown.d.ts
|
|
9
|
+
declare const DEFAULT_OPTIONS: {
|
|
10
|
+
keepNames: boolean;
|
|
11
|
+
treeshake: boolean;
|
|
12
|
+
shimMissingExports: boolean;
|
|
13
|
+
transform: {
|
|
14
|
+
target: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the options for [rolldown](https://rolldown.rs).
|
|
19
|
+
*
|
|
20
|
+
* @param context - The build context.
|
|
21
|
+
* @returns The resolved options.
|
|
22
|
+
*/
|
|
23
|
+
declare function resolveOptions(context: Context): RolldownOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a Rolldown plugin factory that generates a plugin instance.
|
|
26
|
+
*
|
|
27
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // rolldown.config.ts
|
|
32
|
+
* import { createRolldownFactory } from "@powerlines/unplugin/rolldown";
|
|
33
|
+
*
|
|
34
|
+
* const powerlinesPlugin = createRolldownFactory({ name: "example-app", ... });
|
|
35
|
+
*
|
|
36
|
+
* export default defineConfig({
|
|
37
|
+
* plugins: [powerlinesPlugin()],
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param options - The options to create the plugin factory with.
|
|
43
|
+
* @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.
|
|
44
|
+
* @returns A function that generates a Rolldown plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rolldown build.
|
|
45
|
+
*/
|
|
46
|
+
declare function createRolldownFactory<TContext extends ExecutionContext>(options?: Omit<UnpluginFactoryOptions, "variant">, decorate?: UnpluginFactoryDecorator<TContext>): UnpluginFactory<ExecutionContext<_$_powerlines_core0.ResolvedConfig, unknown>>;
|
|
47
|
+
/**
|
|
48
|
+
* A Rolldown plugin that will invoke the Powerlines API hooks during the build process.
|
|
49
|
+
*
|
|
50
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // rolldown.config.ts
|
|
55
|
+
* import powerlines from "@powerlines/unplugin/rolldown";
|
|
56
|
+
*
|
|
57
|
+
* export default defineConfig({
|
|
58
|
+
* plugins: [powerlines({ name: "example-app", ... })],
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const plugin: (options?: UnpluginExecutionOptions | undefined) => _$rolldown.Plugin<any> | _$rolldown.Plugin<any>[];
|
|
63
|
+
//#endregion
|
|
64
|
+
export { DEFAULT_OPTIONS, createRolldownFactory, plugin as default, resolveOptions };
|
|
65
|
+
//# sourceMappingURL=rolldown.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rolldown.d.cts","names":[],"sources":["../src/rolldown.ts"],"mappings":";;;;;;;;cA4Ca,eAAA;;;;;;;;;;;;;;iBAeG,cAAA,CAAe,OAAA,EAAS,OAAA,GAAU,eAAA;;AAAlD;;;;;;;;;AAuJA;;;;;;;;;;;;iBAAgB,qBAAA,kBAAuC,gBAAA,CAAA,CACrD,OAAA,GAAS,IAAA,CAAK,sBAAA,cACd,QAAA,GAAU,wBAAA,CAAyB,QAAA,IAA8B,eAAA,CAAA,gBAAA,CAA/B,mBAAA,CAA+B,cAAA;;;;;;;;;;;;;;AAsBlE;;cAiBK,MAAA,GAAM,OAAA,GAAgD,wBAAA,iBAAhD,UAAA,CAAA,MAAA,QAAA,UAAA,CAAA,MAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 * as _$rolldown from "rolldown";
|
|
6
|
+
import { RolldownOptions } from "rolldown";
|
|
7
|
+
|
|
8
|
+
//#region src/rolldown.d.ts
|
|
9
|
+
declare const DEFAULT_OPTIONS: {
|
|
10
|
+
keepNames: boolean;
|
|
11
|
+
treeshake: boolean;
|
|
12
|
+
shimMissingExports: boolean;
|
|
13
|
+
transform: {
|
|
14
|
+
target: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Resolves the options for [rolldown](https://rolldown.rs).
|
|
19
|
+
*
|
|
20
|
+
* @param context - The build context.
|
|
21
|
+
* @returns The resolved options.
|
|
22
|
+
*/
|
|
23
|
+
declare function resolveOptions(context: Context): RolldownOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a Rolldown plugin factory that generates a plugin instance.
|
|
26
|
+
*
|
|
27
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // rolldown.config.ts
|
|
32
|
+
* import { createRolldownFactory } from "@powerlines/unplugin/rolldown";
|
|
33
|
+
*
|
|
34
|
+
* const powerlinesPlugin = createRolldownFactory({ name: "example-app", ... });
|
|
35
|
+
*
|
|
36
|
+
* export default defineConfig({
|
|
37
|
+
* plugins: [powerlinesPlugin()],
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param options - The options to create the plugin factory with.
|
|
43
|
+
* @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.
|
|
44
|
+
* @returns A function that generates a Rolldown plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rolldown build.
|
|
45
|
+
*/
|
|
46
|
+
declare function createRolldownFactory<TContext extends ExecutionContext>(options?: Omit<UnpluginFactoryOptions, "variant">, decorate?: UnpluginFactoryDecorator<TContext>): UnpluginFactory<ExecutionContext<_$_powerlines_core0.ResolvedConfig, unknown>>;
|
|
47
|
+
/**
|
|
48
|
+
* A Rolldown plugin that will invoke the Powerlines API hooks during the build process.
|
|
49
|
+
*
|
|
50
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // rolldown.config.ts
|
|
55
|
+
* import powerlines from "@powerlines/unplugin/rolldown";
|
|
56
|
+
*
|
|
57
|
+
* export default defineConfig({
|
|
58
|
+
* plugins: [powerlines({ name: "example-app", ... })],
|
|
59
|
+
* })
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare const plugin: (options?: UnpluginExecutionOptions | undefined) => _$rolldown.Plugin<any> | _$rolldown.Plugin<any>[];
|
|
63
|
+
//#endregion
|
|
64
|
+
export { DEFAULT_OPTIONS, createRolldownFactory, plugin as default, resolveOptions };
|
|
65
|
+
//# sourceMappingURL=rolldown.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rolldown.d.mts","names":[],"sources":["../src/rolldown.ts"],"mappings":";;;;;;;;cA4Ca,eAAA;;;;;;;;;;;;;;iBAeG,cAAA,CAAe,OAAA,EAAS,OAAA,GAAU,eAAA;;AAAlD;;;;;;;;;AAuJA;;;;;;;;;;;;iBAAgB,qBAAA,kBAAuC,gBAAA,CAAA,CACrD,OAAA,GAAS,IAAA,CAAK,sBAAA,cACd,QAAA,GAAU,wBAAA,CAAyB,QAAA,IAA8B,eAAA,CAAA,gBAAA,CAA/B,mBAAA,CAA+B,cAAA;;;;;;;;;;;;;;AAsBlE;;cAiBK,MAAA,GAAM,OAAA,GAAgD,wBAAA,iBAAhD,UAAA,CAAA,MAAA,QAAA,UAAA,CAAA,MAAA"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { createUnpluginFactory } from "./unplugin.mjs";
|
|
2
|
+
import { dtsBundlePlugin } from "./rollup.mjs";
|
|
3
|
+
import { appendPath } from "@stryke/path/append";
|
|
4
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
5
|
+
import { defu as defu$1 } from "defu";
|
|
6
|
+
import { createRolldownPlugin } from "unplugin";
|
|
7
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
8
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
9
|
+
import inject from "@rollup/plugin-inject";
|
|
10
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
11
|
+
import replace from "@rollup/plugin-replace";
|
|
12
|
+
import { globSync } from "glob";
|
|
13
|
+
import { viteAliasPlugin } from "rolldown/experimental";
|
|
14
|
+
import typescriptPlugin from "rollup-plugin-typescript2";
|
|
15
|
+
|
|
16
|
+
//#region src/rolldown.ts
|
|
17
|
+
const DEFAULT_OPTIONS = {
|
|
18
|
+
keepNames: true,
|
|
19
|
+
treeshake: true,
|
|
20
|
+
shimMissingExports: true,
|
|
21
|
+
transform: { target: "esnext" }
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the options for [rolldown](https://rolldown.rs).
|
|
25
|
+
*
|
|
26
|
+
* @param context - The build context.
|
|
27
|
+
* @returns The resolved options.
|
|
28
|
+
*/
|
|
29
|
+
function resolveOptions(context) {
|
|
30
|
+
return defu$1({
|
|
31
|
+
input: globSync(toArray(context.entry).map((entry) => isString(entry) ? entry : entry.file)).flat(),
|
|
32
|
+
external: (source) => {
|
|
33
|
+
if (context.config.resolve.external && toArray(context.config.resolve.external).includes(source)) return true;
|
|
34
|
+
if (context.config.resolve.noExternal && toArray(context.config.resolve.noExternal).includes(source)) return false;
|
|
35
|
+
if (context.builtins.includes(source)) return context.config.projectType !== "application";
|
|
36
|
+
return !context.config.resolve.skipNodeModulesBundle;
|
|
37
|
+
},
|
|
38
|
+
plugins: [
|
|
39
|
+
typescriptPlugin({
|
|
40
|
+
check: false,
|
|
41
|
+
tsconfig: context.tsconfig.tsconfigFilePath
|
|
42
|
+
}),
|
|
43
|
+
context.config.define && Object.keys(context.config.define).length > 0 && replace({
|
|
44
|
+
sourceMap: context.config.mode === "development",
|
|
45
|
+
preventAssignment: true,
|
|
46
|
+
...context.config.define ?? {}
|
|
47
|
+
}),
|
|
48
|
+
context.config.inject && Object.keys(context.config.inject).length > 0 && inject({
|
|
49
|
+
sourceMap: context.config.mode === "development",
|
|
50
|
+
...context.config.inject
|
|
51
|
+
}),
|
|
52
|
+
viteAliasPlugin({ entries: Object.entries(context.alias).reduce((ret, [id, path]) => {
|
|
53
|
+
if (!ret.find((e) => e.find === id)) ret.push({
|
|
54
|
+
find: id,
|
|
55
|
+
replacement: path
|
|
56
|
+
});
|
|
57
|
+
else context.warn(`Duplicate alias entry for '${id}' detected. The first entry will be used.`);
|
|
58
|
+
return ret;
|
|
59
|
+
}, []) }),
|
|
60
|
+
resolve({
|
|
61
|
+
moduleDirectories: ["node_modules"],
|
|
62
|
+
preferBuiltins: true
|
|
63
|
+
}),
|
|
64
|
+
dtsBundlePlugin
|
|
65
|
+
],
|
|
66
|
+
resolve: {
|
|
67
|
+
alias: context.alias,
|
|
68
|
+
mainFields: context.config.resolve.mainFields,
|
|
69
|
+
conditions: context.config.resolve.conditions,
|
|
70
|
+
define: context.config.define,
|
|
71
|
+
extensions: context.config.resolve.extensions
|
|
72
|
+
},
|
|
73
|
+
transform: {
|
|
74
|
+
define: context.config.define,
|
|
75
|
+
inject: context.config.inject,
|
|
76
|
+
typescript: { target: context.tsconfig.tsconfigJson?.compilerOptions?.target }
|
|
77
|
+
},
|
|
78
|
+
platform: context.config.platform,
|
|
79
|
+
tsconfig: appendPath(context.tsconfig.tsconfigFilePath, context.config.cwd),
|
|
80
|
+
cache: !context.config.skipCache ? joinPaths(context.cachePath, "rolldown") : false,
|
|
81
|
+
logLevel: context.config.logLevel.general === "trace" ? "debug" : context.config.logLevel.general === "debug" ? "warn" : "error",
|
|
82
|
+
onLog(level, log) {
|
|
83
|
+
if (log.message?.trim()) if (level === "info") context.logger.debug(log.message?.trim() ?? "");
|
|
84
|
+
else context.logger.log(level, log.message?.trim() ?? "");
|
|
85
|
+
},
|
|
86
|
+
minify: context.config.output.minify,
|
|
87
|
+
output: [{
|
|
88
|
+
dir: context.config.output.path,
|
|
89
|
+
format: "es",
|
|
90
|
+
preserveModules: true,
|
|
91
|
+
sourcemap: context.config.output.sourceMap
|
|
92
|
+
}, {
|
|
93
|
+
dir: context.config.output.path,
|
|
94
|
+
format: "cjs",
|
|
95
|
+
preserveModules: true,
|
|
96
|
+
sourcemap: context.config.output.sourceMap
|
|
97
|
+
}]
|
|
98
|
+
}, DEFAULT_OPTIONS);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a Rolldown plugin factory that generates a plugin instance.
|
|
102
|
+
*
|
|
103
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* // rolldown.config.ts
|
|
108
|
+
* import { createRolldownFactory } from "@powerlines/unplugin/rolldown";
|
|
109
|
+
*
|
|
110
|
+
* const powerlinesPlugin = createRolldownFactory({ name: "example-app", ... });
|
|
111
|
+
*
|
|
112
|
+
* export default defineConfig({
|
|
113
|
+
* plugins: [powerlinesPlugin()],
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @param options - The options to create the plugin factory with.
|
|
119
|
+
* @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.
|
|
120
|
+
* @returns A function that generates a Rolldown plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rolldown build.
|
|
121
|
+
*/
|
|
122
|
+
function createRolldownFactory(options = {}, decorate = (options) => options) {
|
|
123
|
+
return createUnpluginFactory({
|
|
124
|
+
...options,
|
|
125
|
+
variant: "rolldown"
|
|
126
|
+
}, (unplugin) => decorate({
|
|
127
|
+
...unplugin,
|
|
128
|
+
rolldown: { async options(options) {
|
|
129
|
+
const environment = await unplugin.context.getEnvironment();
|
|
130
|
+
return defu$1(resolveOptions(environment), options, unplugin.context.callHook("rolldown:options", { environment }, options) ?? {});
|
|
131
|
+
} }
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A Rolldown plugin that will invoke the Powerlines API hooks during the build process.
|
|
136
|
+
*
|
|
137
|
+
* @see https://rolldown.rs/guide/en/#plugins-overview
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* // rolldown.config.ts
|
|
142
|
+
* import powerlines from "@powerlines/unplugin/rolldown";
|
|
143
|
+
*
|
|
144
|
+
* export default defineConfig({
|
|
145
|
+
* plugins: [powerlines({ name: "example-app", ... })],
|
|
146
|
+
* })
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
const plugin = createRolldownPlugin(createRolldownFactory());
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
export { DEFAULT_OPTIONS, createRolldownFactory, plugin as default, resolveOptions };
|
|
153
|
+
//# sourceMappingURL=rolldown.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rolldown.mjs","names":["defu","alias"],"sources":["../src/rolldown.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 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 { appendPath } from \"@stryke/path/append\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { defu } from \"defu\";\nimport { globSync } from \"glob\";\nimport type { InputOptions } from \"rolldown\";\nimport { RolldownOptions, RollupLog } from \"rolldown\";\nimport { viteAliasPlugin as alias } from \"rolldown/experimental\";\nimport typescriptPlugin from \"rollup-plugin-typescript2\";\nimport { createRolldownPlugin } from \"unplugin\";\nimport { dtsBundlePlugin } from \"./rollup\";\nimport {\n createUnpluginFactory,\n UnpluginFactoryDecorator,\n UnpluginFactoryOptions\n} from \"./unplugin\";\n\nexport const DEFAULT_OPTIONS = {\n keepNames: true,\n treeshake: true,\n shimMissingExports: true,\n transform: {\n target: \"esnext\"\n }\n};\n\n/**\n * Resolves the options for [rolldown](https://rolldown.rs).\n *\n * @param context - The build context.\n * @returns The resolved options.\n */\nexport function resolveOptions(context: Context): RolldownOptions {\n return defu<RolldownOptions, any>(\n {\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 ],\n resolve: {\n alias: context.alias,\n mainFields: context.config.resolve.mainFields,\n conditions: context.config.resolve.conditions,\n define: context.config.define,\n extensions: context.config.resolve.extensions\n },\n transform: {\n define: context.config.define,\n inject: context.config.inject,\n typescript: {\n target: context.tsconfig.tsconfigJson?.compilerOptions?.target\n }\n },\n platform: context.config.platform,\n tsconfig: appendPath(\n context.tsconfig.tsconfigFilePath,\n context.config.cwd\n ),\n cache: !context.config.skipCache\n ? joinPaths(context.cachePath, \"rolldown\")\n : false,\n logLevel:\n context.config.logLevel.general === \"trace\"\n ? \"debug\"\n : context.config.logLevel.general === \"debug\"\n ? \"warn\"\n : \"error\",\n onLog(level: \"info\" | \"debug\" | \"warn\", log: RollupLog) {\n if (log.message?.trim()) {\n if (level === \"info\") {\n context.logger.debug(log.message?.trim() ?? \"\");\n } else {\n context.logger.log(level, log.message?.trim() ?? \"\");\n }\n }\n },\n minify: context.config.output.minify,\n output: [\n {\n dir: context.config.output.path,\n format: \"es\",\n preserveModules: true,\n sourcemap: context.config.output.sourceMap\n },\n {\n dir: context.config.output.path,\n format: \"cjs\",\n preserveModules: true,\n sourcemap: context.config.output.sourceMap\n }\n ]\n },\n DEFAULT_OPTIONS\n );\n}\n\n/**\n * Creates a Rolldown plugin factory that generates a plugin instance.\n *\n * @see https://rolldown.rs/guide/en/#plugins-overview\n *\n * @example\n * ```ts\n * // rolldown.config.ts\n * import { createRolldownFactory } from \"@powerlines/unplugin/rolldown\";\n *\n * const powerlinesPlugin = createRolldownFactory({ 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 Rolldown plugin instance when called. The generated plugin will invoke the Powerlines API hooks during the build process, allowing you to integrate Powerlines into your Rolldown build.\n */\nexport function createRolldownFactory<TContext extends ExecutionContext>(\n options: Omit<UnpluginFactoryOptions, \"variant\"> = {},\n decorate: UnpluginFactoryDecorator<TContext> = options => options\n) {\n return createUnpluginFactory({ ...options, variant: \"rolldown\" }, unplugin =>\n decorate({\n ...(unplugin as UnpluginOptions<TContext>),\n rolldown: {\n async options(options: InputOptions) {\n const environment = await unplugin.context.getEnvironment();\n\n return defu(\n resolveOptions(environment),\n options,\n unplugin.context.callHook(\n \"rolldown:options\",\n { environment },\n options\n ) ?? {}\n );\n }\n }\n })\n );\n}\n\n/**\n * A Rolldown plugin that will invoke the Powerlines API hooks during the build process.\n *\n * @see https://rolldown.rs/guide/en/#plugins-overview\n *\n * @example\n * ```ts\n * // rolldown.config.ts\n * import powerlines from \"@powerlines/unplugin/rolldown\";\n *\n * export default defineConfig({\n * plugins: [powerlines({ name: \"example-app\", ... })],\n * })\n * ```\n */\nconst plugin = createRolldownPlugin(createRolldownFactory());\n\nexport default plugin;\n"],"mappings":"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"}
|
package/dist/rollup.cjs
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
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 defu = require("defu");
|
|
5
|
+
let unplugin = require("unplugin");
|
|
6
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
7
|
+
let _stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
8
|
+
let _rollup_plugin_inject = require("@rollup/plugin-inject");
|
|
9
|
+
_rollup_plugin_inject = require_runtime.__toESM(_rollup_plugin_inject, 1);
|
|
10
|
+
let _rollup_plugin_node_resolve = require("@rollup/plugin-node-resolve");
|
|
11
|
+
_rollup_plugin_node_resolve = require_runtime.__toESM(_rollup_plugin_node_resolve, 1);
|
|
12
|
+
let _rollup_plugin_replace = require("@rollup/plugin-replace");
|
|
13
|
+
_rollup_plugin_replace = require_runtime.__toESM(_rollup_plugin_replace, 1);
|
|
14
|
+
let rollup_plugin_typescript2 = require("rollup-plugin-typescript2");
|
|
15
|
+
rollup_plugin_typescript2 = require_runtime.__toESM(rollup_plugin_typescript2, 1);
|
|
16
|
+
let _rollup_plugin_alias = require("@rollup/plugin-alias");
|
|
17
|
+
_rollup_plugin_alias = require_runtime.__toESM(_rollup_plugin_alias, 1);
|
|
18
|
+
let node_fs = require("node:fs");
|
|
19
|
+
|
|
20
|
+
//#region src/rollup.ts
|
|
21
|
+
/**
|
|
22
|
+
* A Rollup plugin to bundle TypeScript declaration files (.d.ts) alongside the JavaScript output files.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* This plugin generates .d.ts files for each entry point in the bundle, ensuring that type definitions are available for consumers of the library.
|
|
26
|
+
*/
|
|
27
|
+
const dtsBundlePlugin = {
|
|
28
|
+
name: "powerlines:dts-bundle",
|
|
29
|
+
async generateBundle(_opts, bundle) {
|
|
30
|
+
for (const [, file] of Object.entries(bundle)) {
|
|
31
|
+
if (file.type === "asset" || !file.isEntry || file.facadeModuleId == null) continue;
|
|
32
|
+
const dtsFileName = file.fileName.replace(/(?:\.cjs|\.mjs|\.esm\.js|\.cjs\.js|\.mjs\.js|\.js)$/, ".d.ts");
|
|
33
|
+
const relativeSourceDtsName = JSON.stringify(`./${file.facadeModuleId.replace(/\.[cm]?[jt]sx?$/, "")}`);
|
|
34
|
+
this.emitFile({
|
|
35
|
+
type: "asset",
|
|
36
|
+
fileName: dtsFileName,
|
|
37
|
+
source: file.exports.includes("default") ? `export * from ${relativeSourceDtsName};\nexport { default } from ${relativeSourceDtsName};\n` : `export * from ${relativeSourceDtsName};\n`
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the options for [rollup](https://rollupjs.org).
|
|
44
|
+
*
|
|
45
|
+
* @param context - The build context.
|
|
46
|
+
* @returns The resolved options.
|
|
47
|
+
*/
|
|
48
|
+
function resolveOptions(context) {
|
|
49
|
+
return {
|
|
50
|
+
input: (0, node_fs.globSync)((0, _stryke_convert_to_array.toArray)(context.entry).map((entry) => (0, _stryke_type_checks_is_string.isString)(entry) ? entry : entry.file)).flat(),
|
|
51
|
+
external: (source) => {
|
|
52
|
+
if (context.config.resolve.external && (0, _stryke_convert_to_array.toArray)(context.config.resolve.external).includes(source)) return true;
|
|
53
|
+
if (context.config.resolve.noExternal && (0, _stryke_convert_to_array.toArray)(context.config.resolve.noExternal).includes(source)) return false;
|
|
54
|
+
if (context.builtins.includes(source)) return context.config.projectType !== "application";
|
|
55
|
+
return !context.config.resolve.skipNodeModulesBundle;
|
|
56
|
+
},
|
|
57
|
+
plugins: [
|
|
58
|
+
(0, rollup_plugin_typescript2.default)({
|
|
59
|
+
check: false,
|
|
60
|
+
tsconfig: context.tsconfig.tsconfigFilePath
|
|
61
|
+
}),
|
|
62
|
+
context.config.define && Object.keys(context.config.define).length > 0 && (0, _rollup_plugin_replace.default)({
|
|
63
|
+
sourceMap: context.config.mode === "development",
|
|
64
|
+
preventAssignment: true,
|
|
65
|
+
...context.config.define ?? {}
|
|
66
|
+
}),
|
|
67
|
+
context.config.inject && Object.keys(context.config.inject).length > 0 && (0, _rollup_plugin_inject.default)({
|
|
68
|
+
sourceMap: context.config.mode === "development",
|
|
69
|
+
...context.config.inject
|
|
70
|
+
}),
|
|
71
|
+
(0, _rollup_plugin_alias.default)({ entries: Object.entries(context.alias).reduce((ret, [id, path]) => {
|
|
72
|
+
if (!ret.find((e) => e.find === id)) ret.push({
|
|
73
|
+
find: id,
|
|
74
|
+
replacement: path
|
|
75
|
+
});
|
|
76
|
+
else context.warn(`Duplicate alias entry for '${id}' detected. The first entry will be used.`);
|
|
77
|
+
return ret;
|
|
78
|
+
}, []) }),
|
|
79
|
+
(0, _rollup_plugin_node_resolve.default)({
|
|
80
|
+
moduleDirectories: ["node_modules"],
|
|
81
|
+
preferBuiltins: true
|
|
82
|
+
}),
|
|
83
|
+
dtsBundlePlugin
|
|
84
|
+
].filter(Boolean),
|
|
85
|
+
cache: !context.config.skipCache ? void 0 : false,
|
|
86
|
+
logLevel: context.config.logLevel.general === "trace" ? "debug" : context.config.logLevel.general === "debug" ? "warn" : "silent",
|
|
87
|
+
output: [{
|
|
88
|
+
dir: context.config.output.path,
|
|
89
|
+
format: "es",
|
|
90
|
+
entryFileNames: "[name].js",
|
|
91
|
+
preserveModules: true,
|
|
92
|
+
sourcemap: context.config.output.sourceMap
|
|
93
|
+
}, {
|
|
94
|
+
dir: context.config.output.path,
|
|
95
|
+
format: "cjs",
|
|
96
|
+
entryFileNames: "[name].cjs",
|
|
97
|
+
preserveModules: true,
|
|
98
|
+
sourcemap: context.config.output.sourceMap
|
|
99
|
+
}]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates a Rollup plugin factory that generates a plugin instance.
|
|
104
|
+
*
|
|
105
|
+
* @see https://rollupjs.org/guide/en/#plugins-overview
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* // rollup.config.ts
|
|
110
|
+
* import { createRollupFactory } from "@powerlines/unplugin/rollup";
|
|
111
|
+
*
|
|
112
|
+
* const powerlinesPlugin = createRollupFactory({ name: "example-app", ... });
|
|
113
|
+
*
|
|
114
|
+
* export default defineConfig({
|
|
115
|
+
* plugins: [powerlinesPlugin()],
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @param options - The options to create the plugin factory with.
|
|
121
|
+
* @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.
|
|
122
|
+
* @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.
|
|
123
|
+
*/
|
|
124
|
+
function createRollupFactory(options = {}, decorate = (options) => options) {
|
|
125
|
+
return require_unplugin.createUnpluginFactory({
|
|
126
|
+
...options,
|
|
127
|
+
variant: "rollup"
|
|
128
|
+
}, (unplugin$1) => decorate({
|
|
129
|
+
...unplugin$1,
|
|
130
|
+
rollup: { async options(opts) {
|
|
131
|
+
const environment = await unplugin$1.context.getEnvironment();
|
|
132
|
+
return (0, defu.defu)(resolveOptions(environment), opts, unplugin$1.context.callHook("rollup:options", { environment }, opts) ?? {});
|
|
133
|
+
} }
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A Rollup plugin that will invoke the Powerlines API hooks during the build process.
|
|
138
|
+
*
|
|
139
|
+
* @see https://rollupjs.org/guide/en/#plugins-overview
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* // rollup.config.ts
|
|
144
|
+
*
|
|
145
|
+
* import powerlines from "@powerlines/unplugin/rollup";
|
|
146
|
+
*
|
|
147
|
+
* export default defineConfig({
|
|
148
|
+
* plugins: [powerlines({ name: "example-app", ... })],
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
const plugin = (0, unplugin.createRollupPlugin)(createRollupFactory());
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
exports.createRollupFactory = createRollupFactory;
|
|
156
|
+
exports.default = plugin;
|
|
157
|
+
exports.plugin = plugin;
|
|
158
|
+
exports.dtsBundlePlugin = dtsBundlePlugin;
|
|
159
|
+
exports.resolveOptions = resolveOptions;
|