@adonisjs/assembler 6.1.3-22 → 6.1.3-24
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 +109 -3
- package/build/index.js +913 -11
- package/build/src/code_transformer/main.d.ts +48 -4
- package/build/src/code_transformer/main.js +394 -210
- package/build/src/types.d.ts +12 -11
- package/build/src/types.js +0 -9
- package/package.json +27 -16
- package/build/src/assets_dev_server.d.ts +0 -32
- package/build/src/assets_dev_server.js +0 -158
- package/build/src/bundler.d.ts +0 -19
- package/build/src/bundler.js +0 -205
- package/build/src/code_transformer/rc_file_transformer.d.ts +0 -43
- package/build/src/code_transformer/rc_file_transformer.js +0 -272
- package/build/src/debug.d.ts +0 -3
- package/build/src/debug.js +0 -10
- package/build/src/dev_server.d.ts +0 -47
- package/build/src/dev_server.js +0 -253
- package/build/src/helpers.d.ts +0 -50
- package/build/src/helpers.js +0 -183
- package/build/src/test_runner.d.ts +0 -47
- package/build/src/test_runner.js +0 -310
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { Node, SyntaxKind, } from 'ts-morph';
|
|
3
|
-
/**
|
|
4
|
-
* RcFileTransformer is used to transform the `adonisrc.ts` file
|
|
5
|
-
* for adding new commands, providers, meta files etc
|
|
6
|
-
*/
|
|
7
|
-
export class RcFileTransformer {
|
|
8
|
-
#cwd;
|
|
9
|
-
#project;
|
|
10
|
-
/**
|
|
11
|
-
* Settings to use when persisting files
|
|
12
|
-
*/
|
|
13
|
-
#editorSettings = {
|
|
14
|
-
indentSize: 2,
|
|
15
|
-
convertTabsToSpaces: true,
|
|
16
|
-
trimTrailingWhitespace: true,
|
|
17
|
-
};
|
|
18
|
-
constructor(cwd, project) {
|
|
19
|
-
this.#cwd = cwd;
|
|
20
|
-
this.#project = project;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Get the `adonisrc.ts` source file
|
|
24
|
-
*/
|
|
25
|
-
#getRcFileOrThrow() {
|
|
26
|
-
const kernelUrl = fileURLToPath(new URL('./adonisrc.ts', this.#cwd));
|
|
27
|
-
return this.#project.getSourceFileOrThrow(kernelUrl);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if environments array has a subset of available environments
|
|
31
|
-
*/
|
|
32
|
-
#isInSpecificEnvironment(environments) {
|
|
33
|
-
if (!environments)
|
|
34
|
-
return false;
|
|
35
|
-
return !!['web', 'console', 'test', 'repl'].find((env) => !environments.includes(env));
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Locate the `defineConfig` call inside the `adonisrc.ts` file
|
|
39
|
-
*/
|
|
40
|
-
#locateDefineConfigCallOrThrow(file) {
|
|
41
|
-
const call = file
|
|
42
|
-
.getDescendantsOfKind(SyntaxKind.CallExpression)
|
|
43
|
-
.find((statement) => statement.getExpression().getText() === 'defineConfig');
|
|
44
|
-
if (!call) {
|
|
45
|
-
throw new Error('Could not locate the defineConfig call.');
|
|
46
|
-
}
|
|
47
|
-
return call;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Return the ObjectLiteralExpression of the defineConfig call
|
|
51
|
-
*/
|
|
52
|
-
#getDefineConfigObjectOrThrow(defineConfigCall) {
|
|
53
|
-
const configObject = defineConfigCall
|
|
54
|
-
.getArguments()[0]
|
|
55
|
-
.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
56
|
-
return configObject;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Check if the defineConfig() call has the property assignment
|
|
60
|
-
* inside it or not. If not, it will create one and return it.
|
|
61
|
-
*/
|
|
62
|
-
#getPropertyAssignmentInDefineConfigCall(propertyName, initializer) {
|
|
63
|
-
const file = this.#getRcFileOrThrow();
|
|
64
|
-
const defineConfigCall = this.#locateDefineConfigCallOrThrow(file);
|
|
65
|
-
const configObject = this.#getDefineConfigObjectOrThrow(defineConfigCall);
|
|
66
|
-
let property = configObject.getProperty(propertyName);
|
|
67
|
-
if (!property) {
|
|
68
|
-
configObject.addPropertyAssignment({ name: propertyName, initializer });
|
|
69
|
-
property = configObject.getProperty(propertyName);
|
|
70
|
-
}
|
|
71
|
-
return property;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Extract list of imported modules from an ArrayLiteralExpression
|
|
75
|
-
*
|
|
76
|
-
* It assumes that the array can have two types of elements:
|
|
77
|
-
*
|
|
78
|
-
* - Simple lazy imported modules: [() => import('path/to/file')]
|
|
79
|
-
* - Or an object entry: [{ file: () => import('path/to/file'), environment: ['web', 'console'] }]
|
|
80
|
-
* where the `file` property is a lazy imported module.
|
|
81
|
-
*/
|
|
82
|
-
#extractModulesFromArray(array) {
|
|
83
|
-
const modules = array.getElements().map((element) => {
|
|
84
|
-
/**
|
|
85
|
-
* Simple lazy imported module
|
|
86
|
-
*/
|
|
87
|
-
if (Node.isArrowFunction(element)) {
|
|
88
|
-
const importExp = element.getFirstDescendantByKindOrThrow(SyntaxKind.CallExpression);
|
|
89
|
-
const literal = importExp.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral);
|
|
90
|
-
return literal.getLiteralValue();
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Object entry
|
|
94
|
-
*/
|
|
95
|
-
if (Node.isObjectLiteralExpression(element)) {
|
|
96
|
-
const fileProp = element.getPropertyOrThrow('file');
|
|
97
|
-
const arrowFn = fileProp.getFirstDescendantByKindOrThrow(SyntaxKind.ArrowFunction);
|
|
98
|
-
const importExp = arrowFn.getFirstDescendantByKindOrThrow(SyntaxKind.CallExpression);
|
|
99
|
-
const literal = importExp.getFirstDescendantByKindOrThrow(SyntaxKind.StringLiteral);
|
|
100
|
-
return literal.getLiteralValue();
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return modules.filter(Boolean);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Extract a specific property from an ArrayLiteralExpression
|
|
107
|
-
* that contains object entries.
|
|
108
|
-
*
|
|
109
|
-
* This function is mainly used for extractring the `pattern` property
|
|
110
|
-
* when adding a new meta files entry, or the `name` property when
|
|
111
|
-
* adding a new test suite.
|
|
112
|
-
*/
|
|
113
|
-
#extractPropertyFromArray(array, propertyName) {
|
|
114
|
-
const property = array.getElements().map((el) => {
|
|
115
|
-
if (!Node.isObjectLiteralExpression(el))
|
|
116
|
-
return;
|
|
117
|
-
const nameProp = el.getPropertyOrThrow(propertyName);
|
|
118
|
-
if (!Node.isPropertyAssignment(nameProp))
|
|
119
|
-
return;
|
|
120
|
-
const name = nameProp.getInitializerIfKindOrThrow(SyntaxKind.StringLiteral);
|
|
121
|
-
return name.getLiteralValue();
|
|
122
|
-
});
|
|
123
|
-
return property.filter(Boolean);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Build a new module entry for the preloads and providers array
|
|
127
|
-
* based upon the environments specified
|
|
128
|
-
*/
|
|
129
|
-
#buildNewModuleEntry(modulePath, environments) {
|
|
130
|
-
if (!this.#isInSpecificEnvironment(environments)) {
|
|
131
|
-
return `() => import('${modulePath}')`;
|
|
132
|
-
}
|
|
133
|
-
return `{
|
|
134
|
-
file: () => import('${modulePath}'),
|
|
135
|
-
environment: [${environments?.map((env) => `'${env}'`).join(', ')}],
|
|
136
|
-
}`;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Add a new command to the rcFile
|
|
140
|
-
*/
|
|
141
|
-
addCommand(commandPath) {
|
|
142
|
-
const commandsProperty = this.#getPropertyAssignmentInDefineConfigCall('providers', '[]');
|
|
143
|
-
const commandsArray = commandsProperty.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
|
144
|
-
const commandString = `() => import('${commandPath}')`;
|
|
145
|
-
/**
|
|
146
|
-
* If the command already exists, do nothing
|
|
147
|
-
*/
|
|
148
|
-
if (commandsArray.getElements().some((el) => el.getText() === commandString)) {
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Add the command to the array
|
|
153
|
-
*/
|
|
154
|
-
commandsArray.addElement(commandString);
|
|
155
|
-
return this;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Add a new preloaded file to the rcFile
|
|
159
|
-
*/
|
|
160
|
-
addPreloadFile(modulePath, environments) {
|
|
161
|
-
const preloadsProperty = this.#getPropertyAssignmentInDefineConfigCall('preloads', '[]');
|
|
162
|
-
const preloadsArray = preloadsProperty.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
|
163
|
-
/**
|
|
164
|
-
* Check for duplicates
|
|
165
|
-
*/
|
|
166
|
-
const existingPreloadedFiles = this.#extractModulesFromArray(preloadsArray);
|
|
167
|
-
const isDuplicate = existingPreloadedFiles.includes(modulePath);
|
|
168
|
-
if (isDuplicate) {
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Add the preloaded file to the array
|
|
173
|
-
*/
|
|
174
|
-
preloadsArray.addElement(this.#buildNewModuleEntry(modulePath, environments));
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Add a new provider to the rcFile
|
|
179
|
-
*/
|
|
180
|
-
addProvider(providerPath, environments) {
|
|
181
|
-
const property = this.#getPropertyAssignmentInDefineConfigCall('providers', '[]');
|
|
182
|
-
const providersArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
|
183
|
-
/**
|
|
184
|
-
* Check for duplicates
|
|
185
|
-
*/
|
|
186
|
-
const existingProviderPaths = this.#extractModulesFromArray(providersArray);
|
|
187
|
-
const isDuplicate = existingProviderPaths.includes(providerPath);
|
|
188
|
-
if (isDuplicate) {
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Add the provider to the array
|
|
193
|
-
*/
|
|
194
|
-
providersArray.addElement(this.#buildNewModuleEntry(providerPath, environments));
|
|
195
|
-
return this;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Add a new meta file to the rcFile
|
|
199
|
-
*/
|
|
200
|
-
addMetaFile(globPattern, reloadServer = false) {
|
|
201
|
-
const property = this.#getPropertyAssignmentInDefineConfigCall('metaFiles', '[]');
|
|
202
|
-
const metaFilesArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
|
203
|
-
/**
|
|
204
|
-
* Check for duplicates
|
|
205
|
-
*/
|
|
206
|
-
const alreadyDefinedPatterns = this.#extractPropertyFromArray(metaFilesArray, 'pattern');
|
|
207
|
-
if (alreadyDefinedPatterns.includes(globPattern)) {
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Add the meta file to the array
|
|
212
|
-
*/
|
|
213
|
-
metaFilesArray.addElement(`{
|
|
214
|
-
pattern: '${globPattern}',
|
|
215
|
-
reloadServer: ${reloadServer},
|
|
216
|
-
}`);
|
|
217
|
-
return this;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Set directory name and path
|
|
221
|
-
*/
|
|
222
|
-
setDirectory(key, value) {
|
|
223
|
-
const property = this.#getPropertyAssignmentInDefineConfigCall('directories', '{}');
|
|
224
|
-
const directories = property.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
225
|
-
directories.addPropertyAssignment({ name: key, initializer: `'${value}'` });
|
|
226
|
-
return this;
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Set command alias
|
|
230
|
-
*/
|
|
231
|
-
setCommandAlias(alias, command) {
|
|
232
|
-
const aliasProperty = this.#getPropertyAssignmentInDefineConfigCall('commandsAliases', '{}');
|
|
233
|
-
const aliases = aliasProperty.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
|
|
234
|
-
aliases.addPropertyAssignment({ name: alias, initializer: `'${command}'` });
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Add a new test suite to the rcFile
|
|
239
|
-
*/
|
|
240
|
-
addSuite(suiteName, files, timeout) {
|
|
241
|
-
const testProperty = this.#getPropertyAssignmentInDefineConfigCall('tests', `{ suites: [], forceExit: true, timeout: 2000 }`);
|
|
242
|
-
const property = testProperty
|
|
243
|
-
.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression)
|
|
244
|
-
.getPropertyOrThrow('suites');
|
|
245
|
-
const suitesArray = property.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
|
246
|
-
/**
|
|
247
|
-
* Check for duplicates
|
|
248
|
-
*/
|
|
249
|
-
const existingSuitesNames = this.#extractPropertyFromArray(suitesArray, 'name');
|
|
250
|
-
if (existingSuitesNames.includes(suiteName)) {
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Add the suite to the array
|
|
255
|
-
*/
|
|
256
|
-
const filesArray = Array.isArray(files) ? files : [files];
|
|
257
|
-
suitesArray.addElement(`{
|
|
258
|
-
name: '${suiteName}',
|
|
259
|
-
files: [${filesArray.map((file) => `'${file}'`).join(', ')}],
|
|
260
|
-
timeout: ${timeout ?? 2000},
|
|
261
|
-
}`);
|
|
262
|
-
return this;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Save the adonisrc.ts file
|
|
266
|
-
*/
|
|
267
|
-
save() {
|
|
268
|
-
const file = this.#getRcFileOrThrow();
|
|
269
|
-
file.formatText(this.#editorSettings);
|
|
270
|
-
return file.save();
|
|
271
|
-
}
|
|
272
|
-
}
|
package/build/src/debug.d.ts
DELETED
package/build/src/debug.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/assembler
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { debuglog } from 'node:util';
|
|
10
|
-
export default debuglog('adonisjs:assembler');
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type tsStatic from 'typescript';
|
|
3
|
-
import { type Logger } from '@poppinss/cliui';
|
|
4
|
-
import type { DevServerOptions } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Exposes the API to start the development. Optionally, the watch API can be
|
|
7
|
-
* used to watch for file changes and restart the development server.
|
|
8
|
-
*
|
|
9
|
-
* The Dev server performs the following actions
|
|
10
|
-
*
|
|
11
|
-
* - Assigns a random PORT, when PORT inside .env file is in use
|
|
12
|
-
* - Uses tsconfig.json file to collect a list of files to watch.
|
|
13
|
-
* - Uses metaFiles from .adonisrc.json file to collect a list of files to watch.
|
|
14
|
-
* - Restart HTTP server on every file change.
|
|
15
|
-
*/
|
|
16
|
-
export declare class DevServer {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(cwd: URL, options: DevServerOptions);
|
|
19
|
-
/**
|
|
20
|
-
* Set a custom CLI UI logger
|
|
21
|
-
*/
|
|
22
|
-
setLogger(logger: Logger): this;
|
|
23
|
-
/**
|
|
24
|
-
* Add listener to get notified when dev server is
|
|
25
|
-
* closed
|
|
26
|
-
*/
|
|
27
|
-
onClose(callback: (exitCode: number) => any): this;
|
|
28
|
-
/**
|
|
29
|
-
* Add listener to get notified when dev server exists
|
|
30
|
-
* with an error
|
|
31
|
-
*/
|
|
32
|
-
onError(callback: (error: any) => any): this;
|
|
33
|
-
/**
|
|
34
|
-
* Close watchers and running child processes
|
|
35
|
-
*/
|
|
36
|
-
close(): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Start the development server
|
|
39
|
-
*/
|
|
40
|
-
start(): Promise<void>;
|
|
41
|
-
/**
|
|
42
|
-
* Start the development server in watch mode
|
|
43
|
-
*/
|
|
44
|
-
startAndWatch(ts: typeof tsStatic, options?: {
|
|
45
|
-
poll: boolean;
|
|
46
|
-
}): Promise<void>;
|
|
47
|
-
}
|
package/build/src/dev_server.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/assembler
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import picomatch from 'picomatch';
|
|
10
|
-
import { cliui } from '@poppinss/cliui';
|
|
11
|
-
import { AssetsDevServer } from './assets_dev_server.js';
|
|
12
|
-
import { getPort, isDotEnvFile, isRcFile, runNode, watch } from './helpers.js';
|
|
13
|
-
/**
|
|
14
|
-
* Instance of CLIUI
|
|
15
|
-
*/
|
|
16
|
-
const ui = cliui();
|
|
17
|
-
/**
|
|
18
|
-
* Exposes the API to start the development. Optionally, the watch API can be
|
|
19
|
-
* used to watch for file changes and restart the development server.
|
|
20
|
-
*
|
|
21
|
-
* The Dev server performs the following actions
|
|
22
|
-
*
|
|
23
|
-
* - Assigns a random PORT, when PORT inside .env file is in use
|
|
24
|
-
* - Uses tsconfig.json file to collect a list of files to watch.
|
|
25
|
-
* - Uses metaFiles from .adonisrc.json file to collect a list of files to watch.
|
|
26
|
-
* - Restart HTTP server on every file change.
|
|
27
|
-
*/
|
|
28
|
-
export class DevServer {
|
|
29
|
-
#cwd;
|
|
30
|
-
#logger = ui.logger;
|
|
31
|
-
#options;
|
|
32
|
-
#isWatching = false;
|
|
33
|
-
#scriptFile = 'bin/server.js';
|
|
34
|
-
#isMetaFileWithReloadsEnabled;
|
|
35
|
-
#isMetaFileWithReloadsDisabled;
|
|
36
|
-
#onError;
|
|
37
|
-
#onClose;
|
|
38
|
-
#httpServer;
|
|
39
|
-
#watcher;
|
|
40
|
-
#assetsServer;
|
|
41
|
-
/**
|
|
42
|
-
* Getting reference to colors library from logger
|
|
43
|
-
*/
|
|
44
|
-
get #colors() {
|
|
45
|
-
return this.#logger.getColors();
|
|
46
|
-
}
|
|
47
|
-
constructor(cwd, options) {
|
|
48
|
-
this.#cwd = cwd;
|
|
49
|
-
this.#options = options;
|
|
50
|
-
this.#isMetaFileWithReloadsEnabled = picomatch((this.#options.metaFiles || [])
|
|
51
|
-
.filter(({ reloadServer }) => reloadServer === true)
|
|
52
|
-
.map(({ pattern }) => pattern));
|
|
53
|
-
this.#isMetaFileWithReloadsDisabled = picomatch((this.#options.metaFiles || [])
|
|
54
|
-
.filter(({ reloadServer }) => reloadServer !== true)
|
|
55
|
-
.map(({ pattern }) => pattern));
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Inspect if child process message is from AdonisJS HTTP server
|
|
59
|
-
*/
|
|
60
|
-
#isAdonisJSReadyMessage(message) {
|
|
61
|
-
return (message !== null &&
|
|
62
|
-
typeof message === 'object' &&
|
|
63
|
-
'isAdonisJS' in message &&
|
|
64
|
-
'environment' in message &&
|
|
65
|
-
message.environment === 'web');
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Conditionally clear the terminal screen
|
|
69
|
-
*/
|
|
70
|
-
#clearScreen() {
|
|
71
|
-
if (this.#options.clearScreen) {
|
|
72
|
-
process.stdout.write('\u001Bc');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Starts the HTTP server
|
|
77
|
-
*/
|
|
78
|
-
#startHTTPServer(port, mode) {
|
|
79
|
-
this.#httpServer = runNode(this.#cwd, {
|
|
80
|
-
script: this.#scriptFile,
|
|
81
|
-
env: { PORT: port, ...this.#options.env },
|
|
82
|
-
nodeArgs: this.#options.nodeArgs,
|
|
83
|
-
scriptArgs: this.#options.scriptArgs,
|
|
84
|
-
});
|
|
85
|
-
this.#httpServer.on('message', (message) => {
|
|
86
|
-
if (this.#isAdonisJSReadyMessage(message)) {
|
|
87
|
-
ui.sticker()
|
|
88
|
-
.useColors(this.#colors)
|
|
89
|
-
.useRenderer(this.#logger.getRenderer())
|
|
90
|
-
.add(`Server address: ${this.#colors.cyan(`http://${message.host}:${message.port}`)}`)
|
|
91
|
-
.add(`File system watcher: ${this.#colors.cyan(`${this.#isWatching ? 'enabled' : 'disabled'}`)}`)
|
|
92
|
-
.render();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
this.#httpServer
|
|
96
|
-
.then((result) => {
|
|
97
|
-
if (mode === 'nonblocking') {
|
|
98
|
-
this.#onClose?.(result.exitCode);
|
|
99
|
-
this.#watcher?.close();
|
|
100
|
-
this.#assetsServer?.stop();
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
.catch((error) => {
|
|
104
|
-
if (mode === 'nonblocking') {
|
|
105
|
-
this.#onError?.(error);
|
|
106
|
-
this.#watcher?.close();
|
|
107
|
-
this.#assetsServer?.stop();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Starts the assets server
|
|
113
|
-
*/
|
|
114
|
-
#startAssetsServer() {
|
|
115
|
-
this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets);
|
|
116
|
-
this.#assetsServer.setLogger(this.#logger);
|
|
117
|
-
this.#assetsServer.start();
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Restarts the HTTP server
|
|
121
|
-
*/
|
|
122
|
-
#restartHTTPServer(port) {
|
|
123
|
-
if (this.#httpServer) {
|
|
124
|
-
this.#httpServer.removeAllListeners();
|
|
125
|
-
this.#httpServer.kill('SIGKILL');
|
|
126
|
-
}
|
|
127
|
-
this.#startHTTPServer(port, 'blocking');
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Handles a non TypeScript file change
|
|
131
|
-
*/
|
|
132
|
-
#handleFileChange(action, port, relativePath) {
|
|
133
|
-
if (isDotEnvFile(relativePath) || isRcFile(relativePath)) {
|
|
134
|
-
this.#clearScreen();
|
|
135
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
136
|
-
this.#restartHTTPServer(port);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
if (this.#isMetaFileWithReloadsEnabled(relativePath)) {
|
|
140
|
-
this.#clearScreen();
|
|
141
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
142
|
-
this.#restartHTTPServer(port);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (this.#isMetaFileWithReloadsDisabled(relativePath)) {
|
|
146
|
-
this.#clearScreen();
|
|
147
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Handles TypeScript source file change
|
|
152
|
-
*/
|
|
153
|
-
#handleSourceFileChange(action, port, relativePath) {
|
|
154
|
-
this.#clearScreen();
|
|
155
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
156
|
-
this.#restartHTTPServer(port);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Set a custom CLI UI logger
|
|
160
|
-
*/
|
|
161
|
-
setLogger(logger) {
|
|
162
|
-
this.#logger = logger;
|
|
163
|
-
this.#assetsServer?.setLogger(logger);
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Add listener to get notified when dev server is
|
|
168
|
-
* closed
|
|
169
|
-
*/
|
|
170
|
-
onClose(callback) {
|
|
171
|
-
this.#onClose = callback;
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Add listener to get notified when dev server exists
|
|
176
|
-
* with an error
|
|
177
|
-
*/
|
|
178
|
-
onError(callback) {
|
|
179
|
-
this.#onError = callback;
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Close watchers and running child processes
|
|
184
|
-
*/
|
|
185
|
-
async close() {
|
|
186
|
-
await this.#watcher?.close();
|
|
187
|
-
this.#assetsServer?.stop();
|
|
188
|
-
if (this.#httpServer) {
|
|
189
|
-
this.#httpServer.removeAllListeners();
|
|
190
|
-
this.#httpServer.kill('SIGKILL');
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Start the development server
|
|
195
|
-
*/
|
|
196
|
-
async start() {
|
|
197
|
-
this.#clearScreen();
|
|
198
|
-
this.#logger.info('starting HTTP server...');
|
|
199
|
-
this.#startHTTPServer(String(await getPort(this.#cwd)), 'nonblocking');
|
|
200
|
-
this.#startAssetsServer();
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Start the development server in watch mode
|
|
204
|
-
*/
|
|
205
|
-
async startAndWatch(ts, options) {
|
|
206
|
-
const port = String(await getPort(this.#cwd));
|
|
207
|
-
this.#isWatching = true;
|
|
208
|
-
this.#clearScreen();
|
|
209
|
-
this.#logger.info('starting HTTP server...');
|
|
210
|
-
this.#startHTTPServer(port, 'blocking');
|
|
211
|
-
this.#startAssetsServer();
|
|
212
|
-
/**
|
|
213
|
-
* Create watcher using tsconfig.json file
|
|
214
|
-
*/
|
|
215
|
-
const output = watch(this.#cwd, ts, options || {});
|
|
216
|
-
if (!output) {
|
|
217
|
-
this.#onClose?.(1);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Storing reference to watcher, so that we can close it
|
|
222
|
-
* when HTTP server exists with error
|
|
223
|
-
*/
|
|
224
|
-
this.#watcher = output.chokidar;
|
|
225
|
-
/**
|
|
226
|
-
* Notify the watcher is ready
|
|
227
|
-
*/
|
|
228
|
-
output.watcher.on('watcher:ready', () => {
|
|
229
|
-
this.#logger.info('watching file system for changes...');
|
|
230
|
-
});
|
|
231
|
-
/**
|
|
232
|
-
* Cleanup when watcher dies
|
|
233
|
-
*/
|
|
234
|
-
output.chokidar.on('error', (error) => {
|
|
235
|
-
this.#logger.warning('file system watcher failure');
|
|
236
|
-
this.#logger.fatal(error);
|
|
237
|
-
this.#onError?.(error);
|
|
238
|
-
output.chokidar.close();
|
|
239
|
-
});
|
|
240
|
-
/**
|
|
241
|
-
* Changes in TypeScript source file
|
|
242
|
-
*/
|
|
243
|
-
output.watcher.on('source:add', ({ relativePath }) => this.#handleSourceFileChange('add', port, relativePath));
|
|
244
|
-
output.watcher.on('source:change', ({ relativePath }) => this.#handleSourceFileChange('update', port, relativePath));
|
|
245
|
-
output.watcher.on('source:unlink', ({ relativePath }) => this.#handleSourceFileChange('delete', port, relativePath));
|
|
246
|
-
/**
|
|
247
|
-
* Changes in non-TypeScript source files
|
|
248
|
-
*/
|
|
249
|
-
output.watcher.on('add', ({ relativePath }) => this.#handleFileChange('add', port, relativePath));
|
|
250
|
-
output.watcher.on('change', ({ relativePath }) => this.#handleFileChange('update', port, relativePath));
|
|
251
|
-
output.watcher.on('unlink', ({ relativePath }) => this.#handleFileChange('delete', port, relativePath));
|
|
252
|
-
}
|
|
253
|
-
}
|
package/build/src/helpers.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
/**
|
|
6
|
-
* Parses tsconfig.json and prints errors using typescript compiler
|
|
7
|
-
* host
|
|
8
|
-
*/
|
|
9
|
-
export declare function parseConfig(cwd: string | URL, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Runs a Node.js script as a child process and inherits the stdio streams
|
|
12
|
-
*/
|
|
13
|
-
export declare function runNode(cwd: string | URL, options: RunOptions): import("execa").ExecaChildProcess<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Runs a script as a child process and inherits the stdio streams
|
|
16
|
-
*/
|
|
17
|
-
export declare function run(cwd: string | URL, options: Omit<RunOptions, 'nodeArgs'>): import("execa").ExecaChildProcess<string>;
|
|
18
|
-
/**
|
|
19
|
-
* Watches the file system using tsconfig file
|
|
20
|
-
*/
|
|
21
|
-
export declare function watch(cwd: string | URL, ts: typeof tsStatic, options: WatchOptions): {
|
|
22
|
-
watcher: Watcher;
|
|
23
|
-
chokidar: import("chokidar").FSWatcher;
|
|
24
|
-
} | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Check if file is an .env file
|
|
27
|
-
*/
|
|
28
|
-
export declare function isDotEnvFile(filePath: string): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Check if file is .adonisrc.json file
|
|
31
|
-
*/
|
|
32
|
-
export declare function isRcFile(filePath: string): boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Returns the port to use after inspect the dot-env files inside
|
|
35
|
-
* a given directory.
|
|
36
|
-
*
|
|
37
|
-
* A random port is used when the specified port is in use. Following
|
|
38
|
-
* is the logic for finding a specified port.
|
|
39
|
-
*
|
|
40
|
-
* - The "process.env.PORT" value is used if exists.
|
|
41
|
-
* - The dot-env files are loaded using the "EnvLoader" and the PORT
|
|
42
|
-
* value is by iterating over all the loaded files. The iteration
|
|
43
|
-
* stops after first find.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getPort(cwd: URL): Promise<number>;
|
|
46
|
-
/**
|
|
47
|
-
* Helper function to copy files from relative paths or glob
|
|
48
|
-
* patterns
|
|
49
|
-
*/
|
|
50
|
-
export declare function copyFiles(files: string[], cwd: string, outDir: string): Promise<string[]>;
|