nitro-ui-macos 0.0.0 → 0.0.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.
- package/CONTRIBUTING.md +56 -0
- package/LICENSE +3 -3
- package/PARITY.md +373 -0
- package/README.md +144 -5
- package/native/nitro-core/Package.swift +78 -0
- package/native/nitro-ui-core/Package.swift +112 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/AnimationFrameDisplayLink.swift +127 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridAnimationFrameScheduler.swift +91 -0
- package/native/nitro-ui-core/Sources/NitroUICoreMac/HybridLinking.swift +18 -0
- package/native/nitro-ui-dev/Package.swift +102 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoad.swift +14 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevBundleLoader.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevLauncher.swift +192 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevMenu.swift +172 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevServerBrowser.swift +86 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevSession.swift +151 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevShortcuts.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevToast.swift +85 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/DevTools.swift +141 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorModels.swift +97 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/ErrorOverlay.swift +698 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevBundles.swift +64 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevErrors.swift +56 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevLoadingView.swift +27 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevMenu.swift +40 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/HybridDevToast.swift +19 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LauncherWindowController.swift +217 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/LoadingOverlay.swift +104 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/RegisterDevLoader.swift +22 -0
- package/native/nitro-ui-dev/Sources/NitroUIDevMac/SavedBundles.swift +70 -0
- package/native/nitro-ui-glass/Package.swift +103 -0
- package/native/nitro-ui-glass/macos/HybridLiquidGlass.swift +5 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassContainerView.swift +40 -0
- package/native/nitro-ui-glass/macos/HybridNativeLiquidGlassView.swift +80 -0
- package/native/nitro-ui-glass/macos/LiquidGlassEffectView.swift +181 -0
- package/native/nitro-ui-glass/macos/LiquidGlassSupport.swift +17 -0
- package/native/nitro-ui-navigation/Package.swift +105 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationScreen.swift +199 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSharedElement.swift +17 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationSplit.swift +889 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationStack.swift +404 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/HybridNavigationTabs.swift +186 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/MacStackContainerController.swift +260 -0
- package/native/nitro-ui-navigation/Sources/NitroUINavigationMac/NavigationSharedElementView.swift +28 -0
- package/native/nitro-ui-renderer/Package.swift +105 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/HybridAnimator.swift +502 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/NitroAnimationContext.swift +54 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Animations/View+Animations.swift +35 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/AssetFonts.swift +36 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/FlippedView.swift +360 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridContainerView.swift +28 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridFonts.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridLabel.swift +127 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridMaskedView.swift +185 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollView.swift +255 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridScrollViewContent.swift +22 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/HybridView.swift +18 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImage.swift +281 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageFactory.swift +132 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageLoader.swift +149 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/HybridImageView.swift +601 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/Image/ImagePixelSupport.swift +418 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/LabelView.swift +198 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/HybridListView.swift +177 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListCell.swift +98 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListContentView.swift +12 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListFenwickTree.swift +94 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListScrollView.swift +1100 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListSnapshot.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListUpdate.swift +11 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/List/NativeListView.swift +260 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NativeContainerView.swift +443 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/NitroViewProtocols.swift +275 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/ShadowLayers.swift +338 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/HybridTextInput.swift +252 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/TextInput/NitroTextInputView.swift +447 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Components/View.swift +660 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/CustomViewController.swift +254 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/DesktopHostDelegate.swift +14 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Extensions.swift +102 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/GestureRecognizerDelegate.swift +24 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridGestureRecognizer.swift +41 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridLongPressGestureRecognizer.swift +172 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridPanGestureRecognizer.swift +193 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Gestures/HybridTapGestureRecognizer.swift +165 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridAppearance.swift +75 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridApplication.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridKeyboard.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridScreen.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridViewController.swift +232 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindow.swift +61 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/HybridWindowScene.swift +17 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/LayoutNode.swift +73 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/NSColor+rgba.swift +29 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RegisterRootCallback.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/RuntimeReloadableAppDelegate.swift +7 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SafeAreaInsetsListeners.swift +26 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/SizeListeners.swift +27 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/UIErrorHandler.swift +15 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/ViewController.swift +6 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/Window.swift +156 -0
- package/native/nitro-ui-renderer/Sources/NitroUIRendererMac/WindowScene.swift +23 -0
- package/native/nitro-ui-runtime/Package.swift +67 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/DevLoader.swift +16 -0
- package/native/nitro-ui-runtime/Sources/NitroUIRuntimeMac/NitroUIAppDelegate.swift +253 -0
- package/package.json +57 -8
- package/src/Platform.ts +43 -0
- package/src/bin.js +18 -0
- package/src/build.ts +453 -0
- package/src/bundleWorker.ts +80 -0
- package/src/cli.ts +157 -0
- package/src/config.ts +233 -0
- package/src/create.ts +67 -0
- package/src/files.ts +70 -0
- package/src/index.ts +1 -0
- package/src/init.ts +301 -0
- package/src/inlinePlatform.ts +140 -0
- package/src/modules.ts +385 -0
- package/src/packageApp.ts +103 -0
- package/src/packageDirectory.ts +61 -0
- package/src/preload.ts +40 -0
- package/src/prepare.ts +433 -0
- package/src/run.ts +41 -0
- package/src/runApp.ts +81 -0
- package/src/start.ts +152 -0
- package/src/toolchain.ts +83 -0
- package/src/versions.ts +103 -0
- package/templates/AppIcon.icns +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ScopeTracker, walk } from 'oxc-walker'
|
|
2
|
+
import { RolldownMagicString, type Plugin } from 'rolldown'
|
|
3
|
+
import type { ESTree } from 'rolldown/utils'
|
|
4
|
+
|
|
5
|
+
export type BundlePlatform = 'ios' | 'android' | 'macos'
|
|
6
|
+
|
|
7
|
+
const corePlatformModulePattern = /(?:^|[\\/])nitro-ui-core[\\/]src[\\/]Platform\.(?:ts|js|mjs)$/
|
|
8
|
+
|
|
9
|
+
const macOSRuntimePlatformModule = `export const Platform = {
|
|
10
|
+
OS: 'macos',
|
|
11
|
+
select(values) {
|
|
12
|
+
if (values.macos !== undefined) {
|
|
13
|
+
return values.macos
|
|
14
|
+
}
|
|
15
|
+
return values.ios
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
const platformImportSources = new Set(['nitro-ui-core', 'nitro-ui-macos'])
|
|
21
|
+
const statementLists = new Set(['Program', 'BlockStatement', 'StaticBlock', 'SwitchCase', 'TSModuleBlock'])
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Replaces `Platform.OS` and `Platform.select(...)` for macOS bundles (falling back to `ios` when `macos` is absent)
|
|
25
|
+
* and overrides the runtime `nitro-ui-core` Platform module for non-inlined dynamic accesses.
|
|
26
|
+
*
|
|
27
|
+
* When injected into unmodified `nitro-ui-bundler@0.3.0`, `'ios'` bundles are redirected to `'macos'` while `'android'` stays unchanged.
|
|
28
|
+
*/
|
|
29
|
+
export function inlinePlatform(platform: BundlePlatform): Plugin {
|
|
30
|
+
const effectivePlatform: 'macos' | 'android' = platform === 'android' ? 'android' : 'macos'
|
|
31
|
+
const isMacOS = effectivePlatform === 'macos'
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: 'inline-platform',
|
|
35
|
+
load: {
|
|
36
|
+
filter: { id: corePlatformModulePattern },
|
|
37
|
+
handler() {
|
|
38
|
+
if (isMacOS === false) return null
|
|
39
|
+
return { code: macOSRuntimePlatformModule, moduleType: 'js' }
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
transform: {
|
|
43
|
+
filter: { code: /nitro-ui-(?:core|macos)/, moduleType: ['js', 'jsx', 'ts', 'tsx'] },
|
|
44
|
+
handler(code, _id, meta) {
|
|
45
|
+
const lang = meta.moduleType
|
|
46
|
+
if (lang !== 'js' && lang !== 'jsx' && lang !== 'ts' && lang !== 'tsx') return null
|
|
47
|
+
const program = this.parse(code, { lang: lang })
|
|
48
|
+
const names = new Set<string>()
|
|
49
|
+
for (const statement of program.body) {
|
|
50
|
+
if (statement.type !== 'ImportDeclaration') continue
|
|
51
|
+
if (statement.importKind === 'type') continue
|
|
52
|
+
if (platformImportSources.has(statement.source.value) === false) continue
|
|
53
|
+
for (const specifier of statement.specifiers) {
|
|
54
|
+
if (
|
|
55
|
+
specifier.type === 'ImportSpecifier' &&
|
|
56
|
+
specifier.importKind !== 'type' &&
|
|
57
|
+
specifier.imported.type === 'Identifier' &&
|
|
58
|
+
specifier.imported.name === 'Platform'
|
|
59
|
+
) {
|
|
60
|
+
names.add(specifier.local.name)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (names.size === 0) return null
|
|
65
|
+
|
|
66
|
+
const context = this
|
|
67
|
+
const output = new RolldownMagicString(code)
|
|
68
|
+
const scopes = new ScopeTracker({ preserveExitedScopes: true })
|
|
69
|
+
const statementStarts = new Set<number>()
|
|
70
|
+
walk(program, {
|
|
71
|
+
scopeTracker: scopes,
|
|
72
|
+
enter(node, parent) {
|
|
73
|
+
if (node.type === 'ExpressionStatement' && parent !== null && statementLists.has(parent.type)) {
|
|
74
|
+
statementStarts.add(node.start)
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
scopes.freeze()
|
|
79
|
+
|
|
80
|
+
const isPlatform = (node: ESTree.MemberExpression['object']) =>
|
|
81
|
+
node.type === 'Identifier' && names.has(node.name) && scopes.getDeclaration(node.name)?.type === 'Import'
|
|
82
|
+
|
|
83
|
+
let selectDepth = 0
|
|
84
|
+
walk(program, {
|
|
85
|
+
scopeTracker: scopes,
|
|
86
|
+
enter(node) {
|
|
87
|
+
if (node.type === 'MemberExpression') {
|
|
88
|
+
if (node.computed || isPlatform(node.object) === false) return
|
|
89
|
+
if (node.property.type !== 'Identifier' || node.property.name !== 'OS') return
|
|
90
|
+
if (selectDepth > 0) {
|
|
91
|
+
context.error("Platform.OS can't be used inside Platform.select. Use the value for each platform instead.", node.start)
|
|
92
|
+
}
|
|
93
|
+
output.overwrite(node.start, node.end, JSON.stringify(effectivePlatform))
|
|
94
|
+
} else if (node.type === 'CallExpression' && isSelectCall(node, isPlatform)) {
|
|
95
|
+
if (selectDepth > 0) {
|
|
96
|
+
context.error("Platform.select calls can't be nested. Use a single Platform.select instead.", node.start)
|
|
97
|
+
}
|
|
98
|
+
selectDepth++
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
leave(node) {
|
|
102
|
+
if (node.type !== 'CallExpression' || isSelectCall(node, isPlatform) === false) return
|
|
103
|
+
selectDepth--
|
|
104
|
+
const values = node.arguments[0]
|
|
105
|
+
if (node.arguments.length !== 1 || values?.type !== 'ObjectExpression') return
|
|
106
|
+
for (const property of values.properties) {
|
|
107
|
+
if (property.type !== 'Property' || property.computed || property.kind !== 'init' || property.method) return
|
|
108
|
+
}
|
|
109
|
+
let match = values.properties.find(
|
|
110
|
+
(property) => property.type === 'Property' && propertyName(property.key) === effectivePlatform,
|
|
111
|
+
)
|
|
112
|
+
if (match === undefined && isMacOS) {
|
|
113
|
+
match = values.properties.find(
|
|
114
|
+
(property) => property.type === 'Property' && propertyName(property.key) === 'ios',
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
if (match === undefined || match.type !== 'Property') return
|
|
118
|
+
const separator = statementStarts.has(node.start) ? ';' : ''
|
|
119
|
+
output.overwrite(node.start, node.end, `${separator}(${code.slice(match.value.start, match.value.end)})`)
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
if (output.hasChanged() === false) return null
|
|
124
|
+
return { code: output }
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function isSelectCall(node: ESTree.CallExpression, isPlatform: (node: ESTree.MemberExpression['object']) => boolean): boolean {
|
|
131
|
+
const callee = node.callee
|
|
132
|
+
if (callee.type !== 'MemberExpression' || callee.computed || isPlatform(callee.object) === false) return false
|
|
133
|
+
return callee.property.type === 'Identifier' && callee.property.name === 'select'
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function propertyName(key: ESTree.PropertyKey): string | undefined {
|
|
137
|
+
if (key.type === 'Identifier') return key.name
|
|
138
|
+
if (key.type === 'Literal' && typeof key.value === 'string') return key.value
|
|
139
|
+
return undefined
|
|
140
|
+
}
|
package/src/modules.ts
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { readFile, realpath } from 'node:fs/promises'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { z } from 'zod'
|
|
6
|
+
import { fileExists, isMissingFile, writeChanged } from './files'
|
|
7
|
+
import { packageDirectory, readPackageManifest, tryPackageDirectory } from './packageDirectory'
|
|
8
|
+
import { run } from './run'
|
|
9
|
+
import { SUPPORTED_NITRO_CORE_VERSION } from './versions'
|
|
10
|
+
|
|
11
|
+
const identifier = z.string().regex(/^[A-Za-z][A-Za-z0-9_]*$/)
|
|
12
|
+
const versionSchema = z.object({ version: z.string() })
|
|
13
|
+
const packageNameSchema = z.object({ name: z.string() })
|
|
14
|
+
const dependencySchema = z.record(z.string(), z.string())
|
|
15
|
+
const appDependenciesSchema = z.object({
|
|
16
|
+
dependencies: dependencySchema.optional(),
|
|
17
|
+
optionalDependencies: dependencySchema.optional(),
|
|
18
|
+
})
|
|
19
|
+
const bareModuleSchema = z.object({ environment: z.literal('bare') })
|
|
20
|
+
const moduleSchema = bareModuleSchema.extend({
|
|
21
|
+
cxxNamespace: z.array(identifier).min(1),
|
|
22
|
+
apple: z.object({ moduleName: identifier }),
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export const FRAMEWORK_PACKAGES = new Set([
|
|
26
|
+
'nitro-hermes',
|
|
27
|
+
'nitro-ui-layout',
|
|
28
|
+
'nitro-ui-layout-starlight',
|
|
29
|
+
'nitro-ui-layout-yoga',
|
|
30
|
+
'nitro-ui-core',
|
|
31
|
+
'nitro-ui-dev',
|
|
32
|
+
'nitro-networking',
|
|
33
|
+
'nitro-ui-renderer',
|
|
34
|
+
'nitro-ui-navigation',
|
|
35
|
+
'nitro-ui-runtime',
|
|
36
|
+
'nitro-ui-macos',
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
/** Optional upstream packages whose Mac native sources are supplied by nitro-ui-macos overlays. */
|
|
40
|
+
export const OVERLAY_MODULES = new Set(['nitro-ui-glass'])
|
|
41
|
+
|
|
42
|
+
export interface DiscoveredMacModule {
|
|
43
|
+
packageName: string
|
|
44
|
+
directory: string
|
|
45
|
+
name: string
|
|
46
|
+
wrapper: string
|
|
47
|
+
namespace: string
|
|
48
|
+
source: 'dependency' | 'configured'
|
|
49
|
+
overlay: boolean
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface SkippedMacModule {
|
|
53
|
+
packageName: string
|
|
54
|
+
name: string
|
|
55
|
+
directory: string
|
|
56
|
+
reason: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ModuleDiscoveryResult {
|
|
60
|
+
included: DiscoveredMacModule[]
|
|
61
|
+
skipped: SkippedMacModule[]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Strips Swift line comments and block comments while respecting string literals.
|
|
65
|
+
function stripSwiftComments(source: string): string {
|
|
66
|
+
let result = ''
|
|
67
|
+
let i = 0
|
|
68
|
+
let inString = false
|
|
69
|
+
let blockDepth = 0
|
|
70
|
+
|
|
71
|
+
while (i < source.length) {
|
|
72
|
+
const ch = source[i]
|
|
73
|
+
const next = source[i + 1]
|
|
74
|
+
|
|
75
|
+
if (blockDepth > 0) {
|
|
76
|
+
if (ch === '/' && next === '*') {
|
|
77
|
+
blockDepth++
|
|
78
|
+
i += 2
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
if (ch === '*' && next === '/') {
|
|
82
|
+
blockDepth--
|
|
83
|
+
i += 2
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
if (ch === '\n') result += '\n'
|
|
87
|
+
i++
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (inString) {
|
|
92
|
+
if (ch === '\\' && next !== undefined) {
|
|
93
|
+
i += 2
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
if (ch === '"') {
|
|
97
|
+
result += '"'
|
|
98
|
+
inString = false
|
|
99
|
+
}
|
|
100
|
+
i++
|
|
101
|
+
continue
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (ch === '"') {
|
|
105
|
+
inString = true
|
|
106
|
+
result += ch
|
|
107
|
+
i++
|
|
108
|
+
continue
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (ch === '/' && next === '/') {
|
|
112
|
+
while (i < source.length && source[i] !== '\n') {
|
|
113
|
+
i++
|
|
114
|
+
}
|
|
115
|
+
continue
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (ch === '/' && next === '*') {
|
|
119
|
+
blockDepth = 1
|
|
120
|
+
i += 2
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
result += ch ?? ''
|
|
125
|
+
i++
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return result
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Checks whether a SwiftPM `Package.swift` manifest explicitly declares macOS support in its `platforms: [...]` list.
|
|
133
|
+
*/
|
|
134
|
+
export function packageDeclaresMacOS(manifestContents: string): boolean {
|
|
135
|
+
const cleaned = stripSwiftComments(manifestContents)
|
|
136
|
+
const platformsPattern = /\bplatforms\s*:\s*\[/g
|
|
137
|
+
let match = platformsPattern.exec(cleaned)
|
|
138
|
+
while (match !== null) {
|
|
139
|
+
let index = match.index + match[0].length
|
|
140
|
+
let depth = 1
|
|
141
|
+
let body = ''
|
|
142
|
+
while (index < cleaned.length && depth > 0) {
|
|
143
|
+
const ch = cleaned[index]
|
|
144
|
+
if (ch === '[') depth++
|
|
145
|
+
else if (ch === ']') depth--
|
|
146
|
+
if (depth > 0 && ch !== undefined) body += ch
|
|
147
|
+
index++
|
|
148
|
+
}
|
|
149
|
+
if (/(?:SupportedPlatform)?\.macOS\s*\(/.test(body)) {
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
match = platformsPattern.exec(cleaned)
|
|
153
|
+
}
|
|
154
|
+
return false
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function findDependencyManifest(name: string, searchPaths: string[]): Promise<string | undefined> {
|
|
158
|
+
for (const searchPath of searchPaths) {
|
|
159
|
+
const path = join(searchPath, name, 'package.json')
|
|
160
|
+
if (await fileExists(path)) return path
|
|
161
|
+
}
|
|
162
|
+
return undefined
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function findNitroConfigFile(directory: string): Promise<string | undefined> {
|
|
166
|
+
const standard = join(directory, 'nitro.json')
|
|
167
|
+
if (await fileExists(standard)) return standard
|
|
168
|
+
const macOnly = join(directory, 'nitro-macos.json')
|
|
169
|
+
if (await fileExists(macOnly)) return macOnly
|
|
170
|
+
return undefined
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function findCandidateDirectories(
|
|
174
|
+
root: string,
|
|
175
|
+
patterns: string[],
|
|
176
|
+
): Promise<Map<string, { source: 'dependency' | 'configured'; packageName: string }>> {
|
|
177
|
+
const manifestPath = join(root, 'package.json')
|
|
178
|
+
const manifestContents = await readPackageManifest(manifestPath)
|
|
179
|
+
const { dependencies, optionalDependencies } = appDependenciesSchema.parse(manifestContents)
|
|
180
|
+
const require = createRequire(manifestPath)
|
|
181
|
+
const directories = new Map<string, { source: 'dependency' | 'configured'; packageName: string }>()
|
|
182
|
+
const dependencyNames = Object.keys({ ...dependencies, ...optionalDependencies })
|
|
183
|
+
|
|
184
|
+
for (const name of dependencyNames) {
|
|
185
|
+
const searchPaths = require.resolve.paths(`${name}/package.json`) ?? []
|
|
186
|
+
let packagePath = await findDependencyManifest(name, searchPaths)
|
|
187
|
+
if (packagePath === undefined) {
|
|
188
|
+
const resolvedDir = tryPackageDirectory(name, [root])
|
|
189
|
+
if (resolvedDir !== undefined) {
|
|
190
|
+
const candidate = join(resolvedDir, 'package.json')
|
|
191
|
+
if (await fileExists(candidate)) {
|
|
192
|
+
packagePath = candidate
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (packagePath === undefined) {
|
|
197
|
+
if (optionalDependencies?.[name] !== undefined) continue
|
|
198
|
+
throw new Error(`Cannot find app dependency ${name}. Install dependencies before preparing the app.`)
|
|
199
|
+
}
|
|
200
|
+
const directory = dirname(packagePath)
|
|
201
|
+
const configPath = await findNitroConfigFile(directory)
|
|
202
|
+
if (configPath === undefined) continue
|
|
203
|
+
const packageContents = await readPackageManifest(packagePath)
|
|
204
|
+
const installed = packageNameSchema.parse(packageContents)
|
|
205
|
+
if (FRAMEWORK_PACKAGES.has(installed.name)) continue
|
|
206
|
+
const canonicalDirectory = await realpath(directory)
|
|
207
|
+
directories.set(canonicalDirectory, { source: 'dependency', packageName: installed.name })
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
for (const pattern of patterns) {
|
|
211
|
+
for (const filename of ['nitro.json', 'nitro-macos.json']) {
|
|
212
|
+
const configPattern = join(pattern, filename)
|
|
213
|
+
const glob = new Bun.Glob(configPattern)
|
|
214
|
+
for await (const path of glob.scan({ cwd: root, absolute: true })) {
|
|
215
|
+
const directory = dirname(path)
|
|
216
|
+
const canonicalDirectory = await realpath(directory)
|
|
217
|
+
if (directories.has(canonicalDirectory)) continue
|
|
218
|
+
let pkgName = directory
|
|
219
|
+
const pkgJson = join(directory, 'package.json')
|
|
220
|
+
if (await fileExists(pkgJson)) {
|
|
221
|
+
const pkgContents = await readPackageManifest(pkgJson)
|
|
222
|
+
const parsedPkg = packageNameSchema.safeParse(pkgContents)
|
|
223
|
+
if (parsedPkg.success) {
|
|
224
|
+
if (FRAMEWORK_PACKAGES.has(parsedPkg.data.name)) continue
|
|
225
|
+
pkgName = parsedPkg.data.name
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
directories.set(canonicalDirectory, { source: 'configured', packageName: pkgName })
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return directories
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function discoverMacModules(root: string, patterns: string[]): Promise<ModuleDiscoveryResult> {
|
|
237
|
+
const candidates = await findCandidateDirectories(root, patterns)
|
|
238
|
+
const sortedDirectories = Array.from(candidates.keys()).sort()
|
|
239
|
+
|
|
240
|
+
const names = new Set<string>()
|
|
241
|
+
const namespaces = new Set<string>()
|
|
242
|
+
const included: DiscoveredMacModule[] = []
|
|
243
|
+
const skipped: SkippedMacModule[] = []
|
|
244
|
+
|
|
245
|
+
for (const directory of sortedDirectories) {
|
|
246
|
+
const entry = candidates.get(directory)
|
|
247
|
+
if (entry === undefined) continue
|
|
248
|
+
const configPath = await findNitroConfigFile(directory)
|
|
249
|
+
if (configPath === undefined) continue
|
|
250
|
+
const contents: unknown = await Bun.file(configPath).json()
|
|
251
|
+
if (entry.source === 'dependency') {
|
|
252
|
+
const bare = bareModuleSchema.safeParse(contents)
|
|
253
|
+
if (bare.success === false) continue
|
|
254
|
+
}
|
|
255
|
+
const config = moduleSchema.parse(contents)
|
|
256
|
+
const name = config.apple.moduleName
|
|
257
|
+
const namespace = config.cxxNamespace.join('::')
|
|
258
|
+
const wrapper = `app-${name.toLowerCase()}`
|
|
259
|
+
if (name.startsWith('NitroUI') || name.startsWith('NitroModules') || names.has(wrapper) || namespaces.has(namespace)) {
|
|
260
|
+
throw new Error(`Native module ${configPath} must have a unique module name and C++ namespace, distinct from the framework.`)
|
|
261
|
+
}
|
|
262
|
+
names.add(wrapper)
|
|
263
|
+
namespaces.add(namespace)
|
|
264
|
+
|
|
265
|
+
const isOverlay = OVERLAY_MODULES.has(entry.packageName)
|
|
266
|
+
if (isOverlay) {
|
|
267
|
+
included.push({
|
|
268
|
+
packageName: entry.packageName,
|
|
269
|
+
directory: directory,
|
|
270
|
+
name: name,
|
|
271
|
+
wrapper: wrapper,
|
|
272
|
+
namespace: namespace,
|
|
273
|
+
source: entry.source,
|
|
274
|
+
overlay: true,
|
|
275
|
+
})
|
|
276
|
+
continue
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const packageSwiftPath = join(directory, 'Package.swift')
|
|
280
|
+
if ((await fileExists(packageSwiftPath)) === false) {
|
|
281
|
+
skipped.push({
|
|
282
|
+
packageName: entry.packageName,
|
|
283
|
+
name: name,
|
|
284
|
+
directory: directory,
|
|
285
|
+
reason: 'no Package.swift found',
|
|
286
|
+
})
|
|
287
|
+
continue
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const manifestContents = await readFile(packageSwiftPath, 'utf8')
|
|
291
|
+
if (packageDeclaresMacOS(manifestContents) === false) {
|
|
292
|
+
skipped.push({
|
|
293
|
+
packageName: entry.packageName,
|
|
294
|
+
name: name,
|
|
295
|
+
directory: directory,
|
|
296
|
+
reason: 'Package.swift does not declare macOS support',
|
|
297
|
+
})
|
|
298
|
+
continue
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
included.push({
|
|
302
|
+
packageName: entry.packageName,
|
|
303
|
+
directory: directory,
|
|
304
|
+
name: name,
|
|
305
|
+
wrapper: wrapper,
|
|
306
|
+
namespace: namespace,
|
|
307
|
+
source: entry.source,
|
|
308
|
+
overlay: false,
|
|
309
|
+
})
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return { included: included, skipped: skipped }
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export async function generateMacModules(options: {
|
|
316
|
+
root: string
|
|
317
|
+
searchRoots: string[]
|
|
318
|
+
modules: DiscoveredMacModule[]
|
|
319
|
+
clean: boolean
|
|
320
|
+
}): Promise<void> {
|
|
321
|
+
const { root, searchRoots, modules, clean } = options
|
|
322
|
+
const nitrogen = packageDirectory('nitrogen', searchRoots)
|
|
323
|
+
const nitrogenManifest = await readFile(join(nitrogen, 'package.json'), 'utf8')
|
|
324
|
+
const generator = join(nitrogen, 'bin/nitrogen.js')
|
|
325
|
+
|
|
326
|
+
for (const module of modules) {
|
|
327
|
+
const generated = join(module.directory, 'nitrogen/generated')
|
|
328
|
+
const generatedManifest = join(generated, 'hybrid-classes.json')
|
|
329
|
+
const hasGenerated = await fileExists(generatedManifest)
|
|
330
|
+
|
|
331
|
+
const moduleCoreDir = tryPackageDirectory('nitro-core', [module.directory, ...searchRoots])
|
|
332
|
+
if (moduleCoreDir !== undefined) {
|
|
333
|
+
const moduleCoreContents: unknown = await Bun.file(join(moduleCoreDir, 'package.json')).json()
|
|
334
|
+
const moduleCoreManifest = versionSchema.parse(moduleCoreContents)
|
|
335
|
+
if (moduleCoreManifest.version !== SUPPORTED_NITRO_CORE_VERSION) {
|
|
336
|
+
throw new Error(
|
|
337
|
+
`${module.name} resolves nitro-core@${moduleCoreManifest.version}. ` +
|
|
338
|
+
`Update its dependency to ${SUPPORTED_NITRO_CORE_VERSION} and run \`bun install\`.`,
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const isInsideNodeModules = module.directory.includes('/node_modules/') || module.directory.includes('\\node_modules\\')
|
|
344
|
+
if ((module.source === 'dependency' || isInsideNodeModules) && hasGenerated) {
|
|
345
|
+
// Dependencies ship pre-generated bindings; avoid mutating node_modules or workspace packages.
|
|
346
|
+
continue
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const nitroConfigPath = join(module.directory, 'nitro.json')
|
|
350
|
+
if ((await fileExists(nitroConfigPath)) === false) {
|
|
351
|
+
if (hasGenerated) continue
|
|
352
|
+
throw new Error(`Module ${module.name} at ${module.directory} has no nitro.json and no pre-generated nitrogen/generated bindings.`)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const hash = createHash('sha256')
|
|
356
|
+
hash.update(nitrogenManifest)
|
|
357
|
+
const glob = new Bun.Glob('**/*.{ts,tsx}')
|
|
358
|
+
const sources: string[] = []
|
|
359
|
+
for await (const path of glob.scan({ cwd: module.directory })) {
|
|
360
|
+
if (path.startsWith('node_modules/') || path.startsWith('nitrogen/')) continue
|
|
361
|
+
sources.push(path)
|
|
362
|
+
}
|
|
363
|
+
sources.sort()
|
|
364
|
+
const inputs = ['nitro.json', 'package.json', ...sources]
|
|
365
|
+
for (const input of inputs) {
|
|
366
|
+
const path = join(module.directory, input)
|
|
367
|
+
if ((await fileExists(path)) === false) continue
|
|
368
|
+
const contents = await readFile(path, 'utf8')
|
|
369
|
+
hash.update(input)
|
|
370
|
+
hash.update(contents)
|
|
371
|
+
}
|
|
372
|
+
const fingerprint = hash.digest('hex')
|
|
373
|
+
const marker = join(root, '.nitro/macos/codegen', `${module.wrapper}.sha256`)
|
|
374
|
+
let previous: string | undefined
|
|
375
|
+
try {
|
|
376
|
+
previous = await readFile(marker, 'utf8')
|
|
377
|
+
} catch (error) {
|
|
378
|
+
if (isMissingFile(error) === false) throw error
|
|
379
|
+
}
|
|
380
|
+
if (clean || previous !== fingerprint || hasGenerated === false) {
|
|
381
|
+
await run([process.execPath, generator, '.', '--out', generated], { cwd: module.directory })
|
|
382
|
+
await writeChanged(marker, fingerprint)
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { cp, mkdir, mkdtemp, rm, symlink } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path'
|
|
4
|
+
import { buildMacOS, type BuildArch } from './build'
|
|
5
|
+
import { run } from './run'
|
|
6
|
+
|
|
7
|
+
export interface PackageOptions {
|
|
8
|
+
root: string
|
|
9
|
+
arch?: BuildArch
|
|
10
|
+
jobs?: number
|
|
11
|
+
scratchPath?: string
|
|
12
|
+
signIdentity?: string
|
|
13
|
+
notarizeProfile?: string
|
|
14
|
+
output?: string
|
|
15
|
+
noDmg?: boolean
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PackageResult {
|
|
19
|
+
appBundlePath: string
|
|
20
|
+
dmgPath?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function packageMacOS(options: PackageOptions): Promise<PackageResult> {
|
|
24
|
+
const { root, arch, jobs, scratchPath, signIdentity, notarizeProfile, output, noDmg } = options
|
|
25
|
+
|
|
26
|
+
if (notarizeProfile !== undefined && signIdentity === undefined) {
|
|
27
|
+
throw new Error('--notarize requires --sign <Developer ID Application identity>.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const built = await buildMacOS({
|
|
31
|
+
root: root,
|
|
32
|
+
release: true,
|
|
33
|
+
arch: arch,
|
|
34
|
+
jobs: jobs,
|
|
35
|
+
scratchPath: scratchPath,
|
|
36
|
+
signIdentity: signIdentity,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
let dmgPath: string | undefined
|
|
40
|
+
if (noDmg !== true) {
|
|
41
|
+
const safeName = built.config.name.replace(/[/\\:*?"<>|]/g, '-')
|
|
42
|
+
dmgPath = output !== undefined
|
|
43
|
+
? resolve(root, output)
|
|
44
|
+
: join(root, 'macos/build/release', `${safeName}-${built.config.version}.dmg`)
|
|
45
|
+
await mkdir(dirname(dmgPath), { recursive: true })
|
|
46
|
+
await rm(dmgPath, { force: true })
|
|
47
|
+
|
|
48
|
+
const staging = await mkdtemp(join(tmpdir(), 'nitro-macos-dmg-'))
|
|
49
|
+
try {
|
|
50
|
+
const stagedApp = join(staging, basename(built.appBundlePath))
|
|
51
|
+
await cp(built.appBundlePath, stagedApp, { recursive: true, verbatimSymlinks: true })
|
|
52
|
+
await symlink('/Applications', join(staging, 'Applications'))
|
|
53
|
+
|
|
54
|
+
await run(
|
|
55
|
+
[
|
|
56
|
+
'hdiutil',
|
|
57
|
+
'create',
|
|
58
|
+
'-volname',
|
|
59
|
+
built.config.name,
|
|
60
|
+
'-srcfolder',
|
|
61
|
+
staging,
|
|
62
|
+
'-ov',
|
|
63
|
+
'-format',
|
|
64
|
+
'UDZO',
|
|
65
|
+
dmgPath,
|
|
66
|
+
],
|
|
67
|
+
{ cwd: root },
|
|
68
|
+
)
|
|
69
|
+
} finally {
|
|
70
|
+
await rm(staging, { recursive: true, force: true })
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (signIdentity !== undefined) {
|
|
74
|
+
await run(['codesign', '--force', '--timestamp', '--sign', signIdentity, dmgPath], { cwd: root })
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (notarizeProfile !== undefined) {
|
|
78
|
+
await run(
|
|
79
|
+
['xcrun', 'notarytool', 'submit', dmgPath, '--keychain-profile', notarizeProfile, '--wait'],
|
|
80
|
+
{ cwd: root },
|
|
81
|
+
)
|
|
82
|
+
await run(['xcrun', 'stapler', 'staple', dmgPath], { cwd: root })
|
|
83
|
+
await run(['xcrun', 'stapler', 'staple', built.appBundlePath], { cwd: root })
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(`Packaged DMG: ${dmgPath}`)
|
|
87
|
+
} else if (notarizeProfile !== undefined) {
|
|
88
|
+
const zipTemp = await mkdtemp(join(tmpdir(), 'nitro-macos-notarize-'))
|
|
89
|
+
try {
|
|
90
|
+
const zipPath = join(zipTemp, `${built.config.product}.zip`)
|
|
91
|
+
await run(['ditto', '-c', '-k', '--keepParent', built.appBundlePath, zipPath], { cwd: root })
|
|
92
|
+
await run(
|
|
93
|
+
['xcrun', 'notarytool', 'submit', zipPath, '--keychain-profile', notarizeProfile, '--wait'],
|
|
94
|
+
{ cwd: root },
|
|
95
|
+
)
|
|
96
|
+
await run(['xcrun', 'stapler', 'staple', built.appBundlePath], { cwd: root })
|
|
97
|
+
} finally {
|
|
98
|
+
await rm(zipTemp, { recursive: true, force: true })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return { appBundlePath: built.appBundlePath, dmgPath: dmgPath }
|
|
103
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { dirname, join, resolve } from 'node:path'
|
|
4
|
+
|
|
5
|
+
export function packageRoot(): string {
|
|
6
|
+
return resolve(import.meta.dir, '..')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function tryPackageDirectory(name: string, fromRoots: string[]): string | undefined {
|
|
10
|
+
for (const root of fromRoots) {
|
|
11
|
+
try {
|
|
12
|
+
const anchor = join(root, 'package.json')
|
|
13
|
+
const require = createRequire(anchor)
|
|
14
|
+
const manifest = require.resolve(`${name}/package.json`)
|
|
15
|
+
return dirname(manifest)
|
|
16
|
+
} catch {
|
|
17
|
+
// Try next resolution root.
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function packageDirectory(name: string, fromRoots: string[]): string {
|
|
24
|
+
const found = tryPackageDirectory(name, fromRoots)
|
|
25
|
+
if (found === undefined) {
|
|
26
|
+
throw new Error(`Cannot resolve package "${name}". Run \`bun install\` and ensure it is installed.`)
|
|
27
|
+
}
|
|
28
|
+
return found
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolutionRoots(appRoot: string): string[] {
|
|
32
|
+
const seen = new Set<string>()
|
|
33
|
+
const roots: string[] = []
|
|
34
|
+
const add = (dir: string | undefined): void => {
|
|
35
|
+
if (dir !== undefined && seen.has(dir) === false) {
|
|
36
|
+
seen.add(dir)
|
|
37
|
+
roots.push(dir)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
add(appRoot)
|
|
42
|
+
// Walk direct NitroUI packages so transitive framework packages resolve under strict isolated linkers (pnpm, bun isolated).
|
|
43
|
+
const seedPackages = [
|
|
44
|
+
'nitro-ui-cli',
|
|
45
|
+
'nitro-ui-renderer',
|
|
46
|
+
'nitro-ui-navigation',
|
|
47
|
+
'nitro-ui-runtime',
|
|
48
|
+
'nitro-ui-core',
|
|
49
|
+
'nitro-ui-bundler',
|
|
50
|
+
]
|
|
51
|
+
for (const name of seedPackages) {
|
|
52
|
+
add(tryPackageDirectory(name, roots))
|
|
53
|
+
}
|
|
54
|
+
add(packageRoot())
|
|
55
|
+
return roots
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function readPackageManifest(path: string): Promise<unknown> {
|
|
59
|
+
const contents = await readFile(path, 'utf8')
|
|
60
|
+
return Bun.JSONC.parse(contents)
|
|
61
|
+
}
|