@open-xchange/vite-plugin-es-decorators 1.1.1 → 1.2.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 +4 -0
- package/LICENSE +21 -0
- package/README.md +8 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +27 -20
- package/package.json +21 -19
package/CHANGELOG.md
CHANGED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
|
|
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
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @open-xchange/vite-plugin-es-decorators
|
|
2
2
|
|
|
3
|
-
A Vite plugin that adds support for native ES decorators in JS source files.
|
|
3
|
+
A Vite plugin that adds support for native ES decorators in JS and TS source files.
|
|
4
|
+
|
|
5
|
+
Supports Vite 6 and 7 (with rollup/esbuild), and Vite 8 (with rolldown/oxc).
|
|
4
6
|
|
|
5
7
|
## Usage
|
|
6
8
|
|
|
@@ -9,8 +11,8 @@ Add the plugin to your Vite configuration:
|
|
|
9
11
|
```ts
|
|
10
12
|
// vite.config.ts
|
|
11
13
|
|
|
12
|
-
import { defineConfig } from
|
|
13
|
-
import decoratorsPlugin from
|
|
14
|
+
import { defineConfig } from 'vite' // or 'vitest/config'
|
|
15
|
+
import decoratorsPlugin from '@open-xchange/vite-plugin-es-decorators'
|
|
14
16
|
|
|
15
17
|
export default defineConfig(() => {
|
|
16
18
|
|
|
@@ -24,4 +26,6 @@ export default defineConfig(() => {
|
|
|
24
26
|
})
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
The plugin will detect the version of Vite currently used and will configure the appropriate Babel plugin ([vite-plugin-babel](https://www.npmjs.com/package/vite-plugin-babel) for Vite 7 and less with rollup/esbuild, or [@rolldown/plugin-babel](https://www.npmjs.com/package/@rolldown/plugin-babel) for Vite 8 and up with rolldown/oxc).
|
|
30
|
+
|
|
31
|
+
Vite will then send all source files to the Babel parser which will transpile ES decorators using the plugin [@babel/plugin-proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Plugin } from 'vite';
|
|
2
2
|
export declare const PROJECT_NAME = "@open-xchange/vite-plugin-es-decorators";
|
|
3
3
|
/**
|
|
4
4
|
* Vite plugin that adds support for native ES decorators in JS source files.
|
|
@@ -6,4 +6,4 @@ export declare const PROJECT_NAME = "@open-xchange/vite-plugin-es-decorators";
|
|
|
6
6
|
* @returns
|
|
7
7
|
* The Vite plugin object.
|
|
8
8
|
*/
|
|
9
|
-
export default function vitePluginEsDecorators(): Plugin
|
|
9
|
+
export default function vitePluginEsDecorators(): Promise<Plugin>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { version } from 'vite';
|
|
2
|
+
import vitePluginBabel from 'vite-plugin-babel';
|
|
3
|
+
import rolldownPluginBabel from '@rolldown/plugin-babel';
|
|
2
4
|
// constants ==================================================================
|
|
3
|
-
export const PROJECT_NAME =
|
|
5
|
+
export const PROJECT_NAME = '@open-xchange/vite-plugin-es-decorators';
|
|
6
|
+
const VITE_VERSION = parseInt(version.split('.')[0], 10);
|
|
4
7
|
// plugin =====================================================================
|
|
5
8
|
/**
|
|
6
9
|
* Vite plugin that adds support for native ES decorators in JS source files.
|
|
@@ -8,22 +11,26 @@ export const PROJECT_NAME = "@open-xchange/vite-plugin-es-decorators";
|
|
|
8
11
|
* @returns
|
|
9
12
|
* The Vite plugin object.
|
|
10
13
|
*/
|
|
11
|
-
export default function vitePluginEsDecorators() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
export default async function vitePluginEsDecorators() {
|
|
15
|
+
const plugin = { name: PROJECT_NAME };
|
|
16
|
+
const babelPlugins = [['@babel/plugin-proposal-decorators', { version: '2023-11' }]];
|
|
17
|
+
if (VITE_VERSION >= 8) {
|
|
18
|
+
Object.assign(plugin, await rolldownPluginBabel({
|
|
19
|
+
presets: [{
|
|
20
|
+
preset: () => ({ plugins: babelPlugins }),
|
|
21
|
+
// only for source files with decorators
|
|
22
|
+
rolldown: { filter: { code: '@' } },
|
|
23
|
+
}],
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const babelPlugin = vitePluginBabel({
|
|
28
|
+
babelConfig: { babelrc: false, configFile: false, plugins: babelPlugins },
|
|
29
|
+
});
|
|
30
|
+
const config = babelPlugin.config;
|
|
31
|
+
Object.assign(plugin, babelPlugin, {
|
|
32
|
+
config: () => Object.assign(config(), { esbuild: { target: 'es2022' } }),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return plugin;
|
|
29
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-es-decorators",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Vite plugin that adds support for native ES decorators in JS source files",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,35 +11,37 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=20.18"
|
|
13
13
|
},
|
|
14
|
-
"packageManager": "yarn@4.9.4",
|
|
15
14
|
"type": "module",
|
|
16
15
|
"exports": "./dist/index.js",
|
|
17
16
|
"files": [
|
|
18
17
|
"dist",
|
|
19
18
|
"CHANGELOG.*"
|
|
20
19
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"prepack": "yarn build && yarn lint",
|
|
23
|
-
"clean": "premove dist",
|
|
24
|
-
"build": "yarn clean && tsc --project src/tsconfig.json",
|
|
25
|
-
"lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint ."
|
|
26
|
-
},
|
|
27
20
|
"dependencies": {
|
|
28
|
-
"@babel/core": "^7.
|
|
29
|
-
"@babel/plugin-proposal-decorators": "^7.
|
|
30
|
-
"vite-plugin-babel": "^1.
|
|
21
|
+
"@babel/core": "^7.29.0",
|
|
22
|
+
"@babel/plugin-proposal-decorators": "^7.29.0",
|
|
23
|
+
"vite-plugin-babel": "^1.5.1"
|
|
31
24
|
},
|
|
32
25
|
"devDependencies": {
|
|
33
|
-
"@
|
|
26
|
+
"@rolldown/plugin-babel": "^0.2.1",
|
|
34
27
|
"@types/babel__core": "^7.20.5",
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
28
|
+
"@vitest/coverage-v8": "^4.1.0",
|
|
29
|
+
"vite": "^8.0.0",
|
|
30
|
+
"vite-v6": "npm:vite@^6.4.1",
|
|
31
|
+
"vite-v7": "npm:vite@^7.3.1",
|
|
32
|
+
"vite-v8": "npm:vite@^8.0.0",
|
|
33
|
+
"vitest": "^4.1.0",
|
|
34
|
+
"@open-xchange/vitest-vite-plugin-utils": "^0.0.1",
|
|
35
|
+
"@open-xchange/linter-presets": "^1.18.4"
|
|
41
36
|
},
|
|
42
37
|
"peerDependencies": {
|
|
43
|
-
"vite": "^
|
|
38
|
+
"vite": "^8.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "pnpm clean && tsc --project src/tsconfig.json",
|
|
42
|
+
"clean": "premove dist",
|
|
43
|
+
"coverage": "vitest run --coverage",
|
|
44
|
+
"lint": "tsc && tsc --project src/tsconfig.json --noEmit && eslint .",
|
|
45
|
+
"test": "vitest run"
|
|
44
46
|
}
|
|
45
47
|
}
|