@adonisjs/vite 1.0.0 → 2.0.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <br />
4
4
 
5
- [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]
5
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url]
6
6
 
7
7
  ## Introduction
8
8
  Package to add [Vite](https://vitejs.dev/) as an assets bundler to AdonisJS.
@@ -21,8 +21,8 @@ In order to ensure that the AdonisJS community is welcoming to all, please revie
21
21
  ## License
22
22
  AdonisJS static files middleware is open-sourced software licensed under the [MIT license](LICENSE.md).
23
23
 
24
- [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/vite/test.yml?style=for-the-badge
25
- [gh-workflow-url]: https://github.com/adonisjs/vite/actions/workflows/test.yml "Github action"
24
+ [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/vite/checks.yml?style=for-the-badge
25
+ [gh-workflow-url]: https://github.com/adonisjs/vite/actions/workflows/checks.yml "Github action"
26
26
 
27
27
  [npm-image]: https://img.shields.io/npm/v/@adonisjs/vite/latest.svg?style=for-the-badge&logo=npm
28
28
  [npm-url]: https://www.npmjs.com/package/@adonisjs/vite/v/latest "npm"
@@ -31,6 +31,3 @@ AdonisJS static files middleware is open-sourced software licensed under the [MI
31
31
 
32
32
  [license-url]: LICENSE.md
33
33
  [license-image]: https://img.shields.io/github/license/adonisjs/vite?style=for-the-badge
34
-
35
- [snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/vite?label=Snyk%20Vulnerabilities&style=for-the-badge
36
- [snyk-url]: https://snyk.io/test/github/adonisjs/vite?targetFile=package.json "snyk"
@@ -16,16 +16,11 @@ export default class ViteServiceProvider {
16
16
  * Registers edge plugin when edge is installed
17
17
  */
18
18
  async registerEdgePlugin() {
19
- let edge = null;
20
- try {
21
- const edgeExports = await import('edge.js');
22
- edge = edgeExports.default;
23
- }
24
- catch { }
25
- if (edge) {
19
+ if (this.app.usingEdgeJS) {
20
+ const edge = await import('edge.js');
26
21
  const vite = await this.app.container.make('vite');
27
22
  const { edgePluginVite } = await import('../src/backend/plugins/edge.js');
28
- edge.use(edgePluginVite(vite));
23
+ edge.default.use(edgePluginVite(vite));
29
24
  }
30
25
  }
31
26
  /**
@@ -6,6 +6,7 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import { join } from 'node:path';
9
10
  /**
10
11
  * Define the backend config for resolving vite assets
11
12
  */
@@ -14,6 +15,9 @@ export function defineConfig(config) {
14
15
  buildDirectory: 'public/assets',
15
16
  hotFile: 'public/assets/hot.json',
16
17
  assetsUrl: '/assets',
18
+ manifestFile: config.buildDirectory
19
+ ? join(config.buildDirectory, '.vite/manifest.json')
20
+ : 'public/assets/.vite/manifest.json',
17
21
  ...config,
18
22
  };
19
23
  }
@@ -45,6 +45,13 @@ export type ViteOptions = {
45
45
  * @default 'public/assets'
46
46
  */
47
47
  buildDirectory: string;
48
+ /**
49
+ * Path to the manifest file relative from the root of
50
+ * the application
51
+ *
52
+ * @default 'public/assets/.vite/manifest.json'
53
+ */
54
+ manifestFile: string;
48
55
  /**
49
56
  * The URL to prefix when generating assets URLs. For example: This
50
57
  * could the CDN URL when generating the production build
@@ -6,7 +6,6 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import { join } from 'node:path';
10
9
  import { existsSync, readFileSync } from 'node:fs';
11
10
  import debug from './debug.js';
12
11
  import { makeAttributes, uniqBy } from './utils.js';
@@ -15,10 +14,6 @@ import { makeAttributes, uniqBy } from './utils.js';
15
14
  * assets processed using vite.
16
15
  */
17
16
  export class Vite {
18
- /**
19
- * Manifest file name
20
- */
21
- #manifestFilename = 'manifest.json';
22
17
  /**
23
18
  * We cache the manifest file content in production
24
19
  * to avoid reading the file multiple times
@@ -156,10 +151,9 @@ export class Vite {
156
151
  tag: this.#generateTag(chunk.file, { ...attributes, integrity: chunk.integrity }),
157
152
  });
158
153
  for (const css of chunk.css || []) {
159
- const cssChunk = this.#chunkByFile(manifest, css);
160
154
  tags.push({
161
- path: cssChunk.file,
162
- tag: this.#generateTag(cssChunk.file, { ...attributes, integrity: cssChunk.integrity }),
155
+ path: css,
156
+ tag: this.#generateTag(css),
163
157
  });
164
158
  }
165
159
  }
@@ -177,16 +171,6 @@ export class Vite {
177
171
  }
178
172
  return chunk;
179
173
  }
180
- /**
181
- * Get a chunk from the manifest file for a given hashed file name
182
- */
183
- #chunkByFile(manifest, fileName) {
184
- const chunk = Object.values(manifest).find((c) => c.file === fileName);
185
- if (!chunk) {
186
- throw new Error(`Cannot find "${fileName}" chunk in the manifest file`);
187
- }
188
- return chunk;
189
- }
190
174
  /**
191
175
  * Check if the given path is a CSS path
192
176
  */
@@ -244,7 +228,7 @@ export class Vite {
244
228
  throw new Error('Cannot read the manifest file when running in hot mode');
245
229
  }
246
230
  if (!this.#manifestCache) {
247
- this.#manifestCache = this.#readFileAsJSON(join(this.#options.buildDirectory, this.#manifestFilename));
231
+ this.#manifestCache = this.#readFileAsJSON(this.#options.manifestFile);
248
232
  }
249
233
  return this.#manifestCache;
250
234
  }
@@ -9,7 +9,6 @@
9
9
  import { defu } from 'defu';
10
10
  import PluginRestart from 'vite-plugin-restart';
11
11
  import { config } from './config.js';
12
- const VitePluginRestart = PluginRestart;
13
12
  /**
14
13
  * Vite plugin for adonisjs
15
14
  */
@@ -20,5 +19,5 @@ export default function adonisjs(options) {
20
19
  hotFile: 'public/assets/hot.json',
21
20
  reload: ['./resources/views/**/*.edge'],
22
21
  });
23
- return [VitePluginRestart({ reload: fullOptions.reload }), config(fullOptions)];
22
+ return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)];
24
23
  }
@@ -6,6 +6,7 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import { networkInterfaces } from 'node:os';
9
10
  /**
10
11
  * Resolve the dev server URL from the server address and configuration.
11
12
  */
@@ -20,6 +21,19 @@ export const resolveDevServerUrl = (address, config) => {
20
21
  if (host === '::1') {
21
22
  host = 'localhost';
22
23
  }
24
+ else if (host === '::') {
25
+ const networkAddress = Object.values(networkInterfaces())
26
+ .flatMap((nInterface) => nInterface ?? [])
27
+ .find((detail) => {
28
+ return (detail &&
29
+ detail.address &&
30
+ detail.family === 'IPv4' &&
31
+ !detail.address.includes('127.0.0.1'));
32
+ });
33
+ if (networkAddress) {
34
+ host = networkAddress.address;
35
+ }
36
+ }
23
37
  return `${protocol}://${host}:${address.port}`;
24
38
  };
25
39
  /**
@@ -11,6 +11,12 @@ const viteBackendConfig = defineConfig({
11
11
  */
12
12
  buildDirectory: 'public/assets',
13
13
 
14
+ /**
15
+ * The path to the manifest file generated by the
16
+ * "vite build" command.
17
+ */
18
+ manifestFile: 'public/assets/.vite/manifest.json',
19
+
14
20
  /**
15
21
  * Feel free to change the value of the "assetsUrl" to
16
22
  * point to a CDN in production.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/vite",
3
3
  "description": "Vite plugin for Adonis.js",
4
- "version": "1.0.0",
4
+ "version": "2.0.1",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -34,51 +34,53 @@
34
34
  "quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts",
35
35
  "pretest": "npm run lint",
36
36
  "test": "c8 npm run quick:test",
37
- "compile": "npm run lint && npm run clean && tsc && npm run copy:templates",
37
+ "precompile": "npm run lint && npm run clean ",
38
+ "compile": "tsc",
39
+ "postcompile": "npm run copy:templates",
38
40
  "build": "npm run compile",
39
- "postbuild": "npm run copy:templates",
40
41
  "release": "np",
41
42
  "version": "npm run build",
42
43
  "prepublishOnly": "npm run build"
43
44
  },
44
45
  "devDependencies": {
45
- "@adonisjs/assembler": "^6.1.3-25",
46
- "@adonisjs/core": "^6.1.5-28",
47
- "@adonisjs/eslint-config": "^1.1.8",
48
- "@adonisjs/prettier-config": "^1.1.8",
49
- "@adonisjs/shield": "^8.0.0-8",
50
- "@adonisjs/tsconfig": "^1.1.8",
51
- "@commitlint/cli": "^17.8.0",
52
- "@commitlint/config-conventional": "^17.8.0",
53
- "@japa/assert": "^2.0.0",
46
+ "@adonisjs/assembler": "^6.1.3-28",
47
+ "@adonisjs/core": "^6.1.5-32",
48
+ "@adonisjs/eslint-config": "^1.1.9",
49
+ "@adonisjs/prettier-config": "^1.1.9",
50
+ "@adonisjs/session": "^7.0.0-14",
51
+ "@adonisjs/shield": "^8.0.0-9",
52
+ "@adonisjs/tsconfig": "^1.1.9",
53
+ "@commitlint/cli": "^18.4.3",
54
+ "@commitlint/config-conventional": "^18.4.3",
55
+ "@japa/assert": "^2.0.1",
54
56
  "@japa/expect-type": "^2.0.0",
55
- "@japa/file-system": "^2.0.0",
56
- "@japa/runner": "^3.0.2",
57
- "@swc/core": "1.3.82",
58
- "@types/node": "^20.8.6",
57
+ "@japa/file-system": "^2.0.1",
58
+ "@japa/runner": "^3.1.0",
59
+ "@swc/core": "^1.3.99",
60
+ "@types/node": "^20.10.0",
59
61
  "c8": "^8.0.0",
60
62
  "copyfiles": "^2.4.1",
61
63
  "del-cli": "^5.1.0",
62
- "edge.js": "^6.0.0-8",
63
- "eslint": "^8.51.0",
64
+ "edge.js": "^6.0.0",
65
+ "eslint": "^8.54.0",
64
66
  "husky": "^8.0.3",
65
67
  "np": "^8.0.4",
66
- "prettier": "^3.0.3",
67
- "rollup": "^4.1.4",
68
+ "prettier": "^3.1.0",
69
+ "rollup": "^4.6.0",
68
70
  "ts-node": "^10.9.1",
69
- "typescript": "^5.2.2",
70
- "vite": "^4.4.11"
71
+ "typescript": "5.2.2",
72
+ "vite": "^5.0.2"
71
73
  },
72
74
  "dependencies": {
73
- "defu": "^6.1.2",
74
- "edge-error": "^4.0.0-0",
75
- "vite-plugin-restart": "^0.3.1"
75
+ "defu": "^6.1.3",
76
+ "edge-error": "^4.0.0",
77
+ "vite-plugin-restart": "^0.4.0"
76
78
  },
77
79
  "peerDependencies": {
78
- "@adonisjs/core": "^6.1.5-28",
79
- "@adonisjs/shield": "^8.0.0-8",
80
- "edge.js": "^6.0.0-8",
81
- "vite": "^4.4.11"
80
+ "@adonisjs/core": "^6.1.5-32",
81
+ "@adonisjs/shield": "^8.0.0-9",
82
+ "edge.js": "^6.0.0",
83
+ "vite": "^4.0.0 || ^5.0.0"
82
84
  },
83
85
  "peerDependenciesMeta": {
84
86
  "vite": {