@shardev/vite-plugin-modular 1.1.0
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/LICENSE +21 -0
- package/README.md +240 -0
- package/dist/index.cjs +329 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +291 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Shardev Community
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# 🚀 @shardev/vite-plugin
|
|
2
|
+
|
|
3
|
+
> Advanced modular Laravel + Vite 7 integration system\
|
|
4
|
+
> Monorepo-ready. Namespace-aware. Production-focused.
|
|
5
|
+
|
|
6
|
+
------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
## ✨ Features
|
|
9
|
+
|
|
10
|
+
- 📦 Automatic module discovery from `packages/`
|
|
11
|
+
- 🔥 Namespace resolution (`vendor:package::file`)
|
|
12
|
+
- 🧠 Smart alias injection
|
|
13
|
+
- 🏗️ Workspace vs Published detection
|
|
14
|
+
- 📄 Manifest rewriting with namespaced keys
|
|
15
|
+
- ⚡ Compatible with **Vite 7+**
|
|
16
|
+
- 🧩 Designed for **Laravel + React + TypeScript** stacks
|
|
17
|
+
|
|
18
|
+
------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
``` bash
|
|
23
|
+
npm install @shardev/vite-plugin --save-dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
## 🔧 Requirements
|
|
29
|
+
|
|
30
|
+
- Node \>= 20
|
|
31
|
+
- Vite \^7
|
|
32
|
+
- laravel-vite-plugin \^2
|
|
33
|
+
|
|
34
|
+
------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
# 🏗 Usage
|
|
37
|
+
|
|
38
|
+
## 1️⃣ Root Project (vite.config.ts)
|
|
39
|
+
|
|
40
|
+
``` ts
|
|
41
|
+
import { defineConfig } from 'vite'
|
|
42
|
+
import laravel from 'laravel-vite-plugin'
|
|
43
|
+
import { laravelModules } from '@shardev/vite-plugin'
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
plugins: [
|
|
47
|
+
laravelModules({
|
|
48
|
+
modulesDir: "packages",
|
|
49
|
+
statusesFile: "modules.json"
|
|
50
|
+
}),
|
|
51
|
+
laravel({
|
|
52
|
+
input: [
|
|
53
|
+
'resources/css/app.css',
|
|
54
|
+
'resources/react/app.tsx'
|
|
55
|
+
],
|
|
56
|
+
refresh: true
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
## 2️⃣ Inside a Module
|
|
65
|
+
|
|
66
|
+
`packages/vendor/package/vite.config.ts`
|
|
67
|
+
|
|
68
|
+
``` ts
|
|
69
|
+
import { defineConfig } from 'vite'
|
|
70
|
+
import { laravelModule } from '@shardev/vite-plugin'
|
|
71
|
+
|
|
72
|
+
export default defineConfig({
|
|
73
|
+
plugins: [
|
|
74
|
+
laravelModule({
|
|
75
|
+
name: "package",
|
|
76
|
+
vendor: "vendor"
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
})
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
# 🧾 Using a Module in Laravel Blade
|
|
85
|
+
|
|
86
|
+
Inside your Laravel Blade view:
|
|
87
|
+
|
|
88
|
+
``` blade
|
|
89
|
+
<!DOCTYPE html>
|
|
90
|
+
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
|
91
|
+
<head>
|
|
92
|
+
<meta charset="utf-8">
|
|
93
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
94
|
+
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
95
|
+
<title>Module</title>
|
|
96
|
+
|
|
97
|
+
@viteReactRefresh
|
|
98
|
+
@vite(['shardevcom:packagemanager::index.tsx'])
|
|
99
|
+
</head>
|
|
100
|
+
<body>
|
|
101
|
+
<div id="packagesmanager"></div>
|
|
102
|
+
</body>
|
|
103
|
+
</html>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### ✅ What's happening here?
|
|
107
|
+
|
|
108
|
+
- `shardevcom:packagemanager::index.tsx`\
|
|
109
|
+
Uses the namespace format:
|
|
110
|
+
|
|
111
|
+
vendor:package::file
|
|
112
|
+
|
|
113
|
+
- The plugin resolves automatically to:
|
|
114
|
+
|
|
115
|
+
packages/shardevcom/packagemanager/resources/react/src/index.tsx
|
|
116
|
+
|
|
117
|
+
Or to the published path if it exists.
|
|
118
|
+
|
|
119
|
+
This allows clean, modular asset loading directly from Blade without
|
|
120
|
+
manual path management.
|
|
121
|
+
|
|
122
|
+
------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
# 📂 Recommended Project Structure
|
|
125
|
+
|
|
126
|
+
project-root/
|
|
127
|
+
│
|
|
128
|
+
├─ packages/
|
|
129
|
+
│ └─ vendor/
|
|
130
|
+
│ └─ package/
|
|
131
|
+
│ ├─ resources/react/src/
|
|
132
|
+
│ └─ vite.config.ts
|
|
133
|
+
│
|
|
134
|
+
├─ resources/
|
|
135
|
+
├─ modules.json
|
|
136
|
+
└─ vite.config.ts
|
|
137
|
+
|
|
138
|
+
------------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
# 📑 modules.json
|
|
141
|
+
|
|
142
|
+
Enable or disable modules easily:
|
|
143
|
+
|
|
144
|
+
``` json
|
|
145
|
+
{
|
|
146
|
+
"vendor/package": true,
|
|
147
|
+
"vendor/other-module": false
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
------------------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
# 🧠 How It Works
|
|
154
|
+
|
|
155
|
+
### 🔍 Module Discovery
|
|
156
|
+
|
|
157
|
+
- Scans `packages/`
|
|
158
|
+
- Loads each module's `vite.config.ts`
|
|
159
|
+
- Extracts metadata from `laravelModule()`
|
|
160
|
+
|
|
161
|
+
------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
### 🧩 Namespace Imports
|
|
164
|
+
|
|
165
|
+
You can reference files like:
|
|
166
|
+
|
|
167
|
+
vendor:package::components/Button.tsx
|
|
168
|
+
|
|
169
|
+
The plugin resolves automatically to:
|
|
170
|
+
|
|
171
|
+
packages/vendor/package/resources/react/src/components/Button.tsx
|
|
172
|
+
|
|
173
|
+
Or the published path if available.
|
|
174
|
+
|
|
175
|
+
------------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
### 📄 Manifest Enhancement
|
|
178
|
+
|
|
179
|
+
The plugin rewrites `manifest.json` and injects:
|
|
180
|
+
|
|
181
|
+
vendor:package::file.tsx
|
|
182
|
+
|
|
183
|
+
So Laravel can resolve namespaced assets cleanly.
|
|
184
|
+
|
|
185
|
+
------------------------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
# ⚙ API
|
|
188
|
+
|
|
189
|
+
## laravelModules(options)
|
|
190
|
+
|
|
191
|
+
Option Type Default
|
|
192
|
+
-------------- -------- ----------------
|
|
193
|
+
modulesDir string "packages"
|
|
194
|
+
statusesFile string "modules.json"
|
|
195
|
+
|
|
196
|
+
------------------------------------------------------------------------
|
|
197
|
+
|
|
198
|
+
## laravelModule(options)
|
|
199
|
+
|
|
200
|
+
Option Type Default
|
|
201
|
+
-------------- ------------ ------------------------
|
|
202
|
+
name string required
|
|
203
|
+
vendor string "shardevcom"
|
|
204
|
+
srcDir string "resources/react/src"
|
|
205
|
+
inputs string\[\] \["main.tsx"\]
|
|
206
|
+
buildDir string build/{vendor}/{name}
|
|
207
|
+
publishedDir string resources/react/{name}
|
|
208
|
+
|
|
209
|
+
------------------------------------------------------------------------
|
|
210
|
+
|
|
211
|
+
# 🛠 Development
|
|
212
|
+
|
|
213
|
+
``` bash
|
|
214
|
+
npm run build
|
|
215
|
+
npm run dev
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
------------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
# 📜 License
|
|
221
|
+
|
|
222
|
+
MIT © Shardev Community
|
|
223
|
+
|
|
224
|
+
------------------------------------------------------------------------
|
|
225
|
+
|
|
226
|
+
# 🔥 Vision
|
|
227
|
+
|
|
228
|
+
This plugin is designed to evolve into a **modular frontend framework
|
|
229
|
+
layer for Laravel**.
|
|
230
|
+
|
|
231
|
+
It enables:
|
|
232
|
+
|
|
233
|
+
- Enterprise module isolation
|
|
234
|
+
- Frontend domain separation
|
|
235
|
+
- Scalable monorepo architecture
|
|
236
|
+
- Clean namespace asset resolution
|
|
237
|
+
|
|
238
|
+
------------------------------------------------------------------------
|
|
239
|
+
|
|
240
|
+
Made with ❤️ for scalable Laravel systems.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
laravelModule: () => laravelModule,
|
|
34
|
+
laravelModules: () => laravelModules
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// src/laravelModule.ts
|
|
39
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
40
|
+
var import_path = __toESM(require("path"), 1);
|
|
41
|
+
function laravelModule(options) {
|
|
42
|
+
return {
|
|
43
|
+
name: `vite-plugin-laravel-module:${options.name}`,
|
|
44
|
+
config: () => {
|
|
45
|
+
const {
|
|
46
|
+
name,
|
|
47
|
+
vendor = "shardevcom",
|
|
48
|
+
srcDir = "resources/react/src",
|
|
49
|
+
inputs = ["main.tsx"],
|
|
50
|
+
buildDir = `build/${vendor}/${name}`,
|
|
51
|
+
publishedDir = `resources/react/${name}`
|
|
52
|
+
} = options;
|
|
53
|
+
const moduleRoot = import_path.default.resolve(`packages/${vendor}/${name}`);
|
|
54
|
+
const isModuleRoot = process.cwd() === moduleRoot;
|
|
55
|
+
const inputPaths = {};
|
|
56
|
+
inputs.forEach((file) => {
|
|
57
|
+
const key = import_path.default.parse(file).name;
|
|
58
|
+
inputPaths[key] = import_path.default.resolve(moduleRoot, srcDir, file);
|
|
59
|
+
});
|
|
60
|
+
const publishedPath = import_path.default.resolve(publishedDir);
|
|
61
|
+
const isPublished = import_fs.default.existsSync(publishedPath);
|
|
62
|
+
if (isModuleRoot) {
|
|
63
|
+
return {
|
|
64
|
+
build: {
|
|
65
|
+
outDir: buildDir,
|
|
66
|
+
emptyOutDir: true,
|
|
67
|
+
rollupOptions: {
|
|
68
|
+
input: inputPaths
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
resolve: {
|
|
72
|
+
alias: {
|
|
73
|
+
[`@${vendor}/${name}`]: import_path.default.resolve(srcDir)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
shardevModule: JSON.stringify({
|
|
80
|
+
...options,
|
|
81
|
+
srcDir,
|
|
82
|
+
input: isPublished ? void 0 : inputPaths,
|
|
83
|
+
usePublished: isPublished,
|
|
84
|
+
alias: {
|
|
85
|
+
[`@${vendor}/${name}`]: isPublished ? publishedPath : import_path.default.resolve(moduleRoot, srcDir)
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
resolve: {
|
|
89
|
+
alias: {
|
|
90
|
+
[`@${vendor}/${name}`]: isPublished ? publishedPath : import_path.default.resolve(moduleRoot, srcDir)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/laravelModules.ts
|
|
99
|
+
var import_vite = require("vite");
|
|
100
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
101
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
102
|
+
function laravelModules(options = {}) {
|
|
103
|
+
const { modulesDir = "packages", statusesFile = "modules.json" } = options;
|
|
104
|
+
const modulesPath = import_path2.default.resolve(process.cwd(), modulesDir);
|
|
105
|
+
const statusesPath = import_path2.default.resolve(process.cwd(), statusesFile);
|
|
106
|
+
const root = process.cwd();
|
|
107
|
+
const findLaravelPlugin = (plugins) => {
|
|
108
|
+
const flattenPlugins = (plugins2) => {
|
|
109
|
+
return plugins2.flatMap((plugin) => {
|
|
110
|
+
if (Array.isArray(plugin)) {
|
|
111
|
+
return flattenPlugins(plugin);
|
|
112
|
+
}
|
|
113
|
+
return plugin && typeof plugin === "object" && "name" in plugin ? [plugin] : [];
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const flatPlugins = flattenPlugins(plugins);
|
|
117
|
+
return flatPlugins.find((plugin) => plugin?.name === "laravel") ?? null;
|
|
118
|
+
};
|
|
119
|
+
const normalizePath = (id) => {
|
|
120
|
+
let cleanPath = id.replace(/^[\/\\]+/, "").split("?")[0].split("#")[0];
|
|
121
|
+
cleanPath = cleanPath.replace(/\\/g, "/");
|
|
122
|
+
const normalizedRoot = root.replace(/\\/g, "/");
|
|
123
|
+
if (cleanPath.startsWith(normalizedRoot)) {
|
|
124
|
+
cleanPath = cleanPath.slice(normalizedRoot.length).replace(/^\/+/, "");
|
|
125
|
+
}
|
|
126
|
+
return cleanPath;
|
|
127
|
+
};
|
|
128
|
+
const parseNamespace = (id) => {
|
|
129
|
+
const cleanPath = normalizePath(id);
|
|
130
|
+
const patterns = [
|
|
131
|
+
/^([\w.-]+):([\w.-]+)::(.+)$/,
|
|
132
|
+
// vendor:pkg::file
|
|
133
|
+
/^packages\/([^/]+)\/([^/]+)\/resources\/react\/src\/(.+)$/,
|
|
134
|
+
// packages/vendor/pkg/resources/react/src/file
|
|
135
|
+
/^resources\/react\/([^/]+)\/([^/]+)\/src\/(.+)$/
|
|
136
|
+
// resources/react/vendor/pkg/src/file
|
|
137
|
+
];
|
|
138
|
+
for (const pattern of patterns) {
|
|
139
|
+
const match = cleanPath.match(pattern);
|
|
140
|
+
if (match) {
|
|
141
|
+
return { vendor: match[1], pkg: match[2], file: match[3] };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
};
|
|
146
|
+
const resolveNamespacedToFs = (vendor, pkg, file) => {
|
|
147
|
+
const paths = [
|
|
148
|
+
import_path2.default.join(root, "resources", "react", vendor, pkg, "src", file),
|
|
149
|
+
// Published path
|
|
150
|
+
import_path2.default.join(root, "packages", vendor, pkg, "resources", "react", "src", file)
|
|
151
|
+
// Workspace path
|
|
152
|
+
];
|
|
153
|
+
return paths.find(import_fs2.default.existsSync) || null;
|
|
154
|
+
};
|
|
155
|
+
const loadModuleStatuses = () => {
|
|
156
|
+
try {
|
|
157
|
+
if (import_fs2.default.existsSync(statusesPath)) {
|
|
158
|
+
return JSON.parse(import_fs2.default.readFileSync(statusesPath, "utf-8"));
|
|
159
|
+
}
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.warn("[laravel-modules] Failed to load module statuses:", error);
|
|
162
|
+
}
|
|
163
|
+
return {};
|
|
164
|
+
};
|
|
165
|
+
const getInputArray = (input) => {
|
|
166
|
+
return Array.isArray(input) ? input : Object.values(input || {});
|
|
167
|
+
};
|
|
168
|
+
const discoverModules = async (statuses) => {
|
|
169
|
+
if (!import_fs2.default.existsSync(modulesPath)) return [];
|
|
170
|
+
const plugins = [];
|
|
171
|
+
const vendors = import_fs2.default.readdirSync(modulesPath, { withFileTypes: true }).filter((dirent) => dirent.isDirectory());
|
|
172
|
+
for (const vendor of vendors) {
|
|
173
|
+
const vendorPath = import_path2.default.join(modulesPath, vendor.name);
|
|
174
|
+
const packages = import_fs2.default.readdirSync(vendorPath, { withFileTypes: true }).filter((dirent) => dirent.isDirectory() && statuses[dirent.name] !== false);
|
|
175
|
+
for (const pkg of packages) {
|
|
176
|
+
const pkgPath = import_path2.default.join(vendorPath, pkg.name);
|
|
177
|
+
const viteConfigPath = import_path2.default.join(pkgPath, "vite.config.ts");
|
|
178
|
+
if (!import_fs2.default.existsSync(viteConfigPath)) continue;
|
|
179
|
+
try {
|
|
180
|
+
const server = await (0, import_vite.createServer)({
|
|
181
|
+
configFile: viteConfigPath,
|
|
182
|
+
logLevel: "silent"
|
|
183
|
+
});
|
|
184
|
+
plugins.push(...server.config.plugins);
|
|
185
|
+
await server.close();
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.warn(`[laravel-modules] Error loading ${viteConfigPath}:`, error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return plugins;
|
|
192
|
+
};
|
|
193
|
+
const extractModuleMetadata = (plugins) => {
|
|
194
|
+
const aliases = {};
|
|
195
|
+
const moduleConfigs = [];
|
|
196
|
+
plugins.forEach((plugin) => {
|
|
197
|
+
if (!plugin?.name?.startsWith("vite-plugin-laravel-module:")) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
let resolvedConfig;
|
|
201
|
+
if (typeof plugin.config === "function") {
|
|
202
|
+
const fn = plugin.config;
|
|
203
|
+
resolvedConfig = fn({});
|
|
204
|
+
}
|
|
205
|
+
if (!resolvedConfig?.shardevModule) return;
|
|
206
|
+
try {
|
|
207
|
+
const meta = JSON.parse(resolvedConfig?.shardevModule);
|
|
208
|
+
if (meta.alias) Object.assign(aliases, meta.alias);
|
|
209
|
+
if (!meta.usePublished && meta.input) moduleConfigs.push(meta);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.warn("[laravel-modules] Failed to parse module metadata:", error);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
return { aliases, moduleConfigs };
|
|
215
|
+
};
|
|
216
|
+
const generateRollupInputs = (moduleConfigs) => {
|
|
217
|
+
const inputs = {};
|
|
218
|
+
moduleConfigs.forEach((mod) => {
|
|
219
|
+
const modInputs = getInputArray(mod.input);
|
|
220
|
+
modInputs.forEach((inputPath, idx) => {
|
|
221
|
+
const name = modInputs.length > 1 ? `${mod.name}-${idx}` : mod.name;
|
|
222
|
+
inputs[name] = inputPath;
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
return inputs;
|
|
226
|
+
};
|
|
227
|
+
function getLaravelResolvedConfig(plugin, config, env) {
|
|
228
|
+
if (!plugin.config || typeof plugin.config !== "function") return null;
|
|
229
|
+
try {
|
|
230
|
+
const fn = plugin.config;
|
|
231
|
+
const result = fn(config, env);
|
|
232
|
+
return result && typeof result === "object" ? result : null;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
console.warn("[laravel-modules] Failed to get Laravel config:", error);
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function extractAliases(config) {
|
|
239
|
+
const alias = config?.resolve?.alias;
|
|
240
|
+
if (!alias) return {};
|
|
241
|
+
if (Array.isArray(alias)) {
|
|
242
|
+
return alias.reduce((acc, item) => {
|
|
243
|
+
if (item && typeof item.find === "string" && typeof item.replacement === "string") {
|
|
244
|
+
acc[item.find] = item.replacement;
|
|
245
|
+
}
|
|
246
|
+
return acc;
|
|
247
|
+
}, {});
|
|
248
|
+
}
|
|
249
|
+
if (typeof alias === "object") {
|
|
250
|
+
return { ...alias };
|
|
251
|
+
}
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
name: "laravel-modules",
|
|
256
|
+
async config(config, env) {
|
|
257
|
+
const statuses = loadModuleStatuses();
|
|
258
|
+
const modules = await discoverModules(statuses);
|
|
259
|
+
const aliases = {};
|
|
260
|
+
const moduleConfigs = [];
|
|
261
|
+
const laravelPlugin = findLaravelPlugin(config.plugins || []);
|
|
262
|
+
if (laravelPlugin && laravelPlugin?.config) {
|
|
263
|
+
try {
|
|
264
|
+
const laravelConfig = getLaravelResolvedConfig(laravelPlugin, config, env);
|
|
265
|
+
if (!laravelConfig) throw new Error("Invalid Laravel config");
|
|
266
|
+
moduleConfigs.push({
|
|
267
|
+
name: "main",
|
|
268
|
+
input: getInputArray(laravelConfig?.build?.rollupOptions?.input || []),
|
|
269
|
+
buildDir: laravelConfig?.build?.buildDir || "build",
|
|
270
|
+
alias: extractAliases(laravelConfig)
|
|
271
|
+
});
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.warn("[laravel-modules] Failed to extract Laravel plugin config:", error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const { aliases: moduleAliases, moduleConfigs: extractedConfigs } = extractModuleMetadata(modules);
|
|
277
|
+
Object.assign(aliases, moduleAliases);
|
|
278
|
+
moduleConfigs.push(...extractedConfigs);
|
|
279
|
+
const rollupInputs = generateRollupInputs(moduleConfigs);
|
|
280
|
+
return (0, import_vite.mergeConfig)(config, {
|
|
281
|
+
resolve: {
|
|
282
|
+
alias: aliases
|
|
283
|
+
},
|
|
284
|
+
build: {
|
|
285
|
+
rollupOptions: {
|
|
286
|
+
input: rollupInputs
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
resolveId(source) {
|
|
292
|
+
const ns = parseNamespace(source);
|
|
293
|
+
if (!ns) return null;
|
|
294
|
+
const resolved = resolveNamespacedToFs(ns.vendor, ns.pkg, ns.file);
|
|
295
|
+
if (resolved) return resolved;
|
|
296
|
+
return null;
|
|
297
|
+
},
|
|
298
|
+
writeBundle(_, bundle) {
|
|
299
|
+
const manifestFile = Object.keys(bundle).find((f) => f === "manifest.json");
|
|
300
|
+
if (!manifestFile) return;
|
|
301
|
+
const asset = bundle[manifestFile];
|
|
302
|
+
if (asset?.type !== "asset" || typeof asset.source !== "string") return;
|
|
303
|
+
try {
|
|
304
|
+
const manifest = JSON.parse(asset.source);
|
|
305
|
+
const rewritten = { ...manifest };
|
|
306
|
+
for (const [src, data] of Object.entries(manifest)) {
|
|
307
|
+
const ns = parseNamespace(src);
|
|
308
|
+
if (ns) {
|
|
309
|
+
const aliasKey = `${ns.vendor}:${ns.pkg}::${ns.file}`;
|
|
310
|
+
rewritten[aliasKey] = data;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
asset.source = JSON.stringify(rewritten, null, 2);
|
|
314
|
+
const outDir = _.dir || import_path2.default.dirname(_.file || "");
|
|
315
|
+
const outPath = import_path2.default.join(outDir, manifestFile);
|
|
316
|
+
import_fs2.default.writeFileSync(outPath, asset.source, "utf-8");
|
|
317
|
+
console.log("[laravel-modules] Manifest namespaced keys injected");
|
|
318
|
+
} catch (error) {
|
|
319
|
+
console.warn("[laravel-modules] Failed to process manifest:", error);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
325
|
+
0 && (module.exports = {
|
|
326
|
+
laravelModule,
|
|
327
|
+
laravelModules
|
|
328
|
+
});
|
|
329
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/laravelModule.ts","../src/laravelModules.ts"],"sourcesContent":["export { default as laravelModule } from './laravelModule';\r\nexport { default as laravelModules } from './laravelModules';","import fs from 'fs';\nimport path from 'path';\nimport type { PluginOption } from 'vite';\n\ninterface ModuleOptions {\n name: string;\n vendor?: string;\n srcDir?: string;\n inputs?: string[];\n buildDir?: string;\n publishedDir?: string;\n}\n\nexport default function laravelModule(options: ModuleOptions): PluginOption {\n return {\n name: `vite-plugin-laravel-module:${options.name}`,\n config: () => {\n const {\n name,\n vendor = 'shardevcom',\n srcDir = 'resources/react/src',\n inputs = ['main.tsx'],\n buildDir = `build/${vendor}/${name}`,\n publishedDir = `resources/react/${name}`\n } = options;\n\n const moduleRoot = path.resolve(`packages/${vendor}/${name}`);\n const isModuleRoot = process.cwd() === moduleRoot;\n\n const inputPaths: Record<string, string> = {};\n inputs.forEach((file) => {\n const key = path.parse(file).name;\n inputPaths[key] = path.resolve(moduleRoot, srcDir, file);\n });\n\n const publishedPath = path.resolve(publishedDir);\n const isPublished = fs.existsSync(publishedPath);\n\n if (isModuleRoot) {\n return {\n build: {\n outDir: buildDir,\n emptyOutDir: true,\n rollupOptions: {\n input: inputPaths\n }\n },\n resolve: {\n alias: {\n [`@${vendor}/${name}`]: path.resolve(srcDir)\n }\n }\n };\n }\n\n return {\n shardevModule: JSON.stringify({\n ...options,\n srcDir,\n input: isPublished ? undefined : inputPaths,\n usePublished: isPublished,\n alias: {\n [`@${vendor}/${name}`]: isPublished ? publishedPath : path.resolve(moduleRoot, srcDir)\n }\n }),\n resolve: {\n alias: {\n [`@${vendor}/${name}`]: isPublished ? publishedPath : path.resolve(moduleRoot, srcDir)\n }\n }\n };\n }\n };\n}\n","import type { Plugin, UserConfig, PluginOption, ConfigEnv } from 'vite';\nimport { mergeConfig, createServer } from 'vite';\nimport path from 'path';\nimport fs from 'fs';\n\ninterface LaravelModulesOptions {\n modulesDir?: string;\n statusesFile?: string;\n}\n\ninterface ModuleConfigMeta {\n name: string;\n input: string[];\n buildDir: string;\n alias?: Record<string, string>;\n usePublished?: boolean;\n}\n\ninterface ParsedNamespace {\n vendor: string;\n pkg: string;\n file: string;\n}\n\nexport interface ShardevUserConfig extends UserConfig {\n shardevModule?: string; // JSON.stringify(ModuleConfigMeta)\n}\n\ninterface LaravelResolvedConfig {\n build?: {\n rollupOptions?: {\n input?: string[] | Record<string, string>;\n };\n buildDir?: string;\n };\n resolve?: {\n alias?: Record<string, string> | Array<{ find: string | RegExp, replacement: string }>;\n };\n}\n\ninterface ModuleDiscoveryResult {\n aliases: Record<string, string>;\n moduleConfigs: ModuleConfigMeta[];\n}\n\n/**\n * Laravel Modules Plugin for Vite\n *\n * This plugin enables Vite to work with Laravel modules by:\n * 1. Discovering and loading module configurations\n * 2. Resolving module-specific aliases\n * 3. Handling namespace resolution for modules\n * 4. Processing manifest files for proper asset handling\n */\nexport default function laravelModules(options: LaravelModulesOptions = {}): Plugin {\n const { modulesDir = 'packages', statusesFile = 'modules.json' } = options;\n const modulesPath = path.resolve(process.cwd(), modulesDir);\n const statusesPath = path.resolve(process.cwd(), statusesFile);\n const root = process.cwd();\n\n /**\n * Finds the Laravel plugin instance within the main Vite config\n */\n const findLaravelPlugin = (plugins: PluginOption[]): Plugin | null => {\n const flattenPlugins = (plugins: PluginOption[]): Plugin[] => {\n return plugins.flatMap(plugin => {\n if (Array.isArray(plugin)) {\n return flattenPlugins(plugin);\n }\n return plugin && typeof plugin === 'object' && 'name' in plugin ? [plugin] : [];\n });\n };\n\n const flatPlugins = flattenPlugins(plugins);\n return flatPlugins.find(plugin => plugin?.name === 'laravel') ?? null;\n };\n\n /**\n * Normalizes path by removing query/hash and standardizing separators\n */\n const normalizePath = (id: string): string => {\n // Remove query/hash and leading slashes\n let cleanPath = id.replace(/^[\\/\\\\]+/, '').split('?')[0].split('#')[0];\n\n // Normalize separators to forward slashes\n cleanPath = cleanPath.replace(/\\\\/g, '/');\n\n // Remove root prefix if present\n const normalizedRoot = root.replace(/\\\\/g, '/');\n if (cleanPath.startsWith(normalizedRoot)) {\n cleanPath = cleanPath.slice(normalizedRoot.length).replace(/^\\/+/, '');\n }\n\n return cleanPath;\n };\n\n /**\n * Parses namespace from path using multiple patterns\n */\n const parseNamespace = (id: string): ParsedNamespace | null => {\n const cleanPath = normalizePath(id);\n\n const patterns = [\n /^([\\w.-]+):([\\w.-]+)::(.+)$/, // vendor:pkg::file\n /^packages\\/([^/]+)\\/([^/]+)\\/resources\\/react\\/src\\/(.+)$/, // packages/vendor/pkg/resources/react/src/file\n /^resources\\/react\\/([^/]+)\\/([^/]+)\\/src\\/(.+)$/ // resources/react/vendor/pkg/src/file\n ];\n\n for (const pattern of patterns) {\n const match = cleanPath.match(pattern);\n if (match) {\n return { vendor: match[1], pkg: match[2], file: match[3] };\n }\n }\n\n return null;\n };\n\n /**\n * Resolves namespace to filesystem path\n */\n const resolveNamespacedToFs = (vendor: string, pkg: string, file: string): string | null => {\n const paths = [\n path.join(root, 'resources', 'react', vendor, pkg, 'src', file), // Published path\n path.join(root, 'packages', vendor, pkg, 'resources', 'react', 'src', file) // Workspace path\n ];\n\n return paths.find(fs.existsSync) || null;\n };\n\n /**\n * Loads module activation statuses from JSON file\n */\n const loadModuleStatuses = (): Record<string, boolean> => {\n try {\n if (fs.existsSync(statusesPath)) {\n return JSON.parse(fs.readFileSync(statusesPath, 'utf-8'));\n }\n } catch (error) {\n console.warn('[laravel-modules] Failed to load module statuses:', error);\n }\n\n return {};\n };\n\n /**\n * Extracts input array from various input formats\n */\n const getInputArray = (input: string[] | Record<string, string>): string[] => {\n return Array.isArray(input) ? input : Object.values(input || {});\n };\n\n /**\n * Discovers all active modules with a vite.config.* file\n */\n const discoverModules = async (statuses: Record<string, boolean>): Promise<Plugin[]> => {\n if (!fs.existsSync(modulesPath)) return [];\n\n const plugins: Plugin[] = [];\n const vendors = fs.readdirSync(modulesPath, { withFileTypes: true })\n .filter(dirent => dirent.isDirectory());\n\n for (const vendor of vendors) {\n const vendorPath = path.join(modulesPath, vendor.name);\n const packages = fs.readdirSync(vendorPath, { withFileTypes: true })\n .filter(dirent => dirent.isDirectory() && (statuses[dirent.name] !== false));\n\n for (const pkg of packages) {\n const pkgPath = path.join(vendorPath, pkg.name);\n const viteConfigPath = path.join(pkgPath, 'vite.config.ts');\n\n if (!fs.existsSync(viteConfigPath)) continue;\n\n try {\n const server = await createServer({\n configFile: viteConfigPath,\n logLevel: 'silent'\n });\n\n // 🚨 Aquí capturamos los plugins del módulo\n plugins.push(...(server.config.plugins as Plugin[]));\n await server.close();\n } catch (error) {\n console.warn(`[laravel-modules] Error loading ${viteConfigPath}:`, error);\n }\n }\n }\n\n return plugins;\n };\n\n\n /**\n * Extracts module metadata from plugins\n */\n const extractModuleMetadata = (plugins: Plugin[]): ModuleDiscoveryResult => {\n const aliases: Record<string, string> = {};\n const moduleConfigs: ModuleConfigMeta[] = [];\n\n plugins.forEach(plugin => {\n\n if (!plugin?.name?.startsWith(\"vite-plugin-laravel-module:\")) {\n return;\n }\n\n let resolvedConfig: ShardevUserConfig | undefined;\n if (typeof plugin.config === \"function\") {\n const fn = plugin.config as (config: ShardevUserConfig, env?: ConfigEnv) => ShardevUserConfig;\n resolvedConfig = fn({}) as ShardevUserConfig;\n }\n\n if (!resolvedConfig?.shardevModule) return;\n\n try {\n const meta: ModuleConfigMeta = JSON.parse(resolvedConfig?.shardevModule);\n if (meta.alias) Object.assign(aliases, meta.alias);\n if (!meta.usePublished && meta.input) moduleConfigs.push(meta);\n } catch (error) {\n console.warn('[laravel-modules] Failed to parse module metadata:', error);\n }\n });\n\n return { aliases, moduleConfigs };\n };\n\n /**\n * Generates rollup inputs from module configurations\n */\n const generateRollupInputs = (moduleConfigs: ModuleConfigMeta[]): Record<string, string> => {\n const inputs: Record<string, string> = {};\n\n moduleConfigs.forEach(mod => {\n const modInputs = getInputArray(mod.input);\n modInputs.forEach((inputPath, idx) => {\n const name = modInputs.length > 1 ? `${mod.name}-${idx}` : mod.name;\n inputs[name] = inputPath;\n });\n });\n\n return inputs;\n };\n\n /**\n * Retrieves resolved Laravel configuration from the plugin\n */\n function getLaravelResolvedConfig(plugin: Plugin, config: UserConfig, env: ConfigEnv) {\n if (!plugin.config || typeof plugin.config !== 'function') return null;\n\n try {\n const fn = plugin.config as (config: UserConfig, env?: ConfigEnv) => LaravelResolvedConfig;\n const result = fn(config, env) as LaravelResolvedConfig;\n return result && typeof result === 'object' ? result : null;\n } catch (error) {\n console.warn('[laravel-modules] Failed to get Laravel config:', error);\n return null;\n }\n }\n\n /**\n * Extracts aliases from Laravel config\n */\n function extractAliases(config: LaravelResolvedConfig): Record<string, string> {\n const alias = config?.resolve?.alias;\n\n if (!alias) return {};\n\n if (Array.isArray(alias)) {\n // Convertir array format [{ find: 'foo', replacement: 'bar' }] to object { foo: 'bar' }\n return alias.reduce((acc, item) => {\n if (item && typeof item.find === 'string' && typeof item.replacement === 'string') {\n acc[item.find] = item.replacement;\n }\n return acc;\n }, {} as Record<string, string>);\n }\n\n if (typeof alias === 'object') {\n return { ...alias };\n }\n\n return {};\n }\n\n\n return {\n name: 'laravel-modules',\n\n async config(config: UserConfig, env) {\n const statuses = loadModuleStatuses();\n const modules = await discoverModules(statuses);\n\n const aliases: Record<string, string> = {};\n const moduleConfigs: ModuleConfigMeta[] = [];\n\n // Extract main Laravel config\n const laravelPlugin = findLaravelPlugin(config.plugins || []);\n if (laravelPlugin && laravelPlugin?.config) {\n try {\n const laravelConfig = getLaravelResolvedConfig(laravelPlugin, config, env);\n if (!laravelConfig) throw new Error('Invalid Laravel config');\n moduleConfigs.push({\n name: 'main',\n input: getInputArray(laravelConfig?.build?.rollupOptions?.input || []),\n buildDir: laravelConfig?.build?.buildDir || 'build',\n alias: extractAliases(laravelConfig)\n });\n } catch (error) {\n console.warn('[laravel-modules] Failed to extract Laravel plugin config:', error);\n }\n }\n\n // Extract module metadata\n const { aliases: moduleAliases, moduleConfigs: extractedConfigs } = extractModuleMetadata(modules);\n Object.assign(aliases, moduleAliases);\n moduleConfigs.push(...extractedConfigs);\n\n // Generate rollup inputs\n const rollupInputs = generateRollupInputs(moduleConfigs);\n\n // Merge with main config\n return mergeConfig(config, {\n resolve: {\n alias: aliases\n },\n build: {\n rollupOptions: {\n input: rollupInputs\n }\n }\n });\n },\n\n resolveId(source: string) {\n const ns = parseNamespace(source);\n if (!ns) return null;\n\n const resolved = resolveNamespacedToFs(ns.vendor, ns.pkg, ns.file);\n if (resolved) return resolved;\n\n //this.warn(`[laravel-modules] Not found: ${ns.vendor}:${ns.pkg}::${ns.file}`);\n return null;\n },\n\n writeBundle(_, bundle) {\n const manifestFile = Object.keys(bundle).find(f => f === 'manifest.json');\n if (!manifestFile) return;\n\n const asset = bundle[manifestFile];\n if (asset?.type !== 'asset' || typeof asset.source !== 'string') return;\n\n try {\n const manifest = JSON.parse(asset.source);\n const rewritten: Record<string, unknown> = { ...manifest };\n\n // Add namespaced entries\n for (const [src, data] of Object.entries<unknown>(manifest)) {\n const ns = parseNamespace(src);\n if (ns) {\n const aliasKey = `${ns.vendor}:${ns.pkg}::${ns.file}`;\n rewritten[aliasKey] = data;\n }\n }\n\n\n // Write updated manifest\n asset.source = JSON.stringify(rewritten, null, 2);\n const outDir = _.dir || path.dirname(_.file || '');\n const outPath = path.join(outDir, manifestFile);\n\n fs.writeFileSync(outPath, asset.source, 'utf-8');\n console.log('[laravel-modules] Manifest namespaced keys injected');\n } catch (error) {\n console.warn('[laravel-modules] Failed to process manifest:', error);\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gBAAe;AACf,kBAAiB;AAYF,SAAR,cAA+B,SAAsC;AACxE,SAAO;AAAA,IACH,MAAM,8BAA8B,QAAQ,IAAI;AAAA,IAChD,QAAQ,MAAM;AACV,YAAM;AAAA,QACF;AA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AAM,QAAQ,OAAO,YAAY;AACjC,UAAI,OAAO,SAAS,WAAW,OAAO,MAAM,WAAW,SAAU;AAEjE,UAAI;AACA,cAAM,WAAW,KAAK,MAAM,MAAM,MAAM;AACxC,cAAM,YAAqC,EAAE,GAAG,SAAS;AAGzD,mBAAW,CAAC,KAAK,IAAI,KAAK,OAAO,QAAiB,QAAQ,GAAG;AACzD,gBAAM,KAAK,eAAe,GAAG;AAC7B,cAAI,IAAI;AACJ,kBAAM,WAAW,GAAG,GAAG,MAAM,IAAI,GAAG,GAAG,KAAK,GAAG,IAAI;AACnD,sBAAU,QAAQ,IAAI;AAAA,UAC1B;AAAA,QACJ;AAIA,cAAM,SAAS,KAAK,UAAU,WAAW,MAAM,CAAC;AAChD,cAAM,SAAS,EAAE,OAAO,aAAAF,QAAK,QAAQ,EAAE,QAAQ,EAAE;AACjD,cAAM,UAAU,aAAAA,QAAK,KAAK,QAAQ,YAAY;AAE9C,mBAAAE,QAAG,cAAc,SAAS,MAAM,QAAQ,OAAO;AAC/C,gBAAQ,IAAI,qDAAqD;AAAA,MACrE,SAAS,OAAO;AACZ,gBAAQ,KAAK,iDAAiD,KAAK;AAAA,MACvE;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["path","fs","import_path","import_fs","path","plugins","fs"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PluginOption, Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface ModuleOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
vendor?: string;
|
|
6
|
+
srcDir?: string;
|
|
7
|
+
inputs?: string[];
|
|
8
|
+
buildDir?: string;
|
|
9
|
+
publishedDir?: string;
|
|
10
|
+
}
|
|
11
|
+
declare function laravelModule(options: ModuleOptions): PluginOption;
|
|
12
|
+
|
|
13
|
+
interface LaravelModulesOptions {
|
|
14
|
+
modulesDir?: string;
|
|
15
|
+
statusesFile?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Laravel Modules Plugin for Vite
|
|
19
|
+
*
|
|
20
|
+
* This plugin enables Vite to work with Laravel modules by:
|
|
21
|
+
* 1. Discovering and loading module configurations
|
|
22
|
+
* 2. Resolving module-specific aliases
|
|
23
|
+
* 3. Handling namespace resolution for modules
|
|
24
|
+
* 4. Processing manifest files for proper asset handling
|
|
25
|
+
*/
|
|
26
|
+
declare function laravelModules(options?: LaravelModulesOptions): Plugin;
|
|
27
|
+
|
|
28
|
+
export { laravelModule, laravelModules };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PluginOption, Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface ModuleOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
vendor?: string;
|
|
6
|
+
srcDir?: string;
|
|
7
|
+
inputs?: string[];
|
|
8
|
+
buildDir?: string;
|
|
9
|
+
publishedDir?: string;
|
|
10
|
+
}
|
|
11
|
+
declare function laravelModule(options: ModuleOptions): PluginOption;
|
|
12
|
+
|
|
13
|
+
interface LaravelModulesOptions {
|
|
14
|
+
modulesDir?: string;
|
|
15
|
+
statusesFile?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Laravel Modules Plugin for Vite
|
|
19
|
+
*
|
|
20
|
+
* This plugin enables Vite to work with Laravel modules by:
|
|
21
|
+
* 1. Discovering and loading module configurations
|
|
22
|
+
* 2. Resolving module-specific aliases
|
|
23
|
+
* 3. Handling namespace resolution for modules
|
|
24
|
+
* 4. Processing manifest files for proper asset handling
|
|
25
|
+
*/
|
|
26
|
+
declare function laravelModules(options?: LaravelModulesOptions): Plugin;
|
|
27
|
+
|
|
28
|
+
export { laravelModule, laravelModules };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// src/laravelModule.ts
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
function laravelModule(options) {
|
|
5
|
+
return {
|
|
6
|
+
name: `vite-plugin-laravel-module:${options.name}`,
|
|
7
|
+
config: () => {
|
|
8
|
+
const {
|
|
9
|
+
name,
|
|
10
|
+
vendor = "shardevcom",
|
|
11
|
+
srcDir = "resources/react/src",
|
|
12
|
+
inputs = ["main.tsx"],
|
|
13
|
+
buildDir = `build/${vendor}/${name}`,
|
|
14
|
+
publishedDir = `resources/react/${name}`
|
|
15
|
+
} = options;
|
|
16
|
+
const moduleRoot = path.resolve(`packages/${vendor}/${name}`);
|
|
17
|
+
const isModuleRoot = process.cwd() === moduleRoot;
|
|
18
|
+
const inputPaths = {};
|
|
19
|
+
inputs.forEach((file) => {
|
|
20
|
+
const key = path.parse(file).name;
|
|
21
|
+
inputPaths[key] = path.resolve(moduleRoot, srcDir, file);
|
|
22
|
+
});
|
|
23
|
+
const publishedPath = path.resolve(publishedDir);
|
|
24
|
+
const isPublished = fs.existsSync(publishedPath);
|
|
25
|
+
if (isModuleRoot) {
|
|
26
|
+
return {
|
|
27
|
+
build: {
|
|
28
|
+
outDir: buildDir,
|
|
29
|
+
emptyOutDir: true,
|
|
30
|
+
rollupOptions: {
|
|
31
|
+
input: inputPaths
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
resolve: {
|
|
35
|
+
alias: {
|
|
36
|
+
[`@${vendor}/${name}`]: path.resolve(srcDir)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
shardevModule: JSON.stringify({
|
|
43
|
+
...options,
|
|
44
|
+
srcDir,
|
|
45
|
+
input: isPublished ? void 0 : inputPaths,
|
|
46
|
+
usePublished: isPublished,
|
|
47
|
+
alias: {
|
|
48
|
+
[`@${vendor}/${name}`]: isPublished ? publishedPath : path.resolve(moduleRoot, srcDir)
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
resolve: {
|
|
52
|
+
alias: {
|
|
53
|
+
[`@${vendor}/${name}`]: isPublished ? publishedPath : path.resolve(moduleRoot, srcDir)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/laravelModules.ts
|
|
62
|
+
import { mergeConfig, createServer } from "vite";
|
|
63
|
+
import path2 from "path";
|
|
64
|
+
import fs2 from "fs";
|
|
65
|
+
function laravelModules(options = {}) {
|
|
66
|
+
const { modulesDir = "packages", statusesFile = "modules.json" } = options;
|
|
67
|
+
const modulesPath = path2.resolve(process.cwd(), modulesDir);
|
|
68
|
+
const statusesPath = path2.resolve(process.cwd(), statusesFile);
|
|
69
|
+
const root = process.cwd();
|
|
70
|
+
const findLaravelPlugin = (plugins) => {
|
|
71
|
+
const flattenPlugins = (plugins2) => {
|
|
72
|
+
return plugins2.flatMap((plugin) => {
|
|
73
|
+
if (Array.isArray(plugin)) {
|
|
74
|
+
return flattenPlugins(plugin);
|
|
75
|
+
}
|
|
76
|
+
return plugin && typeof plugin === "object" && "name" in plugin ? [plugin] : [];
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
const flatPlugins = flattenPlugins(plugins);
|
|
80
|
+
return flatPlugins.find((plugin) => plugin?.name === "laravel") ?? null;
|
|
81
|
+
};
|
|
82
|
+
const normalizePath = (id) => {
|
|
83
|
+
let cleanPath = id.replace(/^[\/\\]+/, "").split("?")[0].split("#")[0];
|
|
84
|
+
cleanPath = cleanPath.replace(/\\/g, "/");
|
|
85
|
+
const normalizedRoot = root.replace(/\\/g, "/");
|
|
86
|
+
if (cleanPath.startsWith(normalizedRoot)) {
|
|
87
|
+
cleanPath = cleanPath.slice(normalizedRoot.length).replace(/^\/+/, "");
|
|
88
|
+
}
|
|
89
|
+
return cleanPath;
|
|
90
|
+
};
|
|
91
|
+
const parseNamespace = (id) => {
|
|
92
|
+
const cleanPath = normalizePath(id);
|
|
93
|
+
const patterns = [
|
|
94
|
+
/^([\w.-]+):([\w.-]+)::(.+)$/,
|
|
95
|
+
// vendor:pkg::file
|
|
96
|
+
/^packages\/([^/]+)\/([^/]+)\/resources\/react\/src\/(.+)$/,
|
|
97
|
+
// packages/vendor/pkg/resources/react/src/file
|
|
98
|
+
/^resources\/react\/([^/]+)\/([^/]+)\/src\/(.+)$/
|
|
99
|
+
// resources/react/vendor/pkg/src/file
|
|
100
|
+
];
|
|
101
|
+
for (const pattern of patterns) {
|
|
102
|
+
const match = cleanPath.match(pattern);
|
|
103
|
+
if (match) {
|
|
104
|
+
return { vendor: match[1], pkg: match[2], file: match[3] };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
};
|
|
109
|
+
const resolveNamespacedToFs = (vendor, pkg, file) => {
|
|
110
|
+
const paths = [
|
|
111
|
+
path2.join(root, "resources", "react", vendor, pkg, "src", file),
|
|
112
|
+
// Published path
|
|
113
|
+
path2.join(root, "packages", vendor, pkg, "resources", "react", "src", file)
|
|
114
|
+
// Workspace path
|
|
115
|
+
];
|
|
116
|
+
return paths.find(fs2.existsSync) || null;
|
|
117
|
+
};
|
|
118
|
+
const loadModuleStatuses = () => {
|
|
119
|
+
try {
|
|
120
|
+
if (fs2.existsSync(statusesPath)) {
|
|
121
|
+
return JSON.parse(fs2.readFileSync(statusesPath, "utf-8"));
|
|
122
|
+
}
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.warn("[laravel-modules] Failed to load module statuses:", error);
|
|
125
|
+
}
|
|
126
|
+
return {};
|
|
127
|
+
};
|
|
128
|
+
const getInputArray = (input) => {
|
|
129
|
+
return Array.isArray(input) ? input : Object.values(input || {});
|
|
130
|
+
};
|
|
131
|
+
const discoverModules = async (statuses) => {
|
|
132
|
+
if (!fs2.existsSync(modulesPath)) return [];
|
|
133
|
+
const plugins = [];
|
|
134
|
+
const vendors = fs2.readdirSync(modulesPath, { withFileTypes: true }).filter((dirent) => dirent.isDirectory());
|
|
135
|
+
for (const vendor of vendors) {
|
|
136
|
+
const vendorPath = path2.join(modulesPath, vendor.name);
|
|
137
|
+
const packages = fs2.readdirSync(vendorPath, { withFileTypes: true }).filter((dirent) => dirent.isDirectory() && statuses[dirent.name] !== false);
|
|
138
|
+
for (const pkg of packages) {
|
|
139
|
+
const pkgPath = path2.join(vendorPath, pkg.name);
|
|
140
|
+
const viteConfigPath = path2.join(pkgPath, "vite.config.ts");
|
|
141
|
+
if (!fs2.existsSync(viteConfigPath)) continue;
|
|
142
|
+
try {
|
|
143
|
+
const server = await createServer({
|
|
144
|
+
configFile: viteConfigPath,
|
|
145
|
+
logLevel: "silent"
|
|
146
|
+
});
|
|
147
|
+
plugins.push(...server.config.plugins);
|
|
148
|
+
await server.close();
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.warn(`[laravel-modules] Error loading ${viteConfigPath}:`, error);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return plugins;
|
|
155
|
+
};
|
|
156
|
+
const extractModuleMetadata = (plugins) => {
|
|
157
|
+
const aliases = {};
|
|
158
|
+
const moduleConfigs = [];
|
|
159
|
+
plugins.forEach((plugin) => {
|
|
160
|
+
if (!plugin?.name?.startsWith("vite-plugin-laravel-module:")) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
let resolvedConfig;
|
|
164
|
+
if (typeof plugin.config === "function") {
|
|
165
|
+
const fn = plugin.config;
|
|
166
|
+
resolvedConfig = fn({});
|
|
167
|
+
}
|
|
168
|
+
if (!resolvedConfig?.shardevModule) return;
|
|
169
|
+
try {
|
|
170
|
+
const meta = JSON.parse(resolvedConfig?.shardevModule);
|
|
171
|
+
if (meta.alias) Object.assign(aliases, meta.alias);
|
|
172
|
+
if (!meta.usePublished && meta.input) moduleConfigs.push(meta);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.warn("[laravel-modules] Failed to parse module metadata:", error);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return { aliases, moduleConfigs };
|
|
178
|
+
};
|
|
179
|
+
const generateRollupInputs = (moduleConfigs) => {
|
|
180
|
+
const inputs = {};
|
|
181
|
+
moduleConfigs.forEach((mod) => {
|
|
182
|
+
const modInputs = getInputArray(mod.input);
|
|
183
|
+
modInputs.forEach((inputPath, idx) => {
|
|
184
|
+
const name = modInputs.length > 1 ? `${mod.name}-${idx}` : mod.name;
|
|
185
|
+
inputs[name] = inputPath;
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
return inputs;
|
|
189
|
+
};
|
|
190
|
+
function getLaravelResolvedConfig(plugin, config, env) {
|
|
191
|
+
if (!plugin.config || typeof plugin.config !== "function") return null;
|
|
192
|
+
try {
|
|
193
|
+
const fn = plugin.config;
|
|
194
|
+
const result = fn(config, env);
|
|
195
|
+
return result && typeof result === "object" ? result : null;
|
|
196
|
+
} catch (error) {
|
|
197
|
+
console.warn("[laravel-modules] Failed to get Laravel config:", error);
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function extractAliases(config) {
|
|
202
|
+
const alias = config?.resolve?.alias;
|
|
203
|
+
if (!alias) return {};
|
|
204
|
+
if (Array.isArray(alias)) {
|
|
205
|
+
return alias.reduce((acc, item) => {
|
|
206
|
+
if (item && typeof item.find === "string" && typeof item.replacement === "string") {
|
|
207
|
+
acc[item.find] = item.replacement;
|
|
208
|
+
}
|
|
209
|
+
return acc;
|
|
210
|
+
}, {});
|
|
211
|
+
}
|
|
212
|
+
if (typeof alias === "object") {
|
|
213
|
+
return { ...alias };
|
|
214
|
+
}
|
|
215
|
+
return {};
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
name: "laravel-modules",
|
|
219
|
+
async config(config, env) {
|
|
220
|
+
const statuses = loadModuleStatuses();
|
|
221
|
+
const modules = await discoverModules(statuses);
|
|
222
|
+
const aliases = {};
|
|
223
|
+
const moduleConfigs = [];
|
|
224
|
+
const laravelPlugin = findLaravelPlugin(config.plugins || []);
|
|
225
|
+
if (laravelPlugin && laravelPlugin?.config) {
|
|
226
|
+
try {
|
|
227
|
+
const laravelConfig = getLaravelResolvedConfig(laravelPlugin, config, env);
|
|
228
|
+
if (!laravelConfig) throw new Error("Invalid Laravel config");
|
|
229
|
+
moduleConfigs.push({
|
|
230
|
+
name: "main",
|
|
231
|
+
input: getInputArray(laravelConfig?.build?.rollupOptions?.input || []),
|
|
232
|
+
buildDir: laravelConfig?.build?.buildDir || "build",
|
|
233
|
+
alias: extractAliases(laravelConfig)
|
|
234
|
+
});
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.warn("[laravel-modules] Failed to extract Laravel plugin config:", error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const { aliases: moduleAliases, moduleConfigs: extractedConfigs } = extractModuleMetadata(modules);
|
|
240
|
+
Object.assign(aliases, moduleAliases);
|
|
241
|
+
moduleConfigs.push(...extractedConfigs);
|
|
242
|
+
const rollupInputs = generateRollupInputs(moduleConfigs);
|
|
243
|
+
return mergeConfig(config, {
|
|
244
|
+
resolve: {
|
|
245
|
+
alias: aliases
|
|
246
|
+
},
|
|
247
|
+
build: {
|
|
248
|
+
rollupOptions: {
|
|
249
|
+
input: rollupInputs
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
resolveId(source) {
|
|
255
|
+
const ns = parseNamespace(source);
|
|
256
|
+
if (!ns) return null;
|
|
257
|
+
const resolved = resolveNamespacedToFs(ns.vendor, ns.pkg, ns.file);
|
|
258
|
+
if (resolved) return resolved;
|
|
259
|
+
return null;
|
|
260
|
+
},
|
|
261
|
+
writeBundle(_, bundle) {
|
|
262
|
+
const manifestFile = Object.keys(bundle).find((f) => f === "manifest.json");
|
|
263
|
+
if (!manifestFile) return;
|
|
264
|
+
const asset = bundle[manifestFile];
|
|
265
|
+
if (asset?.type !== "asset" || typeof asset.source !== "string") return;
|
|
266
|
+
try {
|
|
267
|
+
const manifest = JSON.parse(asset.source);
|
|
268
|
+
const rewritten = { ...manifest };
|
|
269
|
+
for (const [src, data] of Object.entries(manifest)) {
|
|
270
|
+
const ns = parseNamespace(src);
|
|
271
|
+
if (ns) {
|
|
272
|
+
const aliasKey = `${ns.vendor}:${ns.pkg}::${ns.file}`;
|
|
273
|
+
rewritten[aliasKey] = data;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
asset.source = JSON.stringify(rewritten, null, 2);
|
|
277
|
+
const outDir = _.dir || path2.dirname(_.file || "");
|
|
278
|
+
const outPath = path2.join(outDir, manifestFile);
|
|
279
|
+
fs2.writeFileSync(outPath, asset.source, "utf-8");
|
|
280
|
+
console.log("[laravel-modules] Manifest namespaced keys injected");
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.warn("[laravel-modules] Failed to process manifest:", error);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
laravelModule,
|
|
289
|
+
laravelModules
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/laravelModule.ts","../src/laravelModules.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type { PluginOption } from 'vite';\n\ninterface ModuleOptions {\n name: string;\n vendor?: string;\n srcDir?: string;\n inputs?: string[];\n buildDir?: string;\n publishedDir?: string;\n}\n\nexport default function laravelModule(options: ModuleOptions): PluginOption {\n return {\n name: `vite-plugin-laravel-module:${options.name}`,\n config: () => {\n const {\n name,\n vendor = 'shardevcom',\n srcDir = 'resources/react/src',\n inputs = ['main.tsx'],\n buildDir = `build/${vendor}/${name}`,\n publishedDir = `resources/react/${name}`\n } = options;\n\n const moduleRoot = path.resolve(`packages/${vendor}/${name}`);\n const isModuleRoot = process.cwd() === moduleRoot;\n\n const inputPaths: Record<string, string> = {};\n inputs.forEach((file) => {\n const key = path.parse(file).name;\n inputPaths[key] = path.resolve(moduleRoot, srcDir, file);\n });\n\n const publishedPath = path.resolve(publishedDir);\n const isPublished = fs.existsSync(publishedPath);\n\n if (isModuleRoot) {\n return {\n build: {\n outDir: buildDir,\n emptyOutDir: true,\n rollupOptions: {\n input: inputPaths\n }\n },\n resolve: {\n alias: {\n [`@${vendor}/${name}`]: path.resolve(srcDir)\n }\n }\n };\n }\n\n return {\n shardevModule: JSON.stringify({\n ...options,\n srcDir,\n input: isPublished ? undefined : inputPaths,\n usePublished: isPublished,\n alias: {\n [`@${vendor}/${name}`]: isPublished ? publishedPath : path.resolve(moduleRoot, srcDir)\n }\n }),\n resolve: {\n alias: {\n [`@${vendor}/${name}`]: isPublished ? publishedPath : path.resolve(moduleRoot, srcDir)\n }\n }\n };\n }\n };\n}\n","import type { Plugin, UserConfig, PluginOption, ConfigEnv } from 'vite';\nimport { mergeConfig, createServer } from 'vite';\nimport path from 'path';\nimport fs from 'fs';\n\ninterface LaravelModulesOptions {\n modulesDir?: string;\n statusesFile?: string;\n}\n\ninterface ModuleConfigMeta {\n name: string;\n input: string[];\n buildDir: string;\n alias?: Record<string, string>;\n usePublished?: boolean;\n}\n\ninterface ParsedNamespace {\n vendor: string;\n pkg: string;\n file: string;\n}\n\nexport interface ShardevUserConfig extends UserConfig {\n shardevModule?: string; // JSON.stringify(ModuleConfigMeta)\n}\n\ninterface LaravelResolvedConfig {\n build?: {\n rollupOptions?: {\n input?: string[] | Record<string, string>;\n };\n buildDir?: string;\n };\n resolve?: {\n alias?: Record<string, string> | Array<{ find: string | RegExp, replacement: string }>;\n };\n}\n\ninterface ModuleDiscoveryResult {\n aliases: Record<string, string>;\n moduleConfigs: ModuleConfigMeta[];\n}\n\n/**\n * Laravel Modules Plugin for Vite\n *\n * This plugin enables Vite to work with Laravel modules by:\n * 1. Discovering and loading module configurations\n * 2. Resolving module-specific aliases\n * 3. Handling namespace resolution for modules\n * 4. Processing manifest files for proper asset handling\n */\nexport default function laravelModules(options: LaravelModulesOptions = {}): Plugin {\n const { modulesDir = 'packages', statusesFile = 'modules.json' } = options;\n const modulesPath = path.resolve(process.cwd(), modulesDir);\n const statusesPath = path.resolve(process.cwd(), statusesFile);\n const root = process.cwd();\n\n /**\n * Finds the Laravel plugin instance within the main Vite config\n */\n const findLaravelPlugin = (plugins: PluginOption[]): Plugin | null => {\n const flattenPlugins = (plugins: PluginOption[]): Plugin[] => {\n return plugins.flatMap(plugin => {\n if (Array.isArray(plugin)) {\n return flattenPlugins(plugin);\n }\n return plugin && typeof plugin === 'object' && 'name' in plugin ? [plugin] : [];\n });\n };\n\n const flatPlugins = flattenPlugins(plugins);\n return flatPlugins.find(plugin => plugin?.name === 'laravel') ?? null;\n };\n\n /**\n * Normalizes path by removing query/hash and standardizing separators\n */\n const normalizePath = (id: string): string => {\n // Remove query/hash and leading slashes\n let cleanPath = id.replace(/^[\\/\\\\]+/, '').split('?')[0].split('#')[0];\n\n // Normalize separators to forward slashes\n cleanPath = cleanPath.replace(/\\\\/g, '/');\n\n // Remove root prefix if present\n const normalizedRoot = root.replace(/\\\\/g, '/');\n if (cleanPath.startsWith(normalizedRoot)) {\n cleanPath = cleanPath.slice(normalizedRoot.length).replace(/^\\/+/, '');\n }\n\n return cleanPath;\n };\n\n /**\n * Parses namespace from path using multiple patterns\n */\n const parseNamespace = (id: string): ParsedNamespace | null => {\n const cleanPath = normalizePath(id);\n\n const patterns = [\n /^([\\w.-]+):([\\w.-]+)::(.+)$/, // vendor:pkg::file\n /^packages\\/([^/]+)\\/([^/]+)\\/resources\\/react\\/src\\/(.+)$/, // packages/vendor/pkg/resources/react/src/file\n /^resources\\/react\\/([^/]+)\\/([^/]+)\\/src\\/(.+)$/ // resources/react/vendor/pkg/src/file\n ];\n\n for (const pattern of patterns) {\n const match = cleanPath.match(pattern);\n if (match) {\n return { vendor: match[1], pkg: match[2], file: match[3] };\n }\n }\n\n return null;\n };\n\n /**\n * Resolves namespace to filesystem path\n */\n const resolveNamespacedToFs = (vendor: string, pkg: string, file: string): string | null => {\n const paths = [\n path.join(root, 'resources', 'react', vendor, pkg, 'src', file), // Published path\n path.join(root, 'packages', vendor, pkg, 'resources', 'react', 'src', file) // Workspace path\n ];\n\n return paths.find(fs.existsSync) || null;\n };\n\n /**\n * Loads module activation statuses from JSON file\n */\n const loadModuleStatuses = (): Record<string, boolean> => {\n try {\n if (fs.existsSync(statusesPath)) {\n return JSON.parse(fs.readFileSync(statusesPath, 'utf-8'));\n }\n } catch (error) {\n console.warn('[laravel-modules] Failed to load module statuses:', error);\n }\n\n return {};\n };\n\n /**\n * Extracts input array from various input formats\n */\n const getInputArray = (input: string[] | Record<string, string>): string[] => {\n return Array.isArray(input) ? input : Object.values(input || {});\n };\n\n /**\n * Discovers all active modules with a vite.config.* file\n */\n const discoverModules = async (statuses: Record<string, boolean>): Promise<Plugin[]> => {\n if (!fs.existsSync(modulesPath)) return [];\n\n const plugins: Plugin[] = [];\n const vendors = fs.readdirSync(modulesPath, { withFileTypes: true })\n .filter(dirent => dirent.isDirectory());\n\n for (const vendor of vendors) {\n const vendorPath = path.join(modulesPath, vendor.name);\n const packages = fs.readdirSync(vendorPath, { withFileTypes: true })\n .filter(dirent => dirent.isDirectory() && (statuses[dirent.name] !== false));\n\n for (const pkg of packages) {\n const pkgPath = path.join(vendorPath, pkg.name);\n const viteConfigPath = path.join(pkgPath, 'vite.config.ts');\n\n if (!fs.existsSync(viteConfigPath)) continue;\n\n try {\n const server = await createServer({\n configFile: viteConfigPath,\n logLevel: 'silent'\n });\n\n // 🚨 Aquí capturamos los plugins del módulo\n plugins.push(...(server.config.plugins as Plugin[]));\n await server.close();\n } catch (error) {\n console.warn(`[laravel-modules] Error loading ${viteConfigPath}:`, error);\n }\n }\n }\n\n return plugins;\n };\n\n\n /**\n * Extracts module metadata from plugins\n */\n const extractModuleMetadata = (plugins: Plugin[]): ModuleDiscoveryResult => {\n const aliases: Record<string, string> = {};\n const moduleConfigs: ModuleConfigMeta[] = [];\n\n plugins.forEach(plugin => {\n\n if (!plugin?.name?.startsWith(\"vite-plugin-laravel-module:\")) {\n return;\n }\n\n let resolvedConfig: ShardevUserConfig | undefined;\n if (typeof plugin.config === \"function\") {\n const fn = plugin.config as (config: ShardevUserConfig, env?: ConfigEnv) => ShardevUserConfig;\n resolvedConfig = fn({}) as ShardevUserConfig;\n }\n\n if (!resolvedConfig?.shardevModule) return;\n\n try {\n const meta: ModuleConfigMeta = JSON.parse(resolvedConfig?.shardevModule);\n if (meta.alias) Object.assign(aliases, meta.alias);\n if (!meta.usePublished && meta.input) moduleConfigs.push(meta);\n } catch (error) {\n console.warn('[laravel-modules] Failed to parse module metadata:', error);\n }\n });\n\n return { aliases, moduleConfigs };\n };\n\n /**\n * Generates rollup inputs from module configurations\n */\n const generateRollupInputs = (moduleConfigs: ModuleConfigMeta[]): Record<string, string> => {\n const inputs: Record<string, string> = {};\n\n moduleConfigs.forEach(mod => {\n const modInputs = getInputArray(mod.input);\n modInputs.forEach((inputPath, idx) => {\n const name = modInputs.length > 1 ? `${mod.name}-${idx}` : mod.name;\n inputs[name] = inputPath;\n });\n });\n\n return inputs;\n };\n\n /**\n * Retrieves resolved Laravel configuration from the plugin\n */\n function getLaravelResolvedConfig(plugin: Plugin, config: UserConfig, env: ConfigEnv) {\n if (!plugin.config || typeof plugin.config !== 'function') return null;\n\n try {\n const fn = plugin.config as (config: UserConfig, env?: ConfigEnv) => LaravelResolvedConfig;\n const result = fn(config, env) as LaravelResolvedConfig;\n return result && typeof result === 'object' ? result : null;\n } catch (error) {\n console.warn('[laravel-modules] Failed to get Laravel config:', error);\n return null;\n }\n }\n\n /**\n * Extracts aliases from Laravel config\n */\n function extractAliases(config: LaravelResolvedConfig): Record<string, string> {\n const alias = config?.resolve?.alias;\n\n if (!alias) return {};\n\n if (Array.isArray(alias)) {\n // Convertir array format [{ find: 'foo', replacement: 'bar' }] to object { foo: 'bar' }\n return alias.reduce((acc, item) => {\n if (item && typeof item.find === 'string' && typeof item.replacement === 'string') {\n acc[item.find] = item.replacement;\n }\n return acc;\n }, {} as Record<string, string>);\n }\n\n if (typeof alias === 'object') {\n return { ...alias };\n }\n\n return {};\n }\n\n\n return {\n name: 'laravel-modules',\n\n async config(config: UserConfig, env) {\n const statuses = loadModuleStatuses();\n const modules = await discoverModules(statuses);\n\n const aliases: Record<string, string> = {};\n const moduleConfigs: ModuleConfigMeta[] = [];\n\n // Extract main Laravel config\n const laravelPlugin = findLaravelPlugin(config.plugins || []);\n if (laravelPlugin && laravelPlugin?.config) {\n try {\n const laravelConfig = getLaravelResolvedConfig(laravelPlugin, config, env);\n if (!laravelConfig) throw new Error('Invalid Laravel config');\n moduleConfigs.push({\n name: 'main',\n input: getInputArray(laravelConfig?.build?.rollupOptions?.input || []),\n buildDir: laravelConfig?.build?.buildDir || 'build',\n alias: extractAliases(laravelConfig)\n });\n } catch (error) {\n console.warn('[laravel-modules] Failed to extract Laravel plugin config:', error);\n }\n }\n\n // Extract module metadata\n const { aliases: moduleAliases, moduleConfigs: extractedConfigs } = extractModuleMetadata(modules);\n Object.assign(aliases, moduleAliases);\n moduleConfigs.push(...extractedConfigs);\n\n // Generate rollup inputs\n const rollupInputs = generateRollupInputs(moduleConfigs);\n\n // Merge with main config\n return mergeConfig(config, {\n resolve: {\n alias: aliases\n },\n build: {\n rollupOptions: {\n input: rollupInputs\n }\n }\n });\n },\n\n resolveId(source: string) {\n const ns = parseNamespace(source);\n if (!ns) return null;\n\n const resolved = resolveNamespacedToFs(ns.vendor, ns.pkg, ns.file);\n if (resolved) return resolved;\n\n //this.warn(`[laravel-modules] Not found: ${ns.vendor}:${ns.pkg}::${ns.file}`);\n return null;\n },\n\n writeBundle(_, bundle) {\n const manifestFile = Object.keys(bundle).find(f => f === 'manifest.json');\n if (!manifestFile) return;\n\n const asset = bundle[manifestFile];\n if (asset?.type !== 'asset' || typeof asset.source !== 'string') return;\n\n try {\n const manifest = JSON.parse(asset.source);\n const rewritten: Record<string, unknown> = { ...manifest };\n\n // Add namespaced entries\n for (const [src, data] of Object.entries<unknown>(manifest)) {\n const ns = parseNamespace(src);\n if (ns) {\n const aliasKey = `${ns.vendor}:${ns.pkg}::${ns.file}`;\n rewritten[aliasKey] = data;\n }\n }\n\n\n // Write updated manifest\n asset.source = JSON.stringify(rewritten, null, 2);\n const outDir = _.dir || path.dirname(_.file || '');\n const outPath = path.join(outDir, manifestFile);\n\n fs.writeFileSync(outPath, asset.source, 'utf-8');\n console.log('[laravel-modules] Manifest namespaced keys injected');\n } catch (error) {\n console.warn('[laravel-modules] Failed to process manifest:', error);\n }\n }\n };\n}\n"],"mappings":";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AAYF,SAAR,cAA+B,SAAsC;AACxE,SAAO;AAAA,IACH,MAAM,8BAA8B,QAAQ,IAAI;AAAA,IAChD,QAAQ,MAAM;AACV,YAAM;AAAA,QACF;AAAA,QACA,SAAS;AAAA,QACT,SAAS;AAAA,QACT,SAAS,CAAC,UAAU;AAAA,QACpB,WAAW,SAAS,MAAM,IAAI,IAAI;AAAA,QAClC,eAAe,mBAAmB,IAAI;AAAA,MAC1C,IAAI;AAEJ,YAAM,aAAa,KAAK,QAAQ,YAAY,MAAM,IAAI,IAAI,EAAE;AAC5D,YAAM,eAAe,QAAQ,IAAI,MAAM;AAEvC,YAAM,aAAqC,CAAC;AAC5C,aAAO,QAAQ,CAAC,SAAS;AACrB,cAAM,MAAM,KAAK,MAAM,IAAI,EAAE;AAC7B,mBAAW,GAAG,IAAI,KAAK,QAAQ,YAAY,QAAQ,IAAI;AAAA,MAC3D,CAAC;AAED,YAAM,gBAAgB,KAAK,QAAQ,YAAY;AAC/C,YAAM,cAAc,GAAG,WAAW,aAAa;AAE/C,UAAI,cAAc;AACd,eAAO;AAAA,UACH,OAAO;AAAA,YACH,QAAQ;AAAA,YACR,aAAa;AAAA,YACb,eAAe;AAAA,cACX,OAAO;AAAA,YACX;AAAA,UACJ;AAAA,UACA,SAAS;AAAA,YACL,OAAO;AAAA,cACH,CAAC,IAAI,MAAM,IAAI,IAAI,EAAE,GAAG,KAAK,QAAQ,MAAM;AAAA,YAC/C;AAAA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ous",
|
|
5
|
+
"description": "Advanced Laravel Modules support for Vite (monorepo + namespace resolver)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.cjs.js",
|
|
9
|
+
"module": "./dist/index.es.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.es.js",
|
|
15
|
+
"require": "./dist/index.cjs.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20.19"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"clean": "rm -rf dist"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"vite": "^7.0.0",
|
|
31
|
+
"laravel-vite-plugin": "^2.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.0.0",
|
|
35
|
+
"typescript": "^5.7.0",
|
|
36
|
+
"@types/node": "^22.0.0",
|
|
37
|
+
"vite": "^7.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|