Skip to content

Commit 7a03a14

Browse files
committed
feat: enhance package resolution by adding fallbacks for Capacitor packages
1 parent a4c7eb3 commit 7a03a14

File tree

6 files changed

+129
-27
lines changed

6 files changed

+129
-27
lines changed

cli/src/android/update.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ export async function installGradlePlugins(
135135
capacitorPlugins: Plugin[],
136136
cordovaPlugins: Plugin[],
137137
): Promise<void> {
138-
const capacitorAndroidPackagePath = resolveNode(config.app.rootDir, '@capacitor-plus/android', 'package.json');
138+
// Try @capacitor-plus/android first, then fall back to @capacitor/android
139+
let capacitorAndroidPackagePath = resolveNode(config.app.rootDir, '@capacitor-plus/android', 'package.json');
140+
141+
if (!capacitorAndroidPackagePath) {
142+
capacitorAndroidPackagePath = resolveNode(config.app.rootDir, '@capacitor/android', 'package.json');
143+
}
144+
139145
if (!capacitorAndroidPackagePath) {
140146
fatal(
141-
`Unable to find ${c.strong('node_modules/@capacitor-plus/android')}.\n` +
142-
`Are you sure ${c.strong('@capacitor-plus/android')} is installed?`,
147+
`Unable to find ${c.strong('node_modules/@capacitor-plus/android')} or ${c.strong('node_modules/@capacitor/android')}.\n` +
148+
`Are you sure ${c.strong('@capacitor-plus/android')} or ${c.strong('@capacitor/android')} is installed?`,
143149
);
144150
}
145151

cli/src/common.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function checkCapacitorPlatform(config: Config, platform: string):
7676
if (!pkg) {
7777
return (
7878
`Could not find the ${c.input(platform)} platform.\n` +
79-
`You must install it in your project first, e.g. w/ ${c.input(`npm install @capacitor-plus/${platform}`)}`
79+
`You must install it in your project first, e.g. w/ ${c.input(`npm install @capacitor-plus/${platform}`)} or ${c.input(`npm install @capacitor/${platform}`)}`
8080
);
8181
}
8282

@@ -224,7 +224,12 @@ export async function runTask<T>(title: string, fn: () => Promise<T>): Promise<T
224224
}
225225

226226
export async function getCapacitorPackage(config: Config, name: string): Promise<PackageJson | null> {
227-
const packagePath = resolveNode(config.app.rootDir, `@capacitor-plus/${name}`, 'package.json');
227+
// Try @capacitor-plus first, then fall back to @capacitor
228+
let packagePath = resolveNode(config.app.rootDir, `@capacitor-plus/${name}`, 'package.json');
229+
230+
if (!packagePath) {
231+
packagePath = resolveNode(config.app.rootDir, `@capacitor/${name}`, 'package.json');
232+
}
228233

229234
if (!packagePath) {
230235
return null;
@@ -238,8 +243,8 @@ export async function requireCapacitorPackage(config: Config, name: string): Pro
238243

239244
if (!pkg) {
240245
fatal(
241-
`Unable to find node_modules/@capacitor-plus/${name}.\n` +
242-
`Are you sure ${c.strong(`@capacitor-plus/${name}`)} is installed?`,
246+
`Unable to find node_modules/@capacitor-plus/${name} or node_modules/@capacitor/${name}.\n` +
247+
`Are you sure ${c.strong(`@capacitor-plus/${name}`)} or ${c.strong(`@capacitor/${name}`)} is installed?`,
243248
);
244249
}
245250
return pkg;
@@ -472,20 +477,28 @@ export async function checkPlatformVersions(config: Config, platform: string): P
472477

473478
if (semver.diff(coreVersion, platformVersion) === 'minor' || semver.diff(coreVersion, platformVersion) === 'major') {
474479
logger.warn(
475-
`${c.strong('@capacitor-plus/core')}${c.weak(
480+
`${c.strong('core')}${c.weak(
476481
`@${coreVersion}`,
477-
)} version doesn't match ${c.strong(`@capacitor-plus/${platform}`)}${c.weak(`@${platformVersion}`)} version.\n` +
478-
`Consider updating to a matching version, e.g. w/ ${c.input(`npm install @capacitor-plus/core@${platformVersion}`)}`,
482+
)} version doesn't match ${c.strong(`${platform}`)}${c.weak(`@${platformVersion}`)} version.\n` +
483+
`Consider updating to a matching version.`,
479484
);
480485
}
481486
}
482487

