@bagelink/workspace 1.7.39 → 1.7.43

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/dist/vite.mjs CHANGED
@@ -1,3 +1,82 @@
1
- import 'node:process';
2
- import 'node:url';
3
- export { b as bagelink } from './shared/workspace.D0MF8ERh.mjs';
1
+ import process from 'node:process';
2
+ import { fileURLToPath } from 'node:url';
3
+ export { g as generateNetlifyConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.Twuo1PFw.mjs';
4
+ import 'node:fs';
5
+ import 'node:path';
6
+
7
+ function createViteProxy(config) {
8
+ const proxy = {};
9
+ if (config.proxy && config.host) {
10
+ proxy[config.proxy] = {
11
+ target: config.host,
12
+ changeOrigin: true,
13
+ rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
14
+ secure: true
15
+ };
16
+ }
17
+ if (config.host) {
18
+ proxy["/files"] = {
19
+ target: config.host,
20
+ changeOrigin: true,
21
+ secure: true
22
+ };
23
+ }
24
+ return proxy;
25
+ }
26
+ function createCustomProxy(paths, target, options = {}) {
27
+ const proxy = {};
28
+ for (const path of paths) {
29
+ proxy[path] = {
30
+ target,
31
+ changeOrigin: options.changeOrigin ?? true,
32
+ secure: options.secure ?? true,
33
+ ...options.rewrite === true && {
34
+ rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
35
+ }
36
+ };
37
+ }
38
+ return proxy;
39
+ }
40
+
41
+ function bagelink(options) {
42
+ const { workspace, config = {} } = options;
43
+ let workspaceConfig;
44
+ return {
45
+ name: "vite-plugin-bagelink",
46
+ enforce: "pre",
47
+ configResolved(resolved) {
48
+ workspaceConfig = workspace(resolved.mode);
49
+ },
50
+ config(userConfig, { mode }) {
51
+ workspaceConfig = workspace(mode);
52
+ const alias = {};
53
+ if (config.includeSharedAlias !== false) {
54
+ const sharedPath = config.sharedPath ?? "../shared";
55
+ alias["@shared"] = fileURLToPath(new URL(sharedPath, `file://${process.cwd()}/`));
56
+ }
57
+ alias["@"] = fileURLToPath(new URL("./src", `file://${process.cwd()}/`));
58
+ if (config.additionalAliases) {
59
+ Object.assign(alias, config.additionalAliases);
60
+ }
61
+ const server = config.configureProxy !== false ? {
62
+ proxy: createViteProxy(workspaceConfig)
63
+ } : void 0;
64
+ const define = {
65
+ "import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy),
66
+ "import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
67
+ ...workspaceConfig.openapi_url && {
68
+ "import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
69
+ }
70
+ };
71
+ return {
72
+ resolve: {
73
+ alias
74
+ },
75
+ define,
76
+ ...server && { server }
77
+ };
78
+ }
79
+ };
80
+ }
81
+
82
+ export { bagelink, createCustomProxy, createViteProxy };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/workspace",
3
3
  "type": "module",
4
- "version": "1.7.39",
4
+ "version": "1.7.43",
5
5
  "description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
package/src/index.ts CHANGED
@@ -4,16 +4,8 @@ import type {
4
4
  WorkspaceOptions,
5
5
  ProxyConfig,
6
6
  } from './types'
7
- import { resolveConfig, mergeConfigs } from './config'
8
- import { generateWorkspaceConfig, generateWorkspaceConfigSync } from './init'
9
- import {
10
- generateNetlifyConfig,
11
- generateNetlifyRedirect,
12
- writeNetlifyConfig,
13
- setBuildEnvVars,
14
- } from './netlify'
15
- import { createViteProxy, createCustomProxy } from './proxy'
16
7
 
8
+ // Export types (no runtime code)
17
9
  export type {
18
10
  ProxyConfig,
19
11
  WorkspaceConfig,
@@ -21,34 +13,10 @@ export type {
21
13
  WorkspaceOptions,
22
14
  }
23
15
 
24
- export {
25
- createCustomProxy,
26
- createViteProxy,
27
- generateNetlifyConfig,
28
- generateNetlifyRedirect,
29
- generateWorkspaceConfig,
30
- generateWorkspaceConfigSync,
31
- mergeConfigs,
32
- resolveConfig,
33
- setBuildEnvVars,
34
- writeNetlifyConfig,
35
- }
36
-
37
16
  // Runtime composables (browser-safe, no Node.js dependencies)
38
17
  export { getApiUrl, useWorkspace } from './composable'
39
18
  export type { RuntimeWorkspaceConfig } from './composable'
40
19
 
41
- // Node.js / CLI-only exports
42
- export { getWorkspaceInfo, isWorkspace } from './detect'
43
- export { runDev } from './dev'
44
- export { setupLint } from './lint'
45
- export { generateSDK, generateSDKForWorkspace } from './sdk'
46
- // Vite plugin (build-time only)
47
- export { bagelink } from './vite'
48
-
49
- export type { BagelinkPluginOptions } from './vite'
50
- export { addProject, initWorkspace, listProjects } from './workspace'
51
-
52
20
  /**
53
21
  * Define workspace configuration
54
22
  * Simple helper to get config from a config map
@@ -62,53 +30,12 @@ export function defineWorkspace(
62
30
  }
63
31
 
64
32
  /**
65
- * Create a workspace instance for managing project configuration
66
- * Supports both single project and monorepo setups
33
+ * @deprecated Import build-time utilities from '@bagelink/workspace/vite' instead
34
+ * This function is no longer exported to keep the main package browser-safe
67
35
  */
68
- export function createWorkspace(options: WorkspaceOptions = {}) {
69
- let cachedConfig: WorkspaceConfig | null = null
70
-
71
- return {
72
- /**
73
- * Get resolved config for the specified environment
74
- */
75
- async getConfig(mode: WorkspaceEnvironment = 'development'): Promise<WorkspaceConfig> {
76
- if (!cachedConfig) {
77
- cachedConfig = await resolveConfig(mode, options)
78
- }
79
- return cachedConfig
80
- },
36
+ // export function createWorkspace() { ... }
81
37
 
82
- /**
83
- * Create Vite proxy configuration
84
- */
85
- createProxy(config: WorkspaceConfig): ProxyConfig {
86
- return createViteProxy(config)
87
- },
88
-
89
- /**
90
- * Generate Netlify configuration file
91
- */
92
- generateNetlify(
93
- config: WorkspaceConfig,
94
- outPath: string = './netlify.toml',
95
- additionalConfig?: string
96
- ): void {
97
- writeNetlifyConfig(config, outPath, additionalConfig)
98
- },
99
-
100
- /**
101
- * Set build environment variables
102
- */
103
- setBuildEnv(config: WorkspaceConfig): void {
104
- setBuildEnvVars(config)
105
- },
106
-
107
- /**
108
- * Clear cached configuration
109
- */
110
- clearCache(): void {
111
- cachedConfig = null
112
- },
113
- }
114
- }
38
+ // Note: The following are available via separate subpath imports:
39
+ // - Vite plugin and utilities: '@bagelink/workspace/vite'
40
+ // - CLI commands: 'bgl' command
41
+ // This keeps the main '@bagelink/workspace' import browser-safe
package/src/lint.ts CHANGED
@@ -1,8 +1,35 @@
1
- import { existsSync, readFileSync, writeFileSync } from 'node:fs'
1
+ import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
2
2
  import { resolve } from 'node:path'
3
3
  import process from 'node:process'
4
4
  import prompts from 'prompts'
5
5
 
6
+ /**
7
+ * List of redundant lint config files that can be safely removed
8
+ * after setting up the new lint configuration
9
+ */
10
+ const REDUNDANT_FILES = [
11
+ // Old ESLint configs
12
+ '.eslintrc',
13
+ '.eslintrc.json',
14
+ '.eslintrc.js',
15
+ '.eslintrc.cjs',
16
+ '.eslintrc.yaml',
17
+ '.eslintrc.yml',
18
+ // Oxlint
19
+ 'oxlint.json',
20
+ // Old Prettier configs (we create .prettierrc)
21
+ 'prettier.config.js',
22
+ 'prettier.config.cjs',
23
+ 'prettier.config.mjs',
24
+ '.prettierrc.json',
25
+ '.prettierrc.yaml',
26
+ '.prettierrc.yml',
27
+ '.prettierrc.js',
28
+ '.prettierrc.cjs',
29
+ '.prettierrc.mjs',
30
+ '.prettierrc.toml',
31
+ ]
32
+
6
33
  /**
7
34
  * Set up linting in a project
8
35
  */
@@ -24,6 +51,12 @@ export async function setupLint(
24
51
  { title: 'Git Hooks', value: 'githooks', selected: false },
25
52
  ],
26
53
  },
54
+ {
55
+ type: 'confirm',
56
+ name: 'cleanRedundant',
57
+ message: 'Clean up redundant lint config files?',
58
+ initial: true,
59
+ },
27
60
  {
28
61
  type: 'confirm',
29
62
  name: 'installDeps',
@@ -37,7 +70,12 @@ export async function setupLint(
37
70
  process.exit(1)
38
71
  }
39
72
 
40
- const { configs, installDeps } = response
73
+ const { configs, cleanRedundant, installDeps } = response
74
+
75
+ // Clean up redundant files first
76
+ if (cleanRedundant) {
77
+ await cleanRedundantFiles(root)
78
+ }
41
79
 
42
80
  // Create config files
43
81
  if (configs.includes('eslint')) {
@@ -182,6 +220,56 @@ function createGitHooks(root: string): void {
182
220
  console.log(' Then run: npx simple-git-hooks')
183
221
  }
184
222
 
223
+ /**
224
+ * Clean up redundant lint configuration files
225
+ */
226
+ async function cleanRedundantFiles(root: string): Promise<void> {
227
+ const foundFiles: string[] = []
228
+
229
+ // Check which redundant files exist
230
+ for (const file of REDUNDANT_FILES) {
231
+ const filePath = resolve(root, file)
232
+ if (existsSync(filePath)) {
233
+ foundFiles.push(file)
234
+ }
235
+ }
236
+
237
+ if (foundFiles.length === 0) {
238
+ console.log('✨ No redundant files found')
239
+ return
240
+ }
241
+
242
+ console.log('\n📋 Found redundant files:')
243
+ foundFiles.forEach((file) => { console.log(` - ${file}`) })
244
+
245
+ const confirmResponse = await prompts({
246
+ type: 'confirm',
247
+ name: 'confirm',
248
+ message: `Delete ${foundFiles.length} redundant file${foundFiles.length > 1 ? 's' : ''}?`,
249
+ initial: true,
250
+ })
251
+
252
+ if (!confirmResponse.confirm) {
253
+ console.log('⏭️ Skipped cleaning redundant files')
254
+ return
255
+ }
256
+
257
+ // Delete confirmed files
258
+ let deleted = 0
259
+ for (const file of foundFiles) {
260
+ try {
261
+ unlinkSync(resolve(root, file))
262
+ console.log(`🗑️ Deleted ${file}`)
263
+ deleted++
264
+ }
265
+ catch (error) {
266
+ console.error(`❌ Failed to delete ${file}:`, error)
267
+ }
268
+ }
269
+
270
+ console.log(`✅ Cleaned up ${deleted} file${deleted > 1 ? 's' : ''}`)
271
+ }
272
+
185
273
  /**
186
274
  * Update package.json with lint scripts
187
275
  */
package/src/vite.ts CHANGED
@@ -4,6 +4,10 @@ import process from 'node:process'
4
4
  import { fileURLToPath } from 'node:url'
5
5
  import { createViteProxy } from './proxy'
6
6
 
7
+ export { generateNetlifyConfig, setBuildEnvVars, writeNetlifyConfig } from './netlify'
8
+ // Re-export proxy utilities for convenience
9
+ export { createCustomProxy, createViteProxy } from './proxy'
10
+
7
11
  export interface BagelinkPluginOptions {
8
12
  /**
9
13
  * Path to shared package relative to project
@@ -1,113 +0,0 @@
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
- }
45
-
46
- interface BagelinkPluginOptions {
47
- /**
48
- * Path to shared package relative to project
49
- * @default '../shared'
50
- */
51
- sharedPath?: string;
52
- /**
53
- * Whether to include @shared alias
54
- * @default true
55
- */
56
- includeSharedAlias?: boolean;
57
- /**
58
- * Additional path aliases beyond @ and @shared
59
- */
60
- additionalAliases?: Record<string, string>;
61
- /**
62
- * Whether to auto-configure proxy
63
- * @default true
64
- */
65
- configureProxy?: boolean;
66
- }
67
- /**
68
- * Vite plugin for Bagelink workspace integration
69
- * Automatically configures proxy and path aliases based on bgl.config.ts
70
- *
71
- * @example
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({ workspace })
82
- * ]
83
- * })
84
- * ```
85
- *
86
- * @example With custom options
87
- * ```ts
88
- * import { defineConfig } from 'vite'
89
- * import vue from '@vitejs/plugin-vue'
90
- * import { bagelink } from '@bagelink/workspace/vite'
91
- * import workspace from './bgl.config'
92
- *
93
- * export default defineConfig({
94
- * plugins: [
95
- * vue(),
96
- * bagelink({
97
- * workspace,
98
- * sharedPath: '../packages/shared',
99
- * additionalAliases: {
100
- * '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
101
- * }
102
- * })
103
- * ]
104
- * })
105
- * ```
106
- */
107
- declare function bagelink(options: {
108
- workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
109
- config?: BagelinkPluginOptions;
110
- }): Plugin;
111
-
112
- export { bagelink as c };
113
- export type { BagelinkPluginOptions as B, ProxyConfig as P, WorkspaceConfig as W, WorkspaceEnvironment as a, WorkspaceOptions as b };
@@ -1,113 +0,0 @@
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
- }
45
-
46
- interface BagelinkPluginOptions {
47
- /**
48
- * Path to shared package relative to project
49
- * @default '../shared'
50
- */
51
- sharedPath?: string;
52
- /**
53
- * Whether to include @shared alias
54
- * @default true
55
- */
56
- includeSharedAlias?: boolean;
57
- /**
58
- * Additional path aliases beyond @ and @shared
59
- */
60
- additionalAliases?: Record<string, string>;
61
- /**
62
- * Whether to auto-configure proxy
63
- * @default true
64
- */
65
- configureProxy?: boolean;
66
- }
67
- /**
68
- * Vite plugin for Bagelink workspace integration
69
- * Automatically configures proxy and path aliases based on bgl.config.ts
70
- *
71
- * @example
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({ workspace })
82
- * ]
83
- * })
84
- * ```
85
- *
86
- * @example With custom options
87
- * ```ts
88
- * import { defineConfig } from 'vite'
89
- * import vue from '@vitejs/plugin-vue'
90
- * import { bagelink } from '@bagelink/workspace/vite'
91
- * import workspace from './bgl.config'
92
- *
93
- * export default defineConfig({
94
- * plugins: [
95
- * vue(),
96
- * bagelink({
97
- * workspace,
98
- * sharedPath: '../packages/shared',
99
- * additionalAliases: {
100
- * '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
101
- * }
102
- * })
103
- * ]
104
- * })
105
- * ```
106
- */
107
- declare function bagelink(options: {
108
- workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
109
- config?: BagelinkPluginOptions;
110
- }): Plugin;
111
-
112
- export { bagelink as c };
113
- export type { BagelinkPluginOptions as B, ProxyConfig as P, WorkspaceConfig as W, WorkspaceEnvironment as a, WorkspaceOptions as b };
@@ -1,113 +0,0 @@
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
- }
45
-
46
- interface BagelinkPluginOptions {
47
- /**
48
- * Path to shared package relative to project
49
- * @default '../shared'
50
- */
51
- sharedPath?: string;
52
- /**
53
- * Whether to include @shared alias
54
- * @default true
55
- */
56
- includeSharedAlias?: boolean;
57
- /**
58
- * Additional path aliases beyond @ and @shared
59
- */
60
- additionalAliases?: Record<string, string>;
61
- /**
62
- * Whether to auto-configure proxy
63
- * @default true
64
- */
65
- configureProxy?: boolean;
66
- }
67
- /**
68
- * Vite plugin for Bagelink workspace integration
69
- * Automatically configures proxy and path aliases based on bgl.config.ts
70
- *
71
- * @example
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({ workspace })
82
- * ]
83
- * })
84
- * ```
85
- *
86
- * @example With custom options
87
- * ```ts
88
- * import { defineConfig } from 'vite'
89
- * import vue from '@vitejs/plugin-vue'
90
- * import { bagelink } from '@bagelink/workspace/vite'
91
- * import workspace from './bgl.config'
92
- *
93
- * export default defineConfig({
94
- * plugins: [
95
- * vue(),
96
- * bagelink({
97
- * workspace,
98
- * sharedPath: '../packages/shared',
99
- * additionalAliases: {
100
- * '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
101
- * }
102
- * })
103
- * ]
104
- * })
105
- * ```
106
- */
107
- declare function bagelink(options: {
108
- workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
109
- config?: BagelinkPluginOptions;
110
- }): Plugin;
111
-
112
- export { bagelink as c };
113
- export type { BagelinkPluginOptions as B, ProxyConfig as P, WorkspaceConfig as W, WorkspaceEnvironment as a, WorkspaceOptions as b };