@rsbuild/plugin-toml 0.7.10 → 1.0.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
3
+ Copyright (c) 2024 Rspack Contrib
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,19 +1,82 @@
1
- <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
1
+ # @rsbuild/plugin-toml
2
+
3
+ An Rsbuild plugin to import TOML files and convert them to JavaScript objects.
4
+
5
+ > [TOML](https://toml.io/) is a semantically explicit, easy-to-read configuration file format.
6
+
7
+ <p>
8
+ <a href="https://npmjs.com/package/@rsbuild/plugin-toml">
9
+ <img src="https://img.shields.io/npm/v/@rsbuild/plugin-toml?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" />
10
+ </a>
11
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
3
12
  </p>
4
13
 
5
- # Rsbuild
14
+ ## Usage
15
+
16
+ Install:
17
+
18
+ ```bash
19
+ npm add @rsbuild/plugin-toml -D
20
+ ```
21
+
22
+ Add plugin to your `rsbuild.config.ts`:
23
+
24
+ ```ts
25
+ // rsbuild.config.ts
26
+ import { pluginToml } from "@rsbuild/plugin-toml";
27
+
28
+ export default {
29
+ plugins: [pluginToml()],
30
+ };
31
+ ```
32
+
33
+ ## Example
34
+
35
+ Suppose the project has the following code in `example.toml`:
36
+
37
+ ```toml title="example.toml"
38
+ hello = "world"
39
+
40
+ [foo]
41
+ bar = "baz"
42
+ ```
43
+
44
+ After using the TOML plugin, you can reference it as follows:
45
+
46
+ ```js
47
+ import example from "./example.toml";
48
+
49
+ console.log(example.hello); // 'world';
50
+ console.log(example.foo); // { bar: 'baz' };
51
+ ```
52
+
53
+ ## Options
54
+
55
+ ### esModule
56
+
57
+ By default, `@rsbuild/plugin-toml` generates JS modules that use the ES modules syntax. If you want to generate a CommonJS module, you can set the `esModule` option to `false`.
6
58
 
7
- The Rspack-based build tool. It's fast, out-of-the-box and extensible.
59
+ - Type: `boolean`
60
+ - Default: `true`
61
+ - Example:
8
62
 
9
- ## Documentation
63
+ ```js
64
+ pluginToml({
65
+ exModule: false,
66
+ });
67
+ ```
10
68
 
11
- https://rsbuild.dev/
69
+ ## Type Declaration
12
70
 
13
- ## Contributing
71
+ When you import TOML files in TypeScript code, please create a `src/env.d.ts` file in your project and add the type declarations.
14
72
 
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
73
+ ```ts title="src/env.d.ts"
74
+ declare module "*.toml" {
75
+ const content: Record<string, any>;
76
+ export default content;
77
+ }
78
+ ```
16
79
 
17
80
  ## License
18
81
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
82
+ [MIT](./LICENSE).
package/dist/index.cjs CHANGED
@@ -35,13 +35,15 @@ __export(src_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(src_exports);
37
37
  var PLUGIN_TOML_NAME = "rsbuild:toml";
38
- var pluginToml = () => ({
38
+ var pluginToml = (options = {}) => ({
39
39
  name: PLUGIN_TOML_NAME,
40
40
  async setup(api) {
41
41
  const { parse } = await import("toml");
42
+ const { esModule } = options;
42
43
  api.transform({ test: /\.toml$/ }, ({ code }) => {
43
44
  const parsed = parse(code);
44
- return `module.exports = ${JSON.stringify(parsed, void 0, " ")};`;
45
+ const exportType = esModule ? "export default" : "module.exports =";
46
+ return `${exportType} ${JSON.stringify(parsed, void 0, " ")};`;
45
47
  });
46
48
  }
47
49
  });
@@ -0,0 +1,9 @@
1
+ import { RsbuildPlugin } from '@rsbuild/core';
2
+
3
+ declare const PLUGIN_TOML_NAME = "rsbuild:toml";
4
+ type PluginTomlOptions = {
5
+ esModule?: boolean;
6
+ };
7
+ declare const pluginToml: (options?: PluginTomlOptions) => RsbuildPlugin;
8
+
9
+ export { PLUGIN_TOML_NAME, type PluginTomlOptions, pluginToml };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { RsbuildPlugin } from '@rsbuild/core';
2
2
 
3
3
  declare const PLUGIN_TOML_NAME = "rsbuild:toml";
4
- declare const pluginToml: () => RsbuildPlugin;
4
+ type PluginTomlOptions = {
5
+ esModule?: boolean;
6
+ };
7
+ declare const pluginToml: (options?: PluginTomlOptions) => RsbuildPlugin;
5
8
 
6
- export { PLUGIN_TOML_NAME, pluginToml };
9
+ export { PLUGIN_TOML_NAME, type PluginTomlOptions, pluginToml };
package/dist/index.js CHANGED
@@ -1,20 +1,14 @@
1
- import { createRequire } from 'module';
2
- var require = createRequire(import.meta['url']);
3
-
4
-
5
- // ../../node_modules/.pnpm/@modern-js+module-tools@2.52.0_eslint@9.5.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
6
- import { fileURLToPath } from "url";
7
- import path from "path";
8
-
9
1
  // src/index.ts
10
2
  var PLUGIN_TOML_NAME = "rsbuild:toml";
11
- var pluginToml = () => ({
3
+ var pluginToml = (options = {}) => ({
12
4
  name: PLUGIN_TOML_NAME,
13
5
  async setup(api) {
14
6
  const { parse } = await import("toml");
7
+ const { esModule } = options;
15
8
  api.transform({ test: /\.toml$/ }, ({ code }) => {
16
9
  const parsed = parse(code);
17
- return `module.exports = ${JSON.stringify(parsed, void 0, " ")};`;
10
+ const exportType = esModule ? "export default" : "module.exports =";
11
+ return `${exportType} ${JSON.stringify(parsed, void 0, " ")};`;
18
12
  });
19
13
  }
20
14
  });
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-toml",
3
- "version": "0.7.10",
4
- "description": "TOML plugin for Rsbuild",
5
- "homepage": "https://rsbuild.dev",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/web-infra-dev/rsbuild",
9
- "directory": "packages/plugin-toml"
10
- },
3
+ "version": "1.0.1",
4
+ "repository": "https://github.com/rspack-contrib/rsbuild-plugin-toml",
11
5
  "license": "MIT",
12
6
  "type": "module",
13
7
  "exports": {
@@ -17,28 +11,51 @@
17
11
  "require": "./dist/index.cjs"
18
12
  }
19
13
  },
20
- "main": "./dist/index.cjs",
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.mjs",
21
16
  "types": "./dist/index.d.ts",
22
17
  "files": [
23
18
  "dist"
24
19
  ],
20
+ "simple-git-hooks": {
21
+ "pre-commit": "npx nano-staged"
22
+ },
23
+ "nano-staged": {
24
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
25
+ "biome check --write --no-errors-on-unmatched"
26
+ ]
27
+ },
25
28
  "dependencies": {
26
29
  "toml": "^3.0.0"
27
30
  },
28
31
  "devDependencies": {
29
- "typescript": "^5.4.2",
30
- "@rsbuild/core": "0.7.10"
32
+ "@biomejs/biome": "^1.8.3",
33
+ "@playwright/test": "^1.44.1",
34
+ "@rsbuild/core": "1.0.1-beta.10",
35
+ "@types/node": "^20.14.1",
36
+ "nano-staged": "^0.8.0",
37
+ "playwright": "^1.44.1",
38
+ "simple-git-hooks": "^2.11.1",
39
+ "tsup": "^8.0.2",
40
+ "typescript": "^5.5.2"
31
41
  },
32
42
  "peerDependencies": {
33
- "@rsbuild/core": "^0.7.10"
43
+ "@rsbuild/core": "0.x || 1.x || ^1.0.1-beta.0"
44
+ },
45
+ "peerDependenciesMeta": {
46
+ "@rsbuild/core": {
47
+ "optional": true
48
+ }
34
49
  },
35
50
  "publishConfig": {
36
51
  "access": "public",
37
- "provenance": true,
38
52
  "registry": "https://registry.npmjs.org/"
39
53
  },
40
54
  "scripts": {
41
- "build": "modern build",
42
- "dev": "modern build --watch"
55
+ "build": "tsup",
56
+ "dev": "tsup --watch",
57
+ "lint": "biome check .",
58
+ "lint:write": "biome check . --write",
59
+ "test": "playwright test"
43
60
  }
44
61
  }