@ogs-gmbh/rolldown-plugin-package-json 1.0.1 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0](https://github.com/OGS-GmbH/rolldown-plugin-package-json/compare/v1.0.1...v1.1.0) (2026-04-01)
4
+
5
+
6
+ ### Features
7
+
8
+ * add global override api ([8f93c93](https://github.com/OGS-GmbH/rolldown-plugin-package-json/commit/8f93c9336876674f7346615e86fc9de85ca4cf62))
9
+
3
10
  ## [1.0.1](https://github.com/OGS-GmbH/rolldown-plugin-package-json/compare/v1.0.0...v1.0.1) (2026-03-31)
4
11
 
5
12
 
@@ -22,19 +22,22 @@ function packageJsonPlugin(options) {
22
22
  encoding: "utf8",
23
23
  flag: "r"
24
24
  });
25
- const meta = JSON.parse(metaContent);
25
+ let meta = JSON.parse(metaContent);
26
26
  if (isEnabled(options?.clean)) (typeof options?.clean === "boolean" ? defaultCleanProperties : options?.clean?.properties ? options.clean.properties : defaultCleanProperties).map((property) => {
27
27
  delete meta[property];
28
28
  });
29
- if (isEnabled(options?.exports) && typeof options?.exports !== "boolean" && options?.exports?.override) meta.exports = options.exports.override;
30
29
  return {
31
30
  name: "package-json-plugin",
32
31
  generateBundle: async function(_outputOptions, bundle) {
33
- if (isEnabled(options?.exports) && (typeof options?.exports === "boolean" || options?.exports?.override === void 0)) {
32
+ if (options?.exports) {
34
33
  const generatedExports = getExportsFromBundle.call(this, bundle);
35
34
  if (meta.exports) meta.exports = merge(meta.exports, generatedExports);
36
35
  else meta.exports = generatedExports;
37
36
  }
37
+ if (options?.override) meta = {
38
+ ...meta,
39
+ ...options.override
40
+ };
38
41
  const finalMetaContent = JSON.stringify(meta, null, 2);
39
42
  this.emitFile({
40
43
  type: "asset",
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","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.js\";\nimport { defaultCleanProperties } from \"./options.js\";\nimport { Options } from \"./types.js\";\nimport { isEnabled } from \"./utils.js\";\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 };\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;;EAEL"}
1
+ {"version":3,"file":"plugin.js","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.js\";\nimport { defaultCleanProperties } from \"./options.js\";\nimport { Options } from \"./types.js\";\nimport { isEnabled } from \"./utils.js\";\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 const metaContent = fs.readFileSync(metaPath, { encoding: \"utf8\", flag: \"r\" });\n let 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 return {\n name: \"package-json-plugin\",\n generateBundle: async function (\n this: PluginContext,\n _outputOptions: NormalizedOutputOptions,\n bundle: OutputBundle\n ): Promise<void> {\n if (options?.exports) {\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 if (options?.override) {\n meta = {\n ...meta,\n ...options.override\n };\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 };\n}\n\nexport { packageJsonPlugin };\n"],"mappings":";;;;;;;AAUA,MAAM,WAAmB;;;;;;;;;;;AAYzB,SAAS,kBAAkB,SAA2B;CACpD,MAAM,WAAW,KAAK,KAAK,QAAQ,KAAK,EAAE,SAAS;CACnD,MAAM,cAAc,GAAG,aAAa,UAAU;EAAE,UAAU;EAAQ,MAAM;EAAK,CAAC;CAC9E,IAAI,OAAO,KAAK,MAAM,YAAY;AAElC,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,QAAO;EACL,MAAM;EACN,gBAAgB,eAEd,gBACA,QACe;AACf,OAAI,SAAS,SAAS;IACpB,MAAM,mBAAmB,qBAAqB,KAAK,MAAM,OAAO;AAEhE,QAAI,KAAK,QAEP,MAAK,UAAU,MAAM,KAAK,SAAS,iBAAiB;QAC/C,MAAK,UAAU;;AAGxB,OAAI,SAAS,SACX,QAAO;IACL,GAAG;IACH,GAAG,QAAQ;IACZ;GAGH,MAAM,mBAAmB,KAAK,UAAU,MAAM,MAAM,EAAE;AAEtD,QAAK,SAAS;IACZ,MAAM;IACN;IACA,kBAAkB;IAClB,QAAQ;IACT,CAAC;;EAEL"}
@@ -29,36 +29,27 @@ type CleanOption = {
29
29
  properties: string[];
30
30
  };
31
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.
32
+ * 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.
33
33
  *
34
34
  * @since 1.0.0
35
35
  * @author Simon Kovtyk
36
36
  * @category Types
37
37
  */
38
- type ExportsOption = {
38
+ type Options = Partial<{
39
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.
40
+ * An object representing the properties to be overridden in the generated `package.json` file. The properties specified in this object will take precedence over the default values and any values inherited from the root `package.json` file.
41
41
  *
42
- * @since 1.0.0
42
+ * @since 1.1.0
43
43
  * @author Simon Kovtyk
44
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<{
45
+ override: PackageJson;
55
46
  /**
56
47
  * Options for the `exports` feature of the plugin. See {@link ExportsOption} for more details.
57
48
  *
58
49
  * @since 1.0.0
59
50
  * @author Simon Kovtyk
60
51
  */
61
- exports: boolean | WithEnabled<ExportsOption>;
52
+ exports: boolean;
62
53
  /**
63
54
  * Options for the `clean` feature of the plugin. See {@link CleanOption} for more details.
64
55
  *
@@ -68,5 +59,5 @@ type Options = Partial<{
68
59
  clean: boolean | WithEnabled<CleanOption>;
69
60
  }>;
70
61
  //#endregion
71
- export { type CleanOption, type ExportsOption, type Options, type WithEnabled };
62
+ export { type CleanOption, type Options, type WithEnabled };
72
63
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","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"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;;AAAwC;;;;;KASnC,WAAA,MAAiB,CAAA;EAAM,OAAA;AAAA;;AAAO;;;;;AAiBvB;KARP,WAAA;;;;;;;;EAQH,UAAA;AAAA;;;;;;;;KAUG,OAAA,GAAU,OAAA;;;;;;;EAOb,QAAA,EAAU,WAAA;;;;;;;EAOV,OAAA;;;;;;;EAOA,KAAA,YAAiB,WAAA,CAAY,WAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ogs-gmbh/rolldown-plugin-package-json",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "A powerful and flexible plugin for Rolldown that enhances package.json handling.",
5
5
  "keywords": [
6
6
  "build-automation",
@@ -48,25 +48,21 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "es-toolkit": "^1.45.1"
51
+ "es-toolkit": "^1.45.1",
52
+ "rolldown": "1.0.0-rc.12"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@commitlint/cli": "^20.5.0",
55
56
  "@commitlint/config-conventional": "^20.5.0",
56
57
  "@commitlint/prompt-cli": "^20.5.0",
57
- "@eslint/json": "^0.14.0",
58
- "@eslint/markdown": "^7.5.1",
59
- "@ogs-gmbh/linter": "^2.0.5",
60
58
  "@ogs-gmbh/oxlint-presets": "^1.0.4",
61
59
  "@ogs-gmbh/vitepress-plugin-sidebar": "^1.0.3",
62
60
  "@ogs-gmbh/vitepress-theme": "^1.1.0",
63
61
  "@types/node": "^25.5.0",
64
- "eslint": "^9.39.4",
65
62
  "husky": "^9.1.7",
66
63
  "lint-staged": "^16.4.0",
67
64
  "oxfmt": "^0.42.0",
68
65
  "oxlint": "^1.57.0",
69
- "rolldown": "1.0.0-rc.12",
70
66
  "sass-embedded": "^1.98.0",
71
67
  "tsdown": "^0.21.7",
72
68
  "type-fest": "^5.5.0",
@@ -82,7 +78,6 @@
82
78
  "ci:docs:extract:typedoc": "typedoc",
83
79
  "ci:docs:main:vitepress": "bash ./.vitepress/scripts/pre-vitepress.sh && vitepress build .vitepress",
84
80
  "ci:pr:commitlint:main:commitlint": "commitlint",
85
- "ci:pr:lint:main:eslint": "eslint .",
86
81
  "ci:pr:lint:main:oxfmt": "oxfmt --check",
87
82
  "ci:pr:lint:main:oxlint": "oxlint",
88
83
  "commit": "commit",