Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,36 @@ 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
* copy lockfiles
*/
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',
},
}
Expand Down Expand Up @@ -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)

Expand Down
32 changes: 32 additions & 0 deletions tests/bundler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down