@codygo-ai/vite-tools 0.1.0-alpha

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,22 @@
1
+
2
+ > @codygo-ai/vite-tools@0.1.0-alpha build /home/runner/work/tooling/tooling/packages/vite/vite-tools
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /home/runner/work/tooling/tooling/packages/vite/vite-tools/tsup.config.ts
9
+ CLI Target: es2020
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ CJS dist/index.cjs 4.52 KB
14
+ CJS dist/index.cjs.map 6.78 KB
15
+ CJS ⚡️ Build success in 13ms
16
+ ESM dist/index.js 3.31 KB
17
+ ESM dist/index.js.map 6.65 KB
18
+ ESM ⚡️ Build success in 13ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 854ms
21
+ DTS dist/index.d.ts 219.00 B
22
+ DTS dist/index.d.cts 219.00 B
package/dist/index.cjs ADDED
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ workspacePathsPlugin: () => workspacePathsPlugin
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/workspacePathsPlugin.ts
28
+ var import_fs = require("fs");
29
+ var import_path = require("path");
30
+ function findWorkspaceRoot(startPath) {
31
+ let currentDir = startPath;
32
+ const rootDir = "/";
33
+ while (currentDir !== rootDir) {
34
+ const workspaceFile = (0, import_path.join)(currentDir, "pnpm-workspace.yaml");
35
+ try {
36
+ const stats = (0, import_fs.statSync)(workspaceFile);
37
+ if (stats.isFile()) {
38
+ return currentDir;
39
+ }
40
+ } catch {
41
+ }
42
+ currentDir = (0, import_path.dirname)(currentDir);
43
+ }
44
+ return void 0;
45
+ }
46
+ function getWorkspacePackages(workspaceRoot) {
47
+ const packageMap = /* @__PURE__ */ new Map();
48
+ const workspaceFile = (0, import_fs.readFileSync)((0, import_path.join)(workspaceRoot, "pnpm-workspace.yaml"), "utf-8");
49
+ const patterns = workspaceFile.split("\n").filter((line) => line.trim().startsWith("-")).map((line) => line.trim().substring(1).trim());
50
+ function findPackages(pattern) {
51
+ const parts = pattern.split("/").filter(Boolean);
52
+ const searchDirs = [workspaceRoot];
53
+ for (const part of parts) {
54
+ const newDirs = [];
55
+ for (const searchDir of searchDirs) {
56
+ if (part === "*") {
57
+ try {
58
+ const entries = (0, import_fs.readdirSync)(searchDir, { withFileTypes: true });
59
+ for (const entry of entries) {
60
+ if (entry.isDirectory()) {
61
+ newDirs.push((0, import_path.join)(searchDir, entry.name));
62
+ }
63
+ }
64
+ } catch {
65
+ }
66
+ } else if (part.includes("*")) {
67
+ try {
68
+ const entries = (0, import_fs.readdirSync)(searchDir, { withFileTypes: true });
69
+ const regex = new RegExp("^" + part.replace(/\*/g, ".*") + "$");
70
+ for (const entry of entries) {
71
+ if (entry.isDirectory() && regex.test(entry.name)) {
72
+ newDirs.push((0, import_path.join)(searchDir, entry.name));
73
+ }
74
+ }
75
+ } catch {
76
+ }
77
+ } else {
78
+ const literalPath = (0, import_path.join)(searchDir, part);
79
+ if ((0, import_fs.existsSync)(literalPath)) {
80
+ newDirs.push(literalPath);
81
+ }
82
+ }
83
+ }
84
+ searchDirs.length = 0;
85
+ searchDirs.push(...newDirs);
86
+ }
87
+ for (const dir of searchDirs) {
88
+ const packageJsonPath = (0, import_path.join)(dir, "package.json");
89
+ try {
90
+ if ((0, import_fs.statSync)(packageJsonPath).isFile()) {
91
+ const packageJson = JSON.parse((0, import_fs.readFileSync)(packageJsonPath, "utf-8"));
92
+ if (typeof packageJson?.name === "string") {
93
+ packageMap.set(packageJson.name, dir);
94
+ }
95
+ }
96
+ } catch {
97
+ }
98
+ }
99
+ }
100
+ for (const pattern of patterns) {
101
+ findPackages(pattern);
102
+ }
103
+ return packageMap;
104
+ }
105
+ function workspacePathsPlugin(options = {}) {
106
+ const workspaceRoot = findWorkspaceRoot(process.cwd());
107
+ if (!workspaceRoot) {
108
+ return {
109
+ name: "workspace-paths"
110
+ };
111
+ }
112
+ const packages = getWorkspacePackages(workspaceRoot);
113
+ return {
114
+ name: "workspace-paths",
115
+ config(config) {
116
+ const alias = {};
117
+ if (options.appSrcPath) {
118
+ alias["~"] = options.appSrcPath;
119
+ }
120
+ for (const [name, path] of packages.entries()) {
121
+ alias[name] = (0, import_path.resolve)(path, "src");
122
+ }
123
+ if (!config.resolve) {
124
+ config.resolve = {};
125
+ }
126
+ if (!config.resolve.alias) {
127
+ config.resolve.alias = {};
128
+ }
129
+ Object.assign(config.resolve.alias, alias);
130
+ }
131
+ };
132
+ }
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ workspacePathsPlugin
136
+ });
137
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/workspacePathsPlugin.ts"],"sourcesContent":["export { default as workspacePathsPlugin } from './workspacePathsPlugin.js';\n","import { readFileSync, statSync, readdirSync, existsSync } from 'fs';\nimport { join, dirname, resolve } from 'path';\n\nimport type { Plugin } from 'vite';\n\nfunction findWorkspaceRoot(startPath: string): string | undefined {\n let currentDir = startPath;\n const rootDir = '/';\n\n while (currentDir !== rootDir) {\n const workspaceFile = join(currentDir, 'pnpm-workspace.yaml');\n try {\n const stats = statSync(workspaceFile);\n if (stats.isFile()) {\n return currentDir;\n }\n } catch {\n // Continue searching\n }\n currentDir = dirname(currentDir);\n }\n\n return undefined;\n}\n\nfunction getWorkspacePackages(workspaceRoot: string): Map<string, string> {\n const packageMap = new Map<string, string>();\n const workspaceFile = readFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), 'utf-8');\n\n // Simple pattern matching for workspace packages\n const patterns = workspaceFile\n .split('\\n')\n .filter((line) => line.trim().startsWith('-'))\n .map((line) => line.trim().substring(1).trim());\n\n function findPackages(pattern: string): void {\n // Convert glob pattern to directory traversal\n // Patterns like \"apps/*\" or \"libs/*/*\" become directory searches\n const parts = pattern.split('/').filter(Boolean);\n const searchDirs: string[] = [workspaceRoot];\n\n for (const part of parts) {\n const newDirs: string[] = [];\n for (const searchDir of searchDirs) {\n if (part === '*') {\n // Single level wildcard\n try {\n const entries = readdirSync(searchDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n newDirs.push(join(searchDir, entry.name));\n }\n }\n } catch {\n // Skip if can't read\n }\n } else if (part.includes('*')) {\n // Pattern matching (simple implementation)\n try {\n const entries = readdirSync(searchDir, { withFileTypes: true });\n const regex = new RegExp('^' + part.replace(/\\*/g, '.*') + '$');\n for (const entry of entries) {\n if (entry.isDirectory() && regex.test(entry.name)) {\n newDirs.push(join(searchDir, entry.name));\n }\n }\n } catch {\n // Skip if can't read\n }\n } else {\n // Literal directory\n const literalPath = join(searchDir, part);\n if (existsSync(literalPath)) {\n newDirs.push(literalPath);\n }\n }\n }\n searchDirs.length = 0;\n searchDirs.push(...newDirs);\n }\n\n // Check each found directory for package.json\n for (const dir of searchDirs) {\n const packageJsonPath = join(dir, 'package.json');\n try {\n if (statSync(packageJsonPath).isFile()) {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {\n name?: string;\n };\n if (typeof packageJson?.name === 'string') {\n packageMap.set(packageJson.name, dir);\n }\n }\n } catch {\n // Skip invalid packages\n }\n }\n }\n\n for (const pattern of patterns) {\n findPackages(pattern);\n }\n\n return packageMap;\n}\n\ninterface WorkspacePathsPluginOptions {\n appSrcPath?: string;\n}\n\nexport default function workspacePathsPlugin(options: WorkspacePathsPluginOptions = {}): Plugin {\n const workspaceRoot = findWorkspaceRoot(process.cwd());\n if (!workspaceRoot) {\n return {\n name: 'workspace-paths',\n };\n }\n\n const packages = getWorkspacePackages(workspaceRoot);\n\n return {\n name: 'workspace-paths',\n config(config) {\n const alias: Record<string, string> = {};\n\n // Add ~/ alias if appSrcPath is provided\n if (options.appSrcPath) {\n alias['~'] = options.appSrcPath;\n }\n\n // Add workspace package aliases\n for (const [name, path] of packages.entries()) {\n alias[name] = resolve(path, 'src');\n }\n\n if (!config.resolve) {\n config.resolve = {};\n }\n if (!config.resolve.alias) {\n config.resolve.alias = {};\n }\n\n Object.assign(config.resolve.alias, alias);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAAgE;AAChE,kBAAuC;AAIvC,SAAS,kBAAkB,WAAuC;AAChE,MAAI,aAAa;AACjB,QAAM,UAAU;AAEhB,SAAO,eAAe,SAAS;AAC7B,UAAM,oBAAgB,kBAAK,YAAY,qBAAqB;AAC5D,QAAI;AACF,YAAM,YAAQ,oBAAS,aAAa;AACpC,UAAI,MAAM,OAAO,GAAG;AAClB,eAAO;AAAA,MACT;AAAA,IACF,QAAQ;AAAA,IAER;AACA,qBAAa,qBAAQ,UAAU;AAAA,EACjC;AAEA,SAAO;AACT;AAEA,SAAS,qBAAqB,eAA4C;AACxE,QAAM,aAAa,oBAAI,IAAoB;AAC3C,QAAM,oBAAgB,4BAAa,kBAAK,e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IAC5B;AAGA,eAAW,OAAO,YAAY;AAC5B,YAAM,sBAAkB,kBAAK,KAAK,cAAc;AAChD,UAAI;AACF,gBAAI,oBAAS,eAAe,EAAE,OAAO,GAAG;AACtC,gBAAM,cAAc,KAAK,UAAM,wBAAa,iBAAiB,OAAO,CAAC;AAGrE,cAAI,OAAO,aAAa,SAAS,UAAU;AACzC,uBAAW,IAAI,YAAY,MAAM,GAAG;AAAA,UACtC;AAAA,QACF;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,aAAW,WAAW,UAAU;AAC9B,iBAAa,OAAO;AAAA,EACtB;AAEA,SAAO;AACT;AAMe,SAAR,qBAAsC,UAAuC,CAAC,GAAW;AAC9F,QAAM,gBAAgB,kBAAkB,QAAQ,IAAI,CAAC;AACrD,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,MACL,MAAM;AAAA,IACR;AAAA,EACF;AAEA,QAAM,WAAW,qBAAqB,aAAa;AAEnD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO,QAAQ;AACb,YAAM,QAAgC,CAAC;AAGvC,UAAI,QAAQ,YAAY;AACtB,cAAM,GAAG,IAAI,QAAQ;AAAA,MACvB;AAGA,iBAAW,CAAC,MAAM,IAAI,KAAK,SAAS,QAAQ,GAAG;AAC7C,cAAM,IAAI,QAAI,qBAAQ,MAAM,KAAK;AAAA,MACnC;AAEA,UAAI,CAAC,OAAO,SAAS;AACnB,eAAO,UAAU,CAAC;AAAA,MACpB;AACA,UAAI,CAAC,OAAO,QAAQ,OAAO;AACzB,eAAO,QAAQ,QAAQ,CAAC;AAAA,MAC1B;AAEA,aAAO,OAAO,OAAO,QAAQ,OAAO,KAAK;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface WorkspacePathsPluginOptions {
4
+ appSrcPath?: string;
5
+ }
6
+ declare function workspacePathsPlugin(options?: WorkspacePathsPluginOptions): Plugin;
7
+
8
+ export { workspacePathsPlugin };
@@ -0,0 +1,8 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface WorkspacePathsPluginOptions {
4
+ appSrcPath?: string;
5
+ }
6
+ declare function workspacePathsPlugin(options?: WorkspacePathsPluginOptions): Plugin;
7
+
8
+ export { workspacePathsPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,110 @@
1
+ // src/workspacePathsPlugin.ts
2
+ import { readFileSync, statSync, readdirSync, existsSync } from "fs";
3
+ import { join, dirname, resolve } from "path";
4
+ function findWorkspaceRoot(startPath) {
5
+ let currentDir = startPath;
6
+ const rootDir = "/";
7
+ while (currentDir !== rootDir) {
8
+ const workspaceFile = join(currentDir, "pnpm-workspace.yaml");
9
+ try {
10
+ const stats = statSync(workspaceFile);
11
+ if (stats.isFile()) {
12
+ return currentDir;
13
+ }
14
+ } catch {
15
+ }
16
+ currentDir = dirname(currentDir);
17
+ }
18
+ return void 0;
19
+ }
20
+ function getWorkspacePackages(workspaceRoot) {
21
+ const packageMap = /* @__PURE__ */ new Map();
22
+ const workspaceFile = readFileSync(join(workspaceRoot, "pnpm-workspace.yaml"), "utf-8");
23
+ const patterns = workspaceFile.split("\n").filter((line) => line.trim().startsWith("-")).map((line) => line.trim().substring(1).trim());
24
+ function findPackages(pattern) {
25
+ const parts = pattern.split("/").filter(Boolean);
26
+ const searchDirs = [workspaceRoot];
27
+ for (const part of parts) {
28
+ const newDirs = [];
29
+ for (const searchDir of searchDirs) {
30
+ if (part === "*") {
31
+ try {
32
+ const entries = readdirSync(searchDir, { withFileTypes: true });
33
+ for (const entry of entries) {
34
+ if (entry.isDirectory()) {
35
+ newDirs.push(join(searchDir, entry.name));
36
+ }
37
+ }
38
+ } catch {
39
+ }
40
+ } else if (part.includes("*")) {
41
+ try {
42
+ const entries = readdirSync(searchDir, { withFileTypes: true });
43
+ const regex = new RegExp("^" + part.replace(/\*/g, ".*") + "$");
44
+ for (const entry of entries) {
45
+ if (entry.isDirectory() && regex.test(entry.name)) {
46
+ newDirs.push(join(searchDir, entry.name));
47
+ }
48
+ }
49
+ } catch {
50
+ }
51
+ } else {
52
+ const literalPath = join(searchDir, part);
53
+ if (existsSync(literalPath)) {
54
+ newDirs.push(literalPath);
55
+ }
56
+ }
57
+ }
58
+ searchDirs.length = 0;
59
+ searchDirs.push(...newDirs);
60
+ }
61
+ for (const dir of searchDirs) {
62
+ const packageJsonPath = join(dir, "package.json");
63
+ try {
64
+ if (statSync(packageJsonPath).isFile()) {
65
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
66
+ if (typeof packageJson?.name === "string") {
67
+ packageMap.set(packageJson.name, dir);
68
+ }
69
+ }
70
+ } catch {
71
+ }
72
+ }
73
+ }
74
+ for (const pattern of patterns) {
75
+ findPackages(pattern);
76
+ }
77
+ return packageMap;
78
+ }
79
+ function workspacePathsPlugin(options = {}) {
80
+ const workspaceRoot = findWorkspaceRoot(process.cwd());
81
+ if (!workspaceRoot) {
82
+ return {
83
+ name: "workspace-paths"
84
+ };
85
+ }
86
+ const packages = getWorkspacePackages(workspaceRoot);
87
+ return {
88
+ name: "workspace-paths",
89
+ config(config) {
90
+ const alias = {};
91
+ if (options.appSrcPath) {
92
+ alias["~"] = options.appSrcPath;
93
+ }
94
+ for (const [name, path] of packages.entries()) {
95
+ alias[name] = resolve(path, "src");
96
+ }
97
+ if (!config.resolve) {
98
+ config.resolve = {};
99
+ }
100
+ if (!config.resolve.alias) {
101
+ config.resolve.alias = {};
102
+ }
103
+ Object.assign(config.resolve.alias, alias);
104
+ }
105
+ };
106
+ }
107
+ export {
108
+ workspacePathsPlugin
109
+ };
110
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/workspacePathsPlugin.ts"],"sourcesContent":["import { readFileSync, statSync, readdirSync, existsSync } from 'fs';\nimport { join, dirname, resolve } from 'path';\n\nimport type { Plugin } from 'vite';\n\nfunction findWorkspaceRoot(startPath: string): string | undefined {\n let currentDir = startPath;\n const rootDir = '/';\n\n while (currentDir !== rootDir) {\n const workspaceFile = join(currentDir, 'pnpm-workspace.yaml');\n try {\n const stats = statSync(workspaceFile);\n if (stats.isFile()) {\n return currentDir;\n }\n } catch {\n // Continue searching\n }\n currentDir = dirname(currentDir);\n }\n\n return undefined;\n}\n\nfunction getWorkspacePackages(workspaceRoot: string): Map<string, string> {\n const packageMap = new Map<string, string>();\n const workspaceFile = readFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), 'utf-8');\n\n // Simple pattern matching for workspace packages\n const patterns = workspaceFile\n .split('\\n')\n .filter((line) => line.trim().startsWith('-'))\n .map((line) => line.trim().substring(1).trim());\n\n function findPackages(pattern: string): void {\n // Convert glob pattern to directory traversal\n // Patterns like \"apps/*\" or \"libs/*/*\" become directory searches\n const parts = pattern.split('/').filter(Boolean);\n const searchDirs: string[] = [workspaceRoot];\n\n for (const part of parts) {\n const newDirs: string[] = [];\n for (const searchDir of searchDirs) {\n if (part === '*') {\n // Single level wildcard\n try {\n const entries = readdirSync(searchDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n newDirs.push(join(searchDir, entry.name));\n }\n }\n } catch {\n // Skip if can't read\n }\n } else if (part.includes('*')) {\n // Pattern matching (simple implementation)\n try {\n const entries = readdirSync(searchDir, { withFileTypes: true });\n const regex = new RegExp('^' + part.replace(/\\*/g, '.*') + '$');\n for (const entry of entries) {\n if (entry.isDirectory() && regex.test(entry.name)) {\n newDirs.push(join(searchDir, entry.name));\n }\n }\n } catch {\n // Skip if can't read\n }\n } else {\n // Literal directory\n const literalPath = join(searchDir, part);\n if (existsSync(literalPath)) {\n newDirs.push(literalPath);\n }\n }\n }\n searchDirs.length = 0;\n searchDirs.push(...newDirs);\n }\n\n // Check each found directory for package.json\n for (const dir of searchDirs) {\n const packageJsonPath = join(dir, 'package.json');\n try {\n if (statSync(packageJsonPath).isFile()) {\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {\n name?: string;\n };\n if (typeof packageJson?.name === 'string') {\n packageMap.set(packageJson.name, dir);\n }\n }\n } catch {\n // Skip invalid packages\n }\n }\n }\n\n for (const pattern of patterns) {\n findPackages(pattern);\n }\n\n return packageMap;\n}\n\ninterface WorkspacePathsPluginOptions {\n appSrcPath?: string;\n}\n\nexport default function workspacePathsPlugin(options: WorkspacePathsPluginOptions = {}): Plugin {\n const workspaceRoot = findWorkspaceRoot(process.cwd());\n if (!workspaceRoot) {\n return {\n name: 'workspace-paths',\n };\n }\n\n const packages = getWorkspacePackages(workspaceRoot);\n\n return {\n name: 'workspace-paths',\n config(config) {\n const alias: Record<string, string> = {};\n\n // Add ~/ alias if appSrcPath is provided\n if (options.appSrcPath) {\n alias['~'] = options.appSrcPath;\n }\n\n // Add workspace package aliases\n for (const [name, path] of packages.entries()) {\n alias[name] = resolve(path, 'src');\n }\n\n if (!config.resolve) {\n config.resolve = {};\n }\n if (!config.resolve.alias) {\n config.resolve.alias = {};\n }\n\n Object.assign(config.resolve.alias, alias);\n },\n };\n}\n"],"mappings":";AAAA,SAAS,cAAc,UAAU,aAAa,kBAAkB;AAChE,SAAS,MAAM,SAAS,eAAe;AAIvC,SAAS,kBAAkB,WAAuC;AAChE,MAAI,aAAa;AACjB,QAAM,UAAU;AAEhB,SAAO,eAAe,SAAS;AAC7B,UAAM,gBAAgB,KAAK,YAAY,qBAAqB;AAC5D,QAAI;AACF,YAAM,QAAQ,SAAS,aAAa;AACpC,UAAI,MAAM,OAAO,GAAG;AAClB,eAAO;AAAA,MACT;AAAA,IACF,QAAQ;AAAA,IAER;AACA,iBAAa,QAAQ,UAAU;AAAA,EACjC;AAEA,SAAO;AACT;AAEA,SAAS,qBAAqB,eAA4C;AACxE,QAAM,aAAa,oBAAI,IAAoB;AAC3C,QAAM,gBAAgB,aAAa,KAAK,eAAe,qBAAqB,GAAG,OAAO;AAGtF,QAAM,WAAW,cACd,MAAM,IAAI,EACV,OAAO,CAAC,SAAS,KAAK,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eAAe,EAAE,OAAO,GAAG;AACtC,gBAAM,cAAc,KAAK,MAAM,aAAa,iBAAiB,OAAO,CAAC;AAGrE,cAAI,OAAO,aAAa,SAAS,UAAU;AACzC,uBAAW,IAAI,YAAY,MAAM,GAAG;AAAA,UACtC;AAAA,QACF;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AAAA,EACF;AAEA,aAAW,WAAW,UAAU;AAC9B,iBAAa,OAAO;AAAA,EACtB;AAEA,SAAO;AACT;AAMe,SAAR,qBAAsC,UAAuC,CAAC,GAAW;AAC9F,QAAM,gBAAgB,kBAAkB,QAAQ,IAAI,CAAC;AACrD,MAAI,CAAC,eAAe;AAClB,WAAO;AAAA,MACL,MAAM;AAAA,IACR;AAAA,EACF;AAEA,QAAM,WAAW,qBAAqB,aAAa;AAEnD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO,QAAQ;AACb,YAAM,QAAgC,CAAC;AAGvC,UAAI,QAAQ,YAAY;AACtB,cAAM,GAAG,IAAI,QAAQ;AAAA,MACvB;AAGA,iBAAW,CAAC,MAAM,IAAI,KAAK,SAAS,QAAQ,GAAG;AAC7C,cAAM,IAAI,IAAI,QAAQ,MAAM,KAAK;AAAA,MACnC;AAEA,UAAI,CAAC,OAAO,SAAS;AACnB,eAAO,UAAU,CAAC;AAAA,MACpB;AACA,UAAI,CAAC,OAAO,QAAQ,OAAO;AACzB,eAAO,QAAQ,QAAQ,CAAC;AAAA,MAC1B;AAEA,aAAO,OAAO,OAAO,QAAQ,OAAO,KAAK;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,3 @@
1
+ import baseConfig from '@codygo-ai/eslint-config-base';
2
+
3
+ export default [...baseConfig];
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@codygo-ai/vite-tools",
3
+ "version": "0.1.0-alpha",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "peerDependencies": {
16
+ "vite": "^5.0.0 || ^6.0.0"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^22.18.6",
20
+ "tsup": "^8.0.0",
21
+ "typescript": "^5.7.2",
22
+ "vite": "^6.0.5",
23
+ "@codygo-ai/tsconfig": "^0.1.8",
24
+ "@codygo-ai/eslint-config-base": "^0.1.0-alpha"
25
+ },
26
+ "scripts": {
27
+ "build": "tsup",
28
+ "lint": "eslint . --max-warnings 0",
29
+ "typecheck": "tsc --noEmit",
30
+ "release": "node ../../../scripts/release.mjs"
31
+ }
32
+ }
@@ -0,0 +1,6 @@
1
+ # Initial Alpha Release
2
+
3
+ - Initial release of Vite tools package
4
+ - Add package configuration with lint script support
5
+ - Set up GitHub Actions release workflow
6
+ - Remove private flag to enable publishing
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as workspacePathsPlugin } from './workspacePathsPlugin.js';
@@ -0,0 +1,146 @@
1
+ import { readFileSync, statSync, readdirSync, existsSync } from 'fs';
2
+ import { join, dirname, resolve } from 'path';
3
+
4
+ import type { Plugin } from 'vite';
5
+
6
+ function findWorkspaceRoot(startPath: string): string | undefined {
7
+ let currentDir = startPath;
8
+ const rootDir = '/';
9
+
10
+ while (currentDir !== rootDir) {
11
+ const workspaceFile = join(currentDir, 'pnpm-workspace.yaml');
12
+ try {
13
+ const stats = statSync(workspaceFile);
14
+ if (stats.isFile()) {
15
+ return currentDir;
16
+ }
17
+ } catch {
18
+ // Continue searching
19
+ }
20
+ currentDir = dirname(currentDir);
21
+ }
22
+
23
+ return undefined;
24
+ }
25
+
26
+ function getWorkspacePackages(workspaceRoot: string): Map<string, string> {
27
+ const packageMap = new Map<string, string>();
28
+ const workspaceFile = readFileSync(join(workspaceRoot, 'pnpm-workspace.yaml'), 'utf-8');
29
+
30
+ // Simple pattern matching for workspace packages
31
+ const patterns = workspaceFile
32
+ .split('\n')
33
+ .filter((line) => line.trim().startsWith('-'))
34
+ .map((line) => line.trim().substring(1).trim());
35
+
36
+ function findPackages(pattern: string): void {
37
+ // Convert glob pattern to directory traversal
38
+ // Patterns like "apps/*" or "libs/*/*" become directory searches
39
+ const parts = pattern.split('/').filter(Boolean);
40
+ const searchDirs: string[] = [workspaceRoot];
41
+
42
+ for (const part of parts) {
43
+ const newDirs: string[] = [];
44
+ for (const searchDir of searchDirs) {
45
+ if (part === '*') {
46
+ // Single level wildcard
47
+ try {
48
+ const entries = readdirSync(searchDir, { withFileTypes: true });
49
+ for (const entry of entries) {
50
+ if (entry.isDirectory()) {
51
+ newDirs.push(join(searchDir, entry.name));
52
+ }
53
+ }
54
+ } catch {
55
+ // Skip if can't read
56
+ }
57
+ } else if (part.includes('*')) {
58
+ // Pattern matching (simple implementation)
59
+ try {
60
+ const entries = readdirSync(searchDir, { withFileTypes: true });
61
+ const regex = new RegExp('^' + part.replace(/\*/g, '.*') + '$');
62
+ for (const entry of entries) {
63
+ if (entry.isDirectory() && regex.test(entry.name)) {
64
+ newDirs.push(join(searchDir, entry.name));
65
+ }
66
+ }
67
+ } catch {
68
+ // Skip if can't read
69
+ }
70
+ } else {
71
+ // Literal directory
72
+ const literalPath = join(searchDir, part);
73
+ if (existsSync(literalPath)) {
74
+ newDirs.push(literalPath);
75
+ }
76
+ }
77
+ }
78
+ searchDirs.length = 0;
79
+ searchDirs.push(...newDirs);
80
+ }
81
+
82
+ // Check each found directory for package.json
83
+ for (const dir of searchDirs) {
84
+ const packageJsonPath = join(dir, 'package.json');
85
+ try {
86
+ if (statSync(packageJsonPath).isFile()) {
87
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {
88
+ name?: string;
89
+ };
90
+ if (typeof packageJson?.name === 'string') {
91
+ packageMap.set(packageJson.name, dir);
92
+ }
93
+ }
94
+ } catch {
95
+ // Skip invalid packages
96
+ }
97
+ }
98
+ }
99
+
100
+ for (const pattern of patterns) {
101
+ findPackages(pattern);
102
+ }
103
+
104
+ return packageMap;
105
+ }
106
+
107
+ interface WorkspacePathsPluginOptions {
108
+ appSrcPath?: string;
109
+ }
110
+
111
+ export default function workspacePathsPlugin(options: WorkspacePathsPluginOptions = {}): Plugin {
112
+ const workspaceRoot = findWorkspaceRoot(process.cwd());
113
+ if (!workspaceRoot) {
114
+ return {
115
+ name: 'workspace-paths',
116
+ };
117
+ }
118
+
119
+ const packages = getWorkspacePackages(workspaceRoot);
120
+
121
+ return {
122
+ name: 'workspace-paths',
123
+ config(config) {
124
+ const alias: Record<string, string> = {};
125
+
126
+ // Add ~/ alias if appSrcPath is provided
127
+ if (options.appSrcPath) {
128
+ alias['~'] = options.appSrcPath;
129
+ }
130
+
131
+ // Add workspace package aliases
132
+ for (const [name, path] of packages.entries()) {
133
+ alias[name] = resolve(path, 'src');
134
+ }
135
+
136
+ if (!config.resolve) {
137
+ config.resolve = {};
138
+ }
139
+ if (!config.resolve.alias) {
140
+ config.resolve.alias = {};
141
+ }
142
+
143
+ Object.assign(config.resolve.alias, alias);
144
+ },
145
+ };
146
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "@codygo-ai/tsconfig/node.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"]
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ format: ['esm', 'cjs'],
6
+ dts: true,
7
+ clean: true,
8
+ splitting: false,
9
+ sourcemap: true,
10
+ });