@adonisjs/assembler 6.1.3-9 → 7.0.0-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 +388 -11
- package/build/index.js +999 -11
- package/build/index.js.map +1 -0
- package/build/src/bundler.d.ts +3 -1
- package/build/src/code_transformer/main.d.ts +43 -0
- package/build/src/code_transformer/main.js +454 -0
- package/build/src/code_transformer/main.js.map +1 -0
- package/build/src/code_transformer/rc_file_transformer.d.ts +43 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/dev_server.d.ts +2 -2
- package/build/src/helpers.d.ts +7 -6
- package/build/src/test_runner.d.ts +8 -7
- package/build/src/types.d.ts +144 -20
- package/package.json +72 -46
- package/build/src/assets_dev_server.js +0 -158
- package/build/src/bundler.js +0 -223
- package/build/src/dev_server.js +0 -253
- package/build/src/helpers.js +0 -142
- package/build/src/test_runner.js +0 -287
- package/build/src/types.js +0 -9
package/build/src/helpers.js
DELETED
|
@@ -1,142 +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 getRandomPort from 'get-port';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import { execaNode, execa } from 'execa';
|
|
12
|
-
import { EnvLoader, EnvParser } from '@adonisjs/env';
|
|
13
|
-
import { ConfigParser, Watcher } from '@poppinss/chokidar-ts';
|
|
14
|
-
/**
|
|
15
|
-
* Default set of args to pass in order to run TypeScript
|
|
16
|
-
* source. Used by "run" and "runNode" scripts
|
|
17
|
-
*/
|
|
18
|
-
const DEFAULT_NODE_ARGS = [
|
|
19
|
-
// Use ts-node/esm loader. The project must install it
|
|
20
|
-
'--loader=ts-node/esm',
|
|
21
|
-
// Disable annonying warnings
|
|
22
|
-
'--no-warnings',
|
|
23
|
-
// Enable expiremental meta resolve for cases where someone uses magic import string
|
|
24
|
-
'--experimental-import-meta-resolve',
|
|
25
|
-
];
|
|
26
|
-
/**
|
|
27
|
-
* Parses tsconfig.json and prints errors using typescript compiler
|
|
28
|
-
* host
|
|
29
|
-
*/
|
|
30
|
-
export function parseConfig(cwd, ts) {
|
|
31
|
-
const { config, error } = new ConfigParser(cwd, 'tsconfig.json', ts).parse();
|
|
32
|
-
if (error) {
|
|
33
|
-
const compilerHost = ts.createCompilerHost({});
|
|
34
|
-
console.log(ts.formatDiagnosticsWithColorAndContext([error], compilerHost));
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (config.errors.length) {
|
|
38
|
-
const compilerHost = ts.createCompilerHost({});
|
|
39
|
-
console.log(ts.formatDiagnosticsWithColorAndContext(config.errors, compilerHost));
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
return config;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Runs a Node.js script as a child process and inherits the stdio streams
|
|
46
|
-
*/
|
|
47
|
-
export function runNode(cwd, options) {
|
|
48
|
-
const childProcess = execaNode(options.script, options.scriptArgs, {
|
|
49
|
-
nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),
|
|
50
|
-
preferLocal: true,
|
|
51
|
-
windowsHide: false,
|
|
52
|
-
localDir: cwd,
|
|
53
|
-
cwd,
|
|
54
|
-
buffer: false,
|
|
55
|
-
stdio: options.stdio || 'inherit',
|
|
56
|
-
env: {
|
|
57
|
-
...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
|
|
58
|
-
...options.env,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
return childProcess;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Runs a script as a child process and inherits the stdio streams
|
|
65
|
-
*/
|
|
66
|
-
export function run(cwd, options) {
|
|
67
|
-
const childProcess = execa(options.script, options.scriptArgs, {
|
|
68
|
-
preferLocal: true,
|
|
69
|
-
windowsHide: false,
|
|
70
|
-
localDir: cwd,
|
|
71
|
-
cwd,
|
|
72
|
-
buffer: false,
|
|
73
|
-
stdio: options.stdio || 'inherit',
|
|
74
|
-
env: {
|
|
75
|
-
...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
|
|
76
|
-
...options.env,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
return childProcess;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Watches the file system using tsconfig file
|
|
83
|
-
*/
|
|
84
|
-
export function watch(cwd, ts, options) {
|
|
85
|
-
const config = parseConfig(cwd, ts);
|
|
86
|
-
if (!config) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const watcher = new Watcher(typeof cwd === 'string' ? cwd : fileURLToPath(cwd), config);
|
|
90
|
-
const chokidar = watcher.watch(['.'], { usePolling: options.poll });
|
|
91
|
-
return { watcher, chokidar };
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Check if file is an .env file
|
|
95
|
-
*/
|
|
96
|
-
export function isDotEnvFile(filePath) {
|
|
97
|
-
if (filePath === '.env') {
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
return filePath.includes('.env.');
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Check if file is .adonisrc.json file
|
|
104
|
-
*/
|
|
105
|
-
export function isRcFile(filePath) {
|
|
106
|
-
return filePath === '.adonisrc.json';
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Returns the port to use after inspect the dot-env files inside
|
|
110
|
-
* a given directory.
|
|
111
|
-
*
|
|
112
|
-
* A random port is used when the specified port is in use. Following
|
|
113
|
-
* is the logic for finding a specified port.
|
|
114
|
-
*
|
|
115
|
-
* - The "process.env.PORT" value is used if exists.
|
|
116
|
-
* - The dot-env files are loaded using the "EnvLoader" and the PORT
|
|
117
|
-
* value is by iterating over all the loaded files. The iteration
|
|
118
|
-
* stops after first find.
|
|
119
|
-
*/
|
|
120
|
-
export async function getPort(cwd) {
|
|
121
|
-
/**
|
|
122
|
-
* Use existing port if exists
|
|
123
|
-
*/
|
|
124
|
-
if (process.env.PORT) {
|
|
125
|
-
return getRandomPort({ port: Number(process.env.PORT) });
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Loop over files and use the port from their contents. Stops
|
|
129
|
-
* after first match
|
|
130
|
-
*/
|
|
131
|
-
const files = await new EnvLoader(cwd).load();
|
|
132
|
-
for (let file of files) {
|
|
133
|
-
const envVariables = new EnvParser(file.contents).parse();
|
|
134
|
-
if (envVariables.PORT) {
|
|
135
|
-
return getRandomPort({ port: Number(envVariables.PORT) });
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Use 3333 as the port
|
|
140
|
-
*/
|
|
141
|
-
return getRandomPort({ port: 3333 });
|
|
142
|
-
}
|
package/build/src/test_runner.js
DELETED
|
@@ -1,287 +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, 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 TestRunner {
|
|
29
|
-
#cwd;
|
|
30
|
-
#logger = ui.logger;
|
|
31
|
-
#options;
|
|
32
|
-
#scriptFile = 'bin/test.js';
|
|
33
|
-
#isMetaFile;
|
|
34
|
-
#isTestFile;
|
|
35
|
-
/**
|
|
36
|
-
* In watch mode, after a file is changed, we wait for the current
|
|
37
|
-
* set of tests to finish before triggering a re-run. Therefore,
|
|
38
|
-
* we use this flag to know if we are already busy in running
|
|
39
|
-
* tests and ignore file-changes.
|
|
40
|
-
*/
|
|
41
|
-
#isBusy = false;
|
|
42
|
-
#onError;
|
|
43
|
-
#onClose;
|
|
44
|
-
#testScript;
|
|
45
|
-
#watcher;
|
|
46
|
-
#assetsServer;
|
|
47
|
-
/**
|
|
48
|
-
* Getting reference to colors library from logger
|
|
49
|
-
*/
|
|
50
|
-
get #colors() {
|
|
51
|
-
return this.#logger.getColors();
|
|
52
|
-
}
|
|
53
|
-
constructor(cwd, options) {
|
|
54
|
-
this.#cwd = cwd;
|
|
55
|
-
this.#options = options;
|
|
56
|
-
this.#isMetaFile = picomatch((this.#options.metaFiles || []).map(({ pattern }) => pattern));
|
|
57
|
-
this.#isTestFile = picomatch(this.#options.suites
|
|
58
|
-
.filter((suite) => {
|
|
59
|
-
if (this.#options.filters.suites) {
|
|
60
|
-
this.#options.filters.suites.includes(suite.name);
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
})
|
|
64
|
-
.map((suite) => suite.files)
|
|
65
|
-
.flat(1));
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Converts all known filters to CLI args.
|
|
69
|
-
*
|
|
70
|
-
* The following code snippet may seem like repetitive code. But, it
|
|
71
|
-
* is done intentionally to have visibility around how each filter
|
|
72
|
-
* is converted to an arg.
|
|
73
|
-
*/
|
|
74
|
-
#convertFiltersToArgs(filters) {
|
|
75
|
-
const args = [];
|
|
76
|
-
if (filters.suites) {
|
|
77
|
-
args.push(...filters.suites);
|
|
78
|
-
}
|
|
79
|
-
if (filters.files) {
|
|
80
|
-
args.push('--files');
|
|
81
|
-
args.push(filters.files.join(','));
|
|
82
|
-
}
|
|
83
|
-
if (filters.groups) {
|
|
84
|
-
args.push('--groups');
|
|
85
|
-
args.push(filters.groups.join(','));
|
|
86
|
-
}
|
|
87
|
-
if (filters.tags) {
|
|
88
|
-
args.push('--tags');
|
|
89
|
-
args.push(filters.tags.join(','));
|
|
90
|
-
}
|
|
91
|
-
if (filters.ignoreTags) {
|
|
92
|
-
args.push('--ignore-tags');
|
|
93
|
-
args.push(filters.ignoreTags.join(','));
|
|
94
|
-
}
|
|
95
|
-
if (filters.tests) {
|
|
96
|
-
args.push('--ignore-tests');
|
|
97
|
-
args.push(filters.tests.join(','));
|
|
98
|
-
}
|
|
99
|
-
return args;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Conditionally clear the terminal screen
|
|
103
|
-
*/
|
|
104
|
-
#clearScreen() {
|
|
105
|
-
if (this.#options.clearScreen) {
|
|
106
|
-
process.stdout.write('\u001Bc');
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Runs tests
|
|
111
|
-
*/
|
|
112
|
-
#runTests(port, filtersArgs, mode) {
|
|
113
|
-
this.#isBusy = true;
|
|
114
|
-
this.#testScript = runNode(this.#cwd, {
|
|
115
|
-
script: this.#scriptFile,
|
|
116
|
-
env: { PORT: port, ...this.#options.env },
|
|
117
|
-
nodeArgs: this.#options.nodeArgs,
|
|
118
|
-
scriptArgs: filtersArgs.concat(this.#options.scriptArgs),
|
|
119
|
-
});
|
|
120
|
-
this.#testScript
|
|
121
|
-
.then((result) => {
|
|
122
|
-
if (mode === 'nonblocking') {
|
|
123
|
-
this.#onClose?.(result.exitCode);
|
|
124
|
-
this.close();
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
.catch((error) => {
|
|
128
|
-
if (mode === 'nonblocking') {
|
|
129
|
-
this.#onError?.(error);
|
|
130
|
-
this.close();
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
.finally(() => {
|
|
134
|
-
this.#isBusy = false;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Restarts the HTTP server
|
|
139
|
-
*/
|
|
140
|
-
#rerunTests(port, filtersArgs) {
|
|
141
|
-
if (this.#testScript) {
|
|
142
|
-
this.#testScript.removeAllListeners();
|
|
143
|
-
this.#testScript.kill('SIGKILL');
|
|
144
|
-
}
|
|
145
|
-
this.#runTests(port, filtersArgs, 'blocking');
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Starts the assets server
|
|
149
|
-
*/
|
|
150
|
-
#startAssetsServer() {
|
|
151
|
-
this.#assetsServer = new AssetsDevServer(this.#cwd, this.#options.assets);
|
|
152
|
-
this.#assetsServer.setLogger(this.#logger);
|
|
153
|
-
this.#assetsServer.start();
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Handles a non TypeScript file change
|
|
157
|
-
*/
|
|
158
|
-
#handleFileChange(action, port, filters, relativePath) {
|
|
159
|
-
if (this.#isBusy) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (isDotEnvFile(relativePath) || this.#isMetaFile(relativePath)) {
|
|
163
|
-
this.#clearScreen();
|
|
164
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
165
|
-
this.#rerunTests(port, filters);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Handles TypeScript source file change
|
|
170
|
-
*/
|
|
171
|
-
#handleSourceFileChange(action, port, filters, relativePath) {
|
|
172
|
-
if (this.#isBusy) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
this.#clearScreen();
|
|
176
|
-
this.#logger.log(`${this.#colors.green(action)} ${relativePath}`);
|
|
177
|
-
/**
|
|
178
|
-
* If changed file is a test file after considering the initial filters,
|
|
179
|
-
* then only run that file
|
|
180
|
-
*/
|
|
181
|
-
if (this.#isTestFile(relativePath)) {
|
|
182
|
-
this.#rerunTests(port, this.#convertFiltersToArgs({
|
|
183
|
-
...this.#options.filters,
|
|
184
|
-
files: [relativePath],
|
|
185
|
-
}));
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
this.#rerunTests(port, filters);
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Set a custom CLI UI logger
|
|
192
|
-
*/
|
|
193
|
-
setLogger(logger) {
|
|
194
|
-
this.#logger = logger;
|
|
195
|
-
this.#assetsServer?.setLogger(logger);
|
|
196
|
-
return this;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Add listener to get notified when dev server is
|
|
200
|
-
* closed
|
|
201
|
-
*/
|
|
202
|
-
onClose(callback) {
|
|
203
|
-
this.#onClose = callback;
|
|
204
|
-
return this;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Add listener to get notified when dev server exists
|
|
208
|
-
* with an error
|
|
209
|
-
*/
|
|
210
|
-
onError(callback) {
|
|
211
|
-
this.#onError = callback;
|
|
212
|
-
return this;
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Close watchers and running child processes
|
|
216
|
-
*/
|
|
217
|
-
async close() {
|
|
218
|
-
await this.#watcher?.close();
|
|
219
|
-
this.#assetsServer?.stop();
|
|
220
|
-
if (this.#testScript) {
|
|
221
|
-
this.#testScript.removeAllListeners();
|
|
222
|
-
this.#testScript.kill('SIGKILL');
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Runs tests
|
|
227
|
-
*/
|
|
228
|
-
async run() {
|
|
229
|
-
const port = String(await getPort(this.#cwd));
|
|
230
|
-
const initialFilters = this.#convertFiltersToArgs(this.#options.filters);
|
|
231
|
-
this.#clearScreen();
|
|
232
|
-
this.#startAssetsServer();
|
|
233
|
-
this.#logger.info('booting application to run tests...');
|
|
234
|
-
this.#runTests(port, initialFilters, 'nonblocking');
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Run tests in watch mode
|
|
238
|
-
*/
|
|
239
|
-
async runAndWatch(ts, options) {
|
|
240
|
-
const port = String(await getPort(this.#cwd));
|
|
241
|
-
const initialFilters = this.#convertFiltersToArgs(this.#options.filters);
|
|
242
|
-
this.#clearScreen();
|
|
243
|
-
this.#startAssetsServer();
|
|
244
|
-
this.#logger.info('booting application to run tests...');
|
|
245
|
-
this.#runTests(port, initialFilters, 'blocking');
|
|
246
|
-
/**
|
|
247
|
-
* Create watcher using tsconfig.json file
|
|
248
|
-
*/
|
|
249
|
-
const output = watch(this.#cwd, ts, options || {});
|
|
250
|
-
if (!output) {
|
|
251
|
-
this.#onClose?.(1);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Storing reference to watcher, so that we can close it
|
|
256
|
-
* when HTTP server exists with error
|
|
257
|
-
*/
|
|
258
|
-
this.#watcher = output.chokidar;
|
|
259
|
-
/**
|
|
260
|
-
* Notify the watcher is ready
|
|
261
|
-
*/
|
|
262
|
-
output.watcher.on('watcher:ready', () => {
|
|
263
|
-
this.#logger.info('watching file system for changes...');
|
|
264
|
-
});
|
|
265
|
-
/**
|
|
266
|
-
* Cleanup when watcher dies
|
|
267
|
-
*/
|
|
268
|
-
output.chokidar.on('error', (error) => {
|
|
269
|
-
this.#logger.warning('file system watcher failure');
|
|
270
|
-
this.#logger.fatal(error);
|
|
271
|
-
this.#onError?.(error);
|
|
272
|
-
output.chokidar.close();
|
|
273
|
-
});
|
|
274
|
-
/**
|
|
275
|
-
* Changes in TypeScript source file
|
|
276
|
-
*/
|
|
277
|
-
output.watcher.on('source:add', ({ relativePath }) => this.#handleSourceFileChange('add', port, initialFilters, relativePath));
|
|
278
|
-
output.watcher.on('source:change', ({ relativePath }) => this.#handleSourceFileChange('update', port, initialFilters, relativePath));
|
|
279
|
-
output.watcher.on('source:unlink', ({ relativePath }) => this.#handleSourceFileChange('delete', port, initialFilters, relativePath));
|
|
280
|
-
/**
|
|
281
|
-
* Changes in non-TypeScript source files
|
|
282
|
-
*/
|
|
283
|
-
output.watcher.on('add', ({ relativePath }) => this.#handleFileChange('add', port, initialFilters, relativePath));
|
|
284
|
-
output.watcher.on('change', ({ relativePath }) => this.#handleFileChange('update', port, initialFilters, relativePath));
|
|
285
|
-
output.watcher.on('unlink', ({ relativePath }) => this.#handleFileChange('delete', port, initialFilters, relativePath));
|
|
286
|
-
}
|
|
287
|
-
}
|