@open-xchange/vite-plugin-ox-manifests 0.4.5 → 0.5.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/.gitlab-ci.yml +7 -3
- package/README.md +6 -1
- package/index.js +1 -2
- package/package.json +15 -16
- package/src/plugins/manifests.js +5 -5
- package/src/plugins/relative-paths.js +2 -32
- package/src/util.js +5 -1
- package/test/deps/main.test.js +2 -2
- package/test/gettext-chunked/main.test.js +3 -4
- package/test/gettext-multiple/main.test.js +3 -4
- package/test/gettext-simple/main.test.js +3 -4
- package/test/hmr/main.test.js +10 -11
- package/test/html-relative-paths/main.test.js +3 -36
- package/test/manifest-dependencies/main.test.js +1 -1
- package/test/manifest-multiple/main.test.js +2 -3
- package/test/manifest-simple/main.test.js +8 -9
- package/test/settings-core/main.test.js +2 -3
- package/test/settings-external/main.test.js +2 -3
package/.gitlab-ci.yml
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
image: node:
|
|
1
|
+
image: node:18-alpine
|
|
2
2
|
|
|
3
3
|
stages:
|
|
4
4
|
- test
|
|
5
5
|
|
|
6
6
|
unit tests:
|
|
7
|
+
stage: test
|
|
7
8
|
variables:
|
|
8
9
|
KUBERNETES_CPU_REQUEST: 2
|
|
9
10
|
KUBERNETES_CPU_LIMIT: 3
|
|
10
|
-
|
|
11
|
+
KUBERNETES_MEMORY_REQUEST: 2Gi
|
|
12
|
+
KUBERNETES_MEMORY_LIMIT: 2Gi
|
|
11
13
|
script:
|
|
12
14
|
- apk add git
|
|
13
15
|
- yarn
|
|
@@ -16,7 +18,9 @@ unit tests:
|
|
|
16
18
|
artifacts:
|
|
17
19
|
reports:
|
|
18
20
|
junit: output/junit.xml
|
|
19
|
-
|
|
21
|
+
coverage_report:
|
|
22
|
+
coverage_format: cobertura
|
|
23
|
+
path: output/coverage/cobertura-coverage.xml
|
|
20
24
|
needs: []
|
|
21
25
|
tags:
|
|
22
26
|
- kubernetes
|
package/README.md
CHANGED
|
@@ -27,7 +27,6 @@ You can provide the following options to the plugin:
|
|
|
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
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`
|
|
29
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`
|
|
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
30
|
* 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
31
|
* 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
32
|
* meta `<object>` An object that will be translated into a meta.json file in the root directory.
|
|
@@ -51,3 +50,9 @@ export const settings = new Settings('test', () => {})
|
|
|
51
50
|
```sh
|
|
52
51
|
yarn test
|
|
53
52
|
```
|
|
53
|
+
|
|
54
|
+
## Migration guide
|
|
55
|
+
|
|
56
|
+
### From 0.x to 1.x
|
|
57
|
+
|
|
58
|
+
The field `transformAbsolutePaths` has been removed as you can use `base: './'` within your vite configuration.
|
package/index.js
CHANGED
|
@@ -14,7 +14,6 @@ import { deepMergeObject } from './src/util.js'
|
|
|
14
14
|
* @param {boolean} [options.watch=false] - If set to true, this plugin will watch manifest changes and reload the ui
|
|
15
15
|
* @param {string} [options.entryPoints] - Convenience method to specify additional entry points for the production build. Can be specified as a glob-pattern.
|
|
16
16
|
* @param {boolean} [options.manifestsAsEntryPoints=true] - Specifies, that every path in a manifest is used as an entry-point for the production build.
|
|
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
|
|
18
17
|
* @param {boolean} [options.autoloadSettings=true] - If disabled, settings will not be automatically detected and therefore have to provide a manual manifest.json.
|
|
19
18
|
* @param supportedEntryExtensions {string[]=['js', 'mjs', 'ts']} - An array of valid file-extensions for entry points.
|
|
20
19
|
* @param {object} [options.meta] - An object that will be translated into a meta.json file in the root directory.
|
|
@@ -23,7 +22,7 @@ export default function ({
|
|
|
23
22
|
watch = false,
|
|
24
23
|
entryPoints,
|
|
25
24
|
manifestsAsEntryPoints = true,
|
|
26
|
-
transformAbsolutePaths
|
|
25
|
+
transformAbsolutePaths,
|
|
27
26
|
autoloadSettings = true,
|
|
28
27
|
supportedEntryExtensions = ['js', 'mjs', 'ts'],
|
|
29
28
|
meta
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/vite-plugin-ox-manifests",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "A vite plugin to concat and serve ox manifests",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,32 +10,31 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"lint": "eslint *.js src/**/*.js test/**/**.js",
|
|
12
12
|
"prepare": "husky install",
|
|
13
|
-
"test": "NODE_OPTIONS
|
|
13
|
+
"test": "NODE_OPTIONS=\"--experimental-vm-modules --max_old_space_size=1792\" jest test/**/*.test.js --testTimeout=15000 --runInBand"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@open-xchange/rollup-plugin-po2json": "^0.
|
|
17
|
-
"axios": "^0.26.0",
|
|
16
|
+
"@open-xchange/rollup-plugin-po2json": "^0.5.0",
|
|
18
17
|
"chokidar": "^3.5.1",
|
|
19
18
|
"fast-glob": "^3.2.5",
|
|
20
|
-
"magic-string": "^0.
|
|
19
|
+
"magic-string": "^0.26.2",
|
|
21
20
|
"parseurl": "^1.3.3"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
|
-
"@open-xchange/vite-plugin-ox-externals": "^0.
|
|
23
|
+
"@open-xchange/vite-plugin-ox-externals": "^0.3.0",
|
|
25
24
|
"@rollup/plugin-json": "^4.1.0",
|
|
26
|
-
"eslint": "^8.
|
|
27
|
-
"eslint-config-standard": "^
|
|
28
|
-
"eslint-plugin-import": "^2.
|
|
29
|
-
"eslint-plugin-jest": "^26.
|
|
25
|
+
"eslint": "^8.21.0",
|
|
26
|
+
"eslint-config-standard": "^17.0.0",
|
|
27
|
+
"eslint-plugin-import": "^2.26.0",
|
|
28
|
+
"eslint-plugin-jest": "^26.8.0",
|
|
30
29
|
"eslint-plugin-node": "^11.1.0",
|
|
31
30
|
"eslint-plugin-promise": "^6.0.0",
|
|
32
|
-
"express": "^4.
|
|
33
|
-
"husky": "^
|
|
34
|
-
"jest": "^
|
|
35
|
-
"less": "^4.1.
|
|
36
|
-
"rollup": "^2.
|
|
31
|
+
"express": "^4.18.1",
|
|
32
|
+
"husky": "^8.0.1",
|
|
33
|
+
"jest": "^28.1.3",
|
|
34
|
+
"less": "^4.1.3",
|
|
35
|
+
"rollup": "^2.77.2",
|
|
37
36
|
"rollup-plugin-auto-external": "^2.0.0",
|
|
38
|
-
"vite": "^
|
|
37
|
+
"vite": "^3.0.4"
|
|
39
38
|
},
|
|
40
39
|
"lint-staged": {
|
|
41
40
|
"*.js": "eslint --cache --fix"
|
package/src/plugins/manifests.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import fs from 'fs'
|
|
3
3
|
import fastGlob from 'fast-glob'
|
|
4
|
-
import { applyInputToOptions, basepath } from '../util.js'
|
|
4
|
+
import { applyInputToOptions, basepath, joinUrlPaths } from '../util.js'
|
|
5
5
|
|
|
6
6
|
async function getManifestEntryFile (basePath, extensions) {
|
|
7
7
|
if (path.extname(basePath)) {
|
|
@@ -81,12 +81,12 @@ export default function ({ supportedEntryExtensions, entryPoints, manifestsAsEnt
|
|
|
81
81
|
const manifests = [].concat(json)
|
|
82
82
|
const manifestDir = path.dirname(entry).substr(root.length + 1)
|
|
83
83
|
|
|
84
|
-
await Promise.all(manifests.map(async ({ path: srcManifestEntryPath =
|
|
85
|
-
const { dir, base } = await getManifestEntryFile(
|
|
86
|
-
const manifestEntryPath =
|
|
84
|
+
await Promise.all(manifests.map(async ({ path: srcManifestEntryPath = joinUrlPaths(manifestDir, 'register'), ...rest }) => {
|
|
85
|
+
const { dir, base } = await getManifestEntryFile(joinUrlPaths(root, srcManifestEntryPath), supportedEntryExtensions)
|
|
86
|
+
const manifestEntryPath = joinUrlPaths(dir, base)
|
|
87
87
|
|
|
88
88
|
if (manifestsAsEntryPoints) {
|
|
89
|
-
input[basepath(
|
|
89
|
+
input[basepath(joinUrlPaths(path.dirname(srcManifestEntryPath), base))] = manifestEntryPath
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
// 3. put the file content except path into the manifest modules
|
|
@@ -2,36 +2,6 @@ import { PROJECT_NAME as name } from '../constants.js'
|
|
|
2
2
|
import MagicString from 'magic-string'
|
|
3
3
|
|
|
4
4
|
export default function ({ transformAbsolutePaths } = {}) {
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
configResolved (config) {
|
|
8
|
-
resolvedConfig = config
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
transform (code, id) {
|
|
12
|
-
if (id === 'vite/preload-helper') {
|
|
13
|
-
// 2.5.2 transformation
|
|
14
|
-
if (code.search(/const base = '[^']*'/) >= 0) {
|
|
15
|
-
const s = new MagicString(code.replace(/const base = '[^']*'/, 'const base = \'./\''))
|
|
16
|
-
return { code: s.toString(), map: s.generateMap({ hires: true }) }
|
|
17
|
-
} else if (code.indexOf('return Promise.all(deps.map((dep) => {')) {
|
|
18
|
-
// pre 2.5 transformation
|
|
19
|
-
const code = 'return Promise.all(deps.map((dep) => {'
|
|
20
|
-
const s = new MagicString(code.replace(code, `${code}\ndep = dep.startsWith('/') ? \`.\${dep}\` : \`./\${dep}\``))
|
|
21
|
-
return { code: s.toString(), map: s.generateMap({ hires: true }) }
|
|
22
|
-
} else {
|
|
23
|
-
throw new Error(`Cannot transform preload helper. Consider upgrading "${name}".`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
transformIndexHtml (src) {
|
|
29
|
-
if (!transformAbsolutePaths) return src
|
|
30
|
-
if (resolvedConfig.mode !== 'production') return src
|
|
31
|
-
|
|
32
|
-
return src
|
|
33
|
-
.replace(/(<link[^>]*href="?)(\/)/g, '$1.$2')
|
|
34
|
-
.replace(/(<script[^>]*src="?)(\/)/g, '$1.$2')
|
|
35
|
-
}
|
|
36
|
-
}
|
|
5
|
+
if (transformAbsolutePaths !== undefined) console.warn("transformAbsolutePaths is no longer used. Use `base: './'` with vite 3")
|
|
6
|
+
return {}
|
|
37
7
|
}
|
package/src/util.js
CHANGED
|
@@ -17,9 +17,13 @@ export function applyInputToOptions (input, options) {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export function joinUrlPaths (...paths) {
|
|
21
|
+
return path.join.apply(path, paths).replace(/\\+/g, '/')
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
export function basepath (src) {
|
|
21
25
|
const { dir, name } = path.parse(src)
|
|
22
|
-
return
|
|
26
|
+
return joinUrlPaths(dir, name)
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export function deepMergeObject (a, b) {
|
package/test/deps/main.test.js
CHANGED
|
@@ -3,7 +3,6 @@ import { createServer } from 'vite'
|
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import { getPort } from '../util'
|
|
6
|
-
import axios from 'axios'
|
|
7
6
|
|
|
8
7
|
const PORT = getPort()
|
|
9
8
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
@@ -26,7 +25,8 @@ describe('deps', function () {
|
|
|
26
25
|
})
|
|
27
26
|
await server.listen(PORT)
|
|
28
27
|
|
|
29
|
-
const
|
|
28
|
+
const res = await fetch(`http://localhost:${PORT}/api/deps.json`)
|
|
29
|
+
const deps = await res.json()
|
|
30
30
|
expect(deps).toEqual({})
|
|
31
31
|
})
|
|
32
32
|
})
|
|
@@ -4,7 +4,6 @@ import path from 'path'
|
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import rollupPluginPo2Json from '@open-xchange/rollup-plugin-po2json'
|
|
6
6
|
import { getFileFromBundle, getPort } from '../util'
|
|
7
|
-
import axios from 'axios'
|
|
8
7
|
|
|
9
8
|
const PORT = getPort()
|
|
10
9
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
@@ -38,7 +37,7 @@ describe('Dictionary in modules with dynamic imports', function () {
|
|
|
38
37
|
|
|
39
38
|
const manifestFile = getFileFromBundle('manifest', bundle)
|
|
40
39
|
const manifests = JSON.parse(manifestFile.source)
|
|
41
|
-
expect(Object.keys(manifests)).toHaveLength(
|
|
40
|
+
expect(Object.keys(manifests)).toHaveLength(7)
|
|
42
41
|
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
43
42
|
expect(manifests['../../i18n.js'].meta.gettext.dictionary).toEqual(true)
|
|
44
43
|
expect(manifests['../../i18n.js'].meta.manifests[0].namespace).toEqual('i18n')
|
|
@@ -56,8 +55,8 @@ describe('Dictionary in modules with dynamic imports', function () {
|
|
|
56
55
|
})
|
|
57
56
|
await server.listen(PORT)
|
|
58
57
|
|
|
59
|
-
const res = await
|
|
60
|
-
const manifests = res.
|
|
58
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
59
|
+
const manifests = await res.json()
|
|
61
60
|
|
|
62
61
|
expect(manifests).toHaveLength(2)
|
|
63
62
|
expect(manifests[0].namespace).toEqual('i18n')
|
|
@@ -4,7 +4,6 @@ import path from 'path'
|
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import rollupPluginPo2Json from '@open-xchange/rollup-plugin-po2json'
|
|
6
6
|
import { getFileFromBundle, getPort } from '../util'
|
|
7
|
-
import axios from 'axios'
|
|
8
7
|
|
|
9
8
|
const PORT = getPort()
|
|
10
9
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
@@ -40,7 +39,7 @@ describe('Multiple dictionaries gettext scenario', function () {
|
|
|
40
39
|
|
|
41
40
|
const manifestFile = getFileFromBundle('manifest', bundle)
|
|
42
41
|
const manifests = JSON.parse(manifestFile.source)
|
|
43
|
-
expect(Object.keys(manifests)).toHaveLength(
|
|
42
|
+
expect(Object.keys(manifests)).toHaveLength(10)
|
|
44
43
|
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
45
44
|
expect(manifests['../../foobar.js'].meta.manifests[0].namespace).toEqual('i18n')
|
|
46
45
|
expect(manifests['../../i18n'].meta.manifests[0].namespace).toEqual('i18n')
|
|
@@ -58,8 +57,8 @@ describe('Multiple dictionaries gettext scenario', function () {
|
|
|
58
57
|
})
|
|
59
58
|
await server.listen(PORT)
|
|
60
59
|
|
|
61
|
-
const res = await
|
|
62
|
-
const manifests = res.
|
|
60
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
61
|
+
const manifests = await res.json()
|
|
63
62
|
|
|
64
63
|
expect(manifests).toHaveLength(3)
|
|
65
64
|
expect(manifests[0].namespace).toEqual('i18n')
|
|
@@ -4,7 +4,6 @@ import path from 'path'
|
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import rollupPluginPo2Json from '@open-xchange/rollup-plugin-po2json'
|
|
6
6
|
import { getFileFromBundle, getPort } from '../util'
|
|
7
|
-
import axios from 'axios'
|
|
8
7
|
|
|
9
8
|
const PORT = getPort()
|
|
10
9
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
@@ -33,7 +32,7 @@ describe('Simple gettext scenario', function () {
|
|
|
33
32
|
|
|
34
33
|
const manifestFile = getFileFromBundle('manifest', bundle)
|
|
35
34
|
const manifests = JSON.parse(manifestFile.source)
|
|
36
|
-
expect(Object.keys(manifests)).toHaveLength(
|
|
35
|
+
expect(Object.keys(manifests)).toHaveLength(5)
|
|
37
36
|
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
38
37
|
expect(manifests['../../i18n.js'].meta.manifests[0].namespace).toEqual('i18n')
|
|
39
38
|
})
|
|
@@ -50,8 +49,8 @@ describe('Simple gettext scenario', function () {
|
|
|
50
49
|
})
|
|
51
50
|
await server.listen(PORT)
|
|
52
51
|
|
|
53
|
-
const res = await
|
|
54
|
-
const manifests = res.
|
|
52
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
53
|
+
const manifests = await res.json()
|
|
55
54
|
|
|
56
55
|
expect(manifests).toHaveLength(2)
|
|
57
56
|
expect(manifests[0].namespace).toEqual('i18n')
|
package/test/hmr/main.test.js
CHANGED
|
@@ -3,7 +3,6 @@ import { createServer } from 'vite'
|
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import { getPort } from '../util'
|
|
6
|
-
import axios from 'axios'
|
|
7
6
|
import { readFileSync, writeFileSync } from 'fs'
|
|
8
7
|
import { waitForReload } from '../../src/util'
|
|
9
8
|
import vitePluginOxExternals from '@open-xchange/vite-plugin-ox-externals'
|
|
@@ -39,9 +38,9 @@ describe('HMR', function () {
|
|
|
39
38
|
await server.listen(PORT)
|
|
40
39
|
|
|
41
40
|
// fetch this file to start watcher
|
|
42
|
-
await
|
|
41
|
+
await fetch(`http://localhost:${PORT}/register.js`)
|
|
43
42
|
|
|
44
|
-
const
|
|
43
|
+
const manifests = await fetch(`http://localhost:${PORT}/manifests`).then(r => r.json())
|
|
45
44
|
expect(Object.keys(manifests)).toHaveLength(2)
|
|
46
45
|
expect(manifests[1]).not.toContain('raw')
|
|
47
46
|
|
|
@@ -49,7 +48,7 @@ describe('HMR', function () {
|
|
|
49
48
|
|
|
50
49
|
await waitForReload(server)
|
|
51
50
|
|
|
52
|
-
const
|
|
51
|
+
const manifestsWithHMR = await fetch(`http://localhost:${PORT}/manifests`).then(r => r.json())
|
|
53
52
|
expect(Object.keys(manifestsWithHMR)).toHaveLength(2)
|
|
54
53
|
expect(manifestsWithHMR[1].namespace).toEqual('test')
|
|
55
54
|
expect(manifestsWithHMR[1].raw).toMatch(/\/register\.js\?t=\d+/)
|
|
@@ -68,9 +67,9 @@ describe('HMR', function () {
|
|
|
68
67
|
await server.listen(PORT)
|
|
69
68
|
|
|
70
69
|
// fetch this file to start watcher
|
|
71
|
-
await
|
|
70
|
+
await fetch(`http://localhost:${PORT}/settings.js`)
|
|
72
71
|
|
|
73
|
-
const
|
|
72
|
+
const manifests = await fetch(`http://localhost:${PORT}/manifests`).then(r => r.json())
|
|
74
73
|
expect(Object.keys(manifests)).toHaveLength(2)
|
|
75
74
|
expect(manifests[0]).not.toContain('raw')
|
|
76
75
|
|
|
@@ -78,7 +77,7 @@ describe('HMR', function () {
|
|
|
78
77
|
|
|
79
78
|
await waitForReload(server)
|
|
80
79
|
|
|
81
|
-
const
|
|
80
|
+
const manifestsWithHMR = await fetch(`http://localhost:${PORT}/manifests`).then(r => r.json())
|
|
82
81
|
expect(Object.keys(manifestsWithHMR)).toHaveLength(2)
|
|
83
82
|
expect(manifestsWithHMR[0].namespace).toEqual('settings')
|
|
84
83
|
expect(manifestsWithHMR[0].raw).toMatch(/\/settings\.js\?t=\d+/)
|
|
@@ -98,10 +97,10 @@ describe('HMR', function () {
|
|
|
98
97
|
await server.listen(PORT)
|
|
99
98
|
|
|
100
99
|
// fetch this file to start watcher
|
|
101
|
-
await
|
|
102
|
-
await
|
|
100
|
+
await fetch(`http://localhost:${PORT}/appsuite/register.js`)
|
|
101
|
+
await fetch(`http://localhost:${PORT}/appsuite/settings.js`)
|
|
103
102
|
|
|
104
|
-
const
|
|
103
|
+
const manifests = await fetch(`http://localhost:${PORT}/appsuite/manifests`).then(r => r.json())
|
|
105
104
|
expect(Object.keys(manifests)).toHaveLength(2)
|
|
106
105
|
expect(manifests[0]).not.toContain('raw')
|
|
107
106
|
expect(manifests[1]).not.toContain('raw')
|
|
@@ -112,7 +111,7 @@ describe('HMR', function () {
|
|
|
112
111
|
writeFileSync(path.join(__dirname, 'settings.js'), `/* a comment */${data[1].toString()}`)
|
|
113
112
|
await waitForReload(server)
|
|
114
113
|
|
|
115
|
-
const
|
|
114
|
+
const manifestsWithHMR = await fetch(`http://localhost:${PORT}/appsuite/manifests`).then(r => r.json())
|
|
116
115
|
expect(Object.keys(manifestsWithHMR)).toHaveLength(2)
|
|
117
116
|
expect(manifestsWithHMR[0].namespace).toEqual('settings')
|
|
118
117
|
expect(manifestsWithHMR[0].raw).toMatch(/\/appsuite\/settings\.js\?t=\d+/)
|
|
@@ -7,41 +7,12 @@ import { getFileFromBundle } from '../util'
|
|
|
7
7
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
8
8
|
|
|
9
9
|
describe('HTML relative paths', function () {
|
|
10
|
-
it('untransformed paths', async function () {
|
|
11
|
-
const bundle = await build({
|
|
12
|
-
root: __dirname,
|
|
13
|
-
logLevel: 'silent',
|
|
14
|
-
build: {
|
|
15
|
-
write: false,
|
|
16
|
-
rollupOptions: {
|
|
17
|
-
input: {
|
|
18
|
-
'index.html': path.join(__dirname, 'index.html'),
|
|
19
|
-
'other.html': path.join(__dirname, 'other.html')
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
plugins: [vitePluginOxManifests({
|
|
24
|
-
transformAbsolutePaths: false
|
|
25
|
-
})]
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
const indexFile = getFileFromBundle('index.html', bundle)
|
|
29
|
-
expect(indexFile.source).not.toContain('src="./')
|
|
30
|
-
expect(indexFile.source).not.toContain('href="./')
|
|
31
|
-
expect(indexFile.source).toContain('src="/')
|
|
32
|
-
expect(indexFile.source).toContain('href="/')
|
|
33
|
-
|
|
34
|
-
const otherFile = getFileFromBundle('other.html', bundle)
|
|
35
|
-
expect(otherFile.source).not.toContain('src="./')
|
|
36
|
-
expect(otherFile.source).not.toContain('href="./')
|
|
37
|
-
expect(otherFile.source).toContain('src="/')
|
|
38
|
-
expect(otherFile.source).toContain('href="/')
|
|
39
|
-
})
|
|
40
|
-
|
|
41
10
|
it('transforms paths', async function () {
|
|
11
|
+
// keep this test here as reference. Transformation is now done via vite itself
|
|
42
12
|
const bundle = await build({
|
|
43
13
|
root: __dirname,
|
|
44
14
|
logLevel: 'silent',
|
|
15
|
+
base: './',
|
|
45
16
|
build: {
|
|
46
17
|
write: false,
|
|
47
18
|
rollupOptions: {
|
|
@@ -50,11 +21,7 @@ describe('HTML relative paths', function () {
|
|
|
50
21
|
'other.html': path.join(__dirname, 'other.html')
|
|
51
22
|
}
|
|
52
23
|
}
|
|
53
|
-
}
|
|
54
|
-
plugins: [vitePluginOxManifests({
|
|
55
|
-
// is set to true anyways, just to be clear here
|
|
56
|
-
transformAbsolutePaths: true
|
|
57
|
-
})]
|
|
24
|
+
}
|
|
58
25
|
})
|
|
59
26
|
|
|
60
27
|
const indexFile = getFileFromBundle('index.html', bundle)
|
|
@@ -19,7 +19,7 @@ describe('Manifest with dependencies', function () {
|
|
|
19
19
|
|
|
20
20
|
const manifestFile = getFileFromBundle('manifest', bundle)
|
|
21
21
|
const manifests = JSON.parse(manifestFile.source)
|
|
22
|
-
expect(Object.keys(manifests)).toHaveLength(
|
|
22
|
+
expect(Object.keys(manifests)).toHaveLength(2)
|
|
23
23
|
expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
|
|
24
24
|
expect(manifests['register.js'].css).toHaveLength(1)
|
|
25
25
|
})
|
|
@@ -4,7 +4,6 @@ import path from 'path'
|
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import vitePluginOxExternals from '@open-xchange/vite-plugin-ox-externals'
|
|
6
6
|
import { getFileFromBundle, getPort } from '../util'
|
|
7
|
-
import axios from 'axios'
|
|
8
7
|
|
|
9
8
|
const PORT = getPort()
|
|
10
9
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
@@ -60,8 +59,8 @@ describe('Multiple manifest scenario', function () {
|
|
|
60
59
|
})
|
|
61
60
|
await server.listen(PORT)
|
|
62
61
|
|
|
63
|
-
const res = await
|
|
64
|
-
const manifests = res.
|
|
62
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
63
|
+
const manifests = await res.json()
|
|
65
64
|
|
|
66
65
|
expect(manifests).toHaveLength(4)
|
|
67
66
|
|
|
@@ -3,7 +3,6 @@ import { build, createServer } from 'vite'
|
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import { getFileFromBundle, getPort } from '../util'
|
|
6
|
-
import axios from 'axios'
|
|
7
6
|
|
|
8
7
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
|
9
8
|
const PORT = getPort()
|
|
@@ -44,8 +43,8 @@ describe('Simple manifest scenario', function () {
|
|
|
44
43
|
})
|
|
45
44
|
await server.listen(PORT)
|
|
46
45
|
|
|
47
|
-
const res = await
|
|
48
|
-
const manifests = res.
|
|
46
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
47
|
+
const manifests = await res.json()
|
|
49
48
|
|
|
50
49
|
expect(Object.keys(manifests)).toHaveLength(1)
|
|
51
50
|
expect(manifests[0].namespace).toEqual('test')
|
|
@@ -63,8 +62,8 @@ describe('Simple manifest scenario', function () {
|
|
|
63
62
|
})
|
|
64
63
|
await server.listen(PORT)
|
|
65
64
|
|
|
66
|
-
const res = await
|
|
67
|
-
const manifests = res.
|
|
65
|
+
const res = await fetch(`http://localhost:${PORT}/appsuite/api/manifest.json`)
|
|
66
|
+
const manifests = await res.json()
|
|
68
67
|
|
|
69
68
|
expect(Object.keys(manifests)).toHaveLength(1)
|
|
70
69
|
expect(manifests[0].namespace).toEqual('test')
|
|
@@ -82,8 +81,8 @@ describe('Simple manifest scenario', function () {
|
|
|
82
81
|
})
|
|
83
82
|
await server.listen(PORT)
|
|
84
83
|
|
|
85
|
-
const res = await
|
|
86
|
-
const manifests = res.
|
|
84
|
+
const res = await fetch(`http://localhost:${PORT}/appsuite/manifests`)
|
|
85
|
+
const manifests = await res.json()
|
|
87
86
|
|
|
88
87
|
expect(Object.keys(manifests)).toHaveLength(1)
|
|
89
88
|
expect(manifests[0].namespace).toEqual('test')
|
|
@@ -100,7 +99,7 @@ describe('Simple manifest scenario', function () {
|
|
|
100
99
|
})
|
|
101
100
|
await server.listen(PORT)
|
|
102
101
|
|
|
103
|
-
const res = await
|
|
104
|
-
expect(res.
|
|
102
|
+
const res = await fetch(`http://localhost:${PORT}/register.js`)
|
|
103
|
+
expect(await res.text()).toEqual("console.log('Hello world')\n")
|
|
105
104
|
})
|
|
106
105
|
})
|
|
@@ -3,7 +3,6 @@ import { build, createServer } from 'vite'
|
|
|
3
3
|
import path from 'path'
|
|
4
4
|
import vitePluginOxManifests from '../../index'
|
|
5
5
|
import { getFileFromBundle, getPort } from '../util'
|
|
6
|
-
import axios from 'axios'
|
|
7
6
|
|
|
8
7
|
const PORT = getPort()
|
|
9
8
|
|
|
@@ -48,8 +47,8 @@ describe('Settings like in core', function () {
|
|
|
48
47
|
})
|
|
49
48
|
await server.listen(PORT)
|
|
50
49
|
|
|
51
|
-
const res = await
|
|
52
|
-
const manifests = res.
|
|
50
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
51
|
+
const manifests = await res.json()
|
|
53
52
|
|
|
54
53
|
expect(manifests).toHaveLength(2)
|
|
55
54
|
expect(manifests[0].namespace).toEqual('settings')
|
|
@@ -4,7 +4,6 @@ import vitePluginOxExternals from '@open-xchange/vite-plugin-ox-externals'
|
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import vitePluginOxManifests from '../../index'
|
|
6
6
|
import { getFileFromBundle, getPort } from '../util'
|
|
7
|
-
import axios from 'axios'
|
|
8
7
|
|
|
9
8
|
const PORT = getPort()
|
|
10
9
|
|
|
@@ -53,8 +52,8 @@ describe('Settings external', function () {
|
|
|
53
52
|
})
|
|
54
53
|
await server.listen(PORT)
|
|
55
54
|
|
|
56
|
-
const res = await
|
|
57
|
-
const manifests = res.
|
|
55
|
+
const res = await fetch(`http://localhost:${PORT}/api/manifest.json`)
|
|
56
|
+
const manifests = await res.json()
|
|
58
57
|
|
|
59
58
|
expect(manifests).toHaveLength(2)
|
|
60
59
|
expect(manifests[0].namespace).toEqual('settings')
|