@adonisjs/vite 0.0.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.
Files changed (67) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +36 -0
  3. package/build/configure.d.ts +3 -0
  4. package/build/configure.d.ts.map +1 -0
  5. package/build/configure.js +13 -0
  6. package/build/index.d.ts +5 -0
  7. package/build/index.d.ts.map +1 -0
  8. package/build/index.js +4 -0
  9. package/build/providers/vite_provider.d.ts +10 -0
  10. package/build/providers/vite_provider.d.ts.map +1 -0
  11. package/build/providers/vite_provider.js +48 -0
  12. package/build/services/vite.d.ts +4 -0
  13. package/build/services/vite.d.ts.map +1 -0
  14. package/build/services/vite.js +6 -0
  15. package/build/src/backend/types/extended.d.ts +7 -0
  16. package/build/src/backend/types/extended.d.ts.map +1 -0
  17. package/build/src/backend/types/extended.js +1 -0
  18. package/build/src/backend/types/main.d.ts +9 -0
  19. package/build/src/backend/types/main.d.ts.map +1 -0
  20. package/build/src/backend/types/main.js +1 -0
  21. package/build/src/backend/utils.d.ts +2 -0
  22. package/build/src/backend/utils.d.ts.map +1 -0
  23. package/build/src/backend/utils.js +7 -0
  24. package/build/src/backend/vite.d.ts +19 -0
  25. package/build/src/backend/vite.d.ts.map +1 -0
  26. package/build/src/backend/vite.js +182 -0
  27. package/build/src/vite_plugin/config.d.ts +5 -0
  28. package/build/src/vite_plugin/config.d.ts.map +1 -0
  29. package/build/src/vite_plugin/config.js +47 -0
  30. package/build/src/vite_plugin/config_resolver.d.ts +9 -0
  31. package/build/src/vite_plugin/config_resolver.d.ts.map +1 -0
  32. package/build/src/vite_plugin/config_resolver.js +27 -0
  33. package/build/src/vite_plugin/helpers/inertia.d.ts +2 -0
  34. package/build/src/vite_plugin/helpers/inertia.d.ts.map +1 -0
  35. package/build/src/vite_plugin/helpers/inertia.js +11 -0
  36. package/build/src/vite_plugin/hot_file.d.ts +9 -0
  37. package/build/src/vite_plugin/hot_file.d.ts.map +1 -0
  38. package/build/src/vite_plugin/hot_file.js +30 -0
  39. package/build/src/vite_plugin/index.d.ts +4 -0
  40. package/build/src/vite_plugin/index.d.ts.map +1 -0
  41. package/build/src/vite_plugin/index.js +16 -0
  42. package/build/src/vite_plugin/types/index.d.ts +10 -0
  43. package/build/src/vite_plugin/types/index.d.ts.map +1 -0
  44. package/build/src/vite_plugin/types/index.js +1 -0
  45. package/build/src/vite_plugin/utils.d.ts +5 -0
  46. package/build/src/vite_plugin/utils.d.ts.map +1 -0
  47. package/build/src/vite_plugin/utils.js +16 -0
  48. package/build/stubs/index.d.ts +2 -0
  49. package/build/stubs/index.d.ts.map +1 -0
  50. package/build/stubs/index.js +2 -0
  51. package/build/stubs/vite/vite_config.stub +14 -0
  52. package/configure.ts +30 -0
  53. package/index.ts +15 -0
  54. package/package.json +147 -0
  55. package/providers/vite_provider.ts +89 -0
  56. package/services/vite.ts +23 -0
  57. package/src/backend/types/extended.ts +19 -0
  58. package/src/backend/types/main.ts +31 -0
  59. package/src/backend/utils.ts +19 -0
  60. package/src/backend/vite.ts +367 -0
  61. package/src/vite_plugin/config.ts +97 -0
  62. package/src/vite_plugin/config_resolver.ts +62 -0
  63. package/src/vite_plugin/helpers/inertia.ts +27 -0
  64. package/src/vite_plugin/hot_file.ts +59 -0
  65. package/src/vite_plugin/index.ts +38 -0
  66. package/src/vite_plugin/types/index.ts +56 -0
  67. package/src/vite_plugin/utils.ts +40 -0
