diff --git a/package-lock.json b/package-lock.json index 81e6639..23ded87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@shoutem/cli", - "version": "0.15.2", - "lockfileVersion": 3, + "version": "0.16.0", + "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@shoutem/cli", - "version": "0.15.2", + "version": "0.16.0", "license": "ISC", "dependencies": { "@babel/cli": "7.24.1", diff --git a/package.json b/package.json index 8468580..7fd244c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@shoutem/cli", - "version": "0.15.2", + "version": "0.16.0", "description": "Command-line tools for Shoutem applications", "repository": { "type": "git", diff --git a/src/clients/default-package-manager.js b/src/clients/default-package-manager.js index 9c58ecc..d801267 100644 --- a/src/clients/default-package-manager.js +++ b/src/clients/default-package-manager.js @@ -13,7 +13,12 @@ export function setDefaultPackageManager(name) { export function getDefaultPackageManager() { try { - return fs.readFileSync(defaultPackageManagerFilePath, 'utf8'); + // Disable bun in favour of npm for the time being + const resolvedManager = fs.readFileSync( + defaultPackageManagerFilePath, + 'utf8', + ); + return resolvedManager === 'bun' ? 'npm' : resolvedManager; } catch (err) { setDefaultPackageManager('npm'); return 'npm'; diff --git a/src/services/packer.js b/src/services/packer.js index 7034635..fa87638 100644 --- a/src/services/packer.js +++ b/src/services/packer.js @@ -26,19 +26,26 @@ function hasPackageJson(dir) { } async function packageManagerPack(dir, destinationDir) { - const resultFilename = path.join(destinationDir, `${path.basename(dir)}.tgz`); - const packageJsonPath = path.join(dir, 'package.json'); + const component = path.basename(dir); + const resultFilename = path.join(destinationDir, `${component}.tgz`); + const isWeb = component === 'web'; + const appDir = isWeb ? dir.replace('web', 'app') : dir; + + const packageJsonPath = path.join(appDir, 'package.json'); const originalFileContent = await fs.readFile(packageJsonPath); const packageJson = await readJsonFile(packageJsonPath); const timestamp = new Date().getTime(); packageJson.version = `${packageJson.version}-build${timestamp}`; + packageJson.dependencies = isWeb + ? packageJson.webDependencies + : packageJson.dependencies; await writeJsonFile(packageJson, packageJsonPath); - const { stdout } = await exec(`${packageManager} pack`, { cwd: dir }); + const { stdout } = await exec(`${packageManager} pack`, { cwd: appDir }); const packageFilename = stdout.replace(/\n$/, ''); - const packagePath = path.join(dir, packageFilename); + const packagePath = path.join(appDir, packageFilename); await mv(packagePath, resultFilename); @@ -104,6 +111,18 @@ function hasExtensionsJson(dir) { return pathExists(path.join(dir, 'extension.json')); } +async function hasWebDependencies(dir) { + const packageJsonPath = path.join(dir, 'app', 'package.json'); + + const packageJson = await readJsonFile(packageJsonPath); + + if (!packageJson.webDependencies) { + return false; + } + + return true; +} + function hasCloudComponent(dir) { return hasPackageJson(path.join(dir, 'cloud')); } @@ -163,6 +182,12 @@ export default async function shoutemPack(dir, options) { components.push('cloud'); } + const hasWeb = await hasWebDependencies(dir); + + if (hasWeb) { + components.push('web'); + } + const packedDirectories = components.map(d => path.join(dir, d)); if (!(await hasExtensionsJson(dir))) { @@ -177,7 +202,15 @@ export default async function shoutemPack(dir, options) { const packageDir = path.join(tmpDir, 'package'); await fs.mkdir(packageDir); - const dirsToPack = await Promise.filter(packedDirectories, hasPackageJson); + const filteredDirsToPack = await Promise.filter( + packedDirectories, + hasPackageJson, + ); + // We still want to pack the web segment even though it uses package.json + // from the app segment + const dirsToPack = hasWeb + ? [...filteredDirsToPack, path.join(dir, 'web')] + : filteredDirsToPack; if (options.nobuild) { console.error('Skipping build step due to --nobuild flag.');