@open-xchange/vite-plugin-ox-manifests 0.4.1 → 0.4.3

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 CHANGED
@@ -1,4 +1,4 @@
1
- image: node:15-alpine
1
+ image: node:17-alpine
2
2
 
3
3
  stages:
4
4
  - test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/vite-plugin-ox-manifests",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
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.21.1",
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": "^7.21.0",
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": "^24.3.6",
29
+ "eslint-plugin-jest": "^26.1.1",
30
30
  "eslint-plugin-node": "^11.1.0",
31
- "eslint-plugin-promise": "^4.3.1",
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.5.2"
38
+ "vite": "^2.8.3"
39
39
  },
40
40
  "lint-staged": {
41
41
  "*.js": "eslint --cache --fix"
@@ -54,9 +54,11 @@ export default function () {
54
54
  const chunk = bundle[file]
55
55
  if (!chunk.facadeModuleId) continue
56
56
 
57
- Object.keys(chunk.modules).forEach(id => {
57
+ const modules = Object.keys(chunk.modules)
58
+ if (modules.length === 0) modules.push(chunk.facadeModuleId)
59
+ modules.forEach(id => {
58
60
  const meta = this.getModuleInfo(id)?.meta
59
- if (!meta?.gettext?.dictionary === true) return
61
+ if (meta?.gettext?.dictionary !== true) return
60
62
 
61
63
  meta.manifests = meta.manifests || []
62
64
  meta.manifests.push({ namespace: 'i18n' })
@@ -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 (path === '/api/manifest.json' || path === '/manifests') {
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 (path === '/api/deps.json' || path === '/dependencies') {
47
+ if (depsRegex.test(path)) {
44
48
  return sendJSON(res, {})
45
49
  }
46
50
 
@@ -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://localhost:${PORT}/api/deps.json` })
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
  })
@@ -0,0 +1,4 @@
1
+ import gt from 'gettext'
2
+
3
+ export const five = 5
4
+ export default gt('five')
@@ -0,0 +1,16 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "PO-Revision-Date: 2014-01-15 14:13+0100\n"
5
+ "Last-Translator: Julian Bäume <julian.baeume@open-xchange.com>\n"
6
+ "Language-Team: German <julian.baeume@open-xchange.com>\n"
7
+ "Language: de_DE\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
12
+ "X-Generator: Lokalize 1.5\n"
13
+
14
+ #: module:i18n
15
+ msgid "Hello world!"
16
+ msgstr "Hallo Welt!"
@@ -0,0 +1,16 @@
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: \n"
4
+ "PO-Revision-Date: 2014-01-15 14:13+0100\n"
5
+ "Last-Translator: Julian Bäume <julian.baeume@open-xchange.com>\n"
6
+ "Language-Team: German <julian.baeume@open-xchange.com>\n"
7
+ "Language: en_US\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
12
+ "X-Generator: Lokalize 1.5\n"
13
+
14
+ #: module:i18n
15
+ msgid "Hello world!"
16
+ msgstr ""
@@ -0,0 +1,68 @@
1
+ import { describe, it, expect, afterEach } from '@jest/globals'
2
+ import { build, createServer } from 'vite'
3
+ import path from 'path'
4
+ import vitePluginOxManifests from '../../index'
5
+ import rollupPluginPo2Json from '@open-xchange/rollup-plugin-po2json'
6
+ import { getFileFromBundle, getPort } from '../util'
7
+ import axios from 'axios'
8
+
9
+ const PORT = getPort()
10
+ const __dirname = path.dirname(new URL(import.meta.url).pathname)
11
+
12
+ describe('Dictionary in modules with dynamic imports', function () {
13
+ let server
14
+
15
+ afterEach(async function () {
16
+ if (server) {
17
+ await server.close()
18
+ server = null
19
+ }
20
+ })
21
+
22
+ it('works', async function () {
23
+ const bundle = await build({
24
+ root: __dirname,
25
+ logLevel: 'silent',
26
+ build: {
27
+ write: false,
28
+ rollupOptions: {
29
+ input: { }
30
+ }
31
+ },
32
+ plugins: [rollupPluginPo2Json({
33
+ poFiles: __dirname + '/i18n/*.po'
34
+ }), vitePluginOxManifests({
35
+
36
+ })]
37
+ })
38
+
39
+ const manifestFile = getFileFromBundle('manifest', bundle)
40
+ const manifests = JSON.parse(manifestFile.source)
41
+ expect(Object.keys(manifests)).toHaveLength(6)
42
+ expect(manifests['register.js'].meta.manifests[0].namespace).toEqual('test')
43
+ expect(manifests['../../i18n.js'].meta.gettext.dictionary).toEqual(true)
44
+ expect(manifests['../../i18n.js'].meta.manifests[0].namespace).toEqual('i18n')
45
+ })
46
+
47
+ it('works in dev mode', async function () {
48
+ server = await createServer({
49
+ root: __dirname,
50
+ logLevel: 'silent',
51
+ plugins: [rollupPluginPo2Json({
52
+ poFiles: __dirname + '/i18n/*.po'
53
+ }), vitePluginOxManifests({
54
+
55
+ })]
56
+ })
57
+ await server.listen(PORT)
58
+
59
+ const res = await axios({ baseURL: `http://127.0.0.1:${PORT}/api/manifest.json` })
60
+ const manifests = res.data
61
+
62
+ expect(manifests).toHaveLength(2)
63
+ expect(manifests[0].namespace).toEqual('i18n')
64
+ expect(manifests[0].path).toEqual('i18n')
65
+ expect(manifests[1].namespace).toEqual('test')
66
+ expect(manifests[1].path).toContain('register')
67
+ })
68
+ })
@@ -0,0 +1,3 @@
1
+ {
2
+ "namespace": "test"
3
+ }
@@ -0,0 +1,6 @@
1
+ import gt from 'gettext'
2
+
3
+ export async function doSomethingDynamic () {
4
+ const { five } = await import('./another_chunk.js')
5
+ console.log(gt('Hello world!'), five)
6
+ }
@@ -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(8)
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://localhost:${PORT}/api/manifest.json` })
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://localhost:${PORT}/api/manifest.json` })
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)
@@ -1 +1,3 @@
1
+ import './style.css'
2
+
1
3
  console.log('Hello world')
@@ -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://localhost:${PORT}/api/manifest.json` })
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://localhost:${PORT}/api/manifest.json` })
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://localhost:${PORT}/register.js` })
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
  })
@@ -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://localhost:${PORT}/api/manifest.json` })
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://localhost:${PORT}/api/manifest.json` })
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)