@opencloud-eu/extension-sdk 4.1.0-alpha.2 → 4.2.0-alpha.1

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 +38 -5
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -79,6 +79,37 @@ const manifestPlugin = () => {
79
79
  }
80
80
  }
81
81
 
82
+ // UPSTREAM: https://github.com/vitejs/vite/pull/20861
83
+ // We are trying to upstream this plugin, it can be removed once the PR above or an alternative approach has been merged
84
+ // TL;DR of the issue: vite uses the require variable for certain features but doesn't ensure it's injected into AMD modules
85
+ // thus the global require variable is used which does not have the correct base path set, so relative imports
86
+ // with ?url or ?worker break
87
+ const completeAmdWrapPlugin = () => {
88
+ const AmdWrapRE = /\bdefine\((?:\s*\[([^\]]*)\],)?\s*(?:\(\s*)?function\s*\(([^)]*)\)\s*\{/
89
+
90
+ return {
91
+ name: 'vite:force-amd-wrap-require',
92
+ enforce: 'pre',
93
+ renderChunk(code, _chunk, opts) {
94
+ if (opts.format !== 'amd') return
95
+
96
+ return {
97
+ code: code.replace(AmdWrapRE, (_, deps, params) => {
98
+ if (deps?.includes('"require"')) {
99
+ return `define([${deps}], (function(${params}) {`
100
+ }
101
+
102
+ const newDeps = deps ? `"require", ${deps}` : '"require"'
103
+ const newParams = params.trim() ? `require, ${params}` : 'require'
104
+
105
+ return `define([${newDeps}], (function(${newParams}) {`
106
+ }),
107
+ map: null // no need to generate sourcemap as no mapping exists for the wrapper
108
+ }
109
+ }
110
+ }
111
+ }
112
+
82
113
  export const defineConfig = (overrides = {}) => {
83
114
  return ({ mode }) => {
84
115
  const isProduction = mode === 'production'
@@ -97,11 +128,7 @@ export const defineConfig = (overrides = {}) => {
97
128
 
98
129
  return mergeConfig(
99
130
  {
100
- server: {
101
- port,
102
- strictPort: true,
103
- ...(isHttps && https)
104
- },
131
+ base: './', // make asset paths relative so imports work from wherever the extension is loaded
105
132
  build: {
106
133
  cssCodeSplit: true,
107
134
  minify: isProduction,
@@ -136,6 +163,7 @@ export const defineConfig = (overrides = {}) => {
136
163
  }
137
164
  },
138
165
  plugins: [
166
+ completeAmdWrapPlugin(),
139
167
  vue({
140
168
  // set to true when switching to esm
141
169
  customElement: false,
@@ -144,6 +172,11 @@ export const defineConfig = (overrides = {}) => {
144
172
  manifestPlugin(),
145
173
  tailwindcss()
146
174
  ],
175
+ server: {
176
+ port,
177
+ strictPort: true,
178
+ ...(isHttps && https)
179
+ },
147
180
  test: {
148
181
  globals: true,
149
182
  environment: 'happy-dom',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencloud-eu/extension-sdk",
3
- "version": "4.1.0-alpha.2",
3
+ "version": "4.2.0-alpha.1",
4
4
  "description": "OpenCloud Web Extension SDK",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "index.mjs",