@adonisjs/vite 5.1.0 → 6.0.0-next.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/build/index.js +69 -45
- package/build/providers/vite_provider.js +138 -139
- package/build/services/vite.js +9 -6
- package/build/src/client/main.js +1002 -59
- package/build/src/client/reload.d.ts +13 -0
- package/build/src/client/resolve_assets.d.ts +20 -0
- package/build/src/client/types.d.ts +26 -1
- package/build/src/hooks/build_hook.js +20 -7
- package/build/src/plugins/edge.js +85 -67
- package/build/src/server_modules/bundled_module_resolver.d.ts +17 -0
- package/build/src/server_modules/dev_module_runner.d.ts +25 -0
- package/build/src/server_modules/server_module_loader.d.ts +25 -0
- package/build/src/types.d.ts +32 -0
- package/build/src/types.js +1 -0
- package/build/src/vite.d.ts +22 -1
- package/build/src/vite_middleware.js +2 -6
- package/build/utils-CdZpa_tV.js +50 -0
- package/build/vite-De-RhsJ1.js +630 -0
- package/build/vite_middleware-CuOBHhnt.js +72 -0
- package/package.json +22 -20
- package/build/chunk-AF6PV64J.js +0 -56
- package/build/chunk-ZCIGOANY.js +0 -451
- package/build/chunk-ZCQTQOMI.js +0 -29
package/build/index.js
CHANGED
|
@@ -1,49 +1,73 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { t as Vite } from "./vite-De-RhsJ1.js";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
//#region stubs/main.ts
|
|
4
|
+
const stubsRoot = import.meta.dirname;
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region configure.ts
|
|
7
|
+
/**
|
|
8
|
+
* Configures the package
|
|
9
|
+
*/
|
|
10
10
|
async function configure(command) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
11
|
+
const codemods = await command.createCodemods();
|
|
12
|
+
let shouldInstallPackages = command.parsedFlags.install;
|
|
13
|
+
/**
|
|
14
|
+
* Publish stubs
|
|
15
|
+
*/
|
|
16
|
+
await codemods.makeUsingStub(stubsRoot, "config/vite.stub", {});
|
|
17
|
+
await codemods.makeUsingStub(stubsRoot, "vite.config.stub", {});
|
|
18
|
+
await codemods.makeUsingStub(stubsRoot, "js_entrypoint.stub", {});
|
|
19
|
+
/**
|
|
20
|
+
* Update RC file
|
|
21
|
+
*/
|
|
22
|
+
await codemods.updateRcFile((rcFile) => {
|
|
23
|
+
rcFile.addProvider("@adonisjs/vite/vite_provider");
|
|
24
|
+
rcFile.addMetaFile("public/**", false);
|
|
25
|
+
rcFile.addAssemblerHook("buildStarting", "@adonisjs/vite/build_hook");
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Add server middleware
|
|
29
|
+
*/
|
|
30
|
+
await codemods.registerMiddleware("server", [{
|
|
31
|
+
path: "@adonisjs/vite/vite_middleware",
|
|
32
|
+
position: "after"
|
|
33
|
+
}]);
|
|
34
|
+
/**
|
|
35
|
+
* Prompt when `install` or `--no-install` flags are
|
|
36
|
+
* not used
|
|
37
|
+
*/
|
|
38
|
+
if (shouldInstallPackages === void 0) shouldInstallPackages = await command.prompt.confirm("Do you want to install \"vite\"?");
|
|
39
|
+
/**
|
|
40
|
+
* Install dependency or list the command to install it
|
|
41
|
+
*/
|
|
42
|
+
if (shouldInstallPackages) await codemods.installPackages([{
|
|
43
|
+
name: "vite",
|
|
44
|
+
isDevDependency: true
|
|
45
|
+
}]);
|
|
46
|
+
else await codemods.listPackagesToInstall([{
|
|
47
|
+
name: "vite",
|
|
48
|
+
isDevDependency: true
|
|
49
|
+
}]);
|
|
32
50
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/define_config.ts
|
|
53
|
+
/**
|
|
54
|
+
* Creates a complete Vite configuration by merging provided options with sensible defaults
|
|
55
|
+
*
|
|
56
|
+
* @param config - Partial Vite configuration options to override defaults
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const viteConfig = defineConfig({
|
|
60
|
+
* assetsUrl: '/static',
|
|
61
|
+
* buildDirectory: 'dist'
|
|
62
|
+
* })
|
|
63
|
+
*/
|
|
36
64
|
function defineConfig(config) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
65
|
+
return {
|
|
66
|
+
assetsUrl: "/assets",
|
|
67
|
+
buildDirectory: "public/assets",
|
|
68
|
+
manifestFile: config.buildDirectory ? join(config.buildDirectory, ".vite/manifest.json") : "public/assets/.vite/manifest.json",
|
|
69
|
+
...config
|
|
70
|
+
};
|
|
43
71
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
configure,
|
|
47
|
-
defineConfig,
|
|
48
|
-
stubsRoot
|
|
49
|
-
};
|
|
72
|
+
//#endregion
|
|
73
|
+
export { Vite, configure, defineConfig, stubsRoot };
|
|
@@ -1,141 +1,140 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { t as Vite } from "../vite-De-RhsJ1.js";
|
|
2
|
+
import { t as ViteMiddleware } from "../vite_middleware-CuOBHhnt.js";
|
|
3
|
+
//#region providers/vite_provider.ts
|
|
4
|
+
/**
|
|
5
|
+
* AdonisJS service provider for integrating Vite build tool and development server
|
|
6
|
+
*
|
|
7
|
+
* Handles lifecycle management of Vite integration including:
|
|
8
|
+
* - Registering Vite service in the container
|
|
9
|
+
* - Setting up Edge.js plugin for template integration
|
|
10
|
+
* - Managing development server startup/shutdown
|
|
11
|
+
* - Configuring CSP keywords for @adonisjs/shield
|
|
12
|
+
*/
|
|
10
13
|
var ViteProvider = class {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const vite = await this.app.container.make("vite");
|
|
136
|
-
await vite.stopDevServer();
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
export {
|
|
140
|
-
ViteProvider as default
|
|
14
|
+
/**
|
|
15
|
+
* Flag indicating whether the Vite development server should be started
|
|
16
|
+
* Set to true when manifest file doesn't exist and running in web/test environment
|
|
17
|
+
*/
|
|
18
|
+
#shouldRunViteDevServer = false;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new ViteProvider instance
|
|
21
|
+
*
|
|
22
|
+
* @param app - The AdonisJS application service instance
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* const provider = new ViteProvider(app)
|
|
26
|
+
*/
|
|
27
|
+
constructor(app) {
|
|
28
|
+
this.app = app;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Registers the Vite Edge.js plugin if Edge.js is available in the application
|
|
32
|
+
*
|
|
33
|
+
* Adds global helpers and custom tags (@vite, @viteReactRefresh) to Edge templates.
|
|
34
|
+
* Only registers the plugin if the application is using Edge.js.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* await provider.registerEdgePlugin()
|
|
38
|
+
* // Enables @vite('app.js') in Edge templates
|
|
39
|
+
*/
|
|
40
|
+
async registerEdgePlugin() {
|
|
41
|
+
if (this.app.usingEdgeJS) {
|
|
42
|
+
const edge = await import("edge.js");
|
|
43
|
+
const vite = await this.app.container.make("vite");
|
|
44
|
+
const { edgePluginVite } = await import("../src/plugins/edge.js");
|
|
45
|
+
edge.default.use(edgePluginVite(vite));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Registers Content Security Policy keywords when @adonisjs/shield is installed
|
|
50
|
+
*
|
|
51
|
+
* Adds the '@viteUrl' keyword for CSP directives that returns the Vite assets URL
|
|
52
|
+
* when it's an HTTP/HTTPS URL, or an empty string otherwise.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* await provider.registerShieldKeywords()
|
|
56
|
+
* // Enables @viteUrl in CSP directives
|
|
57
|
+
*/
|
|
58
|
+
async registerShieldKeywords() {
|
|
59
|
+
let cspKeywords = null;
|
|
60
|
+
try {
|
|
61
|
+
cspKeywords = (await import("@adonisjs/shield")).cspKeywords;
|
|
62
|
+
} catch {}
|
|
63
|
+
if (!cspKeywords) return;
|
|
64
|
+
const vite = await this.app.container.make("vite");
|
|
65
|
+
/**
|
|
66
|
+
* Registering the @viteUrl keyword for CSP directives.
|
|
67
|
+
* Returns http URL to the dev or the CDN server, otherwise
|
|
68
|
+
* an empty string
|
|
69
|
+
*/
|
|
70
|
+
cspKeywords.register("@viteUrl", function() {
|
|
71
|
+
const assetsURL = vite.assetsUrl();
|
|
72
|
+
if (!assetsURL || !assetsURL.startsWith("http://") || assetsURL.startsWith("https://")) return "";
|
|
73
|
+
return assetsURL;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Registers Vite service and middleware bindings in the IoC container
|
|
78
|
+
*
|
|
79
|
+
* Creates a Vite instance using configuration and determines whether
|
|
80
|
+
* the development server should run based on environment and manifest file presence.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* provider.register()
|
|
84
|
+
* // Vite service is now available via container.make('vite')
|
|
85
|
+
*/
|
|
86
|
+
register() {
|
|
87
|
+
const appEnvironment = this.app.getEnvironment();
|
|
88
|
+
const vite = new Vite(this.app.config.get("vite"));
|
|
89
|
+
/**
|
|
90
|
+
* DEV_MODE is injected when the dev server is started
|
|
91
|
+
* by assembler
|
|
92
|
+
*/
|
|
93
|
+
this.#shouldRunViteDevServer = appEnvironment === "test" || !!process.env.DEV_MODE;
|
|
94
|
+
this.app.container.singleton(Vite, () => vite);
|
|
95
|
+
this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite));
|
|
96
|
+
this.app.container.alias("vite", Vite);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Boots the Vite provider by registering plugins and integrations
|
|
100
|
+
*
|
|
101
|
+
* Registers Edge.js plugin and Shield CSP keywords if the respective
|
|
102
|
+
* packages are available in the application.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* await provider.boot()
|
|
106
|
+
*/
|
|
107
|
+
async boot() {
|
|
108
|
+
await this.registerEdgePlugin();
|
|
109
|
+
await this.registerShieldKeywords();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Starts the Vite development server when the application is ready
|
|
113
|
+
*
|
|
114
|
+
* Only starts the server if running in development/test mode and
|
|
115
|
+
* no manifest file exists (indicating development mode).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* await provider.ready()
|
|
119
|
+
* // Dev server starts on configured port
|
|
120
|
+
*/
|
|
121
|
+
async ready() {
|
|
122
|
+
if (!this.#shouldRunViteDevServer) return;
|
|
123
|
+
await (await this.app.container.make("vite")).createDevServer();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gracefully stops the Vite development server during application shutdown
|
|
127
|
+
*
|
|
128
|
+
* Only attempts to stop the server if it was started during the ready phase.
|
|
129
|
+
* Ensures clean shutdown of the development server and its resources.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* await provider.shutdown()
|
|
133
|
+
*/
|
|
134
|
+
async shutdown() {
|
|
135
|
+
if (!this.#shouldRunViteDevServer) return;
|
|
136
|
+
await (await this.app.container.make("vite")).stopDevServer();
|
|
137
|
+
}
|
|
141
138
|
};
|
|
139
|
+
//#endregion
|
|
140
|
+
export { ViteProvider as default };
|
package/build/services/vite.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
// services/vite.ts
|
|
2
1
|
import app from "@adonisjs/core/services/app";
|
|
3
|
-
|
|
2
|
+
//#region services/vite.ts
|
|
3
|
+
let vite;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a singleton instance of Vite class
|
|
6
|
+
* from the container
|
|
7
|
+
*/
|
|
4
8
|
await app.booted(async () => {
|
|
5
|
-
|
|
9
|
+
vite = await app.container.make("vite");
|
|
6
10
|
});
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { vite as default };
|