@bagelink/workspace 1.10.7 → 1.10.9

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.
@@ -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 };
@@ -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.Bc_dpzhA.mjs';
5
+ export { g as generateNetlifyConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.Bc_dpzhA.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.10.7",
4
+ "version": "1.10.9",
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
- "import": "./dist/index.mjs"
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",
package/src/build.ts ADDED
@@ -0,0 +1,45 @@
1
+ import { spawn } from 'node:child_process'
2
+ import process from 'node:process'
3
+ import { listProjects } from './workspace.js'
4
+
5
+ export async function runBuild(
6
+ filter?: string,
7
+ additionalArgs: string[] = [],
8
+ ) {
9
+ const argsStr = additionalArgs.length > 0 ? ` -- ${additionalArgs.join(' ')}` : ''
10
+ const resolvedFilters = resolveFilters(filter)
11
+ if (!resolvedFilters || resolvedFilters.length === 0) return 1
12
+
13
+ const filterArgs = resolvedFilters.map(f => `--filter '${f}'`).join(' ')
14
+ const command = `bun run ${filterArgs} build${argsStr}`
15
+
16
+ const proc = spawn(command, {
17
+ cwd: process.cwd(),
18
+ stdio: 'inherit',
19
+ shell: true,
20
+ })
21
+
22
+ proc.on('error', (error) => {
23
+ console.error('Failed to start build:', error.message)
24
+ })
25
+
26
+ return new Promise<number>((resolve, reject) => {
27
+ proc.on('exit', (code) => {
28
+ resolve(code || 0)
29
+ })
30
+ proc.on('error', reject)
31
+ })
32
+ }
33
+
34
+ function resolveFilters(filter?: string): string[] | null {
35
+ if (filter) return [filter]
36
+
37
+ const projects = listProjects()
38
+ if (projects.length === 0) {
39
+ console.error('No projects found')
40
+ return null
41
+ }
42
+
43
+ // Return all projects as individual filters
44
+ return projects.map(p => `./${p}`)
45
+ }
@@ -0,0 +1,70 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ /**
4
+ * Runtime workspace configuration
5
+ * Provides access to workspace config injected at build time
6
+ */
7
+ export interface RuntimeWorkspaceConfig {
8
+ /** API proxy path (e.g., '/api') */
9
+ proxy?: string
10
+ /** API host URL (e.g., 'https://project.bagel.to') */
11
+ host: string
12
+ /** Base URL for API requests (proxy if available, otherwise host) */
13
+ baseURL: string
14
+ /** OpenAPI specification URL (if configured) */
15
+ openapiUrl?: string
16
+ /** Current environment mode */
17
+ mode: string
18
+ }
19
+
20
+ /**
21
+ * Get workspace configuration at runtime
22
+ * Config is injected as environment variables during build
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { useWorkspace } from '@bagelink/workspace'
27
+ *
28
+ * const { proxy, host } = useWorkspace()
29
+ * const auth = createAuth({ baseURL: proxy })
30
+ * ```
31
+ *
32
+ * @example In Vue component
33
+ * ```vue
34
+ * <script setup>
35
+ * import { useWorkspace } from '@bagelink/workspace'
36
+ *
37
+ * const { proxy, host, mode } = useWorkspace()
38
+ * </script>
39
+ * ```
40
+ */
41
+ export function useWorkspace(): RuntimeWorkspaceConfig {
42
+ // Access env variables injected by the Vite plugin
43
+ const proxy = import.meta.env.VITE_BGL_PROXY || undefined
44
+ const host = import.meta.env.VITE_BGL_HOST || ''
45
+ const openapiUrl = import.meta.env.VITE_BGL_OPENAPI_URL
46
+ const mode = (import.meta.env.MODE as string) || 'development'
47
+
48
+ return {
49
+ proxy,
50
+ host,
51
+ baseURL: proxy ?? host,
52
+ openapiUrl,
53
+ mode,
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Get the full API URL by combining host and proxy
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { getApiUrl } from '@bagelink/workspace'
63
+ *
64
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
65
+ * ```
66
+ */
67
+ export function getApiUrl(): string {
68
+ const { host, proxy } = useWorkspace()
69
+ return `${host}${proxy}`
70
+ }