@oaysus/cli 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 +166 -0
- package/bin/oaysus.js +6 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +174 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +75 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +23 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/whoami.d.ts +2 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +44 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/components/App.d.ts +43 -0
- package/dist/components/App.d.ts.map +1 -0
- package/dist/components/App.js +63 -0
- package/dist/components/App.js.map +1 -0
- package/dist/components/BuildProgress.d.ts +16 -0
- package/dist/components/BuildProgress.d.ts.map +1 -0
- package/dist/components/BuildProgress.js +42 -0
- package/dist/components/BuildProgress.js.map +1 -0
- package/dist/components/ErrorMessage.d.ts +13 -0
- package/dist/components/ErrorMessage.d.ts.map +1 -0
- package/dist/components/ErrorMessage.js +29 -0
- package/dist/components/ErrorMessage.js.map +1 -0
- package/dist/components/FileList.d.ts +13 -0
- package/dist/components/FileList.d.ts.map +1 -0
- package/dist/components/FileList.js +25 -0
- package/dist/components/FileList.js.map +1 -0
- package/dist/components/Header.d.ts +12 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.js +18 -0
- package/dist/components/Header.js.map +1 -0
- package/dist/components/LastCommand.d.ts +9 -0
- package/dist/components/LastCommand.d.ts.map +1 -0
- package/dist/components/LastCommand.js +39 -0
- package/dist/components/LastCommand.js.map +1 -0
- package/dist/components/Logo.d.ts +14 -0
- package/dist/components/Logo.d.ts.map +1 -0
- package/dist/components/Logo.js +44 -0
- package/dist/components/Logo.js.map +1 -0
- package/dist/components/ProgressBar.d.ts +13 -0
- package/dist/components/ProgressBar.d.ts.map +1 -0
- package/dist/components/ProgressBar.js +20 -0
- package/dist/components/ProgressBar.js.map +1 -0
- package/dist/components/SlashCommands.d.ts +17 -0
- package/dist/components/SlashCommands.d.ts.map +1 -0
- package/dist/components/SlashCommands.js +59 -0
- package/dist/components/SlashCommands.js.map +1 -0
- package/dist/components/Spinner.d.ts +13 -0
- package/dist/components/Spinner.d.ts.map +1 -0
- package/dist/components/Spinner.js +16 -0
- package/dist/components/Spinner.js.map +1 -0
- package/dist/components/StatusCard.d.ts +14 -0
- package/dist/components/StatusCard.d.ts.map +1 -0
- package/dist/components/StatusCard.js +40 -0
- package/dist/components/StatusCard.js.map +1 -0
- package/dist/components/SuccessMessage.d.ts +12 -0
- package/dist/components/SuccessMessage.d.ts.map +1 -0
- package/dist/components/SuccessMessage.js +18 -0
- package/dist/components/SuccessMessage.js.map +1 -0
- package/dist/components/UploadProgress.d.ts +13 -0
- package/dist/components/UploadProgress.d.ts.map +1 -0
- package/dist/components/UploadProgress.js +40 -0
- package/dist/components/UploadProgress.js.map +1 -0
- package/dist/components/ValidationProgress.d.ts +12 -0
- package/dist/components/ValidationProgress.d.ts.map +1 -0
- package/dist/components/ValidationProgress.js +44 -0
- package/dist/components/ValidationProgress.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/core/framework-registry.d.ts +27 -0
- package/dist/lib/core/framework-registry.d.ts.map +1 -0
- package/dist/lib/core/framework-registry.js +67 -0
- package/dist/lib/core/framework-registry.js.map +1 -0
- package/dist/lib/core/types.d.ts +124 -0
- package/dist/lib/core/types.d.ts.map +1 -0
- package/dist/lib/core/types.js +6 -0
- package/dist/lib/core/types.js.map +1 -0
- package/dist/lib/project-generator.d.ts +15 -0
- package/dist/lib/project-generator.d.ts.map +1 -0
- package/dist/lib/project-generator.js +286 -0
- package/dist/lib/project-generator.js.map +1 -0
- package/dist/lib/push.d.ts +20 -0
- package/dist/lib/push.d.ts.map +1 -0
- package/dist/lib/push.js +222 -0
- package/dist/lib/push.js.map +1 -0
- package/dist/lib/react/builder.d.ts +45 -0
- package/dist/lib/react/builder.d.ts.map +1 -0
- package/dist/lib/react/builder.js +381 -0
- package/dist/lib/react/builder.js.map +1 -0
- package/dist/lib/react/bundler.d.ts +104 -0
- package/dist/lib/react/bundler.d.ts.map +1 -0
- package/dist/lib/react/bundler.js +654 -0
- package/dist/lib/react/bundler.js.map +1 -0
- package/dist/lib/react/config.d.ts +34 -0
- package/dist/lib/react/config.d.ts.map +1 -0
- package/dist/lib/react/config.js +64 -0
- package/dist/lib/react/config.js.map +1 -0
- package/dist/lib/react/import-map.d.ts +54 -0
- package/dist/lib/react/import-map.d.ts.map +1 -0
- package/dist/lib/react/import-map.js +187 -0
- package/dist/lib/react/import-map.js.map +1 -0
- package/dist/lib/shared/auth-middleware.d.ts +29 -0
- package/dist/lib/shared/auth-middleware.d.ts.map +1 -0
- package/dist/lib/shared/auth-middleware.js +48 -0
- package/dist/lib/shared/auth-middleware.js.map +1 -0
- package/dist/lib/shared/auth.d.ts +50 -0
- package/dist/lib/shared/auth.d.ts.map +1 -0
- package/dist/lib/shared/auth.js +243 -0
- package/dist/lib/shared/auth.js.map +1 -0
- package/dist/lib/shared/cdn-downloader.d.ts +30 -0
- package/dist/lib/shared/cdn-downloader.d.ts.map +1 -0
- package/dist/lib/shared/cdn-downloader.js +126 -0
- package/dist/lib/shared/cdn-downloader.js.map +1 -0
- package/dist/lib/shared/command-history.d.ts +29 -0
- package/dist/lib/shared/command-history.d.ts.map +1 -0
- package/dist/lib/shared/command-history.js +73 -0
- package/dist/lib/shared/command-history.js.map +1 -0
- package/dist/lib/shared/commands.d.ts +24 -0
- package/dist/lib/shared/commands.d.ts.map +1 -0
- package/dist/lib/shared/commands.js +63 -0
- package/dist/lib/shared/commands.js.map +1 -0
- package/dist/lib/shared/config.d.ts +40 -0
- package/dist/lib/shared/config.d.ts.map +1 -0
- package/dist/lib/shared/config.js +69 -0
- package/dist/lib/shared/config.js.map +1 -0
- package/dist/lib/shared/file-utils.d.ts +45 -0
- package/dist/lib/shared/file-utils.d.ts.map +1 -0
- package/dist/lib/shared/file-utils.js +88 -0
- package/dist/lib/shared/file-utils.js.map +1 -0
- package/dist/lib/shared/import-analyzer.d.ts +49 -0
- package/dist/lib/shared/import-analyzer.d.ts.map +1 -0
- package/dist/lib/shared/import-analyzer.js +268 -0
- package/dist/lib/shared/import-analyzer.js.map +1 -0
- package/dist/lib/shared/path-builder.d.ts +55 -0
- package/dist/lib/shared/path-builder.d.ts.map +1 -0
- package/dist/lib/shared/path-builder.js +66 -0
- package/dist/lib/shared/path-builder.js.map +1 -0
- package/dist/lib/shared/uploader.d.ts +79 -0
- package/dist/lib/shared/uploader.d.ts.map +1 -0
- package/dist/lib/shared/uploader.js +340 -0
- package/dist/lib/shared/uploader.js.map +1 -0
- package/dist/lib/shared/zip-creator.d.ts +18 -0
- package/dist/lib/shared/zip-creator.d.ts.map +1 -0
- package/dist/lib/shared/zip-creator.js +131 -0
- package/dist/lib/shared/zip-creator.js.map +1 -0
- package/dist/lib/svelte/builder.d.ts +37 -0
- package/dist/lib/svelte/builder.d.ts.map +1 -0
- package/dist/lib/svelte/builder.js +364 -0
- package/dist/lib/svelte/builder.js.map +1 -0
- package/dist/lib/svelte/bundler.d.ts +92 -0
- package/dist/lib/svelte/bundler.d.ts.map +1 -0
- package/dist/lib/svelte/bundler.js +499 -0
- package/dist/lib/svelte/bundler.js.map +1 -0
- package/dist/lib/svelte/config.d.ts +22 -0
- package/dist/lib/svelte/config.d.ts.map +1 -0
- package/dist/lib/svelte/config.js +65 -0
- package/dist/lib/svelte/config.js.map +1 -0
- package/dist/lib/svelte/import-map.d.ts +42 -0
- package/dist/lib/svelte/import-map.d.ts.map +1 -0
- package/dist/lib/svelte/import-map.js +197 -0
- package/dist/lib/svelte/import-map.js.map +1 -0
- package/dist/lib/template-manager.d.ts +33 -0
- package/dist/lib/template-manager.d.ts.map +1 -0
- package/dist/lib/template-manager.js +69 -0
- package/dist/lib/template-manager.js.map +1 -0
- package/dist/lib/validator.d.ts +10 -0
- package/dist/lib/validator.d.ts.map +1 -0
- package/dist/lib/validator.js +343 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/lib/vue/builder.d.ts +37 -0
- package/dist/lib/vue/builder.d.ts.map +1 -0
- package/dist/lib/vue/builder.js +366 -0
- package/dist/lib/vue/builder.js.map +1 -0
- package/dist/lib/vue/bundler.d.ts +78 -0
- package/dist/lib/vue/bundler.d.ts.map +1 -0
- package/dist/lib/vue/bundler.js +208 -0
- package/dist/lib/vue/bundler.js.map +1 -0
- package/dist/lib/vue/config.d.ts +18 -0
- package/dist/lib/vue/config.d.ts.map +1 -0
- package/dist/lib/vue/config.js +42 -0
- package/dist/lib/vue/config.js.map +1 -0
- package/dist/lib/vue/import-map.d.ts +42 -0
- package/dist/lib/vue/import-map.d.ts.map +1 -0
- package/dist/lib/vue/import-map.js +156 -0
- package/dist/lib/vue/import-map.js.map +1 -0
- package/dist/screens/BuildScreen.d.ts +8 -0
- package/dist/screens/BuildScreen.d.ts.map +1 -0
- package/dist/screens/BuildScreen.js +158 -0
- package/dist/screens/BuildScreen.js.map +1 -0
- package/dist/screens/CreateScreen.d.ts +12 -0
- package/dist/screens/CreateScreen.d.ts.map +1 -0
- package/dist/screens/CreateScreen.js +305 -0
- package/dist/screens/CreateScreen.js.map +1 -0
- package/dist/screens/InitScreen.d.ts +11 -0
- package/dist/screens/InitScreen.d.ts.map +1 -0
- package/dist/screens/InitScreen.js +339 -0
- package/dist/screens/InitScreen.js.map +1 -0
- package/dist/screens/LoginScreen.d.ts +15 -0
- package/dist/screens/LoginScreen.d.ts.map +1 -0
- package/dist/screens/LoginScreen.js +427 -0
- package/dist/screens/LoginScreen.js.map +1 -0
- package/dist/screens/LogoutScreen.d.ts +15 -0
- package/dist/screens/LogoutScreen.d.ts.map +1 -0
- package/dist/screens/LogoutScreen.js +187 -0
- package/dist/screens/LogoutScreen.js.map +1 -0
- package/dist/screens/PushScreen.d.ts +12 -0
- package/dist/screens/PushScreen.d.ts.map +1 -0
- package/dist/screens/PushScreen.js +546 -0
- package/dist/screens/PushScreen.js.map +1 -0
- package/dist/screens/ValidateScreen.d.ts +12 -0
- package/dist/screens/ValidateScreen.d.ts.map +1 -0
- package/dist/screens/ValidateScreen.js +193 -0
- package/dist/screens/ValidateScreen.js.map +1 -0
- package/dist/screens/WelcomeScreen.d.ts +39 -0
- package/dist/screens/WelcomeScreen.d.ts.map +1 -0
- package/dist/screens/WelcomeScreen.js +297 -0
- package/dist/screens/WelcomeScreen.js.map +1 -0
- package/dist/screens/WhoamiScreen.d.ts +14 -0
- package/dist/screens/WhoamiScreen.d.ts.map +1 -0
- package/dist/screens/WhoamiScreen.js +180 -0
- package/dist/screens/WhoamiScreen.js.map +1 -0
- package/dist/types/index.d.ts +40 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/templates.d.ts +55 -0
- package/dist/types/templates.d.ts.map +1 -0
- package/dist/types/templates.js +6 -0
- package/dist/types/templates.js.map +1 -0
- package/dist/types/validation.d.ts +108 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/dist/types/validation.js +6 -0
- package/dist/types/validation.js.map +1 -0
- package/package.json +94 -0
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Dependency Bundler
|
|
3
|
+
* React-specific implementation for bundling dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { build } from 'vite';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
// React-specific export configurations
|
|
9
|
+
const REACT_EXPORT_CONFIG = {
|
|
10
|
+
'react': {
|
|
11
|
+
exports: ['jsx-runtime', 'jsx-dev-runtime']
|
|
12
|
+
},
|
|
13
|
+
'react-dom': {
|
|
14
|
+
exports: ['client'],
|
|
15
|
+
externals: ['react']
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
// Explicit named exports for sub-exports
|
|
19
|
+
const EXPLICIT_NAMED_EXPORTS = {
|
|
20
|
+
'react': {
|
|
21
|
+
'jsx-runtime': ['jsx', 'jsxs', 'Fragment'],
|
|
22
|
+
'jsx-dev-runtime': ['jsx', 'jsxs', 'jsxDEV', 'Fragment'],
|
|
23
|
+
// Main bundle exports
|
|
24
|
+
'': ['createElement', 'createContext', 'forwardRef', 'useCallback', 'useContext', 'useDebugValue', 'useDeferredValue', 'useEffect', 'useId', 'useImperativeHandle', 'useInsertionEffect', 'useLayoutEffect', 'useMemo', 'useOptimistic', 'useReducer', 'useRef', 'useState', 'useSyncExternalStore', 'useTransition', 'use', 'Fragment', 'Profiler', 'StrictMode', 'Suspense', 'Children', 'Component', 'PureComponent', 'createRef', 'isValidElement', 'memo', 'lazy', 'startTransition', 'unstable_Activity', 'cache', 'version']
|
|
25
|
+
},
|
|
26
|
+
'react-dom': {
|
|
27
|
+
'client': ['createRoot', 'hydrateRoot'],
|
|
28
|
+
// Main bundle exports
|
|
29
|
+
'': ['createPortal', 'flushSync', 'prefetchDNS', 'preconnect', 'preload', 'preloadModule', 'preinit', 'preinitModule', 'version']
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
class ReactBundler {
|
|
33
|
+
/**
|
|
34
|
+
* Get exports configuration for a React package
|
|
35
|
+
*/
|
|
36
|
+
getExportsConfig(packageName) {
|
|
37
|
+
return REACT_EXPORT_CONFIG[packageName];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read bundle file from multiple possible paths
|
|
41
|
+
*/
|
|
42
|
+
readBundleFile(tempDir, distFolder, fileName) {
|
|
43
|
+
const possiblePaths = [
|
|
44
|
+
path.join(tempDir, distFolder, `${fileName}.es.js`),
|
|
45
|
+
path.join(tempDir, distFolder, `${fileName}.mjs`),
|
|
46
|
+
path.join(tempDir, distFolder, `${fileName}.js`)
|
|
47
|
+
];
|
|
48
|
+
for (const bundlePath of possiblePaths) {
|
|
49
|
+
if (fs.existsSync(bundlePath)) {
|
|
50
|
+
return fs.readFileSync(bundlePath, 'utf-8');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Bundle a sub-export (e.g., react/jsx-runtime, react-dom/client)
|
|
57
|
+
*/
|
|
58
|
+
async bundleSubExport(packageName, exportName, tempDir, projectRoot, externals) {
|
|
59
|
+
const exportEntry = path.join(tempDir, `${exportName}-entry.js`);
|
|
60
|
+
const outDir = `dist-${exportName.replace(/\//g, '-')}`;
|
|
61
|
+
// Create parent directory if it doesn't exist (for nested paths like internal/disclose-version)
|
|
62
|
+
const entryDir = path.dirname(exportEntry);
|
|
63
|
+
if (!fs.existsSync(entryDir)) {
|
|
64
|
+
fs.mkdirSync(entryDir, { recursive: true });
|
|
65
|
+
}
|
|
66
|
+
// Check if we need explicit named exports
|
|
67
|
+
const explicitExports = EXPLICIT_NAMED_EXPORTS[packageName]?.[exportName];
|
|
68
|
+
let entryContent;
|
|
69
|
+
if (explicitExports && explicitExports.length > 0) {
|
|
70
|
+
const imports = explicitExports.join(', ');
|
|
71
|
+
entryContent = `import { ${imports} } from '${packageName}/${exportName}';\nexport { ${imports} };`;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
entryContent = `export * from '${packageName}/${exportName}';`;
|
|
75
|
+
}
|
|
76
|
+
fs.writeFileSync(exportEntry, entryContent);
|
|
77
|
+
try {
|
|
78
|
+
await build({
|
|
79
|
+
root: projectRoot,
|
|
80
|
+
logLevel: 'silent',
|
|
81
|
+
build: {
|
|
82
|
+
lib: {
|
|
83
|
+
entry: exportEntry,
|
|
84
|
+
formats: ['es'],
|
|
85
|
+
fileName: exportName.replace(/\//g, '-')
|
|
86
|
+
},
|
|
87
|
+
outDir: path.join(tempDir, outDir),
|
|
88
|
+
emptyOutDir: true,
|
|
89
|
+
minify: true,
|
|
90
|
+
rollupOptions: {
|
|
91
|
+
external: externals,
|
|
92
|
+
output: {
|
|
93
|
+
globals: externals.reduce((acc, ext) => ({ ...acc, [ext]: ext }), {})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
define: {
|
|
98
|
+
'process.env.NODE_ENV': '"production"'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return this.readBundleFile(tempDir, outDir, exportName.replace(/\//g, '-'));
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
console.warn(`[ReactBundler] Could not bundle ${packageName}/${exportName}: ${err}`);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Bundle a single dependency
|
|
110
|
+
*/
|
|
111
|
+
async bundleSingleDependency(packageName, version, options) {
|
|
112
|
+
const { projectRoot, outputDir } = options;
|
|
113
|
+
const tempDir = path.join(projectRoot, '.oaysus-temp', `${packageName}@${version}`);
|
|
114
|
+
const result = {
|
|
115
|
+
name: packageName,
|
|
116
|
+
version,
|
|
117
|
+
mainBundle: '',
|
|
118
|
+
additionalExports: {}
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
122
|
+
// Get React-specific config
|
|
123
|
+
const config = this.getExportsConfig(packageName);
|
|
124
|
+
const externals = config?.externals || [];
|
|
125
|
+
// Build main bundle
|
|
126
|
+
const mainEntry = path.join(tempDir, 'main-entry.js');
|
|
127
|
+
// Check if we need explicit named exports for the main bundle
|
|
128
|
+
const explicitExports = EXPLICIT_NAMED_EXPORTS[packageName]?.[''];
|
|
129
|
+
let entryContent;
|
|
130
|
+
if (explicitExports && explicitExports.length > 0) {
|
|
131
|
+
const imports = explicitExports.join(', ');
|
|
132
|
+
entryContent = `import { ${imports} } from '${packageName}';\nimport * as _pkg from '${packageName}';\nexport { ${imports} };\nexport default _pkg;`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
entryContent = `import * as _pkg from '${packageName}';\nexport * from '${packageName}';\nexport default _pkg;`;
|
|
136
|
+
}
|
|
137
|
+
fs.writeFileSync(mainEntry, entryContent);
|
|
138
|
+
await build({
|
|
139
|
+
root: projectRoot,
|
|
140
|
+
logLevel: 'silent',
|
|
141
|
+
build: {
|
|
142
|
+
lib: {
|
|
143
|
+
entry: mainEntry,
|
|
144
|
+
formats: ['es'],
|
|
145
|
+
fileName: 'index'
|
|
146
|
+
},
|
|
147
|
+
outDir: path.join(tempDir, 'dist'),
|
|
148
|
+
emptyOutDir: true,
|
|
149
|
+
minify: true,
|
|
150
|
+
rollupOptions: {
|
|
151
|
+
external: externals,
|
|
152
|
+
output: {
|
|
153
|
+
globals: externals.reduce((acc, ext) => ({ ...acc, [ext]: ext }), {})
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
define: {
|
|
158
|
+
'process.env.NODE_ENV': '"production"'
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
// Read main bundle
|
|
162
|
+
result.mainBundle = this.readBundleFile(tempDir, 'dist', 'index') || '';
|
|
163
|
+
if (!result.mainBundle) {
|
|
164
|
+
console.warn(`[ReactBundler] Could not find main bundle for ${packageName}`);
|
|
165
|
+
}
|
|
166
|
+
// Bundle additional exports
|
|
167
|
+
if (config?.exports && config.exports.length > 0) {
|
|
168
|
+
for (const exportName of config.exports) {
|
|
169
|
+
const exportBundle = await this.bundleSubExport(packageName, exportName, tempDir, projectRoot, externals);
|
|
170
|
+
if (exportBundle) {
|
|
171
|
+
result.additionalExports[exportName] = exportBundle;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// Save to output directory
|
|
176
|
+
if (outputDir) {
|
|
177
|
+
const depDir = path.join(outputDir, `${packageName}@${version}`);
|
|
178
|
+
fs.mkdirSync(depDir, { recursive: true });
|
|
179
|
+
fs.writeFileSync(path.join(depDir, 'index.js'), result.mainBundle);
|
|
180
|
+
for (const [exportName, content] of Object.entries(result.additionalExports || {})) {
|
|
181
|
+
// Use dashes in filename to match bundler output (e.g., jsx-runtime.js)
|
|
182
|
+
const fileName = exportName.replace(/\//g, '-');
|
|
183
|
+
const exportPath = path.join(depDir, `${fileName}.js`);
|
|
184
|
+
fs.writeFileSync(exportPath, content);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// Cleanup temp directory
|
|
188
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (fs.existsSync(tempDir)) {
|
|
193
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
194
|
+
}
|
|
195
|
+
console.error(`Failed to bundle ${packageName}@${version}:`, error);
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Bundle multiple dependencies for R2 upload
|
|
201
|
+
*/
|
|
202
|
+
async bundleDependencies(dependencies, options) {
|
|
203
|
+
const results = [];
|
|
204
|
+
for (const dep of dependencies) {
|
|
205
|
+
console.log(`Bundling ${dep.name}@${dep.version}...`);
|
|
206
|
+
const bundled = await this.bundleSingleDependency(dep.name, dep.version, options);
|
|
207
|
+
results.push(bundled);
|
|
208
|
+
}
|
|
209
|
+
return results;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Filter dependencies to only include runtime dependencies
|
|
213
|
+
*/
|
|
214
|
+
filterRuntimeDependencies(dependencies) {
|
|
215
|
+
const devOnlyPatterns = [
|
|
216
|
+
/^@types\//,
|
|
217
|
+
/^typescript$/,
|
|
218
|
+
/^eslint/,
|
|
219
|
+
/^prettier/,
|
|
220
|
+
/^vite$/,
|
|
221
|
+
/^vitest/,
|
|
222
|
+
/^jest/,
|
|
223
|
+
/^@testing-library/,
|
|
224
|
+
/^autoprefixer$/,
|
|
225
|
+
/^postcss$/,
|
|
226
|
+
/^tailwindcss$/,
|
|
227
|
+
/^@vitejs\//,
|
|
228
|
+
/^@sveltejs\/vite-plugin/,
|
|
229
|
+
/^svelte-check$/,
|
|
230
|
+
/^vue-tsc$/
|
|
231
|
+
];
|
|
232
|
+
return dependencies.filter(dep => {
|
|
233
|
+
return !devOnlyPatterns.some(pattern => pattern.test(dep.name));
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get the size of bundled dependencies in bytes
|
|
238
|
+
*/
|
|
239
|
+
getBundleSize(bundles) {
|
|
240
|
+
let totalSize = 0;
|
|
241
|
+
for (const bundle of bundles) {
|
|
242
|
+
totalSize += Buffer.byteLength(bundle.mainBundle, 'utf8');
|
|
243
|
+
for (const content of Object.values(bundle.additionalExports || {})) {
|
|
244
|
+
totalSize += Buffer.byteLength(content, 'utf8');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return totalSize;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Format bundle size for display
|
|
251
|
+
*/
|
|
252
|
+
formatBundleSize(bytes) {
|
|
253
|
+
if (bytes < 1024)
|
|
254
|
+
return `${bytes} B`;
|
|
255
|
+
if (bytes < 1024 * 1024)
|
|
256
|
+
return `${(bytes / 1024).toFixed(2)} KB`;
|
|
257
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Bundle framework dependencies for server-side rendering (Node.js)
|
|
261
|
+
* Creates node_modules structure that can be downloaded and used by Express
|
|
262
|
+
*/
|
|
263
|
+
async bundleServerDependencies(dependencies, options) {
|
|
264
|
+
const { projectRoot, outputDir } = options;
|
|
265
|
+
const results = [];
|
|
266
|
+
// Group react and react-dom together since they share the same version
|
|
267
|
+
const reactDep = dependencies.find(d => d.name === 'react');
|
|
268
|
+
const reactDomDep = dependencies.find(d => d.name === 'react-dom');
|
|
269
|
+
if (!reactDep) {
|
|
270
|
+
console.warn('[ReactBundler] No React dependency found for server bundling');
|
|
271
|
+
return results;
|
|
272
|
+
}
|
|
273
|
+
const version = reactDep.version;
|
|
274
|
+
const depKey = `react@${version}`;
|
|
275
|
+
const serverDepsDir = path.join(outputDir, 'server-deps', depKey, 'node_modules');
|
|
276
|
+
// Create directory structure
|
|
277
|
+
const reactDir = path.join(serverDepsDir, 'react');
|
|
278
|
+
const reactDomDir = path.join(serverDepsDir, 'react-dom');
|
|
279
|
+
fs.mkdirSync(reactDir, { recursive: true });
|
|
280
|
+
fs.mkdirSync(reactDomDir, { recursive: true });
|
|
281
|
+
const tempDir = path.join(projectRoot, '.oaysus-temp', 'server-deps');
|
|
282
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
283
|
+
let totalSize = 0;
|
|
284
|
+
try {
|
|
285
|
+
// Bundle React core for Node.js
|
|
286
|
+
// IMPORTANT: Include both named exports AND a default export
|
|
287
|
+
// because react-dom/server may import React with a default import
|
|
288
|
+
const reactEntry = path.join(tempDir, 'react-entry.js');
|
|
289
|
+
const reactExports = EXPLICIT_NAMED_EXPORTS['react'][''];
|
|
290
|
+
fs.writeFileSync(reactEntry, `import * as React from 'react';\nimport { ${reactExports.join(', ')} } from 'react';\nexport { ${reactExports.join(', ')} };\nexport default React;`);
|
|
291
|
+
await build({
|
|
292
|
+
root: projectRoot,
|
|
293
|
+
logLevel: 'silent',
|
|
294
|
+
build: {
|
|
295
|
+
lib: { entry: reactEntry, formats: ['es'], fileName: 'index' },
|
|
296
|
+
outDir: path.join(tempDir, 'react-dist'),
|
|
297
|
+
emptyOutDir: true,
|
|
298
|
+
minify: false, // Keep readable for debugging
|
|
299
|
+
target: 'node18',
|
|
300
|
+
rollupOptions: { external: [] }
|
|
301
|
+
},
|
|
302
|
+
define: { 'process.env.NODE_ENV': '"production"' }
|
|
303
|
+
});
|
|
304
|
+
// Copy to node_modules structure
|
|
305
|
+
const reactBundle = this.readBundleFile(tempDir, 'react-dist', 'index');
|
|
306
|
+
if (reactBundle) {
|
|
307
|
+
fs.writeFileSync(path.join(reactDir, 'index.js'), reactBundle);
|
|
308
|
+
totalSize += Buffer.byteLength(reactBundle, 'utf8');
|
|
309
|
+
}
|
|
310
|
+
// Bundle React JSX runtime
|
|
311
|
+
const jsxEntry = path.join(tempDir, 'jsx-entry.js');
|
|
312
|
+
const jsxExports = EXPLICIT_NAMED_EXPORTS['react']['jsx-runtime'];
|
|
313
|
+
fs.writeFileSync(jsxEntry, `import { ${jsxExports.join(', ')} } from 'react/jsx-runtime';\nexport { ${jsxExports.join(', ')} };`);
|
|
314
|
+
await build({
|
|
315
|
+
root: projectRoot,
|
|
316
|
+
logLevel: 'silent',
|
|
317
|
+
build: {
|
|
318
|
+
lib: { entry: jsxEntry, formats: ['es'], fileName: 'jsx-runtime' },
|
|
319
|
+
outDir: path.join(tempDir, 'jsx-dist'),
|
|
320
|
+
emptyOutDir: true,
|
|
321
|
+
minify: false,
|
|
322
|
+
target: 'node18',
|
|
323
|
+
rollupOptions: { external: ['react'] }
|
|
324
|
+
},
|
|
325
|
+
define: { 'process.env.NODE_ENV': '"production"' }
|
|
326
|
+
});
|
|
327
|
+
const jsxBundle = this.readBundleFile(tempDir, 'jsx-dist', 'jsx-runtime');
|
|
328
|
+
if (jsxBundle) {
|
|
329
|
+
fs.writeFileSync(path.join(reactDir, 'jsx-runtime.js'), jsxBundle);
|
|
330
|
+
totalSize += Buffer.byteLength(jsxBundle, 'utf8');
|
|
331
|
+
}
|
|
332
|
+
// Bundle React DOM server (for renderToString)
|
|
333
|
+
if (reactDomDep) {
|
|
334
|
+
const serverEntry = path.join(tempDir, 'server-entry.js');
|
|
335
|
+
fs.writeFileSync(serverEntry, `export { renderToString, renderToStaticMarkup } from 'react-dom/server';`);
|
|
336
|
+
await build({
|
|
337
|
+
root: projectRoot,
|
|
338
|
+
logLevel: 'silent',
|
|
339
|
+
build: {
|
|
340
|
+
lib: { entry: serverEntry, formats: ['es'], fileName: 'server' },
|
|
341
|
+
outDir: path.join(tempDir, 'server-dist'),
|
|
342
|
+
emptyOutDir: true,
|
|
343
|
+
minify: false,
|
|
344
|
+
target: 'node18',
|
|
345
|
+
rollupOptions: { external: ['react'] }
|
|
346
|
+
},
|
|
347
|
+
define: { 'process.env.NODE_ENV': '"production"' }
|
|
348
|
+
});
|
|
349
|
+
const serverBundle = this.readBundleFile(tempDir, 'server-dist', 'server');
|
|
350
|
+
if (serverBundle) {
|
|
351
|
+
fs.writeFileSync(path.join(reactDomDir, 'server.js'), serverBundle);
|
|
352
|
+
totalSize += Buffer.byteLength(serverBundle, 'utf8');
|
|
353
|
+
}
|
|
354
|
+
// Bundle React DOM client (for hydrateRoot - completeness)
|
|
355
|
+
const clientEntry = path.join(tempDir, 'client-entry.js');
|
|
356
|
+
fs.writeFileSync(clientEntry, `export { createRoot, hydrateRoot } from 'react-dom/client';`);
|
|
357
|
+
await build({
|
|
358
|
+
root: projectRoot,
|
|
359
|
+
logLevel: 'silent',
|
|
360
|
+
build: {
|
|
361
|
+
lib: { entry: clientEntry, formats: ['es'], fileName: 'client' },
|
|
362
|
+
outDir: path.join(tempDir, 'client-dist'),
|
|
363
|
+
emptyOutDir: true,
|
|
364
|
+
minify: false,
|
|
365
|
+
target: 'node18',
|
|
366
|
+
rollupOptions: { external: ['react'] }
|
|
367
|
+
},
|
|
368
|
+
define: { 'process.env.NODE_ENV': '"production"' }
|
|
369
|
+
});
|
|
370
|
+
const clientBundle = this.readBundleFile(tempDir, 'client-dist', 'client');
|
|
371
|
+
if (clientBundle) {
|
|
372
|
+
fs.writeFileSync(path.join(reactDomDir, 'client.js'), clientBundle);
|
|
373
|
+
totalSize += Buffer.byteLength(clientBundle, 'utf8');
|
|
374
|
+
}
|
|
375
|
+
// React DOM main index
|
|
376
|
+
const domEntry = path.join(tempDir, 'dom-entry.js');
|
|
377
|
+
fs.writeFileSync(domEntry, `export { createPortal, flushSync } from 'react-dom';`);
|
|
378
|
+
await build({
|
|
379
|
+
root: projectRoot,
|
|
380
|
+
logLevel: 'silent',
|
|
381
|
+
build: {
|
|
382
|
+
lib: { entry: domEntry, formats: ['es'], fileName: 'index' },
|
|
383
|
+
outDir: path.join(tempDir, 'dom-dist'),
|
|
384
|
+
emptyOutDir: true,
|
|
385
|
+
minify: false,
|
|
386
|
+
target: 'node18',
|
|
387
|
+
rollupOptions: { external: ['react'] }
|
|
388
|
+
},
|
|
389
|
+
define: { 'process.env.NODE_ENV': '"production"' }
|
|
390
|
+
});
|
|
391
|
+
const domBundle = this.readBundleFile(tempDir, 'dom-dist', 'index');
|
|
392
|
+
if (domBundle) {
|
|
393
|
+
fs.writeFileSync(path.join(reactDomDir, 'index.js'), domBundle);
|
|
394
|
+
totalSize += Buffer.byteLength(domBundle, 'utf8');
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
// Create package.json files for Node.js module resolution
|
|
398
|
+
const reactPkg = {
|
|
399
|
+
name: 'react',
|
|
400
|
+
version: version,
|
|
401
|
+
main: 'index.js',
|
|
402
|
+
module: 'index.js',
|
|
403
|
+
type: 'module',
|
|
404
|
+
exports: {
|
|
405
|
+
'.': './index.js',
|
|
406
|
+
'./jsx-runtime': './jsx-runtime.js',
|
|
407
|
+
'./jsx-dev-runtime': './jsx-runtime.js'
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
fs.writeFileSync(path.join(reactDir, 'package.json'), JSON.stringify(reactPkg, null, 2));
|
|
411
|
+
if (reactDomDep) {
|
|
412
|
+
const reactDomPkg = {
|
|
413
|
+
name: 'react-dom',
|
|
414
|
+
version: reactDomDep.version,
|
|
415
|
+
main: 'index.js',
|
|
416
|
+
module: 'index.js',
|
|
417
|
+
type: 'module',
|
|
418
|
+
exports: {
|
|
419
|
+
'.': './index.js',
|
|
420
|
+
'./server': './server.js',
|
|
421
|
+
'./client': './client.js'
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
fs.writeFileSync(path.join(reactDomDir, 'package.json'), JSON.stringify(reactDomPkg, null, 2));
|
|
425
|
+
}
|
|
426
|
+
results.push({
|
|
427
|
+
depKey,
|
|
428
|
+
path: serverDepsDir,
|
|
429
|
+
size: totalSize
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
finally {
|
|
433
|
+
// Cleanup temp directory
|
|
434
|
+
if (fs.existsSync(tempDir)) {
|
|
435
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return results;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Bundle detected external dependencies (non-React libraries)
|
|
442
|
+
* Creates ESM bundles for JS and CSS wrapper modules
|
|
443
|
+
*/
|
|
444
|
+
async bundleDetectedDependencies(detectedDeps, options) {
|
|
445
|
+
const results = [];
|
|
446
|
+
for (const dep of detectedDeps) {
|
|
447
|
+
console.log(`Bundling ${dep.name}@${dep.version}...`);
|
|
448
|
+
const bundled = await this.bundleExternalDependency(dep, options);
|
|
449
|
+
results.push(bundled);
|
|
450
|
+
}
|
|
451
|
+
return results;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Bundle a single external dependency with all its sub-exports and CSS
|
|
455
|
+
*/
|
|
456
|
+
async bundleExternalDependency(dep, options) {
|
|
457
|
+
const { projectRoot, outputDir } = options;
|
|
458
|
+
const tempDir = path.join(projectRoot, '.oaysus-temp', `${dep.name}@${dep.version}`);
|
|
459
|
+
const depDir = path.join(outputDir, `${dep.name}@${dep.version}`);
|
|
460
|
+
const result = {
|
|
461
|
+
name: dep.name,
|
|
462
|
+
version: dep.version,
|
|
463
|
+
mainBundle: '',
|
|
464
|
+
additionalExports: {}
|
|
465
|
+
};
|
|
466
|
+
try {
|
|
467
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
468
|
+
fs.mkdirSync(depDir, { recursive: true });
|
|
469
|
+
// Bundle main package
|
|
470
|
+
const mainBundle = await this.bundlePackageExport(dep.name, '', tempDir, projectRoot);
|
|
471
|
+
if (mainBundle) {
|
|
472
|
+
result.mainBundle = mainBundle;
|
|
473
|
+
fs.writeFileSync(path.join(depDir, 'index.js'), mainBundle);
|
|
474
|
+
}
|
|
475
|
+
// Bundle sub-exports (JS)
|
|
476
|
+
for (const subExport of dep.subExports) {
|
|
477
|
+
const subBundle = await this.bundlePackageExport(dep.name, subExport, tempDir, projectRoot);
|
|
478
|
+
if (subBundle) {
|
|
479
|
+
result.additionalExports[subExport] = subBundle;
|
|
480
|
+
// Create directory structure for nested exports
|
|
481
|
+
const exportPath = path.join(depDir, `${subExport.replace(/\//g, '-')}.js`);
|
|
482
|
+
fs.writeFileSync(exportPath, subBundle);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// Bundle CSS imports as JS modules that inject styles
|
|
486
|
+
for (const cssImport of dep.cssImports) {
|
|
487
|
+
const cssBundle = await this.bundleCSSAsModule(cssImport, tempDir, projectRoot);
|
|
488
|
+
if (cssBundle) {
|
|
489
|
+
// Get the path relative to package (e.g., "swiper/css" -> "css")
|
|
490
|
+
const relativePath = cssImport.slice(dep.name.length + 1); // Remove "swiper/"
|
|
491
|
+
const fileName = relativePath.replace(/\//g, '-').replace(/\.css$/, '') + '.js';
|
|
492
|
+
result.additionalExports[relativePath] = cssBundle;
|
|
493
|
+
fs.writeFileSync(path.join(depDir, fileName), cssBundle);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
// Cleanup temp directory
|
|
497
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
if (fs.existsSync(tempDir)) {
|
|
502
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
503
|
+
}
|
|
504
|
+
console.error(`Failed to bundle ${dep.name}@${dep.version}:`, error);
|
|
505
|
+
throw error;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Bundle a package export (main or sub-export)
|
|
510
|
+
*/
|
|
511
|
+
async bundlePackageExport(packageName, exportPath, tempDir, projectRoot) {
|
|
512
|
+
const fullImport = exportPath ? `${packageName}/${exportPath}` : packageName;
|
|
513
|
+
const entryFile = path.join(tempDir, `entry-${exportPath.replace(/\//g, '-') || 'main'}.js`);
|
|
514
|
+
const outDir = path.join(tempDir, `dist-${exportPath.replace(/\//g, '-') || 'main'}`);
|
|
515
|
+
// Create entry file - only use named exports, don't assume default export exists
|
|
516
|
+
fs.writeFileSync(entryFile, `export * from '${fullImport}';`);
|
|
517
|
+
try {
|
|
518
|
+
await build({
|
|
519
|
+
root: projectRoot,
|
|
520
|
+
logLevel: 'silent',
|
|
521
|
+
build: {
|
|
522
|
+
lib: {
|
|
523
|
+
entry: entryFile,
|
|
524
|
+
formats: ['es'],
|
|
525
|
+
fileName: 'index'
|
|
526
|
+
},
|
|
527
|
+
outDir,
|
|
528
|
+
emptyOutDir: true,
|
|
529
|
+
minify: true,
|
|
530
|
+
rollupOptions: {
|
|
531
|
+
external: (id) => {
|
|
532
|
+
// Externalize React and other framework deps
|
|
533
|
+
if (id === 'react' || id.startsWith('react/') ||
|
|
534
|
+
id === 'react-dom' || id.startsWith('react-dom/')) {
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
},
|
|
541
|
+
define: {
|
|
542
|
+
'process.env.NODE_ENV': '"production"'
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
// Read the bundle
|
|
546
|
+
const bundlePath = path.join(outDir, 'index.es.js');
|
|
547
|
+
const altPath = path.join(outDir, 'index.js');
|
|
548
|
+
const msjPath = path.join(outDir, 'index.mjs');
|
|
549
|
+
for (const p of [bundlePath, altPath, msjPath]) {
|
|
550
|
+
if (fs.existsSync(p)) {
|
|
551
|
+
return fs.readFileSync(p, 'utf-8');
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
catch (err) {
|
|
557
|
+
console.warn(`[ReactBundler] Could not bundle ${fullImport}: ${err}`);
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Bundle a CSS import as a JS module that injects styles
|
|
563
|
+
*/
|
|
564
|
+
async bundleCSSAsModule(cssImport, tempDir, projectRoot) {
|
|
565
|
+
try {
|
|
566
|
+
// Try to resolve the CSS file from node_modules
|
|
567
|
+
const nodeModulesPath = path.join(projectRoot, 'node_modules', cssImport);
|
|
568
|
+
let cssContent = '';
|
|
569
|
+
// Handle various CSS paths
|
|
570
|
+
const possiblePaths = [
|
|
571
|
+
nodeModulesPath,
|
|
572
|
+
nodeModulesPath + '.css',
|
|
573
|
+
path.join(nodeModulesPath, 'index.css'),
|
|
574
|
+
// For paths like "swiper/css" try "swiper/swiper.css"
|
|
575
|
+
path.join(projectRoot, 'node_modules', cssImport.replace(/\/css$/, '/swiper.css')),
|
|
576
|
+
// Try package.json style field
|
|
577
|
+
path.join(projectRoot, 'node_modules', cssImport.split('/')[0], 'swiper-bundle.css')
|
|
578
|
+
];
|
|
579
|
+
for (const cssPath of possiblePaths) {
|
|
580
|
+
if (fs.existsSync(cssPath) && fs.statSync(cssPath).isFile()) {
|
|
581
|
+
cssContent = fs.readFileSync(cssPath, 'utf-8');
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// If still not found, try to use Vite to build and extract CSS
|
|
586
|
+
if (!cssContent) {
|
|
587
|
+
const entryFile = path.join(tempDir, 'css-entry.js');
|
|
588
|
+
const outDir = path.join(tempDir, 'css-dist');
|
|
589
|
+
fs.writeFileSync(entryFile, `import '${cssImport}';`);
|
|
590
|
+
try {
|
|
591
|
+
await build({
|
|
592
|
+
root: projectRoot,
|
|
593
|
+
logLevel: 'silent',
|
|
594
|
+
build: {
|
|
595
|
+
lib: {
|
|
596
|
+
entry: entryFile,
|
|
597
|
+
formats: ['es'],
|
|
598
|
+
fileName: 'css'
|
|
599
|
+
},
|
|
600
|
+
outDir,
|
|
601
|
+
emptyOutDir: true,
|
|
602
|
+
cssCodeSplit: false
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
// Look for extracted CSS
|
|
606
|
+
const files = fs.readdirSync(outDir);
|
|
607
|
+
const cssFile = files.find(f => f.endsWith('.css'));
|
|
608
|
+
if (cssFile) {
|
|
609
|
+
cssContent = fs.readFileSync(path.join(outDir, cssFile), 'utf-8');
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
catch (err) {
|
|
613
|
+
console.warn(`[ReactBundler] Could not extract CSS for ${cssImport}`);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
if (!cssContent) {
|
|
617
|
+
console.warn(`[ReactBundler] No CSS content found for ${cssImport}`);
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
620
|
+
// Create a JS module that injects the CSS
|
|
621
|
+
const escapedCSS = JSON.stringify(cssContent);
|
|
622
|
+
const jsModule = `// CSS Module: ${cssImport}
|
|
623
|
+
const css = ${escapedCSS};
|
|
624
|
+
if (typeof document !== 'undefined') {
|
|
625
|
+
const id = 'oaysus-css-${cssImport.replace(/[^a-zA-Z0-9]/g, '-')}';
|
|
626
|
+
if (!document.getElementById(id)) {
|
|
627
|
+
const style = document.createElement('style');
|
|
628
|
+
style.id = id;
|
|
629
|
+
style.textContent = css;
|
|
630
|
+
document.head.appendChild(style);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
export default css;
|
|
634
|
+
`;
|
|
635
|
+
return jsModule;
|
|
636
|
+
}
|
|
637
|
+
catch (error) {
|
|
638
|
+
console.warn(`[ReactBundler] Failed to bundle CSS ${cssImport}:`, error);
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
// Export singleton instance
|
|
644
|
+
const bundler = new ReactBundler();
|
|
645
|
+
export default bundler;
|
|
646
|
+
export { bundler };
|
|
647
|
+
// Export individual functions for backward compatibility
|
|
648
|
+
export const bundleDependencies = bundler.bundleDependencies.bind(bundler);
|
|
649
|
+
export const filterRuntimeDependencies = bundler.filterRuntimeDependencies.bind(bundler);
|
|
650
|
+
export const getBundleSize = bundler.getBundleSize.bind(bundler);
|
|
651
|
+
export const formatBundleSize = bundler.formatBundleSize.bind(bundler);
|
|
652
|
+
export const bundleServerDependencies = bundler.bundleServerDependencies.bind(bundler);
|
|
653
|
+
export const bundleDetectedDependencies = bundler.bundleDetectedDependencies.bind(bundler);
|
|
654
|
+
//# sourceMappingURL=bundler.js.map
|