Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bolt install production #280

Open
mindesik opened this issue Sep 21, 2020 · 1 comment
Open

Bolt install production #280

mindesik opened this issue Sep 21, 2020 · 1 comment

Comments

@mindesik
Copy link

mindesik commented Sep 21, 2020

Bolt is not installing --production only packages.

Title Description
Version 0.24.5
Type Request
node 14.11.0
Operating System macOS
Short Description It should run yarn install --production but instead all packages being installed (including devDependencies).
@steve-taylor
Copy link

steve-taylor commented Oct 23, 2023

Run this and then bolt. It'll do what you expect, but be warned: It will modify your package.json files.

import {getPackages} from '@manypkg/get-packages'

import {writeFile} from 'fs/promises'
import path from 'path'

// remove-dev-deps.js - Removes dev dependencies from a bolt monorepo

const {
    packages,
    rootPackage: {packageJson: rootPackageJson}
} = await getPackages(process.cwd())

// Get all dependencies used by sub-packages.
const usedPackages = new Set(
    packages
        .reduce(
            (acc, {packageJson: {dependencies = {}}}) => [
                ...acc,
                ...Object.keys(dependencies)
            ],
            []
        )
        .sort()
)

// Remove packages from the root package.json that aren't any sub-packages' dependencies
rootPackageJson.dependencies = Object.fromEntries(
    Object
        .entries(rootPackageJson.dependencies)
        .filter(([name]) => usedPackages.has(name))
)
await writeFile(
    'package.json',
    JSON.stringify(rootPackageJson, null, 2) + '\n'
)

// Remove devDependencies from all sub-packages' package.json
await Promise.all(
    packages.map(({
        relativeDir,
        packageJson: {
            devDependencies,
            ...packageJson
        }
    }) => writeFile(
        path.join(relativeDir, 'package.json'),
        JSON.stringify(packageJson, null, 2) + '\n'
    ))
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants