@open-xchange/app-suite-ui-sdk 0.0.0-stage → 0.1.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/README.md CHANGED
@@ -1,3 +1,118 @@
1
- # Temporary Holding Version
1
+ # @open-xchange/app-suite-ui-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared build, lint and test tooling for OX App Suite UI projects: core ui, plugins, customer plugins and services with a UI build.
4
+
5
+ A project depends on this one package instead of vite, eslint, stylelint, vitest, lefthook and their plugins. A tool bump or a security fix becomes one SDK release. Renovate then rolls it out to every project with one automerged MR. Tracked in [IDEAS-16](https://jira.atlassian.open-xchange.com/browse/IDEAS-16).
6
+
7
+ ## Status
8
+
9
+ Version 0.1 ships the CLI, the configs and `doctor`. Not in place yet: automatic release on merge, the downstream core ui pipeline that gates SDK MRs, and the SDK renovate preset with the `doctor --fix` post-upgrade task.
10
+
11
+ ## Setup
12
+
13
+ ```sh
14
+ pnpm add -D @open-xchange/app-suite-ui-sdk
15
+ pnpm exec ui-sdk doctor --fix
16
+ pnpm install
17
+ ```
18
+
19
+ `doctor --fix` removes the tooling the SDK provides from `package.json`, points the scripts at `ui-sdk`, and writes the pnpm settings the SDK needs into `pnpm-workspace.yaml`.
20
+
21
+ ## Commands
22
+
23
+ | Command | Runs | Default arguments |
24
+ |---|---|---|
25
+ | `ui-sdk dev` | vite dev server | |
26
+ | `ui-sdk build` | `vite build` | |
27
+ | `ui-sdk test` | vitest | `--run` |
28
+ | `ui-sdk lint` | eslint | `. --cache` |
29
+ | `ui-sdk stylelint` | stylelint | `src/**/*.{scss,css} --allow-empty-input` |
30
+ | `ui-sdk msgmerge [po] [pot]` | gettext `msgmerge` for each po file | `src/i18n/*.po dist/ox.pot` |
31
+ | `ui-sdk doctor [--fix]` | checks the project setup, `--fix` writes the changes | |
32
+ | `ui-sdk audit [--fix]` | `pnpm audit`, `--fix` applies the SDK security overrides and reinstalls first | |
33
+
34
+ Arguments after the command replace the defaults and go straight to the tool, for example `ui-sdk lint src spec --fix`. `msgmerge` needs gettext installed.
35
+
36
+ The tools run from the SDK's own dependencies. pnpm links only the binaries of direct dependencies, so `pnpm exec vite` does not work in a project; use `ui-sdk`.
37
+
38
+ ## Configs
39
+
40
+ Without a config file in the project, `ui-sdk` uses the SDK defaults. To change them, add the file and start from the SDK export:
41
+
42
+ ```js
43
+ // vite.config.js
44
+ import { defineConfig } from '@open-xchange/app-suite-ui-sdk/vite'
45
+
46
+ export default defineConfig({
47
+ id: 'gpg-ui',
48
+ name: 'GPG UI',
49
+ tailwind: true,
50
+ gettext: { poFiles: 'src/i18n/*.po', outFile: 'ox.pot', defaultDictionary: 'io.ox/gpg/i18n', defaultLanguage: 'en_US' },
51
+ vite: { build: { sourcemap: true } }
52
+ })
53
+ ```
54
+
55
+ `defineConfig` builds the usual plugin setup: `src` as root and `dist` as output, the dev proxy to `SERVER` from `.env`, manifests, `$` externals, css and po2json. Vitest runs with jsdom on `spec/**/*_test.{js,mjs}` and `src/**/*.test.{js,mjs}`. `options.vite` and `options.test` are merged over the defaults.
56
+
57
+ ```js
58
+ // eslint.config.js
59
+ import config from '@open-xchange/app-suite-ui-sdk/eslint'
60
+
61
+ export default [...config]
62
+ ```
63
+
64
+ ```js
65
+ // stylelint.config.js
66
+ import config from '@open-xchange/app-suite-ui-sdk/stylelint'
67
+
68
+ export default { ...config, rules: { ...config.rules } }
69
+ ```
70
+
71
+ ```yaml
72
+ # lefthook.yml
73
+ extends:
74
+ - node_modules/@open-xchange/app-suite-ui-sdk/configs/lefthook.yml
75
+ ```
76
+
77
+ ## What doctor checks
78
+
79
+ - `packageManager` and `engines.node` match the SDK.
80
+ - `package.json` lists no tooling that the SDK or `@open-xchange/lint` provides, and none of the tools the SDK replaced (release-it, lint-staged, simple-git-hooks, husky, eslint-config-standard).
81
+ - Scripts call `ui-sdk` instead of the tools. `--fix` rewrites simple cases like `vite build` or `eslint src` and keeps their arguments. Chained scripts get a warning and need a manual change.
82
+ - `pnpm-workspace.yaml` has `publicHoistPattern` (so editors and test files find eslint, stylelint, typescript, vite and vitest), `allowBuilds`, and the SDK security overrides.
83
+ - `lefthook.yml` extends the SDK config.
84
+ - rlsy is installed globally, and `renovate.json` exists. Both are warnings only.
85
+
86
+ CI runs `ui-sdk doctor`; it exits non-zero while errors remain.
87
+
88
+ ## Security overrides
89
+
90
+ pnpm reads `overrides` only from the project root, so the SDK cannot pin a patched transitive version for its consumers by itself. Instead, [security-overrides.json](security-overrides.json) lists the overrides, and `doctor --fix` writes them into the project's `pnpm-workspace.yaml` with a `# managed by ui-sdk` comment. Managed overrides that the SDK no longer lists are removed again. An override the project set itself always wins, and doctor only warns about it.
91
+
92
+ To fix a CVE everywhere, add the override here and release. The renovate SDK bump in each project runs `ui-sdk doctor --fix` as a post-upgrade task and automerges. For an urgent fix in one project, run `pnpm exec ui-sdk audit --fix`.
93
+
94
+ ## Releasing
95
+
96
+ Releasing stays out of the SDK. Projects release with a globally installed [rlsy](https://gitlab.com/openxchange/appsuite/web-foundation/rlsy) (`pnpm add -g rlsy`) and get no `release` script. The SDK itself publishes to npm from a tag pipeline: a tag like `0.2.0` that matches `package.json` publishes that version.
97
+
98
+ ## Decisions
99
+
100
+ Agreed on 2026-11-03.
101
+
102
+ - **One package with everything.** Projects without a vite build install the build tooling too. One version to bump matters more than install size.
103
+ - **Tooling only.** Runtime libraries stay in the projects or come from core ui as `$` externals.
104
+ - **Exact pins, no SDK lockfile.** pnpm ignores a dependency's lockfile, and bundling the dependencies fails on platform-specific binaries (rolldown, sass, lefthook). Each project's own lockfile keeps its build reproducible.
105
+ - **One CLI.** `ui-sdk` wraps every tool, so all projects run the same scripts. It has no release command.
106
+ - **Config factories with overrides.** Projects keep only what differs from the defaults.
107
+ - **`doctor --fix` writes visible settings** into `package.json` and `pnpm-workspace.yaml` instead of injecting them at install time.
108
+ - **Same tools everywhere.** lefthook, the SDK's pnpm and Node version, enforced by `ui-sdk doctor` in CI.
109
+ - **`@open-xchange/lint` stays its own package.** The SDK pins it and re-exports it.
110
+ - **Semver, released on merge.** A tool bump that breaks consumers is a major. Consumers automerge minor and patch updates and review majors.
111
+ - **Core ui gates releases.** Every SDK MR runs a downstream core ui pipeline with the candidate package.
112
+ - **Renovate everywhere** through an SDK preset in [web-foundation/renovate](https://gitlab.com/openxchange/appsuite/web-foundation/renovate). Every project has a one-line `renovate.json`.
113
+ - **e2e is out of scope** and gets its own SDK.
114
+ - **Rollout:** core ui first, then the other vite projects, then the customer plugins.
115
+
116
+ ## License
117
+
118
+ MIT
package/bin/ui-sdk.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ import { commands } from '../lib/commands.js'
3
+ import { doctor } from '../lib/doctor.js'
4
+ import { runCommand, sdkPackage } from '../lib/tools.js'
5
+
6
+ const USAGE = `ui-sdk ${sdkPackage.version}
7
+
8
+ Usage: ui-sdk <command> [args]
9
+
10
+ dev start the vite dev server
11
+ build build with vite
12
+ test run vitest (default: --run)
13
+ lint run eslint (default: . --cache)
14
+ stylelint run stylelint (default: src/**/*.{scss,css})
15
+ msgmerge [po] [pot] merge po files with the pot (default: src/i18n/*.po dist/ox.pot)
16
+ doctor [--fix] check the project setup against the SDK, --fix writes the changes
17
+ audit [--fix] run pnpm audit, --fix applies the SDK security overrides first
18
+
19
+ Arguments after the command are passed to the underlying tool.`
20
+
21
+ const [name, ...args] = process.argv.slice(2)
22
+ const cwd = process.cwd()
23
+
24
+ function audit (fix) {
25
+ if (fix) {
26
+ doctor(cwd, { fix: true })
27
+ const status = runCommand('pnpm', ['install', '--no-frozen-lockfile'], { cwd })
28
+ if (status !== 0) return status
29
+ }
30
+ return runCommand('pnpm', ['audit'], { cwd })
31
+ }
32
+
33
+ let status
34
+ if (!name || name === '--help' || name === '-h') {
35
+ console.log(USAGE)
36
+ status = name ? 0 : 1
37
+ } else if (name === '--version' || name === '-v') {
38
+ console.log(sdkPackage.version)
39
+ status = 0
40
+ } else if (name === 'doctor') {
41
+ status = doctor(cwd, { fix: args.includes('--fix') })
42
+ } else if (name === 'audit') {
43
+ status = audit(args.includes('--fix'))
44
+ } else if (commands[name]) {
45
+ status = commands[name](cwd, args)
46
+ } else {
47
+ console.error(`Unknown command: ${name}\n\n${USAGE}`)
48
+ status = 1
49
+ }
50
+ process.exit(status)
@@ -0,0 +1,5 @@
1
+ import config from '@open-xchange/lint'
2
+
3
+ export { plugins } from '@open-xchange/lint'
4
+
5
+ export default config
@@ -0,0 +1,10 @@
1
+ pre-commit:
2
+ jobs:
3
+ - name: eslint
4
+ glob: '*.{js,cjs,mjs,vue}'
5
+ run: pnpm exec ui-sdk lint --cache --fix --no-warn-ignored {staged_files}
6
+ stage_fixed: true
7
+ - name: stylelint
8
+ glob: '*.{css,scss}'
9
+ run: pnpm exec ui-sdk stylelint --fix --allow-empty-input {staged_files}
10
+ stage_fixed: true
@@ -0,0 +1,61 @@
1
+ /** @type {import('stylelint').Config} */
2
+ export default {
3
+ extends: [
4
+ 'stylelint-config-standard-scss',
5
+ ],
6
+ rules: {
7
+ // core rules
8
+ 'alpha-value-notation': null,
9
+ 'at-rule-empty-line-before': null,
10
+ 'block-no-redundant-nested-style-rules': null,
11
+ 'color-function-alias-notation': null,
12
+ 'color-function-notation': null,
13
+ 'color-hex-length': null,
14
+ 'comment-empty-line-before': null,
15
+ 'comment-whitespace-inside': null,
16
+ 'custom-property-empty-line-before': null,
17
+ 'declaration-block-no-duplicate-properties': null,
18
+ 'declaration-block-no-redundant-longhand-properties': null,
19
+ 'declaration-block-no-shorthand-property-overrides': null,
20
+ 'declaration-block-single-line-max-declarations': null,
21
+ 'declaration-empty-line-before': null,
22
+ 'declaration-property-value-keyword-no-deprecated': null,
23
+ 'font-family-name-quotes': null,
24
+ 'font-family-no-missing-generic-family-keyword': null,
25
+ 'function-url-quotes': null,
26
+ 'hue-degree-notation': null,
27
+ 'keyframes-name-pattern': null,
28
+ 'length-zero-no-unit': null,
29
+ 'lightness-notation': null,
30
+ 'media-feature-range-notation': null,
31
+ 'no-empty-source': null,
32
+ 'no-invalid-position-declaration': null,
33
+ 'number-max-precision': null,
34
+ 'property-no-deprecated': null,
35
+ 'property-no-vendor-prefix': null,
36
+ 'rule-empty-line-before': null,
37
+ 'selector-attribute-quotes': null,
38
+ 'selector-class-pattern': null,
39
+ 'selector-id-pattern': null,
40
+ 'selector-no-vendor-prefix': null,
41
+ 'selector-not-notation': null,
42
+ 'selector-pseudo-class-no-unknown': null,
43
+ 'selector-pseudo-element-colon-notation': null,
44
+ 'shorthand-property-no-redundant-values': null,
45
+ 'value-keyword-case': null,
46
+ 'value-no-vendor-prefix': null,
47
+ // scss plugin
48
+ 'scss/at-if-no-null': null,
49
+ 'scss/at-mixin-argumentless-call-parentheses': null,
50
+ 'scss/at-mixin-parentheses-space-before': null,
51
+ 'scss/at-mixin-pattern': null,
52
+ 'scss/at-rule-conditional-no-parentheses': null,
53
+ 'scss/comment-no-empty': null,
54
+ 'scss/dollar-variable-colon-space-after': null,
55
+ 'scss/dollar-variable-empty-line-before': null,
56
+ 'scss/dollar-variable-pattern': null,
57
+ 'scss/double-slash-comment-empty-line-before': null,
58
+ 'scss/double-slash-comment-whitespace-inside': null,
59
+ 'scss/operator-no-unspaced': null,
60
+ },
61
+ }
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from './vite.js'
2
+
3
+ export default defineConfig()
@@ -0,0 +1,161 @@
1
+ import { globSync, readFileSync } from 'node:fs'
2
+ import path from 'node:path'
3
+ import { defineConfig as defineViteConfig, mergeConfig } from 'vite'
4
+ import vitePluginVue from '@vitejs/plugin-vue'
5
+ import vitePluginTailwindcss from '@tailwindcss/vite'
6
+ import vitePluginOxManifests from '@open-xchange/vite-plugin-ox-manifests'
7
+ import vitePluginOxExternals from '@open-xchange/vite-plugin-ox-externals'
8
+ import vitePluginProxy from '@open-xchange/vite-plugin-proxy'
9
+ import vitePluginOxCss from '@open-xchange/vite-plugin-ox-css'
10
+ import gettextPlugin from '@open-xchange/vite-plugin-po2json'
11
+
12
+ function loadEnv () {
13
+ for (const file of ['.env', '.env.defaults']) {
14
+ try { process.loadEnvFile(file) } catch {}
15
+ }
16
+ const env = process.env
17
+ return {
18
+ server: env.SERVER,
19
+ frontendUris: env.FRONTEND_URIS || '',
20
+ strictFilesystem: env.ENABLE_STRICT_FILESYSTEM === 'true',
21
+ httpProxy: env.ENABLE_HTTP_PROXY === 'true',
22
+ secureFrontends: env.ENABLE_SECURE_FRONTENDS === 'true',
23
+ secureProxy: env.ENABLE_SECURE_PROXY === 'true',
24
+ port: env.PORT,
25
+ hmr: env.ENABLE_HMR === 'true',
26
+ hostKey: env.HOST_KEY || 'ssl/host.key',
27
+ hostCrt: env.HOST_CRT || 'ssl/host.crt',
28
+ proxyLogLevel: env.PROXY_LOGLEVEL || 'error'
29
+ }
30
+ }
31
+
32
+ function readProjectName () {
33
+ try {
34
+ return JSON.parse(readFileSync(path.resolve('package.json'), 'utf8')).name
35
+ } catch {
36
+ return undefined
37
+ }
38
+ }
39
+
40
+ export function proxyConfig (env) {
41
+ const url = new URL(env.server)
42
+ const http = { target: url.href, changeOrigin: true, secure: env.secureProxy }
43
+ return {
44
+ proxy: {
45
+ [`${url.pathname}/api`.replace(/\/+/g, '/')]: http,
46
+ '/ajax': http,
47
+ '/help': http,
48
+ '/socket.io/appsuite': { target: `wss://${url.host}/socket.io/appsuite`, ws: true, changeOrigin: true, secure: env.secureProxy },
49
+ '/rt2/v1/default/': { target: `wss://${url.host}`, ws: true, changeOrigin: true, secure: env.secureProxy }
50
+ },
51
+ httpProxy: env.httpProxy && { target: url.href, port: url.port || 8080 },
52
+ frontends: env.frontendUris && env.frontendUris.split(',').map(uri => ({ target: uri, secure: env.secureFrontends })),
53
+ secure: false,
54
+ logLevel: env.proxyLogLevel
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Vite and vitest config for App Suite UI plugins.
60
+ *
61
+ * @param {object} [options]
62
+ * @param {string} [options.id] manifest id, defaults to the package name
63
+ * @param {string} [options.name] manifest display name, defaults to the id
64
+ * @param {string[]} [options.entryPoints] manifest entry points
65
+ * @param {boolean} [options.vue] add @vitejs/plugin-vue
66
+ * @param {boolean} [options.tailwind] add @tailwindcss/vite
67
+ * @param {false|object} [options.gettext] options for @open-xchange/vite-plugin-po2json, false to disable; on by default when src/i18n has po files
68
+ * @param {object} [options.meta] extra manifest meta data
69
+ * @param {object} [options.test] vitest options, merged over the defaults
70
+ * @param {import('vite').UserConfig | ((env: import('vite').ConfigEnv) => import('vite').UserConfig)} [options.vite] merged over the generated config
71
+ */
72
+ export function defineConfig (options = {}) {
73
+ const {
74
+ id = readProjectName(),
75
+ name = id,
76
+ entryPoints = ['src/**/*.js'],
77
+ vue = true,
78
+ tailwind = false,
79
+ gettext = globSync('src/i18n/*.po').length > 0 && { poFiles: 'src/i18n/*.po', outFile: 'ox.pot', defaultDictionary: id, defaultLanguage: 'en_US' },
80
+ meta = {},
81
+ test = {},
82
+ vite = {}
83
+ } = options
84
+
85
+ return defineViteConfig(configEnv => {
86
+ const { mode, command } = configEnv
87
+ const env = loadEnv()
88
+ const testing = Boolean(process.env.VITEST)
89
+ const serving = command === 'serve' && !testing
90
+ const debugMode = mode === 'development' || serving
91
+ if (mode === 'development') process.env.VITE_DEBUG = 'true'
92
+ if (serving && !env.server) throw new Error('SERVER is not set; add it to .env, e.g. SERVER=https://appsuite.example.com/appsuite/')
93
+
94
+ const base = {
95
+ root: './src',
96
+ base: debugMode && env.server ? new URL(env.server).pathname : './',
97
+ publicDir: '../public',
98
+ build: {
99
+ minify: true,
100
+ target: 'es2022',
101
+ outDir: '../dist',
102
+ emptyOutDir: true,
103
+ sourcemap: false,
104
+ rolldownOptions: {
105
+ input: {},
106
+ preserveEntrySignatures: 'strict',
107
+ output: {
108
+ minifyInternalExports: false,
109
+ entryFileNames: '[name].js'
110
+ }
111
+ }
112
+ },
113
+ server: {
114
+ port: env.port,
115
+ hmr: { overlay: env.hmr },
116
+ https: serving ? { key: env.hostKey, cert: env.hostCrt } : undefined,
117
+ fs: { strict: env.strictFilesystem }
118
+ },
119
+ resolve: {
120
+ alias: [{ find: '@/', replacement: '/' }]
121
+ },
122
+ plugins: [
123
+ vue && vitePluginVue(),
124
+ tailwind && vitePluginTailwindcss(),
125
+ serving && vitePluginProxy(proxyConfig(env)),
126
+ !testing && vitePluginOxManifests({
127
+ watch: serving,
128
+ entryPoints,
129
+ manifestsAsEntryPoints: true,
130
+ meta: {
131
+ id,
132
+ name,
133
+ buildDate: new Date().toISOString(),
134
+ commitSha: process.env.CI_COMMIT_SHA,
135
+ version: String(process.env.APP_VERSION || '').split('-')[0],
136
+ revision: String(process.env.APP_VERSION || '').split('-')[1],
137
+ ...meta
138
+ }
139
+ }),
140
+ vitePluginOxExternals({ prefix: '$' }),
141
+ !testing && vitePluginOxCss(),
142
+ gettext && gettextPlugin(gettext)
143
+ ].filter(Boolean),
144
+ test: mergeConfig({
145
+ root: '.',
146
+ environment: 'jsdom',
147
+ include: ['spec/**/*_test.{js,mjs}', 'src/**/*.test.{js,mjs}'],
148
+ passWithNoTests: true,
149
+ reporters: process.env.CI ? ['dot', 'junit'] : ['default'],
150
+ outputFile: { junit: 'output/junit.xml' },
151
+ coverage: {
152
+ provider: 'v8',
153
+ reporter: ['cobertura', 'text-summary'],
154
+ reportsDirectory: 'output/coverage'
155
+ }
156
+ }, test)
157
+ }
158
+
159
+ return mergeConfig(base, typeof vite === 'function' ? vite(configEnv) : vite)
160
+ })
161
+ }
@@ -0,0 +1,48 @@
1
+ import { globSync } from 'node:fs'
2
+ import path from 'node:path'
3
+ import { findConfig, resolveBin, runCommand, runNode, sdkRoot } from './tools.js'
4
+
5
+ const VITE_CONFIGS = ['vite.config.js', 'vite.config.mjs', 'vite.config.ts']
6
+ const VITEST_CONFIGS = ['vitest.config.js', 'vitest.config.mjs', 'vitest.config.ts', ...VITE_CONFIGS]
7
+ const ESLINT_CONFIGS = ['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs', 'eslint.config.ts']
8
+ const STYLELINT_CONFIGS = ['stylelint.config.js', 'stylelint.config.mjs', '.stylelintrc.json', '.stylelintrc']
9
+
10
+ function withConfig (cwd, names, fallback, args) {
11
+ if (args.includes('--config') || args.includes('-c') || findConfig(cwd, names)) return args
12
+ return ['--config', path.join(sdkRoot, 'configs', fallback), ...args]
13
+ }
14
+
15
+ function vite (cwd, args) {
16
+ return runNode(resolveBin('vite'), withConfig(cwd, VITE_CONFIGS, 'vite.default.js', args), { cwd })
17
+ }
18
+
19
+ export const commands = {
20
+ dev: (cwd, args) => vite(cwd, args),
21
+
22
+ build: (cwd, args) => vite(cwd, ['build', ...args]),
23
+
24
+ test: (cwd, args) => {
25
+ const vitestArgs = args.length ? args : ['--run']
26
+ return runNode(resolveBin('vitest'), withConfig(cwd, VITEST_CONFIGS, 'vite.default.js', vitestArgs), { cwd })
27
+ },
28
+
29
+ lint: (cwd, args) => {
30
+ const eslintArgs = args.length ? args : ['.', '--cache']
31
+ return runNode(resolveBin('eslint', { via: '@open-xchange/lint' }), withConfig(cwd, ESLINT_CONFIGS, 'eslint.js', eslintArgs), { cwd })
32
+ },
33
+
34
+ stylelint: (cwd, args) => {
35
+ const stylelintArgs = args.length ? args : ['src/**/*.{scss,css}', '--allow-empty-input']
36
+ return runNode(resolveBin('stylelint'), withConfig(cwd, STYLELINT_CONFIGS, 'stylelint.js', stylelintArgs), { cwd })
37
+ },
38
+
39
+ msgmerge: (cwd, args) => {
40
+ const [poPattern = 'src/i18n/*.po', potFile = 'dist/ox.pot'] = args
41
+ const poFiles = globSync(poPattern, { cwd })
42
+ for (const poFile of poFiles) {
43
+ const status = runCommand('msgmerge', ['-Us', '--previous', '--backup=none', poFile, potFile], { cwd })
44
+ if (status !== 0) return status
45
+ }
46
+ return 0
47
+ }
48
+ }
package/lib/doctor.js ADDED
@@ -0,0 +1,230 @@
1
+ import { spawnSync } from 'node:child_process'
2
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs'
3
+ import { createRequire } from 'node:module'
4
+ import path from 'node:path'
5
+ import { isMap, isScalar, parseDocument, Scalar } from 'yaml'
6
+ import { sdkPackage, sdkRoot } from './tools.js'
7
+
8
+ const require = createRequire(import.meta.url)
9
+
10
+ export const MANAGED_MARK = 'managed by ui-sdk'
11
+
12
+ export const PUBLIC_HOIST_PATTERN = ['*eslint*', '*stylelint*', 'typescript', 'vite', 'vitest']
13
+
14
+ export const ALLOW_BUILDS = ['@parcel/watcher', 'lefthook']
15
+
16
+ const REPLACED_PACKAGES = [
17
+ 'release-it',
18
+ '@j-ulrich/release-it-regex-bumper',
19
+ '@release-it/keep-a-changelog',
20
+ 'lint-staged',
21
+ 'simple-git-hooks',
22
+ 'husky',
23
+ 'eslint-config-standard',
24
+ 'eslint-plugin-import',
25
+ 'eslint-plugin-n',
26
+ 'eslint-plugin-promise'
27
+ ]
28
+
29
+ const TOOL_SCRIPTS = {
30
+ dev: /^(?:npx )?vite(?:\s+(?!build\b)(.*))?$/,
31
+ build: /^(?:npx )?vite build(?:\s+(.*))?$/,
32
+ test: /^(?:npx )?vitest(?:\s+(.*))?$|^true$/,
33
+ lint: /^(?:npx )?eslint(?:\s+(.*))?$/,
34
+ stylelint: /^(?:npx )?stylelint(?:\s+(.*))?$/
35
+ }
36
+
37
+ function lintDependencies () {
38
+ const manifest = JSON.parse(readFileSync(require.resolve('@open-xchange/lint/package.json'), 'utf8'))
39
+ return Object.keys(manifest.dependencies || {})
40
+ }
41
+
42
+ export function providedPackages () {
43
+ return new Set([
44
+ ...Object.keys(sdkPackage.dependencies),
45
+ ...lintDependencies(),
46
+ ...REPLACED_PACKAGES
47
+ ])
48
+ }
49
+
50
+ export function securityOverrides () {
51
+ return JSON.parse(readFileSync(path.join(sdkRoot, 'security-overrides.json'), 'utf8'))
52
+ }
53
+
54
+ export function checkPackageJson (pkg, { provided = providedPackages() } = {}) {
55
+ const findings = []
56
+ const fixed = structuredClone(pkg)
57
+
58
+ if (pkg.packageManager !== sdkPackage.packageManager) {
59
+ findings.push({ level: 'error', fixable: true, message: `packageManager is ${pkg.packageManager ?? 'unset'}, expected ${sdkPackage.packageManager}` })
60
+ fixed.packageManager = sdkPackage.packageManager
61
+ }
62
+
63
+ if (pkg.engines?.node !== sdkPackage.engines.node) {
64
+ findings.push({ level: 'error', fixable: true, message: `engines.node is ${pkg.engines?.node ?? 'unset'}, expected ${sdkPackage.engines.node}` })
65
+ fixed.engines = { ...pkg.engines, node: sdkPackage.engines.node }
66
+ }
67
+
68
+ for (const field of ['dependencies', 'devDependencies']) {
69
+ for (const name of Object.keys(pkg[field] || {})) {
70
+ if (!provided.has(name)) continue
71
+ findings.push({ level: 'error', fixable: true, message: `${field} lists ${name}, which the SDK provides` })
72
+ delete fixed[field][name]
73
+ }
74
+ }
75
+
76
+ if (!pkg.devDependencies?.[sdkPackage.name] && !pkg.dependencies?.[sdkPackage.name]) {
77
+ findings.push({ level: 'error', fixable: true, message: `devDependencies does not list ${sdkPackage.name}` })
78
+ fixed.devDependencies = { ...fixed.devDependencies, [sdkPackage.name]: sdkPackage.version }
79
+ }
80
+
81
+ for (const [name, command] of Object.entries(pkg.scripts || {})) {
82
+ const pattern = TOOL_SCRIPTS[name]
83
+ if (pattern) {
84
+ const match = command.match(pattern)
85
+ if (match) {
86
+ const args = match[1]
87
+ fixed.scripts[name] = args ? `ui-sdk ${name} ${args}` : `ui-sdk ${name}`
88
+ findings.push({ level: 'error', fixable: true, message: command === 'true' ? `script "${name}" is a placeholder` : `script "${name}" runs the tool directly: ${command}` })
89
+ continue
90
+ }
91
+ }
92
+ if (/\b(?:release-it|simple-git-hooks|husky|lint-staged)\b/.test(command)) {
93
+ delete fixed.scripts[name]
94
+ findings.push({ level: 'error', fixable: true, message: `script "${name}" uses a tool the SDK replaced: ${command}` })
95
+ continue
96
+ }
97
+ if (!command.startsWith('ui-sdk ') && /(?:^|[\s&;|])(?:npx )?(?:vite|vitest|eslint|stylelint)\b/.test(command)) {
98
+ findings.push({ level: 'warn', fixable: false, message: `script "${name}" calls a tool directly, switch it to ui-sdk by hand: ${command}` })
99
+ }
100
+ }
101
+
102
+ if (fixed.devDependencies && !Object.keys(fixed.devDependencies).length) delete fixed.devDependencies
103
+ if (fixed.dependencies && !Object.keys(fixed.dependencies).length) delete fixed.dependencies
104
+
105
+ return { findings, fixed }
106
+ }
107
+
108
+ function ensureList (doc, key, required, findings) {
109
+ const current = doc.get(key)?.toJSON?.() ?? []
110
+ const missing = required.filter(entry => !current.includes(entry))
111
+ if (!missing.length) return
112
+ findings.push({ level: 'error', fixable: true, message: `${key} misses ${missing.join(', ')}` })
113
+ doc.set(key, [...current, ...missing])
114
+ }
115
+
116
+ function ensureAllowBuilds (doc, findings) {
117
+ const current = doc.get('allowBuilds')?.toJSON?.() ?? {}
118
+ const missing = ALLOW_BUILDS.filter(name => current[name] !== true)
119
+ if (!missing.length) return
120
+ findings.push({ level: 'error', fixable: true, message: `allowBuilds misses ${missing.join(', ')}` })
121
+ for (const name of missing) doc.setIn(['allowBuilds', name], true)
122
+ }
123
+
124
+ function isManaged (node) {
125
+ return isScalar(node) && node.comment?.trim() === MANAGED_MARK
126
+ }
127
+
128
+ function syncOverrides (doc, wanted, findings) {
129
+ let overrides = doc.get('overrides', true)
130
+ if (!isMap(overrides)) {
131
+ if (!Object.keys(wanted).length) return
132
+ doc.set('overrides', doc.createNode({}))
133
+ overrides = doc.get('overrides', true)
134
+ }
135
+
136
+ for (const pair of [...overrides.items]) {
137
+ const key = isScalar(pair.key) ? pair.key.value : pair.key
138
+ if (!isManaged(pair.value) || key in wanted) continue
139
+ findings.push({ level: 'error', fixable: true, message: `override ${key} is no longer needed` })
140
+ overrides.delete(key)
141
+ }
142
+
143
+ for (const [key, version] of Object.entries(wanted)) {
144
+ const node = overrides.get(key, true)
145
+ if (isScalar(node) && node.value === version) {
146
+ if (!isManaged(node)) findings.push({ level: 'warn', fixable: false, message: `override ${key} matches the SDK but is not marked as managed` })
147
+ continue
148
+ }
149
+ if (node && !isManaged(node)) {
150
+ findings.push({ level: 'warn', fixable: false, message: `override ${key} is ${node.value ?? node}, the SDK wants ${version}; the project override wins` })
151
+ continue
152
+ }
153
+ findings.push({ level: 'error', fixable: true, message: `security override ${key}: ${version} is missing` })
154
+ const scalar = new Scalar(version)
155
+ scalar.comment = ` ${MANAGED_MARK}`
156
+ overrides.set(key, scalar)
157
+ }
158
+
159
+ if (!overrides.items.length) doc.delete('overrides')
160
+ }
161
+
162
+ export function checkWorkspace (source, { overrides = securityOverrides() } = {}) {
163
+ const findings = []
164
+ const doc = parseDocument(source || '')
165
+ if (doc.contents === null) doc.contents = doc.createNode({})
166
+ ensureList(doc, 'publicHoistPattern', PUBLIC_HOIST_PATTERN, findings)
167
+ ensureAllowBuilds(doc, findings)
168
+ syncOverrides(doc, overrides, findings)
169
+ return { findings, fixed: doc.toString({ singleQuote: true }) }
170
+ }
171
+
172
+ export function checkLefthook (source) {
173
+ const extendsPath = `node_modules/${sdkPackage.name}/configs/lefthook.yml`
174
+ if (source === undefined) {
175
+ return {
176
+ findings: [{ level: 'error', fixable: true, message: 'lefthook.yml is missing' }],
177
+ fixed: `extends:\n - ${extendsPath}\n`
178
+ }
179
+ }
180
+ const doc = parseDocument(source)
181
+ const current = doc.get('extends')?.toJSON?.() ?? []
182
+ if (current.includes(extendsPath)) return { findings: [], fixed: source }
183
+ return { findings: [{ level: 'warn', fixable: false, message: `lefthook.yml does not extend ${extendsPath}` }], fixed: source }
184
+ }
185
+
186
+ function readIfExists (file) {
187
+ return existsSync(file) ? readFileSync(file, 'utf8') : undefined
188
+ }
189
+
190
+ function hasCommand (name) {
191
+ return spawnSync(process.platform === 'win32' ? 'where' : 'which', [name], { stdio: 'ignore' }).status === 0
192
+ }
193
+
194
+ export function doctor (cwd, { fix = false, log = console.log } = {}) {
195
+ const files = {
196
+ 'package.json': path.join(cwd, 'package.json'),
197
+ 'pnpm-workspace.yaml': path.join(cwd, 'pnpm-workspace.yaml'),
198
+ 'lefthook.yml': path.join(cwd, 'lefthook.yml')
199
+ }
200
+
201
+ const pkgSource = readFileSync(files['package.json'], 'utf8')
202
+ const results = {
203
+ 'package.json': (() => {
204
+ const { findings, fixed } = checkPackageJson(JSON.parse(pkgSource))
205
+ return { findings, fixed: JSON.stringify(fixed, null, 2) + '\n' }
206
+ })(),
207
+ 'pnpm-workspace.yaml': checkWorkspace(readIfExists(files['pnpm-workspace.yaml'])),
208
+ 'lefthook.yml': checkLefthook(readIfExists(files['lefthook.yml']))
209
+ }
210
+
211
+ const general = []
212
+ if (!hasCommand('rlsy')) general.push({ level: 'warn', fixable: false, message: 'rlsy is not installed globally (pnpm add -g rlsy); releases need it' })
213
+ if (!existsSync(path.join(cwd, 'renovate.json'))) general.push({ level: 'warn', fixable: false, message: 'renovate.json is missing' })
214
+
215
+ let remainingErrors = 0
216
+ for (const [name, { findings, fixed }] of Object.entries(results)) {
217
+ for (const finding of findings) {
218
+ const applied = fix && finding.fixable
219
+ if (finding.level === 'error' && !applied) remainingErrors++
220
+ log(`${applied ? 'fixed' : finding.level} ${name}: ${finding.message}`)
221
+ }
222
+ if (fix && findings.some(finding => finding.fixable)) writeFileSync(files[name], fixed)
223
+ }
224
+ for (const finding of general) log(`${finding.level} ${finding.message}`)
225
+
226
+ if (fix && results['package.json'].findings.some(finding => finding.fixable)) {
227
+ log('Run pnpm install to apply the changes.')
228
+ }
229
+ return remainingErrors ? 1 : 0
230
+ }
package/lib/tools.js ADDED
@@ -0,0 +1,35 @@
1
+ import { spawnSync } from 'node:child_process'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import { createRequire } from 'node:module'
4
+ import path from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+
7
+ const require = createRequire(import.meta.url)
8
+
9
+ export const sdkRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
10
+ export const sdkPackage = JSON.parse(readFileSync(path.join(sdkRoot, 'package.json'), 'utf8'))
11
+
12
+ export function resolveBin (pkg, { bin: binName = pkg, via } = {}) {
13
+ const resolver = via ? createRequire(require.resolve(`${via}/package.json`)) : require
14
+ const manifestPath = resolver.resolve(`${pkg}/package.json`)
15
+ const { bin } = JSON.parse(readFileSync(manifestPath, 'utf8'))
16
+ const relative = typeof bin === 'string' ? bin : bin[binName]
17
+ if (!relative) throw new Error(`${pkg} has no "${binName}" binary`)
18
+ return path.join(path.dirname(manifestPath), relative)
19
+ }
20
+
21
+ export function runNode (script, args, options = {}) {
22
+ const result = spawnSync(process.execPath, [script, ...args], { stdio: 'inherit', ...options })
23
+ if (result.error) throw result.error
24
+ return result.status ?? 1
25
+ }
26
+
27
+ export function runCommand (command, args, options = {}) {
28
+ const result = spawnSync(command, args, { stdio: 'inherit', ...options })
29
+ if (result.error) throw result.error
30
+ return result.status ?? 1
31
+ }
32
+
33
+ export function findConfig (cwd, names) {
34
+ return names.map(name => path.join(cwd, name)).find(file => existsSync(file))
35
+ }
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@open-xchange/app-suite-ui-sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Shared build, lint and test tooling for OX App Suite UI projects",
5
+ "type": "module",
6
+ "bin": {
7
+ "ui-sdk": "./bin/ui-sdk.js"
8
+ },
9
+ "exports": {
10
+ "./vite": "./configs/vite.js",
11
+ "./eslint": "./configs/eslint.js",
12
+ "./stylelint": "./configs/stylelint.js",
13
+ "./lefthook.yml": "./configs/lefthook.yml",
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "configs",
19
+ "lib",
20
+ "security-overrides.json"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://gitlab.com/openxchange/appsuite/web-foundation/app-suite-ui-sdk"
25
+ },
26
+ "author": "App Suite Web Foundation <app-suite-web-foundation@open-xchange.com>",
27
+ "contributors": [
28
+ "David Bauer <david.bauer@open-xchange.com>"
29
+ ],
30
+ "license": "MIT",
31
+ "engines": {
32
+ "node": ">=26.0.0"
33
+ },
34
+ "dependencies": {
35
+ "@open-xchange/lint": "0.4.0",
36
+ "@open-xchange/vite-plugin-ox-bundle": "1.0.1",
37
+ "@open-xchange/vite-plugin-ox-css": "1.0.2",
38
+ "@open-xchange/vite-plugin-ox-externals": "1.0.1",
39
+ "@open-xchange/vite-plugin-ox-manifests": "1.0.6",
40
+ "@open-xchange/vite-plugin-po2json": "1.1.6",
41
+ "@open-xchange/vite-plugin-proxy": "1.0.5",
42
+ "@tailwindcss/vite": "4.3.3",
43
+ "@vitejs/plugin-vue": "6.0.10",
44
+ "@vitest/coverage-v8": "5.0.5",
45
+ "jsdom": "30.1.3",
46
+ "lefthook": "2.2.2",
47
+ "postcss": "8.5.30",
48
+ "sass": "1.105.1",
49
+ "stylelint": "17.16.0",
50
+ "stylelint-config-standard": "40.0.0",
51
+ "stylelint-config-standard-scss": "17.0.0",
52
+ "tailwindcss": "4.3.3",
53
+ "typescript": "7.0.2",
54
+ "vite": "8.3.4",
55
+ "vitest": "5.0.5",
56
+ "yaml": "2.9.1"
57
+ },
58
+ "scripts": {
59
+ "lint": "node bin/ui-sdk.js lint",
60
+ "test": "vitest --run"
61
+ }
6
62
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "glob@>=9.0.0 <14.0.2": "^14.0.2",
3
+ "minimatch@<11.0.1": "^11.0.1"
4
+ }