@nimiplatform/app-tools 0.16.0-rc.12 → 0.16.0-rc.13
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 +15 -3
- package/bin/nimi-app.mjs +11 -4
- package/lib/app-doctor-update.mjs +19 -6
- package/lib/app-pack.mjs +209 -12
- package/lib/app-project-lifecycle.mjs +41 -5
- package/lib/app-scaffold-capabilities.mjs +28 -0
- package/lib/app-scaffold-profiles.mjs +50 -0
- package/lib/app-scaffold.mjs +289 -15
- package/lib/desktop-window.mjs +106 -0
- package/lib/index.mjs +1 -0
- package/package.json +3 -3
- package/scripts/dev-shell.mjs +13 -1
- package/templates/default-starter/README.md +14 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertDesktopHostSupport } from './app-host-support.mjs';
|
|
2
|
+
import { validateManifestDesktop } from './desktop-window.mjs';
|
|
2
3
|
import { hostedWebIdentity, isAppId } from './app-identifiers.mjs';
|
|
3
4
|
import { readWebDevelopment } from './web-development.mjs';
|
|
4
5
|
import { readAppInfo } from './app-info.mjs';
|
|
@@ -53,9 +54,10 @@ const SYNCHRONIZED_NIMI_PACKAGES = new Set([
|
|
|
53
54
|
...KIT_OWNED_NATIVE_CARRIERS,
|
|
54
55
|
]);
|
|
55
56
|
const BUILD_PROFILE_PATH = '.nimi/config/build-profile.yaml';
|
|
57
|
+
const MANAGED_WEB_BUILD_PROFILE_REF = 'managed-web-pnpm-vite';
|
|
56
58
|
const ELECTRON_BUILD_PROFILE_REF = 'electron-packager-pnpm-vite';
|
|
57
59
|
const APP_OWNED_ELECTRON_BUILD_PROFILE_REF = 'electron-pnpm';
|
|
58
|
-
const SUPPORTED_BUILD_PROFILE_REFS = new Set([ELECTRON_BUILD_PROFILE_REF, APP_OWNED_ELECTRON_BUILD_PROFILE_REF, 'web-pnpm']);
|
|
60
|
+
const SUPPORTED_BUILD_PROFILE_REFS = new Set([MANAGED_WEB_BUILD_PROFILE_REF, ELECTRON_BUILD_PROFILE_REF, APP_OWNED_ELECTRON_BUILD_PROFILE_REF, 'web-pnpm']);
|
|
59
61
|
const MANAGED_WORKFLOW_PATH = '.github/workflows/nimi-app-release.yml';
|
|
60
62
|
const HOSTED_WEB_WORKFLOW_PATH = '.github/workflows/nimi-web-release.yml';
|
|
61
63
|
function hostedWorkflowSource() {
|
|
@@ -73,10 +75,11 @@ function planHostedWorkflow(targetDir) {
|
|
|
73
75
|
}
|
|
74
76
|
const APP_IDENTITY_PATH = '.nimi/config/app-identity.yaml';
|
|
75
77
|
const SUBMISSION_PATH = '.nimi/admission/submission.yaml';
|
|
76
|
-
const SEMVER_PATTERN = /^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-[0-9A-Za-z]
|
|
78
|
+
const SEMVER_PATTERN = /^(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)\.(?:0|[1-9][0-9]*)(?:-(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u;
|
|
77
79
|
const CURRENT_APP_TARGETS = Object.freeze({
|
|
78
80
|
'windows-x86_64': Object.freeze({ os: 'windows', arch: 'x86_64' }),
|
|
79
81
|
'macos-aarch64': Object.freeze({ os: 'macos', arch: 'arm64' }),
|
|
82
|
+
'desktop-universal': Object.freeze({ os: 'any', arch: 'any' }),
|
|
80
83
|
});
|
|
81
84
|
|
|
82
85
|
function resolveTargetDir(cwd, options = {}) {
|
|
@@ -169,7 +172,8 @@ function readSubmittedManifest(targetDir, sources) {
|
|
|
169
172
|
throw new Error(`nimi.app.yaml ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
|
-
|
|
175
|
+
const desktop = validateManifestDesktop(document.desktop, 'nimi.app.yaml desktop', source);
|
|
176
|
+
return Object.freeze({ appId, displayName, profile, platform, version, publicSlug: hosted?.slug, rendererOrigin: parsedOrigin.origin, capabilityContractRefs: document.capability_contract_refs, requiredStandardizedFeatureRefs: document.required_standardized_feature_refs, storagePolicy: document.storage_policy, safetyProfile, desktop });
|
|
173
177
|
}
|
|
174
178
|
|
|
175
179
|
function assertNoRetiredScaffoldState(targetDir) {
|
|
@@ -352,6 +356,13 @@ function normalizePackageManifest(packageJson, descriptor, versions, buildProfil
|
|
|
352
356
|
normalized.scripts.dev = 'nimi-app dev --platform web';
|
|
353
357
|
normalized.scripts.sync ||= 'nimi-app sync';
|
|
354
358
|
if (normalized.scripts.pack === 'nimi-app pack') delete normalized.scripts.pack;
|
|
359
|
+
} else if (buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF) {
|
|
360
|
+
normalized.scripts.dev = 'nimi-app dev --shell electron';
|
|
361
|
+
normalized.scripts['dev:shell'] = 'nimi-app dev';
|
|
362
|
+
normalized.scripts['dev:renderer'] = `vite --host 127.0.0.1 --port ${new URL(descriptor.rendererOrigin).port} --strictPort`;
|
|
363
|
+
normalized.scripts.sync ||= 'nimi-app sync';
|
|
364
|
+
normalized.scripts.pack = 'nimi-app pack';
|
|
365
|
+
delete normalized.scripts.publish;
|
|
355
366
|
} else {
|
|
356
367
|
if (typeof normalized.scripts['build:electron'] !== 'string' || !normalized.scripts['build:electron'].trim()) {
|
|
357
368
|
throw new Error('package.json build:electron must build the Desktop-supervised Electron host');
|
|
@@ -961,14 +972,27 @@ function readBuildProfile(targetDir, sources) {
|
|
|
961
972
|
if (Object.keys(targets).length === 0) {
|
|
962
973
|
throw new Error(`${BUILD_PROFILE_PATH} must declare at least one target`);
|
|
963
974
|
}
|
|
975
|
+
if (buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF) {
|
|
976
|
+
const keys = Object.keys(targets);
|
|
977
|
+
if (keys.length !== 1 || keys[0] !== 'desktop-universal') {
|
|
978
|
+
throw new Error(`${BUILD_PROFILE_PATH} managed-web-pnpm-vite must declare only the desktop-universal target`);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
964
981
|
for (const [targetId, target] of Object.entries(targets)) {
|
|
965
|
-
const expected = buildProfileRef === 'web-pnpm'
|
|
982
|
+
const expected = buildProfileRef === 'web-pnpm'
|
|
983
|
+
? (targetId === 'web' ? {} : null)
|
|
984
|
+
: buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF
|
|
985
|
+
? (targetId === 'desktop-universal' ? CURRENT_APP_TARGETS['desktop-universal'] : null)
|
|
986
|
+
: (targetId === 'desktop-universal' ? null : CURRENT_APP_TARGETS[targetId]);
|
|
966
987
|
if (!expected || !target || typeof target !== 'object' || Array.isArray(target)) {
|
|
967
988
|
throw new Error(`${BUILD_PROFILE_PATH} declares unsupported target: ${targetId}`);
|
|
968
989
|
}
|
|
969
990
|
if (buildProfileRef !== 'web-pnpm' && (target.os !== expected.os || target.arch !== expected.arch)) {
|
|
970
991
|
throw new Error(`${BUILD_PROFILE_PATH} target identity mismatch: ${targetId}`);
|
|
971
992
|
}
|
|
993
|
+
if (buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF && target.runtime_entry !== 'payload/index.html') {
|
|
994
|
+
throw new Error(`${BUILD_PROFILE_PATH} desktop-universal runtime_entry must be payload/index.html`);
|
|
995
|
+
}
|
|
972
996
|
}
|
|
973
997
|
return {
|
|
974
998
|
buildProfileRef,
|
|
@@ -985,7 +1009,13 @@ function currentTargetId() {
|
|
|
985
1009
|
}
|
|
986
1010
|
|
|
987
1011
|
function selectBuildOwner(profile, requestedTarget) {
|
|
988
|
-
const target = String(requestedTarget || '').trim() || (
|
|
1012
|
+
const target = String(requestedTarget || '').trim() || (
|
|
1013
|
+
profile.buildProfileRef === 'web-pnpm'
|
|
1014
|
+
? 'web'
|
|
1015
|
+
: profile.buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF
|
|
1016
|
+
? 'desktop-universal'
|
|
1017
|
+
: currentTargetId()
|
|
1018
|
+
);
|
|
989
1019
|
const targetProfile = profile.targets[target];
|
|
990
1020
|
if (Object.keys(profile.targets).length > 0 && (!targetProfile || typeof targetProfile !== 'object' || Array.isArray(targetProfile))) {
|
|
991
1021
|
throw new Error(`Unsupported App build target: ${target}`);
|
|
@@ -1046,6 +1076,9 @@ function assertProjectLifecycleCurrent(targetDir, versions, options = {}) {
|
|
|
1046
1076
|
const descriptor = readSubmittedManifest(targetDir, sources);
|
|
1047
1077
|
const buildProfile = readBuildProfile(targetDir, sources);
|
|
1048
1078
|
if ((descriptor.platform === 'web') !== (buildProfile.buildProfileRef === 'web-pnpm')) throw new Error('Manifest platform and build owner disagree.');
|
|
1079
|
+
if (buildProfile.buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF && descriptor.storagePolicy?.kind !== 'nimi-mediated-default') {
|
|
1080
|
+
throw new Error('managed-web Apps must declare storage_policy.kind: nimi-mediated-default (use --carrier native for app-owned-os-storage).');
|
|
1081
|
+
}
|
|
1049
1082
|
const files = readProjectLifecycleFiles(targetDir, sources);
|
|
1050
1083
|
const combination = selectDependencyCombination(files.packageJson, versions, options.managed === true);
|
|
1051
1084
|
assertPackageManifestCurrent(files.packageJson, versions, combination, descriptor.platform);
|
|
@@ -1071,6 +1104,9 @@ function buildExistingSubmittedAppSyncPlan(targetDir, versions, sources, managed
|
|
|
1071
1104
|
const descriptor = readSubmittedManifest(targetDir, sources);
|
|
1072
1105
|
const buildProfile = readBuildProfile(targetDir, sources);
|
|
1073
1106
|
if ((descriptor.platform === 'web') !== (buildProfile.buildProfileRef === 'web-pnpm')) throw new Error('Manifest platform and build owner disagree.');
|
|
1107
|
+
if (buildProfile.buildProfileRef === MANAGED_WEB_BUILD_PROFILE_REF && descriptor.storagePolicy?.kind !== 'nimi-mediated-default') {
|
|
1108
|
+
throw new Error('managed-web Apps must declare storage_policy.kind: nimi-mediated-default (use --carrier native for app-owned-os-storage).');
|
|
1109
|
+
}
|
|
1074
1110
|
const files = readProjectLifecycleFiles(targetDir, sources);
|
|
1075
1111
|
const version = files.packageJson.version;
|
|
1076
1112
|
if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {
|
|
@@ -13,6 +13,7 @@ function frozenModule(definition) {
|
|
|
13
13
|
return Object.freeze({
|
|
14
14
|
...definition,
|
|
15
15
|
carriers: Object.freeze([...(definition.carriers || ['desktop'])]),
|
|
16
|
+
desktopCarriers: Object.freeze([...(definition.desktopCarriers || ['managed-web', 'native'])]),
|
|
16
17
|
requires: Object.freeze([...(definition.requires || [])]),
|
|
17
18
|
sourceMappings: Object.freeze([...(definition.sourceMappings || [])]),
|
|
18
19
|
appAccessItems: Object.freeze([...(definition.appAccessItems || [])]),
|
|
@@ -177,6 +178,7 @@ export const APP_SCAFFOLD_MODULE_REGISTRY = Object.freeze({
|
|
|
177
178
|
}),
|
|
178
179
|
'agent-conversation': frozenModule({
|
|
179
180
|
id: 'agent-conversation',
|
|
181
|
+
desktopCarriers: ['managed-web', 'native'],
|
|
180
182
|
kind: 'feature',
|
|
181
183
|
lifecycle: 'admitted',
|
|
182
184
|
order: 60,
|
|
@@ -201,6 +203,7 @@ export const APP_SCAFFOLD_MODULE_REGISTRY = Object.freeze({
|
|
|
201
203
|
}),
|
|
202
204
|
'agent-realtime': frozenModule({
|
|
203
205
|
id: 'agent-realtime',
|
|
206
|
+
desktopCarriers: ['native'],
|
|
204
207
|
kind: 'feature',
|
|
205
208
|
lifecycle: 'admitted',
|
|
206
209
|
order: 70,
|
|
@@ -679,3 +682,28 @@ export function resolveWebAppScaffoldFeatures(selection, resolver = resolveAppSc
|
|
|
679
682
|
for (const module of resolution.modules) if (!module.carriers.includes('web')) throw new Error(`Feature ${module.id} has no admitted Web carrier.`);
|
|
680
683
|
return resolution;
|
|
681
684
|
}
|
|
685
|
+
|
|
686
|
+
export const APP_SCAFFOLD_MANAGED_WEB_FEATURE_IDS = Object.freeze(
|
|
687
|
+
registryEntries(APP_SCAFFOLD_MODULE_REGISTRY)
|
|
688
|
+
.filter(([, entry]) => entry.kind === 'feature' && entry.lifecycle === 'admitted' && entry.desktopCarriers.includes('managed-web'))
|
|
689
|
+
.map(([id]) => id),
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
|
|
693
|
+
export function resolveDesktopAppScaffoldFeatures(selection, carrier = 'managed-web', resolver = resolveAppScaffoldFeatures) {
|
|
694
|
+
if (carrier !== 'managed-web' && carrier !== 'native') {
|
|
695
|
+
throw new Error(`Unsupported desktop App carrier: ${String(carrier)}`);
|
|
696
|
+
}
|
|
697
|
+
if (carrier === 'native') {
|
|
698
|
+
return resolver(selection);
|
|
699
|
+
}
|
|
700
|
+
const isAll = selection === 'all' || (Array.isArray(selection) && selection.length === 1 && selection[0] === 'all');
|
|
701
|
+
const selected = isAll ? [...APP_SCAFFOLD_MANAGED_WEB_FEATURE_IDS] : selection;
|
|
702
|
+
const resolution = resolver(selected);
|
|
703
|
+
for (const module of resolution.modules) {
|
|
704
|
+
if (!module.desktopCarriers.includes('managed-web')) {
|
|
705
|
+
throw new Error(`Feature ${module.id} requires the native desktop carrier (OS microphone or custom host mechanics); rerun with --carrier native.`);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return resolution;
|
|
709
|
+
}
|
|
@@ -44,6 +44,31 @@ export function resolveWindowsResourceVersion(appVersion) {
|
|
|
44
44
|
|
|
45
45
|
export function buildDefaultStarterFiles(identity) {
|
|
46
46
|
if (identity.platform === 'web') return [...buildWebStarterFiles(identity, { productArea: renderDefaultProductArea(identity), navigation: renderDefaultAppNavigation() }), ...buildGeneratedModuleCompositionFiles(identity)];
|
|
47
|
+
if (identity.carrier === 'managed-web') {
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
path: 'src/main.tsx',
|
|
51
|
+
content: renderDefaultMain(identity),
|
|
52
|
+
mutationClass: 'scaffold-managed glue',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
path: 'src/shell/routes/product-area.tsx',
|
|
56
|
+
content: renderDefaultProductArea(identity),
|
|
57
|
+
mutationClass: 'app-owned product code',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
path: 'src/shell/routes/app-navigation.tsx',
|
|
61
|
+
content: renderDefaultAppNavigation(),
|
|
62
|
+
mutationClass: 'app-owned product code',
|
|
63
|
+
},
|
|
64
|
+
...buildGeneratedModuleCompositionFiles(identity),
|
|
65
|
+
{
|
|
66
|
+
path: 'vite.config.ts',
|
|
67
|
+
content: MANAGED_WEB_VITE_CONFIG,
|
|
68
|
+
mutationClass: 'scaffold-managed glue',
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
}
|
|
47
72
|
return [
|
|
48
73
|
{
|
|
49
74
|
path: 'src/main.tsx',
|
|
@@ -125,6 +150,31 @@ const DEFAULT_VITE_CONFIG = [
|
|
|
125
150
|
'',
|
|
126
151
|
].join('\n');
|
|
127
152
|
|
|
153
|
+
const MANAGED_WEB_VITE_CONFIG = [
|
|
154
|
+
"import { defineConfig } from 'vite';",
|
|
155
|
+
"import react from '@vitejs/plugin-react';",
|
|
156
|
+
"import tailwindcss from '@tailwindcss/vite';",
|
|
157
|
+
'',
|
|
158
|
+
'export default defineConfig({',
|
|
159
|
+
" base: './',",
|
|
160
|
+
" cacheDir: '.vite',",
|
|
161
|
+
" optimizeDeps: { entries: ['index.html'] },",
|
|
162
|
+
' // The bootstrap creates the root once; only components participate in Fast Refresh.',
|
|
163
|
+
" plugins: [react({ exclude: [/\\/node_modules\\//, /\\/src\\/main\\.tsx$/] }), tailwindcss()],",
|
|
164
|
+
' build: {',
|
|
165
|
+
" outDir: 'dist/renderer',",
|
|
166
|
+
' emptyOutDir: true,',
|
|
167
|
+
' },',
|
|
168
|
+
' server: {',
|
|
169
|
+
" watch: { ignored: ['**/.nimi/local/**', '**/dist/**', '**/dist-web/**', '**/dist-mobile/**', '**/android/**/build/**', '**/android/app/src/main/assets/public/**'] },",
|
|
170
|
+
' },',
|
|
171
|
+
' resolve: {',
|
|
172
|
+
" dedupe: ['react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime'],",
|
|
173
|
+
' },',
|
|
174
|
+
'});',
|
|
175
|
+
'',
|
|
176
|
+
].join('\n');
|
|
177
|
+
|
|
128
178
|
const DEFAULT_ELECTRON_PRELOAD = [
|
|
129
179
|
"import { contextBridge, ipcRenderer } from 'electron';",
|
|
130
180
|
"import { installNimiElectronRuntimeBridge } from '@nimiplatform/kit/shell/electron/preload-cjs';",
|