@adonisjs/assembler 6.1.3-3 → 6.1.3-5

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # The MIT License
2
2
 
3
- Copyright (c) 2023 AdonisJS Framework
3
+ Copyright (c) 2023 Harminder Virk
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <br />
4
4
 
5
- [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]
5
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]
6
6
 
7
7
  ## Introduction
8
8
  Assembler exports the API for starting the **AdonisJS development server**, **building project for production** and **running tests** in watch mode. Assembler must be used during development only.
@@ -32,5 +32,5 @@ AdonisJS Assembler is open-sourced software licensed under the [MIT license](LIC
32
32
  [license-url]: LICENSE.md
33
33
  [license-image]: https://img.shields.io/github/license/adonisjs/ace?style=for-the-badge
34
34
 
35
- [synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/assembler?label=Synk%20Vulnerabilities&style=for-the-badge
36
- [synk-url]: https://snyk.io/test/github/adonisjs/assembler?targetFile=package.json "synk"
35
+ [snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/assembler?label=snyk%20Vulnerabilities&style=for-the-badge
36
+ [snyk-url]: https://snyk.io/test/github/adonisjs/assembler?targetFile=package.json "snyk"
package/build/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { Bundler } from './src/bundler.js';
2
2
  export { DevServer } from './src/dev_server.js';
3
+ export { TestRunner } from './src/test_runner.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA"}
package/build/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Bundler } from './src/bundler.js';
2
2
  export { DevServer } from './src/dev_server.js';
3
+ export { TestRunner } from './src/test_runner.js';
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { type Logger } from '@poppinss/cliui';
3
+ import type { AssetsBundlerOptions } from './types.js';
4
+ export declare class AssetsDevServer {
5
+ #private;
6
+ constructor(cwd: URL, options?: AssetsBundlerOptions);
7
+ setLogger(logger: Logger): this;
8
+ start(): void;
9
+ stop(): void;
10
+ }
11
+ //# sourceMappingURL=assets_dev_server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets_dev_server.d.ts","sourceRoot":"","sources":["../../src/assets_dev_server.ts"],"names":[],"mappings":";AAUA,OAAO,EAAE,KAAK,MAAM,EAAS,MAAM,iBAAiB,CAAA;AAGpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAkBtD,qBAAa,eAAe;;gBAad,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,oBAAoB;IAgEpD,SAAS,CAAC,MAAM,EAAE,MAAM;IAUxB,KAAK;IAwDL,IAAI;CAOL"}
@@ -0,0 +1,95 @@
1
+ import { cliui } from '@poppinss/cliui';
2
+ import { run } from './helpers.js';
3
+ const ui = cliui();
4
+ export class AssetsDevServer {
5
+ #cwd;
6
+ #logger = ui.logger;
7
+ #options;
8
+ #devServer;
9
+ get #colors() {
10
+ return this.#logger.getColors();
11
+ }
12
+ constructor(cwd, options) {
13
+ this.#cwd = cwd;
14
+ this.#options = options;
15
+ }
16
+ #logViteDevServerMessage(data) {
17
+ const dataString = data.toString();
18
+ const lines = dataString.split('\n');
19
+ if (dataString.includes('ready in')) {
20
+ console.log('');
21
+ console.log(dataString.trim());
22
+ return;
23
+ }
24
+ if (dataString.includes('Local') && dataString.includes('Network')) {
25
+ const sticker = ui.sticker().useColors(this.#colors).useRenderer(this.#logger.getRenderer());
26
+ lines.forEach((line) => {
27
+ if (line.trim()) {
28
+ sticker.add(line);
29
+ }
30
+ });
31
+ sticker.render();
32
+ return;
33
+ }
34
+ lines.forEach((line) => {
35
+ if (line.trim()) {
36
+ console.log(line);
37
+ }
38
+ });
39
+ }
40
+ #logAssetsDevServerMessage(data) {
41
+ const dataString = data.toString();
42
+ const lines = dataString.split('\n');
43
+ lines.forEach((line) => {
44
+ if (line.trim()) {
45
+ console.log(line);
46
+ }
47
+ });
48
+ }
49
+ setLogger(logger) {
50
+ this.#logger = logger;
51
+ return this;
52
+ }
53
+ start() {
54
+ if (!this.#options?.serve) {
55
+ return;
56
+ }
57
+ this.#logger.info(`starting "${this.#options.driver}" dev server...`);
58
+ this.#devServer = run(this.#cwd, {
59
+ script: this.#options.cmd,
60
+ stdio: 'pipe',
61
+ scriptArgs: this.#options.args,
62
+ });
63
+ this.#devServer.stdout?.on('data', (data) => {
64
+ if (this.#options.driver === 'vite') {
65
+ this.#logViteDevServerMessage(data);
66
+ }
67
+ else {
68
+ this.#logAssetsDevServerMessage(data);
69
+ }
70
+ });
71
+ this.#devServer.stderr?.on('data', (data) => {
72
+ if (this.#options.driver === 'vite') {
73
+ this.#logViteDevServerMessage(data);
74
+ }
75
+ else {
76
+ this.#logAssetsDevServerMessage(data);
77
+ }
78
+ });
79
+ this.#devServer
80
+ .then((result) => {
81
+ this.#logger.warning(`"${this.#options.driver}" dev server closed with status code "${result.exitCode}"`);
82
+ })
83
+ .catch((error) => {
84
+ this.#logger.warning(`unable to connect to "${this.#options.driver}" dev server`);
85
+ this.#logger.fatal(error);
86
+ });
87
+ }
88
+ stop() {
89
+ if (this.#devServer) {
90
+ this.#devServer.removeAllListeners();
91
+ this.#devServer.kill('SIGKILL');
92
+ this.#devServer = undefined;
93
+ }
94
+ }
95
+ }
@@ -8,3 +8,4 @@ export declare class Bundler {
8
8
  setLogger(logger: Logger): this;
9
9
  bundle(stopOnError?: boolean, client?: 'npm' | 'yarn' | 'pnpm'): Promise<boolean>;
10
10
  }
