@bagelink/workspace 1.7.35 → 1.7.39

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 CHANGED
@@ -162,14 +162,13 @@ export default defineConfig(({ mode }) => {
162
162
  **Access config at runtime with `useWorkspace()`:**
163
163
 
164
164
  ```typescript
165
- import { useWorkspace } from '@bagelink/workspace'
165
+ import { useWorkspace, getApiUrl } from '@bagelink/workspace/composable'
166
166
 
167
167
  // In your app setup
168
168
  const { proxy, host, mode } = useWorkspace()
169
169
  const auth = initAuth({ baseURL: proxy })
170
170
 
171
171
  // Or get full API URL
172
- import { getApiUrl } from '@bagelink/workspace'
173
172
  const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
174
173
  ```
175
174
 
@@ -177,7 +176,7 @@ const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
177
176
 
178
177
  ```vue
179
178
  <script setup lang="ts">
180
- import { useWorkspace } from '@bagelink/workspace'
179
+ import { useWorkspace } from '@bagelink/workspace/composable'
181
180
  import { initAuth } from '@bagelink/auth'
182
181
 
183
182
  const { proxy, host, mode } = useWorkspace()
@@ -515,7 +514,7 @@ Show CLI help.
515
514
  Get workspace configuration at runtime. Config is injected as environment variables during build.
516
515
 
517
516
  ```typescript
518
- import { useWorkspace } from '@bagelink/workspace'
517
+ import { useWorkspace } from '@bagelink/workspace/composable'
519
518
 
520
519
  const { proxy, host, openapiUrl, mode } = useWorkspace()
521
520
  ```
@@ -535,7 +534,7 @@ interface RuntimeWorkspaceConfig {
535
534
  Get the full API URL by combining host and proxy.
536
535
 
537
536
  ```typescript
538
- import { getApiUrl } from '@bagelink/workspace'
537
+ import { getApiUrl } from '@bagelink/workspace/composable'
539
538
 
540
539
  const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
541
540
  ```
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ function useWorkspace() {
4
+ const proxy = undefined.VITE_BGL_PROXY || "/api";
5
+ const host = undefined.VITE_BGL_HOST || "";
6
+ const openapiUrl = undefined.VITE_BGL_OPENAPI_URL;
7
+ const mode = undefined.MODE || "development";
8
+ return {
9
+ proxy,
10
+ host,
11
+ openapiUrl,
12
+ mode
13
+ };
14
+ }
15
+ function getApiUrl() {
16
+ const { host, proxy } = useWorkspace();
17
+ return `${host}${proxy}`;
18
+ }
19
+
20
+ exports.getApiUrl = getApiUrl;
21
+ exports.useWorkspace = useWorkspace;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Runtime workspace configuration
3
+ * Provides access to workspace config injected at build time
4
+ */
5
+ interface RuntimeWorkspaceConfig {
6
+ /** API proxy path (e.g., '/api') */
7
+ proxy: string;
8
+ /** API host URL (e.g., 'https://project.bagel.to') */
9
+ host: string;
10
+ /** OpenAPI specification URL (if configured) */
11
+ openapiUrl?: string;
12
+ /** Current environment mode */
13
+ mode: 'localhost' | 'development' | 'production';
14
+ }
15
+ /**
16
+ * Get workspace configuration at runtime
17
+ * Config is injected as environment variables during build
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { useWorkspace } from '@bagelink/workspace'
22
+ *
23
+ * const { proxy, host } = useWorkspace()
24
+ * const auth = initAuth({ baseURL: proxy })
25
+ * ```
26
+ *
27
+ * @example In Vue component
28
+ * ```vue
29
+ * <script setup>
30
+ * import { useWorkspace } from '@bagelink/workspace'
31
+ *
32
+ * const { proxy, host, mode } = useWorkspace()
33
+ * </script>
34
+ * ```
35
+ */
36
+ declare function useWorkspace(): RuntimeWorkspaceConfig;
37
+ /**
38
+ * Get the full API URL by combining host and proxy
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { getApiUrl } from '@bagelink/workspace'
43
+ *
44
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
45
+ * ```
46
+ */
47
+ declare function getApiUrl(): string;
48
+
49
+ export { getApiUrl, useWorkspace };
50
+ export type { RuntimeWorkspaceConfig };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Runtime workspace configuration
3
+ * Provides access to workspace config injected at build time
4
+ */
5
+ interface RuntimeWorkspaceConfig {
6
+ /** API proxy path (e.g., '/api') */
7
+ proxy: string;
8
+ /** API host URL (e.g., 'https://project.bagel.to') */
9
+ host: string;
10
+ /** OpenAPI specification URL (if configured) */
11
+ openapiUrl?: string;
12
+ /** Current environment mode */
13
+ mode: 'localhost' | 'development' | 'production';
14
+ }
15
+ /**
16
+ * Get workspace configuration at runtime
17
+ * Config is injected as environment variables during build
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { useWorkspace } from '@bagelink/workspace'
22
+ *
23
+ * const { proxy, host } = useWorkspace()
24
+ * const auth = initAuth({ baseURL: proxy })
25
+ * ```
26
+ *
27
+ * @example In Vue component
28
+ * ```vue
29
+ * <script setup>
30
+ * import { useWorkspace } from '@bagelink/workspace'
31
+ *
32
+ * const { proxy, host, mode } = useWorkspace()
33
+ * </script>
34
+ * ```
35
+ */
36
+ declare function useWorkspace(): RuntimeWorkspaceConfig;
37
+ /**
38
+ * Get the full API URL by combining host and proxy
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { getApiUrl } from '@bagelink/workspace'
43
+ *
44
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
45
+ * ```
46
+ */
47
+ declare function getApiUrl(): string;
48
+
49
+ export { getApiUrl, useWorkspace };
50
+ export type { RuntimeWorkspaceConfig };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Runtime workspace configuration
3
+ * Provides access to workspace config injected at build time
4
+ */
5
+ interface RuntimeWorkspaceConfig {
6
+ /** API proxy path (e.g., '/api') */
7
+ proxy: string;
8
+ /** API host URL (e.g., 'https://project.bagel.to') */
9
+ host: string;
10
+ /** OpenAPI specification URL (if configured) */
11
+ openapiUrl?: string;
12
+ /** Current environment mode */
13
+ mode: 'localhost' | 'development' | 'production';
14
+ }
15
+ /**
16
+ * Get workspace configuration at runtime
17
+ * Config is injected as environment variables during build
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { useWorkspace } from '@bagelink/workspace'
22
+ *
23
+ * const { proxy, host } = useWorkspace()
24
+ * const auth = initAuth({ baseURL: proxy })
25
+ * ```
26
+ *
27
+ * @example In Vue component
28
+ * ```vue
29
+ * <script setup>
30
+ * import { useWorkspace } from '@bagelink/workspace'
31
+ *
32
+ * const { proxy, host, mode } = useWorkspace()
33
+ * </script>
34
+ * ```
35
+ */
36
+ declare function useWorkspace(): RuntimeWorkspaceConfig;
37
+ /**
38
+ * Get the full API URL by combining host and proxy
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { getApiUrl } from '@bagelink/workspace'
43
+ *
44
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
45
+ * ```
46
+ */
47
+ declare function getApiUrl(): string;
48
+
49
+ export { getApiUrl, useWorkspace };
50
+ export type { RuntimeWorkspaceConfig };
@@ -0,0 +1,18 @@
1
+ function useWorkspace() {
2
+ const proxy = import.meta.env.VITE_BGL_PROXY || "/api";
3
+ const host = import.meta.env.VITE_BGL_HOST || "";
4
+ const openapiUrl = import.meta.env.VITE_BGL_OPENAPI_URL;
5
+ const mode = import.meta.env.MODE || "development";
6
+ return {
7
+ proxy,
8
+ host,
9
+ openapiUrl,
10
+ mode
11
+ };
12
+ }
13
+ function getApiUrl() {
14
+ const { host, proxy } = useWorkspace();
15
+ return `${host}${proxy}`;
16
+ }
17
+
18
+ export { getApiUrl, useWorkspace };
package/dist/index.cjs CHANGED
@@ -4,9 +4,11 @@ const node_fs = require('node:fs');
4
4
  const node_path = require('node:path');
5
5
  const process = require('node:process');
6
6
  const workspace = require('./shared/workspace.CamNrnD_.cjs');
7
- const node_url = require('node:url');
7
+ const vite = require('./shared/workspace.DfLGMczD.cjs');
8
+ const composable = require('./composable.cjs');
8
9
  require('prompts');
9
10
  require('node:child_process');
11
+ require('node:url');
10
12
 
11
13
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
14
 
@@ -72,98 +74,6 @@ function mergeConfigs(base, override) {
72
74
  };
73
75
  }
74
76
 
75
- function createViteProxy(config) {
76
- const proxy = {};
77
- if (config.proxy && config.host) {
78
- proxy[config.proxy] = {
79
- target: config.host,
80
- changeOrigin: true,
81
- rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
82
- secure: true
83
- };
84
- }
85
- if (config.host) {
86
- proxy["/files"] = {
87
- target: config.host,
88
- changeOrigin: true,
89
- secure: true
90
- };
91
- }
92
- return proxy;
93
- }
94
- function createCustomProxy(paths, target, options = {}) {
95
- const proxy = {};
96
- for (const path of paths) {
97
- proxy[path] = {
98
- target,
99
- changeOrigin: options.changeOrigin ?? true,
100
- secure: options.secure ?? true,
101
- ...options.rewrite === true && {
102
- rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
103
- }
104
- };
105
- }
106
- return proxy;
107
- }
108
-
109
- function useWorkspace() {
110
- const proxy = undefined.VITE_BGL_PROXY || "/api";
111
- const host = undefined.VITE_BGL_HOST || "";
112
- const openapiUrl = undefined.VITE_BGL_OPENAPI_URL;
113
- const mode = undefined.MODE || "development";
114
- return {
115
- proxy,
116
- host,
117
- openapiUrl,
118
- mode
119
- };
120
- }
121
- function getApiUrl() {
122
- const { host, proxy } = useWorkspace();
123
- return `${host}${proxy}`;
124
- }
125
-
126
- function bagelink(options) {
127
- const { workspace, config = {} } = options;
128
- let workspaceConfig;
129
- return {
130
- name: "vite-plugin-bagelink",
131
- enforce: "pre",
132
- configResolved(resolved) {
133
- workspaceConfig = workspace(resolved.mode);
134
- },
135
- config(userConfig, { mode }) {
136
- workspaceConfig = workspace(mode);
137
- const alias = {};
138
- if (config.includeSharedAlias !== false) {
139
- const sharedPath = config.sharedPath ?? "../shared";
140
- alias["@shared"] = node_url.fileURLToPath(new URL(sharedPath, `file://${process__default.cwd()}/`));
141
- }
142
- alias["@"] = node_url.fileURLToPath(new URL("./src", `file://${process__default.cwd()}/`));
143
- if (config.additionalAliases) {
144
- Object.assign(alias, config.additionalAliases);
145
- }
146
- const server = config.configureProxy !== false ? {
147
- proxy: createViteProxy(workspaceConfig)
148
- } : void 0;
149
- const define = {
150
- "import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy),
151
- "import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
152
- ...workspaceConfig.openapi_url && {
153
- "import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
154
- }
155
- };
156
- return {
157
- resolve: {
158
- alias
159
- },
160
- define,
161
- ...server && { server }
162
- };
163
- }
164
- };
165
- }
166
-
167
77
  function defineWorkspace(configs) {
168
78
  return (mode = "development") => {
169
79
  return configs[mode] || configs.development;
@@ -185,7 +95,7 @@ function createWorkspace(options = {}) {
185
95
  * Create Vite proxy configuration
186
96
  */
187
97
  createProxy(config) {
188
- return createViteProxy(config);
98
+ return vite.createViteProxy(config);
189
99
  },
190
100
  /**
191
101
  * Generate Netlify configuration file
@@ -223,12 +133,12 @@ exports.runDev = workspace.runDev;
223
133
  exports.setBuildEnvVars = workspace.setBuildEnvVars;
224
134
  exports.setupLint = workspace.setupLint;
225
135
  exports.writeNetlifyConfig = workspace.writeNetlifyConfig;
226
- exports.bagelink = bagelink;
227
- exports.createCustomProxy = createCustomProxy;
228
- exports.createViteProxy = createViteProxy;
136
+ exports.bagelink = vite.bagelink;
137
+ exports.createCustomProxy = vite.createCustomProxy;
138
+ exports.createViteProxy = vite.createViteProxy;
139
+ exports.getApiUrl = composable.getApiUrl;
140
+ exports.useWorkspace = composable.useWorkspace;
229
141
  exports.createWorkspace = createWorkspace;
230
142
  exports.defineWorkspace = defineWorkspace;
231
- exports.getApiUrl = getApiUrl;
232
143
  exports.mergeConfigs = mergeConfigs;
233
144
  exports.resolveConfig = resolveConfig;
234
- exports.useWorkspace = useWorkspace;
package/dist/index.d.cts CHANGED
@@ -1,47 +1,7 @@
1
- import { Plugin } from 'vite';
2
-
3
- type WorkspaceEnvironment = 'localhost' | 'development' | 'production';
4
- interface WorkspaceConfig {
5
- /**
6
- * The host URL of the backend API server
7
- * @example 'http://localhost:8000' | 'https://project.bagel.to'
8
- */
9
- host: string;
10
- /**
11
- * The proxy path to use for API requests
12
- * @default '/api'
13
- */
14
- proxy: string;
15
- /**
16
- * Optional OpenAPI specification URL for SDK generation
17
- */
18
- openapi_url?: string;
19
- }
20
- interface WorkspaceOptions {
21
- /**
22
- * Root directory of the workspace
23
- * @default process.cwd()
24
- */
25
- root?: string;
26
- /**
27
- * Path to the config file relative to root
28
- * @default 'bgl.config.ts'
29
- */
30
- configFile?: string;
31
- /**
32
- * Enable interactive config generation if no config is found
33
- * @default true
34
- */
35
- interactive?: boolean;
36
- }
37
- interface ProxyConfig {
38
- [path: string]: {
39
- target: string;
40
- changeOrigin: boolean;
41
- rewrite?: (path: string) => string;
42
- secure: boolean;
43
- };
44
- }
1
+ import { W as WorkspaceConfig, a as WorkspaceEnvironment, b as WorkspaceOptions, P as ProxyConfig } from './shared/workspace.CSNgk3PR.cjs';
2
+ export { B as BagelinkPluginOptions, c as bagelink } from './shared/workspace.CSNgk3PR.cjs';
3
+ export { RuntimeWorkspaceConfig, getApiUrl, useWorkspace } from './composable.cjs';
4
+ import 'vite';
45
5
 
46
6
  /**
47
7
  * Load and resolve bgl.config.ts with cascading support
@@ -94,54 +54,6 @@ declare function createCustomProxy(paths: string[], target: string, options?: {
94
54
  secure?: boolean;
95
55
  }): ProxyConfig;
96
56
 
97
- /**
98
- * Runtime workspace configuration
99
- * Provides access to workspace config injected at build time
100
- */
101
- interface RuntimeWorkspaceConfig {
102
- /** API proxy path (e.g., '/api') */
103
- proxy: string;
104
- /** API host URL (e.g., 'https://project.bagel.to') */
105
- host: string;
106
- /** OpenAPI specification URL (if configured) */
107
- openapiUrl?: string;
108
- /** Current environment mode */
109
- mode: 'localhost' | 'development' | 'production';
110
- }
111
- /**
112
- * Get workspace configuration at runtime
113
- * Config is injected as environment variables during build
114
- *
115
- * @example
116
- * ```ts
117
- * import { useWorkspace } from '@bagelink/workspace'
118
- *
119
- * const { proxy, host } = useWorkspace()
120
- * const auth = initAuth({ baseURL: proxy })
121
- * ```
122
- *
123
- * @example In Vue component
124
- * ```vue
125
- * <script setup>
126
- * import { useWorkspace } from '@bagelink/workspace'
127
- *
128
- * const { proxy, host, mode } = useWorkspace()
129
- * </script>
130
- * ```
131
- */
132
- declare function useWorkspace(): RuntimeWorkspaceConfig;
133
- /**
134
- * Get the full API URL by combining host and proxy
135
- *
136
- * @example
137
- * ```ts
138
- * import { getApiUrl } from '@bagelink/workspace'
139
- *
140
- * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
141
- * ```
142
- */
143
- declare function getApiUrl(): string;
144
-
145
57
  /**
146
58
  * Detect if current directory is a workspace root
147
59
  */
@@ -171,72 +83,6 @@ declare function generateSDK(root?: string): Promise<void>;
171
83
  */
172
84
  declare function generateSDKForWorkspace(root?: string): Promise<void>;
173
85
 
174
- interface BagelinkPluginOptions {
175
- /**
176
- * Path to shared package relative to project
177
- * @default '../shared'
178
- */
179
- sharedPath?: string;
180
- /**
181
- * Whether to include @shared alias
182
- * @default true
183
- */
184
- includeSharedAlias?: boolean;
185
- /**
186
- * Additional path aliases beyond @ and @shared
187
- */
188
- additionalAliases?: Record<string, string>;
189
- /**
190
- * Whether to auto-configure proxy
191
- * @default true
192
- */
193
- configureProxy?: boolean;
194
- }
195
- /**
196
- * Vite plugin for Bagelink workspace integration
197
- * Automatically configures proxy and path aliases based on bgl.config.ts
198
- *
199
- * @example
200
- * ```ts
201
- * import { defineConfig } from 'vite'
202
- * import vue from '@vitejs/plugin-vue'
203
- * import { bagelink } from '@bagelink/workspace/vite'
204
- * import workspace from './bgl.config'
205
- *
206
- * export default defineConfig({
207
- * plugins: [
208
- * vue(),
209
- * bagelink({ workspace })
210
- * ]
211
- * })
212
- * ```
213
- *
214
- * @example With custom options
215
- * ```ts
216
- * import { defineConfig } from 'vite'
217
- * import vue from '@vitejs/plugin-vue'
218
- * import { bagelink } from '@bagelink/workspace/vite'
219
- * import workspace from './bgl.config'
220
- *
221
- * export default defineConfig({
222
- * plugins: [
223
- * vue(),
224
- * bagelink({
225
- * workspace,
226
- * sharedPath: '../packages/shared',
227
- * additionalAliases: {
228
- * '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
229
- * }
230
- * })
231
- * ]
232
- * })
233
- * ```
234
- */
235
- declare function bagelink(options: {
236
- workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
237
- config?: BagelinkPluginOptions;
238
- }): Plugin;
239
-
240
86
  /**
241
87
  * Initialize a new workspace with flat structure
242
88
  */
@@ -282,5 +128,4 @@ declare function createWorkspace(options?: WorkspaceOptions): {
282
128
  clearCache(): void;
283
129
  };
284
130
 
285
- export { addProject, bagelink, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getApiUrl, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, useWorkspace, writeNetlifyConfig };
286
- export type { BagelinkPluginOptions, ProxyConfig, RuntimeWorkspaceConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
131
+ export { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions, addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, writeNetlifyConfig };