@adonisjs/assembler 6.1.3-4 → 6.1.3-6
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/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/src/assets_dev_server.d.ts +11 -0
- package/build/src/assets_dev_server.d.ts.map +1 -0
- package/build/src/assets_dev_server.js +95 -0
- package/build/src/bundler.d.ts.map +1 -1
- package/build/src/bundler.js +1 -2
- package/build/src/dev_server.d.ts.map +1 -1
- package/build/src/dev_server.js +49 -174
- package/build/src/helpers.d.ts +15 -0
- package/build/src/helpers.d.ts.map +1 -0
- package/build/src/helpers.js +86 -0
- package/build/src/test_runner.d.ts +16 -0
- package/build/src/test_runner.d.ts.map +1 -0
- package/build/src/test_runner.js +179 -0
- package/build/src/types.d.ts +24 -0
- package/build/src/types.d.ts.map +1 -1
- package/index.ts +1 -0
- package/package.json +9 -9
- package/src/assets_dev_server.ts +182 -0
- package/src/bundler.ts +1 -2
- package/src/dev_server.ts +77 -240
- package/src/helpers.ts +162 -0
- package/src/test_runner.ts +339 -0
- package/src/types.ts +41 -0
- package/build/src/parse_config.d.ts +0 -4
- package/build/src/parse_config.d.ts.map +0 -1
- package/build/src/parse_config.js +0 -15
- package/build/src/run.d.ts +0 -5
- package/build/src/run.d.ts.map +0 -1
- package/build/src/run.js +0 -37
- package/build/src/watch.d.ts +0 -9
- package/build/src/watch.d.ts.map +0 -1
- package/build/src/watch.js +0 -12
- package/src/parse_config.ts +0 -32
- package/src/run.ts +0 -65
- package/src/watch.ts +0 -29
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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
|
@@ -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
|
+
}
|
|
@@ -1 +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;
|
|
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"}
|
package/build/src/bundler.js
CHANGED
|
@@ -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 './
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev_server.d.ts","sourceRoot":"","sources":["../../src/dev_server.ts"],"names":[],"mappings":";
|
|
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;IA8I/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"}
|
package/build/src/dev_server.js
CHANGED
|
@@ -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 {
|
|
5
|
-
import { watch } from './
|
|
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.#
|
|
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.#
|
|
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.#
|
|
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,47 @@ 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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
79
|
+
this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets);
|
|
80
|
+
this.#assetsServer.setLogger(this.#logger);
|
|
81
|
+
this.#assetsServer.start();
|
|
82
|
+
}
|
|
83
|
+
#restartHTTPServer(port) {
|
|
84
|
+
if (this.#httpServer) {
|
|
85
|
+
this.#httpServer.removeAllListeners();
|
|
86
|
+
this.#httpServer.kill('SIGKILL');
|
|
137
87
|
}
|
|
138
|
-
this.#
|
|
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
|
-
});
|
|
88
|
+
this.#startHTTPServer(port, 'blocking');
|
|
168
89
|
}
|
|
169
|
-
#
|
|
170
|
-
if (
|
|
171
|
-
this.#
|
|
172
|
-
this.#
|
|
90
|
+
#handleFileChange(action, port, relativePath) {
|
|
91
|
+
if (isDotEnvFile(relativePath) || isRcFile(relativePath)) {
|
|
92
|
+
this.#clearScreen();
|
|
93
|
+
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
94
|
+
this.#restartHTTPServer(port);
|
|
95
|
+
return;
|
|
173
96
|
}
|
|
174
|
-
this.#
|
|
97
|
+
if (this.#isMetaFileWithReloadsEnabled(relativePath)) {
|
|
98
|
+
this.#clearScreen();
|
|
99
|
+
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
100
|
+
this.#restartHTTPServer(port);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (this.#isMetaFileWithReloadsDisabled(relativePath)) {
|
|
104
|
+
this.#clearScreen();
|
|
105
|
+
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
#handleSourceFileChange(action, port, relativePath) {
|
|
109
|
+
this.#clearScreen();
|
|
110
|
+
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
111
|
+
this.#restartHTTPServer(port);
|
|
175
112
|
}
|
|
176
113
|
setLogger(logger) {
|
|
177
114
|
this.#logger = logger;
|
|
115
|
+
this.#assetsServer?.setLogger(logger);
|
|
178
116
|
return this;
|
|
179
117
|
}
|
|
180
118
|
onClose(callback) {
|
|
@@ -188,11 +126,11 @@ export class DevServer {
|
|
|
188
126
|
async start() {
|
|
189
127
|
this.#clearScreen();
|
|
190
128
|
this.#logger.info('starting HTTP server...');
|
|
191
|
-
this.#startHTTPServer(String(await this.#
|
|
129
|
+
this.#startHTTPServer(String(await getPort(this.#cwd)), 'nonblocking');
|
|
192
130
|
this.#startAssetsServer();
|
|
193
131
|
}
|
|
194
132
|
async startAndWatch(ts, options) {
|
|
195
|
-
const port = String(await this.#
|
|
133
|
+
const port = String(await getPort(this.#cwd));
|
|
196
134
|
this.#isWatching = true;
|
|
197
135
|
this.#clearScreen();
|
|
198
136
|
this.#logger.info('starting HTTP server...');
|
|
@@ -213,74 +151,11 @@ export class DevServer {
|
|
|
213
151
|
this.#onError?.(error);
|
|
214
152
|
output.chokidar.close();
|
|
215
153
|
});
|
|
216
|
-
output.watcher.on('source:add', ({ relativePath }) =>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
});
|
|
221
|
-
output.watcher.on('
|
|
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
|
-
});
|
|
154
|
+
output.watcher.on('source:add', ({ relativePath }) => this.#handleSourceFileChange('add', port, relativePath));
|
|
155
|
+
output.watcher.on('source:change', ({ relativePath }) => this.#handleSourceFileChange('update', port, relativePath));
|
|
156
|
+
output.watcher.on('source:unlink', ({ relativePath }) => this.#handleSourceFileChange('delete', port, relativePath));
|
|
157
|
+
output.watcher.on('add', ({ relativePath }) => this.#handleFileChange('add', port, relativePath));
|
|
158
|
+
output.watcher.on('change', ({ relativePath }) => this.#handleFileChange('update', port, relativePath));
|
|
159
|
+
output.watcher.on('unlink', ({ relativePath }) => this.#handleFileChange('delete', port, relativePath));
|
|
285
160
|
}
|
|
286
161
|
}
|
|
@@ -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;IAoKhD,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"}
|