@adonisjs/vite 5.1.0-next.4 → 5.1.1
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 +68 -55
- package/build/src/hooks/build_hook.js +11 -7
- package/build/src/plugins/edge.js +85 -67
- package/build/src/types.js +1 -0
- package/build/src/vite_middleware.d.ts +0 -1
- package/build/src/vite_middleware.js +2 -6
- package/build/utils-CdZpa_tV.js +50 -0
- package/build/vite-DDpuL-Eo.js +472 -0
- package/build/vite_middleware-Bszg_DDr.js +71 -0
- package/package.json +27 -26
- package/build/chunk-AF6PV64J.js +0 -56
- package/build/chunk-ZCIGOANY.js +0 -451
- package/build/chunk-ZCQTQOMI.js +0 -29
|
@@ -1,69 +1,87 @@
|
|
|
1
|
-
// src/plugins/edge.ts
|
|
2
1
|
import { EdgeError } from "edge-error";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
2
|
+
//#region src/plugins/edge.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates an Edge.js plugin that integrates Vite functionality into templates
|
|
5
|
+
*
|
|
6
|
+
* Registers global helpers and custom tags (@vite, @viteReactRefresh) for use in Edge templates.
|
|
7
|
+
* Provides access to asset paths and HMR functionality within template rendering.
|
|
8
|
+
*
|
|
9
|
+
* @param vite - The Vite instance to integrate with Edge templates
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const plugin = edgePluginVite(viteInstance)
|
|
13
|
+
* edge.use(plugin)
|
|
14
|
+
*
|
|
15
|
+
* // In templates:
|
|
16
|
+
* // @vite('app.js')
|
|
17
|
+
* // @viteReactRefresh({ nonce: 'abc123' })
|
|
18
|
+
*/
|
|
19
|
+
const edgePluginVite = (vite) => {
|
|
20
|
+
const edgeVite = (edge) => {
|
|
21
|
+
edge.global("vite", vite);
|
|
22
|
+
edge.global("asset", vite.assetPath.bind(vite));
|
|
23
|
+
edge.registerTag({
|
|
24
|
+
tagName: "viteReactRefresh",
|
|
25
|
+
seekable: true,
|
|
26
|
+
block: false,
|
|
27
|
+
compile(parser, buffer, token) {
|
|
28
|
+
let attributes = "";
|
|
29
|
+
if (token.properties.jsArg.trim()) {
|
|
30
|
+
/**
|
|
31
|
+
* Converting a single argument to a SequenceExpression so that we
|
|
32
|
+
* work around the following edge cases.
|
|
33
|
+
*
|
|
34
|
+
* - If someone passes an object literal to the tag, ie { nonce: 'foo' }
|
|
35
|
+
* it will be parsed as a LabeledStatement and not an object.
|
|
36
|
+
* - If we wrap the object literal inside parenthesis, ie ({nonce: 'foo'})
|
|
37
|
+
* then we will end up messing other expressions like a variable reference
|
|
38
|
+
* , or a member expression and so on.
|
|
39
|
+
* - So the best bet is to convert user supplied argument to a sequence expression
|
|
40
|
+
* and hence ignore it during stringification.
|
|
41
|
+
*/
|
|
42
|
+
const jsArg = `a,${token.properties.jsArg}`;
|
|
43
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(jsArg, token.loc, token.filename), token.filename, parser);
|
|
44
|
+
attributes = parser.utils.stringify(parsed.expressions[1]);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get HMR script
|
|
48
|
+
*/
|
|
49
|
+
buffer.writeExpression(`const __vite_hmr_script = state.vite.getReactHmrScript(${attributes})`, token.filename, token.loc.start.line);
|
|
50
|
+
/**
|
|
51
|
+
* Check if the script exists (only in hot mode)
|
|
52
|
+
*/
|
|
53
|
+
buffer.writeStatement("if(__vite_hmr_script) {", token.filename, token.loc.start.line);
|
|
54
|
+
/**
|
|
55
|
+
* Write output
|
|
56
|
+
*/
|
|
57
|
+
buffer.outputExpression(`__vite_hmr_script.toString()`, token.filename, token.loc.start.line, false);
|
|
58
|
+
/**
|
|
59
|
+
* Close if block
|
|
60
|
+
*/
|
|
61
|
+
buffer.writeStatement("}", token.filename, token.loc.start.line);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
edge.registerTag({
|
|
65
|
+
tagName: "vite",
|
|
66
|
+
seekable: true,
|
|
67
|
+
block: false,
|
|
68
|
+
compile(parser, buffer, token) {
|
|
69
|
+
/**
|
|
70
|
+
* Ensure an argument is defined
|
|
71
|
+
*/
|
|
72
|
+
if (!token.properties.jsArg.trim()) throw new EdgeError("Missing entrypoint name", "E_RUNTIME_EXCEPTION", {
|
|
73
|
+
filename: token.filename,
|
|
74
|
+
line: token.loc.start.line,
|
|
75
|
+
col: token.loc.start.col
|
|
76
|
+
});
|
|
77
|
+
const parsed = parser.utils.transformAst(parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename), token.filename, parser);
|
|
78
|
+
const entrypoints = parser.utils.stringify(parsed);
|
|
79
|
+
const methodCall = parsed.type === "SequenceExpression" ? `generateEntryPointsTags${entrypoints}` : `generateEntryPointsTags(${entrypoints})`;
|
|
80
|
+
buffer.outputExpression(`(await state.vite.${methodCall}).join('\\n')`, token.filename, token.loc.start.line, false);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
return edgeVite;
|
|
69
85
|
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { edgePluginVite };
|
package/build/src/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//#region src/utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new array with unique items filtered by the specified key
|
|
4
|
+
*
|
|
5
|
+
* @param array - The array to filter for unique items
|
|
6
|
+
* @param key - The key to use for uniqueness comparison
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const users = [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 1, name: 'John' }]
|
|
10
|
+
* const unique = uniqBy(users, 'id')
|
|
11
|
+
* // Returns: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]
|
|
12
|
+
*/
|
|
13
|
+
function uniqBy(array, key) {
|
|
14
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15
|
+
return array.filter((item) => {
|
|
16
|
+
const k = item[key];
|
|
17
|
+
return seen.has(k) ? false : seen.add(k);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Converts an object of HTML attributes to a valid HTML attribute string
|
|
22
|
+
*
|
|
23
|
+
* @param attributes - Object containing HTML attributes where values can be strings or booleans
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const attrs = makeAttributes({ class: 'btn', disabled: true, hidden: false })
|
|
27
|
+
* // Returns: 'class="btn" disabled'
|
|
28
|
+
*/
|
|
29
|
+
function makeAttributes(attributes) {
|
|
30
|
+
return Object.keys(attributes).map((key) => {
|
|
31
|
+
const value = attributes[key];
|
|
32
|
+
if (value === true) return key;
|
|
33
|
+
if (!value) return null;
|
|
34
|
+
return `${key}="${value}"`;
|
|
35
|
+
}).filter((attr) => attr !== null).join(" ");
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Adds a trailing slash to a URL if it doesn't already have one
|
|
39
|
+
*
|
|
40
|
+
* @param url - The URL string to process
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* addTrailingSlash('/api') // Returns: '/api/'
|
|
44
|
+
* addTrailingSlash('/api/') // Returns: '/api/'
|
|
45
|
+
*/
|
|
46
|
+
const addTrailingSlash = (url) => {
|
|
47
|
+
return url.endsWith("/") ? url : `${url}/`;
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { makeAttributes as n, uniqBy as r, addTrailingSlash as t };
|