Skip to content

Commit fff1cd6

Browse files
rault-aJulien-R44
authored andcommitted
feat: yarn berry support (#79)
* feat: yarn berry support * fix: add missing yarn berry file to move during build * chore: add tests
1 parent bbee247 commit fff1cd6

File tree

2 files changed

+49
-11
lines changed

2 files changed

+49
-11
lines changed

src/bundler.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,36 @@ import { AssemblerHooks } from './hooks.js'
2020
import type { BundlerOptions } from './types.js'
2121
import { run, parseConfig, copyFiles } from './helpers.js'
2222

23-
type SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'
23+
type SupportedPackageManager = 'npm' | 'yarn' | 'yarn@berry' | 'pnpm' | 'bun'
2424

2525
/**
2626
* List of package managers we support in order to
2727
* copy lockfiles
2828
*/
2929
const SUPPORT_PACKAGE_MANAGERS: {
3030
[K in SupportedPackageManager]: {
31-
lockFile: string
31+
packageManagerFiles: string[]
3232
installCommand: string
3333
}
3434
} = {
35-
npm: {
36-
lockFile: 'package-lock.json',
35+
'npm': {
36+
packageManagerFiles: ['package-lock.json'],
3737
installCommand: 'npm ci --omit="dev"',
3838
},
39-
yarn: {
40-
lockFile: 'yarn.lock',
39+
'yarn': {
40+
packageManagerFiles: ['yarn.lock'],
4141
installCommand: 'yarn install --production',
4242
},
43-
pnpm: {
44-
lockFile: 'pnpm-lock.yaml',
43+
'yarn@berry': {
44+
packageManagerFiles: ['yarn.lock', '.yarn/**/*', '.yarnrc.yml'],
45+
installCommand: 'yarn workspaces focus --production',
46+
},
47+
'pnpm': {
48+
packageManagerFiles: ['pnpm-lock.yaml'],
4549
installCommand: 'pnpm i --prod',
4650
},
47-
bun: {
48-
lockFile: 'bun.lockb',
51+
'bun': {
52+
packageManagerFiles: ['bun.lockb'],
4953
installCommand: 'bun install --production',
5054
},
5155
}
@@ -264,7 +268,9 @@ export class Bundler {
264268
* Step 6: Copy meta files to the build directory
265269
*/
266270
const pkgManager = await this.#getPackageManager(client)
267-
const pkgFiles = pkgManager ? ['package.json', pkgManager.lockFile] : ['package.json']
271+
const pkgFiles = pkgManager
272+
? ['package.json', ...pkgManager.packageManagerFiles]
273+
: ['package.json']
268274
this.#logger.info('copying meta files to the output directory')
269275
await this.#copyMetaFiles(outDir, pkgFiles)
270276

tests/bundler.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,38 @@ test.group('Bundler', () => {
139139
])
140140
})
141141

142+
test('detect yarn@berry and move all its files if not specified', async ({ assert, fs }) => {
143+
await Promise.all([
144+
fs.create(
145+
'tsconfig.json',
146+
JSON.stringify({ compilerOptions: { outDir: 'build', skipLibCheck: true } })
147+
),
148+
fs.create('adonisrc.ts', 'export default {}'),
149+
fs.create('package.json', '{ "packageManager": "[email protected]" }'),
150+
fs.create('yarn.lock', '{}'),
151+
fs.create('.yarnrc.yml', '{}'),
152+
fs.create('.yarn/install-state.gz', '{}'),
153+
])
154+
155+
const bundler = new Bundler(fs.baseUrl, ts, {
156+
metaFiles: [
157+
{
158+
pattern: 'resources/views/**/*.edge',
159+
reloadServer: false,
160+
},
161+
],
162+
})
163+
164+
await bundler.bundle(true)
165+
166+
await Promise.all([
167+
assert.fileExists('./build/package.json'),
168+
assert.fileExists('./build/yarn.lock'),
169+
assert.fileExists('./build/.yarnrc.yml'),
170+
assert.fileExists('./build/.yarn/install-state.gz'),
171+
])
172+
})
173+
142174
test('remove ts-node reference in builded ace.js file', async ({ assert, fs }) => {
143175
await Promise.all([
144176
fs.create('ace.js', 'foo'),

0 commit comments

Comments
 (0)