483488
export function resolvePlatform(config: Config, platform: string): string | null {
484489
if (platform[0] !== '@') {
485-
const core = resolveNode(config.app.rootDir, `@capacitor-plus/${platform}`, 'package.json');
490+
// Try @capacitor-plus first
491+
const capacitorPlus = resolveNode(config.app.rootDir, `@capacitor-plus/${platform}`, 'package.json');
492+
493+
if (capacitorPlus) {
494+
return dirname(capacitorPlus);
495+
}
496+
497+
// Fall back to official @capacitor
498+
const capacitor = resolveNode(config.app.rootDir, `@capacitor/${platform}`, 'package.json');
486499

487-
if (core) {
488-
return dirname(core);
500+
if (capacitor) {
501+
return dirname(capacitor);
489502
}
490503

491504
const community = resolveNode(config.app.rootDir, `@capacitor-community/${platform}`, 'package.json');

cli/src/cordova.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ export async function copyPluginsJS(config: Config, cordovaPlugins: Plugin[], pl
145145
}
146146

147147
export async function copyCordovaJS(config: Config, platform: string): Promise<void> {
148-
const cordovaPath = resolveNode(config.app.rootDir, '@capacitor-plus/core', 'cordova.js');
148+
// Try @capacitor-plus/core first, then fall back to @capacitor/core
149+
let cordovaPath = resolveNode(config.app.rootDir, '@capacitor-plus/core', 'cordova.js');
150+
151+
if (!cordovaPath) {
152+
cordovaPath = resolveNode(config.app.rootDir, '@capacitor/core', 'cordova.js');
153+
}
154+
149155
if (!cordovaPath) {
150156
fatal(
151-
`Unable to find ${c.strong('node_modules/@capacitor-plus/core/cordova.js')}.\n` +
152-
`Are you sure ${c.strong('@capacitor-plus/core')} is installed?`,
157+
`Unable to find ${c.strong('node_modules/@capacitor-plus/core/cordova.js')} or ${c.strong('node_modules/@capacitor/core/cordova.js')}.\n` +
158+
`Are you sure ${c.strong('@capacitor-plus/core')} or ${c.strong('@capacitor/core')} is installed?`,
153159
);
154160
}
155161

cli/src/ios/update.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,17 @@ async function updatePodfile(config: Config, plugins: Plugin[], deployment: bool
158158
}
159159

160160
async function getRelativeCapacitoriOSPath(config: Config) {
161-
const capacitoriOSPath = resolveNode(config.app.rootDir, '@capacitor-plus/ios', 'package.json');
161+
// Try @capacitor-plus/ios first, then fall back to @capacitor/ios
162+
let capacitoriOSPath = resolveNode(config.app.rootDir, '@capacitor-plus/ios', 'package.json');
163+
164+
if (!capacitoriOSPath) {
165+
capacitoriOSPath = resolveNode(config.app.rootDir, '@capacitor/ios', 'package.json');
166+
}
162167

163168
if (!capacitoriOSPath) {
164169
fatal(
165-
`Unable to find ${c.strong('node_modules/@capacitor-plus/ios')}.\n` +
166-
`Are you sure ${c.strong('@capacitor-plus/ios')} is installed?`,
170+
`Unable to find ${c.strong('node_modules/@capacitor-plus/ios')} or ${c.strong('node_modules/@capacitor/ios')}.\n` +
171+
`Are you sure ${c.strong('@capacitor-plus/ios')} or ${c.strong('@capacitor/ios')} is installed?`,
167172
);
168173
}
169174

cli/src/tasks/doctor.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,36 @@ export async function doctorCommand(config: Config, selectedPlatformName: string
2424
}
2525

2626
export async function doctorCore(config: Config): Promise<void> {
27-
const [cliVersion, coreVersion, androidVersion, iosVersion] = await Promise.all([
27+
const [
28+
cliVersionPlus,
29+
coreVersionPlus,
30+
androidVersionPlus,
31+
iosVersionPlus,
32+
cliVersion,
33+
coreVersion,
34+
androidVersion,
35+
iosVersion,
36+
] = await Promise.all([
2837
getCommandOutput('npm', ['info', '@capacitor-plus/cli', 'version']),
2938
getCommandOutput('npm', ['info', '@capacitor-plus/core', 'version']),
3039
getCommandOutput('npm', ['info', '@capacitor-plus/android', 'version']),
3140
getCommandOutput('npm', ['info', '@capacitor-plus/ios', 'version']),
41+
getCommandOutput('npm', ['info', '@capacitor/cli', 'version']),
42+
getCommandOutput('npm', ['info', '@capacitor/core', 'version']),
43+
getCommandOutput('npm', ['info', '@capacitor/android', 'version']),
44+
getCommandOutput('npm', ['info', '@capacitor/ios', 'version']),
3245
]);
3346

3447
output.write(
3548
`${c.strong('Latest Dependencies:')}\n\n` +
36-
` @capacitor-plus/cli: ${c.weak(cliVersion ?? 'unknown')}\n` +
37-
` @capacitor-plus/core: ${c.weak(coreVersion ?? 'unknown')}\n` +
38-
` @capacitor-plus/android: ${c.weak(androidVersion ?? 'unknown')}\n` +
39-
` @capacitor-plus/ios: ${c.weak(iosVersion ?? 'unknown')}\n\n` +
49+
` @capacitor-plus/cli: ${c.weak(cliVersionPlus ?? 'unknown')}\n` +
50+
` @capacitor-plus/core: ${c.weak(coreVersionPlus ?? 'unknown')}\n` +
51+
` @capacitor-plus/android: ${c.weak(androidVersionPlus ?? 'unknown')}\n` +
52+
` @capacitor-plus/ios: ${c.weak(iosVersionPlus ?? 'unknown')}\n\n` +
53+
` @capacitor/cli: ${c.weak(cliVersion ?? 'unknown')}\n` +
54+
` @capacitor/core: ${c.weak(coreVersion ?? 'unknown')}\n` +
55+
` @capacitor/android: ${c.weak(androidVersion ?? 'unknown')}\n` +
56+
` @capacitor/ios: ${c.weak(iosVersion ?? 'unknown')}\n\n` +
4057
`${c.strong('Installed Dependencies:')}\n\n`,
4158
);
4259

@@ -51,6 +68,10 @@ async function printInstalledPackages(config: Config) {
5168
'@capacitor-plus/core',
5269
'@capacitor-plus/android',
5370
'@capacitor-plus/ios',
71+
'@capacitor/cli',
72+
'@capacitor/core',
73+
'@capacitor/android',
74+
'@capacitor/ios',
5475
];
5576
await Promise.all(
5677
packageNames.map(async (packageName) => {

cli/src/tasks/migrate.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ import { extractTemplate } from '../util/template';
1616

1717
// eslint-disable-next-line prefer-const
1818
let allDependencies: { [key: string]: any } = {};
19-
const libs = ['@capacitor-plus/core', '@capacitor-plus/cli', '@capacitor-plus/ios', '@capacitor-plus/android'];
19+
const libs = [
20+
'@capacitor-plus/core',
21+
'@capacitor-plus/cli',
22+
'@capacitor-plus/ios',
23+
'@capacitor-plus/android',
24+
'@capacitor/core',
25+
'@capacitor/cli',
26+
'@capacitor/ios',
27+
'@capacitor/android',
28+
];
2029
const plugins = [
2130
'@capacitor-plus/action-sheet',
2231
'@capacitor-plus/app',
@@ -43,6 +52,31 @@ const plugins = [
4352
'@capacitor-plus/status-bar',
4453
'@capacitor-plus/text-zoom',
4554
'@capacitor-plus/toast',
55+
'@capacitor/action-sheet',
56+
'@capacitor/app',
57+
'@capacitor/app-launcher',
58+
'@capacitor/browser',
59+
'@capacitor/camera',
60+
'@capacitor/clipboard',
61+
'@capacitor/device',
62+
'@capacitor/dialog',
63+
'@capacitor/filesystem',
64+
'@capacitor/geolocation',
65+
'@capacitor/google-maps',
66+
'@capacitor/haptics',
67+
'@capacitor/keyboard',
68+
'@capacitor/local-notifications',
69+
'@capacitor/motion',
70+
'@capacitor/network',
71+
'@capacitor/preferences',
72+
'@capacitor/push-notifications',
73+
'@capacitor/screen-orientation',
74+
'@capacitor/screen-reader',
75+
'@capacitor/share',
76+
'@capacitor/splash-screen',
77+
'@capacitor/status-bar',
78+
'@capacitor/text-zoom',
79+
'@capacitor/toast',
4680
];
4781
const coreVersion = '^8.0.0';
4882
const pluginVersion = '^8.0.0';
@@ -147,7 +181,10 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
147181
}
148182

149183
// Update iOS Projects
150-
if (allDependencies['@capacitor-plus/ios'] && existsSync(config.ios.platformDirAbs)) {
184+
if (
185+
(allDependencies['@capacitor-plus/ios'] || allDependencies['@capacitor/ios']) &&
186+
existsSync(config.ios.platformDirAbs)
187+
) {
151188
const currentiOSVersion = getMajoriOSVersion(config);
152189
if (parseInt(currentiOSVersion) < parseInt(iOSVersion)) {
153190
// ios template changes
@@ -186,7 +223,10 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
186223
logger.warn('Skipped Running cap sync.');
187224
}
188225

189-
if (allDependencies['@capacitor-plus/android'] && existsSync(config.android.platformDirAbs)) {
226+
if (
227+
(allDependencies['@capacitor-plus/android'] || allDependencies['@capacitor/android']) &&
228+
existsSync(config.android.platformDirAbs)
229+
) {
190230
// AndroidManifest.xml add "density"
191231
await runTask(`Migrating AndroidManifest.xml by adding density to Activity configChanges.`, () => {
192232
return updateAndroidManifest(join(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
@@ -355,6 +395,7 @@ async function installLatestLibs(dependencyManager: string, runInstall: boolean,
355395

356396
if (runInstall) {
357397
rimraf.sync(join(config.app.rootDir, 'node_modules/@capacitor-plus/!(cli)'));
398+
rimraf.sync(join(config.app.rootDir, 'node_modules/@capacitor/!(cli)'));
358399
await runCommand(dependencyManager, ['install']);
359400
if (dependencyManager == 'yarn') {
360401
await runCommand(dependencyManager, ['upgrade']);
@@ -378,6 +419,16 @@ async function writeBreakingChanges() {
378419
'@capacitor-plus/screen-orientation',
379420
'@capacitor-plus/splash-screen',
380421
'@capacitor-plus/status-bar',
422+
'@capacitor/action-sheet',
423+
'@capacitor/barcode-scanner',
424+
'@capacitor/browser',
425+
'@capacitor/camera',
426+
'@capacitor/geolocation',
427+
'@capacitor/google-maps',
428+
'@capacitor/push-notifications',
429+
'@capacitor/screen-orientation',
430+
'@capacitor/splash-screen',
431+
'@capacitor/status-bar',
381432
];
382433
const broken = [];
383434
for (const lib of breaking) {

0 commit comments

Comments
 (0)