Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking change: extract TOML plugin into a separate package #1201

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions e2e/cases/import-toml/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { pluginToml } from '@rsbuild/plugin-toml';

export default {
plugins: [pluginToml()],
};
1 change: 1 addition & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@rsbuild/plugin-svgr": "workspace:*",
"@rsbuild/plugin-swc": "workspace:*",
"@rsbuild/plugin-type-check": "workspace:*",
"@rsbuild/plugin-toml": "workspace:*",
"@rsbuild/plugin-umd": "workspace:*",
"@rsbuild/plugin-vue": "workspace:*",
"@rsbuild/plugin-vue-jsx": "workspace:*",
Expand Down
1 change: 0 additions & 1 deletion packages/compat/webpack/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const applyDefaultPlugins = (plugins: Plugins) =>
import('./plugins/sass').then((m) => m.pluginSass()),
import('./plugins/less').then((m) => m.pluginLess()),
plugins.bundleAnalyzer(),
plugins.toml(),
plugins.yaml(),
plugins.splitChunks(),
plugins.startUrl?.(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down Expand Up @@ -843,15 +834,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down Expand Up @@ -1294,15 +1276,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down Expand Up @@ -1646,15 +1619,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const plugins: Plugins = {
entry: () => import('./entry').then((m) => m.pluginEntry()),
cache: () => import('./cache').then((m) => m.pluginCache()),
yaml: () => import('./yaml').then((m) => m.pluginYaml()),
toml: () => import('./toml').then((m) => m.pluginToml()),
splitChunks: () => import('./splitChunks').then((m) => m.pluginSplitChunks()),
inlineChunk: () => import('./inlineChunk').then((m) => m.pluginInlineChunk()),
bundleAnalyzer: () =>
Expand Down
17 changes: 0 additions & 17 deletions packages/core/src/plugins/toml.ts
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
import { join } from 'path';
import type { RsbuildPlugin } from '../types';

export const pluginToml = (): RsbuildPlugin => ({
name: 'rsbuild:toml',

setup(api) {
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
chain.module
.rule(CHAIN_ID.RULE.TOML)
.type('javascript/auto')
.test(/\.toml$/)
.use(CHAIN_ID.USE.TOML)
.loader(join(__dirname, '../../compiled', 'toml-loader'));
});
},
});
1 change: 0 additions & 1 deletion packages/core/src/provider/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const applyDefaultPlugins = (plugins: Plugins) =>
import('./plugins/progress').then((m) => m.pluginProgress()),
import('./plugins/swc').then((m) => m.pluginSwc()),
plugins.externals(),
plugins.toml(),
plugins.yaml(),
plugins.splitChunks(),
plugins.startUrl(),
Expand Down
9 changes: 0 additions & 9 deletions packages/core/tests/__snapshots__/builder.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,6 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = `
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down
1 change: 0 additions & 1 deletion packages/core/tests/__snapshots__/inspect.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ exports[`inspectConfig > should print plugin names when inspect config 1`] = `
"rsbuild:progress",
"rsbuild:swc",
"rsbuild:externals",
"rsbuild:toml",
"rsbuild:yaml",
"rsbuild:split-chunks",
"rsbuild:start-url",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = `
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down Expand Up @@ -1248,15 +1239,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down Expand Up @@ -1786,15 +1768,6 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when targe
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down Expand Up @@ -2423,15 +2396,6 @@ exports[`tools.rspack > should match snapshot 1`] = `
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down
9 changes: 0 additions & 9 deletions packages/plugin-react/tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -588,15 +588,6 @@ exports[`plugins/react > should work with swc-loader 1`] = `
},
],
},
{
"test": /\\\\\\.toml\\$/,
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
},
],
},
{
"test": /\\\\\\.ya\\?ml\\$/,
"type": "javascript/auto",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-toml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @rsbuild/plugin-toml
21 changes: 21 additions & 0 deletions packages/plugin-toml/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-present Bytedance, Inc. and its affiliates.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions packages/plugin-toml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<p align="center">
<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>
</p>

# Rsbuild

The Rspack-based build tool. It's fast, out-of-the-box and extensible.

## Documentation

https://rsbuild.dev/

## Contributing

Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).

## License

Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
7 changes: 7 additions & 0 deletions packages/plugin-toml/modern.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import moduleTools from '@modern-js/module-tools';
import { buildConfigWithMjs } from '../../scripts/modern.base.config';

export default {
plugins: [moduleTools()],
buildConfig: buildConfigWithMjs,
};
43 changes: 43 additions & 0 deletions packages/plugin-toml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@rsbuild/plugin-toml",
"version": "0.2.18",
"description": "TOML plugin for Rsbuild",
"homepage": "https://rsbuild.dev",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsbuild",
"directory": "packages/plugin-toml"
},
"license": "MIT",
"type": "commonjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"default": "./dist/index.js"
}
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"compiled"
],
"scripts": {
"build": "modern build",
"dev": "modern build --watch"
},
"dependencies": {
"@rsbuild/shared": "workspace:*"
},
"devDependencies": {
"@rsbuild/core": "workspace:*",
"@rsbuild/test-helper": "workspace:*",
"typescript": "^5.3.0"
},
"publishConfig": {
"access": "public",
"provenance": true,
"registry": "https://registry.npmjs.org/"
}
}
17 changes: 17 additions & 0 deletions packages/plugin-toml/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { join } from 'path';
import type { RsbuildPlugin } from '@rsbuild/core';

export const pluginToml = (): RsbuildPlugin => ({
name: 'rsbuild:toml',

setup(api) {
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
chain.module
.rule(CHAIN_ID.RULE.TOML)
.type('javascript/auto')
.test(/\.toml$/)
.use(CHAIN_ID.USE.TOML)
.loader(join(__dirname, '../compiled', 'toml-loader'));
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`plugin-toml > should add toml rule properly 1`] = `
"type": "javascript/auto",
"use": [
{
"loader": "<ROOT>/packages/core/compiled/toml-loader",
"loader": "<ROOT>/packages/plugin-toml/compiled/toml-loader",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createStubRsbuild } from '@rsbuild/test-helper';
import { pluginToml } from '@src/plugins/toml';
import { pluginToml } from '../src';

describe('plugin-toml', () => {
it('should add toml rule properly', async () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin-toml/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@rsbuild/tsconfig/base",
"compilerOptions": {
"baseUrl": "./",
"types": ["vitest/globals"],
"paths": {
"@src/*": ["../src/*"],
"@/*": ["../src/provider/*"],
"@rsbuild/test-helper": ["../../vitest-helper/*"]
}
},
"include": ["./**/*.ts"]
}
18 changes: 18 additions & 0 deletions packages/plugin-toml/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "@rsbuild/tsconfig/base",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./",
"rootDir": "src",
"composite": true
},
"references": [
{
"path": "../core"
},
{
"path": "../shared"
}
],
"include": ["src"]
}
1 change: 0 additions & 1 deletion packages/shared/src/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ export type Plugins = {
entry: PluginsFn;
cache: PluginsFn;
yaml: PluginsFn;
toml: PluginsFn;
splitChunks: PluginsFn;
inlineChunk: PluginsFn;
bundleAnalyzer: PluginsFn;
Expand Down
Loading