diff --git a/src/bundler.ts b/src/bundler.ts index 0ca7178f..b42cc4f3 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -20,7 +20,7 @@ import { AssemblerHooks } from './hooks.js' import type { BundlerOptions } from './types.js' import { run, parseConfig, copyFiles } from './helpers.js' -type SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun' +type SupportedPackageManager = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'bun' /** * List of package managers we support in order to @@ -28,24 +28,28 @@ type SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun' */ const SUPPORT_PACKAGE_MANAGERS: { [K in SupportedPackageManager]: { - lockFile: string + packageManagerFiles: string[] installCommand: string } } = { - npm: { - lockFile: 'package-lock.json', + 'npm': { + packageManagerFiles: ['package-lock.json'], installCommand: 'npm ci --omit="dev"', }, - yarn: { - lockFile: 'yarn.lock', + 'yarn': { + packageManagerFiles: ['yarn.lock'], installCommand: 'yarn install --production', }, - pnpm: { - lockFile: 'pnpm-lock.yaml', + 'yarn@berry': { + packageManagerFiles: ['yarn.lock', '.yarn/**/*', '.yarnrc.yml'], + installCommand: 'yarn workspaces focus --production', + }, + 'pnpm': { + packageManagerFiles: ['pnpm-lock.yaml'], installCommand: 'pnpm i --prod', }, - bun: { - lockFile: 'bun.lockb', + 'bun': { + packageManagerFiles: ['bun.lockb'], installCommand: 'bun install --production', }, } @@ -264,7 +268,9 @@ export class Bundler { * Step 6: Copy meta files to the build directory */ const pkgManager = await this.#getPackageManager(client) - const pkgFiles = pkgManager ? ['package.json', pkgManager.lockFile] : ['package.json'] + const pkgFiles = pkgManager + ? ['package.json', ...pkgManager.packageManagerFiles] + : ['package.json'] this.#logger.info('copying meta files to the output directory') await this.#copyMetaFiles(outDir, pkgFiles) diff --git a/tests/bundler.spec.ts b/tests/bundler.spec.ts index 87c1cacd..d45dee52 100644 --- a/tests/bundler.spec.ts +++ b/tests/bundler.spec.ts @@ -139,6 +139,38 @@ test.group('Bundler', () => { ]) }) + test('detect yarn@berry and move all its files if not specified', async ({ assert, fs }) => { + await Promise.all([ + fs.create( + 'tsconfig.json', + JSON.stringify({ compilerOptions: { outDir: 'build', skipLibCheck: true } }) + ), + fs.create('adonisrc.ts', 'export default {}'), + fs.create('package.json', '{ "packageManager": "yarn@4.2.1" }'), + fs.create('yarn.lock', '{}'), + fs.create('.yarnrc.yml', '{}'), + fs.create('.yarn/install-state.gz', '{}'), + ]) + + const bundler = new Bundler(fs.baseUrl, ts, { + metaFiles: [ + { + pattern: 'resources/views/**/*.edge', + reloadServer: false, + }, + ], + }) + + await bundler.bundle(true) + + await Promise.all([ + assert.fileExists('./build/package.json'), + assert.fileExists('./build/yarn.lock'), + assert.fileExists('./build/.yarnrc.yml'), + assert.fileExists('./build/.yarn/install-state.gz'), + ]) + }) + test('remove ts-node reference in builded ace.js file', async ({ assert, fs }) => { await Promise.all([ fs.create('ace.js', 'foo'),