@ogs-gmbh/rolldown-plugin-package-json 1.0.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 — present OGS Gesellschaft für Datenverarbeitung und Systemberatung mbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ > _We're OGS, check out our work on [github.com/ogs-gmbh](https://github.com/ogs-gmbh)_
2
+
3
+ # package.json Plugin for Rolldown
4
+
5
+ _A powerful and flexible plugin for Rolldown that enhances package.json handling._
6
+
7
+ ![Preview](./docs/preview.avif)
8
+
9
+ <a href="./LICENSE" target="_blank"><img alt="license badge" src="https://img.shields.io/github/license/OGS-GmbH/rolldown-plugin-package-json?color=0f434e&logo=hackthebox&logoColor=000000&labelColor=ffffff" /></a>
10
+ <a href="https://github.com/OGS-GmbH/rolldown-plugin-package-json/actions/workflows/main-trusted-deploy.yml" target="_blank"><img alt="workflow badge" src="https://img.shields.io/github/actions/workflow/status/OGS-GmbH/rolldown-plugin-package-json/main-trusted-deploy.yml?color=0f434e&logo=rocket&logoColor=000000&labelColor=ffffff" /></a>
11
+ <a href="https://www.npmjs.com/package/@ogs-gmbh/rolldown-plugin-package-json" target="_blank"><img alt="npm badge" src="https://img.shields.io/npm/v/%40ogs-gmbh%2Frolldown-plugin-package-json?color=0f434e&logo=npm&logoColor=000000&labelColor=ffffff" /></a>
12
+
13
+ - **Package Transformation**\
14
+ Automated copying and modification of `package.json`, allowing selective removal of fields to produce a clean, production-ready manifest.
15
+
16
+ - **Dynamic Exports Generation**\
17
+ Automatically generates `exports` maps based on build outputs, ensuring correct module resolution for ESM and CommonJS environments.
18
+
19
+ - **Dependency Optimization**\
20
+ Integrates with the build pipeline to control dependency handling and reduce unnecessary bundle inclusion.
21
+
22
+ - **Build-Time Integration**\
23
+ Seamlessly hooks into the Rolldown lifecycle to perform transformations efficiently during the build process.
24
+
25
+ ## Getting Started
26
+
27
+ > [!IMPORTANT]
28
+ > We're offering an extensive API-Reference covered with in-depth usage examples of this project.
29
+
30
+ To get a starting point, simply refer to our documentation at [ogs-gmbh.github.io/rolldown-plugin-package-json](https://ogs-gmbh.github.io/rolldown-plugin-package-json).
31
+
32
+ ### Prerequisites
33
+
34
+ - Node.js version 18 or higher
35
+ - A package manager: e.g. npm, pnpm, ...
36
+
37
+ ### Installation
38
+
39
+ Using npm:
40
+
41
+ ```sh
42
+ $ npm add -D @ogs-gmbh/rolldown-plugin-package-json
43
+ ```
44
+
45
+ <details>
46
+ <summary>Using a different package manager?</summary>
47
+ <br/>
48
+
49
+ Using yarn:
50
+ ```sh
51
+ $ pnpm add -D @ogs-gmbh/rolldown-plugin-package-json
52
+ ```
53
+
54
+ Using pnpm:
55
+ ```sh
56
+ $ pnpm add -D @ogs-gmbh/rolldown-plugin-package-json
57
+ ```
58
+
59
+ Using bun:
60
+ ```sh
61
+ $ bun add -D @ogs-gmbh/rolldown-plugin-package-json
62
+ ```
63
+
64
+ </details>
65
+
66
+ ### Usage
67
+
68
+ `rolldown-plugin-package-json` can be integrated with either [`tsdown`](https://tsdown.dev/) or [`Rolldown`](https://rolldown.rs/). Here's an example showing the usage of this plugin with `tsdown`. You can get a deeper understanding about this plugin by taking a look into the [reference](https://ogs-gmbh.github.io/rolldown-plugin-package-json/reference).
69
+
70
+ ```ts
71
+ import { defineConfig } from "tsdown";
72
+ import { packageJsonPlugin } from "@ogs-gmbh/rolldown-plugin-package-json";
73
+
74
+ export default defineConfig({
75
+ entry: "src/**/*.ts",
76
+ dts: true,
77
+ outDir: "dist/main",
78
+ unbundle: true,
79
+ plugins: [
80
+ packageJsonPlugin({
81
+ clean: true,
82
+ exports: {
83
+ enabled: true,
84
+ override: { ".": "./public-api.mjs", "./feature-a": "feature-a.mjs" }
85
+ }
86
+ })
87
+ ]
88
+ });
89
+ ```
90
+
91
+ ## License
92
+
93
+ The MIT License (MIT) - Please have a look at the [LICENSE file](./LICENSE) for more details.
94
+
95
+ ## Contributing
96
+
97
+ Contributions are always welcome and greatly appreciated. Whether you want to report a bug, suggest a new feature, or improve the documentation, your input helps make the project better for everyone.
98
+
99
+ Feel free to submit a pull request, issue or feature request.
100
+
101
+ ### Issues and Feature Requests
102
+
103
+ Reporting an issue or creating a feature request is made by creating a new issue on this repository.
104
+
105
+ You can create a [new issue or feature request here](../../issues/new/choose).
106
+
107
+ ### Pull Requests
108
+
109
+ GitHub offers a solid guideline for contributing to open source projects through pull requests, covering key practices. These best practices provide a reliable starting point for making effective contributions.
110
+
111
+ You can find the [guidelines here](https://docs.github.com/get-started/exploring-projects-on-github/contributing-to-a-project).
112
+
113
+ ### Code Of Conduct
114
+
115
+ We are committed to keeping a welcoming, inclusive, and respectful community for everyone. To help us achieve this, we kindly ask that you adhere to our [Code of Conduct](./CODE_OF_CONDUCT.md).
116
+
117
+ ## Disclaimer
118
+
119
+ All trademarks and registered trademarks mentioned are property of their respective owners and are used for identification purposes only. Use of these names does not imply endorsement or affiliation.
120
+
121
+ This project is a trademark of OGS Gesellschaft für Datenverarbeitung und Systemberatung mbH. The License does not grant rights to use the trademark without permission.
122
+
123
+ ---
124
+
125
+ <a href="https://www.ogs.de/en/">
126
+ <picture>
127
+ <source
128
+ srcset="https://raw.githubusercontent.com/OGS-GmbH/.github/refs/tags/v1.0.0/docs/assets/logo/light.svg"
129
+ media="(prefers-color-scheme: dark)"
130
+ />
131
+ <img height="64" alt="OGS Logo" src="https://raw.githubusercontent.com/OGS-GmbH/.github/refs/tags/v1.0.0/docs/assets/logo/dark.svg"
132
+ </picture>
133
+ </a>
134
+
135
+ Gesellschaft für Datenverarbeitung und Systemberatung mbH
136
+
137
+ [Imprint](https://www.ogs.de/en/imprint/) | [Contact](https://www.ogs.de/en/contact/) | [Careers](https://www.ogs.de/en/about-ogs/#Careers)
@@ -0,0 +1,8 @@
1
+ import { OutputBundle, PluginContext } from "rolldown";
2
+ import { PackageJson } from "type-fest";
3
+
4
+ //#region src/exports.d.ts
5
+ declare function getExportsFromBundle(this: PluginContext, bundle: OutputBundle): PackageJson.Exports;
6
+ //#endregion
7
+ export { getExportsFromBundle };
8
+ //# sourceMappingURL=exports.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.d.mts","names":[],"sources":["../../src/exports.ts"],"mappings":";;;;iBAgBS,oBAAA,CAAqB,IAAA,EAAM,aAAA,EAAe,MAAA,EAAQ,YAAA,GAAe,WAAA,CAAY,OAAA"}
@@ -0,0 +1,48 @@
1
+ import path from "node:path";
2
+ //#region src/exports.ts
3
+ const fileExtensionToField = {
4
+ ".js": "default",
5
+ ".mjs": "import",
6
+ ".cjs": "require",
7
+ ".ts": "default",
8
+ ".mts": "import",
9
+ ".cts": "require"
10
+ };
11
+ const declarationMarker = ".d";
12
+ const relativeMarker = "./";
13
+ function getExportsFromBundle(bundle) {
14
+ const files = {};
15
+ for (const [name, content] of Object.entries(bundle)) {
16
+ const relativeName = `${relativeMarker}${name}`;
17
+ if (content.type === "asset") {
18
+ files[relativeName] = relativeName;
19
+ continue;
20
+ }
21
+ const parsedPath = path.parse(name);
22
+ if (parsedPath.name.endsWith(declarationMarker)) {
23
+ const relativeVirtualPath = `${relativeMarker}${parsedPath.name.slice(0, -2)}`;
24
+ const currentFile = files[relativeVirtualPath];
25
+ files[relativeVirtualPath] = {
26
+ ...typeof currentFile === "object" ? currentFile : {},
27
+ types: relativeName
28
+ };
29
+ continue;
30
+ }
31
+ const relativeVirtualPath = `${relativeMarker}${parsedPath.name}`;
32
+ const currentFile = files[relativeVirtualPath];
33
+ const field = fileExtensionToField[parsedPath.ext];
34
+ if (field === void 0) {
35
+ this.warn(`Bundle file '${name}' doesn't match any export rule and is ignored.`);
36
+ continue;
37
+ }
38
+ files[relativeVirtualPath] = {
39
+ ...typeof currentFile === "object" ? currentFile : {},
40
+ [field]: relativeName
41
+ };
42
+ }
43
+ return files;
44
+ }
45
+ //#endregion
46
+ export { getExportsFromBundle };
47
+
48
+ //# sourceMappingURL=exports.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.mjs","names":[],"sources":["../../src/exports.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { OutputBundle, PluginContext } from \"rolldown\";\nimport { PackageJson } from \"type-fest\";\n\nconst fileExtensionToField: Record<string, keyof PackageJson.ExportConditions> = {\n \".js\": \"default\",\n \".mjs\": \"import\",\n \".cjs\": \"require\",\n \".ts\": \"default\",\n \".mts\": \"import\",\n \".cts\": \"require\"\n};\n\nconst declarationMarker = \".d\";\nconst relativeMarker = \"./\";\n\nfunction getExportsFromBundle(this: PluginContext, bundle: OutputBundle): PackageJson.Exports {\n const files: PackageJson.Exports = {};\n\n for (const [name, content] of Object.entries(bundle)) {\n const relativeName = `${relativeMarker}${name}`;\n\n if (content.type === \"asset\") {\n files[relativeName] = relativeName;\n\n continue;\n }\n\n const parsedPath = path.parse(name);\n\n // If we found a declaration file, we need to handle it differently\n if (parsedPath.name.endsWith(declarationMarker)) {\n const relativeVirtualPath = `${relativeMarker}${parsedPath.name.slice(0, -2)}`;\n const currentFile = files[relativeVirtualPath];\n\n files[relativeVirtualPath] = {\n ...(typeof currentFile === \"object\" ? currentFile : {}),\n types: relativeName\n };\n\n continue;\n }\n\n const relativeVirtualPath = `${relativeMarker}${parsedPath.name}`;\n const currentFile = files[relativeVirtualPath];\n const field = fileExtensionToField[parsedPath.ext];\n\n if (field === undefined) {\n this.warn(`Bundle file '${name}' doesn't match any export rule and is ignored.`);\n continue;\n }\n\n files[relativeVirtualPath] = {\n ...(typeof currentFile === \"object\" ? currentFile : {}),\n [field]: relativeName\n };\n }\n\n return files;\n}\n\nexport { getExportsFromBundle };\n"],"mappings":";;AAIA,MAAM,uBAA2E;CAC/E,OAAO;CACP,QAAQ;CACR,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,QAAQ;CACT;AAED,MAAM,oBAAoB;AAC1B,MAAM,iBAAiB;AAEvB,SAAS,qBAA0C,QAA2C;CAC5F,MAAM,QAA6B,EAAE;AAErC,MAAK,MAAM,CAAC,MAAM,YAAY,OAAO,QAAQ,OAAO,EAAE;EACpD,MAAM,eAAe,GAAG,iBAAiB;AAEzC,MAAI,QAAQ,SAAS,SAAS;AAC5B,SAAM,gBAAgB;AAEtB;;EAGF,MAAM,aAAa,KAAK,MAAM,KAAK;AAGnC,MAAI,WAAW,KAAK,SAAS,kBAAkB,EAAE;GAC/C,MAAM,sBAAsB,GAAG,iBAAiB,WAAW,KAAK,MAAM,GAAG,GAAG;GAC5E,MAAM,cAAc,MAAM;AAE1B,SAAM,uBAAuB;IAC3B,GAAI,OAAO,gBAAgB,WAAW,cAAc,EAAE;IACtD,OAAO;IACR;AAED;;EAGF,MAAM,sBAAsB,GAAG,iBAAiB,WAAW;EAC3D,MAAM,cAAc,MAAM;EAC1B,MAAM,QAAQ,qBAAqB,WAAW;AAE9C,MAAI,UAAU,KAAA,GAAW;AACvB,QAAK,KAAK,gBAAgB,KAAK,iDAAiD;AAChF;;AAGF,QAAM,uBAAuB;GAC3B,GAAI,OAAO,gBAAgB,WAAW,cAAc,EAAE;IACrD,QAAQ;GACV;;AAGH,QAAO"}
@@ -0,0 +1,5 @@
1
+ //#region src/options.d.ts
2
+ declare const defaultCleanProperties: string[];
3
+ //#endregion
4
+ export { defaultCleanProperties };
5
+ //# sourceMappingURL=options.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.mts","names":[],"sources":["../../src/options.ts"],"mappings":";cAAM,sBAAA"}
@@ -0,0 +1,10 @@
1
+ //#region src/options.ts
2
+ const defaultCleanProperties = [
3
+ "scripts",
4
+ "packageManager",
5
+ "publishConfig"
6
+ ];
7
+ //#endregion
8
+ export { defaultCleanProperties };
9
+
10
+ //# sourceMappingURL=options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.mjs","names":[],"sources":["../../src/options.ts"],"sourcesContent":["const defaultCleanProperties: string[] = [\"scripts\", \"packageManager\", \"publishConfig\"];\n\nexport { defaultCleanProperties };\n"],"mappings":";AAAA,MAAM,yBAAmC;CAAC;CAAW;CAAkB;CAAgB"}
@@ -0,0 +1,18 @@
1
+ import { Options } from "./types";
2
+ import { Plugin } from "rolldown";
3
+
4
+ //#region src/plugin.d.ts
5
+ /**
6
+ * A Rollup plugin that generates a `package.json` file based on your root `package.json` and the generated bundle.
7
+ *
8
+ * @param options - An optional object to configure {@link Options} for the plugin's behavior.
9
+ * @returns A Rollup plugin that generates a `package.json` file.
10
+ *
11
+ * @since 1.0.0
12
+ * @author Simon Kovtyk
13
+ * @category Plugin
14
+ */
15
+ declare function packageJsonPlugin(options?: Options): Plugin;
16
+ //#endregion
17
+ export { packageJsonPlugin };
18
+ //# sourceMappingURL=plugin.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/plugin.ts"],"mappings":";;;;;;AAOkC;;;;;;;;iBAezB,iBAAA,CAAkB,OAAA,GAAU,OAAA,GAAU,MAAA"}
@@ -0,0 +1,54 @@
1
+ import path from "node:path";
2
+ import fs from "node:fs";
3
+ import { merge } from "es-toolkit";
4
+ import { getExportsFromBundle } from "./exports";
5
+ import { defaultCleanProperties } from "./options";
6
+ import { isEnabled } from "./utils";
7
+ //#region src/plugin.ts
8
+ const fileName = "package.json";
9
+ /**
10
+ * A Rollup plugin that generates a `package.json` file based on your root `package.json` and the generated bundle.
11
+ *
12
+ * @param options - An optional object to configure {@link Options} for the plugin's behavior.
13
+ * @returns A Rollup plugin that generates a `package.json` file.
14
+ *
15
+ * @since 1.0.0
16
+ * @author Simon Kovtyk
17
+ * @category Plugin
18
+ */
19
+ function packageJsonPlugin(options) {
20
+ const metaPath = path.join(process.cwd(), fileName);
21
+ const metaContent = fs.readFileSync(metaPath, {
22
+ encoding: "utf8",
23
+ flag: "r"
24
+ });
25
+ const meta = JSON.parse(metaContent);
26
+ if (isEnabled(options?.clean)) (typeof options?.clean === "boolean" ? defaultCleanProperties : options?.clean?.properties ? options.clean.properties : defaultCleanProperties).map((property) => {
27
+ delete meta[property];
28
+ });
29
+ if (isEnabled(options?.exports) && typeof options?.exports !== "boolean" && options?.exports?.override) meta.exports = options.exports.override;
30
+ return {
31
+ name: "package-json-plugin",
32
+ generateBundle: async function(_outputOptions, bundle) {
33
+ if (isEnabled(options?.exports) && (typeof options?.exports === "boolean" || options?.exports?.override === void 0)) {
34
+ const generatedExports = getExportsFromBundle.call(this, bundle);
35
+ if (meta.exports) meta.exports = merge(meta.exports, generatedExports);
36
+ else meta.exports = generatedExports;
37
+ }
38
+ const finalMetaContent = JSON.stringify(meta, null, 2);
39
+ this.emitFile({
40
+ type: "asset",
41
+ fileName,
42
+ originalFileName: metaPath,
43
+ source: finalMetaContent
44
+ });
45
+ },
46
+ buildEnd: function() {
47
+ this.info("'package.json' successfully created!");
48
+ }
49
+ };
50
+ }
51
+ //#endregion
52
+ export { packageJsonPlugin };
53
+
54
+ //# sourceMappingURL=plugin.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/plugin.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { merge } from \"es-toolkit\";\nimport type { NormalizedOutputOptions, OutputBundle, Plugin, PluginContext } from \"rolldown\";\nimport { PackageJson } from \"type-fest\";\nimport { getExportsFromBundle } from \"./exports\";\nimport { defaultCleanProperties } from \"./options\";\nimport { Options } from \"./types\";\nimport { isEnabled } from \"./utils\";\n\nconst fileName: string = \"package.json\";\n\n/**\n * A Rollup plugin that generates a `package.json` file based on your root `package.json` and the generated bundle.\n *\n * @param options - An optional object to configure {@link Options} for the plugin's behavior.\n * @returns A Rollup plugin that generates a `package.json` file.\n *\n * @since 1.0.0\n * @author Simon Kovtyk\n * @category Plugin\n */\nfunction packageJsonPlugin(options?: Options): Plugin {\n const metaPath = path.join(process.cwd(), fileName);\n\n const metaContent = fs.readFileSync(metaPath, { encoding: \"utf8\", flag: \"r\" });\n\n const meta = JSON.parse(metaContent) as PackageJson;\n\n if (isEnabled(options?.clean)) {\n const properties =\n typeof options?.clean === \"boolean\"\n ? defaultCleanProperties\n : options?.clean?.properties\n ? options.clean.properties\n : defaultCleanProperties;\n\n properties.map((property) => {\n delete meta[property];\n });\n }\n\n if (\n isEnabled(options?.exports) &&\n typeof options?.exports !== \"boolean\" &&\n options?.exports?.override\n )\n meta.exports = options.exports.override;\n\n return {\n name: \"package-json-plugin\",\n generateBundle: async function (\n this: PluginContext,\n _outputOptions: NormalizedOutputOptions,\n bundle: OutputBundle\n ): Promise<void> {\n if (\n isEnabled(options?.exports) &&\n (typeof options?.exports === \"boolean\" || options?.exports?.override === undefined)\n ) {\n const generatedExports = getExportsFromBundle.call(this, bundle);\n\n if (meta.exports) {\n // @ts-ignore\n meta.exports = merge(meta.exports, generatedExports);\n } else meta.exports = generatedExports;\n }\n\n const finalMetaContent = JSON.stringify(meta, null, 2);\n\n this.emitFile({\n type: \"asset\",\n fileName,\n originalFileName: metaPath,\n source: finalMetaContent\n });\n },\n buildEnd: function (this: PluginContext) {\n this.info(\"'package.json' successfully created!\");\n }\n };\n}\n\nexport { packageJsonPlugin };\n"],"mappings":";;;;;;;AAUA,MAAM,WAAmB;;;;;;;;;;;AAYzB,SAAS,kBAAkB,SAA2B;CACpD,MAAM,WAAW,KAAK,KAAK,QAAQ,KAAK,EAAE,SAAS;CAEnD,MAAM,cAAc,GAAG,aAAa,UAAU;EAAE,UAAU;EAAQ,MAAM;EAAK,CAAC;CAE9E,MAAM,OAAO,KAAK,MAAM,YAAY;AAEpC,KAAI,UAAU,SAAS,MAAM,CAQ3B,EANE,OAAO,SAAS,UAAU,YACtB,yBACA,SAAS,OAAO,aACd,QAAQ,MAAM,aACd,wBAEG,KAAK,aAAa;AAC3B,SAAO,KAAK;GACZ;AAGJ,KACE,UAAU,SAAS,QAAQ,IAC3B,OAAO,SAAS,YAAY,aAC5B,SAAS,SAAS,SAElB,MAAK,UAAU,QAAQ,QAAQ;AAEjC,QAAO;EACL,MAAM;EACN,gBAAgB,eAEd,gBACA,QACe;AACf,OACE,UAAU,SAAS,QAAQ,KAC1B,OAAO,SAAS,YAAY,aAAa,SAAS,SAAS,aAAa,KAAA,IACzE;IACA,MAAM,mBAAmB,qBAAqB,KAAK,MAAM,OAAO;AAEhE,QAAI,KAAK,QAEP,MAAK,UAAU,MAAM,KAAK,SAAS,iBAAiB;QAC/C,MAAK,UAAU;;GAGxB,MAAM,mBAAmB,KAAK,UAAU,MAAM,MAAM,EAAE;AAEtD,QAAK,SAAS;IACZ,MAAM;IACN;IACA,kBAAkB;IAClB,QAAQ;IACT,CAAC;;EAEJ,UAAU,WAA+B;AACvC,QAAK,KAAK,uCAAuC;;EAEpD"}
@@ -0,0 +1,2 @@
1
+ export * from "./plugin";
2
+ export * from "./types";
@@ -0,0 +1,3 @@
1
+ export * from "./plugin";
2
+ export * from "./types";
3
+ export {};
@@ -0,0 +1,72 @@
1
+ import { PackageJson } from "type-fest";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * A type that represents an object with an `enabled` property, which can be used to conditionally enable or disable certain features or options.
6
+ *
7
+ * @since 1.0.0
8
+ * @author Simon Kovtyk
9
+ * @category Types
10
+ */
11
+ type WithEnabled<T> = T & {
12
+ enabled: boolean;
13
+ };
14
+ /**
15
+ * Options for the `clean` feature of the plugin, which allows you to specify which properties should be removed from the generated `package.json` file.
16
+ *
17
+ * @since 1.0.0
18
+ * @author Simon Kovtyk
19
+ * @category Types
20
+ */
21
+ type CleanOption = {
22
+ /**
23
+ * An array of strings representing the properties to be removed from the generated `package.json` file. If not provided, a default set of properties will be removed.
24
+ * @default ["scripts", "packageManager", "publishConfig"]
25
+ *
26
+ * @since 1.0.0
27
+ * @author Simon Kovtyk
28
+ */
29
+ properties: string[];
30
+ };
31
+ /**
32
+ * Options for the `exports` feature of the plugin, which allows you to specify a custom `exports` field for the generated `package.json` file.
33
+ *
34
+ * @since 1.0.0
35
+ * @author Simon Kovtyk
36
+ * @category Types
37
+ */
38
+ type ExportsOption = {
39
+ /**
40
+ * An object representing the `exports` field to be included in the generated `package.json` file. This will override any automatically generated `exports` field based on the bundle.
41
+ *
42
+ * @since 1.0.0
43
+ * @author Simon Kovtyk
44
+ */
45
+ override: PackageJson.Exports;
46
+ };
47
+ /**
48
+ * Options for the plugin, which can be used to configure its behavior. Each option can be either a `boolean` to enable/disable the feature or an `Object` with additional configuration.
49
+ *
50
+ * @since 1.0.0
51
+ * @author Simon Kovtyk
52
+ * @category Types
53
+ */
54
+ type Options = Partial<{
55
+ /**
56
+ * Options for the `exports` feature of the plugin. See {@link ExportsOption} for more details.
57
+ *
58
+ * @since 1.0.0
59
+ * @author Simon Kovtyk
60
+ */
61
+ exports: boolean | WithEnabled<ExportsOption>;
62
+ /**
63
+ * Options for the `clean` feature of the plugin. See {@link CleanOption} for more details.
64
+ *
65
+ * @since 1.0.0
66
+ * @author Simon Kovtyk
67
+ */
68
+ clean: boolean | WithEnabled<CleanOption>;
69
+ }>;
70
+ //#endregion
71
+ export { type CleanOption, type ExportsOption, type Options, type WithEnabled };
72
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;;AAAwC;;;;;KASnC,WAAA,MAAiB,CAAA;EAAM,OAAA;AAAA;;AAAO;;;;;AAiBvB;KARP,WAAA;;;;;;;;EAQH,UAAA;AAAA;;;;;;;;KAUG,aAAA;EAiBU;;;;;;EAVb,QAAA,EAAU,WAAA,CAAY,OAAA;AAAA;;;;;;;;KAUnB,OAAA,GAAU,OAAA;;;;;;;EAOb,OAAA,YAAmB,WAAA,CAAY,aAAA;;;;;;;EAO/B,KAAA,YAAiB,WAAA,CAAY,WAAA;AAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { WithEnabled } from "./types";
2
+
3
+ //#region src/utils.d.ts
4
+ declare function isEnabled<T extends boolean | WithEnabled<unknown> | undefined>(option: T): boolean;
5
+ //#endregion
6
+ export { isEnabled };
7
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","names":[],"sources":["../../src/utils.ts"],"mappings":";;;iBAES,SAAA,qBAA8B,WAAA,sBAAA,CAAkC,MAAA,EAAQ,CAAA"}
@@ -0,0 +1,10 @@
1
+ //#region src/utils.ts
2
+ function isEnabled(option) {
3
+ if (option === void 0) return false;
4
+ if (typeof option === "boolean") return option;
5
+ return option.enabled;
6
+ }
7
+ //#endregion
8
+ export { isEnabled };
9
+
10
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../../src/utils.ts"],"sourcesContent":["import { WithEnabled } from \"./types\";\n\nfunction isEnabled<T extends boolean | WithEnabled<unknown> | undefined>(option: T): boolean {\n if (option === undefined) return false;\n\n if (typeof option === \"boolean\") return option;\n\n return option.enabled;\n}\n\nexport { isEnabled };\n"],"mappings":";AAEA,SAAS,UAAgE,QAAoB;AAC3F,KAAI,WAAW,KAAA,EAAW,QAAO;AAEjC,KAAI,OAAO,WAAW,UAAW,QAAO;AAExC,QAAO,OAAO"}
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@ogs-gmbh/rolldown-plugin-package-json",
3
+ "version": "1.0.0",
4
+ "description": "A powerful and flexible plugin for Rolldown that enhances package.json handling.",
5
+ "keywords": [
6
+ "build-automation",
7
+ "build-tool",
8
+ "bundler",
9
+ "cjs",
10
+ "dependency",
11
+ "esm",
12
+ "exports",
13
+ "external",
14
+ "library",
15
+ "module-resolution",
16
+ "node",
17
+ "npm",
18
+ "package.json",
19
+ "packaging",
20
+ "plugin",
21
+ "publish",
22
+ "tooling",
23
+ "transform",
24
+ "tree-shaking",
25
+ "typescript"
26
+ ],
27
+ "homepage": "https://ogs-gmbh.github.io/rolldown-plugin-package-json/",
28
+ "bugs": "https://github.com/OGS-GmbH/rolldown-plugin-package-json/issues",
29
+ "license": "MIT",
30
+ "author": "OGS GmbH",
31
+ "contributors": [
32
+ {
33
+ "name": "Simon Kovtyk",
34
+ "email": "simon@kovtyk.com",
35
+ "url": "https://simonkov.dev"
36
+ }
37
+ ],
38
+ "repository": "https://github.com/OGS-GmbH/rolldown-plugin-package-json",
39
+ "files": [
40
+ "./dist/main"
41
+ ],
42
+ "type": "module",
43
+ "exports": {
44
+ ".": {
45
+ "types": "./dist/main/public-api.d.ts",
46
+ "default": "./dist/main/public-api.mjs"
47
+ }
48
+ },
49
+ "dependencies": {
50
+ "es-toolkit": "^1.45.1"
51
+ },
52
+ "devDependencies": {
53
+ "@commitlint/cli": "^20.5.0",
54
+ "@commitlint/config-conventional": "^20.5.0",
55
+ "@commitlint/prompt-cli": "^20.5.0",
56
+ "@eslint/json": "^0.14.0",
57
+ "@eslint/markdown": "^7.5.1",
58
+ "@ogs-gmbh/linter": "^2.0.5",
59
+ "@ogs-gmbh/oxlint-presets": "^1.0.4",
60
+ "@ogs-gmbh/vitepress-plugin-sidebar": "^1.0.3",
61
+ "@ogs-gmbh/vitepress-theme": "^1.1.0",
62
+ "@types/node": "^25.5.0",
63
+ "eslint": "^9.39.4",
64
+ "husky": "^9.1.7",
65
+ "lint-staged": "^16.4.0",
66
+ "oxfmt": "^0.42.0",
67
+ "oxlint": "^1.57.0",
68
+ "rolldown": "1.0.0-rc.12",
69
+ "sass-embedded": "^1.98.0",
70
+ "tsdown": "^0.21.7",
71
+ "type-fest": "^5.5.0",
72
+ "typedoc": "^0.28.18",
73
+ "typedoc-plugin-frontmatter": "^1.3.1",
74
+ "typedoc-plugin-markdown": "^4.11.0",
75
+ "typescript": "^5.9.3",
76
+ "vitepress": "^1.6.4",
77
+ "vitepress-plugin-group-icons": "^1.7.3"
78
+ },
79
+ "scripts": {
80
+ "ci:build:main:production": "tsdown",
81
+ "ci:docs:extract:typedoc": "typedoc",
82
+ "ci:docs:main:vitepress": "bash ./.vitepress/scripts/pre-vitepress.sh && vitepress build .vitepress",
83
+ "ci:pr:commitlint:main:commitlint": "commitlint",
84
+ "ci:pr:lint:main:eslint": "eslint .",
85
+ "ci:pr:lint:main:oxfmt": "oxfmt --check",
86
+ "ci:pr:lint:main:oxlint": "oxlint",
87
+ "commit": "commit",
88
+ "vitepress": "bash ./.vitepress/scripts/pre-vitepress.sh && vitepress dev .vitepress",
89
+ "vitepress:preview": "vitepress preview .vitepress"
90
+ }
91
+ }