@adonisjs/assembler 6.0.0-0 → 6.1.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 +24 -37
- package/build/src/bundler.js +14 -4
- package/build/src/dev_server.d.ts +2 -0
- package/build/src/dev_server.js +35 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,49 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px">
|
|
3
|
-
</div>
|
|
1
|
+
# @adonisjs/assembler
|
|
4
2
|
|
|
5
3
|
<br />
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
<h3> Core Commands for building AdonisJS projects </h3>
|
|
9
|
-
<p>
|
|
10
|
-
Assembler contains a set of core commands to <strong>build and serve the AdonisJS typescript project</strong>, along with scaffolding <code>make</code> commands.
|
|
11
|
-
</p>
|
|
12
|
-
</div>
|
|
5
|
+
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]
|
|
13
6
|
|
|
14
|
-
|
|
7
|
+
## Introduction
|
|
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.
|
|
9
|
+
|
|
10
|
+
## Official Documentation
|
|
11
|
+
The documentation is available on the official website
|
|
12
|
+
|
|
13
|
+
## Contributing
|
|
14
|
+
One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
|
|
15
|
+
|
|
16
|
+
We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<h3>
|
|
24
|
-
<a href="https://adonisjs.com">
|
|
25
|
-
Website
|
|
26
|
-
</a>
|
|
27
|
-
<span> | </span>
|
|
28
|
-
<a href="https://docs.adonisjs.com/guides/installation">
|
|
29
|
-
Guides
|
|
30
|
-
</a>
|
|
31
|
-
<span> | </span>
|
|
32
|
-
<a href="CONTRIBUTING.md">
|
|
33
|
-
Contributing
|
|
34
|
-
</a>
|
|
35
|
-
</h3>
|
|
36
|
-
</div>
|
|
37
|
-
|
|
38
|
-
<div align="center">
|
|
39
|
-
<sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a>
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
[gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/assembler/test?style=for-the-badge
|
|
18
|
+
## Code of Conduct
|
|
19
|
+
In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/adonisjs/.github/blob/main/docs/CODE_OF_CONDUCT.md).
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
AdonisJS Assembler is open-sourced software licensed under the [MIT license](LICENSE.md).
|
|
23
|
+
|
|
24
|
+
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/assembler/test.yml?style=for-the-badge
|
|
43
25
|
[gh-workflow-url]: https://github.com/adonisjs/assembler/actions/workflows/test.yml "Github action"
|
|
44
26
|
|
|
45
27
|
[npm-image]: https://img.shields.io/npm/v/@adonisjs/assembler/latest.svg?style=for-the-badge&logo=npm
|
|
46
28
|
[npm-url]: https://npmjs.org/package/@adonisjs/assembler/v/latest "npm"
|
|
47
29
|
|
|
30
|
+
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
|
|
31
|
+
|
|
32
|
+
[license-url]: LICENSE.md
|
|
33
|
+
[license-image]: https://img.shields.io/github/license/adonisjs/ace?style=for-the-badge
|
|
34
|
+
|
|
48
35
|
[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/assembler?label=Synk%20Vulnerabilities&style=for-the-badge
|
|
49
36
|
[synk-url]: https://snyk.io/test/github/adonisjs/assembler?targetFile=package.json "synk"
|
package/build/src/bundler.js
CHANGED
|
@@ -28,9 +28,9 @@ export class Bundler {
|
|
|
28
28
|
async #cleanupBuildDirectory(outDir) {
|
|
29
29
|
await fs.remove(outDir);
|
|
30
30
|
}
|
|
31
|
-
async #runTsc() {
|
|
31
|
+
async #runTsc(outDir) {
|
|
32
32
|
try {
|
|
33
|
-
await execa('tsc', [], {
|
|
33
|
+
await execa('tsc', ['--outDir', outDir], {
|
|
34
34
|
cwd: this.#cwd,
|
|
35
35
|
preferLocal: true,
|
|
36
36
|
localDir: this.#cwd,
|
|
@@ -93,7 +93,17 @@ export class Bundler {
|
|
|
93
93
|
return this;
|
|
94
94
|
}
|
|
95
95
|
async bundle(stopOnError = true, client = 'npm') {
|
|
96
|
-
const { config } = new ConfigParser(this.#cwd, 'tsconfig.json', this.#ts).parse();
|
|
96
|
+
const { config, error } = new ConfigParser(this.#cwd, 'tsconfig.json', this.#ts).parse();
|
|
97
|
+
if (error) {
|
|
98
|
+
const compilerHost = this.#ts.createCompilerHost({});
|
|
99
|
+
this.#logger.logError(this.#ts.formatDiagnosticsWithColorAndContext([error], compilerHost));
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (config.errors.length) {
|
|
103
|
+
const compilerHost = this.#ts.createCompilerHost({});
|
|
104
|
+
this.#logger.logError(this.#ts.formatDiagnosticsWithColorAndContext(config.errors, compilerHost));
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
97
107
|
if (!config) {
|
|
98
108
|
return false;
|
|
99
109
|
}
|
|
@@ -101,7 +111,7 @@ export class Bundler {
|
|
|
101
111
|
this.#logger.info('cleaning up output directory', { suffix: this.#getRelativeName(outDir) });
|
|
102
112
|
await this.#cleanupBuildDirectory(outDir);
|
|
103
113
|
this.#logger.info('compiling typescript source', { suffix: 'tsc' });
|
|
104
|
-
const buildCompleted = await this.#runTsc();
|
|
114
|
+
const buildCompleted = await this.#runTsc(outDir);
|
|
105
115
|
await this.#copyFiles(['ace.js'], outDir);
|
|
106
116
|
if (!buildCompleted && stopOnError) {
|
|
107
117
|
await this.#cleanupBuildDirectory(outDir);
|
|
@@ -6,6 +6,8 @@ export declare class DevServer {
|
|
|
6
6
|
#private;
|
|
7
7
|
constructor(cwd: URL, options: DevServerOptions);
|
|
8
8
|
setLogger(logger: Logger): this;
|
|
9
|
+
onClose(callback: (exitCode: number) => any): this;
|
|
10
|
+
onError(callback: (error: any) => any): this;
|
|
9
11
|
start(): Promise<void>;
|
|
10
12
|
startAndWatch(ts: typeof tsStatic, options?: {
|
|
11
13
|
poll: boolean;
|
package/build/src/dev_server.js
CHANGED
|
@@ -14,6 +14,9 @@ export class DevServer {
|
|
|
14
14
|
#httpServerProcess;
|
|
15
15
|
#isMetaFileWithReloadsEnabled;
|
|
16
16
|
#isMetaFileWithReloadsDisabled;
|
|
17
|
+
#watcher;
|
|
18
|
+
#onError;
|
|
19
|
+
#onClose;
|
|
17
20
|
get #colors() {
|
|
18
21
|
return this.#logger.getColors();
|
|
19
22
|
}
|
|
@@ -61,7 +64,7 @@ export class DevServer {
|
|
|
61
64
|
}
|
|
62
65
|
return getPort({ port: 3333 });
|
|
63
66
|
}
|
|
64
|
-
#startHTTPServer(port) {
|
|
67
|
+
#startHTTPServer(port, mode) {
|
|
65
68
|
this.#httpServerProcess = run(this.#cwd, {
|
|
66
69
|
script: this.#scriptFile,
|
|
67
70
|
env: { PORT: port, ...this.#options.env },
|
|
@@ -78,13 +81,19 @@ export class DevServer {
|
|
|
78
81
|
.render();
|
|
79
82
|
}
|
|
80
83
|
});
|
|
81
|
-
this.#httpServerProcess
|
|
84
|
+
this.#httpServerProcess
|
|
85
|
+
.then((result) => {
|
|
86
|
+
this.#logger.warning(`underlying HTTP server closed with status code "${result.exitCode}"`);
|
|
87
|
+
if (mode === 'nonblocking') {
|
|
88
|
+
this.#onClose?.(result.exitCode);
|
|
89
|
+
this.#watcher?.close();
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
.catch((error) => {
|
|
82
93
|
this.#logger.warning('unable to connect to underlying HTTP server process');
|
|
83
94
|
this.#logger.fatal(error);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.#logger.warning(`underlying HTTP server closed with status code "${exitCode}"`);
|
|
87
|
-
this.#logger.info('watching file system and waiting for application to recover');
|
|
95
|
+
this.#onError?.(error);
|
|
96
|
+
this.#watcher?.close();
|
|
88
97
|
});
|
|
89
98
|
}
|
|
90
99
|
#restart(port) {
|
|
@@ -92,30 +101,46 @@ export class DevServer {
|
|
|
92
101
|
this.#httpServerProcess.removeAllListeners();
|
|
93
102
|
this.#httpServerProcess.kill('SIGKILL');
|
|
94
103
|
}
|
|
95
|
-
this.#startHTTPServer(port);
|
|
104
|
+
this.#startHTTPServer(port, 'blocking');
|
|
96
105
|
}
|
|
97
106
|
setLogger(logger) {
|
|
98
107
|
this.#logger = logger;
|
|
99
108
|
return this;
|
|
100
109
|
}
|
|
110
|
+
onClose(callback) {
|
|
111
|
+
this.#onClose = callback;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
onError(callback) {
|
|
115
|
+
this.#onError = callback;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
101
118
|
async start() {
|
|
102
119
|
this.#clearScreen();
|
|
103
120
|
this.#logger.info('starting HTTP server...');
|
|
104
|
-
this.#startHTTPServer(String(await this.#getPort()));
|
|
121
|
+
this.#startHTTPServer(String(await this.#getPort()), 'nonblocking');
|
|
105
122
|
}
|
|
106
123
|
async startAndWatch(ts, options) {
|
|
107
|
-
const port = String(await this.#getPort());
|
|
108
124
|
this.#isWatching = true;
|
|
109
125
|
this.#clearScreen();
|
|
126
|
+
const port = String(await this.#getPort());
|
|
110
127
|
this.#logger.info('starting HTTP server...');
|
|
111
|
-
this.#startHTTPServer(port);
|
|
128
|
+
this.#startHTTPServer(port, 'blocking');
|
|
112
129
|
const output = watch(this.#cwd, ts, options || {});
|
|
113
130
|
if (!output) {
|
|
131
|
+
this.#onClose?.(1);
|
|
114
132
|
return;
|
|
115
133
|
}
|
|
134
|
+
this.#watcher = output.chokidar;
|
|
116
135
|
output.watcher.on('watcher:ready', () => {
|
|
117
136
|
this.#logger.info('watching file system for changes...');
|
|
118
137
|
});
|
|
138
|
+
output.chokidar.on('error', (error) => {
|
|
139
|
+
this.#logger.warning('file system watcher failure');
|
|
140
|
+
this.#logger.fatal(error);
|
|
141
|
+
this.#onError?.(error);
|
|
142
|
+
output.chokidar.close();
|
|
143
|
+
});
|
|
119
144
|
output.watcher.on('source:add', ({ relativePath }) => {
|
|
120
145
|
this.#clearScreen();
|
|
121
146
|
this.#logger.log(`${this.#colors.green('add')} ${relativePath}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/assembler",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0-0",
|
|
4
4
|
"description": "Provides utilities to run AdonisJS development server and build project for production",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"pretest": "npm run lint",
|
|
18
|
-
"test": "cross-env NODE_DEBUG=
|
|
18
|
+
"test": "cross-env NODE_DEBUG=chokidar:ts c8 npm run vscode:test",
|
|
19
19
|
"lint": "eslint . --ext=.ts",
|
|
20
20
|
"clean": "del-cli build",
|
|
21
21
|
"compile": "npm run lint && npm run clean && tsc",
|