@omniviewdev/vite-plugin 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/LICENSE +661 -0
- package/dist/index.cjs +215 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +177 -0
- package/package.json +50 -0
- package/shims/_dnd-kit__core.mjs +45 -0
- package/shims/_dnd-kit__modifiers.mjs +21 -0
- package/shims/_dnd-kit__sortable.mjs +26 -0
- package/shims/_dnd-kit__utilities.mjs +39 -0
- package/shims/_emotion__react.mjs +27 -0
- package/shims/_emotion__styled.mjs +14 -0
- package/shims/_monaco-editor__react.mjs +18 -0
- package/shims/_mui__icons-material.mjs +10787 -0
- package/shims/_mui__material.mjs +476 -0
- package/shims/_mui__material__Box.mjs +15 -0
- package/shims/_mui__material__CircularProgress.mjs +16 -0
- package/shims/_mui__material__CssBaseline.mjs +14 -0
- package/shims/_mui__material__Divider.mjs +16 -0
- package/shims/_mui__material__GlobalStyles.mjs +14 -0
- package/shims/_mui__material__Grid.mjs +16 -0
- package/shims/_mui__material__LinearProgress.mjs +16 -0
- package/shims/_mui__material__styles.mjs +60 -0
- package/shims/_mui__material__utils.mjs +33 -0
- package/shims/_mui__x-charts.mjs +257 -0
- package/shims/_omniviewdev__runtime.mjs +82 -0
- package/shims/_omniviewdev__runtime__api.mjs +30 -0
- package/shims/_omniviewdev__runtime__models.mjs +29 -0
- package/shims/_omniviewdev__runtime__runtime.mjs +67 -0
- package/shims/_omniviewdev__ui.mjs +46 -0
- package/shims/_omniviewdev__ui__buttons.mjs +25 -0
- package/shims/_omniviewdev__ui__cells.mjs +19 -0
- package/shims/_omniviewdev__ui__charts.mjs +33 -0
- package/shims/_omniviewdev__ui__domain.mjs +25 -0
- package/shims/_omniviewdev__ui__editors.mjs +22 -0
- package/shims/_omniviewdev__ui__feedback.mjs +29 -0
- package/shims/_omniviewdev__ui__inputs.mjs +30 -0
- package/shims/_omniviewdev__ui__layout.mjs +22 -0
- package/shims/_omniviewdev__ui__menus.mjs +19 -0
- package/shims/_omniviewdev__ui__navigation.mjs +22 -0
- package/shims/_omniviewdev__ui__overlays.mjs +24 -0
- package/shims/_omniviewdev__ui__sidebars.mjs +20 -0
- package/shims/_omniviewdev__ui__table.mjs +20 -0
- package/shims/_omniviewdev__ui__theme.mjs +31 -0
- package/shims/_omniviewdev__ui__types.mjs +23 -0
- package/shims/_omniviewdev__ui__typography.mjs +19 -0
- package/shims/_tanstack__react-query.mjs +68 -0
- package/shims/_tanstack__react-table.mjs +67 -0
- package/shims/_tanstack__react-virtual.mjs +30 -0
- package/shims/date-fns.mjs +264 -0
- package/shims/monaco-editor.mjs +14 -0
- package/shims/monaco-types.mjs +14 -0
- package/shims/monaco-yaml.mjs +15 -0
- package/shims/react-dom.mjs +22 -0
- package/shims/react-icons.mjs +19 -0
- package/shims/react-icons__lu.mjs +1555 -0
- package/shims/react-icons__si.mjs +3289 -0
- package/shims/react-router-dom.mjs +70 -0
- package/shims/react.mjs +50 -0
- package/shims/react__jsx-dev-runtime.mjs +16 -0
- package/shims/react__jsx-runtime.mjs +17 -0
- package/shims/yaml.mjs +43 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
SHARED_PACKAGES: () => SHARED_PACKAGES,
|
|
34
|
+
default: () => index_default,
|
|
35
|
+
omniviewExternals: () => omniviewExternals,
|
|
36
|
+
safeFilename: () => safeFilename
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
40
|
+
var import_node_url = require("url");
|
|
41
|
+
|
|
42
|
+
// src/sharedPackages.ts
|
|
43
|
+
var SHARED_PACKAGES = [
|
|
44
|
+
// Emotion
|
|
45
|
+
"@emotion/react",
|
|
46
|
+
"@emotion/styled",
|
|
47
|
+
// MUI Material
|
|
48
|
+
"@mui/material",
|
|
49
|
+
"@mui/material/utils",
|
|
50
|
+
"@mui/material/styles",
|
|
51
|
+
"@mui/material/Box",
|
|
52
|
+
"@mui/material/Grid",
|
|
53
|
+
"@mui/material/GlobalStyles",
|
|
54
|
+
"@mui/material/CssBaseline",
|
|
55
|
+
"@mui/material/CircularProgress",
|
|
56
|
+
"@mui/material/LinearProgress",
|
|
57
|
+
"@mui/material/Divider",
|
|
58
|
+
"@mui/icons-material",
|
|
59
|
+
"@mui/x-charts",
|
|
60
|
+
// @omniviewdev/ui design system
|
|
61
|
+
"@omniviewdev/ui",
|
|
62
|
+
"@omniviewdev/ui/buttons",
|
|
63
|
+
"@omniviewdev/ui/inputs",
|
|
64
|
+
"@omniviewdev/ui/feedback",
|
|
65
|
+
"@omniviewdev/ui/typography",
|
|
66
|
+
"@omniviewdev/ui/overlays",
|
|
67
|
+
"@omniviewdev/ui/navigation",
|
|
68
|
+
"@omniviewdev/ui/table",
|
|
69
|
+
"@omniviewdev/ui/layout",
|
|
70
|
+
"@omniviewdev/ui/domain",
|
|
71
|
+
"@omniviewdev/ui/charts",
|
|
72
|
+
"@omniviewdev/ui/editors",
|
|
73
|
+
"@omniviewdev/ui/types",
|
|
74
|
+
"@omniviewdev/ui/theme",
|
|
75
|
+
"@omniviewdev/ui/menus",
|
|
76
|
+
"@omniviewdev/ui/sidebars",
|
|
77
|
+
"@omniviewdev/ui/cells",
|
|
78
|
+
// React
|
|
79
|
+
"react",
|
|
80
|
+
"react/jsx-runtime",
|
|
81
|
+
"react/jsx-dev-runtime",
|
|
82
|
+
"react-router-dom",
|
|
83
|
+
"react-dom",
|
|
84
|
+
"react-icons",
|
|
85
|
+
"react-icons/lu",
|
|
86
|
+
"react-icons/si",
|
|
87
|
+
// Monaco
|
|
88
|
+
"monaco-editor",
|
|
89
|
+
"monaco-types",
|
|
90
|
+
"monaco-yaml",
|
|
91
|
+
"@monaco-editor/react",
|
|
92
|
+
// Tanstack
|
|
93
|
+
"@tanstack/react-query",
|
|
94
|
+
"@tanstack/react-table",
|
|
95
|
+
"@tanstack/react-virtual",
|
|
96
|
+
// Omniview
|
|
97
|
+
"@omniviewdev/runtime",
|
|
98
|
+
"@omniviewdev/runtime/api",
|
|
99
|
+
"@omniviewdev/runtime/runtime",
|
|
100
|
+
"@omniviewdev/runtime/models",
|
|
101
|
+
// DND Kit
|
|
102
|
+
"@dnd-kit/core",
|
|
103
|
+
"@dnd-kit/modifiers",
|
|
104
|
+
"@dnd-kit/sortable",
|
|
105
|
+
"@dnd-kit/utilities",
|
|
106
|
+
// Utilities
|
|
107
|
+
"date-fns",
|
|
108
|
+
"yaml"
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
// src/safeFilename.ts
|
|
112
|
+
function safeFilename(packageName) {
|
|
113
|
+
let result = packageName;
|
|
114
|
+
if (result.startsWith("@")) {
|
|
115
|
+
result = "_" + result.slice(1);
|
|
116
|
+
}
|
|
117
|
+
result = result.replace(/\//g, "__");
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/index.ts
|
|
122
|
+
var import_meta = {};
|
|
123
|
+
var __dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
124
|
+
function getShimsDir() {
|
|
125
|
+
const packageRoot = import_node_path.default.resolve(__dirname, "..");
|
|
126
|
+
return import_node_path.default.join(packageRoot, "shims");
|
|
127
|
+
}
|
|
128
|
+
function buildShimMap(shimsDir) {
|
|
129
|
+
const map = /* @__PURE__ */ new Map();
|
|
130
|
+
for (const pkg of SHARED_PACKAGES) {
|
|
131
|
+
const shimFile = import_node_path.default.join(shimsDir, `${safeFilename(pkg)}.mjs`);
|
|
132
|
+
map.set(pkg, shimFile);
|
|
133
|
+
}
|
|
134
|
+
return map;
|
|
135
|
+
}
|
|
136
|
+
function omniviewExternals(options = {}) {
|
|
137
|
+
const shimsDir = options.shimsDir ?? getShimsDir();
|
|
138
|
+
const allPackages = [...SHARED_PACKAGES, ...options.additionalShared ?? []];
|
|
139
|
+
const shimMap = buildShimMap(shimsDir);
|
|
140
|
+
if (options.additionalShared) {
|
|
141
|
+
for (const pkg of options.additionalShared) {
|
|
142
|
+
const shimFile = import_node_path.default.join(shimsDir, `${safeFilename(pkg)}.mjs`);
|
|
143
|
+
shimMap.set(pkg, shimFile);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const sharedSet = new Set(allPackages);
|
|
147
|
+
return {
|
|
148
|
+
name: "omniview-externals",
|
|
149
|
+
enforce: "pre",
|
|
150
|
+
// Run before other plugins (especially @vitejs/plugin-react)
|
|
151
|
+
config(config, { command }) {
|
|
152
|
+
if (command === "serve") {
|
|
153
|
+
config.optimizeDeps = config.optimizeDeps ?? {};
|
|
154
|
+
config.optimizeDeps.esbuildOptions = config.optimizeDeps.esbuildOptions ?? {};
|
|
155
|
+
config.optimizeDeps.esbuildOptions.plugins = [
|
|
156
|
+
...config.optimizeDeps.esbuildOptions.plugins ?? [],
|
|
157
|
+
{
|
|
158
|
+
name: "omniview-redirect-shared-to-shims",
|
|
159
|
+
setup(build) {
|
|
160
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
161
|
+
if (args.kind !== "entry-point" && sharedSet.has(args.path)) {
|
|
162
|
+
const shimPath = shimMap.get(args.path);
|
|
163
|
+
if (shimPath) {
|
|
164
|
+
return { path: shimPath };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
if (command === "build") {
|
|
174
|
+
config.build = config.build ?? {};
|
|
175
|
+
config.build.rollupOptions = config.build.rollupOptions ?? {};
|
|
176
|
+
const existing = config.build.rollupOptions.external;
|
|
177
|
+
if (Array.isArray(existing)) {
|
|
178
|
+
const merged = /* @__PURE__ */ new Set([...existing, ...allPackages]);
|
|
179
|
+
config.build.rollupOptions.external = [...merged];
|
|
180
|
+
} else if (typeof existing === "function") {
|
|
181
|
+
const originalFn = existing;
|
|
182
|
+
config.build.rollupOptions.external = (source, importer, isResolved) => {
|
|
183
|
+
if (sharedSet.has(source)) return true;
|
|
184
|
+
return originalFn(source, importer, isResolved);
|
|
185
|
+
};
|
|
186
|
+
} else if (existing === void 0 || existing === null) {
|
|
187
|
+
config.build.rollupOptions.external = [...allPackages];
|
|
188
|
+
} else {
|
|
189
|
+
config.build.rollupOptions.external = (source) => {
|
|
190
|
+
if (sharedSet.has(source)) return true;
|
|
191
|
+
if (typeof existing === "string") return source === existing;
|
|
192
|
+
if (existing instanceof RegExp) return existing.test(source);
|
|
193
|
+
return false;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
resolveId(source) {
|
|
199
|
+
if (sharedSet.has(source)) {
|
|
200
|
+
const shimPath = shimMap.get(source);
|
|
201
|
+
if (shimPath) {
|
|
202
|
+
return shimPath;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
var index_default = omniviewExternals;
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
SHARED_PACKAGES,
|
|
213
|
+
omniviewExternals,
|
|
214
|
+
safeFilename
|
|
215
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The canonical list of package names shared between the Omniview host app
|
|
5
|
+
* and plugins. Every entry here corresponds to an entry in the host's
|
|
6
|
+
* shared_dependencies.ts.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: Keep this list in sync with:
|
|
9
|
+
* /ui/features/plugins/api/shared_dependencies.ts
|
|
10
|
+
*
|
|
11
|
+
* After modifying this list, run:
|
|
12
|
+
* pnpm --filter @omniviewdev/vite-plugin generate-shims
|
|
13
|
+
*/
|
|
14
|
+
declare const SHARED_PACKAGES: readonly string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Convert a package name to a filesystem-safe filename (without extension).
|
|
18
|
+
*
|
|
19
|
+
* Transformation rules:
|
|
20
|
+
* '@' at the start of a scoped package -> '_'
|
|
21
|
+
* '/' -> '__'
|
|
22
|
+
* '-' -> '-' (unchanged, already safe)
|
|
23
|
+
* '.' -> '.' (unchanged, already safe)
|
|
24
|
+
*
|
|
25
|
+
* Examples:
|
|
26
|
+
* 'react' -> 'react'
|
|
27
|
+
* 'react/jsx-runtime' -> 'react__jsx-runtime'
|
|
28
|
+
* 'react-router-dom' -> 'react-router-dom'
|
|
29
|
+
* '@mui/material' -> '_mui__material'
|
|
30
|
+
* '@mui/material/Box' -> '_mui__material__Box'
|
|
31
|
+
* '@emotion/react' -> '_emotion__react'
|
|
32
|
+
* '@tanstack/react-query' -> '_tanstack__react-query'
|
|
33
|
+
* '@omniviewdev/runtime/api' -> '_omniviewdev__runtime__api'
|
|
34
|
+
* 'date-fns' -> 'date-fns'
|
|
35
|
+
* '@monaco-editor/react' -> '_monaco-editor__react'
|
|
36
|
+
*
|
|
37
|
+
* The mapping is bijective (reversible): given the rules, no two distinct
|
|
38
|
+
* package names produce the same safe filename.
|
|
39
|
+
*/
|
|
40
|
+
declare function safeFilename(packageName: string): string;
|
|
41
|
+
|
|
42
|
+
interface OmniviewExternalsOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Additional package names to treat as shared. These are appended to the
|
|
45
|
+
* built-in SHARED_PACKAGES list. You must also ensure shim files exist for
|
|
46
|
+
* these packages (run generate-shims after adding them to sharedPackages.ts).
|
|
47
|
+
*/
|
|
48
|
+
additionalShared?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Override the path to the shims directory. Defaults to the shims/ directory
|
|
51
|
+
* inside this package.
|
|
52
|
+
*/
|
|
53
|
+
shimsDir?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Vite plugin that redirects imports of shared dependencies to shim files
|
|
57
|
+
* that re-export from window.__OMNIVIEW_SHARED__.
|
|
58
|
+
*
|
|
59
|
+
* Usage in a plugin's vite.config.ts:
|
|
60
|
+
*
|
|
61
|
+
* import { omniviewExternals } from '@omniviewdev/vite-plugin';
|
|
62
|
+
*
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* plugins: [
|
|
65
|
+
* react(),
|
|
66
|
+
* omniviewExternals(),
|
|
67
|
+
* ],
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* How it works:
|
|
71
|
+
* - In the `resolveId` hook, if the import source matches a shared package
|
|
72
|
+
* name, we return the absolute path to the corresponding shim .mjs file.
|
|
73
|
+
* - Vite then loads the shim file instead of resolving the package from
|
|
74
|
+
* node_modules.
|
|
75
|
+
* - The shim file contains: `const mod = window.__OMNIVIEW_SHARED__['<pkg>'];`
|
|
76
|
+
* and re-exports all of its named exports plus a default export.
|
|
77
|
+
* - This works in both dev mode (native ESM) and build mode (Rollup).
|
|
78
|
+
*
|
|
79
|
+
* In BUILD mode, this plugin also marks all shared packages as external in
|
|
80
|
+
* Rollup config, so the SystemJS bundle still uses external references.
|
|
81
|
+
*/
|
|
82
|
+
declare function omniviewExternals(options?: OmniviewExternalsOptions): Plugin;
|
|
83
|
+
|
|
84
|
+
export { type OmniviewExternalsOptions, SHARED_PACKAGES, omniviewExternals as default, omniviewExternals, safeFilename };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The canonical list of package names shared between the Omniview host app
|
|
5
|
+
* and plugins. Every entry here corresponds to an entry in the host's
|
|
6
|
+
* shared_dependencies.ts.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: Keep this list in sync with:
|
|
9
|
+
* /ui/features/plugins/api/shared_dependencies.ts
|
|
10
|
+
*
|
|
11
|
+
* After modifying this list, run:
|
|
12
|
+
* pnpm --filter @omniviewdev/vite-plugin generate-shims
|
|
13
|
+
*/
|
|
14
|
+
declare const SHARED_PACKAGES: readonly string[];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Convert a package name to a filesystem-safe filename (without extension).
|
|
18
|
+
*
|
|
19
|
+
* Transformation rules:
|
|
20
|
+
* '@' at the start of a scoped package -> '_'
|
|
21
|
+
* '/' -> '__'
|
|
22
|
+
* '-' -> '-' (unchanged, already safe)
|
|
23
|
+
* '.' -> '.' (unchanged, already safe)
|
|
24
|
+
*
|
|
25
|
+
* Examples:
|
|
26
|
+
* 'react' -> 'react'
|
|
27
|
+
* 'react/jsx-runtime' -> 'react__jsx-runtime'
|
|
28
|
+
* 'react-router-dom' -> 'react-router-dom'
|
|
29
|
+
* '@mui/material' -> '_mui__material'
|
|
30
|
+
* '@mui/material/Box' -> '_mui__material__Box'
|
|
31
|
+
* '@emotion/react' -> '_emotion__react'
|
|
32
|
+
* '@tanstack/react-query' -> '_tanstack__react-query'
|
|
33
|
+
* '@omniviewdev/runtime/api' -> '_omniviewdev__runtime__api'
|
|
34
|
+
* 'date-fns' -> 'date-fns'
|
|
35
|
+
* '@monaco-editor/react' -> '_monaco-editor__react'
|
|
36
|
+
*
|
|
37
|
+
* The mapping is bijective (reversible): given the rules, no two distinct
|
|
38
|
+
* package names produce the same safe filename.
|
|
39
|
+
*/
|
|
40
|
+
declare function safeFilename(packageName: string): string;
|
|
41
|
+
|
|
42
|
+
interface OmniviewExternalsOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Additional package names to treat as shared. These are appended to the
|
|
45
|
+
* built-in SHARED_PACKAGES list. You must also ensure shim files exist for
|
|
46
|
+
* these packages (run generate-shims after adding them to sharedPackages.ts).
|
|
47
|
+
*/
|
|
48
|
+
additionalShared?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Override the path to the shims directory. Defaults to the shims/ directory
|
|
51
|
+
* inside this package.
|
|
52
|
+
*/
|
|
53
|
+
shimsDir?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Vite plugin that redirects imports of shared dependencies to shim files
|
|
57
|
+
* that re-export from window.__OMNIVIEW_SHARED__.
|
|
58
|
+
*
|
|
59
|
+
* Usage in a plugin's vite.config.ts:
|
|
60
|
+
*
|
|
61
|
+
* import { omniviewExternals } from '@omniviewdev/vite-plugin';
|
|
62
|
+
*
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* plugins: [
|
|
65
|
+
* react(),
|
|
66
|
+
* omniviewExternals(),
|
|
67
|
+
* ],
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* How it works:
|
|
71
|
+
* - In the `resolveId` hook, if the import source matches a shared package
|
|
72
|
+
* name, we return the absolute path to the corresponding shim .mjs file.
|
|
73
|
+
* - Vite then loads the shim file instead of resolving the package from
|
|
74
|
+
* node_modules.
|
|
75
|
+
* - The shim file contains: `const mod = window.__OMNIVIEW_SHARED__['<pkg>'];`
|
|
76
|
+
* and re-exports all of its named exports plus a default export.
|
|
77
|
+
* - This works in both dev mode (native ESM) and build mode (Rollup).
|
|
78
|
+
*
|
|
79
|
+
* In BUILD mode, this plugin also marks all shared packages as external in
|
|
80
|
+
* Rollup config, so the SystemJS bundle still uses external references.
|
|
81
|
+
*/
|
|
82
|
+
declare function omniviewExternals(options?: OmniviewExternalsOptions): Plugin;
|
|
83
|
+
|
|
84
|
+
export { type OmniviewExternalsOptions, SHARED_PACKAGES, omniviewExternals as default, omniviewExternals, safeFilename };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
// src/sharedPackages.ts
|
|
6
|
+
var SHARED_PACKAGES = [
|
|
7
|
+
// Emotion
|
|
8
|
+
"@emotion/react",
|
|
9
|
+
"@emotion/styled",
|
|
10
|
+
// MUI Material
|
|
11
|
+
"@mui/material",
|
|
12
|
+
"@mui/material/utils",
|
|
13
|
+
"@mui/material/styles",
|
|
14
|
+
"@mui/material/Box",
|
|
15
|
+
"@mui/material/Grid",
|
|
16
|
+
"@mui/material/GlobalStyles",
|
|
17
|
+
"@mui/material/CssBaseline",
|
|
18
|
+
"@mui/material/CircularProgress",
|
|
19
|
+
"@mui/material/LinearProgress",
|
|
20
|
+
"@mui/material/Divider",
|
|
21
|
+
"@mui/icons-material",
|
|
22
|
+
"@mui/x-charts",
|
|
23
|
+
// @omniviewdev/ui design system
|
|
24
|
+
"@omniviewdev/ui",
|
|
25
|
+
"@omniviewdev/ui/buttons",
|
|
26
|
+
"@omniviewdev/ui/inputs",
|
|
27
|
+
"@omniviewdev/ui/feedback",
|
|
28
|
+
"@omniviewdev/ui/typography",
|
|
29
|
+
"@omniviewdev/ui/overlays",
|
|
30
|
+
"@omniviewdev/ui/navigation",
|
|
31
|
+
"@omniviewdev/ui/table",
|
|
32
|
+
"@omniviewdev/ui/layout",
|
|
33
|
+
"@omniviewdev/ui/domain",
|
|
34
|
+
"@omniviewdev/ui/charts",
|
|
35
|
+
"@omniviewdev/ui/editors",
|
|
36
|
+
"@omniviewdev/ui/types",
|
|
37
|
+
"@omniviewdev/ui/theme",
|
|
38
|
+
"@omniviewdev/ui/menus",
|
|
39
|
+
"@omniviewdev/ui/sidebars",
|
|
40
|
+
"@omniviewdev/ui/cells",
|
|
41
|
+
// React
|
|
42
|
+
"react",
|
|
43
|
+
"react/jsx-runtime",
|
|
44
|
+
"react/jsx-dev-runtime",
|
|
45
|
+
"react-router-dom",
|
|
46
|
+
"react-dom",
|
|
47
|
+
"react-icons",
|
|
48
|
+
"react-icons/lu",
|
|
49
|
+
"react-icons/si",
|
|
50
|
+
// Monaco
|
|
51
|
+
"monaco-editor",
|
|
52
|
+
"monaco-types",
|
|
53
|
+
"monaco-yaml",
|
|
54
|
+
"@monaco-editor/react",
|
|
55
|
+
// Tanstack
|
|
56
|
+
"@tanstack/react-query",
|
|
57
|
+
"@tanstack/react-table",
|
|
58
|
+
"@tanstack/react-virtual",
|
|
59
|
+
// Omniview
|
|
60
|
+
"@omniviewdev/runtime",
|
|
61
|
+
"@omniviewdev/runtime/api",
|
|
62
|
+
"@omniviewdev/runtime/runtime",
|
|
63
|
+
"@omniviewdev/runtime/models",
|
|
64
|
+
// DND Kit
|
|
65
|
+
"@dnd-kit/core",
|
|
66
|
+
"@dnd-kit/modifiers",
|
|
67
|
+
"@dnd-kit/sortable",
|
|
68
|
+
"@dnd-kit/utilities",
|
|
69
|
+
// Utilities
|
|
70
|
+
"date-fns",
|
|
71
|
+
"yaml"
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
// src/safeFilename.ts
|
|
75
|
+
function safeFilename(packageName) {
|
|
76
|
+
let result = packageName;
|
|
77
|
+
if (result.startsWith("@")) {
|
|
78
|
+
result = "_" + result.slice(1);
|
|
79
|
+
}
|
|
80
|
+
result = result.replace(/\//g, "__");
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/index.ts
|
|
85
|
+
var __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
86
|
+
function getShimsDir() {
|
|
87
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
88
|
+
return path.join(packageRoot, "shims");
|
|
89
|
+
}
|
|
90
|
+
function buildShimMap(shimsDir) {
|
|
91
|
+
const map = /* @__PURE__ */ new Map();
|
|
92
|
+
for (const pkg of SHARED_PACKAGES) {
|
|
93
|
+
const shimFile = path.join(shimsDir, `${safeFilename(pkg)}.mjs`);
|
|
94
|
+
map.set(pkg, shimFile);
|
|
95
|
+
}
|
|
96
|
+
return map;
|
|
97
|
+
}
|
|
98
|
+
function omniviewExternals(options = {}) {
|
|
99
|
+
const shimsDir = options.shimsDir ?? getShimsDir();
|
|
100
|
+
const allPackages = [...SHARED_PACKAGES, ...options.additionalShared ?? []];
|
|
101
|
+
const shimMap = buildShimMap(shimsDir);
|
|
102
|
+
if (options.additionalShared) {
|
|
103
|
+
for (const pkg of options.additionalShared) {
|
|
104
|
+
const shimFile = path.join(shimsDir, `${safeFilename(pkg)}.mjs`);
|
|
105
|
+
shimMap.set(pkg, shimFile);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const sharedSet = new Set(allPackages);
|
|
109
|
+
return {
|
|
110
|
+
name: "omniview-externals",
|
|
111
|
+
enforce: "pre",
|
|
112
|
+
// Run before other plugins (especially @vitejs/plugin-react)
|
|
113
|
+
config(config, { command }) {
|
|
114
|
+
if (command === "serve") {
|
|
115
|
+
config.optimizeDeps = config.optimizeDeps ?? {};
|
|
116
|
+
config.optimizeDeps.esbuildOptions = config.optimizeDeps.esbuildOptions ?? {};
|
|
117
|
+
config.optimizeDeps.esbuildOptions.plugins = [
|
|
118
|
+
...config.optimizeDeps.esbuildOptions.plugins ?? [],
|
|
119
|
+
{
|
|
120
|
+
name: "omniview-redirect-shared-to-shims",
|
|
121
|
+
setup(build) {
|
|
122
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
123
|
+
if (args.kind !== "entry-point" && sharedSet.has(args.path)) {
|
|
124
|
+
const shimPath = shimMap.get(args.path);
|
|
125
|
+
if (shimPath) {
|
|
126
|
+
return { path: shimPath };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return null;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
if (command === "build") {
|
|
136
|
+
config.build = config.build ?? {};
|
|
137
|
+
config.build.rollupOptions = config.build.rollupOptions ?? {};
|
|
138
|
+
const existing = config.build.rollupOptions.external;
|
|
139
|
+
if (Array.isArray(existing)) {
|
|
140
|
+
const merged = /* @__PURE__ */ new Set([...existing, ...allPackages]);
|
|
141
|
+
config.build.rollupOptions.external = [...merged];
|
|
142
|
+
} else if (typeof existing === "function") {
|
|
143
|
+
const originalFn = existing;
|
|
144
|
+
config.build.rollupOptions.external = (source, importer, isResolved) => {
|
|
145
|
+
if (sharedSet.has(source)) return true;
|
|
146
|
+
return originalFn(source, importer, isResolved);
|
|
147
|
+
};
|
|
148
|
+
} else if (existing === void 0 || existing === null) {
|
|
149
|
+
config.build.rollupOptions.external = [...allPackages];
|
|
150
|
+
} else {
|
|
151
|
+
config.build.rollupOptions.external = (source) => {
|
|
152
|
+
if (sharedSet.has(source)) return true;
|
|
153
|
+
if (typeof existing === "string") return source === existing;
|
|
154
|
+
if (existing instanceof RegExp) return existing.test(source);
|
|
155
|
+
return false;
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
resolveId(source) {
|
|
161
|
+
if (sharedSet.has(source)) {
|
|
162
|
+
const shimPath = shimMap.get(source);
|
|
163
|
+
if (shimPath) {
|
|
164
|
+
return shimPath;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
var index_default = omniviewExternals;
|
|
172
|
+
export {
|
|
173
|
+
SHARED_PACKAGES,
|
|
174
|
+
index_default as default,
|
|
175
|
+
omniviewExternals,
|
|
176
|
+
safeFilename
|
|
177
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omniviewdev/vite-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin for Omniview plugin development. Redirects shared dependency imports to the host app's singleton instances via window.__OMNIVIEW_SHARED__.",
|
|
5
|
+
"license": "AGPL-3.0-only",
|
|
6
|
+
"author": "Omniview",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.cjs",
|
|
9
|
+
"module": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"shims"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"directory": "packages/omniviewdev-vite-plugin",
|
|
24
|
+
"url": "https://github.com/omniviewdev/omniview.git"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org/",
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"omniview",
|
|
32
|
+
"vite",
|
|
33
|
+
"plugin",
|
|
34
|
+
"shared-dependencies"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsup": "^8.0.2",
|
|
39
|
+
"tsx": "^4.7.0",
|
|
40
|
+
"typescript": "^5.8.3",
|
|
41
|
+
"vite": "^5.2.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"vite": ">=5.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
48
|
+
"generate-shims": "tsx scripts/generate-shims.ts"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Auto-generated shim for '@dnd-kit/core'
|
|
2
|
+
// DO NOT EDIT -- regenerate with: pnpm --filter @omniviewdev/vite-plugin generate-shims
|
|
3
|
+
|
|
4
|
+
const mod = window.__OMNIVIEW_SHARED__['@dnd-kit/core'];
|
|
5
|
+
|
|
6
|
+
if (!mod) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
'[omniview] Shared dependency "@dnd-kit/core" is not available on window.__OMNIVIEW_SHARED__. ' +
|
|
9
|
+
'Ensure the Omniview host app is running and shared deps are exported before loading this plugin.'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const KeyboardCode = mod.KeyboardCode;
|
|
14
|
+
export const AutoScrollActivator = mod.AutoScrollActivator;
|
|
15
|
+
export const TraversalOrder = mod.TraversalOrder;
|
|
16
|
+
export const MeasuringStrategy = mod.MeasuringStrategy;
|
|
17
|
+
export const MeasuringFrequency = mod.MeasuringFrequency;
|
|
18
|
+
export const DndContext = mod.DndContext;
|
|
19
|
+
export const DragOverlay = mod.DragOverlay;
|
|
20
|
+
export const KeyboardSensor = mod.KeyboardSensor;
|
|
21
|
+
export const MouseSensor = mod.MouseSensor;
|
|
22
|
+
export const PointerSensor = mod.PointerSensor;
|
|
23
|
+
export const TouchSensor = mod.TouchSensor;
|
|
24
|
+
export const applyModifiers = mod.applyModifiers;
|
|
25
|
+
export const closestCenter = mod.closestCenter;
|
|
26
|
+
export const closestCorners = mod.closestCorners;
|
|
27
|
+
export const defaultAnnouncements = mod.defaultAnnouncements;
|
|
28
|
+
export const defaultCoordinates = mod.defaultCoordinates;
|
|
29
|
+
export const defaultDropAnimation = mod.defaultDropAnimation;
|
|
30
|
+
export const defaultDropAnimationSideEffects = mod.defaultDropAnimationSideEffects;
|
|
31
|
+
export const defaultKeyboardCoordinateGetter = mod.defaultKeyboardCoordinateGetter;
|
|
32
|
+
export const defaultScreenReaderInstructions = mod.defaultScreenReaderInstructions;
|
|
33
|
+
export const getClientRect = mod.getClientRect;
|
|
34
|
+
export const getFirstCollision = mod.getFirstCollision;
|
|
35
|
+
export const getScrollableAncestors = mod.getScrollableAncestors;
|
|
36
|
+
export const pointerWithin = mod.pointerWithin;
|
|
37
|
+
export const rectIntersection = mod.rectIntersection;
|
|
38
|
+
export const useDndContext = mod.useDndContext;
|
|
39
|
+
export const useDndMonitor = mod.useDndMonitor;
|
|
40
|
+
export const useDraggable = mod.useDraggable;
|
|
41
|
+
export const useDroppable = mod.useDroppable;
|
|
42
|
+
export const useSensor = mod.useSensor;
|
|
43
|
+
export const useSensors = mod.useSensors;
|
|
44
|
+
|
|
45
|
+
export default mod.default !== undefined ? mod.default : mod;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Auto-generated shim for '@dnd-kit/modifiers'
|
|
2
|
+
// DO NOT EDIT -- regenerate with: pnpm --filter @omniviewdev/vite-plugin generate-shims
|
|
3
|
+
|
|
4
|
+
const mod = window.__OMNIVIEW_SHARED__['@dnd-kit/modifiers'];
|
|
5
|
+
|
|
6
|
+
if (!mod) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
'[omniview] Shared dependency "@dnd-kit/modifiers" is not available on window.__OMNIVIEW_SHARED__. ' +
|
|
9
|
+
'Ensure the Omniview host app is running and shared deps are exported before loading this plugin.'
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const createSnapModifier = mod.createSnapModifier;
|
|
14
|
+
export const restrictToFirstScrollableAncestor = mod.restrictToFirstScrollableAncestor;
|
|
15
|
+
export const restrictToHorizontalAxis = mod.restrictToHorizontalAxis;
|
|
16
|
+
export const restrictToParentElement = mod.restrictToParentElement;
|
|
17
|
+
export const restrictToVerticalAxis = mod.restrictToVerticalAxis;
|
|
18
|
+
export const restrictToWindowEdges = mod.restrictToWindowEdges;
|
|
19
|
+
export const snapCenterToCursor = mod.snapCenterToCursor;
|
|
20
|
+
|
|
21
|
+
export default mod.default !== undefined ? mod.default : mod;
|