11
+ //# sourceMappingURL=bundler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../../src/bundler.ts"],"names":[],"mappings":";AAYA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAGtC,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAUhD,qBAAa,OAAO;;gBAcN,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,QAAQ,EAAE,OAAO,EAAE,cAAc;IAkIlE,SAAS,CAAC,MAAM,EAAE,MAAM;IAQlB,MAAM,CACV,WAAW,GAAE,OAAc,EAC3B,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,MAAc,GACtC,OAAO,CAAC,OAAO,CAAC;CAmFpB"}
@@ -4,8 +4,7 @@ import fs from 'node:fs/promises';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { join, relative } from 'node:path';
6
6
  import { cliui } from '@poppinss/cliui';
7
- import { run } from './run.js';
8
- import { parseConfig } from './parse_config.js';
7
+ import { run, parseConfig } from './helpers.js';
9
8
  const ui = cliui();
10
9
  export class Bundler {
11
10
  #cwd;
@@ -13,3 +13,4 @@ export declare class DevServer {
13
13
  poll: boolean;
14
14
  }): Promise<void>;
15
15
  }
16
+ //# sourceMappingURL=dev_server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev_server.d.ts","sourceRoot":"","sources":["../../src/dev_server.ts"],"names":[],"mappings":";AAUA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAEtC,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAoBlD,qBAAa,SAAS;;gBAuBR,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB;IA6I/C,SAAS,CAAC,MAAM,EAAE,MAAM;IAUxB,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI;IASlD,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI;IAQtC,KAAK;IAUL,aAAa,CAAC,EAAE,EAAE,OAAO,QAAQ,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE;CAqErE"}
@@ -1,9 +1,7 @@
1
- import getPort from 'get-port';
2
1
  import picomatch from 'picomatch';
3
2
  import { cliui } from '@poppinss/cliui';
4
- import { EnvLoader, EnvParser } from '@adonisjs/env';
5
- import { watch } from './watch.js';
6
- import { run, runNode } from './run.js';
3
+ import { AssetsDevServer } from './assets_dev_server.js';
4
+ import { getPort, isDotEnvFile, isRcFile, runNode, watch } from './helpers.js';
7
5
  const ui = cliui();
8
6
  export class DevServer {
9
7
  #cwd;
@@ -11,13 +9,13 @@ export class DevServer {
11
9
  #options;
12
10
  #isWatching = false;
13
11
  #scriptFile = 'bin/server.js';
14
- #httpServerProcess;
15
12
  #isMetaFileWithReloadsEnabled;
16
13
  #isMetaFileWithReloadsDisabled;
17
- #watcher;
18
- #assetsServerProcess;
19
14
  #onError;
20
15
  #onClose;
16
+ #httpServer;
17
+ #watcher;
18
+ #assetsServer;
21
19
  get #colors() {
22
20
  return this.#logger.getColors();
23
21
  }
@@ -31,15 +29,6 @@ export class DevServer {
31
29
  .filter(({ reloadServer }) => reloadServer !== true)
32
30
  .map(({ pattern }) => pattern));
33
31
  }
