diff --git a/package.json b/package.json index e67e19fd..8c40a976 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "scripts": { "pretest": "npm run lint", - "test": "cross-env NODE_DEBUG=chokidar:ts c8 npm run vscode:test", + "test": "cross-env NODE_DEBUG=chokidar:ts c8 npm run quick:test", "lint": "eslint . --ext=.ts", "clean": "del-cli build", "typecheck": "tsc --noEmit", @@ -29,7 +29,7 @@ "sync-labels": "github-label-sync --labels .github/labels.json adonisjs/assembler", "format": "prettier --write .", "prepublishOnly": "npm run build", - "vscode:test": "node --loader=ts-node/esm bin/test.ts" + "quick:test": "node --loader=ts-node/esm bin/test.ts" }, "keywords": [ "adonisjs", @@ -66,7 +66,7 @@ "@adonisjs/env": "^4.2.0-3", "@poppinss/chokidar-ts": "^4.1.0-4", "@poppinss/cliui": "^6.1.1-3", - "cpy": "^10.1.0", + "cpy": "^8.1.2", "execa": "^7.0.0", "get-port": "^7.0.0", "picomatch": "^2.3.1", diff --git a/src/bundler.ts b/src/bundler.ts index a4116e98..30abad1f 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -101,7 +101,7 @@ export class Bundler { */ async #copyFiles(files: string[], outDir: string) { try { - await copyfiles(files, outDir, { cwd: this.#cwdPath }) + await copyfiles(files, outDir, { parents: true, cwd: this.#cwdPath }) } catch (error) { if (!error.message.includes("the file doesn't exist")) { throw error diff --git a/tests/bundler.spec.ts b/tests/bundler.spec.ts new file mode 100644 index 00000000..928b8366 --- /dev/null +++ b/tests/bundler.spec.ts @@ -0,0 +1,44 @@ +import { test } from '@japa/runner' +import { Bundler } from '../index.js' +import ts from 'typescript' + +test.group('Bundler', () => { + test('should copy metafiles to the build directory', async ({ assert, fs }) => { + await Promise.all([ + fs.create( + 'tsconfig.json', + JSON.stringify({ compilerOptions: { outDir: 'build', skipLibCheck: true } }) + ), + fs.create('.adonisrc.json', '{}'), + fs.create('package.json', '{}'), + fs.create('package-lock.json', '{}'), + + fs.create('resources/js/app.ts', ''), + fs.create('resources/views/app.edge', ''), + fs.create('resources/views/foo.edge', ''), + fs.create('resources/views/nested/bar.edge', ''), + fs.create('resources/views/nested/baz.edge', ''), + ]) + + const bundler = new Bundler(fs.baseUrl, ts, { + metaFiles: [ + { + pattern: 'resources/views/**/*.edge', + reloadServer: false, + }, + ], + }) + + await bundler.bundle(true, 'npm') + + await Promise.all([ + assert.fileExists('./build/resources/views/app.edge'), + assert.fileExists('./build/resources/views/foo.edge'), + assert.fileExists('./build/resources/views/nested/bar.edge'), + assert.fileExists('./build/resources/views/nested/baz.edge'), + assert.fileExists('./build/.adonisrc.json'), + assert.fileExists('./build/package.json'), + assert.fileExists('./build/package-lock.json'), + ]) + }) +})