@adonisjs/assembler 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -390,6 +390,45 @@ export const plugins: Config['plugins'] = [
390
390
  ]
391
391
  ```
392
392
 
393
+ ### addVitePlugin
394
+
395
+ Register a Vite plugin to the `vite.config.ts` file.
396
+
397
+ > [!IMPORTANT]
398
+ > This codemod expects the `vite.config.ts` file to exist and must have the `export default defineConfig` function call.
399
+
400
+ ```ts
401
+ const transformer = new CodeTransformer(appRoot)
402
+ const imports = [
403
+ {
404
+ isNamed: false,
405
+ module: '@vitejs/plugin-vue',
406
+ identifier: 'vue'
407
+ },
408
+ ]
409
+ const pluginUsage = 'vue({ jsx: true })'
410
+
411
+ try {
412
+ await transformer.addVitePlugin(pluginUsage, imports)
413
+ } catch (error) {
414
+ console.error('Unable to register vite plugin')
415
+ console.error(error)
416
+ }
417
+ ```
418
+
419
+ Output
420
+
421
+ ```ts
422
+ import { defineConfig } from 'vite'
423
+ import vue from '@vitejs/plugin-vue'
424
+
425
+ export default defineConfig({
426
+ plugins: [
427
+ vue({ jsx: true })
428
+ ]
429
+ })
430
+ ```
431
+
393
432
  ### addPolicies
394
433
  Register AdonisJS bouncer policies to the list of `policies` object exported from the `app/policies/main.ts` file.
395
434
 
package/build/index.js CHANGED
@@ -1,11 +1,83 @@
1
1
  // src/bundler.ts
2
2
  import slash from "slash";
3
+ import dedent from "dedent";
3
4
  import fs from "node:fs/promises";
4
- import { relative as relative2 } from "node:path";
5
5
  import { fileURLToPath as fileURLToPath2 } from "node:url";
6
+ import { join as join2, relative as relative2 } from "node:path";
6
7
  import { cliui } from "@poppinss/cliui";
7
8
  import { detectPackageManager } from "@antfu/install-pkg";
8
9
 
10
+ // src/hooks.ts
11
+ import { RuntimeException } from "@poppinss/utils";
12
+ import Hooks from "@poppinss/hooks";
13
+ var AssemblerHooks = class {
14
+ #config;
15
+ #hooks = new Hooks();
16
+ constructor(config) {
17
+ this.#config = config;
18
+ }
19
+ /**
20
+ * Resolve the hook by importing the file and returning the default export
21
+ */
22
+ async #resolveHookNode(node) {
23
+ const exports = await node();
24
+ if (!exports.default) {
25
+ throw new RuntimeException("Assembler hook must be defined using the default export");
26
+ }
27
+ return exports.default;
28
+ }
29
+ /**
30
+ * Resolve hooks needed for dev-time and register them to the Hooks instance
31
+ */
32
+ async registerDevServerHooks() {
33
+ await Promise.all([
34
+ this.#config?.onDevServerStarted?.map(
35
+ async (node) => this.#hooks.add("onDevServerStarted", await this.#resolveHookNode(node))
36
+ ),
37
+ this.#config?.onSourceFileChanged?.map(
38
+ async (node) => this.#hooks.add("onSourceFileChanged", await this.#resolveHookNode(node))
39
+ )
40
+ ]);
41
+ }
42
+ /**
43
+ * Resolve hooks needed for build-time and register them to the Hooks instance
44
+ */
45
+ async registerBuildHooks() {
46
+ await Promise.all([
47
+ this.#config?.onBuildStarting?.map(
48
+ async (node) => this.#hooks.add("onBuildStarting", await this.#resolveHookNode(node))
49
+ ),
50
+ this.#config?.onBuildCompleted?.map(
51
+ async (node) => this.#hooks.add("onBuildCompleted", await this.#resolveHookNode(node))
52
+ )
53
+ ]);
54
+ }
55
+ /**
56
+ * When the dev server is started
57
+ */
58
+ async onDevServerStarted(...args) {
59
+ await this.#hooks.runner("onDevServerStarted").run(...args);
60
+ }
61
+ /**
62
+ * When a source file changes
63
+ */
64
+ async onSourceFileChanged(...args) {
65
+ await this.#hooks.runner("onSourceFileChanged").run(...args);
66
+ }
67
+ /**
68
+ * When the build process is starting
69
+ */
70
+ async onBuildStarting(...args) {
71
+ await this.#hooks.runner("onBuildStarting").run(...args);
72
+ }
73
+ /**
74
+ * When the build process is completed
75
+ */
76
+ async onBuildCompleted(...args) {
77
+ await this.#hooks.runner("onBuildCompleted").run(...args);
78
+ }
79
+ };
80
+
9
81
  // src/helpers.ts
10
82
  import { isJunk } from "junk";
11
83
  import fastGlob from "fast-glob";
@@ -160,6 +232,7 @@ var Bundler = class {
160
232
  #cwdPath;
161
233
  #ts;
162
234
  #logger = ui.logger;
235
+ #hooks;
163
236
  #options;
164
237
  /**
165
238
  * Getting reference to colors library from logger
@@ -172,6 +245,7 @@ var Bundler = class {
172
245
  this.#cwdPath = fileURLToPath2(this.#cwd);
173
246
  this.#ts = ts;
174
247
  this.#options = options;
248
+ this.#hooks = new AssemblerHooks(options.hooks);
175
249
  }
176
250
  /**
177
251
  * Returns the relative unix path for an absolute
@@ -246,6 +320,28 @@ var Bundler = class {
246
320
  }
247
321
  return SUPPORT_PACKAGE_MANAGERS[pkgManager];
248
322
  }
323
+ /**
324
+ * Rewrite the ace file since the original one
325
+ * is importing ts-node which is not installed
326
+ * in a production environment.
327
+ */
328
+ async #createAceFile(outDir) {
329
+ const aceFileLocation = join2(outDir, "ace.js");
330
+ const aceFileContent = dedent(
331
+ /* JavaScript */
332
+ `
333
+ /**
334
+ * This file is auto-generated by the build process.
335
+ * If you had any custom code inside this file, then
336
+ * instead write it inside the "bin/console.js" file.
337
+ */
338
+
339
+ await import('./bin/console.js')
340
+ `
341
+ );
342
+ await fs.writeFile(aceFileLocation, aceFileContent);
343
+ this.#logger.info("rewrited ace file", { suffix: this.#getRelativeName(aceFileLocation) });
344
+ }
249
345
  /**
250
346
  * Set a custom CLI UI logger
251
347
  */
@@ -257,6 +353,7 @@ var Bundler = class {
257
353
  * Bundles the application to be run in production
258
354
  */
259
355
  async bundle(stopOnError = true, client) {
356
+ await this.#hooks.registerBuildHooks();
260
357
  const config = parseConfig(this.#cwd, this.#ts);
261
358
  if (!config) {
262
359
  return false;
@@ -267,9 +364,10 @@ var Bundler = class {
267
364
  if (!await this.#buildAssets()) {
268
365
  return false;
269
366
  }
367
+ await this.#hooks.onBuildStarting({ colors: ui.colors, logger: this.#logger });
270
368
  this.#logger.info("compiling typescript source", { suffix: "tsc" });
271
369
  const buildCompleted = await this.#runTsc(outDir);
272
- await copyFiles(["ace.js"], this.#cwdPath, outDir);
370
+ await this.#createAceFile(outDir);
273
371
  if (!buildCompleted && stopOnError) {
274
372
  await this.#cleanupBuildDirectory(outDir);
275
373
  const instructions = ui.sticker().fullScreen().drawBorder((borderChar, colors) => colors.red(borderChar));
@@ -290,6 +388,7 @@ var Bundler = class {
290
388
  await this.#copyMetaFiles(outDir, pkgFiles);
291
389
  this.#logger.success("build completed");
292
390
  this.#logger.log("");
391
+ await this.#hooks.onBuildCompleted({ colors: ui.colors, logger: this.#logger });
293
392
  ui.instructions().useRenderer(this.#logger.getRenderer()).heading("Run the following commands to start the server in production").add(this.#colors.cyan(`cd ${this.#getRelativeName(outDir)}`)).add(
294
393
  this.#colors.cyan(
295
394
  pkgManager ? pkgManager.installCommand : "Install production dependencies"
@@ -466,6 +565,10 @@ var DevServer = class {
466
565
  * Reference to the assets server
467
566
  */
468
567
  #assetsServer;
568
+ /**
569
+ * Hooks to execute custom actions during the dev server lifecycle
570
+ */
571
+ #hooks;
469
572
  /**
470
573
  * Getting reference to colors library from logger
471
574
  */
@@ -475,6 +578,7 @@ var DevServer = class {
475
578
  constructor(cwd, options) {
476
579
  this.#cwd = cwd;
477
580
  this.#options = options;
581
+ this.#hooks = new AssemblerHooks(options.hooks);
478
582
  this.#isMetaFileWithReloadsEnabled = picomatch(
479
583
  (this.#options.metaFiles || []).filter(({ reloadServer }) => reloadServer === true).map(({ pattern }) => pattern)
480
584
  );
@@ -506,7 +610,7 @@ var DevServer = class {
506
610
  nodeArgs: this.#options.nodeArgs,
507
611
  scriptArgs: this.#options.scriptArgs
508
612
  });
509
- this.#httpServer.on("message", (message) => {
613
+ this.#httpServer.on("message", async (message) => {
510
614
  if (this.#isAdonisJSReadyMessage(message)) {
511
615
  const host = message.host === "0.0.0.0" ? "127.0.0.1" : message.host;
512
616
  const displayMessage = ui3.sticker().useColors(this.#colors).useRenderer(this.#logger.getRenderer()).add(`Server address: ${this.#colors.cyan(`http://${host}:${message.port}`)}`).add(
@@ -518,6 +622,7 @@ var DevServer = class {
518
622
  displayMessage.add(`Ready in: ${this.#colors.cyan(prettyHrtime(message.duration))}`);
519
623
  }
520
624
  displayMessage.render();
625
+ await this.#hooks.onDevServerStarted({ colors: ui3.colors, logger: this.#logger });
521
626
  }
522
627
  });
523
628
  this.#httpServer.then((result) => {
@@ -582,6 +687,7 @@ var DevServer = class {
582
687
  * Handles TypeScript source file change
583
688
  */
584
689
  #handleSourceFileChange(action, port, relativePath) {
690
+ void this.#hooks.onSourceFileChanged({ colors: ui3.colors, logger: this.#logger }, relativePath);
585
691
  this.#clearScreen();
586
692
  this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
587
693
  this.#restartHTTPServer(port);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bundler.ts","../src/helpers.ts","../src/debug.ts","../src/dev_server.ts","../src/assets_dev_server.ts","../src/test_runner.ts"],"sourcesContent":["/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport slash from 'slash'\nimport fs from 'node:fs/promises'\nimport { relative } from 'node:path'\nimport type tsStatic from 'typescript'\nimport { fileURLToPath } from 'node:url'\nimport { cliui, type Logger } from '@poppinss/cliui'\nimport { detectPackageManager } from '@antfu/install-pkg'\n\nimport type { BundlerOptions } from './types.js'\nimport { run, parseConfig, copyFiles } from './helpers.js'\n\ntype SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'\n\n/**\n * List of package managers we support in order to\n * copy lockfiles\n */\nconst SUPPORT_PACKAGE_MANAGERS: {\n [K in SupportedPackageManager]: {\n lockFile: string\n installCommand: string\n }\n} = {\n npm: {\n lockFile: 'package-lock.json',\n installCommand: 'npm ci --omit=\"dev\"',\n },\n yarn: {\n lockFile: 'yarn.lock',\n installCommand: 'yarn install --production',\n },\n pnpm: {\n lockFile: 'pnpm-lock.yaml',\n installCommand: 'pnpm i --prod',\n },\n bun: {\n lockFile: 'bun.lockb',\n installCommand: 'bun install --production',\n },\n}\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * The bundler class exposes the API to build an AdonisJS project.\n */\nexport class Bundler {\n #cwd: URL\n #cwdPath: string\n #ts: typeof tsStatic\n #logger = ui.logger\n #options: BundlerOptions\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, ts: typeof tsStatic, options: BundlerOptions) {\n this.#cwd = cwd\n this.#cwdPath = fileURLToPath(this.#cwd)\n this.#ts = ts\n this.#options = options\n }\n\n /**\n * Returns the relative unix path for an absolute\n * file path\n */\n #getRelativeName(filePath: string) {\n return slash(relative(this.#cwdPath, filePath))\n }\n\n /**\n * Cleans up the build directory\n */\n async #cleanupBuildDirectory(outDir: string) {\n await fs.rm(outDir, { recursive: true, force: true, maxRetries: 5 })\n }\n\n /**\n * Runs assets bundler command to build assets\n */\n async #buildAssets(): Promise<boolean> {\n const assetsBundler = this.#options.assets\n if (!assetsBundler?.enabled) {\n return true\n }\n\n try {\n this.#logger.info('compiling frontend assets', { suffix: assetsBundler.cmd })\n await run(this.#cwd, {\n stdio: 'inherit',\n script: assetsBundler.cmd,\n scriptArgs: assetsBundler.args,\n })\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Runs tsc command to build the source.\n */\n async #runTsc(outDir: string): Promise<boolean> {\n try {\n await run(this.#cwd, {\n stdio: 'inherit',\n script: 'tsc',\n scriptArgs: ['--outDir', outDir],\n })\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Copy meta files to the output directory\n */\n async #copyMetaFiles(outDir: string, additionalFilesToCopy: string[]) {\n const metaFiles = (this.#options.metaFiles || [])\n .map((file) => file.pattern)\n .concat(additionalFilesToCopy)\n\n await copyFiles(metaFiles, this.#cwdPath, outDir)\n }\n\n /**\n * Detect the package manager used by the project\n * and return the lockfile name and install command\n * related to it.\n */\n async #getPackageManager(client?: SupportedPackageManager) {\n let pkgManager: string | null | undefined = client\n\n if (!pkgManager) {\n pkgManager = await detectPackageManager(this.#cwdPath)\n }\n if (!pkgManager) {\n pkgManager = 'npm'\n }\n\n if (!Object.keys(SUPPORT_PACKAGE_MANAGERS).includes(pkgManager)) {\n return null\n }\n\n return SUPPORT_PACKAGE_MANAGERS[pkgManager as SupportedPackageManager]\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n return this\n }\n\n /**\n * Bundles the application to be run in production\n */\n async bundle(stopOnError: boolean = true, client?: SupportedPackageManager): Promise<boolean> {\n /**\n * Step 1: Parse config file to get the build output directory\n */\n const config = parseConfig(this.#cwd, this.#ts)\n if (!config) {\n return false\n }\n\n /**\n * Step 2: Cleanup existing build directory (if any)\n */\n const outDir = config.options.outDir || fileURLToPath(new URL('build/', this.#cwd))\n this.#logger.info('cleaning up output directory', { suffix: this.#getRelativeName(outDir) })\n await this.#cleanupBuildDirectory(outDir)\n\n /**\n * Step 3: Build frontend assets\n */\n if (!(await this.#buildAssets())) {\n return false\n }\n\n /**\n * Step 4: Build typescript source code\n */\n this.#logger.info('compiling typescript source', { suffix: 'tsc' })\n const buildCompleted = await this.#runTsc(outDir)\n await copyFiles(['ace.js'], this.#cwdPath, outDir)\n\n /**\n * Remove incomplete build directory when tsc build\n * failed and stopOnError is set to true.\n */\n if (!buildCompleted && stopOnError) {\n await this.#cleanupBuildDirectory(outDir)\n const instructions = ui\n .sticker()\n .fullScreen()\n .drawBorder((borderChar, colors) => colors.red(borderChar))\n\n instructions.add(\n this.#colors.red('Cannot complete the build process as there are TypeScript errors.')\n )\n instructions.add(\n this.#colors.red(\n 'Use \"--ignore-ts-errors\" flag to ignore TypeScript errors and continue the build.'\n )\n )\n\n this.#logger.logError(instructions.prepare())\n return false\n }\n\n /**\n * Step 5: Copy meta files to the build directory\n */\n const pkgManager = await this.#getPackageManager(client)\n const pkgFiles = pkgManager ? ['package.json', pkgManager.lockFile] : ['package.json']\n this.#logger.info('copying meta files to the output directory')\n await this.#copyMetaFiles(outDir, pkgFiles)\n\n this.#logger.success('build completed')\n this.#logger.log('')\n\n /**\n * Next steps\n */\n ui.instructions()\n .useRenderer(this.#logger.getRenderer())\n .heading('Run the following commands to start the server in production')\n .add(this.#colors.cyan(`cd ${this.#getRelativeName(outDir)}`))\n .add(\n this.#colors.cyan(\n pkgManager ? pkgManager.installCommand : 'Install production dependencies'\n )\n )\n .add(this.#colors.cyan('node bin/server.js'))\n .render()\n\n return true\n }\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { isJunk } from 'junk'\nimport fastGlob from 'fast-glob'\nimport getRandomPort from 'get-port'\nimport { existsSync } from 'node:fs'\nimport type tsStatic from 'typescript'\nimport { fileURLToPath } from 'node:url'\nimport { execaNode, execa } from 'execa'\nimport { copyFile, mkdir } from 'node:fs/promises'\nimport { EnvLoader, EnvParser } from '@adonisjs/env'\nimport { ConfigParser, Watcher } from '@poppinss/chokidar-ts'\nimport { basename, dirname, isAbsolute, join, relative } from 'node:path'\n\nimport type { RunOptions, WatchOptions } from './types.js'\nimport debug from './debug.js'\n\n/**\n * Default set of args to pass in order to run TypeScript\n * source. Used by \"run\" and \"runNode\" scripts\n */\nconst DEFAULT_NODE_ARGS = [\n // Use ts-node/esm loader. The project must install it\n '--loader=ts-node/esm',\n // Enable source maps, since TSNode source maps are broken\n '--enable-source-maps',\n]\n\n/**\n * Disable experimental warnings, since the ts-node loader hook\n * uses an expiremental feature. We are waiting for them to\n * cut a new release and support the newer `--import` flag\n * instead\n */\nif (process.allowedNodeEnvironmentFlags.has('--disable-warning')) {\n // supported in node>=v21.13.0\n DEFAULT_NODE_ARGS.push('--disable-warning=ExperimentalWarning')\n} else {\n DEFAULT_NODE_ARGS.push('--no-warnings')\n}\n\n/**\n * Parses tsconfig.json and prints errors using typescript compiler\n * host\n */\nexport function parseConfig(cwd: string | URL, ts: typeof tsStatic) {\n const { config, error } = new ConfigParser(cwd, 'tsconfig.json', ts).parse()\n if (error) {\n const compilerHost = ts.createCompilerHost({})\n console.log(ts.formatDiagnosticsWithColorAndContext([error], compilerHost))\n return\n }\n\n if (config!.errors.length) {\n const compilerHost = ts.createCompilerHost({})\n console.log(ts.formatDiagnosticsWithColorAndContext(config!.errors, compilerHost))\n return\n }\n\n return config\n}\n\n/**\n * Runs a Node.js script as a child process and inherits the stdio streams\n */\nexport function runNode(cwd: string | URL, options: RunOptions) {\n const childProcess = execaNode(options.script, options.scriptArgs, {\n nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),\n preferLocal: true,\n windowsHide: false,\n localDir: cwd,\n cwd,\n buffer: false,\n stdio: options.stdio || 'inherit',\n env: {\n ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),\n ...options.env,\n },\n })\n\n return childProcess\n}\n\n/**\n * Runs a script as a child process and inherits the stdio streams\n */\nexport function run(cwd: string | URL, options: Omit<RunOptions, 'nodeArgs'>) {\n const childProcess = execa(options.script, options.scriptArgs, {\n preferLocal: true,\n windowsHide: false,\n localDir: cwd,\n cwd,\n buffer: false,\n stdio: options.stdio || 'inherit',\n env: {\n ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),\n ...options.env,\n },\n })\n\n return childProcess\n}\n\n/**\n * Watches the file system using tsconfig file\n */\nexport function watch(cwd: string | URL, ts: typeof tsStatic, options: WatchOptions) {\n const config = parseConfig(cwd, ts)\n if (!config) {\n return\n }\n\n const watcher = new Watcher(typeof cwd === 'string' ? cwd : fileURLToPath(cwd), config!)\n const chokidar = watcher.watch(['.'], { usePolling: options.poll })\n return { watcher, chokidar }\n}\n\n/**\n * Check if file is an .env file\n */\nexport function isDotEnvFile(filePath: string) {\n if (filePath === '.env') {\n return true\n }\n\n return filePath.includes('.env.')\n}\n\n/**\n * Returns the port to use after inspect the dot-env files inside\n * a given directory.\n *\n * A random port is used when the specified port is in use. Following\n * is the logic for finding a specified port.\n *\n * - The \"process.env.PORT\" value is used if exists.\n * - The dot-env files are loaded using the \"EnvLoader\" and the PORT\n * value is used by iterating over all the loaded files. The\n * iteration stops after first find.\n */\nexport async function getPort(cwd: URL): Promise<number> {\n /**\n * Use existing port if exists\n */\n if (process.env.PORT) {\n return getRandomPort({ port: Number(process.env.PORT) })\n }\n\n /**\n * Loop over files and use the port from their contents. Stops\n * after first match\n */\n const files = await new EnvLoader(cwd).load()\n for (let file of files) {\n const envVariables = new EnvParser(file.contents).parse()\n if (envVariables.PORT) {\n return getRandomPort({ port: Number(envVariables.PORT) })\n }\n }\n\n /**\n * Use 3333 as the port\n */\n return getRandomPort({ port: 3333 })\n}\n\n/**\n * Helper function to copy files from relative paths or glob\n * patterns\n */\nexport async function copyFiles(files: string[], cwd: string, outDir: string) {\n /**\n * Looping over files and create a new collection with paths\n * and glob patterns\n */\n const { paths, patterns } = files.reduce<{ patterns: string[]; paths: string[] }>(\n (result, file) => {\n /**\n * If file is a glob pattern, then push it to patterns\n */\n if (fastGlob.isDynamicPattern(file)) {\n result.patterns.push(file)\n return result\n }\n\n /**\n * Otherwise, check if file exists and push it to paths to copy\n */\n if (existsSync(join(cwd, file))) {\n result.paths.push(file)\n }\n\n return result\n },\n { patterns: [], paths: [] }\n )\n\n debug('copyFiles inputs: %O, paths: %O, patterns: %O', files, paths, patterns)\n\n /**\n * Getting list of relative paths from glob patterns\n */\n const filePaths = paths.concat(await fastGlob(patterns, { cwd, dot: true })).filter((file) => {\n return !isJunk(basename(file))\n })\n\n /**\n * Finally copy files to the destination by keeping the same\n * directory structure and ignoring junk files\n */\n debug('copying files %O to destination \"%s\"', filePaths, outDir)\n const copyPromises = filePaths.map(async (file) => {\n const src = isAbsolute(file) ? file : join(cwd, file)\n const dest = join(outDir, relative(cwd, src))\n\n await mkdir(dirname(dest), { recursive: true })\n return copyFile(src, dest)\n })\n\n return await Promise.all(copyPromises)\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:assembler')\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport picomatch from 'picomatch'\nimport type tsStatic from 'typescript'\nimport prettyHrtime from 'pretty-hrtime'\nimport { type ExecaChildProcess } from 'execa'\nimport { cliui, type Logger } from '@poppinss/cliui'\nimport type { Watcher } from '@poppinss/chokidar-ts'\n\nimport type { DevServerOptions } from './types.js'\nimport { AssetsDevServer } from './assets_dev_server.js'\nimport { getPort, isDotEnvFile, runNode, watch } from './helpers.js'\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * Exposes the API to start the development. Optionally, the watch API can be\n * used to watch for file changes and restart the development server.\n *\n * The Dev server performs the following actions\n *\n * - Assigns a random PORT, when PORT inside .env file is in use.\n * - Uses tsconfig.json file to collect a list of files to watch.\n * - Uses metaFiles from adonisrc.ts file to collect a list of files to watch.\n * - Restart HTTP server on every file change.\n */\nexport class DevServer {\n #cwd: URL\n #logger = ui.logger\n #options: DevServerOptions\n\n /**\n * Flag to know if the dev server is running in watch\n * mode\n */\n #isWatching: boolean = false\n\n /**\n * Script file to start the development server\n */\n #scriptFile: string = 'bin/server.js'\n\n /**\n * Picomatch matcher function to know if a file path is a\n * meta file with reloadServer option enabled\n */\n #isMetaFileWithReloadsEnabled: picomatch.Matcher\n\n /**\n * Picomatch matcher function to know if a file path is a\n * meta file with reloadServer option disabled\n */\n #isMetaFileWithReloadsDisabled: picomatch.Matcher\n\n /**\n * External listeners that are invoked when child process\n * gets an error or closes\n */\n #onError?: (error: any) => any\n #onClose?: (exitCode: number) => any\n\n /**\n * Reference to the child process\n */\n #httpServer?: ExecaChildProcess<string>\n\n /**\n * Reference to the watcher\n */\n #watcher?: ReturnType<Watcher['watch']>\n\n /**\n * Reference to the assets server\n */\n #assetsServer?: AssetsDevServer\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, options: DevServerOptions) {\n this.#cwd = cwd\n this.#options = options\n\n this.#isMetaFileWithReloadsEnabled = picomatch(\n (this.#options.metaFiles || [])\n .filter(({ reloadServer }) => reloadServer === true)\n .map(({ pattern }) => pattern)\n )\n\n this.#isMetaFileWithReloadsDisabled = picomatch(\n (this.#options.metaFiles || [])\n .filter(({ reloadServer }) => reloadServer !== true)\n .map(({ pattern }) => pattern)\n )\n }\n\n /**\n * Inspect if child process message is from AdonisJS HTTP server\n */\n #isAdonisJSReadyMessage(message: unknown): message is {\n isAdonisJS: true\n environment: 'web'\n port: number\n host: string\n duration?: [number, number]\n } {\n return (\n message !== null &&\n typeof message === 'object' &&\n 'isAdonisJS' in message &&\n 'environment' in message &&\n message.environment === 'web'\n )\n }\n\n /**\n * Conditionally clear the terminal screen\n */\n #clearScreen() {\n if (this.#options.clearScreen) {\n process.stdout.write('\\u001Bc')\n }\n }\n\n /**\n * Starts the HTTP server\n */\n #startHTTPServer(port: string, mode: 'blocking' | 'nonblocking') {\n this.#httpServer = runNode(this.#cwd, {\n script: this.#scriptFile,\n env: { PORT: port, ...this.#options.env },\n nodeArgs: this.#options.nodeArgs,\n scriptArgs: this.#options.scriptArgs,\n })\n\n this.#httpServer.on('message', (message) => {\n if (this.#isAdonisJSReadyMessage(message)) {\n const host = message.host === '0.0.0.0' ? '127.0.0.1' : message.host\n\n const displayMessage = ui\n .sticker()\n .useColors(this.#colors)\n .useRenderer(this.#logger.getRenderer())\n .add(`Server address: ${this.#colors.cyan(`http://${host}:${message.port}`)}`)\n .add(\n `File system watcher: ${this.#colors.cyan(\n `${this.#isWatching ? 'enabled' : 'disabled'}`\n )}`\n )\n\n if (message.duration) {\n displayMessage.add(`Ready in: ${this.#colors.cyan(prettyHrtime(message.duration))}`)\n }\n\n displayMessage.render()\n }\n })\n\n this.#httpServer\n .then((result) => {\n if (mode === 'nonblocking') {\n this.#onClose?.(result.exitCode)\n this.#watcher?.close()\n this.#assetsServer?.stop()\n } else {\n this.#logger.info('Underlying HTTP server closed. Still watching for changes')\n }\n })\n .catch((error) => {\n if (mode === 'nonblocking') {\n this.#onError?.(error)\n this.#watcher?.close()\n this.#assetsServer?.stop()\n } else {\n this.#logger.info('Underlying HTTP server died. Still watching for changes')\n }\n })\n }\n\n /**\n * Starts the assets server\n */\n #startAssetsServer() {\n this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets)\n this.#assetsServer.setLogger(this.#logger)\n this.#assetsServer.start()\n }\n\n /**\n * Restarts the HTTP server in the watch mode. Do not call this\n * method when not in watch mode\n */\n #restartHTTPServer(port: string) {\n if (this.#httpServer) {\n this.#httpServer.removeAllListeners()\n this.#httpServer.kill('SIGKILL')\n }\n\n this.#startHTTPServer(port, 'blocking')\n }\n\n /**\n * Handles a non TypeScript file change\n */\n #handleFileChange(action: string, port: string, relativePath: string) {\n if (isDotEnvFile(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#restartHTTPServer(port)\n return\n }\n\n if (this.#isMetaFileWithReloadsEnabled(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#restartHTTPServer(port)\n return\n }\n\n if (this.#isMetaFileWithReloadsDisabled(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n }\n }\n\n /**\n * Handles TypeScript source file change\n */\n #handleSourceFileChange(action: string, port: string, relativePath: string) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#restartHTTPServer(port)\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n this.#assetsServer?.setLogger(logger)\n return this\n }\n\n /**\n * Add listener to get notified when dev server is\n * closed\n */\n onClose(callback: (exitCode: number) => any): this {\n this.#onClose = callback\n return this\n }\n\n /**\n * Add listener to get notified when dev server exists\n * with an error\n */\n onError(callback: (error: any) => any): this {\n this.#onError = callback\n return this\n }\n\n /**\n * Close watchers and running child processes\n */\n async close() {\n await this.#watcher?.close()\n this.#assetsServer?.stop()\n if (this.#httpServer) {\n this.#httpServer.removeAllListeners()\n this.#httpServer.kill('SIGKILL')\n }\n }\n\n /**\n * Start the development server\n */\n async start() {\n this.#clearScreen()\n this.#logger.info('starting HTTP server...')\n this.#startHTTPServer(String(await getPort(this.#cwd)), 'nonblocking')\n this.#startAssetsServer()\n }\n\n /**\n * Start the development server in watch mode\n */\n async startAndWatch(ts: typeof tsStatic, options?: { poll: boolean }) {\n const port = String(await getPort(this.#cwd))\n this.#isWatching = true\n\n this.#clearScreen()\n\n this.#logger.info('starting HTTP server...')\n this.#startHTTPServer(port, 'blocking')\n\n this.#startAssetsServer()\n\n /**\n * Create watcher using tsconfig.json file\n */\n const output = watch(this.#cwd, ts, options || {})\n if (!output) {\n this.#onClose?.(1)\n return\n }\n\n /**\n * Storing reference to watcher, so that we can close it\n * when HTTP server exists with error\n */\n this.#watcher = output.chokidar\n\n /**\n * Notify the watcher is ready\n */\n output.watcher.on('watcher:ready', () => {\n this.#logger.info('watching file system for changes...')\n })\n\n /**\n * Cleanup when watcher dies\n */\n output.chokidar.on('error', (error) => {\n this.#logger.warning('file system watcher failure')\n this.#logger.fatal(error)\n this.#onError?.(error)\n output.chokidar.close()\n })\n\n /**\n * Changes in TypeScript source file\n */\n output.watcher.on('source:add', ({ relativePath }) =>\n this.#handleSourceFileChange('add', port, relativePath)\n )\n output.watcher.on('source:change', ({ relativePath }) =>\n this.#handleSourceFileChange('update', port, relativePath)\n )\n output.watcher.on('source:unlink', ({ relativePath }) =>\n this.#handleSourceFileChange('delete', port, relativePath)\n )\n\n /**\n * Changes in non-TypeScript source files\n */\n output.watcher.on('add', ({ relativePath }) =>\n this.#handleFileChange('add', port, relativePath)\n )\n output.watcher.on('change', ({ relativePath }) =>\n this.#handleFileChange('update', port, relativePath)\n )\n output.watcher.on('unlink', ({ relativePath }) =>\n this.#handleFileChange('delete', port, relativePath)\n )\n }\n}\n","/*\n * @adonisjs/core\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ExecaChildProcess } from 'execa'\nimport { type Logger, cliui } from '@poppinss/cliui'\n\nimport { run } from './helpers.js'\nimport type { AssetsBundlerOptions } from './types.js'\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * Exposes the API to start the development server for processing assets during\n * development.\n *\n * - Here we are running the assets dev server in a child process.\n * - Piping the output from the child process and reformatting it before writing it to\n * process streams.\n *\n * AssetsDevServer is agnostic and can run any assets dev server. Be it Vite or Encore or\n * even Webpack directly.\n */\nexport class AssetsDevServer {\n #cwd: URL\n #logger = ui.logger\n #options?: AssetsBundlerOptions\n #devServer?: ExecaChildProcess<string>\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, options?: AssetsBundlerOptions) {\n this.#cwd = cwd\n this.#options = options\n }\n\n /**\n * Logs messages from vite dev server stdout and stderr\n */\n #logViteDevServerMessage(data: Buffer) {\n const dataString = data.toString()\n const lines = dataString.split('\\n')\n\n /**\n * Put a wrapper around vite network address log\n */\n if (dataString.includes('Local') && dataString.includes('Network')) {\n const sticker = ui.sticker().useColors(this.#colors).useRenderer(this.#logger.getRenderer())\n\n lines.forEach((line: string) => {\n if (line.trim()) {\n sticker.add(line)\n }\n })\n\n sticker.render()\n return\n }\n\n /**\n * Logging VITE ready in message with proper\n * spaces and newlines\n */\n if (dataString.includes('ready in')) {\n console.log('')\n console.log(dataString.trim())\n return\n }\n\n /**\n * Log rest of the lines\n */\n lines.forEach((line: string) => {\n if (line.trim()) {\n console.log(line)\n }\n })\n }\n\n /**\n * Logs messages from assets dev server stdout and stderr\n */\n #logAssetsDevServerMessage(data: Buffer) {\n const dataString = data.toString()\n const lines = dataString.split('\\n')\n lines.forEach((line: string) => {\n if (line.trim()) {\n console.log(line)\n }\n })\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n return this\n }\n\n /**\n * Starts the assets bundler server. The assets bundler server process is\n * considered as the secondary process and therefore we do not perform\n * any cleanup if it dies.\n */\n start() {\n if (!this.#options?.enabled) {\n return\n }\n\n this.#logger.info(`starting \"${this.#options.driver}\" dev server...`)\n\n /**\n * Create child process\n */\n this.#devServer = run(this.#cwd, {\n script: this.#options.cmd,\n\n /**\n * We do not inherit the stdio for vite and encore, because in\n * inherit mode they own the stdin and interrupts the\n * `Ctrl + C` command.\n */\n stdio: 'pipe',\n scriptArgs: this.#options.args,\n })\n\n /**\n * Log child process messages\n */\n this.#devServer.stdout?.on('data', (data) => {\n if (this.#options!.driver === 'vite') {\n this.#logViteDevServerMessage(data)\n } else {\n this.#logAssetsDevServerMessage(data)\n }\n })\n\n this.#devServer.stderr?.on('data', (data) => {\n if (this.#options!.driver === 'vite') {\n this.#logViteDevServerMessage(data)\n } else {\n this.#logAssetsDevServerMessage(data)\n }\n })\n\n this.#devServer\n .then((result) => {\n this.#logger.warning(\n `\"${this.#options!.driver}\" dev server closed with status code \"${result.exitCode}\"`\n )\n })\n .catch((error) => {\n this.#logger.warning(`unable to connect to \"${this.#options!.driver}\" dev server`)\n this.#logger.fatal(error)\n })\n }\n\n /**\n * Stop the dev server\n */\n stop() {\n if (this.#devServer) {\n this.#devServer.removeAllListeners()\n this.#devServer.kill('SIGKILL')\n this.#devServer = undefined\n }\n }\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport picomatch from 'picomatch'\nimport type tsStatic from 'typescript'\nimport { type ExecaChildProcess } from 'execa'\nimport { cliui, type Logger } from '@poppinss/cliui'\nimport type { Watcher } from '@poppinss/chokidar-ts'\n\nimport type { TestRunnerOptions } from './types.js'\nimport { AssetsDevServer } from './assets_dev_server.js'\nimport { getPort, isDotEnvFile, runNode, watch } from './helpers.js'\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * Exposes the API to run Japa tests and optionally watch for file\n * changes to re-run the tests.\n *\n * The watch mode functions as follows.\n *\n * - If the changed file is a test file, then only tests for that file\n * will be re-run.\n * - Otherwise, all tests will re-run with respect to the initial\n * filters applied when running the `node ace test` command.\n *\n */\nexport class TestRunner {\n #cwd: URL\n #logger = ui.logger\n #options: TestRunnerOptions\n\n /**\n * The script file to run as a child process\n */\n #scriptFile: string = 'bin/test.js'\n\n /**\n * Pico matcher function to check if the filepath is\n * part of the `metaFiles` glob patterns\n */\n #isMetaFile: picomatch.Matcher\n\n /**\n * Pico matcher function to check if the filepath is\n * part of a test file.\n */\n #isTestFile: picomatch.Matcher\n\n /**\n * Arguments to pass to the \"bin/test.js\" file.\n */\n #scriptArgs: string[]\n\n /**\n * Set of initial filters applied when running the test\n * command. In watch mode, we will append an additional\n * filter to run tests only for the file that has been\n * changed.\n */\n #initialFiltersArgs: string[]\n\n /**\n * In watch mode, after a file is changed, we wait for the current\n * set of tests to finish before triggering a re-run. Therefore,\n * we use this flag to know if we are already busy in running\n * tests and ignore file-changes.\n */\n #isBusy: boolean = false\n\n /**\n * External listeners that are invoked when child process\n * gets an error or closes\n */\n #onError?: (error: any) => any\n #onClose?: (exitCode: number) => any\n\n /**\n * Reference to the test script child process\n */\n #testScript?: ExecaChildProcess<string>\n\n /**\n * Reference to the watcher\n */\n #watcher?: ReturnType<Watcher['watch']>\n\n /**\n * Reference to the assets server\n */\n #assetsServer?: AssetsDevServer\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, options: TestRunnerOptions) {\n this.#cwd = cwd\n this.#options = options\n\n this.#isMetaFile = picomatch((this.#options.metaFiles || []).map(({ pattern }) => pattern))\n\n /**\n * Create a test file watch by collection all the globs\n * used by all the suites. However, if a suite filter\n * was used, then we only collect glob for the mentioned\n * suites.\n */\n this.#isTestFile = picomatch(\n this.#options.suites\n .filter((suite) => {\n if (this.#options.filters.suites) {\n return this.#options.filters.suites.includes(suite.name)\n }\n return true\n })\n .map((suite) => suite.files)\n .flat(1)\n )\n\n this.#scriptArgs = this.#convertOptionsToArgs().concat(this.#options.scriptArgs)\n this.#initialFiltersArgs = this.#convertFiltersToArgs(this.#options.filters)\n }\n\n /**\n * Convert test runner options to the CLI args\n */\n #convertOptionsToArgs() {\n const args: string[] = []\n\n if (this.#options.reporters) {\n args.push('--reporters')\n args.push(this.#options.reporters.join(','))\n }\n\n if (this.#options.timeout !== undefined) {\n args.push('--timeout')\n args.push(String(this.#options.timeout))\n }\n\n if (this.#options.failed) {\n args.push('--failed')\n }\n\n if (this.#options.retries !== undefined) {\n args.push('--retries')\n args.push(String(this.#options.retries))\n }\n\n return args\n }\n\n /**\n * Converts all known filters to CLI args.\n *\n * The following code snippet may seem like repetitive code. But, it\n * is done intentionally to have visibility around how each filter\n * is converted to an arg.\n */\n #convertFiltersToArgs(filters: TestRunnerOptions['filters']): string[] {\n const args: string[] = []\n\n if (filters.suites) {\n args.push(...filters.suites)\n }\n\n if (filters.files) {\n args.push('--files')\n args.push(filters.files.join(','))\n }\n\n if (filters.groups) {\n args.push('--groups')\n args.push(filters.groups.join(','))\n }\n\n if (filters.tags) {\n args.push('--tags')\n args.push(filters.tags.join(','))\n }\n\n if (filters.tests) {\n args.push('--tests')\n args.push(filters.tests.join(','))\n }\n\n return args\n }\n\n /**\n * Conditionally clear the terminal screen\n */\n #clearScreen() {\n if (this.#options.clearScreen) {\n process.stdout.write('\\u001Bc')\n }\n }\n\n /**\n * Runs tests\n */\n #runTests(\n port: string,\n mode: 'blocking' | 'nonblocking',\n filters?: TestRunnerOptions['filters']\n ) {\n this.#isBusy = true\n\n /**\n * If inline filters are defined, then we ignore the\n * initial filters\n */\n const scriptArgs = filters\n ? this.#convertFiltersToArgs(filters).concat(this.#scriptArgs)\n : this.#initialFiltersArgs.concat(this.#scriptArgs)\n\n this.#testScript = runNode(this.#cwd, {\n script: this.#scriptFile,\n env: { PORT: port, ...this.#options.env },\n nodeArgs: this.#options.nodeArgs,\n scriptArgs,\n })\n\n this.#testScript\n .then((result) => {\n if (mode === 'nonblocking') {\n this.#onClose?.(result.exitCode)\n this.close()\n }\n })\n .catch((error) => {\n if (mode === 'nonblocking') {\n this.#onError?.(error)\n this.close()\n }\n })\n .finally(() => {\n this.#isBusy = false\n })\n }\n\n /**\n * Re-run tests with additional inline filters. Should be\n * executed in watch mode only.\n */\n #rerunTests(port: string, filters?: TestRunnerOptions['filters']) {\n if (this.#testScript) {\n this.#testScript.removeAllListeners()\n this.#testScript.kill('SIGKILL')\n }\n\n this.#runTests(port, 'blocking', filters)\n }\n\n /**\n * Starts the assets server\n */\n #startAssetsServer() {\n this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets)\n this.#assetsServer.setLogger(this.#logger)\n this.#assetsServer.start()\n }\n\n /**\n * Handles a non TypeScript file change\n */\n #handleFileChange(action: string, port: string, relativePath: string) {\n if (this.#isBusy) {\n return\n }\n\n if (isDotEnvFile(relativePath) || this.#isMetaFile(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#rerunTests(port)\n }\n }\n\n /**\n * Handles TypeScript source file change\n */\n #handleSourceFileChange(action: string, port: string, relativePath: string) {\n if (this.#isBusy) {\n return\n }\n\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n\n /**\n * If changed file is a test file after considering the initial filters,\n * then only run that file\n */\n if (this.#isTestFile(relativePath)) {\n this.#rerunTests(port, {\n ...this.#options.filters,\n files: [relativePath],\n })\n return\n }\n\n this.#rerunTests(port)\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n this.#assetsServer?.setLogger(logger)\n return this\n }\n\n /**\n * Add listener to get notified when dev server is\n * closed\n */\n onClose(callback: (exitCode: number) => any): this {\n this.#onClose = callback\n return this\n }\n\n /**\n * Add listener to get notified when dev server exists\n * with an error\n */\n onError(callback: (error: any) => any): this {\n this.#onError = callback\n return this\n }\n\n /**\n * Close watchers and running child processes\n */\n async close() {\n await this.#watcher?.close()\n this.#assetsServer?.stop()\n if (this.#testScript) {\n this.#testScript.removeAllListeners()\n this.#testScript.kill('SIGKILL')\n }\n }\n\n /**\n * Runs tests\n */\n async run() {\n const port = String(await getPort(this.#cwd))\n\n this.#clearScreen()\n this.#startAssetsServer()\n\n this.#logger.info('booting application to run tests...')\n this.#runTests(port, 'nonblocking')\n }\n\n /**\n * Run tests in watch mode\n */\n async runAndWatch(ts: typeof tsStatic, options?: { poll: boolean }) {\n const port = String(await getPort(this.#cwd))\n\n this.#clearScreen()\n this.#startAssetsServer()\n\n this.#logger.info('booting application to run tests...')\n this.#runTests(port, 'blocking')\n\n /**\n * Create watcher using tsconfig.json file\n */\n const output = watch(this.#cwd, ts, options || {})\n if (!output) {\n this.#onClose?.(1)\n return\n }\n\n /**\n * Storing reference to watcher, so that we can close it\n * when HTTP server exists with error\n */\n this.#watcher = output.chokidar\n\n /**\n * Notify the watcher is ready\n */\n output.watcher.on('watcher:ready', () => {\n this.#logger.info('watching file system for changes...')\n })\n\n /**\n * Cleanup when watcher dies\n */\n output.chokidar.on('error', (error) => {\n this.#logger.warning('file system watcher failure')\n this.#logger.fatal(error)\n this.#onError?.(error)\n output.chokidar.close()\n })\n\n /**\n * Changes in TypeScript source file\n */\n output.watcher.on('source:add', ({ relativePath }) =>\n this.#handleSourceFileChange('add', port, relativePath)\n )\n output.watcher.on('source:change', ({ relativePath }) =>\n this.#handleSourceFileChange('update', port, relativePath)\n )\n output.watcher.on('source:unlink', ({ relativePath }) =>\n this.#handleSourceFileChange('delete', port, relativePath)\n )\n\n /**\n * Changes in non-TypeScript source files\n */\n output.watcher.on('add', ({ relativePath }) =>\n this.#handleFileChange('add', port, relativePath)\n )\n output.watcher.on('change', ({ relativePath }) =>\n this.#handleFileChange('update', port, relativePath)\n )\n output.watcher.on('unlink', ({ relativePath }) =>\n this.#handleFileChange('delete', port, relativePath)\n )\n }\n}\n"],"mappings":";AASA,OAAO,WAAW;AAClB,OAAO,QAAQ;AACf,SAAS,YAAAA,iBAAgB;AAEzB,SAAS,iBAAAC,sBAAqB;AAC9B,SAAS,aAA0B;AACnC,SAAS,4BAA4B;;;ACNrC,SAAS,cAAc;AACvB,OAAO,cAAc;AACrB,OAAO,mBAAmB;AAC1B,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,WAAW,aAAa;AACjC,SAAS,UAAU,aAAa;AAChC,SAAS,WAAW,iBAAiB;AACrC,SAAS,cAAc,eAAe;AACtC,SAAS,UAAU,SAAS,YAAY,MAAM,gBAAgB;;;ACV9D,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,oBAAoB;;;ADiB5C,IAAM,oBAAoB;AAAA;AAAA,EAExB;AAAA;AAAA,EAEA;AACF;AAQA,IAAI,QAAQ,4BAA4B,IAAI,mBAAmB,GAAG;AAEhE,oBAAkB,KAAK,uCAAuC;AAChE,OAAO;AACL,oBAAkB,KAAK,eAAe;AACxC;AAMO,SAAS,YAAY,KAAmB,IAAqB;AAClE,QAAM,EAAE,QAAQ,MAAM,IAAI,IAAI,aAAa,KAAK,iBAAiB,EAAE,EAAE,MAAM;AAC3E,MAAI,OAAO;AACT,UAAM,eAAe,GAAG,mBAAmB,CAAC,CAAC;AAC7C,YAAQ,IAAI,GAAG,qCAAqC,CAAC,KAAK,GAAG,YAAY,CAAC;AAC1E;AAAA,EACF;AAEA,MAAI,OAAQ,OAAO,QAAQ;AACzB,UAAM,eAAe,GAAG,mBAAmB,CAAC,CAAC;AAC7C,YAAQ,IAAI,GAAG,qCAAqC,OAAQ,QAAQ,YAAY,CAAC;AACjF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,SAAS,QAAQ,KAAmB,SAAqB;AAC9D,QAAM,eAAe,UAAU,QAAQ,QAA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QAAQ,QAAQ,6BAA6B;AAClD,WAAK,QAAQ,MAAM,KAAK;AACxB,WAAK,WAAW,KAAK;AACrB,aAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAKD,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAc,CAAC,EAAE,aAAa,MAC9C,KAAK,wBAAwB,OAAO,MAAM,YAAY;AAAA,IACxD;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAiB,CAAC,EAAE,aAAa,MACjD,KAAK,wBAAwB,UAAU,MAAM,YAAY;AAAA,IAC3D;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAiB,CAAC,EAAE,aAAa,MACjD,KAAK,wBAAwB,UAAU,MAAM,YAAY;AAAA,IAC3D;AAKA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAO,CAAC,EAAE,aAAa,MACvC,KAAK,kBAAkB,OAAO,MAAM,YAAY;AAAA,IAClD;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAU,CAAC,EAAE,aAAa,MAC1C,KAAK,kBAAkB,UAAU,MAAM,YAAY;AAAA,IACrD;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAU,CAAC,EAAE,aAAa,MAC1C,KAAK,kBAAkB,UAAU,MAAM,YAAY;AAAA,IACrD;AAAA,EACF;AACF;","names":["relative","fileURLToPath","fileURLToPath","relative","cliui","cliui","ui","cliui","ui","cliui","picomatch","cliui","ui","cliui","picomatch"]}
1
+ {"version":3,"sources":["../src/bundler.ts","../src/hooks.ts","../src/helpers.ts","../src/debug.ts","../src/dev_server.ts","../src/assets_dev_server.ts","../src/test_runner.ts"],"sourcesContent":["/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport slash from 'slash'\nimport dedent from 'dedent'\nimport fs from 'node:fs/promises'\nimport type tsStatic from 'typescript'\nimport { fileURLToPath } from 'node:url'\nimport { join, relative } from 'node:path'\nimport { cliui, type Logger } from '@poppinss/cliui'\nimport { detectPackageManager } from '@antfu/install-pkg'\n\nimport { AssemblerHooks } from './hooks.js'\nimport type { BundlerOptions } from './types.js'\nimport { run, parseConfig, copyFiles } from './helpers.js'\n\ntype SupportedPackageManager = 'npm' | 'yarn' | 'pnpm' | 'bun'\n\n/**\n * List of package managers we support in order to\n * copy lockfiles\n */\nconst SUPPORT_PACKAGE_MANAGERS: {\n [K in SupportedPackageManager]: {\n lockFile: string\n installCommand: string\n }\n} = {\n npm: {\n lockFile: 'package-lock.json',\n installCommand: 'npm ci --omit=\"dev\"',\n },\n yarn: {\n lockFile: 'yarn.lock',\n installCommand: 'yarn install --production',\n },\n pnpm: {\n lockFile: 'pnpm-lock.yaml',\n installCommand: 'pnpm i --prod',\n },\n bun: {\n lockFile: 'bun.lockb',\n installCommand: 'bun install --production',\n },\n}\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * The bundler class exposes the API to build an AdonisJS project.\n */\nexport class Bundler {\n #cwd: URL\n #cwdPath: string\n #ts: typeof tsStatic\n #logger = ui.logger\n #hooks: AssemblerHooks\n #options: BundlerOptions\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, ts: typeof tsStatic, options: BundlerOptions) {\n this.#cwd = cwd\n this.#cwdPath = fileURLToPath(this.#cwd)\n this.#ts = ts\n this.#options = options\n this.#hooks = new AssemblerHooks(options.hooks)\n }\n\n /**\n * Returns the relative unix path for an absolute\n * file path\n */\n #getRelativeName(filePath: string) {\n return slash(relative(this.#cwdPath, filePath))\n }\n\n /**\n * Cleans up the build directory\n */\n async #cleanupBuildDirectory(outDir: string) {\n await fs.rm(outDir, { recursive: true, force: true, maxRetries: 5 })\n }\n\n /**\n * Runs assets bundler command to build assets\n */\n async #buildAssets(): Promise<boolean> {\n const assetsBundler = this.#options.assets\n if (!assetsBundler?.enabled) {\n return true\n }\n\n try {\n this.#logger.info('compiling frontend assets', { suffix: assetsBundler.cmd })\n await run(this.#cwd, {\n stdio: 'inherit',\n script: assetsBundler.cmd,\n scriptArgs: assetsBundler.args,\n })\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Runs tsc command to build the source.\n */\n async #runTsc(outDir: string): Promise<boolean> {\n try {\n await run(this.#cwd, {\n stdio: 'inherit',\n script: 'tsc',\n scriptArgs: ['--outDir', outDir],\n })\n return true\n } catch {\n return false\n }\n }\n\n /**\n * Copy meta files to the output directory\n */\n async #copyMetaFiles(outDir: string, additionalFilesToCopy: string[]) {\n const metaFiles = (this.#options.metaFiles || [])\n .map((file) => file.pattern)\n .concat(additionalFilesToCopy)\n\n await copyFiles(metaFiles, this.#cwdPath, outDir)\n }\n\n /**\n * Detect the package manager used by the project\n * and return the lockfile name and install command\n * related to it.\n */\n async #getPackageManager(client?: SupportedPackageManager) {\n let pkgManager: string | null | undefined = client\n\n if (!pkgManager) {\n pkgManager = await detectPackageManager(this.#cwdPath)\n }\n if (!pkgManager) {\n pkgManager = 'npm'\n }\n\n if (!Object.keys(SUPPORT_PACKAGE_MANAGERS).includes(pkgManager)) {\n return null\n }\n\n return SUPPORT_PACKAGE_MANAGERS[pkgManager as SupportedPackageManager]\n }\n\n /**\n * Rewrite the ace file since the original one\n * is importing ts-node which is not installed\n * in a production environment.\n */\n async #createAceFile(outDir: string) {\n const aceFileLocation = join(outDir, 'ace.js')\n const aceFileContent = dedent(/* JavaScript */ `\n /**\n * This file is auto-generated by the build process.\n * If you had any custom code inside this file, then\n * instead write it inside the \"bin/console.js\" file.\n */\n\n await import('./bin/console.js')\n `)\n\n await fs.writeFile(aceFileLocation, aceFileContent)\n this.#logger.info('rewrited ace file', { suffix: this.#getRelativeName(aceFileLocation) })\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n return this\n }\n\n /**\n * Bundles the application to be run in production\n */\n async bundle(stopOnError: boolean = true, client?: SupportedPackageManager): Promise<boolean> {\n await this.#hooks.registerBuildHooks()\n\n /**\n * Step 1: Parse config file to get the build output directory\n */\n const config = parseConfig(this.#cwd, this.#ts)\n if (!config) {\n return false\n }\n\n /**\n * Step 2: Cleanup existing build directory (if any)\n */\n const outDir = config.options.outDir || fileURLToPath(new URL('build/', this.#cwd))\n this.#logger.info('cleaning up output directory', { suffix: this.#getRelativeName(outDir) })\n await this.#cleanupBuildDirectory(outDir)\n\n /**\n * Step 3: Build frontend assets\n */\n if (!(await this.#buildAssets())) {\n return false\n }\n\n /**\n * Step 4: Execute build starting hook\n */\n await this.#hooks.onBuildStarting({ colors: ui.colors, logger: this.#logger })\n\n /**\n * Step 5: Build typescript source code\n */\n this.#logger.info('compiling typescript source', { suffix: 'tsc' })\n const buildCompleted = await this.#runTsc(outDir)\n await this.#createAceFile(outDir)\n\n /**\n * Remove incomplete build directory when tsc build\n * failed and stopOnError is set to true.\n */\n if (!buildCompleted && stopOnError) {\n await this.#cleanupBuildDirectory(outDir)\n const instructions = ui\n .sticker()\n .fullScreen()\n .drawBorder((borderChar, colors) => colors.red(borderChar))\n\n instructions.add(\n this.#colors.red('Cannot complete the build process as there are TypeScript errors.')\n )\n instructions.add(\n this.#colors.red(\n 'Use \"--ignore-ts-errors\" flag to ignore TypeScript errors and continue the build.'\n )\n )\n\n this.#logger.logError(instructions.prepare())\n return false\n }\n\n /**\n * Step 6: Copy meta files to the build directory\n */\n const pkgManager = await this.#getPackageManager(client)\n const pkgFiles = pkgManager ? ['package.json', pkgManager.lockFile] : ['package.json']\n this.#logger.info('copying meta files to the output directory')\n await this.#copyMetaFiles(outDir, pkgFiles)\n\n this.#logger.success('build completed')\n this.#logger.log('')\n\n /**\n * Step 7: Execute build completed hook\n */\n await this.#hooks.onBuildCompleted({ colors: ui.colors, logger: this.#logger })\n\n /**\n * Next steps\n */\n ui.instructions()\n .useRenderer(this.#logger.getRenderer())\n .heading('Run the following commands to start the server in production')\n .add(this.#colors.cyan(`cd ${this.#getRelativeName(outDir)}`))\n .add(\n this.#colors.cyan(\n pkgManager ? pkgManager.installCommand : 'Install production dependencies'\n )\n )\n .add(this.#colors.cyan('node bin/server.js'))\n .render()\n\n return true\n }\n}\n","import {\n AssemblerHookNode,\n SourceFileChangedHookHandler,\n AssemblerHookHandler,\n RcFile,\n} from '@adonisjs/application/types'\nimport { RuntimeException } from '@poppinss/utils'\nimport Hooks from '@poppinss/hooks'\n\nexport class AssemblerHooks {\n #config: RcFile['unstable_assembler']\n\n #hooks = new Hooks<{\n onDevServerStarted: [Parameters<AssemblerHookHandler>, []]\n onSourceFileChanged: [Parameters<SourceFileChangedHookHandler>, []]\n onBuildStarting: [Parameters<AssemblerHookHandler>, []]\n onBuildCompleted: [Parameters<AssemblerHookHandler>, []]\n }>()\n\n constructor(config: RcFile['unstable_assembler']) {\n this.#config = config\n }\n\n /**\n * Resolve the hook by importing the file and returning the default export\n */\n async #resolveHookNode(node: AssemblerHookNode<any>) {\n const exports = await node()\n\n if (!exports.default) {\n throw new RuntimeException('Assembler hook must be defined using the default export')\n }\n\n return exports.default\n }\n\n /**\n * Resolve hooks needed for dev-time and register them to the Hooks instance\n */\n async registerDevServerHooks() {\n await Promise.all([\n this.#config?.onDevServerStarted?.map(async (node) =>\n this.#hooks.add('onDevServerStarted', await this.#resolveHookNode(node))\n ),\n this.#config?.onSourceFileChanged?.map(async (node) =>\n this.#hooks.add('onSourceFileChanged', await this.#resolveHookNode(node))\n ),\n ])\n }\n\n /**\n * Resolve hooks needed for build-time and register them to the Hooks instance\n */\n async registerBuildHooks() {\n await Promise.all([\n this.#config?.onBuildStarting?.map(async (node) =>\n this.#hooks.add('onBuildStarting', await this.#resolveHookNode(node))\n ),\n this.#config?.onBuildCompleted?.map(async (node) =>\n this.#hooks.add('onBuildCompleted', await this.#resolveHookNode(node))\n ),\n ])\n }\n\n /**\n * When the dev server is started\n */\n async onDevServerStarted(...args: Parameters<AssemblerHookHandler>) {\n await this.#hooks.runner('onDevServerStarted').run(...args)\n }\n\n /**\n * When a source file changes\n */\n async onSourceFileChanged(...args: Parameters<SourceFileChangedHookHandler>) {\n await this.#hooks.runner('onSourceFileChanged').run(...args)\n }\n\n /**\n * When the build process is starting\n */\n async onBuildStarting(...args: Parameters<AssemblerHookHandler>) {\n await this.#hooks.runner('onBuildStarting').run(...args)\n }\n\n /**\n * When the build process is completed\n */\n async onBuildCompleted(...args: Parameters<AssemblerHookHandler>) {\n await this.#hooks.runner('onBuildCompleted').run(...args)\n }\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { isJunk } from 'junk'\nimport fastGlob from 'fast-glob'\nimport getRandomPort from 'get-port'\nimport { existsSync } from 'node:fs'\nimport type tsStatic from 'typescript'\nimport { fileURLToPath } from 'node:url'\nimport { execaNode, execa } from 'execa'\nimport { copyFile, mkdir } from 'node:fs/promises'\nimport { EnvLoader, EnvParser } from '@adonisjs/env'\nimport { ConfigParser, Watcher } from '@poppinss/chokidar-ts'\nimport { basename, dirname, isAbsolute, join, relative } from 'node:path'\n\nimport type { RunOptions, WatchOptions } from './types.js'\nimport debug from './debug.js'\n\n/**\n * Default set of args to pass in order to run TypeScript\n * source. Used by \"run\" and \"runNode\" scripts\n */\nconst DEFAULT_NODE_ARGS = [\n // Use ts-node/esm loader. The project must install it\n '--loader=ts-node/esm',\n // Enable source maps, since TSNode source maps are broken\n '--enable-source-maps',\n]\n\n/**\n * Disable experimental warnings, since the ts-node loader hook\n * uses an expiremental feature. We are waiting for them to\n * cut a new release and support the newer `--import` flag\n * instead\n */\nif (process.allowedNodeEnvironmentFlags.has('--disable-warning')) {\n // supported in node>=v21.13.0\n DEFAULT_NODE_ARGS.push('--disable-warning=ExperimentalWarning')\n} else {\n DEFAULT_NODE_ARGS.push('--no-warnings')\n}\n\n/**\n * Parses tsconfig.json and prints errors using typescript compiler\n * host\n */\nexport function parseConfig(cwd: string | URL, ts: typeof tsStatic) {\n const { config, error } = new ConfigParser(cwd, 'tsconfig.json', ts).parse()\n if (error) {\n const compilerHost = ts.createCompilerHost({})\n console.log(ts.formatDiagnosticsWithColorAndContext([error], compilerHost))\n return\n }\n\n if (config!.errors.length) {\n const compilerHost = ts.createCompilerHost({})\n console.log(ts.formatDiagnosticsWithColorAndContext(config!.errors, compilerHost))\n return\n }\n\n return config\n}\n\n/**\n * Runs a Node.js script as a child process and inherits the stdio streams\n */\nexport function runNode(cwd: string | URL, options: RunOptions) {\n const childProcess = execaNode(options.script, options.scriptArgs, {\n nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),\n preferLocal: true,\n windowsHide: false,\n localDir: cwd,\n cwd,\n buffer: false,\n stdio: options.stdio || 'inherit',\n env: {\n ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),\n ...options.env,\n },\n })\n\n return childProcess\n}\n\n/**\n * Runs a script as a child process and inherits the stdio streams\n */\nexport function run(cwd: string | URL, options: Omit<RunOptions, 'nodeArgs'>) {\n const childProcess = execa(options.script, options.scriptArgs, {\n preferLocal: true,\n windowsHide: false,\n localDir: cwd,\n cwd,\n buffer: false,\n stdio: options.stdio || 'inherit',\n env: {\n ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),\n ...options.env,\n },\n })\n\n return childProcess\n}\n\n/**\n * Watches the file system using tsconfig file\n */\nexport function watch(cwd: string | URL, ts: typeof tsStatic, options: WatchOptions) {\n const config = parseConfig(cwd, ts)\n if (!config) {\n return\n }\n\n const watcher = new Watcher(typeof cwd === 'string' ? cwd : fileURLToPath(cwd), config!)\n const chokidar = watcher.watch(['.'], { usePolling: options.poll })\n return { watcher, chokidar }\n}\n\n/**\n * Check if file is an .env file\n */\nexport function isDotEnvFile(filePath: string) {\n if (filePath === '.env') {\n return true\n }\n\n return filePath.includes('.env.')\n}\n\n/**\n * Returns the port to use after inspect the dot-env files inside\n * a given directory.\n *\n * A random port is used when the specified port is in use. Following\n * is the logic for finding a specified port.\n *\n * - The \"process.env.PORT\" value is used if exists.\n * - The dot-env files are loaded using the \"EnvLoader\" and the PORT\n * value is used by iterating over all the loaded files. The\n * iteration stops after first find.\n */\nexport async function getPort(cwd: URL): Promise<number> {\n /**\n * Use existing port if exists\n */\n if (process.env.PORT) {\n return getRandomPort({ port: Number(process.env.PORT) })\n }\n\n /**\n * Loop over files and use the port from their contents. Stops\n * after first match\n */\n const files = await new EnvLoader(cwd).load()\n for (let file of files) {\n const envVariables = new EnvParser(file.contents).parse()\n if (envVariables.PORT) {\n return getRandomPort({ port: Number(envVariables.PORT) })\n }\n }\n\n /**\n * Use 3333 as the port\n */\n return getRandomPort({ port: 3333 })\n}\n\n/**\n * Helper function to copy files from relative paths or glob\n * patterns\n */\nexport async function copyFiles(files: string[], cwd: string, outDir: string) {\n /**\n * Looping over files and create a new collection with paths\n * and glob patterns\n */\n const { paths, patterns } = files.reduce<{ patterns: string[]; paths: string[] }>(\n (result, file) => {\n /**\n * If file is a glob pattern, then push it to patterns\n */\n if (fastGlob.isDynamicPattern(file)) {\n result.patterns.push(file)\n return result\n }\n\n /**\n * Otherwise, check if file exists and push it to paths to copy\n */\n if (existsSync(join(cwd, file))) {\n result.paths.push(file)\n }\n\n return result\n },\n { patterns: [], paths: [] }\n )\n\n debug('copyFiles inputs: %O, paths: %O, patterns: %O', files, paths, patterns)\n\n /**\n * Getting list of relative paths from glob patterns\n */\n const filePaths = paths.concat(await fastGlob(patterns, { cwd, dot: true })).filter((file) => {\n return !isJunk(basename(file))\n })\n\n /**\n * Finally copy files to the destination by keeping the same\n * directory structure and ignoring junk files\n */\n debug('copying files %O to destination \"%s\"', filePaths, outDir)\n const copyPromises = filePaths.map(async (file) => {\n const src = isAbsolute(file) ? file : join(cwd, file)\n const dest = join(outDir, relative(cwd, src))\n\n await mkdir(dirname(dest), { recursive: true })\n return copyFile(src, dest)\n })\n\n return await Promise.all(copyPromises)\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:assembler')\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport picomatch from 'picomatch'\nimport type tsStatic from 'typescript'\nimport prettyHrtime from 'pretty-hrtime'\nimport { type ExecaChildProcess } from 'execa'\nimport { cliui, type Logger } from '@poppinss/cliui'\nimport type { Watcher } from '@poppinss/chokidar-ts'\n\nimport { AssemblerHooks } from './hooks.js'\nimport type { DevServerOptions } from './types.js'\nimport { AssetsDevServer } from './assets_dev_server.js'\nimport { getPort, isDotEnvFile, runNode, watch } from './helpers.js'\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * Exposes the API to start the development. Optionally, the watch API can be\n * used to watch for file changes and restart the development server.\n *\n * The Dev server performs the following actions\n *\n * - Assigns a random PORT, when PORT inside .env file is in use.\n * - Uses tsconfig.json file to collect a list of files to watch.\n * - Uses metaFiles from adonisrc.ts file to collect a list of files to watch.\n * - Restart HTTP server on every file change.\n */\nexport class DevServer {\n #cwd: URL\n #logger = ui.logger\n #options: DevServerOptions\n\n /**\n * Flag to know if the dev server is running in watch\n * mode\n */\n #isWatching: boolean = false\n\n /**\n * Script file to start the development server\n */\n #scriptFile: string = 'bin/server.js'\n\n /**\n * Picomatch matcher function to know if a file path is a\n * meta file with reloadServer option enabled\n */\n #isMetaFileWithReloadsEnabled: picomatch.Matcher\n\n /**\n * Picomatch matcher function to know if a file path is a\n * meta file with reloadServer option disabled\n */\n #isMetaFileWithReloadsDisabled: picomatch.Matcher\n\n /**\n * External listeners that are invoked when child process\n * gets an error or closes\n */\n #onError?: (error: any) => any\n #onClose?: (exitCode: number) => any\n\n /**\n * Reference to the child process\n */\n #httpServer?: ExecaChildProcess<string>\n\n /**\n * Reference to the watcher\n */\n #watcher?: ReturnType<Watcher['watch']>\n\n /**\n * Reference to the assets server\n */\n #assetsServer?: AssetsDevServer\n\n /**\n * Hooks to execute custom actions during the dev server lifecycle\n */\n #hooks: AssemblerHooks\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, options: DevServerOptions) {\n this.#cwd = cwd\n this.#options = options\n this.#hooks = new AssemblerHooks(options.hooks)\n\n this.#isMetaFileWithReloadsEnabled = picomatch(\n (this.#options.metaFiles || [])\n .filter(({ reloadServer }) => reloadServer === true)\n .map(({ pattern }) => pattern)\n )\n\n this.#isMetaFileWithReloadsDisabled = picomatch(\n (this.#options.metaFiles || [])\n .filter(({ reloadServer }) => reloadServer !== true)\n .map(({ pattern }) => pattern)\n )\n }\n\n /**\n * Inspect if child process message is from AdonisJS HTTP server\n */\n #isAdonisJSReadyMessage(message: unknown): message is {\n isAdonisJS: true\n environment: 'web'\n port: number\n host: string\n duration?: [number, number]\n } {\n return (\n message !== null &&\n typeof message === 'object' &&\n 'isAdonisJS' in message &&\n 'environment' in message &&\n message.environment === 'web'\n )\n }\n\n /**\n * Conditionally clear the terminal screen\n */\n #clearScreen() {\n if (this.#options.clearScreen) {\n process.stdout.write('\\u001Bc')\n }\n }\n\n /**\n * Starts the HTTP server\n */\n #startHTTPServer(port: string, mode: 'blocking' | 'nonblocking') {\n this.#httpServer = runNode(this.#cwd, {\n script: this.#scriptFile,\n env: { PORT: port, ...this.#options.env },\n nodeArgs: this.#options.nodeArgs,\n scriptArgs: this.#options.scriptArgs,\n })\n\n this.#httpServer.on('message', async (message) => {\n if (this.#isAdonisJSReadyMessage(message)) {\n const host = message.host === '0.0.0.0' ? '127.0.0.1' : message.host\n\n const displayMessage = ui\n .sticker()\n .useColors(this.#colors)\n .useRenderer(this.#logger.getRenderer())\n .add(`Server address: ${this.#colors.cyan(`http://${host}:${message.port}`)}`)\n .add(\n `File system watcher: ${this.#colors.cyan(\n `${this.#isWatching ? 'enabled' : 'disabled'}`\n )}`\n )\n\n if (message.duration) {\n displayMessage.add(`Ready in: ${this.#colors.cyan(prettyHrtime(message.duration))}`)\n }\n\n displayMessage.render()\n\n await this.#hooks.onDevServerStarted({ colors: ui.colors, logger: this.#logger })\n }\n })\n\n this.#httpServer\n .then((result) => {\n if (mode === 'nonblocking') {\n this.#onClose?.(result.exitCode)\n this.#watcher?.close()\n this.#assetsServer?.stop()\n } else {\n this.#logger.info('Underlying HTTP server closed. Still watching for changes')\n }\n })\n .catch((error) => {\n if (mode === 'nonblocking') {\n this.#onError?.(error)\n this.#watcher?.close()\n this.#assetsServer?.stop()\n } else {\n this.#logger.info('Underlying HTTP server died. Still watching for changes')\n }\n })\n }\n\n /**\n * Starts the assets server\n */\n #startAssetsServer() {\n this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets)\n this.#assetsServer.setLogger(this.#logger)\n this.#assetsServer.start()\n }\n\n /**\n * Restarts the HTTP server in the watch mode. Do not call this\n * method when not in watch mode\n */\n #restartHTTPServer(port: string) {\n if (this.#httpServer) {\n this.#httpServer.removeAllListeners()\n this.#httpServer.kill('SIGKILL')\n }\n\n this.#startHTTPServer(port, 'blocking')\n }\n\n /**\n * Handles a non TypeScript file change\n */\n #handleFileChange(action: string, port: string, relativePath: string) {\n if (isDotEnvFile(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#restartHTTPServer(port)\n return\n }\n\n if (this.#isMetaFileWithReloadsEnabled(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#restartHTTPServer(port)\n return\n }\n\n if (this.#isMetaFileWithReloadsDisabled(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n }\n }\n\n /**\n * Handles TypeScript source file change\n */\n #handleSourceFileChange(action: string, port: string, relativePath: string) {\n void this.#hooks.onSourceFileChanged({ colors: ui.colors, logger: this.#logger }, relativePath)\n\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#restartHTTPServer(port)\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n this.#assetsServer?.setLogger(logger)\n return this\n }\n\n /**\n * Add listener to get notified when dev server is\n * closed\n */\n onClose(callback: (exitCode: number) => any): this {\n this.#onClose = callback\n return this\n }\n\n /**\n * Add listener to get notified when dev server exists\n * with an error\n */\n onError(callback: (error: any) => any): this {\n this.#onError = callback\n return this\n }\n\n /**\n * Close watchers and running child processes\n */\n async close() {\n await this.#watcher?.close()\n this.#assetsServer?.stop()\n if (this.#httpServer) {\n this.#httpServer.removeAllListeners()\n this.#httpServer.kill('SIGKILL')\n }\n }\n\n /**\n * Start the development server\n */\n async start() {\n this.#clearScreen()\n this.#logger.info('starting HTTP server...')\n this.#startHTTPServer(String(await getPort(this.#cwd)), 'nonblocking')\n this.#startAssetsServer()\n }\n\n /**\n * Start the development server in watch mode\n */\n async startAndWatch(ts: typeof tsStatic, options?: { poll: boolean }) {\n const port = String(await getPort(this.#cwd))\n this.#isWatching = true\n\n this.#clearScreen()\n\n this.#logger.info('starting HTTP server...')\n this.#startHTTPServer(port, 'blocking')\n\n this.#startAssetsServer()\n\n /**\n * Create watcher using tsconfig.json file\n */\n const output = watch(this.#cwd, ts, options || {})\n if (!output) {\n this.#onClose?.(1)\n return\n }\n\n /**\n * Storing reference to watcher, so that we can close it\n * when HTTP server exists with error\n */\n this.#watcher = output.chokidar\n\n /**\n * Notify the watcher is ready\n */\n output.watcher.on('watcher:ready', () => {\n this.#logger.info('watching file system for changes...')\n })\n\n /**\n * Cleanup when watcher dies\n */\n output.chokidar.on('error', (error) => {\n this.#logger.warning('file system watcher failure')\n this.#logger.fatal(error)\n this.#onError?.(error)\n output.chokidar.close()\n })\n\n /**\n * Changes in TypeScript source file\n */\n output.watcher.on('source:add', ({ relativePath }) =>\n this.#handleSourceFileChange('add', port, relativePath)\n )\n output.watcher.on('source:change', ({ relativePath }) =>\n this.#handleSourceFileChange('update', port, relativePath)\n )\n output.watcher.on('source:unlink', ({ relativePath }) =>\n this.#handleSourceFileChange('delete', port, relativePath)\n )\n\n /**\n * Changes in non-TypeScript source files\n */\n output.watcher.on('add', ({ relativePath }) =>\n this.#handleFileChange('add', port, relativePath)\n )\n output.watcher.on('change', ({ relativePath }) =>\n this.#handleFileChange('update', port, relativePath)\n )\n output.watcher.on('unlink', ({ relativePath }) =>\n this.#handleFileChange('delete', port, relativePath)\n )\n }\n}\n","/*\n * @adonisjs/core\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ExecaChildProcess } from 'execa'\nimport { type Logger, cliui } from '@poppinss/cliui'\n\nimport { run } from './helpers.js'\nimport type { AssetsBundlerOptions } from './types.js'\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * Exposes the API to start the development server for processing assets during\n * development.\n *\n * - Here we are running the assets dev server in a child process.\n * - Piping the output from the child process and reformatting it before writing it to\n * process streams.\n *\n * AssetsDevServer is agnostic and can run any assets dev server. Be it Vite or Encore or\n * even Webpack directly.\n */\nexport class AssetsDevServer {\n #cwd: URL\n #logger = ui.logger\n #options?: AssetsBundlerOptions\n #devServer?: ExecaChildProcess<string>\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, options?: AssetsBundlerOptions) {\n this.#cwd = cwd\n this.#options = options\n }\n\n /**\n * Logs messages from vite dev server stdout and stderr\n */\n #logViteDevServerMessage(data: Buffer) {\n const dataString = data.toString()\n const lines = dataString.split('\\n')\n\n /**\n * Put a wrapper around vite network address log\n */\n if (dataString.includes('Local') && dataString.includes('Network')) {\n const sticker = ui.sticker().useColors(this.#colors).useRenderer(this.#logger.getRenderer())\n\n lines.forEach((line: string) => {\n if (line.trim()) {\n sticker.add(line)\n }\n })\n\n sticker.render()\n return\n }\n\n /**\n * Logging VITE ready in message with proper\n * spaces and newlines\n */\n if (dataString.includes('ready in')) {\n console.log('')\n console.log(dataString.trim())\n return\n }\n\n /**\n * Log rest of the lines\n */\n lines.forEach((line: string) => {\n if (line.trim()) {\n console.log(line)\n }\n })\n }\n\n /**\n * Logs messages from assets dev server stdout and stderr\n */\n #logAssetsDevServerMessage(data: Buffer) {\n const dataString = data.toString()\n const lines = dataString.split('\\n')\n lines.forEach((line: string) => {\n if (line.trim()) {\n console.log(line)\n }\n })\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n return this\n }\n\n /**\n * Starts the assets bundler server. The assets bundler server process is\n * considered as the secondary process and therefore we do not perform\n * any cleanup if it dies.\n */\n start() {\n if (!this.#options?.enabled) {\n return\n }\n\n this.#logger.info(`starting \"${this.#options.driver}\" dev server...`)\n\n /**\n * Create child process\n */\n this.#devServer = run(this.#cwd, {\n script: this.#options.cmd,\n\n /**\n * We do not inherit the stdio for vite and encore, because in\n * inherit mode they own the stdin and interrupts the\n * `Ctrl + C` command.\n */\n stdio: 'pipe',\n scriptArgs: this.#options.args,\n })\n\n /**\n * Log child process messages\n */\n this.#devServer.stdout?.on('data', (data) => {\n if (this.#options!.driver === 'vite') {\n this.#logViteDevServerMessage(data)\n } else {\n this.#logAssetsDevServerMessage(data)\n }\n })\n\n this.#devServer.stderr?.on('data', (data) => {\n if (this.#options!.driver === 'vite') {\n this.#logViteDevServerMessage(data)\n } else {\n this.#logAssetsDevServerMessage(data)\n }\n })\n\n this.#devServer\n .then((result) => {\n this.#logger.warning(\n `\"${this.#options!.driver}\" dev server closed with status code \"${result.exitCode}\"`\n )\n })\n .catch((error) => {\n this.#logger.warning(`unable to connect to \"${this.#options!.driver}\" dev server`)\n this.#logger.fatal(error)\n })\n }\n\n /**\n * Stop the dev server\n */\n stop() {\n if (this.#devServer) {\n this.#devServer.removeAllListeners()\n this.#devServer.kill('SIGKILL')\n this.#devServer = undefined\n }\n }\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport picomatch from 'picomatch'\nimport type tsStatic from 'typescript'\nimport { type ExecaChildProcess } from 'execa'\nimport { cliui, type Logger } from '@poppinss/cliui'\nimport type { Watcher } from '@poppinss/chokidar-ts'\n\nimport type { TestRunnerOptions } from './types.js'\nimport { AssetsDevServer } from './assets_dev_server.js'\nimport { getPort, isDotEnvFile, runNode, watch } from './helpers.js'\n\n/**\n * Instance of CLIUI\n */\nconst ui = cliui()\n\n/**\n * Exposes the API to run Japa tests and optionally watch for file\n * changes to re-run the tests.\n *\n * The watch mode functions as follows.\n *\n * - If the changed file is a test file, then only tests for that file\n * will be re-run.\n * - Otherwise, all tests will re-run with respect to the initial\n * filters applied when running the `node ace test` command.\n *\n */\nexport class TestRunner {\n #cwd: URL\n #logger = ui.logger\n #options: TestRunnerOptions\n\n /**\n * The script file to run as a child process\n */\n #scriptFile: string = 'bin/test.js'\n\n /**\n * Pico matcher function to check if the filepath is\n * part of the `metaFiles` glob patterns\n */\n #isMetaFile: picomatch.Matcher\n\n /**\n * Pico matcher function to check if the filepath is\n * part of a test file.\n */\n #isTestFile: picomatch.Matcher\n\n /**\n * Arguments to pass to the \"bin/test.js\" file.\n */\n #scriptArgs: string[]\n\n /**\n * Set of initial filters applied when running the test\n * command. In watch mode, we will append an additional\n * filter to run tests only for the file that has been\n * changed.\n */\n #initialFiltersArgs: string[]\n\n /**\n * In watch mode, after a file is changed, we wait for the current\n * set of tests to finish before triggering a re-run. Therefore,\n * we use this flag to know if we are already busy in running\n * tests and ignore file-changes.\n */\n #isBusy: boolean = false\n\n /**\n * External listeners that are invoked when child process\n * gets an error or closes\n */\n #onError?: (error: any) => any\n #onClose?: (exitCode: number) => any\n\n /**\n * Reference to the test script child process\n */\n #testScript?: ExecaChildProcess<string>\n\n /**\n * Reference to the watcher\n */\n #watcher?: ReturnType<Watcher['watch']>\n\n /**\n * Reference to the assets server\n */\n #assetsServer?: AssetsDevServer\n\n /**\n * Getting reference to colors library from logger\n */\n get #colors() {\n return this.#logger.getColors()\n }\n\n constructor(cwd: URL, options: TestRunnerOptions) {\n this.#cwd = cwd\n this.#options = options\n\n this.#isMetaFile = picomatch((this.#options.metaFiles || []).map(({ pattern }) => pattern))\n\n /**\n * Create a test file watch by collection all the globs\n * used by all the suites. However, if a suite filter\n * was used, then we only collect glob for the mentioned\n * suites.\n */\n this.#isTestFile = picomatch(\n this.#options.suites\n .filter((suite) => {\n if (this.#options.filters.suites) {\n return this.#options.filters.suites.includes(suite.name)\n }\n return true\n })\n .map((suite) => suite.files)\n .flat(1)\n )\n\n this.#scriptArgs = this.#convertOptionsToArgs().concat(this.#options.scriptArgs)\n this.#initialFiltersArgs = this.#convertFiltersToArgs(this.#options.filters)\n }\n\n /**\n * Convert test runner options to the CLI args\n */\n #convertOptionsToArgs() {\n const args: string[] = []\n\n if (this.#options.reporters) {\n args.push('--reporters')\n args.push(this.#options.reporters.join(','))\n }\n\n if (this.#options.timeout !== undefined) {\n args.push('--timeout')\n args.push(String(this.#options.timeout))\n }\n\n if (this.#options.failed) {\n args.push('--failed')\n }\n\n if (this.#options.retries !== undefined) {\n args.push('--retries')\n args.push(String(this.#options.retries))\n }\n\n return args\n }\n\n /**\n * Converts all known filters to CLI args.\n *\n * The following code snippet may seem like repetitive code. But, it\n * is done intentionally to have visibility around how each filter\n * is converted to an arg.\n */\n #convertFiltersToArgs(filters: TestRunnerOptions['filters']): string[] {\n const args: string[] = []\n\n if (filters.suites) {\n args.push(...filters.suites)\n }\n\n if (filters.files) {\n args.push('--files')\n args.push(filters.files.join(','))\n }\n\n if (filters.groups) {\n args.push('--groups')\n args.push(filters.groups.join(','))\n }\n\n if (filters.tags) {\n args.push('--tags')\n args.push(filters.tags.join(','))\n }\n\n if (filters.tests) {\n args.push('--tests')\n args.push(filters.tests.join(','))\n }\n\n return args\n }\n\n /**\n * Conditionally clear the terminal screen\n */\n #clearScreen() {\n if (this.#options.clearScreen) {\n process.stdout.write('\\u001Bc')\n }\n }\n\n /**\n * Runs tests\n */\n #runTests(\n port: string,\n mode: 'blocking' | 'nonblocking',\n filters?: TestRunnerOptions['filters']\n ) {\n this.#isBusy = true\n\n /**\n * If inline filters are defined, then we ignore the\n * initial filters\n */\n const scriptArgs = filters\n ? this.#convertFiltersToArgs(filters).concat(this.#scriptArgs)\n : this.#initialFiltersArgs.concat(this.#scriptArgs)\n\n this.#testScript = runNode(this.#cwd, {\n script: this.#scriptFile,\n env: { PORT: port, ...this.#options.env },\n nodeArgs: this.#options.nodeArgs,\n scriptArgs,\n })\n\n this.#testScript\n .then((result) => {\n if (mode === 'nonblocking') {\n this.#onClose?.(result.exitCode)\n this.close()\n }\n })\n .catch((error) => {\n if (mode === 'nonblocking') {\n this.#onError?.(error)\n this.close()\n }\n })\n .finally(() => {\n this.#isBusy = false\n })\n }\n\n /**\n * Re-run tests with additional inline filters. Should be\n * executed in watch mode only.\n */\n #rerunTests(port: string, filters?: TestRunnerOptions['filters']) {\n if (this.#testScript) {\n this.#testScript.removeAllListeners()\n this.#testScript.kill('SIGKILL')\n }\n\n this.#runTests(port, 'blocking', filters)\n }\n\n /**\n * Starts the assets server\n */\n #startAssetsServer() {\n this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets)\n this.#assetsServer.setLogger(this.#logger)\n this.#assetsServer.start()\n }\n\n /**\n * Handles a non TypeScript file change\n */\n #handleFileChange(action: string, port: string, relativePath: string) {\n if (this.#isBusy) {\n return\n }\n\n if (isDotEnvFile(relativePath) || this.#isMetaFile(relativePath)) {\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n this.#rerunTests(port)\n }\n }\n\n /**\n * Handles TypeScript source file change\n */\n #handleSourceFileChange(action: string, port: string, relativePath: string) {\n if (this.#isBusy) {\n return\n }\n\n this.#clearScreen()\n this.#logger.log(`${this.#colors.green(action)} ${relativePath}`)\n\n /**\n * If changed file is a test file after considering the initial filters,\n * then only run that file\n */\n if (this.#isTestFile(relativePath)) {\n this.#rerunTests(port, {\n ...this.#options.filters,\n files: [relativePath],\n })\n return\n }\n\n this.#rerunTests(port)\n }\n\n /**\n * Set a custom CLI UI logger\n */\n setLogger(logger: Logger) {\n this.#logger = logger\n this.#assetsServer?.setLogger(logger)\n return this\n }\n\n /**\n * Add listener to get notified when dev server is\n * closed\n */\n onClose(callback: (exitCode: number) => any): this {\n this.#onClose = callback\n return this\n }\n\n /**\n * Add listener to get notified when dev server exists\n * with an error\n */\n onError(callback: (error: any) => any): this {\n this.#onError = callback\n return this\n }\n\n /**\n * Close watchers and running child processes\n */\n async close() {\n await this.#watcher?.close()\n this.#assetsServer?.stop()\n if (this.#testScript) {\n this.#testScript.removeAllListeners()\n this.#testScript.kill('SIGKILL')\n }\n }\n\n /**\n * Runs tests\n */\n async run() {\n const port = String(await getPort(this.#cwd))\n\n this.#clearScreen()\n this.#startAssetsServer()\n\n this.#logger.info('booting application to run tests...')\n this.#runTests(port, 'nonblocking')\n }\n\n /**\n * Run tests in watch mode\n */\n async runAndWatch(ts: typeof tsStatic, options?: { poll: boolean }) {\n const port = String(await getPort(this.#cwd))\n\n this.#clearScreen()\n this.#startAssetsServer()\n\n this.#logger.info('booting application to run tests...')\n this.#runTests(port, 'blocking')\n\n /**\n * Create watcher using tsconfig.json file\n */\n const output = watch(this.#cwd, ts, options || {})\n if (!output) {\n this.#onClose?.(1)\n return\n }\n\n /**\n * Storing reference to watcher, so that we can close it\n * when HTTP server exists with error\n */\n this.#watcher = output.chokidar\n\n /**\n * Notify the watcher is ready\n */\n output.watcher.on('watcher:ready', () => {\n this.#logger.info('watching file system for changes...')\n })\n\n /**\n * Cleanup when watcher dies\n */\n output.chokidar.on('error', (error) => {\n this.#logger.warning('file system watcher failure')\n this.#logger.fatal(error)\n this.#onError?.(error)\n output.chokidar.close()\n })\n\n /**\n * Changes in TypeScript source file\n */\n output.watcher.on('source:add', ({ relativePath }) =>\n this.#handleSourceFileChange('add', port, relativePath)\n )\n output.watcher.on('source:change', ({ relativePath }) =>\n this.#handleSourceFileChange('update', port, relativePath)\n )\n output.watcher.on('source:unlink', ({ relativePath }) =>\n this.#handleSourceFileChange('delete', port, relativePath)\n )\n\n /**\n * Changes in non-TypeScript source files\n */\n output.watcher.on('add', ({ relativePath }) =>\n this.#handleFileChange('add', port, relativePath)\n )\n output.watcher.on('change', ({ relativePath }) =>\n this.#handleFileChange('update', port, relativePath)\n )\n output.watcher.on('unlink', ({ relativePath }) =>\n this.#handleFileChange('delete', port, relativePath)\n )\n }\n}\n"],"mappings":";AASA,OAAO,WAAW;AAClB,OAAO,YAAY;AACnB,OAAO,QAAQ;AAEf,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,QAAAC,OAAM,YAAAC,iBAAgB;AAC/B,SAAS,aAA0B;AACnC,SAAS,4BAA4B;;;ACVrC,SAAS,wBAAwB;AACjC,OAAO,WAAW;AAEX,IAAM,iBAAN,MAAqB;AAAA,EAC1B;AAAA,EAEA,SAAS,IAAI,MAKV;AAAA,EAEH,YAAY,QAAsC;AAChD,SAAK,UAAU;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,iBAAiB,MAA8B;AACnD,UAAM,UAAU,MAAM,KAAK;AAE3B,QAAI,CAAC,QAAQ,SAAS;AACpB,YAAM,IAAI,iBAAiB,yDAAyD;AAAA,IACtF;AAEA,WAAO,QAAQ;AAAA,EACjB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,yBAAyB;AAC7B,UAAM,QAAQ,IAAI;AAAA,MAChB,KAAK,SAAS,oBAAoB;AAAA,QAAI,OAAO,SAC3C,KAAK,OAAO,IAAI,sBAAsB,MAAM,KAAK,iBAAiB,IAAI,CAAC;AAAA,MACzE;AAAA,MACA,KAAK,SAAS,qBAAqB;AAAA,QAAI,OAAO,SAC5C,KAAK,OAAO,IAAI,uBAAuB,MAAM,KAAK,iBAAiB,IAAI,CAAC;AAAA,MAC1E;AAAA,IACF,CAAC;AAAA,EACH;AAAA;AAAA;A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;AACX,WAAK,WAAW,CAAC;AACjB;AAAA,IACF;AAMA,SAAK,WAAW,OAAO;AAKvB,WAAO,QAAQ,GAAG,iBAAiB,MAAM;AACvC,WAAK,QAAQ,KAAK,qCAAqC;AAAA,IACzD,CAAC;AAKD,WAAO,SAAS,GAAG,SAAS,CAAC,UAAU;AACrC,WAAK,QAAQ,QAAQ,6BAA6B;AAClD,WAAK,QAAQ,MAAM,KAAK;AACxB,WAAK,WAAW,KAAK;AACrB,aAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAKD,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAc,CAAC,EAAE,aAAa,MAC9C,KAAK,wBAAwB,OAAO,MAAM,YAAY;AAAA,IACxD;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAiB,CAAC,EAAE,aAAa,MACjD,KAAK,wBAAwB,UAAU,MAAM,YAAY;AAAA,IAC3D;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAiB,CAAC,EAAE,aAAa,MACjD,KAAK,wBAAwB,UAAU,MAAM,YAAY;AAAA,IAC3D;AAKA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAO,CAAC,EAAE,aAAa,MACvC,KAAK,kBAAkB,OAAO,MAAM,YAAY;AAAA,IAClD;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAU,CAAC,EAAE,aAAa,MAC1C,KAAK,kBAAkB,UAAU,MAAM,YAAY;AAAA,IACrD;AACA,WAAO,QAAQ;AAAA,MAAG;AAAA,MAAU,CAAC,EAAE,aAAa,MAC1C,KAAK,kBAAkB,UAAU,MAAM,YAAY;AAAA,IACrD;AAAA,EACF;AACF;","names":["fileURLToPath","join","relative","fileURLToPath","relative","join","cliui","cliui","ui","cliui","ui","cliui","picomatch","cliui","ui","cliui","picomatch"]}
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import { installPackage, detectPackageManager } from '@antfu/install-pkg';
3
+ import { Project } from 'ts-morph';
3
4
  import { RcFileTransformer } from './rc_file_transformer.js';
4
5
  import type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '../types.js';
5
6
  /**
@@ -13,6 +14,10 @@ export declare class CodeTransformer {
13
14
  */
14
15
  installPackage: typeof installPackage;
15
16
  detectPackageManager: typeof detectPackageManager;
17
+ /**
18
+ * The TsMorph project
19
+ */
20
+ project: Project;
16
21
  constructor(cwd: URL);
17
22
  /**
18
23
  * Add new env variable validation in the
@@ -40,6 +45,14 @@ export declare class CodeTransformer {
40
45
  module: string;
41
46
  identifier: string;
42
47
  }[]): Promise<void>;
48
+ /**
49
+ * Add a new Vite plugin
50
+ */
51
+ addVitePlugin(pluginCall: string, importDeclarations: {
52
+ isNamed: boolean;
53
+ module: string;
54
+ identifier: string;
55
+ }[]): Promise<void>;
43
56
  /**
44
57
  * Adds a policy to the list of `policies` object configured
45
58
  * inside the `app/policies/main.ts` file.
@@ -273,7 +273,7 @@ var CodeTransformer = class {
273
273
  /**
274
274
  * The TsMorph project
275
275
  */
276
- #project;
276
+ project;
277
277
  /**
278
278
  * Settings to use when persisting files
279
279
  */
@@ -288,7 +288,7 @@ var CodeTransformer = class {
288
288
  };
289
289
  constructor(cwd) {
290
290
  this.#cwd = cwd;
291
- this.#project = new Project2({
291
+ this.project = new Project2({
292
292
  tsConfigFilePath: join(fileURLToPath2(this.#cwd), "tsconfig.json"),
293
293
  manipulationSettings: { quoteKind: QuoteKind.Single }
294
294
  });
@@ -348,6 +348,31 @@ var CodeTransformer = class {
348
348
  policiesObject.insertProperty(0, policy);
349
349
  }
350
350
  }
351
+ /**
352
+ * Add the given import declarations to the source file
353
+ * and merge named imports with the existing import
354
+ */
355
+ #addImportDeclarations(file, importDeclarations) {
356
+ const existingImports = file.getImportDeclarations();
357
+ importDeclarations.forEach((importDeclaration) => {
358
+ const existingImport = existingImports.find(
359
+ (mod) => mod.getModuleSpecifierValue() === importDeclaration.module
360
+ );
361
+ if (existingImport && importDeclaration.isNamed) {
362
+ if (!existingImport.getNamedImports().find((namedImport) => namedImport.getName() === importDeclaration.identifier)) {
363
+ existingImport.addNamedImport(importDeclaration.identifier);
364
+ }
365
+ return;
366
+ }
367
+ if (existingImport) {
368
+ return;
369
+ }
370
+ file.addImportDeclaration({
371
+ ...importDeclaration.isNamed ? { namedImports: [importDeclaration.identifier] } : { defaultImport: importDeclaration.identifier },
372
+ moduleSpecifier: importDeclaration.module
373
+ });
374
+ });
375
+ }
351
376
  /**
352
377
  * Write a leading comment
353
378
  */
@@ -363,7 +388,7 @@ var CodeTransformer = class {
363
388
  */
364
389
  async defineEnvValidations(definition) {
365
390
  const kernelUrl = fileURLToPath2(new URL("./start/env.ts", this.#cwd));
366
- const file = this.#project.getSourceFileOrThrow(kernelUrl);
391
+ const file = this.project.getSourceFileOrThrow(kernelUrl);
367
392
  const callExpressions = file.getDescendantsOfKind(SyntaxKind2.CallExpression).filter((statement) => statement.getExpression().getText() === "Env.create");
368
393
  if (!callExpressions.length) {
369
394
  throw new Error(`Cannot find Env.create statement in the file.`);
@@ -405,7 +430,7 @@ var CodeTransformer = class {
405
430
  */
406
431
  async addMiddlewareToStack(stack, middleware) {
407
432
  const kernelUrl = fileURLToPath2(new URL("./start/kernel.ts", this.#cwd));
408
- const file = this.#project.getSourceFileOrThrow(kernelUrl);
433
+ const file = this.project.getSourceFileOrThrow(kernelUrl);
409
434
  for (const middlewareEntry of middleware) {
410
435
  if (stack === "named") {
411
436
  this.#addToNamedMiddleware(file, middlewareEntry);
@@ -420,7 +445,7 @@ var CodeTransformer = class {
420
445
  * Update the `adonisrc.ts` file
421
446
  */
422
447
  async updateRcFile(callback) {
423
- const rcFileTransformer = new RcFileTransformer(this.#cwd, this.#project);
448
+ const rcFileTransformer = new RcFileTransformer(this.#cwd, this.project);
424
449
  callback(rcFileTransformer);
425
450
  await rcFileTransformer.save();
426
451
  }
@@ -429,26 +454,8 @@ var CodeTransformer = class {
429
454
  */
430
455
  async addJapaPlugin(pluginCall, importDeclarations) {
431
456
  const testBootstrapUrl = fileURLToPath2(new URL("./tests/bootstrap.ts", this.#cwd));
432
- const file = this.#project.getSourceFileOrThrow(testBootstrapUrl);
433
- const existingImports = file.getImportDeclarations();
434
- importDeclarations.forEach((importDeclaration) => {
435
- const existingImport = existingImports.find(
436
- (mod) => mod.getModuleSpecifierValue() === importDeclaration.module
437
- );
438
- if (existingImport && importDeclaration.isNamed) {
439
- if (!existingImport.getNamedImports().find((namedImport) => namedImport.getName() === importDeclaration.identifier)) {
440
- existingImport.addNamedImport(importDeclaration.identifier);
441
- }
442
- return;
443
- }
444
- if (existingImport) {
445
- return;
446
- }
447
- file.addImportDeclaration({
448
- ...importDeclaration.isNamed ? { namedImports: [importDeclaration.identifier] } : { defaultImport: importDeclaration.identifier },
449
- moduleSpecifier: importDeclaration.module
450
- });
451
- });
457
+ const file = this.project.getSourceFileOrThrow(testBootstrapUrl);
458
+ this.#addImportDeclarations(file, importDeclarations);
452
459
  const pluginsArray = file.getVariableDeclaration("plugins")?.getInitializerIfKind(SyntaxKind2.ArrayLiteralExpression);
453
460
  if (pluginsArray) {
454
461
  if (!pluginsArray.getElements().find((element) => element.getText() === pluginCall)) {
@@ -458,13 +465,37 @@ var CodeTransformer = class {
458
465
  file.formatText(this.#editorSettings);
459
466
  await file.save();
460
467
  }
468
+ /**
469
+ * Add a new Vite plugin
470
+ */
471
+ async addVitePlugin(pluginCall, importDeclarations) {
472
+ const viteConfigTsUrl = fileURLToPath2(new URL("./vite.config.ts", this.#cwd));
473
+ const file = this.project.getSourceFile(viteConfigTsUrl);
474
+ if (!file) {
475
+ throw new Error(
476
+ "Cannot find vite.config.ts file. Make sure to rename vite.config.js to vite.config.ts"
477
+ );
478
+ }
479
+ this.#addImportDeclarations(file, importDeclarations);
480
+ const defaultExport = file.getDefaultExportSymbol();
481
+ if (!defaultExport) {
482
+ throw new Error("Cannot find the default export in vite.config.ts");
483
+ }
484
+ const options = defaultExport.getDeclarations()[0].getChildrenOfKind(SyntaxKind2.ObjectLiteralExpression)[0];
485
+ const pluginsArray = options.getPropertyOrThrow("plugins").getFirstChildByKindOrThrow(SyntaxKind2.ArrayLiteralExpression);
486
+ if (!pluginsArray.getElements().find((element) => element.getText() === pluginCall)) {
487
+ pluginsArray.addElement(pluginCall);
488
+ }
489
+ file.formatText(this.#editorSettings);
490
+ await file.save();
491
+ }
461
492
  /**
462
493
  * Adds a policy to the list of `policies` object configured
463
494
  * inside the `app/policies/main.ts` file.
464
495
  */
465
496
  async addPolicies(policies) {
466
497
  const kernelUrl = fileURLToPath2(new URL("./app/policies/main.ts", this.#cwd));
467
- const file = this.#project.getSourceFileOrThrow(kernelUrl);
498
+ const file = this.project.getSourceFileOrThrow(kernelUrl);
468
499
  for (const policy of policies) {
469
500
  this.#addToPoliciesList(file, policy);
470
501
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/code_transformer/main.ts","../../../src/code_transformer/rc_file_transformer.ts"],"sourcesContent":["/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { installPackage, detectPackageManager } from '@antfu/install-pkg'\nimport {\n Node,\n Project,\n QuoteKind,\n SourceFile,\n SyntaxKind,\n CodeBlockWriter,\n FormatCodeSettings,\n} from 'ts-morph'\n\nimport { RcFileTransformer } from './rc_file_transformer.js'\nimport type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '../types.js'\n\n/**\n * This class is responsible for updating\n */\nexport class CodeTransformer {\n /**\n * Exporting utilities to install package and detect\n * the package manager\n */\n installPackage = installPackage\n detectPackageManager = detectPackageManager\n\n /**\n * Directory of the adonisjs project\n */\n #cwd: URL\n\n /**\n * The TsMorph project\n */\n #project: Project\n\n /**\n * Settings to use when persisting files\n */\n #editorSettings: FormatCodeSettings = {\n indentSize: 2,\n convertTabsToSpaces: true,\n trimTrailingWhitespace: true,\n ensureNewLineAtEndOfFile: true,\n indentStyle: 2,\n // @ts-expect-error SemicolonPreference doesn't seem to be re-exported from ts-morph\n semicolons: 'remove',\n }\n\n constructor(cwd: URL) {\n this.#cwd = cwd\n this.#project = new Project({\n tsConfigFilePath: join(fileURLToPath(this.#cwd), 'tsconfig.json'),\n manipulationSettings: { quoteKind: QuoteKind.Single },\n })\n }\n\n /**\n * Add a new middleware to the middleware array of the\n * given file\n */\n #addToMiddlewareArray(file: SourceFile, target: string, middlewareEntry: MiddlewareNode) {\n const callExpressions = file\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((statement) => statement.getExpression().getText() === target)\n\n if (!callExpressions.length) {\n throw new Error(`Cannot find ${target} statement in the file.`)\n }\n\n const arrayLiteralExpression = callExpressions[0].getArguments()[0]\n if (!arrayLiteralExpression || !Node.isArrayLiteralExpression(arrayLiteralExpression)) {\n throw new Error(`Cannot find middleware array in ${target} statement.`)\n }\n\n const middleware = `() => import('${middlewareEntry.path}')`\n\n /**\n * Delete the existing middleware if it exists\n */\n const existingMiddlewareIndex = arrayLiteralExpression\n .getElements()\n .findIndex((element) => element.getText() === middleware)\n\n if (existingMiddlewareIndex === -1) {\n /**\n * Add the middleware to the top or bottom of the array\n */\n if (middlewareEntry.position === 'before') {\n arrayLiteralExpression.insertElement(0, middleware)\n } else {\n arrayLiteralExpression.addElement(middleware)\n }\n }\n }\n\n /**\n * Add a new middleware to the named middleware of the given file\n */\n #addToNamedMiddleware(file: SourceFile, middlewareEntry: MiddlewareNode) {\n if (!middlewareEntry.name) {\n throw new Error('Named middleware requires a name.')\n }\n\n const callArguments = file\n .getVariableDeclarationOrThrow('middleware')\n .getInitializerIfKindOrThrow(SyntaxKind.CallExpression)\n .getArguments()\n\n if (callArguments.length === 0) {\n throw new Error('Named middleware call has no arguments.')\n }\n\n const namedMiddlewareObject = callArguments[0]\n if (!Node.isObjectLiteralExpression(namedMiddlewareObject)) {\n throw new Error('The argument of the named middleware call is not an object literal.')\n }\n\n /**\n * Check if property is already defined. If so, remove it\n */\n const existingProperty = namedMiddlewareObject.getProperty(middlewareEntry.name)\n if (!existingProperty) {\n /**\n * Add the named middleware\n */\n const middleware = `${middlewareEntry.name}: () => import('${middlewareEntry.path}')`\n namedMiddlewareObject!.insertProperty(0, middleware)\n }\n }\n\n /**\n * Add a policy to the list of pre-registered policy\n */\n #addToPoliciesList(file: SourceFile, policyEntry: BouncerPolicyNode) {\n const policiesObject = file\n .getVariableDeclarationOrThrow('policies')\n .getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\n /**\n * Only define policy when one with the existing name does not\n * exist.\n */\n const existingProperty = policiesObject.getProperty(policyEntry.name)\n if (!existingProperty) {\n const policy = `${policyEntry.name}: () => import('${policyEntry.path}')`\n policiesObject!.insertProperty(0, policy)\n }\n }\n\n /**\n * Write a leading comment\n */\n #addLeadingComment(writer: CodeBlockWriter, comment?: string) {\n if (!comment) {\n return writer.blankLine()\n }\n\n return writer\n .blankLine()\n .writeLine('/*')\n .writeLine(`|----------------------------------------------------------`)\n .writeLine(`| ${comment}`)\n .writeLine(`|----------------------------------------------------------`)\n .writeLine(`*/`)\n }\n\n /**\n * Add new env variable validation in the\n * `env.ts` file\n */\n async defineEnvValidations(definition: EnvValidationNode) {\n /**\n * Get the `start/env.ts` source file\n */\n const kernelUrl = fileURLToPath(new URL('./start/env.ts', this.#cwd))\n const file = this.#project.getSourceFileOrThrow(kernelUrl)\n\n /**\n * Get the `Env.create` call expression\n */\n const callExpressions = file\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((statement) => statement.getExpression().getText() === 'Env.create')\n\n if (!callExpressions.length) {\n throw new Error(`Cannot find Env.create statement in the file.`)\n }\n\n const objectLiteralExpression = callExpressions[0].getArguments()[1]\n if (!Node.isObjectLiteralExpression(objectLiteralExpression)) {\n throw new Error(`The second argument of Env.create is not an object literal.`)\n }\n\n let shouldAddComment = true\n\n /**\n * Add each variable validation\n */\n for (const [variable, validation] of Object.entries(definition.variables)) {\n /**\n * Check if the variable is already defined. If so, remove it\n */\n const existingProperty = objectLiteralExpression.getProperty(variable)\n\n /**\n * Do not add leading comment if one or more properties\n * already exists\n */\n if (existingProperty) {\n shouldAddComment = false\n }\n\n /**\n * Add property only when the property does not exist\n */\n if (!existingProperty) {\n objectLiteralExpression.addPropertyAssignment({\n name: variable,\n initializer: validation,\n leadingTrivia: (writer) => {\n if (!shouldAddComment) {\n return\n }\n\n shouldAddComment = false\n return this.#addLeadingComment(writer, definition.leadingComment)\n },\n })\n }\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Define new middlewares inside the `start/kernel.ts`\n * file\n *\n * This function is highly based on some assumptions\n * and will not work if you significantly tweaked\n * your `start/kernel.ts` file.\n */\n async addMiddlewareToStack(stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[]) {\n /**\n * Get the `start/kernel.ts` source file\n */\n const kernelUrl = fileURLToPath(new URL('./start/kernel.ts', this.#cwd))\n const file = this.#project.getSourceFileOrThrow(kernelUrl)\n\n /**\n * Process each middleware entry\n */\n for (const middlewareEntry of middleware) {\n if (stack === 'named') {\n this.#addToNamedMiddleware(file, middlewareEntry)\n } else {\n this.#addToMiddlewareArray(file!, `${stack}.use`, middlewareEntry)\n }\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Update the `adonisrc.ts` file\n */\n async updateRcFile(callback: (transformer: RcFileTransformer) => void) {\n const rcFileTransformer = new RcFileTransformer(this.#cwd, this.#project)\n callback(rcFileTransformer)\n await rcFileTransformer.save()\n }\n\n /**\n * Add a new Japa plugin in the `tests/bootstrap.ts` file\n */\n async addJapaPlugin(\n pluginCall: string,\n importDeclarations: { isNamed: boolean; module: string; identifier: string }[]\n ) {\n /**\n * Get the `tests/bootstrap.ts` source file\n */\n const testBootstrapUrl = fileURLToPath(new URL('./tests/bootstrap.ts', this.#cwd))\n const file = this.#project.getSourceFileOrThrow(testBootstrapUrl)\n\n /**\n * Add the import declaration\n */\n const existingImports = file.getImportDeclarations()\n\n importDeclarations.forEach((importDeclaration) => {\n const existingImport = existingImports.find(\n (mod) => mod.getModuleSpecifierValue() === importDeclaration.module\n )\n\n /**\n * Add a new named import to existing import for the\n * same module\n */\n if (existingImport && importDeclaration.isNamed) {\n if (\n !existingImport\n .getNamedImports()\n .find((namedImport) => namedImport.getName() === importDeclaration.identifier)\n ) {\n existingImport.addNamedImport(importDeclaration.identifier)\n }\n return\n }\n\n /**\n * Ignore default import when the same module is already imported.\n * The chances are the existing default import and the importDeclaration\n * identifiers are not the same. But we should not modify existing source\n */\n if (existingImport) {\n return\n }\n\n file.addImportDeclaration({\n ...(importDeclaration.isNamed\n ? { namedImports: [importDeclaration.identifier] }\n : { defaultImport: importDeclaration.identifier }),\n moduleSpecifier: importDeclaration.module,\n })\n })\n\n /**\n * Insert the plugin call in the `plugins` array\n */\n const pluginsArray = file\n .getVariableDeclaration('plugins')\n ?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Add plugin call to the plugins array\n */\n if (pluginsArray) {\n if (!pluginsArray.getElements().find((element) => element.getText() === pluginCall)) {\n pluginsArray.addElement(pluginCall)\n }\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Adds a policy to the list of `policies` object configured\n * inside the `app/policies/main.ts` file.\n */\n async addPolicies(policies: BouncerPolicyNode[]) {\n /**\n * Get the `app/policies/main.ts` source file\n */\n const kernelUrl = fileURLToPath(new URL('./app/policies/main.ts', this.#cwd))\n const file = this.#project.getSourceFileOrThrow(kernelUrl)\n\n /**\n * Process each middleware entry\n */\n for (const policy of policies) {\n this.#addToPoliciesList(file, policy)\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport type { AppEnvironments } from '@adonisjs/application/types'\nimport {\n Node,\n Project,\n SourceFile,\n SyntaxKind,\n CallExpression,\n PropertyAssignment,\n FormatCodeSettings,\n ArrayLiteralExpression,\n} from 'ts-morph'\n\n/**\n * RcFileTransformer is used to transform the `adonisrc.ts` file\n * for adding new commands, providers, meta files etc\n */\nexport class RcFileTransformer {\n #cwd: URL\n #project: Project\n\n /**\n * Settings to use when persisting files\n */\n #editorSettings: FormatCodeSettings = {\n indentSize: 2,\n convertTabsToSpaces: true,\n trimTrailingWhitespace: true,\n ensureNewLineAtEndOfFile: true,\n indentStyle: 2,\n // @ts-expect-error SemicolonPreference doesn't seem to be re-exported from ts-morph\n semicolons: 'remove',\n }\n\n constructor(cwd: URL, project: Project) {\n this.#cwd = cwd\n this.#project = project\n }\n\n /**\n * Get the `adonisrc.ts` source file\n */\n #getRcFileOrThrow() {\n const kernelUrl = fileURLToPath(new URL('./adonisrc.ts', this.#cwd))\n return this.#project.getSourceFileOrThrow(kernelUrl)\n }\n\n /**\n * Check if environments array has a subset of available environments\n */\n #isInSpecificEnvironment(environments?: AppEnvironments[]): boolean {\n if (!environments) {\n return false\n }\n\n return !!(['web', 'console', 'test', 'repl'] as const).find(\n (env) => !environments.includes(env)\n )\n }\n\n /**\n * Locate the `defineConfig` call inside the `adonisrc.ts` file\n */\n #locateDefineConfigCallOrThrow(file: SourceFile) {\n const call = file\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((statement) => statement.getExpression().getText() === 'defineConfig')\n\n if (!call) {\n throw new Error('Could not locate the defineConfig call.')\n }\n\n return call\n }\n\n /**\n * Return the ObjectLiteralExpression of the defineConfig call\n */\n #getDefineConfigObjectOrThrow(defineConfigCall: CallExpression) {\n const configObject = defineConfigCall\n .getArguments()[0]\n .asKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\n return configObject\n }\n\n /**\n * Check if the defineConfig() call has the property assignment\n * inside it or not. If not, it will create one and return it.\n */\n #getPropertyAssignmentInDefineConfigCall(propertyName: string, initializer: string) {\n const file = this.#getRcFileOrThrow()\n const defineConfigCall = this.#locateDefineConfigCallOrThrow(file)\n const configObject = this.#getDefineConfigObjectOrThrow(defineConfigCall)\n\n let property = configObject.getProperty(propertyName)\n\n if (!property) {\n configObject.addPropertyAssignment({ name: propertyName, initializer })\n property = configObject.getProperty(propertyName)\n }\n\n return property as PropertyAssignment\n }\n\n /**\n * Extract list of imported modules from an ArrayLiteralExpression\n *\n * It assumes that the array can have two types of elements:\n *\n * - Simple lazy imported modules: [() => import('path/to/file')]\n * - Or an object entry: [{ file: () => import('path/to/file'), environment: ['web', 'console'] }]\n * where the `file` property is a lazy imported module.\n */\n #extractModulesFromArray(array: ArrayLiteralExpression) {\n const modules = array.getElements().map((element) => {\n /**\n * Simple lazy imported module\n */\n if (Node.isArrowFunction(element)) {\n const importExp = element.getFirstDescendantByKindOrThrow(SyntaxKind.CallExpression)\n const literal = importExp.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral)\n return literal.getLiteralValue()\n }\n\n /**\n * Object entry\n */\n if (Node.isObjectLiteralExpression(element)) {\n const fileProp = element.getPropertyOrThrow('file') as PropertyAssignment\n const arrowFn = fileProp.getFirstDescendantByKindOrThrow(SyntaxKind.ArrowFunction)\n const importExp = arrowFn.getFirstDescendantByKindOrThrow(SyntaxKind.CallExpression)\n const literal = importExp.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral)\n return literal.getLiteralValue()\n }\n })\n\n return modules.filter(Boolean) as string[]\n }\n\n /**\n * Extract a specific property from an ArrayLiteralExpression\n * that contains object entries.\n *\n * This function is mainly used for extractring the `pattern` property\n * when adding a new meta files entry, or the `name` property when\n * adding a new test suite.\n */\n #extractPropertyFromArray(array: ArrayLiteralExpression, propertyName: string) {\n const property = array.getElements().map((el) => {\n if (!Node.isObjectLiteralExpression(el)) return\n\n const nameProp = el.getPropertyOrThrow(propertyName)\n if (!Node.isPropertyAssignment(nameProp)) return\n\n const name = nameProp.getInitializerIfKindOrThrow(SyntaxKind.StringLiteral)\n return name.getLiteralValue()\n })\n\n return property.filter(Boolean) as string[]\n }\n\n /**\n * Build a new module entry for the preloads and providers array\n * based upon the environments specified\n */\n #buildNewModuleEntry(modulePath: string, environments?: AppEnvironments[]) {\n if (!this.#isInSpecificEnvironment(environments)) {\n return `() => import('${modulePath}')`\n }\n\n return `{\n file: () => import('${modulePath}'),\n environment: [${environments?.map((env) => `'${env}'`).join(', ')}],\n }`\n }\n\n /**\n * Add a new command to the rcFile\n */\n addCommand(commandPath: string) {\n const commandsProperty = this.#getPropertyAssignmentInDefineConfigCall('commands', '[]')\n const commandsArray = commandsProperty.getInitializerIfKindOrThrow(\n SyntaxKind.ArrayLiteralExpression\n )\n\n const commandString = `() => import('${commandPath}')`\n\n /**\n * If the command already exists, do nothing\n */\n if (commandsArray.getElements().some((el) => el.getText() === commandString)) {\n return this\n }\n\n /**\n * Add the command to the array\n */\n commandsArray.addElement(commandString)\n return this\n }\n\n /**\n * Add a new preloaded file to the rcFile\n */\n addPreloadFile(modulePath: string, environments?: AppEnvironments[]) {\n const preloadsProperty = this.#getPropertyAssignmentInDefineConfigCall('preloads', '[]')\n const preloadsArray = preloadsProperty.getInitializerIfKindOrThrow(\n SyntaxKind.ArrayLiteralExpression\n )\n\n /**\n * Check for duplicates\n */\n const existingPreloadedFiles = this.#extractModulesFromArray(preloadsArray)\n const isDuplicate = existingPreloadedFiles.includes(modulePath)\n if (isDuplicate) {\n return this\n }\n\n /**\n * Add the preloaded file to the array\n */\n preloadsArray.addElement(this.#buildNewModuleEntry(modulePath, environments))\n return this\n }\n\n /**\n * Add a new provider to the rcFile\n */\n addProvider(providerPath: string, environments?: AppEnvironments[]) {\n const property = this.#getPropertyAssignmentInDefineConfigCall('providers', '[]')\n const providersArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Check for duplicates\n */\n const existingProviderPaths = this.#extractModulesFromArray(providersArray)\n const isDuplicate = existingProviderPaths.includes(providerPath)\n if (isDuplicate) {\n return this\n }\n\n /**\n * Add the provider to the array\n */\n providersArray.addElement(this.#buildNewModuleEntry(providerPath, environments))\n\n return this\n }\n\n /**\n * Add a new meta file to the rcFile\n */\n addMetaFile(globPattern: string, reloadServer = false) {\n const property = this.#getPropertyAssignmentInDefineConfigCall('metaFiles', '[]')\n const metaFilesArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Check for duplicates\n */\n const alreadyDefinedPatterns = this.#extractPropertyFromArray(metaFilesArray, 'pattern')\n if (alreadyDefinedPatterns.includes(globPattern)) {\n return this\n }\n\n /**\n * Add the meta file to the array\n */\n metaFilesArray.addElement(\n `{\n pattern: '${globPattern}',\n reloadServer: ${reloadServer},\n }`\n )\n\n return this\n }\n\n /**\n * Set directory name and path\n */\n setDirectory(key: string, value: string) {\n const property = this.#getPropertyAssignmentInDefineConfigCall('directories', '{}')\n const directories = property.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n directories.addPropertyAssignment({ name: key, initializer: `'${value}'` })\n\n return this\n }\n\n /**\n * Set command alias\n */\n setCommandAlias(alias: string, command: string) {\n const aliasProperty = this.#getPropertyAssignmentInDefineConfigCall('commandsAliases', '{}')\n const aliases = aliasProperty.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n aliases.addPropertyAssignment({ name: alias, initializer: `'${command}'` })\n\n return this\n }\n\n /**\n * Add a new test suite to the rcFile\n */\n addSuite(suiteName: string, files: string | string[], timeout?: number) {\n const testProperty = this.#getPropertyAssignmentInDefineConfigCall(\n 'tests',\n `{ suites: [], forceExit: true, timeout: 2000 }`\n )\n\n const property = testProperty\n .getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n .getPropertyOrThrow('suites') as PropertyAssignment\n\n const suitesArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Check for duplicates\n */\n const existingSuitesNames = this.#extractPropertyFromArray(suitesArray, 'name')\n if (existingSuitesNames.includes(suiteName)) {\n return this\n }\n\n /**\n * Add the suite to the array\n */\n const filesArray = Array.isArray(files) ? files : [files]\n suitesArray.addElement(\n `{\n name: '${suiteName}',\n files: [${filesArray.map((file) => `'${file}'`).join(', ')}],\n timeout: ${timeout ?? 2000},\n }`\n )\n\n return this\n }\n\n /**\n * Save the adonisrc.ts file\n */\n save() {\n const file = this.#getRcFileOrThrow()\n file.formatText(this.#editorSettings)\n return file.save()\n }\n}\n"],"mappings":";AASA,SAAS,YAAY;AACrB,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,gBAAgB,4BAA4B;AACrD;AAAA,EACE,QAAAC;AAAA,EACA,WAAAC;AAAA,EACA;AAAA,EAEA,cAAAC;AAAA,OAGK;;;ACXP,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EAGA;AAAA,OAKK;AAMA,IAAM,oBAAN,MAAwB;AAAA,EAC7B;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAsC;AAAA,IACpC,YAAY;AAAA,IACZ,qBAAqB;AAAA,IACrB,wBAAwB;AAAA,IACxB,0BAA0B;AAAA,IAC1B,aAAa;AAAA;AAAA,IAEb,YAAY;AAAA,EACd;AAAA,EAEA,YAAY,KAAU,SAAkB;AACtC,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,oBAAoB;AAClB,UAAM,YAAY,cAAc,IAAI,IAAI,iBAAiB,KAAK,IAAI,CAAC;AACnE,WAAO,KAAK,SAAS,qBAAqB,SAAS;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA,EAKA,yBAAyB,cAA2C;AAClE,QAAI,CAAC,cAAc;AACjB,aAAO;AAAA,IACT;AAEA,WAAO,CAAC,CAAE,CAAC,OAAO,WAAW,QAAQ,MAAM,EAAY;AAAA,MACrD,CAAC,QAAQ,CAAC,aAAa,SAAS,GAAG;AAAA,IACrC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,+BAA+B,MAAkB;AAC/C,UAAM,OAAO,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AM,OAAO,KAAK,SAAS,qBAAqB,SAAS;AAKzD,eAAW,UAAU,UAAU;AAC7B,WAAK,mBAAmB,MAAM,MAAM;AAAA,IACtC;AAEA,SAAK,WAAW,KAAK,eAAe;AACpC,UAAM,KAAK,KAAK;AAAA,EAClB;AACF;","names":["fileURLToPath","Node","Project","SyntaxKind","Project","fileURLToPath","SyntaxKind","Node"]}
1
+ {"version":3,"sources":["../../../src/code_transformer/main.ts","../../../src/code_transformer/rc_file_transformer.ts"],"sourcesContent":["/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { installPackage, detectPackageManager } from '@antfu/install-pkg'\nimport {\n Node,\n Project,\n QuoteKind,\n SourceFile,\n SyntaxKind,\n CodeBlockWriter,\n FormatCodeSettings,\n} from 'ts-morph'\n\nimport { RcFileTransformer } from './rc_file_transformer.js'\nimport type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '../types.js'\n\n/**\n * This class is responsible for updating\n */\nexport class CodeTransformer {\n /**\n * Exporting utilities to install package and detect\n * the package manager\n */\n installPackage = installPackage\n detectPackageManager = detectPackageManager\n\n /**\n * Directory of the adonisjs project\n */\n #cwd: URL\n\n /**\n * The TsMorph project\n */\n project: Project\n\n /**\n * Settings to use when persisting files\n */\n #editorSettings: FormatCodeSettings = {\n indentSize: 2,\n convertTabsToSpaces: true,\n trimTrailingWhitespace: true,\n ensureNewLineAtEndOfFile: true,\n indentStyle: 2,\n // @ts-expect-error SemicolonPreference doesn't seem to be re-exported from ts-morph\n semicolons: 'remove',\n }\n\n constructor(cwd: URL) {\n this.#cwd = cwd\n this.project = new Project({\n tsConfigFilePath: join(fileURLToPath(this.#cwd), 'tsconfig.json'),\n manipulationSettings: { quoteKind: QuoteKind.Single },\n })\n }\n\n /**\n * Add a new middleware to the middleware array of the\n * given file\n */\n #addToMiddlewareArray(file: SourceFile, target: string, middlewareEntry: MiddlewareNode) {\n const callExpressions = file\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((statement) => statement.getExpression().getText() === target)\n\n if (!callExpressions.length) {\n throw new Error(`Cannot find ${target} statement in the file.`)\n }\n\n const arrayLiteralExpression = callExpressions[0].getArguments()[0]\n if (!arrayLiteralExpression || !Node.isArrayLiteralExpression(arrayLiteralExpression)) {\n throw new Error(`Cannot find middleware array in ${target} statement.`)\n }\n\n const middleware = `() => import('${middlewareEntry.path}')`\n\n /**\n * Delete the existing middleware if it exists\n */\n const existingMiddlewareIndex = arrayLiteralExpression\n .getElements()\n .findIndex((element) => element.getText() === middleware)\n\n if (existingMiddlewareIndex === -1) {\n /**\n * Add the middleware to the top or bottom of the array\n */\n if (middlewareEntry.position === 'before') {\n arrayLiteralExpression.insertElement(0, middleware)\n } else {\n arrayLiteralExpression.addElement(middleware)\n }\n }\n }\n\n /**\n * Add a new middleware to the named middleware of the given file\n */\n #addToNamedMiddleware(file: SourceFile, middlewareEntry: MiddlewareNode) {\n if (!middlewareEntry.name) {\n throw new Error('Named middleware requires a name.')\n }\n\n const callArguments = file\n .getVariableDeclarationOrThrow('middleware')\n .getInitializerIfKindOrThrow(SyntaxKind.CallExpression)\n .getArguments()\n\n if (callArguments.length === 0) {\n throw new Error('Named middleware call has no arguments.')\n }\n\n const namedMiddlewareObject = callArguments[0]\n if (!Node.isObjectLiteralExpression(namedMiddlewareObject)) {\n throw new Error('The argument of the named middleware call is not an object literal.')\n }\n\n /**\n * Check if property is already defined. If so, remove it\n */\n const existingProperty = namedMiddlewareObject.getProperty(middlewareEntry.name)\n if (!existingProperty) {\n /**\n * Add the named middleware\n */\n const middleware = `${middlewareEntry.name}: () => import('${middlewareEntry.path}')`\n namedMiddlewareObject!.insertProperty(0, middleware)\n }\n }\n\n /**\n * Add a policy to the list of pre-registered policy\n */\n #addToPoliciesList(file: SourceFile, policyEntry: BouncerPolicyNode) {\n const policiesObject = file\n .getVariableDeclarationOrThrow('policies')\n .getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\n /**\n * Only define policy when one with the existing name does not\n * exist.\n */\n const existingProperty = policiesObject.getProperty(policyEntry.name)\n if (!existingProperty) {\n const policy = `${policyEntry.name}: () => import('${policyEntry.path}')`\n policiesObject!.insertProperty(0, policy)\n }\n }\n\n /**\n * Add the given import declarations to the source file\n * and merge named imports with the existing import\n */\n #addImportDeclarations(\n file: SourceFile,\n importDeclarations: { isNamed: boolean; module: string; identifier: string }[]\n ) {\n const existingImports = file.getImportDeclarations()\n\n importDeclarations.forEach((importDeclaration) => {\n const existingImport = existingImports.find(\n (mod) => mod.getModuleSpecifierValue() === importDeclaration.module\n )\n\n /**\n * Add a new named import to existing import for the\n * same module\n */\n if (existingImport && importDeclaration.isNamed) {\n if (\n !existingImport\n .getNamedImports()\n .find((namedImport) => namedImport.getName() === importDeclaration.identifier)\n ) {\n existingImport.addNamedImport(importDeclaration.identifier)\n }\n return\n }\n\n /**\n * Ignore default import when the same module is already imported.\n * The chances are the existing default import and the importDeclaration\n * identifiers are not the same. But we should not modify existing source\n */\n if (existingImport) {\n return\n }\n\n file.addImportDeclaration({\n ...(importDeclaration.isNamed\n ? { namedImports: [importDeclaration.identifier] }\n : { defaultImport: importDeclaration.identifier }),\n moduleSpecifier: importDeclaration.module,\n })\n })\n }\n\n /**\n * Write a leading comment\n */\n #addLeadingComment(writer: CodeBlockWriter, comment?: string) {\n if (!comment) {\n return writer.blankLine()\n }\n\n return writer\n .blankLine()\n .writeLine('/*')\n .writeLine(`|----------------------------------------------------------`)\n .writeLine(`| ${comment}`)\n .writeLine(`|----------------------------------------------------------`)\n .writeLine(`*/`)\n }\n\n /**\n * Add new env variable validation in the\n * `env.ts` file\n */\n async defineEnvValidations(definition: EnvValidationNode) {\n /**\n * Get the `start/env.ts` source file\n */\n const kernelUrl = fileURLToPath(new URL('./start/env.ts', this.#cwd))\n const file = this.project.getSourceFileOrThrow(kernelUrl)\n\n /**\n * Get the `Env.create` call expression\n */\n const callExpressions = file\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .filter((statement) => statement.getExpression().getText() === 'Env.create')\n\n if (!callExpressions.length) {\n throw new Error(`Cannot find Env.create statement in the file.`)\n }\n\n const objectLiteralExpression = callExpressions[0].getArguments()[1]\n if (!Node.isObjectLiteralExpression(objectLiteralExpression)) {\n throw new Error(`The second argument of Env.create is not an object literal.`)\n }\n\n let shouldAddComment = true\n\n /**\n * Add each variable validation\n */\n for (const [variable, validation] of Object.entries(definition.variables)) {\n /**\n * Check if the variable is already defined. If so, remove it\n */\n const existingProperty = objectLiteralExpression.getProperty(variable)\n\n /**\n * Do not add leading comment if one or more properties\n * already exists\n */\n if (existingProperty) {\n shouldAddComment = false\n }\n\n /**\n * Add property only when the property does not exist\n */\n if (!existingProperty) {\n objectLiteralExpression.addPropertyAssignment({\n name: variable,\n initializer: validation,\n leadingTrivia: (writer) => {\n if (!shouldAddComment) {\n return\n }\n\n shouldAddComment = false\n return this.#addLeadingComment(writer, definition.leadingComment)\n },\n })\n }\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Define new middlewares inside the `start/kernel.ts`\n * file\n *\n * This function is highly based on some assumptions\n * and will not work if you significantly tweaked\n * your `start/kernel.ts` file.\n */\n async addMiddlewareToStack(stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[]) {\n /**\n * Get the `start/kernel.ts` source file\n */\n const kernelUrl = fileURLToPath(new URL('./start/kernel.ts', this.#cwd))\n const file = this.project.getSourceFileOrThrow(kernelUrl)\n\n /**\n * Process each middleware entry\n */\n for (const middlewareEntry of middleware) {\n if (stack === 'named') {\n this.#addToNamedMiddleware(file, middlewareEntry)\n } else {\n this.#addToMiddlewareArray(file!, `${stack}.use`, middlewareEntry)\n }\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Update the `adonisrc.ts` file\n */\n async updateRcFile(callback: (transformer: RcFileTransformer) => void) {\n const rcFileTransformer = new RcFileTransformer(this.#cwd, this.project)\n callback(rcFileTransformer)\n await rcFileTransformer.save()\n }\n\n /**\n * Add a new Japa plugin in the `tests/bootstrap.ts` file\n */\n async addJapaPlugin(\n pluginCall: string,\n importDeclarations: { isNamed: boolean; module: string; identifier: string }[]\n ) {\n /**\n * Get the `tests/bootstrap.ts` source file\n */\n const testBootstrapUrl = fileURLToPath(new URL('./tests/bootstrap.ts', this.#cwd))\n const file = this.project.getSourceFileOrThrow(testBootstrapUrl)\n\n /**\n * Add the import declarations\n */\n this.#addImportDeclarations(file, importDeclarations)\n\n /**\n * Insert the plugin call in the `plugins` array\n */\n const pluginsArray = file\n .getVariableDeclaration('plugins')\n ?.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Add plugin call to the plugins array\n */\n if (pluginsArray) {\n if (!pluginsArray.getElements().find((element) => element.getText() === pluginCall)) {\n pluginsArray.addElement(pluginCall)\n }\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Add a new Vite plugin\n */\n async addVitePlugin(\n pluginCall: string,\n importDeclarations: { isNamed: boolean; module: string; identifier: string }[]\n ) {\n /**\n * Get the `vite.config.ts` source file\n */\n const viteConfigTsUrl = fileURLToPath(new URL('./vite.config.ts', this.#cwd))\n\n const file = this.project.getSourceFile(viteConfigTsUrl)\n if (!file) {\n throw new Error(\n 'Cannot find vite.config.ts file. Make sure to rename vite.config.js to vite.config.ts'\n )\n }\n\n /**\n * Add the import declarations\n */\n this.#addImportDeclarations(file, importDeclarations)\n\n /**\n * Get the default export options\n */\n const defaultExport = file.getDefaultExportSymbol()\n if (!defaultExport) {\n throw new Error('Cannot find the default export in vite.config.ts')\n }\n\n const options = defaultExport\n .getDeclarations()[0]\n .getChildrenOfKind(SyntaxKind.ObjectLiteralExpression)[0]\n\n const pluginsArray = options\n .getPropertyOrThrow('plugins')\n .getFirstChildByKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Add plugin call to the plugins array\n */\n if (!pluginsArray.getElements().find((element) => element.getText() === pluginCall)) {\n pluginsArray.addElement(pluginCall)\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n\n /**\n * Adds a policy to the list of `policies` object configured\n * inside the `app/policies/main.ts` file.\n */\n async addPolicies(policies: BouncerPolicyNode[]) {\n /**\n * Get the `app/policies/main.ts` source file\n */\n const kernelUrl = fileURLToPath(new URL('./app/policies/main.ts', this.#cwd))\n const file = this.project.getSourceFileOrThrow(kernelUrl)\n\n /**\n * Process each middleware entry\n */\n for (const policy of policies) {\n this.#addToPoliciesList(file, policy)\n }\n\n file.formatText(this.#editorSettings)\n await file.save()\n }\n}\n","/*\n * @adonisjs/assembler\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { fileURLToPath } from 'node:url'\nimport type { AppEnvironments } from '@adonisjs/application/types'\nimport {\n Node,\n Project,\n SourceFile,\n SyntaxKind,\n CallExpression,\n PropertyAssignment,\n FormatCodeSettings,\n ArrayLiteralExpression,\n} from 'ts-morph'\n\n/**\n * RcFileTransformer is used to transform the `adonisrc.ts` file\n * for adding new commands, providers, meta files etc\n */\nexport class RcFileTransformer {\n #cwd: URL\n #project: Project\n\n /**\n * Settings to use when persisting files\n */\n #editorSettings: FormatCodeSettings = {\n indentSize: 2,\n convertTabsToSpaces: true,\n trimTrailingWhitespace: true,\n ensureNewLineAtEndOfFile: true,\n indentStyle: 2,\n // @ts-expect-error SemicolonPreference doesn't seem to be re-exported from ts-morph\n semicolons: 'remove',\n }\n\n constructor(cwd: URL, project: Project) {\n this.#cwd = cwd\n this.#project = project\n }\n\n /**\n * Get the `adonisrc.ts` source file\n */\n #getRcFileOrThrow() {\n const kernelUrl = fileURLToPath(new URL('./adonisrc.ts', this.#cwd))\n return this.#project.getSourceFileOrThrow(kernelUrl)\n }\n\n /**\n * Check if environments array has a subset of available environments\n */\n #isInSpecificEnvironment(environments?: AppEnvironments[]): boolean {\n if (!environments) {\n return false\n }\n\n return !!(['web', 'console', 'test', 'repl'] as const).find(\n (env) => !environments.includes(env)\n )\n }\n\n /**\n * Locate the `defineConfig` call inside the `adonisrc.ts` file\n */\n #locateDefineConfigCallOrThrow(file: SourceFile) {\n const call = file\n .getDescendantsOfKind(SyntaxKind.CallExpression)\n .find((statement) => statement.getExpression().getText() === 'defineConfig')\n\n if (!call) {\n throw new Error('Could not locate the defineConfig call.')\n }\n\n return call\n }\n\n /**\n * Return the ObjectLiteralExpression of the defineConfig call\n */\n #getDefineConfigObjectOrThrow(defineConfigCall: CallExpression) {\n const configObject = defineConfigCall\n .getArguments()[0]\n .asKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n\n return configObject\n }\n\n /**\n * Check if the defineConfig() call has the property assignment\n * inside it or not. If not, it will create one and return it.\n */\n #getPropertyAssignmentInDefineConfigCall(propertyName: string, initializer: string) {\n const file = this.#getRcFileOrThrow()\n const defineConfigCall = this.#locateDefineConfigCallOrThrow(file)\n const configObject = this.#getDefineConfigObjectOrThrow(defineConfigCall)\n\n let property = configObject.getProperty(propertyName)\n\n if (!property) {\n configObject.addPropertyAssignment({ name: propertyName, initializer })\n property = configObject.getProperty(propertyName)\n }\n\n return property as PropertyAssignment\n }\n\n /**\n * Extract list of imported modules from an ArrayLiteralExpression\n *\n * It assumes that the array can have two types of elements:\n *\n * - Simple lazy imported modules: [() => import('path/to/file')]\n * - Or an object entry: [{ file: () => import('path/to/file'), environment: ['web', 'console'] }]\n * where the `file` property is a lazy imported module.\n */\n #extractModulesFromArray(array: ArrayLiteralExpression) {\n const modules = array.getElements().map((element) => {\n /**\n * Simple lazy imported module\n */\n if (Node.isArrowFunction(element)) {\n const importExp = element.getFirstDescendantByKindOrThrow(SyntaxKind.CallExpression)\n const literal = importExp.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral)\n return literal.getLiteralValue()\n }\n\n /**\n * Object entry\n */\n if (Node.isObjectLiteralExpression(element)) {\n const fileProp = element.getPropertyOrThrow('file') as PropertyAssignment\n const arrowFn = fileProp.getFirstDescendantByKindOrThrow(SyntaxKind.ArrowFunction)\n const importExp = arrowFn.getFirstDescendantByKindOrThrow(SyntaxKind.CallExpression)\n const literal = importExp.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral)\n return literal.getLiteralValue()\n }\n })\n\n return modules.filter(Boolean) as string[]\n }\n\n /**\n * Extract a specific property from an ArrayLiteralExpression\n * that contains object entries.\n *\n * This function is mainly used for extractring the `pattern` property\n * when adding a new meta files entry, or the `name` property when\n * adding a new test suite.\n */\n #extractPropertyFromArray(array: ArrayLiteralExpression, propertyName: string) {\n const property = array.getElements().map((el) => {\n if (!Node.isObjectLiteralExpression(el)) return\n\n const nameProp = el.getPropertyOrThrow(propertyName)\n if (!Node.isPropertyAssignment(nameProp)) return\n\n const name = nameProp.getInitializerIfKindOrThrow(SyntaxKind.StringLiteral)\n return name.getLiteralValue()\n })\n\n return property.filter(Boolean) as string[]\n }\n\n /**\n * Build a new module entry for the preloads and providers array\n * based upon the environments specified\n */\n #buildNewModuleEntry(modulePath: string, environments?: AppEnvironments[]) {\n if (!this.#isInSpecificEnvironment(environments)) {\n return `() => import('${modulePath}')`\n }\n\n return `{\n file: () => import('${modulePath}'),\n environment: [${environments?.map((env) => `'${env}'`).join(', ')}],\n }`\n }\n\n /**\n * Add a new command to the rcFile\n */\n addCommand(commandPath: string) {\n const commandsProperty = this.#getPropertyAssignmentInDefineConfigCall('commands', '[]')\n const commandsArray = commandsProperty.getInitializerIfKindOrThrow(\n SyntaxKind.ArrayLiteralExpression\n )\n\n const commandString = `() => import('${commandPath}')`\n\n /**\n * If the command already exists, do nothing\n */\n if (commandsArray.getElements().some((el) => el.getText() === commandString)) {\n return this\n }\n\n /**\n * Add the command to the array\n */\n commandsArray.addElement(commandString)\n return this\n }\n\n /**\n * Add a new preloaded file to the rcFile\n */\n addPreloadFile(modulePath: string, environments?: AppEnvironments[]) {\n const preloadsProperty = this.#getPropertyAssignmentInDefineConfigCall('preloads', '[]')\n const preloadsArray = preloadsProperty.getInitializerIfKindOrThrow(\n SyntaxKind.ArrayLiteralExpression\n )\n\n /**\n * Check for duplicates\n */\n const existingPreloadedFiles = this.#extractModulesFromArray(preloadsArray)\n const isDuplicate = existingPreloadedFiles.includes(modulePath)\n if (isDuplicate) {\n return this\n }\n\n /**\n * Add the preloaded file to the array\n */\n preloadsArray.addElement(this.#buildNewModuleEntry(modulePath, environments))\n return this\n }\n\n /**\n * Add a new provider to the rcFile\n */\n addProvider(providerPath: string, environments?: AppEnvironments[]) {\n const property = this.#getPropertyAssignmentInDefineConfigCall('providers', '[]')\n const providersArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Check for duplicates\n */\n const existingProviderPaths = this.#extractModulesFromArray(providersArray)\n const isDuplicate = existingProviderPaths.includes(providerPath)\n if (isDuplicate) {\n return this\n }\n\n /**\n * Add the provider to the array\n */\n providersArray.addElement(this.#buildNewModuleEntry(providerPath, environments))\n\n return this\n }\n\n /**\n * Add a new meta file to the rcFile\n */\n addMetaFile(globPattern: string, reloadServer = false) {\n const property = this.#getPropertyAssignmentInDefineConfigCall('metaFiles', '[]')\n const metaFilesArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Check for duplicates\n */\n const alreadyDefinedPatterns = this.#extractPropertyFromArray(metaFilesArray, 'pattern')\n if (alreadyDefinedPatterns.includes(globPattern)) {\n return this\n }\n\n /**\n * Add the meta file to the array\n */\n metaFilesArray.addElement(\n `{\n pattern: '${globPattern}',\n reloadServer: ${reloadServer},\n }`\n )\n\n return this\n }\n\n /**\n * Set directory name and path\n */\n setDirectory(key: string, value: string) {\n const property = this.#getPropertyAssignmentInDefineConfigCall('directories', '{}')\n const directories = property.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n directories.addPropertyAssignment({ name: key, initializer: `'${value}'` })\n\n return this\n }\n\n /**\n * Set command alias\n */\n setCommandAlias(alias: string, command: string) {\n const aliasProperty = this.#getPropertyAssignmentInDefineConfigCall('commandsAliases', '{}')\n const aliases = aliasProperty.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n aliases.addPropertyAssignment({ name: alias, initializer: `'${command}'` })\n\n return this\n }\n\n /**\n * Add a new test suite to the rcFile\n */\n addSuite(suiteName: string, files: string | string[], timeout?: number) {\n const testProperty = this.#getPropertyAssignmentInDefineConfigCall(\n 'tests',\n `{ suites: [], forceExit: true, timeout: 2000 }`\n )\n\n const property = testProperty\n .getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)\n .getPropertyOrThrow('suites') as PropertyAssignment\n\n const suitesArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression)\n\n /**\n * Check for duplicates\n */\n const existingSuitesNames = this.#extractPropertyFromArray(suitesArray, 'name')\n if (existingSuitesNames.includes(suiteName)) {\n return this\n }\n\n /**\n * Add the suite to the array\n */\n const filesArray = Array.isArray(files) ? files : [files]\n suitesArray.addElement(\n `{\n name: '${suiteName}',\n files: [${filesArray.map((file) => `'${file}'`).join(', ')}],\n timeout: ${timeout ?? 2000},\n }`\n )\n\n return this\n }\n\n /**\n * Save the adonisrc.ts file\n */\n save() {\n const file = this.#getRcFileOrThrow()\n file.formatText(this.#editorSettings)\n return file.save()\n }\n}\n"],"mappings":";AASA,SAAS,YAAY;AACrB,SAAS,iBAAAA,sBAAqB;AAC9B,SAAS,gBAAgB,4BAA4B;AACrD;AAAA,EACE,QAAAC;AAAA,EACA,WAAAC;AAAA,EACA;AAAA,EAEA,cAAAC;AAAA,OAGK;;;ACXP,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EAGA;AAAA,OAKK;AAMA,IAAM,oBAAN,MAAwB;AAAA,EAC7B;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKA,kBAAsC;AAAA,IACpC,YAAY;AAAA,IACZ,qBAAqB;AAAA,IACrB,wBAAwB;AAAA,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AAW,KAAK,eAAe;AACpC,UAAM,KAAK,KAAK;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,YAAY,UAA+B;AAI/C,UAAM,YAAYD,eAAc,IAAI,IAAI,0BAA0B,KAAK,IAAI,CAAC;AAC5E,UAAM,OAAO,KAAK,QAAQ,qBAAqB,SAAS;AAKxD,eAAW,UAAU,UAAU;AAC7B,WAAK,mBAAmB,MAAM,MAAM;AAAA,IACtC;AAEA,SAAK,WAAW,KAAK,eAAe;AACpC,UAAM,KAAK,KAAK;AAAA,EAClB;AACF;","names":["fileURLToPath","Node","Project","SyntaxKind","Project","fileURLToPath","SyntaxKind","Node"]}
@@ -0,0 +1,29 @@
1
+ import { SourceFileChangedHookHandler, AssemblerHookHandler, RcFile } from '@adonisjs/application/types';
2
+ export declare class AssemblerHooks {
3
+ #private;
4
+ constructor(config: RcFile['unstable_assembler']);
5
+ /**
6
+ * Resolve hooks needed for dev-time and register them to the Hooks instance
7
+ */
8
+ registerDevServerHooks(): Promise<void>;
9
+ /**
10
+ * Resolve hooks needed for build-time and register them to the Hooks instance
11
+ */
12
+ registerBuildHooks(): Promise<void>;
13
+ /**
14
+ * When the dev server is started
15
+ */
16
+ onDevServerStarted(...args: Parameters<AssemblerHookHandler>): Promise<void>;
17
+ /**
18
+ * When a source file changes
19
+ */
20
+ onSourceFileChanged(...args: Parameters<SourceFileChangedHookHandler>): Promise<void>;
21
+ /**
22
+ * When the build process is starting
23
+ */
24
+ onBuildStarting(...args: Parameters<AssemblerHookHandler>): Promise<void>;
25
+ /**
26
+ * When the build process is completed
27
+ */
28
+ onBuildCompleted(...args: Parameters<AssemblerHookHandler>): Promise<void>;
29
+ }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
+ import type { RcFile } from '@adonisjs/application/types';
2
3
  /**
3
4
  * Options needed to run a script file
4
5
  */
@@ -90,6 +91,10 @@ export type DevServerOptions = {
90
91
  * Assets bundler options to start its dev server
91
92
  */
92
93
  assets?: AssetsBundlerOptions;
94
+ /**
95
+ * Hooks to execute at different stages
96
+ */
97
+ hooks?: Pick<NonNullable<RcFile['unstable_assembler']>, 'onDevServerStarted' | 'onSourceFileChanged'>;
93
98
  };
94
99
  /**
95
100
  * Options accepted by the test runner
@@ -168,6 +173,10 @@ export type BundlerOptions = {
168
173
  * for assets
169
174
  */
170
175
  assets?: AssetsBundlerOptions;
176
+ /**
177
+ * Hooks to execute at different stages
178
+ */
179
+ hooks?: Pick<NonNullable<RcFile['unstable_assembler']>, 'onBuildCompleted' | 'onBuildStarting'>;
171
180
  };
172
181
  /**
173
182
  * Entry to add a middleware to a given middleware stack
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
3
  "description": "Provides utilities to run AdonisJS development server and build project for production",
4
- "version": "7.1.0",
4
+ "version": "7.2.0",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -34,23 +34,22 @@
34
34
  "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --loader=ts-node/esm bin/test.ts"
35
35
  },
36
36
  "devDependencies": {
37
- "@adonisjs/application": "^8.0.0",
37
+ "@adonisjs/application": "8.1.0",
38
38
  "@adonisjs/eslint-config": "^1.2.1",
39
39
  "@adonisjs/prettier-config": "^1.2.1",
40
40
  "@adonisjs/tsconfig": "^1.2.1",
41
- "@commitlint/cli": "^18.4.4",
42
- "@commitlint/config-conventional": "^18.4.4",
41
+ "@commitlint/cli": "^18.5.0",
42
+ "@commitlint/config-conventional": "^18.5.0",
43
43
  "@japa/assert": "^2.1.0",
44
- "@japa/file-system": "^2.1.0",
44
+ "@japa/file-system": "^2.2.0",
45
45
  "@japa/runner": "^3.1.1",
46
46
  "@japa/snapshot": "^2.0.4",
47
- "@swc/core": "^1.3.104",
47
+ "@swc/core": "^1.3.105",
48
48
  "@types/node": "^20.11.5",
49
49
  "@types/picomatch": "^2.3.3",
50
50
  "@types/pretty-hrtime": "^1.0.3",
51
51
  "c8": "^9.1.0",
52
52
  "cross-env": "^7.0.3",
53
- "dedent": "^1.5.1",
54
53
  "del-cli": "^5.0.0",
55
54
  "eslint": "^8.56.0",
56
55
  "github-label-sync": "^2.3.1",
@@ -63,11 +62,14 @@
63
62
  "typescript": "^5.3.3"
64
63
  },
65
64
  "dependencies": {
66
- "@adonisjs/env": "^5.0.0",
65
+ "@adonisjs/env": "^5.0.1",
67
66
  "@antfu/install-pkg": "^0.3.1",
68
67
  "@poppinss/chokidar-ts": "^4.1.3",
69
68
  "@poppinss/cliui": "^6.3.0",
69
+ "@poppinss/hooks": "^7.2.2",
70
+ "@poppinss/utils": "^6.7.2",
70
71
  "cpy": "^11.0.0",
72
+ "dedent": "^1.5.1",
71
73
  "execa": "^8.0.1",
72
74
  "fast-glob": "^3.3.2",
73
75
  "get-port": "^7.0.0",