34
- #isDotEnvFile(filePath) {
35
- if (filePath === '.env') {
36
- return true;
37
- }
38
- return filePath.includes('.env.');
39
- }
40
- #isRcFile(filePath) {
41
- return filePath === '.adonisrc.json';
42
- }
43
32
  #isAdonisJSReadyMessage(message) {
44
33
  return (message !== null &&
45
34
  typeof message === 'object' &&
@@ -52,60 +41,14 @@ export class DevServer {
52
41
  process.stdout.write('\u001Bc');
53
42
  }
54
43
  }
55
- #logViteDevServerMessage(data) {
56
- const dataString = data.toString();
57
- const lines = dataString.split('\n');
58
- if (dataString.includes('ready in')) {
59
- console.log('');
60
- console.log(dataString.trim());
61
- return;
62
- }
63
- if (dataString.includes('Local') && dataString.includes('Network')) {
64
- const sticker = ui.sticker().useColors(this.#colors).useRenderer(this.#logger.getRenderer());
65
- lines.forEach((line) => {
66
- if (line.trim()) {
67
- sticker.add(line);
68
- }
69
- });
70
- sticker.render();
71
- return;
72
- }
73
- lines.forEach((line) => {
74
- if (line.trim()) {
75
- console.log(line);
76
- }
77
- });
78
- }
79
- #logAssetsDevServerMessage(data) {
80
- const dataString = data.toString();
81
- const lines = dataString.split('\n');
82
- lines.forEach((line) => {
83
- if (line.trim()) {
84
- console.log(line);
85
- }
86
- });
87
- }
88
- async #getPort() {
89
- if (process.env.PORT) {
90
- return getPort({ port: Number(process.env.PORT) });
91
- }
92
- const files = await new EnvLoader(this.#cwd).load();
93
- for (let file of files) {
94
- const envVariables = new EnvParser(file.contents).parse();
95
- if (envVariables.PORT) {
96
- return getPort({ port: Number(envVariables.PORT) });
97
- }
98
- }
99
- return getPort({ port: 3333 });
100
- }
101
44
  #startHTTPServer(port, mode) {
102
- this.#httpServerProcess = runNode(this.#cwd, {
45
+ this.#httpServer = runNode(this.#cwd, {
103
46
  script: this.#scriptFile,
104
47
  env: { PORT: port, ...this.#options.env },
105
48
  nodeArgs: this.#options.nodeArgs,
106
49
  scriptArgs: this.#options.scriptArgs,
107
50
  });
108
- this.#httpServerProcess.on('message', (message) => {
51
+ this.#httpServer.on('message', (message) => {
109
52
  if (this.#isAdonisJSReadyMessage(message)) {
110
53
  ui.sticker()
111
54
  .useColors(this.#colors)
@@ -115,12 +58,13 @@ export class DevServer {
115
58
  .render();
116
59
  }
117
60
  });
118
- this.#httpServerProcess
61
+ this.#httpServer
119
62
  .then((result) => {
120
63
  this.#logger.warning(`underlying HTTP server closed with status code "${result.exitCode}"`);
121
64
  if (mode === 'nonblocking') {
122
65
  this.#onClose?.(result.exitCode);
123
66
  this.#watcher?.close();
67
+ this.#assetsServer?.stop();
124
68
  }
125
69
  })
126
70
  .catch((error) => {
@@ -128,53 +72,46 @@ export class DevServer {
128
72
  this.#logger.fatal(error);
129
73
  this.#onError?.(error);
130
74
  this.#watcher?.close();
75
+ this.#assetsServer?.stop();
131
76
  });
132
77
  }
133
78
  #startAssetsServer() {
