|
8 | 8 | */
|
9 | 9 |
|
10 | 10 | import slash from 'slash'
|
| 11 | +import dedent from 'dedent' |
11 | 12 | import fs from 'node:fs/promises'
|
12 |
| -import { relative } from 'node:path' |
13 | 13 | import type tsStatic from 'typescript'
|
14 | 14 | import { fileURLToPath } from 'node:url'
|
| 15 | +import { join, relative } from 'node:path' |
15 | 16 | import { cliui, type Logger } from '@poppinss/cliui'
|
16 | 17 | import { detectPackageManager } from '@antfu/install-pkg'
|
17 | 18 |
|
@@ -163,6 +164,27 @@ export class Bundler {
|
163 | 164 | return SUPPORT_PACKAGE_MANAGERS[pkgManager as SupportedPackageManager]
|
164 | 165 | }
|
165 | 166 |
|
| 167 | + /** |
| 168 | + * Rewrite the ace file since the original one |
| 169 | + * is importing ts-node which is not installed |
| 170 | + * in a production environment. |
| 171 | + */ |
| 172 | + async #createAceFile(outDir: string) { |
| 173 | + const aceFileLocation = join(outDir, 'ace.js') |
| 174 | + const aceFileContent = dedent(/* JavaScript */ ` |
| 175 | + /** |
| 176 | + * This file is auto-generated by the build process. |
| 177 | + * If you had any custom code inside this file, then |
| 178 | + * instead write it inside the "bin/console.js" file. |
| 179 | + */ |
| 180 | +
|
| 181 | + await import('./bin/console.js') |
| 182 | + `) |
| 183 | + |
| 184 | + await fs.writeFile(aceFileLocation, aceFileContent) |
| 185 | + this.#logger.info('rewrited ace file', { suffix: this.#getRelativeName(aceFileLocation) }) |
| 186 | + } |
| 187 | + |
166 | 188 | /**
|
167 | 189 | * Set a custom CLI UI logger
|
168 | 190 | */
|
@@ -202,7 +224,7 @@ export class Bundler {
|
202 | 224 | */
|
203 | 225 | this.#logger.info('compiling typescript source', { suffix: 'tsc' })
|
204 | 226 | const buildCompleted = await this.#runTsc(outDir)
|
205 |
| - await copyFiles(['ace.js'], this.#cwdPath, outDir) |
| 227 | + await this.#createAceFile(outDir) |
206 | 228 |
|
207 | 229 | /**
|
208 | 230 | * Remove incomplete build directory when tsc build
|
|
0 commit comments