@open-xchange/vite-plugin-ox-manifests 0.2.1 → 0.2.2

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/index.js CHANGED
@@ -6,6 +6,7 @@ import servePlugin from './src/plugins/serve.js'
6
6
  import serverManifestPlugin from './src/plugins/server-manifests.js'
7
7
  import gettextPlugin from './src/plugins/gettext.js'
8
8
  import { deepMergeObject } from './src/util.js'
9
+ import additionalManifestsPlugin from './src/plugins/additional-manifests.js'
9
10
 
10
11
  /**
11
12
  * Creates a vite-plugin to include manifests in dev and production mode
@@ -13,6 +14,7 @@ import { deepMergeObject } from './src/util.js'
13
14
  * @param {object} [options]
14
15
  * @param {boolean} [options.watch=false] - If set to true, this plugin will watch manifest changes and reload the ui
15
16
  * @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.
17
+ * @param {Array} [options.additionalManifestUrls] - You can add additional urls which can point to manifest files during development. This parameter will be ignored in production
16
18
  * @param {string} [options.entryPoints] - Convenience method to specify additional entry points for the production build. Can be specified as a glob-pattern.
17
19
  * @param {boolean} [options.manifestsAsEntryPoints=true] - Specifies, that every path in a manifest is used as an entry-point for the production build.
18
20
  * @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
@@ -22,6 +24,7 @@ import { deepMergeObject } from './src/util.js'
22
24
  export default function ({
23
25
  watch = false,
24
26
  appsuiteUrl,
27
+ additionalManifestUrls,
25
28
  entryPoints,
26
29
  manifestsAsEntryPoints = true,
27
30
  transformAbsolutePaths = true,
@@ -31,6 +34,7 @@ export default function ({
31
34
  const options = {
32
35
  watch,
33
36
  appsuiteUrl,
37
+ additionalManifestUrls,
34
38
  entryPoints,
35
39
  manifestsAsEntryPoints,
36
40
  transformAbsolutePaths,
@@ -44,6 +48,7 @@ export default function ({
44
48
  relativePathsPlugin(options),
45
49
  servePlugin(options),
46
50
  serverManifestPlugin(options),
51
+ additionalManifestsPlugin(options),
47
52
  gettextPlugin(options),
48
53
  // manifest plugin last
49
54
  manifestsPlugin(options)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/vite-plugin-ox-manifests",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "A vite plugin to concat and serve ox manifests",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,18 @@
1
+ import axios from 'axios'
2
+
3
+ export default function ({ additionalManifestUrls = [] } = {}) {
4
+ return {
5
+ async getManifests () {
6
+ const manifestSets = await Promise.all(additionalManifestUrls.map(async url => {
7
+ try {
8
+ const res = await axios.get(url)
9
+ return res.data
10
+ } catch (e) {
11
+ console.error(`Could not fetch manifest ${url}`, e)
12
+ return []
13
+ }
14
+ }))
15
+ return manifestSets.flat(1)
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,64 @@
1
+ import { describe, it, expect, afterEach } from '@jest/globals'
2
+ import { createServer } from 'vite'
3
+ import path from 'path'
4
+ import vitePluginOxManifests from '../../index'
5
+ import { getPort } from '../util'
6
+ import axios from 'axios'
7
+ import express from 'express'
8
+
9
+ const __dirname = path.dirname(new URL(import.meta.url).pathname)
10
+ const PORT = getPort()
11
+ const MANIFEST_PORT = getPort()
12
+ const OTHER_PORT = getPort()
13
+
14
+ describe('Additional upstream manifests', function () {
15
+ let server, manifestServer, otherServer
16
+
17
+ afterEach(async function () {
18
+ if (server) {
19
+ await server.close()
20
+ server = null
21
+ }
22
+ if (manifestServer) {
23
+ await manifestServer.close()
24
+ manifestServer = null
25
+ }
26
+ if (otherServer) {
27
+ await otherServer.close()
28
+ otherServer = null
29
+ }
30
+ })
31
+
32
+ it('works in dev mode', async function () {
33
+ server = await createServer({
34
+ root: __dirname,
35
+ logLevel: 'silent',
36
+ plugins: [vitePluginOxManifests({
37
+ appsuiteUrl: `http://localhost:${MANIFEST_PORT}`,
38
+ additionalManifestUrls: [`http://localhost:${OTHER_PORT}/path/to/file.json`]
39
+ })]
40
+ })
41
+ await server.listen(PORT)
42
+
43
+ // create a manifest server
44
+ const app = express()
45
+ manifestServer = app.listen(MANIFEST_PORT)
46
+ app.get('/api/manifest.json', (req, res) => {
47
+ res.json([{ namespace: 'server' }])
48
+ })
49
+
50
+ // create other server with random endpoint
51
+ const app2 = express()
52
+ otherServer = app2.listen(OTHER_PORT)
53
+ app2.get('/path/to/file.json', (req, res) => {
54
+ res.json([{ namespace: 'other' }])
55
+ })
56
+
57
+ const res = await axios({ baseURL: `http://localhost:${PORT}/api/manifest.json` })
58
+ const manifests = res.data
59
+ expect(Object.keys(manifests)).toHaveLength(3)
60
+ expect(manifests.map(m => m.namespace)).toContain('test')
61
+ expect(manifests.map(m => m.namespace)).toContain('server')
62
+ expect(manifests.map(m => m.namespace)).toContain('other')
63
+ })
64
+ })
@@ -0,0 +1,3 @@
1
+ {
2
+ "namespace": "test"
3
+ }
@@ -0,0 +1 @@
1
+ console.log('Hello world')