@@ -0,0 +1,5 @@
1
+ import { AddressInfo } from 'node:net';
2
+ import { ResolvedConfig } from 'vite';
3
+ export declare const resolveDevServerUrl: (address: AddressInfo, config: ResolvedConfig) => string;
4
+ export declare const addTrailingSlash: (url: string) => string;
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/vite_plugin/utils.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAKrC,eAAO,MAAM,mBAAmB,YAAa,WAAW,UAAU,cAAc,WAiB/E,CAAA;AAKD,eAAO,MAAM,gBAAgB,QAAS,MAAM,WAE3C,CAAA"}
@@ -0,0 +1,16 @@
1
+ export const resolveDevServerUrl = (address, config) => {
2
+ const configHmrProtocol = typeof config.server.hmr === 'object' ? config.server.hmr.protocol : null;
3
+ const clientProtocol = configHmrProtocol ? (configHmrProtocol === 'wss' ? 'https' : 'http') : null;
4
+ const serverProtocol = config.server.https ? 'https' : 'http';
5
+ const protocol = clientProtocol ?? serverProtocol;
6
+ const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null;
7
+ const configHost = typeof config.server.host === 'string' ? config.server.host : null;
8
+ let host = configHmrHost ?? configHost ?? address.address;
9
+ if (host === '::1') {
10
+ host = 'localhost';
11
+ }
12
+ return `${protocol}://${host}:${address.port}`;
13
+ };
14
+ export const addTrailingSlash = (url) => {
15
+ return url.endsWith('/') ? url : url + '/';
16
+ };
@@ -0,0 +1,2 @@
1
+ export declare const stubsRoot: string;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../stubs/index.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,SAAS,QAA2B,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { dirname } from 'desm';
2
+ export const stubsRoot = dirname(import.meta.url);
@@ -0,0 +1,14 @@
1
+ ---
2
+ to: {{ destination }}
3
+ ---
4
+
5
+ import { defineConfig } from 'vite'
6
+ import Adonis from '@adonisjs/vite/plugin'
7
+
8
+ export default defineConfig({
9
+ plugins: [
10
+ Adonis({
11
+ entrypoints: ['resources/js/vue.js'],
12
+ }),
13
+ ],
14
+ })
package/configure.ts ADDED
@@ -0,0 +1,30 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { join } from 'node:path'
11
+ import { fileURLToPath } from 'node:url'
12
+ import type Configure from '@adonisjs/core/commands/configure'
13
+
14
+ /**
15
+ * Configures the package
16
+ */
17
+ export async function configure(command: Configure) {
18
+ const stubDestination = join(fileURLToPath(command.app.appRoot), 'vite.config.js')
19
+
20
+ await command.publishStub('vite/vite_config.stub', {
21
+ destination: stubDestination,
22
+ })
23
+
24
+ await command.updateRcFile((rcFile) => {
25
+ rcFile.addProvider('@adonisjs/vite/providers/vite_provider')
26
+ })
27
+
28
+ const packagesToInstall = [{ name: 'vite', isDevDependency: true }]
29
+ command.listPackagesToInstall(packagesToInstall)
30
+ }
package/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import './src/backend/types/extended.js'
11
+
12
+ export { configure } from './configure.js'
13
+ export { stubsRoot } from './stubs/index.js'
14
+
15
+ export { Vite } from './src/backend/vite.js'
package/package.json ADDED
@@ -0,0 +1,147 @@
1
+ {
2
+ "name": "@adonisjs/vite",
3
+ "version": "0.0.1-0",
4
+ "description": "Vite plugin for Adonis.js",
5
+ "type": "module",
6
+ "main": "build/index.js",
7
+ "files": [
8
+ "index.ts",
9
+ "configure.ts",
10
+ "src",
11
+ "services",
12
+ "providers",
13
+ "build/stubs",
14
+ "build/configure.js",
15
+ "build/configure.d.ts",
16
+ "build/configure.d.ts.map",
17
+ "build/index.js",
18
+ "build/index.d.ts",
19
+ "build/index.d.ts.map",
20
+ "build/src",
21
+ "build/services",
22
+ "build/providers"
23
+ ],
24
+ "exports": {
25
+ ".": "./build/index.js",
26
+ "./services/main": "./build/services/vite.js",
27
+ "./providers/vite_provider": "./build/providers/vite_provider.js",
28
+ "./plugin": "./build/src/vite_plugin/index.js",
29
+ "./types": "./build/src/backend/types.js",
30
+ "./types/extended": "./build/src/backend/types/extended.js"
31
+ },
32
+ "scripts": {
33
+ "clean": "del-cli build",
34
+ "copy:templates": "copyfiles \"stubs/**/*.stub\" build",
35
+ "typecheck": "tsc --no-emit",
36
+ "lint": "eslint . --ext=.ts",
37
+ "format": "prettier --write .",
38
+ "quick:test": "node --loader=ts-node/esm bin/test.ts",
39
+ "pretest": "npm run lint",
40
+ "test": "c8 npm run quick:test",
41
+ "compile": "npm run lint && npm run clean && tsc && npm run copy:templates",
42
+ "build": "npm run compile",
43
+ "postbuild": "npm run copy:templates",
44
+ "release": "np",
45
+ "version": "npm run build",
46
+ "prepublishOnly": "npm run build"
47
+ },
48
+ "keywords": [
49
+ "vite",
50
+ "adonisjs"
51
+ ],
52
+ "author": "Julien Ripouteau <julien@ripouteau.com>",
53
+ "license": "MIT",
54
+ "dependencies": {
55
+ "defu": "^6.1.2",
56
+ "edge-error": "^3.0.0",
57
+ "vite-plugin-restart": "^0.3.1"
58
+ },
59
+ "devDependencies": {
60
+ "@adonisjs/core": "^6.1.5-4",
61
+ "@adonisjs/view": "7.0.0-0",
62
+ "@commitlint/cli": "^17.6.1",
63
+ "@commitlint/config-conventional": "^17.6.1",
64
+ "@japa/assert": "^1.4.1",
65
+ "@japa/expect-type": "^1.0.3",
66
+ "@japa/file-system": "^1.0.1",
67
+ "@japa/run-failed-tests": "^1.1.1",
68
+ "@japa/runner": "^2.5.1",
69
+ "@japa/spec-reporter": "^1.3.3",
70
+ "@poppinss/dev-utils": "^2.0.3",
71
+ "@swc/core": "^1.3.53",
72
+ "@types/node": "^18.16.0",
73
+ "c8": "^7.13.0",
74
+ "copyfiles": "^2.4.1",
75
+ "del-cli": "^5.0.0",
76
+ "desm": "^1.3.0",
77
+ "eslint": "^8.39.0",
78
+ "eslint-config-prettier": "^8.8.0",
79
+ "eslint-plugin-adonis": "^3.0.3",
80
+ "eslint-plugin-prettier": "^4.2.1",
81
+ "husky": "^8.0.3",
82
+ "np": "^7.7.0",
83
+ "prettier": "^2.8.8",
84
+ "rollup": "^3.21.0",
85
+ "ts-node": "^10.9.1",
86
+ "typescript": "^5.0.4",
87
+ "vite": "^4.3.1"
88
+ },
89
+ "peerDependencies": {
90
+ "@adonisjs/core": "^6.1.1-0",
91
+ "@adonisjs/view": "7.0.0-0"
92
+ },
93
+ "eslintConfig": {
94
+ "extends": [
95
+ "plugin:adonis/typescriptPackage",
96
+ "prettier"
97
+ ],
98
+ "plugins": [
99
+ "prettier"
100
+ ],
101
+ "rules": {
102
+ "prettier/prettier": [
103
+ "error",
104
+ {
105
+ "endOfLine": "auto"
106
+ }
107
+ ]
108
+ }
109
+ },
110
+ "eslintIgnore": [
111
+ "build"
112
+ ],
113
+ "prettier": {
114
+ "trailingComma": "es5",
115
+ "semi": false,
116
+ "singleQuote": true,
117
+ "useTabs": false,
118
+ "quoteProps": "consistent",
119
+ "bracketSpacing": true,
120
+ "arrowParens": "always",
121
+ "printWidth": 100
122
+ },
123
+ "commitlint": {
124
+ "extends": [
125
+ "@commitlint/config-conventional"
126
+ ]
127
+ },
128
+ "publishConfig": {
129
+ "access": "public",
130
+ "tag": "next"
131
+ },
132
+ "np": {
133
+ "message": "chore(release): %s",
134
+ "tag": "next",
135
+ "branch": "main",
136
+ "anyBranch": false
137
+ },
138
+ "c8": {
139
+ "reporter": [
140
+ "text",
141
+ "html"
142
+ ],
143
+ "exclude": [
144
+ "tests/**"
145
+ ]
146
+ }
147
+ }
@@ -0,0 +1,89 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import '@adonisjs/view'
11
+ import { ApplicationService } from '@adonisjs/core/types'
12
+ import { ViewContract } from '@adonisjs/view/types'
13
+ import { Vite } from '../src/backend/vite.js'
14
+ import { EdgeError } from 'edge-error'
15
+
16
+ export default class ViteServiceProvider {
17
+ constructor(protected app: ApplicationService) {}
18
+
19
+ /**
20
+ * Inject the script needed for Vite HMR
21
+ */
22
+ #registerViteTag(view: ViewContract) {
23
+ view.registerTag({
24
+ tagName: 'vite',
25
+ seekable: true,
26
+ block: false,
27
+ compile(parser, buffer, token) {
28
+ /**
29
+ * Ensure an argument is defined
30
+ */
31
+ if (!token.properties.jsArg.trim()) {
32
+ throw new EdgeError('Missing entrypoint name', 'E_RUNTIME_EXCEPTION', {
33
+ filename: token.filename,
34
+ line: token.loc.start.line,
35
+ col: token.loc.start.col,
36
+ })
37
+ }
38
+
39
+ const parsed = parser.utils.transformAst(
40
+ parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),
41
+ token.filename,
42
+ parser
43
+ )
44
+
45
+ const entrypoints = parser.utils.stringify(parsed)
46
+
47
+ buffer.outputExpression(
48
+ `state.vite.generateEntryPointsTags(${entrypoints})`,
49
+ token.filename,
50
+ token.loc.start.line,
51
+ false
52
+ )
53
+ },
54
+ })
55
+ }
56
+
57
+ /**
58
+ * Inject a script needed for the HMR working with React
59
+ */
60
+ #registerViteReactTag(view: ViewContract) {
61
+ view.registerTag({
62
+ tagName: 'viteReactRefresh',
63
+ seekable: true,
64
+ block: false,
65
+ compile(_parser, buffer, token) {
66
+ buffer.outputExpression(
67
+ `state.vite.getReactHmrScript()`,
68
+ token.filename,
69
+ token.loc.start.line,
70
+ false
71
+ )
72
+ },
73
+ })
74
+ }
75
+
76
+ register() {
77
+ this.app.container.singleton('vite', async () => new Vite(this.app))
78
+ }
79
+
80
+ async boot() {
81
+ const view = await this.app.container.make('view')
82
+ const vite = await this.app.container.make('vite')
83
+
84
+ view.global('vite', vite)
85
+
86
+ this.#registerViteTag(view)
87
+ this.#registerViteReactTag(view)
88
+ }
89
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import app from '@adonisjs/core/services/app'
11
+ import { Vite } from '../index.js'
12
+
13
+ let vite: Vite
14
+
15
+ /**
16
+ * Returns a singleton instance of Vite class
17
+ * from the container
18
+ */
19
+ await app.booted(async () => {
20
+ vite = await app.container.make('vite')
21
+ })
22
+
23
+ export { vite as default }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import { Vite } from '../vite.js'
11
+
12
+ /**
13
+ * Extend the container bindings
14
+ */
15
+ declare module '@adonisjs/core/types' {
16
+ interface ContainerBindings {
17
+ vite: Vite
18
+ }
19
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ /**
11
+ * Content of the hotfile
12
+ */
13
+ export type HotFile = {
14
+ url: string
15
+ }
16
+
17
+ /**
18
+ * Parameters passed to the setAttributes callback
19
+ */
20
+ export type SetAttributesCallbackParams = {
21
+ src: string
22
+ url: string
23
+ }
24
+
25
+ /**
26
+ * Attributes to be set on the script/style tags.
27
+ * Can be either a record or a callback that returns a record.
28
+ */
29
+ export type SetAttributes =
30
+ | Record<string, string | boolean>
31
+ | ((params: SetAttributesCallbackParams) => Record<string, string | boolean>)
@@ -0,0 +1,19 @@
1
+ /*
2
+ * @adonisjs/vite
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ /**
11
+ * Returns a new array with unique items by the given key
12
+ */
13
+ export function uniqBy<T>(array: T[], key: keyof T): T[] {
14
+ const seen = new Set()
15
+ return array.filter((item) => {
16
+ const k = item[key]
17
+ return seen.has(k) ? false : seen.add(k)
18
+ })
19
+ }