@bagelink/workspace 1.11.0 → 1.11.3
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 +214 -9
- package/bin/bgl.ts +88 -2
- package/dist/bin/bgl.cjs +854 -14
- package/dist/bin/bgl.mjs +845 -6
- package/dist/composable.cjs +22 -0
- package/dist/composable.d.cts +52 -0
- package/dist/composable.d.mts +52 -0
- package/dist/composable.d.ts +52 -0
- package/dist/composable.mjs +19 -0
- package/dist/index.cjs +3 -160
- package/dist/index.d.cts +4 -160
- package/dist/index.d.mts +4 -160
- package/dist/index.d.ts +4 -160
- package/dist/index.mjs +2 -139
- package/dist/shared/workspace.Bhp9XbPk.mjs +581 -0
- package/dist/shared/workspace.BshPcRI_.cjs +593 -0
- package/dist/shared/workspace.BzlV5kcN.d.cts +50 -0
- package/dist/shared/workspace.BzlV5kcN.d.mts +50 -0
- package/dist/shared/workspace.BzlV5kcN.d.ts +50 -0
- package/dist/vite.cjs +135 -0
- package/dist/vite.d.cts +98 -0
- package/dist/vite.d.mts +98 -0
- package/dist/vite.d.ts +98 -0
- package/dist/vite.mjs +125 -0
- package/env.d.ts +30 -0
- package/package.json +24 -3
- package/src/build.ts +45 -0
- package/src/composable.ts +70 -0
- package/src/dev.ts +171 -0
- package/src/index.ts +4 -78
- package/src/init.ts +72 -14
- package/src/lint.ts +90 -2
- package/src/netlify.ts +54 -3
- package/src/proxy.ts +23 -3
- package/src/sdk.ts +80 -44
- package/src/types.ts +10 -4
- package/src/vite.ts +166 -0
- package/src/workspace.ts +158 -33
- package/templates/tsconfig.app.json +23 -0
- package/dist/shared/workspace.BMTTo3s8.cjs +0 -993
- package/dist/shared/workspace.COhZ__uF.mjs +0 -973
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
type WorkspaceEnvironment = string;
|
|
2
|
+
interface WorkspaceConfig {
|
|
3
|
+
/**
|
|
4
|
+
* The host URL of the backend API server
|
|
5
|
+
* @example 'http://localhost:8000' | 'https://project.bagel.to'
|
|
6
|
+
*/
|
|
7
|
+
host: string;
|
|
8
|
+
/**
|
|
9
|
+
* Optional proxy path to use for API requests
|
|
10
|
+
* If not set, no proxy will be configured for this environment
|
|
11
|
+
* @example '/api'
|
|
12
|
+
*/
|
|
13
|
+
proxy?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optional OpenAPI specification URL for SDK generation
|
|
16
|
+
*/
|
|
17
|
+
openapi_url?: string;
|
|
18
|
+
}
|
|
19
|
+
interface WorkspaceOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Root directory of the workspace
|
|
22
|
+
* @default process.cwd()
|
|
23
|
+
*/
|
|
24
|
+
root?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Path to the config file relative to root
|
|
27
|
+
* @default 'bgl.config.ts'
|
|
28
|
+
*/
|
|
29
|
+
configFile?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Enable interactive config generation if no config is found
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
interactive?: boolean;
|
|
35
|
+
}
|
|
36
|
+
interface ProxyConfig {
|
|
37
|
+
[path: string]: {
|
|
38
|
+
target: string;
|
|
39
|
+
changeOrigin: boolean;
|
|
40
|
+
rewrite?: (path: string) => string;
|
|
41
|
+
secure: boolean;
|
|
42
|
+
ws?: boolean;
|
|
43
|
+
followRedirects?: boolean;
|
|
44
|
+
autoRewrite?: boolean;
|
|
45
|
+
protocolRewrite?: string;
|
|
46
|
+
configure?: (proxy: any, options: any) => void;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_path = require('node:path');
|
|
4
|
+
const process = require('node:process');
|
|
5
|
+
const node_url = require('node:url');
|
|
6
|
+
const netlify = require('./shared/workspace.BshPcRI_.cjs');
|
|
7
|
+
require('node:fs');
|
|
8
|
+
require('prompts');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
|
+
|
|
12
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
13
|
+
|
|
14
|
+
function createViteProxy(config) {
|
|
15
|
+
const proxy = {};
|
|
16
|
+
if (config.proxy && config.host) {
|
|
17
|
+
proxy[config.proxy] = {
|
|
18
|
+
target: config.host,
|
|
19
|
+
changeOrigin: true,
|
|
20
|
+
rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
|
|
21
|
+
secure: false,
|
|
22
|
+
ws: true,
|
|
23
|
+
followRedirects: true,
|
|
24
|
+
autoRewrite: true,
|
|
25
|
+
protocolRewrite: "http",
|
|
26
|
+
configure: (proxy2, _options) => {
|
|
27
|
+
proxy2.on("proxyReq", (proxyReq, req, _res) => {
|
|
28
|
+
if (req.headers.origin) {
|
|
29
|
+
proxyReq.setHeader("origin", config.host);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
proxy2.on("error", (err, _req, _res) => {
|
|
33
|
+
console.log("proxy error", err);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (config.host) {
|
|
39
|
+
proxy["/files"] = {
|
|
40
|
+
target: config.host,
|
|
41
|
+
changeOrigin: true,
|
|
42
|
+
secure: false,
|
|
43
|
+
ws: true,
|
|
44
|
+
followRedirects: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return proxy;
|
|
48
|
+
}
|
|
49
|
+
function createCustomProxy(paths, target, options = {}) {
|
|
50
|
+
const proxy = {};
|
|
51
|
+
for (const path of paths) {
|
|
52
|
+
proxy[path] = {
|
|
53
|
+
target,
|
|
54
|
+
changeOrigin: options.changeOrigin ?? true,
|
|
55
|
+
secure: options.secure ?? false,
|
|
56
|
+
ws: options.ws ?? true,
|
|
57
|
+
...options.rewrite === true && {
|
|
58
|
+
rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return proxy;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function bagelink(options) {
|
|
66
|
+
const { workspace, config = {} } = options;
|
|
67
|
+
let workspaceConfig;
|
|
68
|
+
return {
|
|
69
|
+
name: "vite-plugin-bagelink",
|
|
70
|
+
enforce: "pre",
|
|
71
|
+
configResolved(resolved) {
|
|
72
|
+
workspaceConfig = workspace(resolved.mode);
|
|
73
|
+
},
|
|
74
|
+
config(userConfig, { mode }) {
|
|
75
|
+
workspaceConfig = workspace(mode);
|
|
76
|
+
const alias = {};
|
|
77
|
+
if (config.includeSharedAlias !== false) {
|
|
78
|
+
const sharedPath = config.sharedPath ?? "../shared";
|
|
79
|
+
alias["@shared"] = node_url.fileURLToPath(new URL(sharedPath, `file://${process__default.cwd()}/`));
|
|
80
|
+
}
|
|
81
|
+
alias["@"] = node_url.fileURLToPath(new URL("./src", `file://${process__default.cwd()}/`));
|
|
82
|
+
if (config.additionalAliases) {
|
|
83
|
+
Object.assign(alias, config.additionalAliases);
|
|
84
|
+
}
|
|
85
|
+
let port;
|
|
86
|
+
try {
|
|
87
|
+
const currentDir = process__default.cwd();
|
|
88
|
+
const projectName = node_path.basename(currentDir);
|
|
89
|
+
const parentDir = node_url.fileURLToPath(new URL("..", `file://${currentDir}/`));
|
|
90
|
+
const allProjects = netlify.listProjects(parentDir);
|
|
91
|
+
const projectIndex = allProjects.indexOf(projectName);
|
|
92
|
+
if (projectIndex !== -1) {
|
|
93
|
+
port = 5173 + projectIndex;
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
}
|
|
97
|
+
const server = {
|
|
98
|
+
...config.configureProxy !== false && {
|
|
99
|
+
proxy: createViteProxy(workspaceConfig)
|
|
100
|
+
},
|
|
101
|
+
...port !== void 0 && {
|
|
102
|
+
port,
|
|
103
|
+
strictPort: false
|
|
104
|
+
// use next available port if preferred is taken
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const define = {
|
|
108
|
+
...workspaceConfig.proxy && {
|
|
109
|
+
"import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy)
|
|
110
|
+
},
|
|
111
|
+
"import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
|
|
112
|
+
...workspaceConfig.openapi_url && {
|
|
113
|
+
"import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
resolve: {
|
|
118
|
+
alias
|
|
119
|
+
},
|
|
120
|
+
define,
|
|
121
|
+
server,
|
|
122
|
+
optimizeDeps: {
|
|
123
|
+
exclude: ["@bagelink/workspace"]
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
exports.generateNetlifyConfig = netlify.generateNetlifyConfig;
|
|
131
|
+
exports.setBuildEnvVars = netlify.setBuildEnvVars;
|
|
132
|
+
exports.writeNetlifyConfig = netlify.writeNetlifyConfig;
|
|
133
|
+
exports.bagelink = bagelink;
|
|
134
|
+
exports.createCustomProxy = createCustomProxy;
|
|
135
|
+
exports.createViteProxy = createViteProxy;
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { a as WorkspaceConfig, P as ProxyConfig, W as WorkspaceEnvironment } from './shared/workspace.BzlV5kcN.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate complete netlify.toml file
|
|
6
|
+
*/
|
|
7
|
+
declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
|
|
8
|
+
/**
|
|
9
|
+
* Write netlify.toml file to disk
|
|
10
|
+
*/
|
|
11
|
+
declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* Set environment variables for build process
|
|
14
|
+
*/
|
|
15
|
+
declare function setBuildEnvVars(config: WorkspaceConfig): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create Vite proxy configuration from WorkspaceConfig
|
|
19
|
+
*/
|
|
20
|
+
declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Create custom proxy configuration
|
|
23
|
+
*/
|
|
24
|
+
declare function createCustomProxy(paths: string[], target: string, options?: {
|
|
25
|
+
changeOrigin?: boolean;
|
|
26
|
+
rewrite?: boolean;
|
|
27
|
+
secure?: boolean;
|
|
28
|
+
ws?: boolean;
|
|
29
|
+
}): ProxyConfig;
|
|
30
|
+
|
|
31
|
+
interface BagelinkPluginOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Path to shared package relative to project
|
|
34
|
+
* @default '../shared'
|
|
35
|
+
*/
|
|
36
|
+
sharedPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to include @shared alias
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
includeSharedAlias?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Additional path aliases beyond @ and @shared
|
|
44
|
+
*/
|
|
45
|
+
additionalAliases?: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to auto-configure proxy
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
configureProxy?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Vite plugin for Bagelink workspace integration
|
|
54
|
+
* Automatically configures proxy and path aliases based on bgl.config.ts
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { defineConfig } from 'vite'
|
|
59
|
+
* import vue from '@vitejs/plugin-vue'
|
|
60
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
61
|
+
* import workspace from './bgl.config'
|
|
62
|
+
*
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* plugins: [
|
|
65
|
+
* vue(),
|
|
66
|
+
* bagelink({ workspace })
|
|
67
|
+
* ]
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example With custom options
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { defineConfig } from 'vite'
|
|
74
|
+
* import vue from '@vitejs/plugin-vue'
|
|
75
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
76
|
+
* import workspace from './bgl.config'
|
|
77
|
+
*
|
|
78
|
+
* export default defineConfig({
|
|
79
|
+
* plugins: [
|
|
80
|
+
* vue(),
|
|
81
|
+
* bagelink({
|
|
82
|
+
* workspace,
|
|
83
|
+
* sharedPath: '../packages/shared',
|
|
84
|
+
* additionalAliases: {
|
|
85
|
+
* '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
* ]
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function bagelink(options: {
|
|
93
|
+
workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
|
|
94
|
+
config?: BagelinkPluginOptions;
|
|
95
|
+
}): Plugin;
|
|
96
|
+
|
|
97
|
+
export { bagelink, createCustomProxy, createViteProxy, generateNetlifyConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
98
|
+
export type { BagelinkPluginOptions };
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { a as WorkspaceConfig, P as ProxyConfig, W as WorkspaceEnvironment } from './shared/workspace.BzlV5kcN.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate complete netlify.toml file
|
|
6
|
+
*/
|
|
7
|
+
declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
|
|
8
|
+
/**
|
|
9
|
+
* Write netlify.toml file to disk
|
|
10
|
+
*/
|
|
11
|
+
declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* Set environment variables for build process
|
|
14
|
+
*/
|
|
15
|
+
declare function setBuildEnvVars(config: WorkspaceConfig): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create Vite proxy configuration from WorkspaceConfig
|
|
19
|
+
*/
|
|
20
|
+
declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Create custom proxy configuration
|
|
23
|
+
*/
|
|
24
|
+
declare function createCustomProxy(paths: string[], target: string, options?: {
|
|
25
|
+
changeOrigin?: boolean;
|
|
26
|
+
rewrite?: boolean;
|
|
27
|
+
secure?: boolean;
|
|
28
|
+
ws?: boolean;
|
|
29
|
+
}): ProxyConfig;
|
|
30
|
+
|
|
31
|
+
interface BagelinkPluginOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Path to shared package relative to project
|
|
34
|
+
* @default '../shared'
|
|
35
|
+
*/
|
|
36
|
+
sharedPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to include @shared alias
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
includeSharedAlias?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Additional path aliases beyond @ and @shared
|
|
44
|
+
*/
|
|
45
|
+
additionalAliases?: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to auto-configure proxy
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
configureProxy?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Vite plugin for Bagelink workspace integration
|
|
54
|
+
* Automatically configures proxy and path aliases based on bgl.config.ts
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { defineConfig } from 'vite'
|
|
59
|
+
* import vue from '@vitejs/plugin-vue'
|
|
60
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
61
|
+
* import workspace from './bgl.config'
|
|
62
|
+
*
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* plugins: [
|
|
65
|
+
* vue(),
|
|
66
|
+
* bagelink({ workspace })
|
|
67
|
+
* ]
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example With custom options
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { defineConfig } from 'vite'
|
|
74
|
+
* import vue from '@vitejs/plugin-vue'
|
|
75
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
76
|
+
* import workspace from './bgl.config'
|
|
77
|
+
*
|
|
78
|
+
* export default defineConfig({
|
|
79
|
+
* plugins: [
|
|
80
|
+
* vue(),
|
|
81
|
+
* bagelink({
|
|
82
|
+
* workspace,
|
|
83
|
+
* sharedPath: '../packages/shared',
|
|
84
|
+
* additionalAliases: {
|
|
85
|
+
* '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
* ]
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function bagelink(options: {
|
|
93
|
+
workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
|
|
94
|
+
config?: BagelinkPluginOptions;
|
|
95
|
+
}): Plugin;
|
|
96
|
+
|
|
97
|
+
export { bagelink, createCustomProxy, createViteProxy, generateNetlifyConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
98
|
+
export type { BagelinkPluginOptions };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { a as WorkspaceConfig, P as ProxyConfig, W as WorkspaceEnvironment } from './shared/workspace.BzlV5kcN.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate complete netlify.toml file
|
|
6
|
+
*/
|
|
7
|
+
declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
|
|
8
|
+
/**
|
|
9
|
+
* Write netlify.toml file to disk
|
|
10
|
+
*/
|
|
11
|
+
declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
|
|
12
|
+
/**
|
|
13
|
+
* Set environment variables for build process
|
|
14
|
+
*/
|
|
15
|
+
declare function setBuildEnvVars(config: WorkspaceConfig): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Create Vite proxy configuration from WorkspaceConfig
|
|
19
|
+
*/
|
|
20
|
+
declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Create custom proxy configuration
|
|
23
|
+
*/
|
|
24
|
+
declare function createCustomProxy(paths: string[], target: string, options?: {
|
|
25
|
+
changeOrigin?: boolean;
|
|
26
|
+
rewrite?: boolean;
|
|
27
|
+
secure?: boolean;
|
|
28
|
+
ws?: boolean;
|
|
29
|
+
}): ProxyConfig;
|
|
30
|
+
|
|
31
|
+
interface BagelinkPluginOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Path to shared package relative to project
|
|
34
|
+
* @default '../shared'
|
|
35
|
+
*/
|
|
36
|
+
sharedPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to include @shared alias
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
includeSharedAlias?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Additional path aliases beyond @ and @shared
|
|
44
|
+
*/
|
|
45
|
+
additionalAliases?: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether to auto-configure proxy
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
configureProxy?: boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Vite plugin for Bagelink workspace integration
|
|
54
|
+
* Automatically configures proxy and path aliases based on bgl.config.ts
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { defineConfig } from 'vite'
|
|
59
|
+
* import vue from '@vitejs/plugin-vue'
|
|
60
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
61
|
+
* import workspace from './bgl.config'
|
|
62
|
+
*
|
|
63
|
+
* export default defineConfig({
|
|
64
|
+
* plugins: [
|
|
65
|
+
* vue(),
|
|
66
|
+
* bagelink({ workspace })
|
|
67
|
+
* ]
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example With custom options
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { defineConfig } from 'vite'
|
|
74
|
+
* import vue from '@vitejs/plugin-vue'
|
|
75
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
76
|
+
* import workspace from './bgl.config'
|
|
77
|
+
*
|
|
78
|
+
* export default defineConfig({
|
|
79
|
+
* plugins: [
|
|
80
|
+
* vue(),
|
|
81
|
+
* bagelink({
|
|
82
|
+
* workspace,
|
|
83
|
+
* sharedPath: '../packages/shared',
|
|
84
|
+
* additionalAliases: {
|
|
85
|
+
* '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
* ]
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare function bagelink(options: {
|
|
93
|
+
workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
|
|
94
|
+
config?: BagelinkPluginOptions;
|
|
95
|
+
}): Plugin;
|
|
96
|
+
|
|
97
|
+
export { bagelink, createCustomProxy, createViteProxy, generateNetlifyConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
98
|
+
export type { BagelinkPluginOptions };
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { l as listProjects } from './shared/workspace.Bhp9XbPk.mjs';
|
|
5
|
+
export { g as generateNetlifyConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.Bhp9XbPk.mjs';
|
|
6
|
+
import 'node:fs';
|
|
7
|
+
import 'prompts';
|
|
8
|
+
|
|
9
|
+
function createViteProxy(config) {
|
|
10
|
+
const proxy = {};
|
|
11
|
+
if (config.proxy && config.host) {
|
|
12
|
+
proxy[config.proxy] = {
|
|
13
|
+
target: config.host,
|
|
14
|
+
changeOrigin: true,
|
|
15
|
+
rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
|
|
16
|
+
secure: false,
|
|
17
|
+
ws: true,
|
|
18
|
+
followRedirects: true,
|
|
19
|
+
autoRewrite: true,
|
|
20
|
+
protocolRewrite: "http",
|
|
21
|
+
configure: (proxy2, _options) => {
|
|
22
|
+
proxy2.on("proxyReq", (proxyReq, req, _res) => {
|
|
23
|
+
if (req.headers.origin) {
|
|
24
|
+
proxyReq.setHeader("origin", config.host);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
proxy2.on("error", (err, _req, _res) => {
|
|
28
|
+
console.log("proxy error", err);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (config.host) {
|
|
34
|
+
proxy["/files"] = {
|
|
35
|
+
target: config.host,
|
|
36
|
+
changeOrigin: true,
|
|
37
|
+
secure: false,
|
|
38
|
+
ws: true,
|
|
39
|
+
followRedirects: true
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return proxy;
|
|
43
|
+
}
|
|
44
|
+
function createCustomProxy(paths, target, options = {}) {
|
|
45
|
+
const proxy = {};
|
|
46
|
+
for (const path of paths) {
|
|
47
|
+
proxy[path] = {
|
|
48
|
+
target,
|
|
49
|
+
changeOrigin: options.changeOrigin ?? true,
|
|
50
|
+
secure: options.secure ?? false,
|
|
51
|
+
ws: options.ws ?? true,
|
|
52
|
+
...options.rewrite === true && {
|
|
53
|
+
rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return proxy;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function bagelink(options) {
|
|
61
|
+
const { workspace, config = {} } = options;
|
|
62
|
+
let workspaceConfig;
|
|
63
|
+
return {
|
|
64
|
+
name: "vite-plugin-bagelink",
|
|
65
|
+
enforce: "pre",
|
|
66
|
+
configResolved(resolved) {
|
|
67
|
+
workspaceConfig = workspace(resolved.mode);
|
|
68
|
+
},
|
|
69
|
+
config(userConfig, { mode }) {
|
|
70
|
+
workspaceConfig = workspace(mode);
|
|
71
|
+
const alias = {};
|
|
72
|
+
if (config.includeSharedAlias !== false) {
|
|
73
|
+
const sharedPath = config.sharedPath ?? "../shared";
|
|
74
|
+
alias["@shared"] = fileURLToPath(new URL(sharedPath, `file://${process.cwd()}/`));
|
|
75
|
+
}
|
|
76
|
+
alias["@"] = fileURLToPath(new URL("./src", `file://${process.cwd()}/`));
|
|
77
|
+
if (config.additionalAliases) {
|
|
78
|
+
Object.assign(alias, config.additionalAliases);
|
|
79
|
+
}
|
|
80
|
+
let port;
|
|
81
|
+
try {
|
|
82
|
+
const currentDir = process.cwd();
|
|
83
|
+
const projectName = basename(currentDir);
|
|
84
|
+
const parentDir = fileURLToPath(new URL("..", `file://${currentDir}/`));
|
|
85
|
+
const allProjects = listProjects(parentDir);
|
|
86
|
+
const projectIndex = allProjects.indexOf(projectName);
|
|
87
|
+
if (projectIndex !== -1) {
|
|
88
|
+
port = 5173 + projectIndex;
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
const server = {
|
|
93
|
+
...config.configureProxy !== false && {
|
|
94
|
+
proxy: createViteProxy(workspaceConfig)
|
|
95
|
+
},
|
|
96
|
+
...port !== void 0 && {
|
|
97
|
+
port,
|
|
98
|
+
strictPort: false
|
|
99
|
+
// use next available port if preferred is taken
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const define = {
|
|
103
|
+
...workspaceConfig.proxy && {
|
|
104
|
+
"import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy)
|
|
105
|
+
},
|
|
106
|
+
"import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
|
|
107
|
+
...workspaceConfig.openapi_url && {
|
|
108
|
+
"import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
resolve: {
|
|
113
|
+
alias
|
|
114
|
+
},
|
|
115
|
+
define,
|
|
116
|
+
server,
|
|
117
|
+
optimizeDeps: {
|
|
118
|
+
exclude: ["@bagelink/workspace"]
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { bagelink, createCustomProxy, createViteProxy };
|
package/env.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for Bagelink workspace environment variables
|
|
5
|
+
* These are injected by the bagelink Vite plugin at build time
|
|
6
|
+
*/
|
|
7
|
+
interface ImportMetaEnv {
|
|
8
|
+
/**
|
|
9
|
+
* API proxy path (e.g., '/api')
|
|
10
|
+
* Injected from bgl.config.ts if configured
|
|
11
|
+
* Optional - if not set, use VITE_BGL_HOST directly
|
|
12
|
+
*/
|
|
13
|
+
readonly VITE_BGL_PROXY?: string
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* API host URL (e.g., 'https://project.bagel.to')
|
|
17
|
+
* Injected from bgl.config.ts
|
|
18
|
+
*/
|
|
19
|
+
readonly VITE_BGL_HOST: string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* OpenAPI specification URL (optional)
|
|
23
|
+
* Injected from bgl.config.ts if configured
|
|
24
|
+
*/
|
|
25
|
+
readonly VITE_BGL_OPENAPI_URL?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ImportMeta {
|
|
29
|
+
readonly env: ImportMetaEnv
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.11.
|
|
4
|
+
"version": "1.11.3",
|
|
5
5
|
"description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bagel Studio",
|
|
@@ -29,9 +29,28 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.mjs",
|
|
32
33
|
"require": "./dist/index.cjs",
|
|
33
|
-
"
|
|
34
|
-
}
|
|
34
|
+
"default": "./dist/index.mjs"
|
|
35
|
+
},
|
|
36
|
+
"./vite": {
|
|
37
|
+
"types": "./dist/vite.d.ts",
|
|
38
|
+
"node": {
|
|
39
|
+
"import": "./dist/vite.mjs",
|
|
40
|
+
"require": "./dist/vite.cjs"
|
|
41
|
+
},
|
|
42
|
+
"default": "./dist/vite.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./composable": {
|
|
45
|
+
"types": "./dist/composable.d.ts",
|
|
46
|
+
"browser": {
|
|
47
|
+
"import": "./dist/composable.mjs"
|
|
48
|
+
},
|
|
49
|
+
"import": "./dist/composable.mjs",
|
|
50
|
+
"require": "./dist/composable.cjs",
|
|
51
|
+
"default": "./dist/composable.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./env": "./env.d.ts"
|
|
35
54
|
},
|
|
36
55
|
"main": "./dist/index.mjs",
|
|
37
56
|
"module": "./dist/index.mjs",
|
|
@@ -44,6 +63,7 @@
|
|
|
44
63
|
"src",
|
|
45
64
|
"bin",
|
|
46
65
|
"templates",
|
|
66
|
+
"env.d.ts",
|
|
47
67
|
"README.md"
|
|
48
68
|
],
|
|
49
69
|
"publishConfig": {
|
|
@@ -66,6 +86,7 @@
|
|
|
66
86
|
}
|
|
67
87
|
},
|
|
68
88
|
"devDependencies": {
|
|
89
|
+
"@types/bun": "^1.1.16",
|
|
69
90
|
"@types/node": "^24.0.0",
|
|
70
91
|
"@types/prompts": "^2.4.9",
|
|
71
92
|
"rimraf": "^6.0.1",
|