134
- const assetsBundler = this.#options.assets;
135
- if (!assetsBundler?.serve) {
136
- return;
137
- }
138
- this.#logger.info(`starting "${assetsBundler.driver}" dev server...`);
139
- this.#assetsServerProcess = run(this.#cwd, {
140
- script: assetsBundler.cmd,
141
- stdio: 'pipe',
142
- scriptArgs: this.#options.scriptArgs,
143
- });
144
- this.#assetsServerProcess.stdout?.on('data', (data) => {
145
- if (assetsBundler.driver === 'vite') {
146
- this.#logViteDevServerMessage(data);
147
- }
148
- else {
149
- this.#logAssetsDevServerMessage(data);
150
- }
151
- });
152
- this.#assetsServerProcess.stderr?.on('data', (data) => {
153
- if (assetsBundler.driver === 'vite') {
154
- this.#logViteDevServerMessage(data);
155
- }
156
- else {
157
- this.#logAssetsDevServerMessage(data);
158
- }
159
- });
160
- this.#assetsServerProcess
161
- .then((result) => {
162
- this.#logger.warning(`"${assetsBundler.driver}" dev server closed with status code "${result.exitCode}"`);
163
- })
164
- .catch((error) => {
165
- this.#logger.warning(`unable to connect to "${assetsBundler.driver}" dev server`);
166
- this.#logger.fatal(error);
167
- });
79
+ this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets);
80
+ this.#assetsServer.start();
168
81
  }
169
- #restart(port) {
170
- if (this.#httpServerProcess) {
171
- this.#httpServerProcess.removeAllListeners();
172
- this.#httpServerProcess.kill('SIGKILL');
82
+ #restartHTTPServer(port) {
83
+ if (this.#httpServer) {
84
+ this.#httpServer.removeAllListeners();
85
+ this.#httpServer.kill('SIGKILL');
173
86
  }
174
87
  this.#startHTTPServer(port, 'blocking');
175
88
  }
89
+ #handleFileChange(action, port, relativePath) {
90
+ if (isDotEnvFile(relativePath) || isRcFile(relativePath)) {
91
+ this.#clearScreen();
92
+ this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
93
+ this.#restartHTTPServer(port);
94
+ return;
95
+ }
96
+ if (this.#isMetaFileWithReloadsEnabled(relativePath)) {
97
+ this.#clearScreen();
98
+ this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
99
+ this.#restartHTTPServer(port);
100
+ return;
101
+ }
102
+ if (this.#isMetaFileWithReloadsDisabled(relativePath)) {
103
+ this.#clearScreen();
104
+ this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
105
+ }
106
+ }
107
+ #handleSourceFileChange(action, port, relativePath) {
108
+ this.#clearScreen();
109
+ this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
110
+ this.#restartHTTPServer(port);
111
+ }
176
112
  setLogger(logger) {
177
113
  this.#logger = logger;
114
+ this.#assetsServer?.setLogger(logger);
178
115
  return this;
179
116
  }
