@adonisjs/vite 4.0.0-beta.0 → 5.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.
@@ -4,16 +4,11 @@ import {
4
4
  } from "./chunk-CFRBPZ4N.js";
5
5
 
6
6
  // src/vite.ts
7
- import { join } from "node:path";
8
- import { readFileSync } from "node:fs";
7
+ import { join } from "path";
8
+ import { existsSync, readFileSync } from "fs";
9
9
  import { slash } from "@poppinss/utils";
10
10
  var styleFileRegex = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\?)/;
11
11
  var Vite = class {
12
- constructor(isViteRunning, options) {
13
- this.isViteRunning = isViteRunning;
14
- this.#options = options;
15
- this.#options.assetsUrl = (this.#options.assetsUrl || "/").replace(/\/$/, "");
16
- }
17
12
  /**
18
13
  * We cache the manifest file content in production
19
14
  * to avoid reading the file multiple times
@@ -22,6 +17,15 @@ var Vite = class {
22
17
  #options;
23
18
  #devServer;
24
19
  #createServerPromise;
20
+ hasManifestFile;
21
+ constructor(options) {
22
+ this.#options = options;
23
+ this.#options.assetsUrl = (this.#options.assetsUrl || "/").replace(/\/$/, "");
24
+ this.hasManifestFile = this.#hasManifestFile();
25
+ }
26
+ #hasManifestFile() {
27
+ return existsSync(this.#options.manifestFile);
28
+ }
25
29
  /**
26
30
  * Reads the file contents as JSON
27
31
  */
@@ -114,7 +118,7 @@ var Vite = class {
114
118
  */
115
119
  #generateTag(asset, attributes) {
116
120
  let url = "";
117
- if (this.isViteRunning) {
121
+ if (!this.hasManifestFile) {
118
122
  url = `/${asset}`;
119
123
  } else {
120
124
  url = this.#generateAssetUrl(asset);
@@ -239,7 +243,7 @@ var Vite = class {
239
243
  */
240
244
  async generateEntryPointsTags(entryPoints, attributes) {
241
245
  entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints];
242
- if (this.isViteRunning) {
246
+ if (!this.hasManifestFile) {
243
247
  return this.#generateEntryPointsTagsForDevMode(entryPoints, attributes);
244
248
  }
245
249
  return this.#generateEntryPointsTagsWithManifest(entryPoints, attributes);
@@ -254,7 +258,7 @@ var Vite = class {
254
258
  * Returns path to a given asset file using the manifest file
255
259
  */
256
260
  assetPath(asset) {
257
- if (this.isViteRunning) {
261
+ if (!this.hasManifestFile) {
258
262
  return `/${asset}`;
259
263
  }
260
264
  const chunk = this.#chunk(this.manifest(), asset);
@@ -266,7 +270,7 @@ var Vite = class {
266
270
  * @throws Will throw an exception when running in dev
267
271
  */
268
272
  manifest() {
269
- if (this.isViteRunning) {
273
+ if (!this.hasManifestFile) {
270
274
  throw new Error("Cannot read the manifest file when running in dev mode");
271
275
  }
272
276
  if (!this.#manifestCache) {
@@ -316,9 +320,7 @@ var Vite = class {
316
320
  * Returns the script needed for the HMR working with React
317
321
  */
318
322
  getReactHmrScript(attributes) {
319
- if (!this.isViteRunning) {
320
- return null;
321
- }
323
+ if (this.hasManifestFile) return null;
322
324
  return this.#generateElement({
323
325
  tag: "script",
324
326
  attributes: {
@@ -341,4 +343,4 @@ var Vite = class {
341
343
  export {
342
344
  Vite
343
345
  };
344
- //# sourceMappingURL=chunk-ODGNORYO.js.map
346
+ //# sourceMappingURL=chunk-XJ432WGI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { slash } from '@poppinss/utils'\nimport { ModuleRunner } from 'vite/module-runner'\nimport type {\n InlineConfig,\n Manifest,\n ModuleNode,\n ViteDevServer,\n ServerModuleRunnerOptions,\n} from 'vite'\n\nimport { makeAttributes, uniqBy } from './utils.js'\nimport type { AdonisViteElement, SetAttributes, ViteOptions } from './types.js'\n\nconst styleFileRegex = /\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)/\n\n/**\n * Vite class exposes the APIs to generate tags and URLs for\n * assets processed using vite.\n */\nexport class Vite {\n /**\n * We cache the manifest file content in production\n * to avoid reading the file multiple times\n */\n #manifestCache?: Manifest\n #options: ViteOptions\n #devServer?: ViteDevServer\n #createServerPromise?: Promise<ViteDevServer>\n hasManifestFile: boolean\n\n constructor(options: ViteOptions) {\n this.#options = options\n this.#options.assetsUrl = (this.#options.assetsUrl || '/').replace(/\\/$/, '')\n this.hasManifestFile = this.#hasManifestFile()\n }\n\n #hasManifestFile() {\n return existsSync(this.#options.manifestFile)\n }\n\n /**\n * Reads the file contents as JSON\n */\n #readFileAsJSON(filePath: string) {\n return JSON.parse(readFileSync(filePath, 'utf-8'))\n }\n\n /**\n * Generates a JSON element with a custom toString implementation\n */\n #generateElement(element: AdonisViteElement) {\n return {\n ...element,\n toString() {\n const attributes = `${makeAttributes(element.attributes)}`\n if (element.tag === 'link') {\n return `<${element.tag} ${attributes}/>`\n }\n\n return `<${element.tag} ${attributes}>${element.children.join('\\n')}</${element.tag}>`\n },\n }\n }\n\n /**\n * Returns the script needed for the HMR working with Vite\n */\n #getViteHmrScript(attributes?: Record<string, any>) {\n return this.#generateElement({\n tag: 'script',\n attributes: {\n type: 'module',\n src: '/@vite/client',\n ...attributes,\n },\n children: [],\n })\n }\n\n /**\n * Check if the given path is a CSS path\n */\n #isCssPath(path: string) {\n return path.match(styleFileRegex) !== null\n }\n\n /**\n * If the module is a style module\n */\n #isStyleModule(mod: ModuleNode) {\n if (this.#isCssPath(mod.url) || (mod.id && /\\?vue&type=style/.test(mod.id))) {\n return true\n }\n return false\n }\n\n /**\n * Unwrap attributes from the user defined function or return\n * the attributes as it is\n */\n #unwrapAttributes(src: string, url: string, attributes?: SetAttributes) {\n if (typeof attributes === 'function') {\n return attributes({ src, url })\n }\n\n return attributes\n }\n\n /**\n * Create a style tag for the given path\n */\n #makeStyleTag(src: string, url: string, attributes?: Record<string, any>): AdonisViteElement {\n const customAttributes = this.#unwrapAttributes(src, url, this.#options?.styleAttributes)\n return this.#generateElement({\n tag: 'link',\n attributes: { rel: 'stylesheet', ...customAttributes, ...attributes, href: url },\n })\n }\n\n /**\n * Create a script tag for the given path\n */\n #makeScriptTag(src: string, url: string, attributes?: Record<string, any>): AdonisViteElement {\n const customAttributes = this.#unwrapAttributes(src, url, this.#options?.scriptAttributes)\n return this.#generateElement({\n tag: 'script',\n attributes: { type: 'module', ...customAttributes, ...attributes, src: url },\n children: [],\n })\n }\n\n /**\n * Generate an asset URL for a given asset path\n */\n #generateAssetUrl(path: string): string {\n return `${this.#options.assetsUrl}/${path}`\n }\n\n /**\n * Generate a HTML tag for the given asset\n */\n #generateTag(asset: string, attributes?: Record<string, any>): AdonisViteElement {\n let url = ''\n if (!this.hasManifestFile) {\n url = `/${asset}`\n } else {\n url = this.#generateAssetUrl(asset)\n }\n\n if (this.#isCssPath(asset)) {\n return this.#makeStyleTag(asset, url, attributes)\n }\n\n return this.#makeScriptTag(asset, url, attributes)\n }\n\n /**\n * Collect CSS files from the module graph recursively\n */\n #collectCss(\n mod: ModuleNode,\n styleUrls: Set<string>,\n visitedModules: Set<string>,\n importer?: ModuleNode\n ): void {\n if (!mod.url) return\n\n /**\n * Prevent visiting the same module twice\n */\n if (visitedModules.has(mod.url)) return\n visitedModules.add(mod.url)\n\n if (this.#isStyleModule(mod) && (!importer || !this.#isStyleModule(importer))) {\n if (mod.url.startsWith('/')) {\n styleUrls.add(mod.url)\n } else if (mod.url.startsWith('\\0')) {\n // virtual modules are prefixed with \\0\n styleUrls.add(`/@id/__x00__${mod.url.substring(1)}`)\n } else {\n styleUrls.add(`/@id/${mod.url}`)\n }\n }\n\n mod.importedModules.forEach((dep) => this.#collectCss(dep, styleUrls, visitedModules, mod))\n }\n\n /**\n * Generate style and script tags for the given entrypoints\n * Also adds the @vite/client script\n */\n async #generateEntryPointsTagsForDevMode(\n entryPoints: string[],\n attributes?: Record<string, any>\n ): Promise<AdonisViteElement[]> {\n const server = this.getDevServer()!\n\n const tags = entryPoints.map((entrypoint) => this.#generateTag(entrypoint, attributes))\n const jsEntrypoints = entryPoints.filter((entrypoint) => !this.#isCssPath(entrypoint))\n\n /**\n * If the module graph is empty, that means we didn't execute the entrypoint\n * yet : we just started the AdonisJS dev server.\n * So let's execute the entrypoints to populate the module graph\n */\n if (server?.moduleGraph.idToModuleMap.size === 0) {\n await Promise.allSettled(\n jsEntrypoints.map((entrypoint) => server.warmupRequest(`/${entrypoint}`))\n )\n }\n\n /**\n * We need to collect the CSS files imported by the entrypoints\n * Otherwise, we gonna have a FOUC each time we full reload the page\n */\n const preloadUrls = new Set<string>()\n const visitedModules = new Set<string>()\n const cssTagsElement = new Set<AdonisViteElement>()\n\n /**\n * Let's search for the CSS files by browsing the module graph\n * generated by Vite.\n */\n for (const entryPoint of jsEntrypoints) {\n const filePath = join(server.config.root, entryPoint)\n const entryMod = server.moduleGraph.getModuleById(slash(filePath))\n if (entryMod) this.#collectCss(entryMod, preloadUrls, visitedModules)\n }\n\n /**\n * Once we have the CSS files, generate associated tags\n * that will be injected into the HTML\n */\n const elements = Array.from(preloadUrls).map((href) =>\n this.#generateElement({\n tag: 'link',\n attributes: { rel: 'stylesheet', as: 'style', href: href },\n })\n )\n elements.forEach((element) => cssTagsElement.add(element))\n\n const viteHmr = this.#getViteHmrScript(attributes)\n const result = [...cssTagsElement, viteHmr].concat(tags)\n\n return result.sort((tag) => (tag.tag === 'link' ? -1 : 1))\n }\n\n /**\n * Get a chunk from the manifest file for a given file name\n */\n #chunk(manifest: Manifest, entrypoint: string) {\n const chunk = manifest[entrypoint]\n\n if (!chunk) {\n throw new Error(`Cannot find \"${entrypoint}\" chunk in the manifest file`)\n }\n\n return chunk\n }\n\n /**\n * Get a list of chunks for a given filename\n */\n #chunksByFile(manifest: Manifest, file: string) {\n return Object.entries(manifest)\n .filter(([, chunk]) => chunk.file === file)\n .map(([_, chunk]) => chunk)\n }\n\n /**\n * Generate preload tag for a given url\n */\n #makePreloadTagForUrl(url: string) {\n const attributes = this.#isCssPath(url)\n ? { rel: 'preload', as: 'style', href: url }\n : { rel: 'modulepreload', href: url }\n\n return this.#generateElement({ tag: 'link', attributes })\n }\n\n /**\n * Generate style and script tags for the given entrypoints\n * using the manifest file\n */\n #generateEntryPointsTagsWithManifest(\n entryPoints: string[],\n attributes?: Record<string, any>\n ): AdonisViteElement[] {\n const manifest = this.manifest()\n const tags: { path: string; tag: AdonisViteElement }[] = []\n const preloads: Array<{ path: string }> = []\n\n for (const entryPoint of entryPoints) {\n /**\n * 1. We generate tags + modulepreload for the entrypoint\n */\n const chunk = this.#chunk(manifest, entryPoint)\n preloads.push({ path: this.#generateAssetUrl(chunk.file) })\n tags.push({\n path: chunk.file,\n tag: this.#generateTag(chunk.file, { ...attributes, integrity: chunk.integrity }),\n })\n\n /**\n * 2. We go through the CSS files that are imported by the entrypoint\n * and generate tags + preload for them\n */\n for (const css of chunk.css || []) {\n preloads.push({ path: this.#generateAssetUrl(css) })\n tags.push({ path: css, tag: this.#generateTag(css) })\n }\n\n /**\n * 3. We go through every import of the entrypoint and generate preload\n */\n for (const importNode of chunk.imports || []) {\n preloads.push({ path: this.#generateAssetUrl(manifest[importNode].file) })\n\n /**\n * 4. Finally, we generate tags + preload for the CSS files imported by the import\n * of the entrypoint\n */\n for (const css of manifest[importNode].css || []) {\n const subChunk = this.#chunksByFile(manifest, css)\n\n preloads.push({ path: this.#generateAssetUrl(css) })\n tags.push({\n path: this.#generateAssetUrl(css),\n tag: this.#generateTag(css, {\n ...attributes,\n integrity: subChunk[0]?.integrity,\n }),\n })\n }\n }\n }\n\n /**\n * We sort the preload to ensure that CSS files are preloaded first\n */\n const preloadsElements = uniqBy(preloads, 'path')\n .sort((preload) => (this.#isCssPath(preload.path) ? -1 : 1))\n .map((preload) => this.#makePreloadTagForUrl(preload.path))\n\n /**\n * And finally, we return the preloads + script and link tags\n */\n return preloadsElements.concat(tags.map(({ tag }) => tag))\n }\n\n /**\n * Generate tags for the entry points\n */\n async generateEntryPointsTags(\n entryPoints: string[] | string,\n attributes?: Record<string, any>\n ): Promise<AdonisViteElement[]> {\n entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints]\n\n if (!this.hasManifestFile) {\n return this.#generateEntryPointsTagsForDevMode(entryPoints, attributes)\n }\n\n return this.#generateEntryPointsTagsWithManifest(entryPoints, attributes)\n }\n\n /**\n * Returns the explicitly configured assetsUrl\n */\n assetsUrl() {\n return this.#options.assetsUrl\n }\n\n /**\n * Returns path to a given asset file using the manifest file\n */\n assetPath(asset: string): string {\n if (!this.hasManifestFile) {\n return `/${asset}`\n }\n\n const chunk = this.#chunk(this.manifest(), asset)\n return this.#generateAssetUrl(chunk.file)\n }\n\n /**\n * Returns the manifest file contents\n *\n * @throws Will throw an exception when running in dev\n */\n manifest(): Manifest {\n if (!this.hasManifestFile) {\n throw new Error('Cannot read the manifest file when running in dev mode')\n }\n\n if (!this.#manifestCache) {\n this.#manifestCache = this.#readFileAsJSON(this.#options.manifestFile)\n }\n\n return this.#manifestCache!\n }\n\n /**\n * Create the Vite Dev Server and runtime\n *\n * We lazy load the APIs to avoid loading it in production\n * since we don't need it\n */\n async createDevServer(options?: InlineConfig) {\n const { createServer } = await import('vite')\n\n /**\n * We do not await the server creation since it will\n * slow down the boot process of AdonisJS\n */\n this.#createServerPromise = createServer({\n server: { middlewareMode: true },\n appType: 'custom',\n ...options,\n })\n\n this.#devServer = await this.#createServerPromise\n }\n\n /**\n * Create a serverModuleRunner instance\n * Will not be available when running in production since\n * it needs the Vite Dev server\n */\n async createModuleRunner(options: ServerModuleRunnerOptions = {}): Promise<ModuleRunner> {\n const { createServerModuleRunner } = await import('vite')\n return createServerModuleRunner(this.#devServer!.environments.ssr, options)\n }\n\n /**\n * Stop the Vite Dev server\n */\n async stopDevServer() {\n await this.#createServerPromise\n await this.#devServer?.close()\n }\n\n /**\n * Get the Vite Dev server instance\n * Will not be available when running in production\n */\n getDevServer() {\n return this.#devServer\n }\n\n /**\n * Returns the script needed for the HMR working with React\n */\n getReactHmrScript(attributes?: Record<string, any>): AdonisViteElement | null {\n if (this.hasManifestFile) return null\n\n return this.#generateElement({\n tag: 'script',\n attributes: {\n type: 'module',\n ...attributes,\n },\n children: [\n '',\n `import RefreshRuntime from '/@react-refresh'`,\n `RefreshRuntime.injectIntoGlobalHook(window)`,\n `window.$RefreshReg$ = () => {}`,\n `window.$RefreshSig$ = () => (type) => type`,\n `window.__vite_plugin_react_preamble_installed__ = true`,\n '',\n ],\n })\n }\n}\n"],"mappings":";;;;;;AASA,SAAS,YAAY;AACrB,SAAS,YAAY,oBAAoB;AACzC,SAAS,aAAa;AAatB,IAAM,iBAAiB;AAMhB,IAAM,OAAN,MAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAKhB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,SAAsB;AAChC,SAAK,WAAW;AAChB,SAAK,SAAS,aAAa,KAAK,SAAS,aAAa,KAAK,QAAQ,OAAO,EAAE;AAC5E,SAAK,kBAAkB,KAAK,iBAAiB;AAAA,EAC/C;AAAA,EAEA,mBAAmB;AACjB,WAAO,WAAW,KAAK,SAAS,YAAY;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB,UAAkB;AAChC,WAAO,KAAK,MAAM,aAAa,UAAU,OAAO,CAAC;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA,EAKA,iBAAiB,SAA4B;AAC3C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,WAAW;AACT,cAAM,aAAa,GAAG,eAAe,QAAQ,UAAU,CAAC;AACxD,YAAI,QAAQ,QAAQ,QAAQ;AAC1B,iBAAO,IAAI,QAAQ,GAAG,IAAI,UAAU;AAAA,QACtC;AAEA,eAAO,IAAI,QAAQ,GAAG,IAAI,UAAU,IAAI,QAAQ,SAAS,KAAK,IAAI,CAAC,KAAK,QAAQ,GAAG;AAAA,MACrF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,kBAA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A;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAAgB,SAAwB;AAC5C,UAAM,EAAE,aAAa,IAAI,MAAM,OAAO,MAAM;AAM5C,SAAK,uBAAuB,aAAa;AAAA,MACvC,QAAQ,EAAE,gBAAgB,KAAK;AAAA,MAC/B,SAAS;AAAA,MACT,GAAG;AAAA,IACL,CAAC;AAED,SAAK,aAAa,MAAM,KAAK;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,mBAAmB,UAAqC,CAAC,GAA0B;AACvF,UAAM,EAAE,yBAAyB,IAAI,MAAM,OAAO,MAAM;AACxD,WAAO,yBAAyB,KAAK,WAAY,aAAa,KAAK,OAAO;AAAA,EAC5E;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,gBAAgB;AACpB,UAAM,KAAK;AACX,UAAM,KAAK,YAAY,MAAM;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe;AACb,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAkB,YAA4D;AAC5E,QAAI,KAAK,gBAAiB,QAAO;AAEjC,WAAO,KAAK,iBAAiB;AAAA,MAC3B,KAAK;AAAA,MACL,YAAY;AAAA,QACV,MAAM;AAAA,QACN,GAAG;AAAA,MACL;AAAA,MACA,UAAU;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
package/build/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Vite
3
- } from "./chunk-ODGNORYO.js";
3
+ } from "./chunk-XJ432WGI.js";
4
4
  import "./chunk-CFRBPZ4N.js";
5
5
 
6
6
  // stubs/main.ts
@@ -43,7 +43,7 @@ async function configure(command) {
43
43
  }
44
44
 
45
45
  // src/define_config.ts
46
- import { join } from "node:path";
46
+ import { join } from "path";
47
47
  function defineConfig(config) {
48
48
  return {
49
49
  buildDirectory: "public/assets",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Vite
3
- } from "../chunk-ODGNORYO.js";
3
+ } from "../chunk-XJ432WGI.js";
4
4
  import {
5
5
  ViteMiddleware
6
6
  } from "../chunk-H2XHWF4X.js";
@@ -10,10 +10,8 @@ import "../chunk-CFRBPZ4N.js";
10
10
  var ViteProvider = class {
11
11
  constructor(app) {
12
12
  this.app = app;
13
- const env = this.app.getEnvironment();
14
- this.#shouldRunVite = (this.app.inDev || this.app.inTest) && (env === "web" || env === "test");
15
13
  }
16
- #shouldRunVite;
14
+ #shouldRunViteDevServer = false;
17
15
  /**
18
16
  * Registers edge plugin when edge is installed
19
17
  */
@@ -49,8 +47,10 @@ var ViteProvider = class {
49
47
  * Register Vite bindings
50
48
  */
51
49
  register() {
52
- const config = this.app.config.get("vite");
53
- const vite = new Vite(this.#shouldRunVite, config);
50
+ const appEnvironment = this.app.getEnvironment();
51
+ const isWebOrTestEnvironment = appEnvironment === "web" || appEnvironment === "test";
52
+ const vite = new Vite(this.app.config.get("vite"));
53
+ this.#shouldRunViteDevServer = !vite.hasManifestFile && isWebOrTestEnvironment;
54
54
  this.app.container.bind("vite", () => vite);
55
55
  this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite));
56
56
  }
@@ -60,7 +60,7 @@ var ViteProvider = class {
60
60
  */
61
61
  async boot() {
62
62
  await this.registerEdgePlugin();
63
- if (!this.#shouldRunVite) return;
63
+ if (!this.#shouldRunViteDevServer) return;
64
64
  const vite = await this.app.container.make("vite");
65
65
  await vite.createDevServer();
66
66
  }
@@ -68,7 +68,7 @@ var ViteProvider = class {
68
68
  * Stop Vite server when running in development or test
69
69
  */
70
70
  async shutdown() {
71
- if (!this.#shouldRunVite) return;
71
+ if (!this.#shouldRunViteDevServer) return;
72
72
  const vite = await this.app.container.make("vite");
73
73
  await vite.stopDevServer();
74
74
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../providers/vite_provider.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ApplicationService } from '@adonisjs/core/types'\nimport type { cspKeywords as ShieldCSPKeywords } from '@adonisjs/shield'\n\nimport { Vite } from '../src/vite.js'\nimport type { ViteOptions } from '../src/types.js'\nimport ViteMiddleware from '../src/vite_middleware.js'\n\ndeclare module '@adonisjs/core/types' {\n interface ContainerBindings {\n vite: Vite\n }\n}\n\nexport default class ViteProvider {\n #shouldRunVite: boolean\n\n constructor(protected app: ApplicationService) {\n /**\n * We should only run Vite in development and test environments\n */\n const env = this.app.getEnvironment()\n this.#shouldRunVite = (this.app.inDev || this.app.inTest) && (env === 'web' || env === 'test')\n }\n\n /**\n * Registers edge plugin when edge is installed\n */\n protected async registerEdgePlugin() {\n if (this.app.usingEdgeJS) {\n const edge = await import('edge.js')\n const vite = await this.app.container.make('vite')\n const { edgePluginVite } = await import('../src/plugins/edge.js')\n edge.default.use(edgePluginVite(vite))\n }\n }\n\n /**\n * Registers CSP keywords when @adonisjs/shield is installed\n */\n protected async registerShieldKeywords() {\n let cspKeywords: typeof ShieldCSPKeywords | null = null\n try {\n const shieldExports = await import('@adonisjs/shield')\n cspKeywords = shieldExports.cspKeywords\n } catch {}\n\n if (!cspKeywords) return\n\n const vite = await this.app.container.make('vite')\n\n /**\n * Registering the @viteUrl keyword for CSP directives.\n * Returns http URL to the dev or the CDN server, otherwise\n * an empty string\n */\n cspKeywords.register('@viteUrl', function () {\n const assetsURL = vite.assetsUrl()\n if (!assetsURL || !assetsURL.startsWith('http://') || assetsURL.startsWith('https://')) {\n return ''\n }\n\n return assetsURL\n })\n }\n\n /**\n * Register Vite bindings\n */\n register() {\n const config = this.app.config.get<ViteOptions>('vite')\n\n const vite = new Vite(this.#shouldRunVite, config)\n this.app.container.bind('vite', () => vite)\n this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite))\n }\n\n /**\n * - Register edge tags\n * - Start Vite server when running in development or test\n */\n async boot() {\n await this.registerEdgePlugin()\n\n if (!this.#shouldRunVite) return\n\n const vite = await this.app.container.make('vite')\n await vite.createDevServer()\n }\n\n /**\n * Stop Vite server when running in development or test\n */\n async shutdown() {\n if (!this.#shouldRunVite) return\n\n const vite = await this.app.container.make('vite')\n await vite.stopDevServer()\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,IAAqB,eAArB,MAAkC;AAAA,EAGhC,YAAsB,KAAyB;AAAzB;AAIpB,UAAM,MAAM,KAAK,IAAI,eAAe;AACpC,SAAK,kBAAkB,KAAK,IAAI,SAAS,KAAK,IAAI,YAAY,QAAQ,SAAS,QAAQ;AAAA,EACzF;AAAA,EARA;AAAA;AAAA;AAAA;AAAA,EAaA,MAAgB,qBAAqB;AACnC,QAAI,KAAK,IAAI,aAAa;AACxB,YAAM,OAAO,MAAM,OAAO,SAAS;AACnC,YAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,YAAM,EAAE,eAAe,IAAI,MAAM,OAAO,wBAAwB;AAChE,WAAK,QAAQ,IAAI,eAAe,IAAI,CAAC;AAAA,IACvC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,yBAAyB;AACvC,QAAI,cAA+C;AACnD,QAAI;AACF,YAAM,gBAAgB,MAAM,OAAO,kBAAkB;AACrD,oBAAc,cAAc;AAAA,IAC9B,QAAQ;AAAA,IAAC;AAET,QAAI,CAAC,YAAa;AAElB,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AAOjD,gBAAY,SAAS,YAAY,WAAY;AAC3C,YAAM,YAAY,KAAK,UAAU;AACjC,UAAI,CAAC,aAAa,CAAC,UAAU,WAAW,SAAS,KAAK,UAAU,WAAW,UAAU,GAAG;AACtF,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACT,UAAM,SAAS,KAAK,IAAI,OAAO,IAAiB,MAAM;AAEtD,UAAM,OAAO,IAAI,KAAK,KAAK,gBAAgB,MAAM;AACjD,SAAK,IAAI,UAAU,KAAK,QAAQ,MAAM,IAAI;AAC1C,SAAK,IAAI,UAAU,UAAU,gBAAgB,MAAM,IAAI,eAAe,IAAI,CAAC;AAAA,EAC7E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO;AACX,UAAM,KAAK,mBAAmB;AAE9B,QAAI,CAAC,KAAK,eAAgB;AAE1B,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,UAAM,KAAK,gBAAgB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW;AACf,QAAI,CAAC,KAAK,eAAgB;AAE1B,UAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,UAAM,KAAK,cAAc;AAAA,EAC3B;AACF;","names":[]}
1
+ {"version":3,"sources":["../../providers/vite_provider.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ApplicationService } from '@adonisjs/core/types'\nimport type { cspKeywords as ShieldCSPKeywords } from '@adonisjs/shield'\n\nimport { Vite } from '../src/vite.js'\nimport type { ViteOptions } from '../src/types.js'\nimport ViteMiddleware from '../src/vite_middleware.js'\n\ndeclare module '@adonisjs/core/types' {\n interface ContainerBindings {\n vite: Vite\n }\n}\n\nexport default class ViteProvider {\n #shouldRunViteDevServer = false\n\n constructor(protected app: ApplicationService) {}\n\n /**\n * Registers edge plugin when edge is installed\n */\n protected async registerEdgePlugin() {\n if (this.app.usingEdgeJS) {\n const edge = await import('edge.js')\n const vite = await this.app.container.make('vite')\n const { edgePluginVite } = await import('../src/plugins/edge.js')\n edge.default.use(edgePluginVite(vite))\n }\n }\n\n /**\n * Registers CSP keywords when @adonisjs/shield is installed\n */\n protected async registerShieldKeywords() {\n let cspKeywords: typeof ShieldCSPKeywords | null = null\n try {\n const shieldExports = await import('@adonisjs/shield')\n cspKeywords = shieldExports.cspKeywords\n } catch {}\n\n if (!cspKeywords) return\n\n const vite = await this.app.container.make('vite')\n\n /**\n * Registering the @viteUrl keyword for CSP directives.\n * Returns http URL to the dev or the CDN server, otherwise\n * an empty string\n */\n cspKeywords.register('@viteUrl', function () {\n const assetsURL = vite.assetsUrl()\n if (!assetsURL || !assetsURL.startsWith('http://') || assetsURL.startsWith('https://')) {\n return ''\n }\n\n return assetsURL\n })\n }\n\n /**\n * Register Vite bindings\n */\n register() {\n const appEnvironment = this.app.getEnvironment()\n const isWebOrTestEnvironment = appEnvironment === 'web' || appEnvironment === 'test'\n\n const vite = new Vite(this.app.config.get<ViteOptions>('vite'))\n this.#shouldRunViteDevServer = !vite.hasManifestFile && isWebOrTestEnvironment\n\n this.app.container.bind('vite', () => vite)\n this.app.container.singleton(ViteMiddleware, () => new ViteMiddleware(vite))\n }\n\n /**\n * - Register edge tags\n * - Start Vite server when running in development or test\n */\n async boot() {\n await this.registerEdgePlugin()\n\n if (!this.#shouldRunViteDevServer) return\n\n const vite = await this.app.container.make('vite')\n await vite.createDevServer()\n }\n\n /**\n * Stop Vite server when running in development or test\n */\n async shutdown() {\n if (!this.#shouldRunViteDevServer) return\n\n const vite = await this.app.container.make('vite')\n await vite.stopDevServer()\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,IAAqB,eAArB,MAAkC;AAAA,EAGhC,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAFhD,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAO1B,MAAgB,qBAAqB;AACnC,QAAI,KAAK,IAAI,aAAa;AACxB,YAAM,OAAO,MAAM,OAAO,SAAS;AACnC,YAAM,OAAO,MAAM,KAAK,IAAI,UAAU,KAAK,MAAM;AACjD,YAAM,EAAE,eAAe,IAAI,MAAM,OAAO,wBAAwB;AACh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A,EAC3B;AACF;","names":[]}
@@ -6,7 +6,7 @@ import {
6
6
  import PluginRestart from "vite-plugin-restart";
7
7
 
8
8
  // src/client/config.ts
9
- import { join } from "node:path";
9
+ import { join } from "path";
10
10
  function resolveBase(config2, options, command) {
11
11
  if (config2.base) return config2.base;
12
12
  if (command === "build") {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/main.ts","../../../src/client/config.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference types=\"@vavite/multibuild\" />\n\nimport { PluginOption } from 'vite'\nimport PluginRestart from 'vite-plugin-restart'\n\nimport { config } from './config.js'\nimport type { PluginOptions } from './types.js'\n\ndeclare module 'vite' {\n interface ManifestChunk {\n integrity: string\n }\n}\n\n/**\n * Vite plugin for AdonisJS\n */\nexport default function adonisjs(options: PluginOptions): PluginOption[] {\n const fullOptions = Object.assign(\n {\n assetsUrl: '/assets',\n buildDirectory: 'public/assets',\n reload: ['./resources/views/**/*.edge'],\n },\n options\n )\n\n return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)]\n}\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport type { ConfigEnv, Plugin, UserConfig } from 'vite'\n\nimport { addTrailingSlash } from '../utils.js'\nimport type { PluginFullOptions } from './types.js'\n\n/**\n * Resolve the `config.base` value\n */\nexport function resolveBase(\n config: UserConfig,\n options: PluginFullOptions,\n command: 'build' | 'serve'\n): string {\n if (config.base) return config.base\n if (command === 'build') {\n return addTrailingSlash(options.assetsUrl)\n }\n\n return '/'\n}\n\n/**\n * Vite config hook\n */\nexport function configHook(\n options: PluginFullOptions,\n userConfig: UserConfig,\n { command }: ConfigEnv\n): UserConfig {\n const config: UserConfig = {\n publicDir: userConfig.publicDir ?? false,\n base: resolveBase(userConfig, options, command),\n\n /**\n * Disable the vite dev server cors handling. Otherwise, it will\n * override the cors settings defined by @adonisjs/cors\n * https://github.com/adonisjs/vite/issues/13\n */\n server: { cors: userConfig.server?.cors ?? false },\n\n build: {\n assetsDir: '',\n emptyOutDir: true,\n manifest: userConfig.build?.manifest ?? true,\n outDir: userConfig.build?.outDir ?? options.buildDirectory,\n assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,\n\n rollupOptions: {\n input: options.entrypoints.map((entrypoint) => join(userConfig.root || '', entrypoint)),\n },\n },\n }\n\n return config\n}\n\n/**\n * Update the user vite config to match the Adonis requirements\n */\nexport const config = (options: PluginFullOptions): Plugin => {\n return {\n name: 'vite-plugin-adonis:config',\n enforce: 'post',\n config: configHook.bind(null, options),\n }\n}\n"],"mappings":";;;;;AAYA,OAAO,mBAAmB;;;ACH1B,SAAS,YAAY;AASd,SAAS,YACdA,SACA,SACA,SACQ;AACR,MAAIA,QAAO,KAAM,QAAOA,QAAO;AAC/B,MAAI,YAAY,SAAS;AACvB,WAAO,iBAAiB,QAAQ,SAAS;AAAA,EAC3C;AAEA,SAAO;AACT;AAKO,SAAS,WACd,SACA,YACA,EAAE,QAAQ,GACE;AACZ,QAAMA,UAAqB;AAAA,IACzB,WAAW,WAAW,aAAa;AAAA,IACnC,MAAM,YAAY,YAAY,SAAS,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO9C,QAAQ,EAAE,MAAM,WAAW,QAAQ,QAAQ,MAAM;AAAA,IAEjD,OAAO;AAAA,MACL,WAAW;AAAA,MACX,aAAa;AAAA,MACb,UAAU,WAAW,OAAO,YAAY;AAAA,MACxC,QAAQ,WAAW,OAAO,UAAU,QAAQ;AAAA,MAC5C,mBAAmB,WAAW,OAAO,qBAAqB;AAAA,MAE1D,eAAe;AAAA,QACb,OAAO,QAAQ,YAAY,IAAI,CAAC,eAAe,KAAK,WAAW,QAAQ,IAAI,UAAU,CAAC;AAAA,MACxF;AAAA,IACF;AAAA,EACF;AAEA,SAAOA;AACT;AAKO,IAAM,SAAS,CAAC,YAAuC;AAC5D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ,WAAW,KAAK,MAAM,OAAO;AAAA,EACvC;AACF;;;ADjDe,SAAR,SAA0B,SAAwC;AACvE,QAAM,cAAc,OAAO;AAAA,IACzB;AAAA,MACE,WAAW;AAAA,MACX,gBAAgB;AAAA,MAChB,QAAQ,CAAC,6BAA6B;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,CAAC,cAAc,EAAE,QAAQ,YAAY,OAAO,CAAC,GAAG,OAAO,WAAW,CAAC;AAC5E;","names":["config"]}
1
+ {"version":3,"sources":["../../../src/client/main.ts","../../../src/client/config.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { PluginOption } from 'vite'\nimport PluginRestart from 'vite-plugin-restart'\n\nimport { config } from './config.js'\nimport type { PluginOptions } from './types.js'\n\ndeclare module 'vite' {\n interface ManifestChunk {\n integrity: string\n }\n}\n\n/**\n * Vite plugin for AdonisJS\n */\nexport default function adonisjs(options: PluginOptions): PluginOption[] {\n const fullOptions = Object.assign(\n {\n assetsUrl: '/assets',\n buildDirectory: 'public/assets',\n reload: ['./resources/views/**/*.edge'],\n },\n options\n )\n\n return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)]\n}\n","/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport type { ConfigEnv, Plugin, UserConfig } from 'vite'\n\nimport { addTrailingSlash } from '../utils.js'\nimport type { PluginFullOptions } from './types.js'\n\n/**\n * Resolve the `config.base` value\n */\nexport function resolveBase(\n config: UserConfig,\n options: PluginFullOptions,\n command: 'build' | 'serve'\n): string {\n if (config.base) return config.base\n if (command === 'build') {\n return addTrailingSlash(options.assetsUrl)\n }\n\n return '/'\n}\n\n/**\n * Vite config hook\n */\nexport function configHook(\n options: PluginFullOptions,\n userConfig: UserConfig,\n { command }: ConfigEnv\n): UserConfig {\n const config: UserConfig = {\n publicDir: userConfig.publicDir ?? false,\n base: resolveBase(userConfig, options, command),\n\n /**\n * Disable the vite dev server cors handling. Otherwise, it will\n * override the cors settings defined by @adonisjs/cors\n * https://github.com/adonisjs/vite/issues/13\n */\n server: { cors: userConfig.server?.cors ?? false },\n\n build: {\n assetsDir: '',\n emptyOutDir: true,\n manifest: userConfig.build?.manifest ?? true,\n outDir: userConfig.build?.outDir ?? options.buildDirectory,\n assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,\n\n rollupOptions: {\n input: options.entrypoints.map((entrypoint) => join(userConfig.root || '', entrypoint)),\n },\n },\n }\n\n return config\n}\n\n/**\n * Update the user vite config to match the Adonis requirements\n */\nexport const config = (options: PluginFullOptions): Plugin => {\n return {\n name: 'vite-plugin-adonis:config',\n enforce: 'post',\n config: configHook.bind(null, options),\n }\n}\n"],"mappings":";;;;;AAUA,OAAO,mBAAmB;;;ACD1B,SAAS,YAAY;AASd,SAAS,YACdA,SACA,SACA,SACQ;AACR,MAAIA,QAAO,KAAM,QAAOA,QAAO;AAC/B,MAAI,YAAY,SAAS;AACvB,WAAO,iBAAiB,QAAQ,SAAS;AAAA,EAC3C;AAEA,SAAO;AACT;AAKO,SAAS,WACd,SACA,YACA,EAAE,QAAQ,GACE;AACZ,QAAMA,UAAqB;AAAA,IACzB,WAAW,WAAW,aAAa;AAAA,IACnC,MAAM,YAAY,YAAY,SAAS,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO9C,QAAQ,EAAE,MAAM,WAAW,QAAQ,QAAQ,MAAM;AAAA,IAEjD,OAAO;AAAA,MACL,WAAW;AAAA,MACX,aAAa;AAAA,MACb,UAAU,WAAW,OAAO,YAAY;AAAA,MACxC,QAAQ,WAAW,OAAO,UAAU,QAAQ;AAAA,MAC5C,mBAAmB,WAAW,OAAO,qBAAqB;AAAA,MAE1D,eAAe;AAAA,QACb,OAAO,QAAQ,YAAY,IAAI,CAAC,eAAe,KAAK,WAAW,QAAQ,IAAI,UAAU,CAAC;AAAA,MACxF;AAAA,IACF;AAAA,EACF;AAEA,SAAOA;AACT;AAKO,IAAM,SAAS,CAAC,YAAuC;AAC5D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ,WAAW,KAAK,MAAM,OAAO;AAAA,EACvC;AACF;;;ADnDe,SAAR,SAA0B,SAAwC;AACvE,QAAM,cAAc,OAAO;AAAA,IACzB;AAAA,MACE,WAAW;AAAA,MACX,gBAAgB;AAAA,MAChB,QAAQ,CAAC,6BAA6B;AAAA,IACxC;AAAA,IACA;AAAA,EACF;AAEA,SAAO,CAAC,cAAc,EAAE,QAAQ,YAAY,OAAO,CAAC,GAAG,OAAO,WAAW,CAAC;AAC5E;","names":["config"]}
@@ -1,13 +1,9 @@
1
1
  // src/hooks/build_hook.ts
2
- import { multibuild } from "@vavite/multibuild";
2
+ import { createBuilder } from "vite";
3
3
  async function viteBuildHook({ logger }) {
4
4
  logger.info("building assets with vite");
5
- await multibuild(void 0, {
6
- onStartBuildStep: (step) => {
7
- if (!step.currentStep.description) return;
8
- logger.info(step.currentStep.description);
9
- }
10
- });
5
+ const builder = await createBuilder({}, null);
6
+ await builder.buildApp();
11
7
  }
12
8
  export {
13
9
  viteBuildHook as default
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/hooks/build_hook.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { multibuild } from '@vavite/multibuild'\nimport type { AssemblerHookHandler } from '@adonisjs/core/types/app'\n\n/**\n * This is an Assembler hook that should be executed when the application is\n * builded using the `node ace build` command.\n *\n * The hook is responsible for launching a Vite multi-build process.\n */\nexport default async function viteBuildHook({ logger }: Parameters<AssemblerHookHandler>[0]) {\n logger.info('building assets with vite')\n\n await multibuild(undefined, {\n onStartBuildStep: (step) => {\n if (!step.currentStep.description) return\n\n logger.info(step.currentStep.description)\n },\n })\n}\n"],"mappings":";AASA,SAAS,kBAAkB;AAS3B,eAAO,cAAqC,EAAE,OAAO,GAAwC;AAC3F,SAAO,KAAK,2BAA2B;AAEvC,QAAM,WAAW,QAAW;AAAA,IAC1B,kBAAkB,CAAC,SAAS;AAC1B,UAAI,CAAC,KAAK,YAAY,YAAa;AAEnC,aAAO,KAAK,KAAK,YAAY,WAAW;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/hooks/build_hook.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { createBuilder } from 'vite'\nimport type { AssemblerHookHandler } from '@adonisjs/core/types/app'\n\n/**\n * This is an Assembler hook that should be executed when the application is\n * builded using the `node ace build` command.\n *\n * The hook is responsible for launching a Vite multi-build process.\n */\nexport default async function viteBuildHook({ logger }: Parameters<AssemblerHookHandler>[0]) {\n logger.info('building assets with vite')\n\n const builder = await createBuilder({}, null)\n await builder.buildApp()\n}\n"],"mappings":";AASA,SAAS,qBAAqB;AAS9B,eAAO,cAAqC,EAAE,OAAO,GAAwC;AAC3F,SAAO,KAAK,2BAA2B;AAEvC,QAAM,UAAU,MAAM,cAAc,CAAC,GAAG,IAAI;AAC5C,QAAM,QAAQ,SAAS;AACzB;","names":[]}
@@ -7,8 +7,8 @@ import type { AdonisViteElement, ViteOptions } from './types.js';
7
7
  */
8
8
  export declare class Vite {
9
9
  #private;
10
- protected isViteRunning: boolean;
11
- constructor(isViteRunning: boolean, options: ViteOptions);
10
+ hasManifestFile: boolean;
11
+ constructor(options: ViteOptions);
12
12
  /**
13
13
  * Generate tags for the entry points
14
14
  */
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@adonisjs/vite",
3
3
  "description": "Vite plugin for AdonisJS",
4
- "version": "4.0.0-beta.0",
4
+ "version": "5.0.0-next.0",
5
5
  "engines": {
6
- "node": ">=20.6.0"
6
+ "node": ">=22.17.1"
7
7
  },
8
8
  "main": "build/index.js",
9
9
  "type": "module",
@@ -40,46 +40,45 @@
40
40
  "prepublishOnly": "npm run build"
41
41
  },
42
42
  "devDependencies": {
43
- "@adonisjs/assembler": "^7.7.0",
44
- "@adonisjs/core": "6.9.1",
45
- "@adonisjs/eslint-config": "^1.3.0",
46
- "@adonisjs/prettier-config": "^1.3.0",
47
- "@adonisjs/session": "^7.4.0",
48
- "@adonisjs/shield": "^8.1.1",
49
- "@adonisjs/tsconfig": "^1.3.0",
43
+ "@adonisjs/assembler": "^7.8.2",
44
+ "@adonisjs/core": "6.16.0",
45
+ "@adonisjs/eslint-config": "^2.1.0",
46
+ "@adonisjs/prettier-config": "^1.4.5",
47
+ "@adonisjs/session": "^7.5.1",
48
+ "@adonisjs/shield": "^8.2.0",
49
+ "@adonisjs/tsconfig": "^1.4.1",
50
50
  "@japa/assert": "3.0.0",
51
- "@japa/file-system": "^2.3.0",
51
+ "@japa/file-system": "^2.3.2",
52
52
  "@japa/runner": "3.1.4",
53
- "@japa/snapshot": "^2.0.5",
54
- "@release-it/conventional-changelog": "^9.0.3",
55
- "@swc/core": "^1.5.24",
56
- "@types/node": "^20.13.0",
57
- "@types/supertest": "^6.0.2",
58
- "c8": "^9.1.0",
53
+ "@japa/snapshot": "^2.0.8",
54
+ "@release-it/conventional-changelog": "^10.0.1",
55
+ "@swc/core": "^1.13.1",
56
+ "@types/node": "^24.0.15",
57
+ "@types/supertest": "^6.0.3",
58
+ "c8": "^10.1.3",
59
59
  "copyfiles": "^2.4.1",
60
- "del-cli": "^5.1.0",
61
- "edge.js": "^6.0.2",
62
- "eslint": "^8.57.0",
63
- "prettier": "^3.3.0",
64
- "release-it": "^17.3.0",
65
- "supertest": "^6.3.4",
66
- "ts-morph": "^24.0.0",
60
+ "del-cli": "^6.0.0",
61
+ "edge.js": "^6.2.1",
62
+ "eslint": "^9.31.0",
63
+ "prettier": "^3.6.2",
64
+ "release-it": "^19.0.4",
65
+ "supertest": "^7.1.3",
66
+ "ts-morph": "^23.0.0",
67
67
  "ts-node": "^10.9.2",
68
- "tsup": "^8.0.2",
69
- "typescript": "~5.4.5",
70
- "vite": "^6.0.0"
68
+ "tsup": "^8.5.0",
69
+ "typescript": "~5.8.3",
70
+ "vite": "^7.0.5"
71
71
  },
72
72
  "dependencies": {
73
- "@poppinss/utils": "^6.7.3",
74
- "@vavite/multibuild": "^5.1.0",
75
- "edge-error": "^4.0.1",
76
- "vite-plugin-restart": "^0.4.0"
73
+ "@poppinss/utils": "^6.10.0",
74
+ "edge-error": "^4.0.2",
75
+ "vite-plugin-restart": "^1.0.0"
77
76
  },
78
77
  "peerDependencies": {
79
78
  "@adonisjs/core": "^6.3.0",
80
79
  "@adonisjs/shield": "^8.0.0",
81
80
  "edge.js": "^6.0.1",
82
- "vite": "^6.0.0"
81
+ "vite": "^7.0.0"
83
82
  },
84
83
  "peerDependenciesMeta": {
85
84
  "edge.js": {
@@ -152,7 +151,7 @@
152
151
  "npm": {
153
152
  "publish": true,
154
153
  "skipChecks": true,
155
- "tag": "next"
154
+ "tag": "latest"
156
155
  },
157
156
  "plugins": {
158
157
  "@release-it/conventional-changelog": {
@@ -161,5 +160,6 @@
161
160
  }
162
161
  }
163
162
  }
164
- }
163
+ },
164
+ "packageManager": "pnpm@10.13.1"
165
165
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["/*\n * @adonisjs/vite\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport { readFileSync } from 'node:fs'\nimport { slash } from '@poppinss/utils'\nimport { ModuleRunner } from 'vite/module-runner'\nimport type {\n InlineConfig,\n Manifest,\n ModuleNode,\n ViteDevServer,\n ServerModuleRunnerOptions,\n} from 'vite'\n\nimport { makeAttributes, uniqBy } from './utils.js'\nimport type { AdonisViteElement, SetAttributes, ViteOptions } from './types.js'\n\nconst styleFileRegex = /\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)/\n\n/**\n * Vite class exposes the APIs to generate tags and URLs for\n * assets processed using vite.\n */\nexport class Vite {\n /**\n * We cache the manifest file content in production\n * to avoid reading the file multiple times\n */\n #manifestCache?: Manifest\n #options: ViteOptions\n #devServer?: ViteDevServer\n #createServerPromise?: Promise<ViteDevServer>\n\n constructor(\n protected isViteRunning: boolean,\n options: ViteOptions\n ) {\n this.#options = options\n this.#options.assetsUrl = (this.#options.assetsUrl || '/').replace(/\\/$/, '')\n }\n\n /**\n * Reads the file contents as JSON\n */\n #readFileAsJSON(filePath: string) {\n return JSON.parse(readFileSync(filePath, 'utf-8'))\n }\n\n /**\n * Generates a JSON element with a custom toString implementation\n */\n #generateElement(element: AdonisViteElement) {\n return {\n ...element,\n toString() {\n const attributes = `${makeAttributes(element.attributes)}`\n if (element.tag === 'link') {\n return `<${element.tag} ${attributes}/>`\n }\n\n return `<${element.tag} ${attributes}>${element.children.join('\\n')}</${element.tag}>`\n },\n }\n }\n\n /**\n * Returns the script needed for the HMR working with Vite\n */\n #getViteHmrScript(attributes?: Record<string, any>) {\n return this.#generateElement({\n tag: 'script',\n attributes: {\n type: 'module',\n src: '/@vite/client',\n ...attributes,\n },\n children: [],\n })\n }\n\n /**\n * Check if the given path is a CSS path\n */\n #isCssPath(path: string) {\n return path.match(styleFileRegex) !== null\n }\n\n /**\n * If the module is a style module\n */\n #isStyleModule(mod: ModuleNode) {\n if (this.#isCssPath(mod.url) || (mod.id && /\\?vue&type=style/.test(mod.id))) {\n return true\n }\n return false\n }\n\n /**\n * Unwrap attributes from the user defined function or return\n * the attributes as it is\n */\n #unwrapAttributes(src: string, url: string, attributes?: SetAttributes) {\n if (typeof attributes === 'function') {\n return attributes({ src, url })\n }\n\n return attributes\n }\n\n /**\n * Create a style tag for the given path\n */\n #makeStyleTag(src: string, url: string, attributes?: Record<string, any>): AdonisViteElement {\n const customAttributes = this.#unwrapAttributes(src, url, this.#options?.styleAttributes)\n return this.#generateElement({\n tag: 'link',\n attributes: { rel: 'stylesheet', ...customAttributes, ...attributes, href: url },\n })\n }\n\n /**\n * Create a script tag for the given path\n */\n #makeScriptTag(src: string, url: string, attributes?: Record<string, any>): AdonisViteElement {\n const customAttributes = this.#unwrapAttributes(src, url, this.#options?.scriptAttributes)\n return this.#generateElement({\n tag: 'script',\n attributes: { type: 'module', ...customAttributes, ...attributes, src: url },\n children: [],\n })\n }\n\n /**\n * Generate an asset URL for a given asset path\n */\n #generateAssetUrl(path: string): string {\n return `${this.#options.assetsUrl}/${path}`\n }\n\n /**\n * Generate a HTML tag for the given asset\n */\n #generateTag(asset: string, attributes?: Record<string, any>): AdonisViteElement {\n let url = ''\n if (this.isViteRunning) {\n url = `/${asset}`\n } else {\n url = this.#generateAssetUrl(asset)\n }\n\n if (this.#isCssPath(asset)) {\n return this.#makeStyleTag(asset, url, attributes)\n }\n\n return this.#makeScriptTag(asset, url, attributes)\n }\n\n /**\n * Collect CSS files from the module graph recursively\n */\n #collectCss(\n mod: ModuleNode,\n styleUrls: Set<string>,\n visitedModules: Set<string>,\n importer?: ModuleNode\n ): void {\n if (!mod.url) return\n\n /**\n * Prevent visiting the same module twice\n */\n if (visitedModules.has(mod.url)) return\n visitedModules.add(mod.url)\n\n if (this.#isStyleModule(mod) && (!importer || !this.#isStyleModule(importer))) {\n if (mod.url.startsWith('/')) {\n styleUrls.add(mod.url)\n } else if (mod.url.startsWith('\\0')) {\n // virtual modules are prefixed with \\0\n styleUrls.add(`/@id/__x00__${mod.url.substring(1)}`)\n } else {\n styleUrls.add(`/@id/${mod.url}`)\n }\n }\n\n mod.importedModules.forEach((dep) => this.#collectCss(dep, styleUrls, visitedModules, mod))\n }\n\n /**\n * Generate style and script tags for the given entrypoints\n * Also adds the @vite/client script\n */\n async #generateEntryPointsTagsForDevMode(\n entryPoints: string[],\n attributes?: Record<string, any>\n ): Promise<AdonisViteElement[]> {\n const server = this.getDevServer()!\n\n const tags = entryPoints.map((entrypoint) => this.#generateTag(entrypoint, attributes))\n const jsEntrypoints = entryPoints.filter((entrypoint) => !this.#isCssPath(entrypoint))\n\n /**\n * If the module graph is empty, that means we didn't execute the entrypoint\n * yet : we just started the AdonisJS dev server.\n * So let's execute the entrypoints to populate the module graph\n */\n if (server?.moduleGraph.idToModuleMap.size === 0) {\n await Promise.allSettled(\n jsEntrypoints.map((entrypoint) => server.warmupRequest(`/${entrypoint}`))\n )\n }\n\n /**\n * We need to collect the CSS files imported by the entrypoints\n * Otherwise, we gonna have a FOUC each time we full reload the page\n */\n const preloadUrls = new Set<string>()\n const visitedModules = new Set<string>()\n const cssTagsElement = new Set<AdonisViteElement>()\n\n /**\n * Let's search for the CSS files by browsing the module graph\n * generated by Vite.\n */\n for (const entryPoint of jsEntrypoints) {\n const filePath = join(server.config.root, entryPoint)\n const entryMod = server.moduleGraph.getModuleById(slash(filePath))\n if (entryMod) this.#collectCss(entryMod, preloadUrls, visitedModules)\n }\n\n /**\n * Once we have the CSS files, generate associated tags\n * that will be injected into the HTML\n */\n const elements = Array.from(preloadUrls).map((href) =>\n this.#generateElement({\n tag: 'link',\n attributes: { rel: 'stylesheet', as: 'style', href: href },\n })\n )\n elements.forEach((element) => cssTagsElement.add(element))\n\n const viteHmr = this.#getViteHmrScript(attributes)\n const result = [...cssTagsElement, viteHmr].concat(tags)\n\n return result.sort((tag) => (tag.tag === 'link' ? -1 : 1))\n }\n\n /**\n * Get a chunk from the manifest file for a given file name\n */\n #chunk(manifest: Manifest, entrypoint: string) {\n const chunk = manifest[entrypoint]\n\n if (!chunk) {\n throw new Error(`Cannot find \"${entrypoint}\" chunk in the manifest file`)\n }\n\n return chunk\n }\n\n /**\n * Get a list of chunks for a given filename\n */\n #chunksByFile(manifest: Manifest, file: string) {\n return Object.entries(manifest)\n .filter(([, chunk]) => chunk.file === file)\n .map(([_, chunk]) => chunk)\n }\n\n /**\n * Generate preload tag for a given url\n */\n #makePreloadTagForUrl(url: string) {\n const attributes = this.#isCssPath(url)\n ? { rel: 'preload', as: 'style', href: url }\n : { rel: 'modulepreload', href: url }\n\n return this.#generateElement({ tag: 'link', attributes })\n }\n\n /**\n * Generate style and script tags for the given entrypoints\n * using the manifest file\n */\n #generateEntryPointsTagsWithManifest(\n entryPoints: string[],\n attributes?: Record<string, any>\n ): AdonisViteElement[] {\n const manifest = this.manifest()\n const tags: { path: string; tag: AdonisViteElement }[] = []\n const preloads: Array<{ path: string }> = []\n\n for (const entryPoint of entryPoints) {\n /**\n * 1. We generate tags + modulepreload for the entrypoint\n */\n const chunk = this.#chunk(manifest, entryPoint)\n preloads.push({ path: this.#generateAssetUrl(chunk.file) })\n tags.push({\n path: chunk.file,\n tag: this.#generateTag(chunk.file, { ...attributes, integrity: chunk.integrity }),\n })\n\n /**\n * 2. We go through the CSS files that are imported by the entrypoint\n * and generate tags + preload for them\n */\n for (const css of chunk.css || []) {\n preloads.push({ path: this.#generateAssetUrl(css) })\n tags.push({ path: css, tag: this.#generateTag(css) })\n }\n\n /**\n * 3. We go through every import of the entrypoint and generate preload\n */\n for (const importNode of chunk.imports || []) {\n preloads.push({ path: this.#generateAssetUrl(manifest[importNode].file) })\n\n /**\n * 4. Finally, we generate tags + preload for the CSS files imported by the import\n * of the entrypoint\n */\n for (const css of manifest[importNode].css || []) {\n const subChunk = this.#chunksByFile(manifest, css)\n\n preloads.push({ path: this.#generateAssetUrl(css) })\n tags.push({\n path: this.#generateAssetUrl(css),\n tag: this.#generateTag(css, {\n ...attributes,\n integrity: subChunk[0]?.integrity,\n }),\n })\n }\n }\n }\n\n /**\n * We sort the preload to ensure that CSS files are preloaded first\n */\n const preloadsElements = uniqBy(preloads, 'path')\n .sort((preload) => (this.#isCssPath(preload.path) ? -1 : 1))\n .map((preload) => this.#makePreloadTagForUrl(preload.path))\n\n /**\n * And finally, we return the preloads + script and link tags\n */\n return preloadsElements.concat(tags.map(({ tag }) => tag))\n }\n\n /**\n * Generate tags for the entry points\n */\n async generateEntryPointsTags(\n entryPoints: string[] | string,\n attributes?: Record<string, any>\n ): Promise<AdonisViteElement[]> {\n entryPoints = Array.isArray(entryPoints) ? entryPoints : [entryPoints]\n\n if (this.isViteRunning) {\n return this.#generateEntryPointsTagsForDevMode(entryPoints, attributes)\n }\n\n return this.#generateEntryPointsTagsWithManifest(entryPoints, attributes)\n }\n\n /**\n * Returns the explicitly configured assetsUrl\n */\n assetsUrl() {\n return this.#options.assetsUrl\n }\n\n /**\n * Returns path to a given asset file using the manifest file\n */\n assetPath(asset: string): string {\n if (this.isViteRunning) {\n return `/${asset}`\n }\n\n const chunk = this.#chunk(this.manifest(), asset)\n return this.#generateAssetUrl(chunk.file)\n }\n\n /**\n * Returns the manifest file contents\n *\n * @throws Will throw an exception when running in dev\n */\n manifest(): Manifest {\n if (this.isViteRunning) {\n throw new Error('Cannot read the manifest file when running in dev mode')\n }\n\n if (!this.#manifestCache) {\n this.#manifestCache = this.#readFileAsJSON(this.#options.manifestFile)\n }\n\n return this.#manifestCache!\n }\n\n /**\n * Create the Vite Dev Server and runtime\n *\n * We lazy load the APIs to avoid loading it in production\n * since we don't need it\n */\n async createDevServer(options?: InlineConfig) {\n const { createServer } = await import('vite')\n\n /**\n * We do not await the server creation since it will\n * slow down the boot process of AdonisJS\n */\n this.#createServerPromise = createServer({\n server: { middlewareMode: true },\n appType: 'custom',\n ...options,\n })\n\n this.#devServer = await this.#createServerPromise\n }\n\n /**\n * Create a serverModuleRunner instance\n * Will not be available when running in production since\n * it needs the Vite Dev server\n */\n async createModuleRunner(options: ServerModuleRunnerOptions = {}): Promise<ModuleRunner> {\n const { createServerModuleRunner } = await import('vite')\n return createServerModuleRunner(this.#devServer!.environments.ssr, options)\n }\n\n /**\n * Stop the Vite Dev server\n */\n async stopDevServer() {\n await this.#createServerPromise\n await this.#devServer?.close()\n }\n\n /**\n * Get the Vite Dev server instance\n * Will not be available when running in production\n */\n getDevServer() {\n return this.#devServer\n }\n\n /**\n * Returns the script needed for the HMR working with React\n */\n getReactHmrScript(attributes?: Record<string, any>): AdonisViteElement | null {\n if (!this.isViteRunning) {\n return null\n }\n\n return this.#generateElement({\n tag: 'script',\n attributes: {\n type: 'module',\n ...attributes,\n },\n children: [\n '',\n `import RefreshRuntime from '/@react-refresh'`,\n `RefreshRuntime.injectIntoGlobalHook(window)`,\n `window.$RefreshReg$ = () => {}`,\n `window.$RefreshSig$ = () => (type) => type`,\n `window.__vite_plugin_react_preamble_installed__ = true`,\n '',\n ],\n })\n }\n}\n"],"mappings":";;;;;;AASA,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAC7B,SAAS,aAAa;AAatB,IAAM,iBAAiB;AAMhB,IAAM,OAAN,MAAW;AAAA,EAUhB,YACY,eACV,SACA;AAFU;AAGV,SAAK,WAAW;AAChB,SAAK,SAAS,aAAa,KAAK,SAAS,aAAa,KAAK,QAAQ,OAAO,EAAE;AAAA,EAC9E;AAAA;AAAA;AAAA;AAAA;AAAA,EAXA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAaA,gBAAgB,UAAkB;AAChC,WAAO,KAAK,MAAM,aAAa,UAAU,OAAO,CAAC;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA,EAKA,iBAAiB,SAA4B;AAC3C,WAAO;AAAA,MACL,GAAG;AAAA,MACH,WAAW;AACT,cAAM,aAAa,GAAG,eAAe,QAAQ,UAAU,CAAC;AACxD,YAAI,QAAQ,QAAQ,QAAQ;AAC1B,iBAAO,IAAI,QAAQ,GAAG,IAAI,UAAU;AAAA,QACtC;AAEA,eAAO,IAAI,QAAQ,GAAG,IAAI,UAAU,IAAI,QAAQ,SAAS,KAAK,IAAI,CAAC,KAAK,QAAQ,GAAG;AAAA,MACrF;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