@open-xchange/vite-plugin-ox-manifests 0.3.1 → 0.4.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/README.md +0 -2
- package/index.js +0 -5
- package/package.json +1 -1
- package/src/plugins/gettext.js +1 -1
- package/src/plugins/server-manifests.js +0 -25
- package/test/server-manifests/main.test.js +0 -130
- package/test/server-manifests/manifest.json +0 -3
- package/test/server-manifests/register.js +0 -1
package/README.md
CHANGED
|
@@ -25,8 +25,6 @@ return {
|
|
|
25
25
|
You can provide the following options to the plugin:
|
|
26
26
|
|
|
27
27
|
* watch `<boolean>` If set to true, it will watch any changes to manifest.json files and will automatically reload the vite-dev-server. Default: `true`
|
|
28
|
-
* appsuiteUrl `<string>` If this string is provided, the dev-server will try to fetch manifests from that location and will merge them together with local manifests. Duplicate entries will be removed. Useful for plugin development which require core manifests. Default: `undefined`
|
|
29
|
-
* manifestApiPath `<string>` The path where this plugin looks for manifests is `appsuiteUrl + manifestApiPath`. If developing against a common Kubernetes based App Suite deployment, this most like does not have to be changed. Default: `'/api/manifest.json'`
|
|
30
28
|
* entryPoints `<string> | <glob pattern>` Convenience method to specify additional entry points for the production build. The glob pattern will be resolved and injected into the `build.input` options of vite. Can be specified as a glob-pattern. Default: `undefined`
|
|
31
29
|
* manifestsAsEntryPoints `<boolean>` If set to true, this will inject every entrypoint that is defined by a manifest.json file into the `build.input` options of vite. Default: `true`
|
|
32
30
|
* transformAbsolutePaths `<boolean>` If set to true, every absolute path will be transformed into a relative path. This is especially useful, if the production path is not clear at build time. E.g. if you do not know, whether appsuite will be served under `/appsuite`. Default: `true`
|
package/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import manifestsPlugin from './src/plugins/manifests.js'
|
|
|
3
3
|
import relativePathsPlugin from './src/plugins/relative-paths.js'
|
|
4
4
|
import settingsPlugin from './src/plugins/settings.js'
|
|
5
5
|
import servePlugin from './src/plugins/serve.js'
|
|
6
|
-
import serverManifestPlugin from './src/plugins/server-manifests.js'
|
|
7
6
|
import gettextPlugin from './src/plugins/gettext.js'
|
|
8
7
|
import { deepMergeObject } from './src/util.js'
|
|
9
8
|
|
|
@@ -12,7 +11,6 @@ import { deepMergeObject } from './src/util.js'
|
|
|
12
11
|
*
|
|
13
12
|
* @param {object} [options]
|
|
14
13
|
* @param {boolean} [options.watch=false] - If set to true, this plugin will watch manifest changes and reload the ui
|
|
15
|
-
* @param {string} [options.appsuiteUrl] - When used in dev-mode, the dev-server can merge the local manifests with the manifest-files from the appsuiteUrl server.
|
|
16
14
|
* @param {string} [options.entryPoints] - Convenience method to specify additional entry points for the production build. Can be specified as a glob-pattern.
|
|
17
15
|
* @param {boolean} [options.manifestsAsEntryPoints=true] - Specifies, that every path in a manifest is used as an entry-point for the production build.
|
|
18
16
|
* @param {boolean} [options.transformAbsolutePaths=true] - If this is set to true, every path in the html-files is transformed to a relative path. Additionally, every preloaded file will also be loaded relative to the index.html
|
|
@@ -21,7 +19,6 @@ import { deepMergeObject } from './src/util.js'
|
|
|
21
19
|
*/
|
|
22
20
|
export default function ({
|
|
23
21
|
watch = false,
|
|
24
|
-
appsuiteUrl,
|
|
25
22
|
entryPoints,
|
|
26
23
|
manifestsAsEntryPoints = true,
|
|
27
24
|
transformAbsolutePaths = true,
|
|
@@ -30,7 +27,6 @@ export default function ({
|
|
|
30
27
|
} = {}) {
|
|
31
28
|
const options = {
|
|
32
29
|
watch,
|
|
33
|
-
appsuiteUrl,
|
|
34
30
|
entryPoints,
|
|
35
31
|
manifestsAsEntryPoints,
|
|
36
32
|
transformAbsolutePaths,
|
|
@@ -43,7 +39,6 @@ export default function ({
|
|
|
43
39
|
settingsPlugin(options),
|
|
44
40
|
relativePathsPlugin(options),
|
|
45
41
|
servePlugin(options),
|
|
46
|
-
serverManifestPlugin(options),
|
|
47
42
|
gettextPlugin(options),
|
|
48
43
|
// manifest plugin last
|
|
49
44
|
manifestsPlugin(options)
|
package/package.json
CHANGED
package/src/plugins/gettext.js
CHANGED
|
@@ -44,7 +44,7 @@ export default function () {
|
|
|
44
44
|
|
|
45
45
|
getManifests () {
|
|
46
46
|
if (resolvedConfig.mode !== 'production') {
|
|
47
|
-
return manifests.map(({ namespace, path }) => ({ namespace, raw: `/@id/${path}`, path }))
|
|
47
|
+
return manifests.map(({ namespace, path }) => ({ namespace, raw: `/@id/${path}.js`, path }))
|
|
48
48
|
}
|
|
49
49
|
return manifests
|
|
50
50
|
},
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
|
|
3
|
-
export default function ({ appsuiteUrl } = {}) {
|
|
4
|
-
let cache
|
|
5
|
-
return {
|
|
6
|
-
async getManifests () {
|
|
7
|
-
if (!appsuiteUrl) return []
|
|
8
|
-
|
|
9
|
-
if (cache) return cache
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
let res
|
|
13
|
-
try {
|
|
14
|
-
res = await axios.get(new URL('/api/manifest.json', appsuiteUrl).href)
|
|
15
|
-
} catch (e) {
|
|
16
|
-
res = await axios.get(new URL('/manifests', appsuiteUrl).href)
|
|
17
|
-
}
|
|
18
|
-
return (cache = res.data)
|
|
19
|
-
} catch (e) {
|
|
20
|
-
console.error('Could not fetch server manifests', e)
|
|
21
|
-
return []
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, afterEach, jest } from '@jest/globals'
|
|
2
|
-
import { createServer } from 'vite'
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import vitePluginOxManifests from '../../index'
|
|
5
|
-
import axios from 'axios'
|
|
6
|
-
import express from 'express'
|
|
7
|
-
import { getPort } from '../util'
|
|
8
|
-
|
|
9
|
-
const PORT = getPort()
|
|
10
|
-
const SERVER_PORT = getPort()
|
|
11
|
-
|
|
12
|
-
describe('Server manifest scenario', function () {
|
|
13
|
-
let server, expressServer
|
|
14
|
-
|
|
15
|
-
afterEach(async function () {
|
|
16
|
-
if (server) {
|
|
17
|
-
await server.close()
|
|
18
|
-
server = null
|
|
19
|
-
}
|
|
20
|
-
if (expressServer) {
|
|
21
|
-
await expressServer.close()
|
|
22
|
-
expressServer = null
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('works in dev mode', async function () {
|
|
27
|
-
server = await createServer({
|
|
28
|
-
root: path.dirname(new URL(import.meta.url).pathname),
|
|
29
|
-
logLevel: 'silent',
|
|
30
|
-
plugins: [vitePluginOxManifests({
|
|
31
|
-
appsuiteUrl: `http://localhost:${SERVER_PORT}`
|
|
32
|
-
})]
|
|
33
|
-
})
|
|
34
|
-
await server.listen(PORT)
|
|
35
|
-
|
|
36
|
-
const app = express()
|
|
37
|
-
expressServer = app.listen(SERVER_PORT)
|
|
38
|
-
app.get('/api/manifest.json', (req, res) => {
|
|
39
|
-
res.json([{ namespace: 'server' }])
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const res = await axios({ baseURL: `http://localhost:${PORT}/api/manifest.json` })
|
|
43
|
-
const manifests = res.data
|
|
44
|
-
|
|
45
|
-
expect(manifests).toHaveLength(2)
|
|
46
|
-
expect(manifests[1].namespace).toEqual('test')
|
|
47
|
-
expect(manifests[1].path).toContain('register')
|
|
48
|
-
expect(manifests[0].namespace).toEqual('server')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('only fetches manifests once from server', async function () {
|
|
52
|
-
server = await createServer({
|
|
53
|
-
root: path.dirname(new URL(import.meta.url).pathname),
|
|
54
|
-
logLevel: 'silent',
|
|
55
|
-
plugins: [vitePluginOxManifests({
|
|
56
|
-
appsuiteUrl: `http://localhost:${SERVER_PORT}`
|
|
57
|
-
})]
|
|
58
|
-
})
|
|
59
|
-
await server.listen(PORT)
|
|
60
|
-
|
|
61
|
-
const app = express()
|
|
62
|
-
expressServer = app.listen(SERVER_PORT)
|
|
63
|
-
const respond = jest.fn((req, res) => {
|
|
64
|
-
res.json([{ namespace: 'server' }])
|
|
65
|
-
})
|
|
66
|
-
app.get('/api/manifest.json', respond)
|
|
67
|
-
|
|
68
|
-
expect(respond).not.toBeCalled()
|
|
69
|
-
|
|
70
|
-
await axios({ baseURL: `http://localhost:${PORT}/api/manifest.json` })
|
|
71
|
-
|
|
72
|
-
expect(respond).toBeCalledTimes(1)
|
|
73
|
-
|
|
74
|
-
await axios({ baseURL: `http://localhost:${PORT}/api/manifest.json` })
|
|
75
|
-
|
|
76
|
-
expect(respond).toBeCalledTimes(1)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('overwrites existing manfests from server', async function () {
|
|
80
|
-
server = await createServer({
|
|
81
|
-
root: path.dirname(new URL(import.meta.url).pathname),
|
|
82
|
-
logLevel: 'silent',
|
|
83
|
-
plugins: [vitePluginOxManifests({
|
|
84
|
-
appsuiteUrl: `http://localhost:${SERVER_PORT}`
|
|
85
|
-
})]
|
|
86
|
-
})
|
|
87
|
-
await server.listen(PORT)
|
|
88
|
-
|
|
89
|
-
const app = express()
|
|
90
|
-
expressServer = app.listen(SERVER_PORT)
|
|
91
|
-
app.get('/api/manifest.json', (req, res) => {
|
|
92
|
-
// same as from client, but with additional property
|
|
93
|
-
res.json([{ namespace: 'test', path: 'register', other: 'test' }])
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const res = await axios({ baseURL: `http://localhost:${PORT}/api/manifest.json` })
|
|
97
|
-
const manifests = res.data
|
|
98
|
-
|
|
99
|
-
expect(manifests).toHaveLength(1)
|
|
100
|
-
expect(manifests[0].namespace).toEqual('test')
|
|
101
|
-
expect(manifests[0].path).toEqual('register')
|
|
102
|
-
expect(manifests[0].other).toBeUndefined()
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('exposes manifest and dependencies using new API', async () => {
|
|
106
|
-
server = await createServer({
|
|
107
|
-
root: path.dirname(new URL(import.meta.url).pathname),
|
|
108
|
-
logLevel: 'silent',
|
|
109
|
-
plugins: [vitePluginOxManifests({
|
|
110
|
-
appsuiteUrl: `http://localhost:${SERVER_PORT}`
|
|
111
|
-
})]
|
|
112
|
-
})
|
|
113
|
-
await server.listen(PORT)
|
|
114
|
-
const app = express()
|
|
115
|
-
expressServer = app.listen(SERVER_PORT)
|
|
116
|
-
app.get('/api/manifest.json', (req, res) => {
|
|
117
|
-
// same as from client, but with additional property
|
|
118
|
-
res.json([{ namespace: 'test', path: 'register', other: 'test' }])
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
const { data: manifests } = await axios({ baseURL: `http://localhost:${PORT}/manifests` })
|
|
122
|
-
expect(manifests).toHaveLength(1)
|
|
123
|
-
expect(manifests[0].namespace).toEqual('test')
|
|
124
|
-
expect(manifests[0].path).toEqual('register')
|
|
125
|
-
expect(manifests[0].other).toBeUndefined()
|
|
126
|
-
|
|
127
|
-
const { data } = await axios({ baseURL: `http://localhost:${PORT}/dependencies` })
|
|
128
|
-
expect(data).toStrictEqual({})
|
|
129
|
-
})
|
|
130
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
console.log('Hello world')
|