@adonisjs/assembler 6.0.0-0 → 6.1.1-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 +57 -10
- package/build/src/run.d.ts +2 -1
- package/build/src/run.js +14 -2
- package/build/src/types.d.ts +9 -0
- package/package.json +7 -4
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
|
@@ -2,8 +2,8 @@ import getPort from 'get-port';
|
|
|
2
2
|
import picomatch from 'picomatch';
|
|
3
3
|
import { cliui } from '@poppinss/cliui';
|
|
4
4
|
import { EnvLoader, EnvParser } from '@adonisjs/env';
|
|
5
|
-
import { run } from './run.js';
|
|
6
5
|
import { watch } from './watch.js';
|
|
6
|
+
import { run, runNode } from './run.js';
|
|
7
7
|
const ui = cliui();
|
|
8
8
|
export class DevServer {
|
|
9
9
|
#cwd;
|
|
@@ -14,6 +14,10 @@ export class DevServer {
|
|
|
14
14
|
#httpServerProcess;
|
|
15
15
|
#isMetaFileWithReloadsEnabled;
|
|
16
16
|
#isMetaFileWithReloadsDisabled;
|
|
17
|
+
#watcher;
|
|
18
|
+
#assetsServerProcess;
|
|
19
|
+
#onError;
|
|
20
|
+
#onClose;
|
|
17
21
|
get #colors() {
|
|
18
22
|
return this.#logger.getColors();
|
|
19
23
|
}
|
|
@@ -61,8 +65,8 @@ export class DevServer {
|
|
|
61
65
|
}
|
|
62
66
|
return getPort({ port: 3333 });
|
|
63
67
|
}
|
|
64
|
-
#startHTTPServer(port) {
|
|
65
|
-
this.#httpServerProcess =
|
|
68
|
+
#startHTTPServer(port, mode) {
|
|
69
|
+
this.#httpServerProcess = runNode(this.#cwd, {
|
|
66
70
|
script: this.#scriptFile,
|
|
67
71
|
env: { PORT: port, ...this.#options.env },
|
|
68
72
|
nodeArgs: this.#options.nodeArgs,
|
|
@@ -78,13 +82,38 @@ export class DevServer {
|
|
|
78
82
|
.render();
|
|
79
83
|
}
|
|
80
84
|
});
|
|
81
|
-
this.#httpServerProcess
|
|
85
|
+
this.#httpServerProcess
|
|
86
|
+
.then((result) => {
|
|
87
|
+
this.#logger.warning(`underlying HTTP server closed with status code "${result.exitCode}"`);
|
|
88
|
+
if (mode === 'nonblocking') {
|
|
89
|
+
this.#onClose?.(result.exitCode);
|
|
90
|
+
this.#watcher?.close();
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
.catch((error) => {
|
|
82
94
|
this.#logger.warning('unable to connect to underlying HTTP server process');
|
|
83
95
|
this.#logger.fatal(error);
|
|
96
|
+
this.#onError?.(error);
|
|
97
|
+
this.#watcher?.close();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
#startAssetsServer() {
|
|
101
|
+
const assetsBundler = this.#options.assets;
|
|
102
|
+
if (!assetsBundler?.serve) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
this.#logger.info(`starting "${assetsBundler.driver}" dev server...`);
|
|
106
|
+
this.#assetsServerProcess = run(assetsBundler.cmd, {
|
|
107
|
+
script: this.#scriptFile,
|
|
108
|
+
scriptArgs: this.#options.scriptArgs,
|
|
84
109
|
});
|
|
85
|
-
this.#
|
|
86
|
-
|
|
87
|
-
this.#logger.
|
|
110
|
+
this.#assetsServerProcess
|
|
111
|
+
.then((result) => {
|
|
112
|
+
this.#logger.warning(`"${assetsBundler.driver}" dev server closed with status code "${result.exitCode}"`);
|
|
113
|
+
})
|
|
114
|
+
.catch((error) => {
|
|
115
|
+
this.#logger.warning(`unable to connect to "${assetsBundler.driver}" dev server`);
|
|
116
|
+
this.#logger.fatal(error);
|
|
88
117
|
});
|
|
89
118
|
}
|
|
90
119
|
#restart(port) {
|
|
@@ -92,30 +121,48 @@ export class DevServer {
|
|
|
92
121
|
this.#httpServerProcess.removeAllListeners();
|
|
93
122
|
this.#httpServerProcess.kill('SIGKILL');
|
|
94
123
|
}
|
|
95
|
-
this.#startHTTPServer(port);
|
|
124
|
+
this.#startHTTPServer(port, 'blocking');
|
|
96
125
|
}
|
|
97
126
|
setLogger(logger) {
|
|
98
127
|
this.#logger = logger;
|
|
99
128
|
return this;
|
|
100
129
|
}
|
|
130
|
+
onClose(callback) {
|
|
131
|
+
this.#onClose = callback;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
onError(callback) {
|
|
135
|
+
this.#onError = callback;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
101
138
|
async start() {
|
|
102
139
|
this.#clearScreen();
|
|
103
140
|
this.#logger.info('starting HTTP server...');
|
|
104
|
-
this.#startHTTPServer(String(await this.#getPort()));
|
|
141
|
+
this.#startHTTPServer(String(await this.#getPort()), 'nonblocking');
|
|
142
|
+
this.#startAssetsServer();
|
|
105
143
|
}
|
|
106
144
|
async startAndWatch(ts, options) {
|
|
107
145
|
const port = String(await this.#getPort());
|
|
108
146
|
this.#isWatching = true;
|
|
109
147
|
this.#clearScreen();
|
|
110
148
|
this.#logger.info('starting HTTP server...');
|
|
111
|
-
this.#startHTTPServer(port);
|
|
149
|
+
this.#startHTTPServer(port, 'blocking');
|
|
150
|
+
this.#startAssetsServer();
|
|
112
151
|
const output = watch(this.#cwd, ts, options || {});
|
|
113
152
|
if (!output) {
|
|
153
|
+
this.#onClose?.(1);
|
|
114
154
|
return;
|
|
115
155
|
}
|
|
156
|
+
this.#watcher = output.chokidar;
|
|
116
157
|
output.watcher.on('watcher:ready', () => {
|
|
117
158
|
this.#logger.info('watching file system for changes...');
|
|
118
159
|
});
|
|
160
|
+
output.chokidar.on('error', (error) => {
|
|
161
|
+
this.#logger.warning('file system watcher failure');
|
|
162
|
+
this.#logger.fatal(error);
|
|
163
|
+
this.#onError?.(error);
|
|
164
|
+
output.chokidar.close();
|
|
165
|
+
});
|
|
119
166
|
output.watcher.on('source:add', ({ relativePath }) => {
|
|
120
167
|
this.#clearScreen();
|
|
121
168
|
this.#logger.log(`${this.#colors.green('add')} ${relativePath}`);
|
package/build/src/run.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { RunOptions } from './types.js';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function runNode(cwd: string | URL, options: RunOptions): import("execa").ExecaChildProcess<string>;
|
|
4
|
+
export declare function run(cwd: string | URL, options: Omit<RunOptions, 'nodeArgs'>): import("execa").ExecaChildProcess<string>;
|
package/build/src/run.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { execaNode } from 'execa';
|
|
1
|
+
import { execaNode, execa } from 'execa';
|
|
2
2
|
const DEFAULT_NODE_ARGS = [
|
|
3
3
|
'--loader=ts-node/esm',
|
|
4
4
|
'--no-warnings',
|
|
5
5
|
'--experimental-import-meta-resolve',
|
|
6
6
|
];
|
|
7
|
-
export function
|
|
7
|
+
export function runNode(cwd, options) {
|
|
8
8
|
const childProces = execaNode(options.script, options.scriptArgs, {
|
|
9
9
|
nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),
|
|
10
10
|
preferLocal: true,
|
|
@@ -17,3 +17,15 @@ export function run(cwd, options) {
|
|
|
17
17
|
});
|
|
18
18
|
return childProces;
|
|
19
19
|
}
|
|
20
|
+
export function run(cwd, options) {
|
|
21
|
+
const childProces = execa(options.script, options.scriptArgs, {
|
|
22
|
+
preferLocal: true,
|
|
23
|
+
windowsHide: false,
|
|
24
|
+
localDir: cwd,
|
|
25
|
+
cwd,
|
|
26
|
+
buffer: false,
|
|
27
|
+
stdio: 'inherit',
|
|
28
|
+
env: options.env,
|
|
29
|
+
});
|
|
30
|
+
return childProces;
|
|
31
|
+
}
|
package/build/src/types.d.ts
CHANGED
|
@@ -17,6 +17,15 @@ export type DevServerOptions = {
|
|
|
17
17
|
pattern: string;
|
|
18
18
|
reloadServer: boolean;
|
|
19
19
|
}[];
|
|
20
|
+
assets?: {
|
|
21
|
+
serve: false;
|
|
22
|
+
driver?: string;
|
|
23
|
+
cmd?: string;
|
|
24
|
+
} | {
|
|
25
|
+
serve: true;
|
|
26
|
+
driver: string;
|
|
27
|
+
cmd: string;
|
|
28
|
+
};
|
|
20
29
|
};
|
|
21
30
|
export type BundlerOptions = {
|
|
22
31
|
metaFiles?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/assembler",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1-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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@poppinss/cliui": "^6.1.1-0",
|
|
46
46
|
"@poppinss/dev-utils": "^2.0.3",
|
|
47
47
|
"@swc/core": "^1.3.36",
|
|
48
|
-
"@types/node": "^18.14.
|
|
48
|
+
"@types/node": "^18.14.3",
|
|
49
49
|
"c8": "^7.13.0",
|
|
50
50
|
"copyfiles": "^2.4.1",
|
|
51
51
|
"cross-env": "^7.0.3",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@adonisjs/env": "^4.2.0-0",
|
|
67
|
-
"@poppinss/chokidar-ts": "^4.
|
|
67
|
+
"@poppinss/chokidar-ts": "^4.1.0-0",
|
|
68
68
|
"@types/fs-extra": "^11.0.1",
|
|
69
69
|
"@types/picomatch": "^2.3.0",
|
|
70
70
|
"cpy": "^9.0.1",
|
|
@@ -74,6 +74,9 @@
|
|
|
74
74
|
"picomatch": "^2.3.1",
|
|
75
75
|
"slash": "^5.0.0"
|
|
76
76
|
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"typescript": "^4.0.0 || ^5.0.0"
|
|
79
|
+
},
|
|
77
80
|
"repository": {
|
|
78
81
|
"type": "git",
|
|
79
82
|
"url": "git+ssh://git@github.com/adonisjs/assembler.git"
|