180
117
  onClose(callback) {
@@ -188,11 +125,11 @@ export class DevServer {
188
125
  async start() {
189
126
  this.#clearScreen();
190
127
  this.#logger.info('starting HTTP server...');
191
- this.#startHTTPServer(String(await this.#getPort()), 'nonblocking');
128
+ this.#startHTTPServer(String(await getPort(this.#cwd)), 'nonblocking');
192
129
  this.#startAssetsServer();
193
130
  }
194
131
  async startAndWatch(ts, options) {
195
- const port = String(await this.#getPort());
132
+ const port = String(await getPort(this.#cwd));
196
133
  this.#isWatching = true;
197
134
  this.#clearScreen();
198
135
  this.#logger.info('starting HTTP server...');
@@ -213,74 +150,11 @@ export class DevServer {
213
150
  this.#onError?.(error);
214
151
  output.chokidar.close();
215
152
  });
216
- output.watcher.on('source:add', ({ relativePath }) => {
217
- this.#clearScreen();
218
- this.#logger.log(`${this.#colors.green('add')} ${relativePath}`);
219
- this.#restart(port);
220
- });
221
- output.watcher.on('source:change', ({ relativePath }) => {
222
- this.#clearScreen();
223
- this.#logger.log(`${this.#colors.green('update')} ${relativePath}`);
224
- this.#restart(port);
225
- });
226
- output.watcher.on('source:unlink', ({ relativePath }) => {
227
- this.#clearScreen();
228
- this.#logger.log(`${this.#colors.green('delete')} ${relativePath}`);
229
- this.#restart(port);
230
- });
231
- output.watcher.on('add', ({ relativePath }) => {
232
- if (this.#isDotEnvFile(relativePath) || this.#isRcFile(relativePath)) {
233
- this.#clearScreen();
234
- this.#logger.log(`${this.#colors.green('add')} ${relativePath}`);
235
- this.#restart(port);
236
- return;
237
- }
238
- if (this.#isMetaFileWithReloadsEnabled(relativePath)) {
239
- this.#clearScreen();
240
- this.#logger.log(`${this.#colors.green('add')} ${relativePath}`);
241
- this.#restart(port);
242
- return;
243
- }
244
- if (this.#isMetaFileWithReloadsDisabled(relativePath)) {
245
- this.#clearScreen();
246
- this.#logger.log(`${this.#colors.green('add')} ${relativePath}`);
247
- }
248
- });
249
- output.watcher.on('change', ({ relativePath }) => {
250
- if (this.#isDotEnvFile(relativePath) || this.#isRcFile(relativePath)) {
251
- this.#clearScreen();
252
- this.#logger.log(`${this.#colors.green('update')} ${relativePath}`);
253
- this.#restart(port);
254
- return;
255
- }
256
- if (this.#isMetaFileWithReloadsEnabled(relativePath)) {
257
- this.#clearScreen();
258
- this.#logger.log(`${this.#colors.green('update')} ${relativePath}`);
259
- this.#restart(port);
260
- return;
261
- }
262
- if (this.#isMetaFileWithReloadsDisabled(relativePath)) {
263
- this.#clearScreen();
264
- this.#logger.log(`${this.#colors.green('update')} ${relativePath}`);
265
- }
266
- });
267
- output.watcher.on('unlink', ({ relativePath }) => {
268
- if (this.#isDotEnvFile(relativePath) || this.#isRcFile(relativePath)) {
269
- this.#clearScreen();
270
- this.#logger.log(`${this.#colors.green('delete')} ${relativePath}`);
271
- this.#restart(port);
272
- return;
273
- }
274
- if (this.#isMetaFileWithReloadsEnabled(relativePath)) {
275
- this.#clearScreen();
276
- this.#logger.log(`${this.#colors.green('delete')} ${relativePath}`);
277
- this.#restart(port);
278
- return;
279
- }
280
- if (this.#isMetaFileWithReloadsDisabled(relativePath)) {
281
- this.#clearScreen();
282
- this.#logger.log(`${this.#colors.green('delete')} ${relativePath}`);
283
- }
284
- });
153
+ output.watcher.on('source:add', ({ relativePath }) => this.#handleSourceFileChange('add', port, relativePath));
154
+ output.watcher.on('source:change', ({ relativePath }) => this.#handleSourceFileChange('update', port, relativePath));
155
+ output.watcher.on('source:unlink', ({ relativePath }) => this.#handleSourceFileChange('delete', port, relativePath));
156
+ output.watcher.on('add', ({ relativePath }) => this.#handleFileChange('add', port, relativePath));
157
+ output.watcher.on('change', ({ relativePath }) => this.#handleFileChange('update', port, relativePath));
158
+ output.watcher.on('unlink', ({ relativePath }) => this.#handleFileChange('delete', port, relativePath));
285
159
  }
286
160
  }
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type tsStatic from 'typescript';
3
+ import { Watcher } from '@poppinss/chokidar-ts';
4
+ import type { RunOptions, WatchOptions } from './types.js';
5
+ export declare function parseConfig(cwd: string | URL, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
6
+ export declare function runNode(cwd: string | URL, options: RunOptions): import("execa").ExecaChildProcess<string>;
7
+ export declare function run(cwd: string | URL, options: Omit<RunOptions, 'nodeArgs'>): import("execa").ExecaChildProcess<string>;
8
+ export declare function watch(cwd: string | URL, ts: typeof tsStatic, options: WatchOptions): {
9
+ watcher: Watcher;
10
+ chokidar: import("chokidar").FSWatcher;
11
+ } | undefined;
12
+ export declare function isDotEnvFile(filePath: string): boolean;
13
+ export declare function isRcFile(filePath: string): boolean;
14
+ export declare function getPort(cwd: URL): Promise<number>;
15
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":";AAUA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAItC,OAAO,EAAgB,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAmB1D,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE,OAAO,QAAQ,0CAejE;AAKD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,UAAU,6CAgB7D;AAKD,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,6CAe3E;AAKD,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,EAAE,OAAO,QAAQ,EAAE,OAAO,EAAE,YAAY;;;cASlF;AAKD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,WAM5C;AAKD,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,WAExC;AAcD,wBAAsB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBvD"}
@@ -0,0 +1,86 @@
1
+ import getRandomPort from 'get-port';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { execaNode, execa } from 'execa';
4
+ import { EnvLoader, EnvParser } from '@adonisjs/env';
5
+ import { ConfigParser, Watcher } from '@poppinss/chokidar-ts';
6
+ const DEFAULT_NODE_ARGS = [
7
+ '--loader=ts-node/esm',
8
+ '--no-warnings',
9
+ '--experimental-import-meta-resolve',
10
+ ];
11
+ export function parseConfig(cwd, ts) {
12
+ const { config, error } = new ConfigParser(cwd, 'tsconfig.json', ts).parse();
13
+ if (error) {
14
+ const compilerHost = ts.createCompilerHost({});
15
+ console.log(ts.formatDiagnosticsWithColorAndContext([error], compilerHost));
16
+ return;
17
+ }
18
+ if (config.errors.length) {
19
+ const compilerHost = ts.createCompilerHost({});
20
+ console.log(ts.formatDiagnosticsWithColorAndContext(config.errors, compilerHost));
21
+ return;
22
+ }
23
+ return config;
24
+ }
25
+ export function runNode(cwd, options) {
26
+ const childProcess = execaNode(options.script, options.scriptArgs, {
27
+ nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),
28
+ preferLocal: true,
29
+ windowsHide: false,
30
+ localDir: cwd,
31
+ cwd,
32
+ buffer: false,
33
+ stdio: options.stdio || 'inherit',
34
+ env: {
35
+ ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
36
+ ...options.env,
37
+ },
38
+ });
39
+ return childProcess;
40
+ }
41
+ export function run(cwd, options) {
42
+ const childProcess = execa(options.script, options.scriptArgs, {
43
+ preferLocal: true,
44
+ windowsHide: false,
45
+ localDir: cwd,
46
+ cwd,
47
+ buffer: false,
48
+ stdio: options.stdio || 'inherit',
49
+ env: {
50
+ ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
51
+ ...options.env,
52
+ },
53
+ });
54
+ return childProcess;
55
+ }
56
+ export function watch(cwd, ts, options) {
57
+ const config = parseConfig(cwd, ts);
58
+ if (!config) {
59
+ return;
60
+ }
61
+ const watcher = new Watcher(typeof cwd === 'string' ? cwd : fileURLToPath(cwd), config);
62
+ const chokidar = watcher.watch(['.'], { usePolling: options.poll });
63
+ return { watcher, chokidar };
64
+ }
65
+ export function isDotEnvFile(filePath) {
66
+ if (filePath === '.env') {
67
+ return true;
68
+ }
69
+ return filePath.includes('.env.');
70
+ }
71
+ export function isRcFile(filePath) {
72
+ return filePath === '.adonisrc.json';
73
+ }
74
+ export async function getPort(cwd) {
75
+ if (process.env.PORT) {
76
+ return getRandomPort({ port: Number(process.env.PORT) });
77
+ }
78
+ const files = await new EnvLoader(cwd).load();
79
+ for (let file of files) {
80
+ const envVariables = new EnvParser(file.contents).parse();
81
+ if (envVariables.PORT) {
82
+ return getRandomPort({ port: Number(envVariables.PORT) });
83
+ }
84
+ }
85
+ return getRandomPort({ port: 3333 });
86
+ }
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type tsStatic from 'typescript';
3
+ import { type Logger } from '@poppinss/cliui';
4
+ import type { TestRunnerOptions } from './types.js';
5
+ export declare class TestRunner {
6
+ #private;
7
+ constructor(cwd: URL, options: TestRunnerOptions);
8
+ setLogger(logger: Logger): this;
9
+ onClose(callback: (exitCode: number) => any): this;
10
+ onError(callback: (error: any) => any): this;
11
+ run(): Promise<void>;
12
+ runAndWatch(ts: typeof tsStatic, options?: {
13
+ poll: boolean;
14
+ }): Promise<void>;
15
+ }
16
+ //# sourceMappingURL=test_runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_runner.d.ts","sourceRoot":"","sources":["../../src/test_runner.ts"],"names":[],"mappings":";AAUA,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAA;AAEtC,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAoBnD,qBAAa,UAAU;;gBA8BT,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB;IAmKhD,SAAS,CAAC,MAAM,EAAE,MAAM;IAUxB,OAAO,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI;IASlD,OAAO,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,GAAG,IAAI;IAQtC,GAAG;IAcH,WAAW,CAAC,EAAE,EAAE,OAAO,QAAQ,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE;CAoEnE"}