@open-xchange/vite-plugin-ox-manifests 0.4.0 → 0.4.2-pre1
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/.gitlab-ci.yml +1 -1
- package/README.md +1 -0
- package/index.js +7 -2
- package/package.json +6 -6
- package/src/plugins/meta.js +13 -0
- package/src/plugins/serve.js +6 -2
- package/test/deps/main.test.js +1 -1
- package/test/gettext-multiple/main.test.js +3 -3
- package/test/gettext-simple/main.test.js +2 -2
- package/test/html-relative-paths/index.js +2 -0
- package/test/html-relative-paths/style.css +1 -0
- package/test/manifest-multiple/main.test.js +1 -1
- package/test/manifest-simple/main.test.js +40 -2
- package/test/meta/main.test.js +25 -0
- package/test/meta/manifest.json +3 -0
- package/test/meta/register.js +1 -0
- package/test/settings-core/main.test.js +1 -1
- package/test/settings-external/main.test.js +1 -1
package/.gitlab-ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ You can provide the following options to the plugin:
|
|
|
30
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`
|
|
31
31
|
* autoloadSettings `<boolean>` If set to true, this plugin tries to auto-detect files that export settings. Prerequisites are, that the file imports `Settings` from the `io.ox/core/settings` module and have a named export called `settings`. Default true
|
|
32
32
|
* supportedEntryExtensions `<string[]>` This array defines the extensions, that are to expect as entry points. For example, if a manifest.json have `"path": "index"`, it will look for `index.js`, `index.mjs` or `index.ts` next to the manifest.json. Default: `['js', 'mjs', 'ts']`
|
|
33
|
+
* meta `<object>` An object that will be translated into a meta.json file in the root directory.
|
|
33
34
|
|
|
34
35
|
## Examples
|
|
35
36
|
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ 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
6
|
import gettextPlugin from './src/plugins/gettext.js'
|
|
7
|
+
import metaPlugin from './src/plugins/meta.js'
|
|
7
8
|
import { deepMergeObject } from './src/util.js'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -16,6 +17,7 @@ import { deepMergeObject } from './src/util.js'
|
|
|
16
17
|
* @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
|
|
17
18
|
* @param {boolean} [options.autoloadSettings=true] - If disabled, settings will not be automatically detected and therefore have to provide a manual manifest.json.
|
|
18
19
|
* @param supportedEntryExtensions {string[]=['js', 'mjs', 'ts']} - An array of valid file-extensions for entry points.
|
|
20
|
+
* @param {object} [options.meta] - An object that will be translated into a meta.json file in the root directory.
|
|
19
21
|
*/
|
|
20
22
|
export default function ({
|
|
21
23
|
watch = false,
|
|
@@ -23,7 +25,8 @@ export default function ({
|
|
|
23
25
|
manifestsAsEntryPoints = true,
|
|
24
26
|
transformAbsolutePaths = true,
|
|
25
27
|
autoloadSettings = true,
|
|
26
|
-
supportedEntryExtensions = ['js', 'mjs', 'ts']
|
|
28
|
+
supportedEntryExtensions = ['js', 'mjs', 'ts'],
|
|
29
|
+
meta
|
|
27
30
|
} = {}) {
|
|
28
31
|
const options = {
|
|
29
32
|
watch,
|
|
@@ -31,7 +34,8 @@ export default function ({
|
|
|
31
34
|
manifestsAsEntryPoints,
|
|
32
35
|
transformAbsolutePaths,
|
|
33
36
|
autoloadSettings,
|
|
34
|
-
supportedEntryExtensions
|
|
37
|
+
supportedEntryExtensions,
|
|
38
|
+
meta
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
const plugins = [
|
|
@@ -40,6 +44,7 @@ export default function ({
|
|
|
40
44
|
relativePathsPlugin(options),
|
|
41
45
|
servePlugin(options),
|
|
42
46
|
gettextPlugin(options),
|
|
47
|
+
metaPlugin(options),
|
|
43
48
|
// manifest plugin last
|
|
44
49
|
manifestsPlugin(options)
|
|
45
50
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-ox-manifests",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2-pre1",
|
|
4
4
|
"description": "A vite plugin to concat and serve ox manifests",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@open-xchange/rollup-plugin-po2json": "^0.4.1",
|
|
17
|
-
"axios": "^0.
|
|
17
|
+
"axios": "^0.26.0",
|
|
18
18
|
"chokidar": "^3.5.1",
|
|
19
19
|
"fast-glob": "^3.2.5",
|
|
20
20
|
"magic-string": "^0.25.7",
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@open-xchange/vite-plugin-ox-externals": "^0.2.0-pre2",
|
|
25
25
|
"@rollup/plugin-json": "^4.1.0",
|
|
26
|
-
"eslint": "^
|
|
26
|
+
"eslint": "^8.9.0",
|
|
27
27
|
"eslint-config-standard": "^16.0.2",
|
|
28
28
|
"eslint-plugin-import": "^2.22.1",
|
|
29
|
-
"eslint-plugin-jest": "^
|
|
29
|
+
"eslint-plugin-jest": "^26.1.1",
|
|
30
30
|
"eslint-plugin-node": "^11.1.0",
|
|
31
|
-
"eslint-plugin-promise": "^
|
|
31
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
32
32
|
"express": "^4.17.1",
|
|
33
33
|
"husky": "^7.0.1",
|
|
34
34
|
"jest": "^27.0.5",
|
|
35
35
|
"less": "^4.1.1",
|
|
36
36
|
"rollup": "^2.40.0",
|
|
37
37
|
"rollup-plugin-auto-external": "^2.0.0",
|
|
38
|
-
"vite": "^2.
|
|
38
|
+
"vite": "^2.8.3"
|
|
39
39
|
},
|
|
40
40
|
"lint-staged": {
|
|
41
41
|
"*.js": "eslint --cache --fix"
|
package/src/plugins/serve.js
CHANGED
|
@@ -11,10 +11,14 @@ const sendJSON = (res, data) => {
|
|
|
11
11
|
|
|
12
12
|
export default function ({ watch } = {}) {
|
|
13
13
|
let resolvedConfig
|
|
14
|
+
let manifestRegex
|
|
15
|
+
let depsRegex
|
|
14
16
|
|
|
15
17
|
return {
|
|
16
18
|
configResolved (config) {
|
|
17
19
|
resolvedConfig = config
|
|
20
|
+
manifestRegex = new RegExp(`^${config.base}(api/manifest.json|manifests)$`)
|
|
21
|
+
depsRegex = new RegExp(`^${config.base}(api/deps.json|dependencies)$`)
|
|
18
22
|
},
|
|
19
23
|
|
|
20
24
|
async configureServer ({ ws, middlewares, moduleGraph }) {
|
|
@@ -34,13 +38,13 @@ export default function ({ watch } = {}) {
|
|
|
34
38
|
const { path } = parseurl(req)
|
|
35
39
|
if (req.method !== 'GET') return next()
|
|
36
40
|
|
|
37
|
-
if (
|
|
41
|
+
if (manifestRegex.test(path)) {
|
|
38
42
|
const manifests = await this.getManifests()
|
|
39
43
|
await addTimestamp(manifests)
|
|
40
44
|
return sendJSON(res, manifests)
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
if (
|
|
47
|
+
if (depsRegex.test(path)) {
|
|
44
48
|
return sendJSON(res, {})
|
|
45
49
|
}
|
|
46
50
|
|
package/test/deps/main.test.js
CHANGED
|
@@ -26,7 +26,7 @@ describe('deps', function () {
|
|
|
26
26
|
})
|
|
27
27
|
await server.listen(PORT)
|
|
28
28
|
|
|
29
|
-
const { data: deps } = await axios({ baseURL: `http://
|
|
29
|
+
const { data: deps } = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/deps.json` })
|
|
30
30
|
expect(deps).toEqual({})
|
|
31
31
|
})
|
|
32
32
|
})
|
|
@@ -40,9 +40,9 @@ describe('Multiple dictionaries gettext scenario', function () {
|
|
|
40
40
|
|
|
41
41
|
const manifestFile = getFileFromBundle('manifest', bundle)
|
|
42
42
|
const manifests = JSON.parse(manifestFile.source)
|
|
43
|
-
expect(Object.keys(manifests)).toHaveLength(
|
|
43
|
+
expect(Object.keys(manifests)).toHaveLength(9)
|
|
44
44
|
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
45
|
-
expect(manifests['../../foobar'].meta.manifests[0].namespace).toEqual('i18n')
|
|
45
|
+
expect(manifests['../../foobar.js'].meta.manifests[0].namespace).toEqual('i18n')
|
|
46
46
|
expect(manifests['../../i18n'].meta.manifests[0].namespace).toEqual('i18n')
|
|
47
47
|
})
|
|
48
48
|
|
|
@@ -58,7 +58,7 @@ describe('Multiple dictionaries gettext scenario', function () {
|
|
|
58
58
|
})
|
|
59
59
|
await server.listen(PORT)
|
|
60
60
|
|
|
61
|
-
const res = await axios({ baseURL: `http://
|
|
61
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
62
62
|
const manifests = res.data
|
|
63
63
|
|
|
64
64
|
expect(manifests).toHaveLength(3)
|
|
@@ -35,7 +35,7 @@ describe('Simple gettext scenario', function () {
|
|
|
35
35
|
const manifests = JSON.parse(manifestFile.source)
|
|
36
36
|
expect(Object.keys(manifests)).toHaveLength(4)
|
|
37
37
|
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
38
|
-
expect(manifests['../../i18n'].meta.manifests[0].namespace).toEqual('i18n')
|
|
38
|
+
expect(manifests['../../i18n.js'].meta.manifests[0].namespace).toEqual('i18n')
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
it('works in dev mode', async function () {
|
|
@@ -50,7 +50,7 @@ describe('Simple gettext scenario', function () {
|
|
|
50
50
|
})
|
|
51
51
|
await server.listen(PORT)
|
|
52
52
|
|
|
53
|
-
const res = await axios({ baseURL: `http://
|
|
53
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
54
54
|
const manifests = res.data
|
|
55
55
|
|
|
56
56
|
expect(manifests).toHaveLength(2)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
body { background: green; }
|
|
@@ -60,7 +60,7 @@ describe('Multiple manifest scenario', function () {
|
|
|
60
60
|
})
|
|
61
61
|
await server.listen(PORT)
|
|
62
62
|
|
|
63
|
-
const res = await axios({ baseURL: `http://
|
|
63
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
64
64
|
const manifests = res.data
|
|
65
65
|
|
|
66
66
|
expect(manifests).toHaveLength(4)
|
|
@@ -44,7 +44,45 @@ describe('Simple manifest scenario', function () {
|
|
|
44
44
|
})
|
|
45
45
|
await server.listen(PORT)
|
|
46
46
|
|
|
47
|
-
const res = await axios({ baseURL: `http://
|
|
47
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
48
|
+
const manifests = res.data
|
|
49
|
+
|
|
50
|
+
expect(Object.keys(manifests)).toHaveLength(1)
|
|
51
|
+
expect(manifests[0].namespace).toEqual('test')
|
|
52
|
+
expect(manifests[0].path).toContain('register')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('works in dev mode with base set', async function () {
|
|
56
|
+
server = await createServer({
|
|
57
|
+
root: __dirname,
|
|
58
|
+
base: '/appsuite/',
|
|
59
|
+
logLevel: 'silent',
|
|
60
|
+
plugins: [vitePluginOxManifests({
|
|
61
|
+
|
|
62
|
+
})]
|
|
63
|
+
})
|
|
64
|
+
await server.listen(PORT)
|
|
65
|
+
|
|
66
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/appsuite/api/manifest.json` })
|
|
67
|
+
const manifests = res.data
|
|
68
|
+
|
|
69
|
+
expect(Object.keys(manifests)).toHaveLength(1)
|
|
70
|
+
expect(manifests[0].namespace).toEqual('test')
|
|
71
|
+
expect(manifests[0].path).toContain('register')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('works in dev mode with base set (new endpoint)', async function () {
|
|
75
|
+
server = await createServer({
|
|
76
|
+
root: __dirname,
|
|
77
|
+
base: '/appsuite/',
|
|
78
|
+
logLevel: 'silent',
|
|
79
|
+
plugins: [vitePluginOxManifests({
|
|
80
|
+
|
|
81
|
+
})]
|
|
82
|
+
})
|
|
83
|
+
await server.listen(PORT)
|
|
84
|
+
|
|
85
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/appsuite/manifests` })
|
|
48
86
|
const manifests = res.data
|
|
49
87
|
|
|
50
88
|
expect(Object.keys(manifests)).toHaveLength(1)
|
|
@@ -62,7 +100,7 @@ describe('Simple manifest scenario', function () {
|
|
|
62
100
|
})
|
|
63
101
|
await server.listen(PORT)
|
|
64
102
|
|
|
65
|
-
const res = await axios({ baseURL: `http://
|
|
103
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/register.js` })
|
|
66
104
|
expect(res.data).toEqual("console.log('Hello world')\n")
|
|
67
105
|
})
|
|
68
106
|
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from '@jest/globals'
|
|
2
|
+
import { build } from 'vite'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import vitePluginOxManifests from '../../index'
|
|
5
|
+
import { getFileFromBundle } from '../util'
|
|
6
|
+
|
|
7
|
+
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
8
|
+
|
|
9
|
+
describe('Meta option', function () {
|
|
10
|
+
it('works', async function () {
|
|
11
|
+
const bundle = await build({
|
|
12
|
+
root: __dirname,
|
|
13
|
+
logLevel: 'silent',
|
|
14
|
+
build: { write: false, rollupOptions: { input: {} } },
|
|
15
|
+
plugins: [vitePluginOxManifests({
|
|
16
|
+
meta: {
|
|
17
|
+
version: '1.2.3'
|
|
18
|
+
}
|
|
19
|
+
})]
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const metaFile = getFileFromBundle('meta.json', bundle)
|
|
23
|
+
expect(JSON.parse(metaFile.source)).toEqual({ version: '1.2.3' })
|
|
24
|
+
})
|
|
25
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log('Hello world')
|
|
@@ -48,7 +48,7 @@ describe('Settings like in core', function () {
|
|
|
48
48
|
})
|
|
49
49
|
await server.listen(PORT)
|
|
50
50
|
|
|
51
|
-
const res = await axios({ baseURL: `http://
|
|
51
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
52
52
|
const manifests = res.data
|
|
53
53
|
|
|
54
54
|
expect(manifests).toHaveLength(2)
|
|
@@ -53,7 +53,7 @@ describe('Settings external', function () {
|
|
|
53
53
|
})
|
|
54
54
|
await server.listen(PORT)
|
|
55
55
|
|
|
56
|
-
const res = await axios({ baseURL: `http://
|
|
56
|
+
const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
|
|
57
57
|
const manifests = res.data
|
|
58
58
|
|
|
59
59
|
expect(manifests).toHaveLength(2)
|