@fluojs/vite 1.0.2 → 1.0.4
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 +2 -1
- package/README.md +2 -1
- package/dist/decorators-plugin.d.ts +19 -0
- package/dist/decorators-plugin.d.ts.map +1 -0
- package/dist/decorators-plugin.js +71 -0
- package/dist/index.d.ts +1 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -56
- package/package.json +1 -1
package/README.ko.md
CHANGED
|
@@ -42,7 +42,7 @@ export default defineConfig({
|
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
이 플러그인은 `.ts` 애플리케이션 파일을 Babel로 변환하며 `2023-11` decorators proposal과 `@babel/preset-typescript`를 사용합니다. 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 경로를 사용합니다.
|
|
46
46
|
|
|
47
47
|
## 공개 API
|
|
48
48
|
|
|
@@ -56,4 +56,5 @@ export default defineConfig({
|
|
|
56
56
|
## 예제 소스
|
|
57
57
|
|
|
58
58
|
- `packages/vite/src/index.ts`
|
|
59
|
+
- `packages/vite/src/decorators-plugin.ts`
|
|
59
60
|
- `packages/cli/src/new/scaffold.ts`
|
package/README.md
CHANGED
|
@@ -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 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.
|
|
46
46
|
|
|
47
47
|
## Public API
|
|
48
48
|
|
|
@@ -56,4 +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/decorators-plugin.ts`
|
|
59
60
|
- `packages/cli/src/new/scaffold.ts`
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the Vite transform plugin used by fluo starter projects to compile
|
|
4
|
+
* TC39 standard decorator syntax through Babel before Vite bundles the app.
|
|
5
|
+
*
|
|
6
|
+
* @returns A Vite plugin that transforms TypeScript application files and skips test files.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { fluoDecoratorsPlugin } from '@fluojs/vite';
|
|
11
|
+
* import { defineConfig } from 'vite';
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [fluoDecoratorsPlugin()],
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function fluoDecoratorsPlugin(): Plugin;
|
|
19
|
+
//# sourceMappingURL=decorators-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators-plugin.d.ts","sourceRoot":"","sources":["../src/decorators-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AA8BnD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CA6B7C"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { transformAsync } from '@babel/core';
|
|
2
|
+
function readViteFilePath(id) {
|
|
3
|
+
const filePath = id.split(/[?#]/, 1)[0] ?? id;
|
|
4
|
+
return filePath;
|
|
5
|
+
}
|
|
6
|
+
function isNodeModulesPath(filePath) {
|
|
7
|
+
return /(?:^|\/)node_modules(?:\/|$)/u.test(filePath);
|
|
8
|
+
}
|
|
9
|
+
function isTypeScriptTestFile(filePath) {
|
|
10
|
+
return /\.(?:test|spec)\.ts$/u.test(filePath);
|
|
11
|
+
}
|
|
12
|
+
function shouldTransformTypeScriptApplicationFile(id) {
|
|
13
|
+
const normalizedFilePath = readViteFilePath(id).replaceAll('\\', '/');
|
|
14
|
+
if (!normalizedFilePath.endsWith('.ts') || normalizedFilePath.endsWith('.d.ts')) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return !isNodeModulesPath(normalizedFilePath) && !isTypeScriptTestFile(normalizedFilePath);
|
|
18
|
+
}
|
|
19
|
+
function shouldRequestBabelSourceMaps(config) {
|
|
20
|
+
return config.command === 'serve' || Boolean(config.build.sourcemap);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates the Vite transform plugin used by fluo starter projects to compile
|
|
25
|
+
* TC39 standard decorator syntax through Babel before Vite bundles the app.
|
|
26
|
+
*
|
|
27
|
+
* @returns A Vite plugin that transforms TypeScript application files and skips test files.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { fluoDecoratorsPlugin } from '@fluojs/vite';
|
|
32
|
+
* import { defineConfig } from 'vite';
|
|
33
|
+
*
|
|
34
|
+
* export default defineConfig({
|
|
35
|
+
* plugins: [fluoDecoratorsPlugin()],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function fluoDecoratorsPlugin() {
|
|
40
|
+
let shouldGenerateSourceMaps = false;
|
|
41
|
+
return {
|
|
42
|
+
name: 'fluo-babel-decorators',
|
|
43
|
+
configResolved(config) {
|
|
44
|
+
shouldGenerateSourceMaps = shouldRequestBabelSourceMaps(config);
|
|
45
|
+
},
|
|
46
|
+
async transform(code, id) {
|
|
47
|
+
if (!shouldTransformTypeScriptApplicationFile(id)) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const result = await transformAsync(code, {
|
|
51
|
+
babelrc: false,
|
|
52
|
+
configFile: false,
|
|
53
|
+
filename: readViteFilePath(id),
|
|
54
|
+
plugins: [['@babel/plugin-proposal-decorators', {
|
|
55
|
+
version: '2023-11'
|
|
56
|
+
}]],
|
|
57
|
+
presets: [['@babel/preset-typescript', {
|
|
58
|
+
allowDeclareFields: true
|
|
59
|
+
}]],
|
|
60
|
+
sourceMaps: shouldGenerateSourceMaps
|
|
61
|
+
});
|
|
62
|
+
if (!result?.code) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
code: result.code,
|
|
67
|
+
map: result.map ?? null
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Creates the Vite transform plugin used by fluo starter projects to compile
|
|
4
|
-
* TC39 standard decorator syntax through Babel before Vite bundles the app.
|
|
5
|
-
*
|
|
6
|
-
* @returns A Vite plugin that transforms TypeScript application files and skips test files.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { fluoDecoratorsPlugin } from '@fluojs/vite';
|
|
11
|
-
* import { defineConfig } from 'vite';
|
|
12
|
-
*
|
|
13
|
-
* export default defineConfig({
|
|
14
|
-
* plugins: [fluoDecoratorsPlugin()],
|
|
15
|
-
* });
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare function fluoDecoratorsPlugin(): Plugin;
|
|
1
|
+
export { fluoDecoratorsPlugin } from './decorators-plugin.js';
|
|
19
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":"
|
|
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,56 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function shouldTransformTypeScriptApplicationFile(id) {
|
|
3
|
-
const [filePath] = id.split('?', 1);
|
|
4
|
-
const normalizedFilePath = filePath.replaceAll('\\', '/');
|
|
5
|
-
if (!normalizedFilePath.endsWith('.ts') || normalizedFilePath.endsWith('.d.ts')) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
return !normalizedFilePath.includes('/node_modules/') && !normalizedFilePath.includes('.test.') && !normalizedFilePath.includes('.spec.');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates the Vite transform plugin used by fluo starter projects to compile
|
|
13
|
-
* TC39 standard decorator syntax through Babel before Vite bundles the app.
|
|
14
|
-
*
|
|
15
|
-
* @returns A Vite plugin that transforms TypeScript application files and skips test files.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { fluoDecoratorsPlugin } from '@fluojs/vite';
|
|
20
|
-
* import { defineConfig } from 'vite';
|
|
21
|
-
*
|
|
22
|
-
* export default defineConfig({
|
|
23
|
-
* plugins: [fluoDecoratorsPlugin()],
|
|
24
|
-
* });
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export function fluoDecoratorsPlugin() {
|
|
28
|
-
return {
|
|
29
|
-
name: 'fluo-babel-decorators',
|
|
30
|
-
async transform(code, id) {
|
|
31
|
-
if (!shouldTransformTypeScriptApplicationFile(id)) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
const [filename] = id.split('?', 1);
|
|
35
|
-
const result = await transformAsync(code, {
|
|
36
|
-
babelrc: false,
|
|
37
|
-
configFile: false,
|
|
38
|
-
filename,
|
|
39
|
-
plugins: [['@babel/plugin-proposal-decorators', {
|
|
40
|
-
version: '2023-11'
|
|
41
|
-
}]],
|
|
42
|
-
presets: [['@babel/preset-typescript', {
|
|
43
|
-
allowDeclareFields: true
|
|
44
|
-
}]],
|
|
45
|
-
sourceMaps: true
|
|
46
|
-
});
|
|
47
|
-
if (!result?.code) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
code: result.code,
|
|
52
|
-
map: result.map ?? null
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
export { fluoDecoratorsPlugin } from './decorators-plugin.js';
|