{"library":"monopack-cli","title":"Monopack CLI","description":"Monopack CLI is a JavaScript bundler designed for Node.js monorepo applications, aiming to create static, deterministic deliverables. It bundles all imported monorepo sources into a single `main.js` file, alongside a pruned `package.json`, `yarn.lock`, and `node_modules` containing only the truly used third-party dependencies. Originally conceived to streamline continuous integration and deployment for serverless functions, micro-services, and monolithic servers within a monorepo structure, its last known stable release is 0.2.6, published in September 2018. Due to its age and lack of recent updates, the project appears to be abandoned, and its compatibility with modern Node.js and Yarn versions is uncertain.","language":"javascript","status":"abandoned","last_verified":"Tue Apr 21","install":{"commands":["npm install monopack-cli"],"cli":{"name":"monopack","version":null}},"imports":["monopack <command>","yarn run monopack <command>","./node_modules/.bin/monopack <command>"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { execSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\n\n// Create a temporary directory for the mock monorepo\nconst tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'monopack-demo-'));\nconst appPackageDir = path.join(tempDir, 'packages', 'my-app');\nconst sharedLibDir = path.join(tempDir, 'packages', 'shared-lib');\n\nconsole.log(`Setting up mock monorepo in: ${tempDir}`);\n\n// Create application package structure\nfs.mkdirSync(path.join(appPackageDir, 'src'), { recursive: true });\nfs.writeFileSync(path.join(appPackageDir, 'package.json'), JSON.stringify({\n  name: 'my-app',\n  version: '1.0.0',\n  main: 'src/main.js',\n  dependencies: {\n    'lodash': '^4.17.21' // Third-party dependency\n  }\n}, null, 2));\nfs.writeFileSync(path.join(appPackageDir, 'src', 'main.js'), `\n  const _ = require('lodash');\n  const { getMessage } = require('shared-lib'); // Monorepo dependency\n  console.log(_.toUpper(getMessage('Monopack Demo')));\n`);\n\n// Create shared library package structure\nfs.mkdirSync(sharedLibDir, { recursive: true });\nfs.writeFileSync(path.join(sharedLibDir, 'package.json'), JSON.stringify({\n  name: 'shared-lib',\n  version: '1.0.0',\n  main: 'index.js'\n}, null, 2));\nfs.writeFileSync(path.join(sharedLibDir, 'index.js'), `\n  exports.getMessage = (topic) => 'Hello from shared-lib, ' + topic + '!';\n`);\n\n// Simulate monorepo setup with yarn and install local monopack\ntry {\n  console.log('\\nInstalling dependencies and linking shared-lib...');\n  execSync(`cd ${appPackageDir} && yarn add file:${sharedLibDir}`, { stdio: 'inherit' });\n  execSync(`cd ${appPackageDir} && yarn install`, { stdio: 'inherit' });\n  execSync(`cd ${appPackageDir} && yarn add -D monopack-cli@0.2.6`, { stdio: 'inherit' });\n\n  console.log('\\n--- Running monopack build ---');\n  const outputDir = path.join(appPackageDir, 'dist');\n  // Execute monopack locally using its path in node_modules\n  execSync(`cd ${appPackageDir} && ./node_modules/.bin/monopack build src/main.js --out-dir ${outputDir}`, { stdio: 'inherit' });\n\n  console.log(`\\nBuild successful. Output directory contents for 'my-app': ${outputDir}`);\n  console.log(fs.readdirSync(outputDir));\n\n  console.log('\\n--- Running the bundled application ---');\n  // To run the bundled application, it usually requires its own node_modules\n  // which monopack should have generated in the output directory.\n  execSync(`cd ${outputDir} && node main.js`, { stdio: 'inherit' });\n\n} catch (error: any) {\n  console.error('\\nAn error occurred during the quickstart execution:', error.message);\n  if (error.stdout) console.error('stdout:', error.stdout.toString());\n  if (error.stderr) console.error('stderr:', error.stderr.toString());\n} finally {\n  console.log(`\\nCleaning up temporary directory: ${tempDir}`);\n  fs.rmSync(tempDir, { recursive: true, force: true });\n}\n","lang":"typescript","description":"This example demonstrates how to set up a minimal mock Node.js monorepo project and use `monopack build` to bundle an application, including a locally linked shared library and a third-party dependency, into a static deliverable. It then executes the resulting bundle.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}