@fluojs/vite 1.0.3 → 1.0.5
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/README.ko.md +3 -3
- package/README.md +3 -3
- package/dist/decorators-plugin.d.ts.map +1 -0
- package/dist/decorators-plugin.js +106 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/internal/decorators-plugin.d.ts.map +0 -1
- package/dist/internal/decorators-plugin.js +0 -58
- /package/dist/{internal/decorators-plugin.d.ts → decorators-plugin.d.ts} +0 -0
package/README.ko.md
CHANGED
|
@@ -19,7 +19,7 @@ fluo 프로젝트를 위한 Vite 플러그인과 빌드 유틸리티입니다.
|
|
|
19
19
|
npm install --save-dev @fluojs/vite vite @babel/core @babel/plugin-proposal-decorators @babel/preset-typescript
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`@babel/core` `>=7.26.0`, `@babel/plugin-proposal-decorators` `>=7.28.0`, `@babel/preset-typescript` `>=7.27.0`, `vite` `>=6.2.0`은 peer dependency입니다. `fluoDecoratorsPlugin()`이 Vite transform 시점에 Babel decorator plugin과 TypeScript preset을
|
|
22
|
+
`@babel/core` `>=7.26.0`, `@babel/plugin-proposal-decorators` `>=7.28.0`, `@babel/preset-typescript` `>=7.27.0`, `vite` `>=6.2.0`은 peer dependency입니다. `fluoDecoratorsPlugin()`이 Vite transform 시점에 Babel을 로드하고 Babel decorator plugin과 TypeScript preset을 해석하며, 누락된 peer dependency를 Vite `transform` hook의 진단으로 보고하기 때문입니다.
|
|
23
23
|
|
|
24
24
|
## 사용 시점
|
|
25
25
|
|
|
@@ -42,7 +42,7 @@ export default defineConfig({
|
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
이 플러그인은 `.ts` 애플리케이션 파일을 Babel로 변환하며 `2023-11` decorators proposal과 `@babel/preset-typescript`를 사용합니다. 파일 경계를 판단하기 전에 Vite query suffix를 제거한 뒤 declaration 파일,
|
|
45
|
+
이 플러그인은 `.ts` 애플리케이션 파일을 Babel로 변환하며 `2023-11` decorators proposal과 `@babel/preset-typescript`를 사용합니다. 파일 경계를 판단하기 전에 Vite query suffix를 제거한 뒤 declaration 파일, `*.test.ts` 또는 `*.spec.ts` 파일, `node_modules`, `.ts`가 아닌 파일은 건너뛰므로 생성된 Vitest 테스트 파일은 계속 전용 `@fluojs/testing/vitest` transform 경로를 사용합니다. `@fluojs/vite`를 import하거나 `fluoDecoratorsPlugin()`을 생성하는 시점에는 `@babel/core`를 로드하지 않으며, 누락된 Babel peer는 Vite가 변환 중인 소스 파일에 대한 transform-time 진단으로 표시됩니다.
|
|
46
46
|
|
|
47
47
|
## 공개 API
|
|
48
48
|
|
|
@@ -56,5 +56,5 @@ export default defineConfig({
|
|
|
56
56
|
## 예제 소스
|
|
57
57
|
|
|
58
58
|
- `packages/vite/src/index.ts`
|
|
59
|
-
- `packages/vite/src/
|
|
59
|
+
- `packages/vite/src/decorators-plugin.ts`
|
|
60
60
|
- `packages/cli/src/new/scaffold.ts`
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Vite plugin and build utilities for fluo projects.
|
|
|
19
19
|
npm install --save-dev @fluojs/vite vite @babel/core @babel/plugin-proposal-decorators @babel/preset-typescript
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`@babel/core` `>=7.26.0`, `@babel/plugin-proposal-decorators` `>=7.28.0`, `@babel/preset-typescript` `>=7.27.0`, and `vite` `>=6.2.0` are peer dependencies because `fluoDecoratorsPlugin()` resolves the Babel decorator plugin and TypeScript preset when Vite transforms source files.
|
|
22
|
+
`@babel/core` `>=7.26.0`, `@babel/plugin-proposal-decorators` `>=7.28.0`, `@babel/preset-typescript` `>=7.27.0`, and `vite` `>=6.2.0` are peer dependencies because `fluoDecoratorsPlugin()` loads Babel, resolves the Babel decorator plugin and TypeScript preset, and reports missing peer dependencies from the Vite `transform` hook when Vite transforms source files.
|
|
23
23
|
|
|
24
24
|
## When to Use
|
|
25
25
|
|
|
@@ -42,7 +42,7 @@ export default defineConfig({
|
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
The plugin transforms `.ts` application files with Babel using the `2023-11` decorators proposal and `@babel/preset-typescript`. It strips Vite query suffixes before deciding the file boundary, then skips declaration files,
|
|
45
|
+
The plugin transforms `.ts` application files with Babel using the `2023-11` decorators proposal and `@babel/preset-typescript`. It strips Vite query suffixes before deciding the file boundary, then skips declaration files, `*.test.ts` or `*.spec.ts` files, `node_modules`, and non-`.ts` files so generated Vitest test files continue to use the dedicated `@fluojs/testing/vitest` transform path. Importing `@fluojs/vite` or creating `fluoDecoratorsPlugin()` does not load `@babel/core`; missing Babel peers are surfaced as transform-time diagnostics for the source file Vite is transforming.
|
|
46
46
|
|
|
47
47
|
## Public API
|
|
48
48
|
|
|
@@ -56,5 +56,5 @@ The plugin transforms `.ts` application files with Babel using the `2023-11` dec
|
|
|
56
56
|
## Example Sources
|
|
57
57
|
|
|
58
58
|
- `packages/vite/src/index.ts`
|
|
59
|
-
- `packages/vite/src/
|
|
59
|
+
- `packages/vite/src/decorators-plugin.ts`
|
|
60
60
|
- `packages/cli/src/new/scaffold.ts`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators-plugin.d.ts","sourceRoot":"","sources":["../src/decorators-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAoFnD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAsC7C"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const BABEL_PEER_DEPENDENCIES = ['@babel/core', '@babel/plugin-proposal-decorators', '@babel/preset-typescript'];
|
|
2
|
+
function readErrorCode(value) {
|
|
3
|
+
if (!value || typeof value !== 'object' || !('code' in value)) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const code = value.code;
|
|
7
|
+
return typeof code === 'string' ? code : undefined;
|
|
8
|
+
}
|
|
9
|
+
function readErrorMessage(value) {
|
|
10
|
+
return value instanceof Error ? value.message : String(value);
|
|
11
|
+
}
|
|
12
|
+
function isMissingPeerDependencyError(error) {
|
|
13
|
+
const code = readErrorCode(error);
|
|
14
|
+
const message = readErrorMessage(error);
|
|
15
|
+
return (code === 'ERR_MODULE_NOT_FOUND' || code === 'MODULE_NOT_FOUND' || message.includes('Cannot find package')) && BABEL_PEER_DEPENDENCIES.some(dependencyName => message.includes(dependencyName));
|
|
16
|
+
}
|
|
17
|
+
function createBabelTransformDiagnostic(error, filePath) {
|
|
18
|
+
const message = readErrorMessage(error);
|
|
19
|
+
if (!isMissingPeerDependencyError(error)) {
|
|
20
|
+
return error instanceof Error ? error : new Error(message);
|
|
21
|
+
}
|
|
22
|
+
return new Error(`[fluo-babel-decorators] Failed to resolve a Babel peer dependency while transforming ${filePath}. ` + 'Install @babel/core, @babel/plugin-proposal-decorators, and @babel/preset-typescript in the Vite project. ' + `Original error: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
async function loadBabelCore(filePath) {
|
|
25
|
+
try {
|
|
26
|
+
return await import('@babel/core');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw createBabelTransformDiagnostic(error, filePath);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function readViteFilePath(id) {
|
|
32
|
+
const filePath = id.split(/[?#]/, 1)[0] ?? id;
|
|
33
|
+
return filePath;
|
|
34
|
+
}
|
|
35
|
+
function isNodeModulesPath(filePath) {
|
|
36
|
+
return /(?:^|\/)node_modules(?:\/|$)/u.test(filePath);
|
|
37
|
+
}
|
|
38
|
+
function isTypeScriptTestFile(filePath) {
|
|
39
|
+
return /\.(?:test|spec)\.ts$/u.test(filePath);
|
|
40
|
+
}
|
|
41
|
+
function shouldTransformTypeScriptApplicationFile(id) {
|
|
42
|
+
const normalizedFilePath = readViteFilePath(id).replaceAll('\\', '/');
|
|
43
|
+
if (!normalizedFilePath.endsWith('.ts') || normalizedFilePath.endsWith('.d.ts')) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return !isNodeModulesPath(normalizedFilePath) && !isTypeScriptTestFile(normalizedFilePath);
|
|
47
|
+
}
|
|
48
|
+
function shouldRequestBabelSourceMaps(config) {
|
|
49
|
+
return config.command === 'serve' || Boolean(config.build.sourcemap);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Creates the Vite transform plugin used by fluo starter projects to compile
|
|
54
|
+
* TC39 standard decorator syntax through Babel before Vite bundles the app.
|
|
55
|
+
*
|
|
56
|
+
* @returns A Vite plugin that transforms TypeScript application files and skips test files.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { fluoDecoratorsPlugin } from '@fluojs/vite';
|
|
61
|
+
* import { defineConfig } from 'vite';
|
|
62
|
+
*
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* plugins: [fluoDecoratorsPlugin()],
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function fluoDecoratorsPlugin() {
|
|
69
|
+
let shouldGenerateSourceMaps = false;
|
|
70
|
+
let babelCorePromise;
|
|
71
|
+
return {
|
|
72
|
+
name: 'fluo-babel-decorators',
|
|
73
|
+
configResolved(config) {
|
|
74
|
+
shouldGenerateSourceMaps = shouldRequestBabelSourceMaps(config);
|
|
75
|
+
},
|
|
76
|
+
async transform(code, id) {
|
|
77
|
+
if (!shouldTransformTypeScriptApplicationFile(id)) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const filePath = readViteFilePath(id);
|
|
81
|
+
babelCorePromise ??= loadBabelCore(filePath);
|
|
82
|
+
const babelCore = await babelCorePromise;
|
|
83
|
+
const result = await babelCore.transformAsync(code, {
|
|
84
|
+
babelrc: false,
|
|
85
|
+
configFile: false,
|
|
86
|
+
filename: filePath,
|
|
87
|
+
plugins: [['@babel/plugin-proposal-decorators', {
|
|
88
|
+
version: '2023-11'
|
|
89
|
+
}]],
|
|
90
|
+
presets: [['@babel/preset-typescript', {
|
|
91
|
+
allowDeclareFields: true
|
|
92
|
+
}]],
|
|
93
|
+
sourceMaps: shouldGenerateSourceMaps
|
|
94
|
+
}).catch(error => {
|
|
95
|
+
throw createBabelTransformDiagnostic(error, filePath);
|
|
96
|
+
});
|
|
97
|
+
if (!result?.code) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
code: result.code,
|
|
102
|
+
map: result.map ?? null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { fluoDecoratorsPlugin } from './
|
|
1
|
+
export { fluoDecoratorsPlugin } from './decorators-plugin.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { fluoDecoratorsPlugin } from './
|
|
1
|
+
export { fluoDecoratorsPlugin } from './decorators-plugin.js';
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decorators-plugin.d.ts","sourceRoot":"","sources":["../../src/internal/decorators-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAsBnC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAwB7C"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { transformAsync } from '@babel/core';
|
|
2
|
-
function readViteFilePath(id) {
|
|
3
|
-
const [filePath] = id.split('?', 1);
|
|
4
|
-
return filePath;
|
|
5
|
-
}
|
|
6
|
-
function shouldTransformTypeScriptApplicationFile(id) {
|
|
7
|
-
const normalizedFilePath = readViteFilePath(id).replaceAll('\\', '/');
|
|
8
|
-
if (!normalizedFilePath.endsWith('.ts') || normalizedFilePath.endsWith('.d.ts')) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
return !normalizedFilePath.includes('/node_modules/') && !normalizedFilePath.includes('.test.') && !normalizedFilePath.includes('.spec.');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Creates the Vite transform plugin used by fluo starter projects to compile
|
|
16
|
-
* TC39 standard decorator syntax through Babel before Vite bundles the app.
|
|
17
|
-
*
|
|
18
|
-
* @returns A Vite plugin that transforms TypeScript application files and skips test files.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* import { fluoDecoratorsPlugin } from '@fluojs/vite';
|
|
23
|
-
* import { defineConfig } from 'vite';
|
|
24
|
-
*
|
|
25
|
-
* export default defineConfig({
|
|
26
|
-
* plugins: [fluoDecoratorsPlugin()],
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function fluoDecoratorsPlugin() {
|
|
31
|
-
return {
|
|
32
|
-
name: 'fluo-babel-decorators',
|
|
33
|
-
async transform(code, id) {
|
|
34
|
-
if (!shouldTransformTypeScriptApplicationFile(id)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const result = await transformAsync(code, {
|
|
38
|
-
babelrc: false,
|
|
39
|
-
configFile: false,
|
|
40
|
-
filename: readViteFilePath(id),
|
|
41
|
-
plugins: [['@babel/plugin-proposal-decorators', {
|
|
42
|
-
version: '2023-11'
|
|
43
|
-
}]],
|
|
44
|
-
presets: [['@babel/preset-typescript', {
|
|
45
|
-
allowDeclareFields: true
|
|
46
|
-
}]],
|
|
47
|
-
sourceMaps: true
|
|
48
|
-
});
|
|
49
|
-
if (!result?.code) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
code: result.code,
|
|
54
|
-
map: result.map ?? null
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
File without changes
|