@opencloud-eu/extension-sdk 3.2.0 → 4.0.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.
Files changed (2) hide show
  1. package/index.mjs +67 -26
  2. package/package.json +3 -4
package/index.mjs CHANGED
@@ -5,10 +5,9 @@
5
5
  import { mergeConfig, searchForWorkspaceRoot } from 'vite'
6
6
  import { join } from 'path'
7
7
  import { cwd } from 'process'
8
- import { readFileSync } from 'fs'
8
+ import { readFileSync, existsSync } from 'fs'
9
9
 
10
10
  import vue from '@vitejs/plugin-vue'
11
- import serve from 'rollup-plugin-serve'
12
11
 
13
12
  const distDir = process.env.OPENCLOUD_EXTENSION_DIST_DIR || 'dist'
14
13
 
@@ -19,11 +18,70 @@ const defaultHttps = () =>
19
18
  cert: readFileSync(join(certsDir, 'server.crt'))
20
19
  }
21
20
 
21
+ const manifestFile = 'manifest.json'
22
+ const manifestPath = join('./src/', manifestFile)
23
+ const manifestPlugin = () => {
24
+ let outputDir
25
+
26
+ return {
27
+ name: 'manifest',
28
+ apply: 'build',
29
+ configResolved(config) {
30
+ outputDir = config.build.outDir
31
+ },
32
+ buildStart() {
33
+ this.addWatchFile(manifestPath)
34
+ },
35
+ generateBundle(options, bundle) {
36
+ const generatedManifestPath = join(outputDir, manifestFile)
37
+ if (existsSync(generatedManifestPath)) {
38
+ this.warn(
39
+ `${generatedManifestPath} already exists in output directory (likely from public/), skipping generation\n` +
40
+ `Consider using --emptyOutDir if outDir is outside of project root.`
41
+ )
42
+ return
43
+ }
44
+
45
+ // Find the entry chunk
46
+ const entryChunk = Object.values(bundle).find(
47
+ (chunk) => chunk.type === 'chunk' && chunk.isEntry
48
+ )
49
+
50
+ if (!entryChunk) {
51
+ this.error('No entry chunk found')
52
+ return
53
+ }
54
+
55
+ let manifest = {}
56
+ if (existsSync(manifestPath)) {
57
+ try {
58
+ manifest = JSON.parse(readFileSync(manifestPath).toString())
59
+ } catch (err) {
60
+ this.error(
61
+ `Failed to parse manifest.json at ${manifestPath}: ${err.message}\n` +
62
+ `Please ensure manifest.json contains a valid JSON object.`
63
+ )
64
+ return
65
+ }
66
+ }
67
+
68
+ // set entryPoint
69
+ manifest.entrypoint = entryChunk.fileName
70
+
71
+ // Add manifest.json to the bundle
72
+ this.emitFile({
73
+ type: 'asset',
74
+ fileName: 'manifest.json',
75
+ source: JSON.stringify(manifest, null, 2)
76
+ })
77
+ }
78
+ }
79
+ }
80
+
22
81
  export const defineConfig = (overrides = {}) => {
23
82
  return ({ mode }) => {
24
83
  const isProduction = mode === 'production'
25
84
  const isTesting = mode === 'test'
26
- const isServing = !isProduction && !isTesting
27
85
 
28
86
  // read package name from vite workspace
29
87
  const packageJson = JSON.parse(
@@ -32,20 +90,13 @@ export const defineConfig = (overrides = {}) => {
32
90
 
33
91
  const name = overrides.name || packageJson.name
34
92
 
35
- // take vite standard config and reuse it for rollup-plugin-serve config
36
- const { https = defaultHttps(), port = 9210, host = 'localhost' } = overrides?.server || {}
93
+ // set default config
94
+ const { https = defaultHttps(), port = 9210 } = overrides?.server || {}
37
95
  const isHttps = !!https
38
96
 
39
- if (isServing) {
40
- console.log(
41
- `>>> Serving extension at http${isHttps ? 's' : ''}://${host}:${port}/js/${name}.js`
42
- )
43
- }
44
-
45
97
  return mergeConfig(
46
98
  {
47
99
  server: {
48
- host,
49
100
  port,
50
101
  strictPort: true,
51
102
  ...(isHttps && https)
@@ -53,6 +104,7 @@ export const defineConfig = (overrides = {}) => {
53
104
  build: {
54
105
  cssCodeSplit: true,
55
106
  minify: isProduction,
107
+ outDir: distDir,
56
108
  rollupOptions: {
57
109
  // keep in sync with packages/web-runtime/src/container/application/index.ts
58
110
  external: [
@@ -77,21 +129,9 @@ export const defineConfig = (overrides = {}) => {
77
129
  },
78
130
  output: {
79
131
  format: 'amd',
80
- dir: distDir,
81
132
  chunkFileNames: join('js', 'chunks', '[name]-[hash].mjs'),
82
133
  entryFileNames: join('js', `[name]${isProduction ? '-[hash]' : ''}.js`)
83
- },
84
- plugins: [
85
- isServing &&
86
- serve({
87
- headers: {
88
- 'access-control-allow-origin': '*'
89
- },
90
- contentBase: distDir,
91
- ...(https && { https }),
92
- ...(port && { port })
93
- })
94
- ]
134
+ }
95
135
  }
96
136
  },
97
137
  plugins: [
@@ -99,7 +139,8 @@ export const defineConfig = (overrides = {}) => {
99
139
  // set to true when switching to esm
100
140
  customElement: false,
101
141
  ...(isTesting && { template: { compilerOptions: { whitespace: 'preserve' } } })
102
- })
142
+ }),
143
+ manifestPlugin()
103
144
  ],
104
145
  test: {
105
146
  globals: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencloud-eu/extension-sdk",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "description": "OpenCloud Web Extension SDK",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "index.mjs",
@@ -14,11 +14,10 @@
14
14
  "directory": "packages/extension-sdk"
15
15
  },
16
16
  "dependencies": {
17
- "@vitejs/plugin-vue": "^6.0.0",
18
- "rollup-plugin-serve": "^3.0.0"
17
+ "@vitejs/plugin-vue": "^6.0.0"
19
18
  },
20
19
  "peerDependencies": {
21
- "vite": "^5 || ^6.0.0",
20
+ "vite": "^5 || ^6.0.0 || ^7.0.0",
22
21
  "sass": "^1.79.5"
23
22
  }
24
23
  }