@flight-framework/bundler-flightpack 0.1.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/README.md +199 -0
- package/dist/index.d.ts +217 -0
- package/dist/index.js +297 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# @flight-framework/bundler-flightpack
|
|
2
|
+
|
|
3
|
+
FlightPack native Rust bundler adapter for Flight Framework.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the TypeScript adapter that integrates FlightPack with the Flight Framework bundler interface. It wraps the native NAPI bindings to provide a seamless developer experience matching other Flight bundler adapters.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Native Performance** - 1,874+ files/second processing speed
|
|
12
|
+
- **100% Rust Core** - No JavaScript runtime overhead in hot paths
|
|
13
|
+
- **Zero Configuration** - Works out of the box with TypeScript/TSX
|
|
14
|
+
- **HMR Support** - Native Axum WebSocket-based Hot Module Replacement
|
|
15
|
+
- **RSC Ready** - React Server Components with directive detection
|
|
16
|
+
- **CSS Processing** - Lightning CSS for modules, minification, autoprefixer
|
|
17
|
+
- **Universal Builds** - SSR, SSG, CSR, SPA, Edge deployment support
|
|
18
|
+
- **Tree Shaking** - Dead code elimination
|
|
19
|
+
- **Code Splitting** - Automatic chunk optimization
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @flight-framework/bundler-flightpack @flight-framework/flightpack
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Basic Configuration
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// flight.config.ts
|
|
33
|
+
import { defineConfig } from '@flight-framework/core';
|
|
34
|
+
import { flightpack } from '@flight-framework/bundler-flightpack';
|
|
35
|
+
|
|
36
|
+
export default defineConfig({
|
|
37
|
+
bundler: flightpack(),
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### With Options
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { flightpack } from '@flight-framework/bundler-flightpack';
|
|
45
|
+
|
|
46
|
+
export default defineConfig({
|
|
47
|
+
bundler: flightpack({
|
|
48
|
+
minify: true,
|
|
49
|
+
sourcemap: true,
|
|
50
|
+
target: 'es2022',
|
|
51
|
+
rsc: true,
|
|
52
|
+
treeshake: true,
|
|
53
|
+
splitting: true,
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration Options
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
|--------|------|---------|-------------|
|
|
62
|
+
| `minify` | `boolean` | `true` | Enable minification in production |
|
|
63
|
+
| `sourcemap` | `boolean \| 'inline'` | `true` | Generate source maps |
|
|
64
|
+
| `target` | `string` | `'es2022'` | JavaScript target environment |
|
|
65
|
+
| `treeshake` | `boolean` | `true` | Enable tree shaking |
|
|
66
|
+
| `rsc` | `boolean` | `true` | Enable RSC directive detection |
|
|
67
|
+
| `hmr` | `boolean` | `true` | Enable HMR in development |
|
|
68
|
+
| `splitting` | `boolean` | `true` | Enable code splitting |
|
|
69
|
+
| `chunkSizeLimit` | `number` | `500` | Warn on chunks larger than (KB) |
|
|
70
|
+
|
|
71
|
+
## Bundler Interface
|
|
72
|
+
|
|
73
|
+
The adapter implements the full `BundlerAdapter` interface:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
interface BundlerAdapter {
|
|
77
|
+
name: string;
|
|
78
|
+
|
|
79
|
+
// Build operations
|
|
80
|
+
build(config: FlightConfig): Promise<BuildResult>;
|
|
81
|
+
transform(code: string, id: string, config: FlightConfig): Promise<TransformResult | null>;
|
|
82
|
+
|
|
83
|
+
// Development server
|
|
84
|
+
createDevServer(config: FlightConfig): Promise<DevServer>;
|
|
85
|
+
|
|
86
|
+
// Module resolution
|
|
87
|
+
resolve(id: string, importer: string | undefined, config: FlightConfig): Promise<string | null>;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Development Server
|
|
92
|
+
|
|
93
|
+
The dev server uses native Rust (Axum) for maximum performance:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const adapter = await flightpack();
|
|
97
|
+
const devServer = await adapter.createDevServer(config);
|
|
98
|
+
|
|
99
|
+
// Server runs on native Axum with WebSocket HMR
|
|
100
|
+
await devServer.listen(3000);
|
|
101
|
+
|
|
102
|
+
// File watcher triggers HMR updates
|
|
103
|
+
devServer.on('update', (modules) => {
|
|
104
|
+
console.log('Updated:', modules);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Graceful shutdown
|
|
108
|
+
await devServer.close();
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## CSS Handling
|
|
112
|
+
|
|
113
|
+
The adapter provides native CSS processing:
|
|
114
|
+
|
|
115
|
+
- **CSS Minification** - Lightning CSS for fast minification
|
|
116
|
+
- **CSS Modules** - Class name hashing with exports
|
|
117
|
+
- **Autoprefixer** - Automatic vendor prefixes
|
|
118
|
+
- **Source Maps** - Development debugging support
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// .css files are minified and injected
|
|
122
|
+
import './styles.css';
|
|
123
|
+
|
|
124
|
+
// .module.css files export class mappings
|
|
125
|
+
import styles from './component.module.css';
|
|
126
|
+
console.log(styles.button); // 'button_a1b2c3'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Universal Platform Support
|
|
130
|
+
|
|
131
|
+
The adapter includes utilities for multi-platform builds:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { flightpack } from '@flight-framework/bundler-flightpack';
|
|
135
|
+
|
|
136
|
+
// Access native externals detection
|
|
137
|
+
const native = await loadNativeBinding();
|
|
138
|
+
|
|
139
|
+
// SSR - detect Node.js builtins to externalize
|
|
140
|
+
native.isNodeBuiltin('fs'); // true
|
|
141
|
+
native.isBareImport('express'); // true
|
|
142
|
+
|
|
143
|
+
// Edge - check runtime compatibility
|
|
144
|
+
native.isEdgeCompatible('crypto'); // true
|
|
145
|
+
native.isEdgeCompatible('fs'); // false
|
|
146
|
+
|
|
147
|
+
// Platform-specific resolve conditions
|
|
148
|
+
native.getPlatformConditions('browser'); // ['browser', 'import', 'module']
|
|
149
|
+
native.getPlatformConditions('node'); // ['node', 'import', 'module']
|
|
150
|
+
native.getPlatformConditions('edge'); // ['edge', 'worker', 'import', 'module']
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Performance
|
|
154
|
+
|
|
155
|
+
FlightPack benchmarks against Flight Framework monorepo:
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
Files Processed: 126
|
|
159
|
+
Total Lines: 36,231
|
|
160
|
+
|
|
161
|
+
Total Time: 67 ms
|
|
162
|
+
Files/second: 1,874
|
|
163
|
+
Lines/second: 538,908
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Comparison
|
|
167
|
+
|
|
168
|
+
| Bundler | Files/sec | Category |
|
|
169
|
+
|---------|-----------|----------|
|
|
170
|
+
| FlightPack | 1,874 | Elite |
|
|
171
|
+
| Turbopack | ~1,500 | Elite |
|
|
172
|
+
| esbuild | ~1,200 | Excellent |
|
|
173
|
+
| Vite | ~800 | Good |
|
|
174
|
+
| Webpack | ~100 | Legacy |
|
|
175
|
+
|
|
176
|
+
## Native Bindings
|
|
177
|
+
|
|
178
|
+
This adapter wraps the `@flight-framework/flightpack` NAPI package which provides 21 native functions:
|
|
179
|
+
|
|
180
|
+
| Category | Functions |
|
|
181
|
+
|----------|-----------|
|
|
182
|
+
| Core | `build`, `transform`, `version`, `FlightPack` |
|
|
183
|
+
| Dev Server | `startDevServer`, `stopDevServer`, `isDevServerRunning` |
|
|
184
|
+
| HMR | `sendHmrUpdate`, `sendHmrError`, `watchFiles`, `WatchHandle` |
|
|
185
|
+
| CSS | `transformCss`, `minifyCss`, `transformCssModule` |
|
|
186
|
+
| Universal | `isNodeBuiltin`, `getNodeBuiltins`, `isBareImport`, `isEdgeCompatible`, `getPlatformConditions` |
|
|
187
|
+
|
|
188
|
+
## Related Packages
|
|
189
|
+
|
|
190
|
+
| Package | Description |
|
|
191
|
+
|---------|-------------|
|
|
192
|
+
| `@flight-framework/flightpack` | Native NAPI bindings |
|
|
193
|
+
| `@flight-framework/bundler` | Bundler interface definitions |
|
|
194
|
+
| `@flight-framework/bundler-vite` | Vite adapter alternative |
|
|
195
|
+
| `@flight-framework/bundler-esbuild` | esbuild adapter alternative |
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { CSSOptions, BundlerAdapter } from '@flight-framework/bundler';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @flight-framework/bundler-flightpack - Types
|
|
5
|
+
*
|
|
6
|
+
* Type definitions for the FlightPack bundler adapter.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for the FlightPack bundler adapter
|
|
11
|
+
*/
|
|
12
|
+
interface FlightPackAdapterOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Enable minification in production builds
|
|
15
|
+
* @default true in production, false in development
|
|
16
|
+
*/
|
|
17
|
+
minify?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Generate source maps
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
sourcemap?: boolean | 'inline' | 'hidden';
|
|
23
|
+
/**
|
|
24
|
+
* Target environment
|
|
25
|
+
* @default 'es2022'
|
|
26
|
+
*/
|
|
27
|
+
target?: 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'esnext';
|
|
28
|
+
/**
|
|
29
|
+
* Enable tree shaking
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
treeshake?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum chunk size in KB before warning
|
|
35
|
+
* @default 500
|
|
36
|
+
*/
|
|
37
|
+
chunkSizeLimit?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Enable React Server Components support
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
rsc?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Enable Hot Module Replacement in dev mode
|
|
45
|
+
* @default true
|
|
46
|
+
*/
|
|
47
|
+
hmr?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* CSS configuration
|
|
50
|
+
*/
|
|
51
|
+
css?: CSSOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve aliases (similar to webpack resolve.alias)
|
|
54
|
+
*/
|
|
55
|
+
resolveAlias?: Record<string, string>;
|
|
56
|
+
/**
|
|
57
|
+
* File extensions to resolve
|
|
58
|
+
* @default ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
|
|
59
|
+
*/
|
|
60
|
+
resolveExtensions?: string[];
|
|
61
|
+
/**
|
|
62
|
+
* External packages (not bundled)
|
|
63
|
+
*/
|
|
64
|
+
external?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* Define global constants (replaced at compile time)
|
|
67
|
+
*/
|
|
68
|
+
define?: Record<string, string>;
|
|
69
|
+
/**
|
|
70
|
+
* Auto-register adapter on import
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
autoRegister?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Additional options passed directly to FlightPack
|
|
76
|
+
*/
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Options for the FlightPack dev server
|
|
81
|
+
*/
|
|
82
|
+
interface FlightPackDevServerOptions {
|
|
83
|
+
/**
|
|
84
|
+
* Port to run dev server on
|
|
85
|
+
* @default 5173
|
|
86
|
+
*/
|
|
87
|
+
port?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Host to bind to
|
|
90
|
+
* @default 'localhost'
|
|
91
|
+
*/
|
|
92
|
+
host?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Enable HTTPS
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
https?: boolean | {
|
|
98
|
+
key?: string;
|
|
99
|
+
cert?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Open browser on start
|
|
103
|
+
* @default false
|
|
104
|
+
*/
|
|
105
|
+
open?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Proxy configuration for API requests
|
|
108
|
+
*/
|
|
109
|
+
proxy?: Record<string, string | {
|
|
110
|
+
target: string;
|
|
111
|
+
changeOrigin?: boolean;
|
|
112
|
+
rewrite?: (path: string) => string;
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Result from FlightPack native build
|
|
117
|
+
*/
|
|
118
|
+
interface FlightPackBuildResult {
|
|
119
|
+
/** Output directory path */
|
|
120
|
+
outputDir: string;
|
|
121
|
+
/** Build duration in milliseconds */
|
|
122
|
+
durationMs: number;
|
|
123
|
+
/** Total size of all output files in bytes */
|
|
124
|
+
totalSize: number;
|
|
125
|
+
/** Information about each generated chunk */
|
|
126
|
+
chunks: FlightPackChunkInfo[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Information about a generated chunk
|
|
130
|
+
*/
|
|
131
|
+
interface FlightPackChunkInfo {
|
|
132
|
+
/** File name of the chunk */
|
|
133
|
+
fileName: string;
|
|
134
|
+
/** Type of chunk: 'entry', 'chunk', or 'asset' */
|
|
135
|
+
chunkType: 'entry' | 'chunk' | 'asset';
|
|
136
|
+
/** Size in bytes */
|
|
137
|
+
size: number;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Result from single file transformation
|
|
141
|
+
*/
|
|
142
|
+
interface FlightPackTransformResult {
|
|
143
|
+
/** Transformed code */
|
|
144
|
+
code: string;
|
|
145
|
+
/** Source map (if generated) */
|
|
146
|
+
map: string | null;
|
|
147
|
+
/** Whether transformation succeeded */
|
|
148
|
+
success: boolean;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Options for single file transformation
|
|
152
|
+
*/
|
|
153
|
+
interface FlightPackTransformOptions {
|
|
154
|
+
/** Generate source maps */
|
|
155
|
+
sourcemap?: boolean;
|
|
156
|
+
/** Enable minification */
|
|
157
|
+
minify?: boolean;
|
|
158
|
+
/** Target environment */
|
|
159
|
+
target?: string;
|
|
160
|
+
/** JSX factory function */
|
|
161
|
+
jsxFactory?: string;
|
|
162
|
+
/** JSX fragment function */
|
|
163
|
+
jsxFragment?: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @flight-framework/bundler-flightpack
|
|
168
|
+
*
|
|
169
|
+
* FlightPack native Rust bundler adapter for Flight Framework.
|
|
170
|
+
* Wraps the native Rust bundler for maximum performance.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* // In flight.config.ts
|
|
175
|
+
* import { defineConfig } from '@flight-framework/core';
|
|
176
|
+
* import { flightpack } from '@flight-framework/bundler-flightpack';
|
|
177
|
+
*
|
|
178
|
+
* export default defineConfig({
|
|
179
|
+
* bundler: flightpack(),
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @packageDocumentation
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Create a FlightPack bundler adapter
|
|
188
|
+
*
|
|
189
|
+
* FlightPack is a native Rust bundler that provides:
|
|
190
|
+
* - 1,874+ files/second processing speed
|
|
191
|
+
* - Zero-config TypeScript/TSX support via Oxc
|
|
192
|
+
* - React Server Components (RSC) support
|
|
193
|
+
* - Tree shaking and code splitting
|
|
194
|
+
* - Hot Module Replacement (HMR)
|
|
195
|
+
*
|
|
196
|
+
* @param options - FlightPack adapter options
|
|
197
|
+
* @returns A BundlerAdapter instance
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* import { flightpack } from '@flight-framework/bundler-flightpack';
|
|
202
|
+
*
|
|
203
|
+
* const adapter = flightpack({
|
|
204
|
+
* minify: true,
|
|
205
|
+
* sourcemap: true,
|
|
206
|
+
* rsc: true,
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function flightpack(options?: FlightPackAdapterOptions): BundlerAdapter;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Package version
|
|
214
|
+
*/
|
|
215
|
+
declare const VERSION = "0.0.1";
|
|
216
|
+
|
|
217
|
+
export { type FlightPackAdapterOptions, type FlightPackBuildResult, type FlightPackChunkInfo, type FlightPackDevServerOptions, type FlightPackTransformOptions, type FlightPackTransformResult, VERSION, flightpack as createFlightPackAdapter, flightpack as default, flightpack };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/index.ts
|
|
9
|
+
import {
|
|
10
|
+
registerAdapter,
|
|
11
|
+
setDefaultAdapter,
|
|
12
|
+
createTimer,
|
|
13
|
+
createBuildError,
|
|
14
|
+
logDevServerStarted,
|
|
15
|
+
logBuildSuccess,
|
|
16
|
+
logBuildError,
|
|
17
|
+
resolvePath,
|
|
18
|
+
cleanDirectory
|
|
19
|
+
} from "@flight-framework/bundler";
|
|
20
|
+
var ADAPTER_NAME = "flight-flightpack";
|
|
21
|
+
var BUNDLER_NAME = "flightpack";
|
|
22
|
+
var nativeBinding = null;
|
|
23
|
+
async function loadNativeBinding() {
|
|
24
|
+
if (nativeBinding) return nativeBinding;
|
|
25
|
+
try {
|
|
26
|
+
const native = __require("@flight-framework/flightpack");
|
|
27
|
+
nativeBinding = native;
|
|
28
|
+
return native;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Failed to load FlightPack native binding. Make sure @flight-framework/flightpack is installed.
|
|
32
|
+
Original error: ${error}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function flightpack(options = {}) {
|
|
37
|
+
const adapter = {
|
|
38
|
+
name: ADAPTER_NAME,
|
|
39
|
+
bundler: BUNDLER_NAME,
|
|
40
|
+
options,
|
|
41
|
+
async createDevServer(config) {
|
|
42
|
+
const native = await loadNativeBinding();
|
|
43
|
+
const port = config.dev.port ?? 5173;
|
|
44
|
+
const host = config.dev.host ?? "localhost";
|
|
45
|
+
const https = config.dev.https === true;
|
|
46
|
+
const result = await native.startDevServer({
|
|
47
|
+
port,
|
|
48
|
+
publicDir: resolvePath(config.root, "public"),
|
|
49
|
+
outDir: resolvePath(config.root, config.build.outDir),
|
|
50
|
+
hmr: options.hmr ?? true,
|
|
51
|
+
root: config.root
|
|
52
|
+
});
|
|
53
|
+
logDevServerStarted(result.url, "FlightPack");
|
|
54
|
+
let watchHandle;
|
|
55
|
+
if (result.hmr) {
|
|
56
|
+
try {
|
|
57
|
+
watchHandle = native.watchFiles(
|
|
58
|
+
{
|
|
59
|
+
paths: [resolvePath(config.root, "src")],
|
|
60
|
+
extensions: ["ts", "tsx", "js", "jsx", "css"],
|
|
61
|
+
debounceMs: 100
|
|
62
|
+
},
|
|
63
|
+
async (event) => {
|
|
64
|
+
const updates = [];
|
|
65
|
+
for (const filePath of event.paths) {
|
|
66
|
+
try {
|
|
67
|
+
const { readFile } = await import("fs/promises");
|
|
68
|
+
const source = await readFile(filePath, "utf-8");
|
|
69
|
+
const transformed = await native.transform(source, filePath);
|
|
70
|
+
if (transformed.success) {
|
|
71
|
+
updates.push({
|
|
72
|
+
id: filePath,
|
|
73
|
+
path: filePath,
|
|
74
|
+
code: transformed.code,
|
|
75
|
+
accept: true,
|
|
76
|
+
deps: null
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
native.sendHmrError(`Failed to transform ${filePath}: ${error}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (updates.length > 0) {
|
|
84
|
+
native.sendHmrUpdate(updates);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.warn("[FlightPack] File watcher failed to start:", error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
url: result.url,
|
|
94
|
+
port: result.port,
|
|
95
|
+
host,
|
|
96
|
+
https,
|
|
97
|
+
async close() {
|
|
98
|
+
if (watchHandle) {
|
|
99
|
+
watchHandle.stop();
|
|
100
|
+
}
|
|
101
|
+
await native.stopDevServer();
|
|
102
|
+
},
|
|
103
|
+
restart: void 0,
|
|
104
|
+
reload: void 0,
|
|
105
|
+
hmrUpdate: void 0,
|
|
106
|
+
printUrls() {
|
|
107
|
+
console.log(` \u26A1 FlightPack Dev Server`);
|
|
108
|
+
console.log(` \u279C Local: ${result.url}`);
|
|
109
|
+
if (result.hmr) {
|
|
110
|
+
console.log(` \u279C HMR: enabled (WebSocket)`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
async build(config) {
|
|
116
|
+
const native = await loadNativeBinding();
|
|
117
|
+
const timer = createTimer();
|
|
118
|
+
try {
|
|
119
|
+
const minifyOption = typeof options.minify === "boolean" ? options.minify : typeof config.build.minify === "boolean" ? config.build.minify : true;
|
|
120
|
+
const flightpackOptions = {
|
|
121
|
+
entry: getEntryPoints(config),
|
|
122
|
+
outDir: resolvePath(config.root, config.build.outDir),
|
|
123
|
+
root: config.root,
|
|
124
|
+
minify: minifyOption,
|
|
125
|
+
sourcemap: typeof options.sourcemap === "boolean" ? options.sourcemap : typeof config.build.sourcemap === "boolean" ? config.build.sourcemap : true,
|
|
126
|
+
rsc: options.rsc ?? true
|
|
127
|
+
};
|
|
128
|
+
const result = await native.build(flightpackOptions);
|
|
129
|
+
const files = result.chunks.map((chunk) => ({
|
|
130
|
+
path: chunk.fileName,
|
|
131
|
+
size: chunk.size,
|
|
132
|
+
type: chunk.chunkType,
|
|
133
|
+
isDynamicEntry: false
|
|
134
|
+
}));
|
|
135
|
+
const buildResult = {
|
|
136
|
+
outDir: result.outputDir,
|
|
137
|
+
duration: timer.stop(),
|
|
138
|
+
files,
|
|
139
|
+
totalSize: result.totalSize,
|
|
140
|
+
errors: [],
|
|
141
|
+
warnings: [],
|
|
142
|
+
success: true
|
|
143
|
+
};
|
|
144
|
+
logBuildSuccess(buildResult);
|
|
145
|
+
return buildResult;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
const buildResult = {
|
|
148
|
+
outDir: resolvePath(config.root, config.build.outDir),
|
|
149
|
+
duration: timer.stop(),
|
|
150
|
+
files: [],
|
|
151
|
+
totalSize: 0,
|
|
152
|
+
errors: [createBuildError(error)],
|
|
153
|
+
warnings: [],
|
|
154
|
+
success: false
|
|
155
|
+
};
|
|
156
|
+
logBuildError(buildResult);
|
|
157
|
+
return buildResult;
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
async preview(config) {
|
|
161
|
+
const { createServer } = await import("http");
|
|
162
|
+
const { readFile, stat } = await import("fs/promises");
|
|
163
|
+
const { join, extname } = await import("path");
|
|
164
|
+
const outDir = resolvePath(config.root, config.build.outDir);
|
|
165
|
+
const port = 4173;
|
|
166
|
+
const host = "localhost";
|
|
167
|
+
const url = `http://${host}:${port}`;
|
|
168
|
+
const mimeTypes = {
|
|
169
|
+
".html": "text/html",
|
|
170
|
+
".js": "text/javascript",
|
|
171
|
+
".css": "text/css",
|
|
172
|
+
".json": "application/json"
|
|
173
|
+
};
|
|
174
|
+
const server = createServer(async (req, res) => {
|
|
175
|
+
let urlPath = req.url === "/" ? "/index.html" : req.url;
|
|
176
|
+
const filePath = join(outDir, urlPath);
|
|
177
|
+
try {
|
|
178
|
+
const content = await readFile(filePath);
|
|
179
|
+
const ext = extname(filePath);
|
|
180
|
+
res.setHeader("Content-Type", mimeTypes[ext] || "application/octet-stream");
|
|
181
|
+
res.writeHead(200);
|
|
182
|
+
res.end(content);
|
|
183
|
+
} catch {
|
|
184
|
+
try {
|
|
185
|
+
const htmlPath = filePath.endsWith(".html") ? filePath : `${filePath}.html`;
|
|
186
|
+
const content = await readFile(htmlPath);
|
|
187
|
+
res.setHeader("Content-Type", "text/html");
|
|
188
|
+
res.writeHead(200);
|
|
189
|
+
res.end(content);
|
|
190
|
+
} catch {
|
|
191
|
+
res.writeHead(404);
|
|
192
|
+
res.end("Not Found");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
server.listen(port, host);
|
|
197
|
+
return {
|
|
198
|
+
url,
|
|
199
|
+
port,
|
|
200
|
+
async close() {
|
|
201
|
+
return new Promise((resolve) => {
|
|
202
|
+
server.close(() => resolve());
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
printUrls() {
|
|
206
|
+
console.log(` \u279C Preview: ${url}`);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
async clean(config) {
|
|
211
|
+
const outDir = resolvePath(config.root, config.build.outDir);
|
|
212
|
+
await cleanDirectory(outDir);
|
|
213
|
+
},
|
|
214
|
+
async version() {
|
|
215
|
+
const native = await loadNativeBinding();
|
|
216
|
+
return native.version();
|
|
217
|
+
},
|
|
218
|
+
async transform(code, id, transformOptions) {
|
|
219
|
+
const native = await loadNativeBinding();
|
|
220
|
+
if (id.endsWith(".css")) {
|
|
221
|
+
const isCssModule = id.includes(".module.");
|
|
222
|
+
if (isCssModule) {
|
|
223
|
+
const result2 = native.transformCssModule(code, id);
|
|
224
|
+
const classMapObject = Object.fromEntries(
|
|
225
|
+
result2.classMap.map((c) => [c.original, c.hashed])
|
|
226
|
+
);
|
|
227
|
+
const jsCode = [
|
|
228
|
+
`// CSS Module: ${id}`,
|
|
229
|
+
`const styles = ${JSON.stringify(classMapObject)};`,
|
|
230
|
+
`export default styles;`,
|
|
231
|
+
``,
|
|
232
|
+
`// Inject CSS`,
|
|
233
|
+
`if (typeof document !== 'undefined') {`,
|
|
234
|
+
` const style = document.createElement('style');`,
|
|
235
|
+
` style.textContent = ${JSON.stringify(result2.code)};`,
|
|
236
|
+
` document.head.appendChild(style);`,
|
|
237
|
+
`}`
|
|
238
|
+
].join("\n");
|
|
239
|
+
return {
|
|
240
|
+
code: jsCode,
|
|
241
|
+
map: null
|
|
242
|
+
};
|
|
243
|
+
} else {
|
|
244
|
+
const minified = native.minifyCss(code, id);
|
|
245
|
+
const jsCode = [
|
|
246
|
+
`// CSS: ${id}`,
|
|
247
|
+
`if (typeof document !== 'undefined') {`,
|
|
248
|
+
` const style = document.createElement('style');`,
|
|
249
|
+
` style.textContent = ${JSON.stringify(minified)};`,
|
|
250
|
+
` document.head.appendChild(style);`,
|
|
251
|
+
`}`
|
|
252
|
+
].join("\n");
|
|
253
|
+
return {
|
|
254
|
+
code: jsCode,
|
|
255
|
+
map: null
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const sourcemapOption = typeof transformOptions?.sourcemap === "boolean" ? transformOptions.sourcemap : true;
|
|
260
|
+
const result = await native.transform(code, id, {
|
|
261
|
+
sourcemap: sourcemapOption,
|
|
262
|
+
target: transformOptions?.target ?? "es2022"
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
code: result.code,
|
|
266
|
+
map: result.map
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
if (options.autoRegister !== false) {
|
|
271
|
+
registerAdapter(adapter);
|
|
272
|
+
setDefaultAdapter(ADAPTER_NAME);
|
|
273
|
+
}
|
|
274
|
+
return adapter;
|
|
275
|
+
}
|
|
276
|
+
function getEntryPoints(config) {
|
|
277
|
+
const entries = [];
|
|
278
|
+
const possibleEntries = [
|
|
279
|
+
"src/index.ts",
|
|
280
|
+
"src/index.tsx",
|
|
281
|
+
"src/main.ts",
|
|
282
|
+
"src/main.tsx",
|
|
283
|
+
"src/app.ts",
|
|
284
|
+
"src/app.tsx"
|
|
285
|
+
];
|
|
286
|
+
entries.push("src/index.tsx");
|
|
287
|
+
return entries;
|
|
288
|
+
}
|
|
289
|
+
var index_default = flightpack;
|
|
290
|
+
var VERSION = "0.0.1";
|
|
291
|
+
export {
|
|
292
|
+
VERSION,
|
|
293
|
+
flightpack as createFlightPackAdapter,
|
|
294
|
+
index_default as default,
|
|
295
|
+
flightpack
|
|
296
|
+
};
|
|
297
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\r\n * @flight-framework/bundler-flightpack\r\n * \r\n * FlightPack native Rust bundler adapter for Flight Framework.\r\n * Wraps the native Rust bundler for maximum performance.\r\n * \r\n * @example\r\n * ```typescript\r\n * // In flight.config.ts\r\n * import { defineConfig } from '@flight-framework/core';\r\n * import { flightpack } from '@flight-framework/bundler-flightpack';\r\n * \r\n * export default defineConfig({\r\n * bundler: flightpack(),\r\n * });\r\n * ```\r\n * \r\n * @packageDocumentation\r\n */\r\n\r\nimport type {\r\n BundlerAdapter,\r\n DevServer,\r\n BuildResult,\r\n PreviewServer,\r\n OutputFile,\r\n TransformOptions,\r\n TransformResult as BundlerTransformResult,\r\n} from '@flight-framework/bundler';\r\nimport {\r\n registerAdapter,\r\n setDefaultAdapter,\r\n createTimer,\r\n createBuildError,\r\n logDevServerStarted,\r\n logBuildSuccess,\r\n logBuildError,\r\n resolvePath,\r\n cleanDirectory,\r\n} from '@flight-framework/bundler';\r\nimport type { FlightConfig } from '@flight-framework/core/config';\r\nimport type {\r\n FlightPackAdapterOptions,\r\n} from './types.js';\r\n\r\n// Re-export types\r\nexport * from './types.js';\r\n\r\n// ============================================================================\r\n// Constants\r\n// ============================================================================\r\n\r\nconst ADAPTER_NAME = 'flight-flightpack';\r\nconst BUNDLER_NAME = 'flightpack';\r\n\r\n// ============================================================================\r\n// Native Binding Loader\r\n// ============================================================================\r\n\r\n/**\r\n * Native binding interface matching the NAPI exports\r\n */\r\ninterface NativeBinding {\r\n FlightPack: new (options?: FlightPackNativeOptions | undefined | null) => {\r\n build(): Promise<NativeBuildResult>;\r\n };\r\n build: (options: FlightPackNativeOptions) => Promise<NativeBuildResult>;\r\n transform: (code: string, filename: string, options?: NativeTransformOptions | undefined | null) => Promise<NativeTransformResult>;\r\n version: () => string;\r\n // Dev Server\r\n startDevServer: (options?: NativeDevServerOptions | undefined | null) => Promise<NativeDevServerResult>;\r\n stopDevServer: () => Promise<boolean>;\r\n isDevServerRunning: () => boolean;\r\n // HMR\r\n sendHmrUpdate: (modules: NativeHMRModuleUpdate[]) => boolean;\r\n sendHmrError: (message: string) => boolean;\r\n // File Watcher\r\n watchFiles: (options: NativeWatcherOptions, callback: (event: NativeWatchEvent) => void) => NativeWatchHandle;\r\n // CSS Processing\r\n transformCss: (code: string, filename: string, options?: NativeCssTransformOptions | undefined | null) => NativeCssTransformResult;\r\n minifyCss: (code: string, filename: string) => string;\r\n transformCssModule: (code: string, filename: string) => NativeCssModuleResult;\r\n}\r\n\r\n/**\r\n * Native CSS transform options\r\n */\r\ninterface NativeCssTransformOptions {\r\n minify?: boolean;\r\n cssModules?: boolean;\r\n cssModulesPattern?: string;\r\n dashedIdents?: boolean;\r\n sourcemap?: boolean;\r\n browserTargets?: {\r\n chrome?: number;\r\n firefox?: number;\r\n safari?: number;\r\n edge?: number;\r\n };\r\n}\r\n\r\n/**\r\n * Native CSS transform result\r\n */\r\ninterface NativeCssTransformResult {\r\n code: string;\r\n map?: string | null;\r\n exports: Array<{\r\n original: string;\r\n hashed: string;\r\n isReferenced: boolean;\r\n composes: string[];\r\n }>;\r\n success: boolean;\r\n}\r\n\r\n/**\r\n * Native CSS module result\r\n */\r\ninterface NativeCssModuleResult {\r\n code: string;\r\n classMap: Array<{\r\n original: string;\r\n hashed: string;\r\n }>;\r\n}\r\n\r\n/**\r\n * Platform type\r\n */\r\ntype NativePlatform = 'browser' | 'node' | 'edge' | 'neutral';\r\n\r\n/**\r\n * Extended NativeBinding interface with universal support\r\n */\r\ninterface NativeBindingExtended extends NativeBinding {\r\n // Externals Detection\r\n isNodeBuiltin: (moduleId: string) => boolean;\r\n getNodeBuiltins: () => string[];\r\n getNodeBuiltinsPrefixed: () => string[];\r\n isBareImport: (moduleId: string) => boolean;\r\n isEdgeCompatible: (moduleId: string) => boolean;\r\n getEdgeIncompatibleModules: () => string[];\r\n getPlatformConditions: (platform: string) => string[];\r\n}\r\n\r\n\r\n/**\r\n * Native dev server options\r\n */\r\ninterface NativeDevServerOptions {\r\n port?: number;\r\n publicDir?: string;\r\n outDir?: string;\r\n hmr?: boolean;\r\n root?: string;\r\n}\r\n\r\n/**\r\n * Native dev server result\r\n */\r\ninterface NativeDevServerResult {\r\n url: string;\r\n port: number;\r\n hmr: boolean;\r\n}\r\n\r\n/**\r\n * Native HMR module update\r\n */\r\ninterface NativeHMRModuleUpdate {\r\n id: string;\r\n path: string;\r\n code: string;\r\n deps?: string[] | null;\r\n accept: boolean;\r\n}\r\n\r\n/**\r\n * Native watcher options\r\n */\r\ninterface NativeWatcherOptions {\r\n paths: string[];\r\n extensions?: string[] | null;\r\n debounceMs?: number | null;\r\n}\r\n\r\n/**\r\n * Native watch event\r\n */\r\ninterface NativeWatchEvent {\r\n paths: string[];\r\n eventType: string;\r\n}\r\n\r\n/**\r\n * Native watch handle\r\n */\r\ninterface NativeWatchHandle {\r\n stop(): boolean;\r\n}\r\n\r\n/**\r\n * Native options matching Rust struct\r\n */\r\ninterface FlightPackNativeOptions {\r\n entry: string[];\r\n outDir: string;\r\n root?: string;\r\n minify?: boolean;\r\n sourcemap?: boolean;\r\n rsc?: boolean;\r\n}\r\n\r\n/**\r\n * Native build result matching Rust struct\r\n */\r\ninterface NativeBuildResult {\r\n outputDir: string;\r\n durationMs: number;\r\n totalSize: number;\r\n chunks: NativeChunkInfo[];\r\n}\r\n\r\n/**\r\n * Native chunk info matching Rust struct\r\n */\r\ninterface NativeChunkInfo {\r\n fileName: string;\r\n chunkType: string;\r\n size: number;\r\n}\r\n\r\n/**\r\n * Native transform options matching Rust struct\r\n */\r\ninterface NativeTransformOptions {\r\n sourcemap?: boolean;\r\n minify?: boolean;\r\n target?: string;\r\n jsxFactory?: string;\r\n jsxFragment?: string;\r\n}\r\n\r\n/**\r\n * Native transform result matching Rust struct\r\n */\r\ninterface NativeTransformResult {\r\n code: string;\r\n map?: string | null;\r\n success: boolean;\r\n}\r\n\r\n/**\r\n * Lazy-loaded native FlightPack binding\r\n * This defers loading until actually needed, improving startup time\r\n */\r\nlet nativeBinding: NativeBinding | null = null;\r\n\r\nasync function loadNativeBinding(): Promise<NativeBinding> {\r\n if (nativeBinding) return nativeBinding;\r\n\r\n try {\r\n // Dynamic import of the native module\r\n // eslint-disable-next-line @typescript-eslint/no-require-imports\r\n const native = require('@flight-framework/flightpack') as NativeBinding;\r\n nativeBinding = native;\r\n return native;\r\n } catch (error) {\r\n throw new Error(\r\n `Failed to load FlightPack native binding. ` +\r\n `Make sure @flight-framework/flightpack is installed.\\n` +\r\n `Original error: ${error}`\r\n );\r\n }\r\n}\r\n\r\n// ============================================================================\r\n// Adapter Implementation\r\n// ============================================================================\r\n\r\n/**\r\n * Create a FlightPack bundler adapter\r\n * \r\n * FlightPack is a native Rust bundler that provides:\r\n * - 1,874+ files/second processing speed\r\n * - Zero-config TypeScript/TSX support via Oxc\r\n * - React Server Components (RSC) support\r\n * - Tree shaking and code splitting\r\n * - Hot Module Replacement (HMR)\r\n * \r\n * @param options - FlightPack adapter options\r\n * @returns A BundlerAdapter instance\r\n * \r\n * @example\r\n * ```typescript\r\n * import { flightpack } from '@flight-framework/bundler-flightpack';\r\n * \r\n * const adapter = flightpack({\r\n * minify: true,\r\n * sourcemap: true,\r\n * rsc: true,\r\n * });\r\n * ```\r\n */\r\nexport function flightpack(options: FlightPackAdapterOptions = {}): BundlerAdapter {\r\n const adapter: BundlerAdapter = {\r\n name: ADAPTER_NAME,\r\n bundler: BUNDLER_NAME,\r\n options,\r\n\r\n async createDevServer(config: FlightConfig): Promise<DevServer> {\r\n const native = await loadNativeBinding();\r\n\r\n const port = config.dev.port ?? 5173;\r\n const host = config.dev.host ?? 'localhost';\r\n const https = config.dev.https === true;\r\n\r\n // Use native Rust dev server with Axum and WebSocket HMR\r\n const result = await native.startDevServer({\r\n port,\r\n publicDir: resolvePath(config.root, 'public'),\r\n outDir: resolvePath(config.root, config.build.outDir),\r\n hmr: options.hmr ?? true,\r\n root: config.root,\r\n });\r\n\r\n logDevServerStarted(result.url, 'FlightPack');\r\n\r\n // Set up file watcher for HMR updates\r\n let watchHandle: NativeWatchHandle | undefined;\r\n if (result.hmr) {\r\n try {\r\n watchHandle = native.watchFiles(\r\n {\r\n paths: [resolvePath(config.root, 'src')],\r\n extensions: ['ts', 'tsx', 'js', 'jsx', 'css'],\r\n debounceMs: 100,\r\n },\r\n async (event: NativeWatchEvent) => {\r\n // Transform changed files and send HMR updates\r\n const updates: NativeHMRModuleUpdate[] = [];\r\n\r\n for (const filePath of event.paths) {\r\n try {\r\n const { readFile } = await import('node:fs/promises');\r\n const source = await readFile(filePath, 'utf-8');\r\n const transformed = await native.transform(source, filePath);\r\n\r\n if (transformed.success) {\r\n updates.push({\r\n id: filePath,\r\n path: filePath,\r\n code: transformed.code,\r\n accept: true,\r\n deps: null,\r\n });\r\n }\r\n } catch (error) {\r\n native.sendHmrError(`Failed to transform ${filePath}: ${error}`);\r\n }\r\n }\r\n\r\n if (updates.length > 0) {\r\n native.sendHmrUpdate(updates);\r\n }\r\n }\r\n );\r\n } catch (error) {\r\n console.warn('[FlightPack] File watcher failed to start:', error);\r\n }\r\n }\r\n\r\n return {\r\n url: result.url,\r\n port: result.port,\r\n host: host as string,\r\n https,\r\n async close() {\r\n // Stop file watcher\r\n if (watchHandle) {\r\n watchHandle.stop();\r\n }\r\n // Stop native dev server\r\n await native.stopDevServer();\r\n },\r\n restart: undefined,\r\n reload: undefined,\r\n hmrUpdate: undefined,\r\n printUrls() {\r\n console.log(` ⚡ FlightPack Dev Server`);\r\n console.log(` ➜ Local: ${result.url}`);\r\n if (result.hmr) {\r\n console.log(` ➜ HMR: enabled (WebSocket)`);\r\n }\r\n },\r\n };\r\n },\r\n\r\n async build(config: FlightConfig): Promise<BuildResult> {\r\n const native = await loadNativeBinding();\r\n const timer = createTimer();\r\n\r\n try {\r\n // Build FlightPack options from config\r\n const minifyOption = typeof options.minify === 'boolean'\r\n ? options.minify\r\n : typeof config.build.minify === 'boolean'\r\n ? config.build.minify\r\n : true;\r\n\r\n const flightpackOptions: FlightPackNativeOptions = {\r\n entry: getEntryPoints(config),\r\n outDir: resolvePath(config.root, config.build.outDir),\r\n root: config.root,\r\n minify: minifyOption,\r\n sourcemap: typeof options.sourcemap === 'boolean'\r\n ? options.sourcemap\r\n : typeof config.build.sourcemap === 'boolean'\r\n ? config.build.sourcemap\r\n : true,\r\n rsc: options.rsc ?? true,\r\n };\r\n\r\n // Run the native build\r\n const result = await native.build(flightpackOptions);\r\n\r\n // Convert to BundlerAdapter result format\r\n const files: OutputFile[] = result.chunks.map((chunk: NativeChunkInfo) => ({\r\n path: chunk.fileName,\r\n size: chunk.size,\r\n type: chunk.chunkType as 'entry' | 'chunk' | 'asset',\r\n isDynamicEntry: false,\r\n }));\r\n\r\n const buildResult: BuildResult = {\r\n outDir: result.outputDir,\r\n duration: timer.stop(),\r\n files,\r\n totalSize: result.totalSize,\r\n errors: [],\r\n warnings: [],\r\n success: true,\r\n };\r\n\r\n logBuildSuccess(buildResult);\r\n return buildResult;\r\n\r\n } catch (error) {\r\n const buildResult: BuildResult = {\r\n outDir: resolvePath(config.root, config.build.outDir),\r\n duration: timer.stop(),\r\n files: [],\r\n totalSize: 0,\r\n errors: [createBuildError(error)],\r\n warnings: [],\r\n success: false,\r\n };\r\n\r\n logBuildError(buildResult);\r\n return buildResult;\r\n }\r\n },\r\n\r\n async preview(config: FlightConfig): Promise<PreviewServer> {\r\n const { createServer } = await import('node:http');\r\n const { readFile, stat } = await import('node:fs/promises');\r\n const { join, extname } = await import('node:path');\r\n\r\n const outDir = resolvePath(config.root, config.build.outDir);\r\n const port = 4173;\r\n const host = 'localhost';\r\n const url = `http://${host}:${port}`;\r\n\r\n const mimeTypes: Record<string, string> = {\r\n '.html': 'text/html',\r\n '.js': 'text/javascript',\r\n '.css': 'text/css',\r\n '.json': 'application/json',\r\n };\r\n\r\n const server = createServer(async (req, res) => {\r\n let urlPath = req.url === '/' ? '/index.html' : req.url!;\r\n const filePath = join(outDir, urlPath);\r\n\r\n try {\r\n const content = await readFile(filePath);\r\n const ext = extname(filePath);\r\n res.setHeader('Content-Type', mimeTypes[ext] || 'application/octet-stream');\r\n res.writeHead(200);\r\n res.end(content);\r\n } catch {\r\n // Try with .html extension\r\n try {\r\n const htmlPath = filePath.endsWith('.html') ? filePath : `${filePath}.html`;\r\n const content = await readFile(htmlPath);\r\n res.setHeader('Content-Type', 'text/html');\r\n res.writeHead(200);\r\n res.end(content);\r\n } catch {\r\n res.writeHead(404);\r\n res.end('Not Found');\r\n }\r\n }\r\n });\r\n\r\n server.listen(port, host);\r\n\r\n return {\r\n url,\r\n port,\r\n async close() {\r\n return new Promise((resolve) => {\r\n server.close(() => resolve());\r\n });\r\n },\r\n printUrls() {\r\n console.log(` ➜ Preview: ${url}`);\r\n },\r\n };\r\n },\r\n\r\n async clean(config: FlightConfig): Promise<void> {\r\n const outDir = resolvePath(config.root, config.build.outDir);\r\n await cleanDirectory(outDir);\r\n },\r\n\r\n async version(): Promise<string> {\r\n const native = await loadNativeBinding();\r\n return native.version();\r\n },\r\n\r\n async transform(\r\n code: string,\r\n id: string,\r\n transformOptions?: TransformOptions\r\n ): Promise<BundlerTransformResult> {\r\n const native = await loadNativeBinding();\r\n\r\n // Handle CSS files with native CSS processor\r\n if (id.endsWith('.css')) {\r\n const isCssModule = id.includes('.module.');\r\n\r\n if (isCssModule) {\r\n // CSS Modules: transform and generate class mappings\r\n const result = native.transformCssModule(code, id);\r\n\r\n // Generate JS export for CSS modules\r\n const classMapObject = Object.fromEntries(\r\n result.classMap.map(c => [c.original, c.hashed])\r\n );\r\n\r\n const jsCode = [\r\n `// CSS Module: ${id}`,\r\n `const styles = ${JSON.stringify(classMapObject)};`,\r\n `export default styles;`,\r\n ``,\r\n `// Inject CSS`,\r\n `if (typeof document !== 'undefined') {`,\r\n ` const style = document.createElement('style');`,\r\n ` style.textContent = ${JSON.stringify(result.code)};`,\r\n ` document.head.appendChild(style);`,\r\n `}`,\r\n ].join('\\n');\r\n\r\n return {\r\n code: jsCode,\r\n map: null,\r\n };\r\n } else {\r\n // Regular CSS: just minify and inject\r\n const minified = native.minifyCss(code, id);\r\n\r\n const jsCode = [\r\n `// CSS: ${id}`,\r\n `if (typeof document !== 'undefined') {`,\r\n ` const style = document.createElement('style');`,\r\n ` style.textContent = ${JSON.stringify(minified)};`,\r\n ` document.head.appendChild(style);`,\r\n `}`,\r\n ].join('\\n');\r\n\r\n return {\r\n code: jsCode,\r\n map: null,\r\n };\r\n }\r\n }\r\n\r\n // Handle TypeScript/JavaScript files\r\n const sourcemapOption = typeof transformOptions?.sourcemap === 'boolean'\r\n ? transformOptions.sourcemap\r\n : true;\r\n\r\n const result = await native.transform(code, id, {\r\n sourcemap: sourcemapOption,\r\n target: transformOptions?.target ?? 'es2022',\r\n });\r\n\r\n return {\r\n code: result.code,\r\n map: result.map,\r\n };\r\n },\r\n };\r\n\r\n // Auto-register as default if specified\r\n if (options.autoRegister !== false) {\r\n registerAdapter(adapter);\r\n\r\n // Set as default bundler\r\n setDefaultAdapter(ADAPTER_NAME);\r\n }\r\n\r\n return adapter;\r\n}\r\n\r\n// ============================================================================\r\n// Helper Functions\r\n// ============================================================================\r\n\r\n/**\r\n * Get entry points from Flight configuration\r\n */\r\nfunction getEntryPoints(config: FlightConfig): string[] {\r\n // Default entry points for Flight applications\r\n const entries: string[] = [];\r\n\r\n // Look for common entry patterns\r\n const possibleEntries = [\r\n 'src/index.ts',\r\n 'src/index.tsx',\r\n 'src/main.ts',\r\n 'src/main.tsx',\r\n 'src/app.ts',\r\n 'src/app.tsx',\r\n ];\r\n\r\n // In a real implementation, we'd check which files exist\r\n // For now, return the first common pattern\r\n entries.push('src/index.tsx');\r\n\r\n return entries;\r\n}\r\n\r\n// ============================================================================\r\n// Exports\r\n// ============================================================================\r\n\r\nexport default flightpack;\r\nexport { flightpack as createFlightPackAdapter };\r\n\r\n/**\r\n * Package version\r\n */\r\nexport const VERSION = '0.0.1';\r\n"],"mappings":";;;;;;;;AA6BA;AAAA,EACI;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACG;AAaP,IAAM,eAAe;AACrB,IAAM,eAAe;AA4MrB,IAAI,gBAAsC;AAE1C,eAAe,oBAA4C;AACvD,MAAI,cAAe,QAAO;AAE1B,MAAI;AAGA,UAAM,SAAS,UAAQ,8BAA8B;AACrD,oBAAgB;AAChB,WAAO;AAAA,EACX,SAAS,OAAO;AACZ,UAAM,IAAI;AAAA,MACN;AAAA,kBAEmB,KAAK;AAAA,IAC5B;AAAA,EACJ;AACJ;AA8BO,SAAS,WAAW,UAAoC,CAAC,GAAmB;AAC/E,QAAM,UAA0B;AAAA,IAC5B,MAAM;AAAA,IACN,SAAS;AAAA,IACT;AAAA,IAEA,MAAM,gBAAgB,QAA0C;AAC5D,YAAM,SAAS,MAAM,kBAAkB;AAEvC,YAAM,OAAO,OAAO,IAAI,QAAQ;AAChC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3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "FlightPack native Rust bundler adapter for Flight Framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"keywords": [
|
|
19
|
+
"flight",
|
|
20
|
+
"flightpack",
|
|
21
|
+
"bundler",
|
|
22
|
+
"rust",
|
|
23
|
+
"native",
|
|
24
|
+
"performance",
|
|
25
|
+
"typescript",
|
|
26
|
+
"react"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/flight-framework/flight.git",
|
|
31
|
+
"directory": "packages/bundler-flightpack"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"clean": "rimraf dist"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@flight-framework/bundler": "^3.0.0",
|
|
42
|
+
"@flight-framework/core": "^0.6.7"
|
|
43
|
+
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"@flight-framework/flightpack": "^0.1.1"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"tsup": "^8.5.1",
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=20.0.0"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
}
|
|
57
|
+
}
|