@adonisjs/assembler 6.1.2-0 → 6.1.3-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/build/src/bundler.js +28 -20
- package/build/src/dev_server.js +52 -2
- package/build/src/parse_config.d.ts +3 -0
- package/build/src/parse_config.js +15 -0
- package/build/src/run.js +14 -8
- package/build/src/types.d.ts +18 -17
- package/build/src/watch.js +4 -10
- package/package.json +1 -1
package/build/src/bundler.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import slash from 'slash';
|
|
3
3
|
import copyfiles from 'cpy';
|
|
4
|
-
import { execa } from 'execa';
|
|
5
|
-
import { join, relative } from 'node:path';
|
|
6
4
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import {
|
|
5
|
+
import { join, relative } from 'node:path';
|
|
8
6
|
import { cliui } from '@poppinss/cliui';
|
|
7
|
+
import { run } from './run.js';
|
|
8
|
+
import { parseConfig } from './parse_config.js';
|
|
9
9
|
const ui = cliui();
|
|
10
10
|
export class Bundler {
|
|
11
11
|
#cwd;
|
|
@@ -28,15 +28,30 @@ export class Bundler {
|
|
|
28
28
|
async #cleanupBuildDirectory(outDir) {
|
|
29
29
|
await fs.remove(outDir);
|
|
30
30
|
}
|
|
31
|
+
async #buildAssets() {
|
|
32
|
+
const assetsBundler = this.#options.assets;
|
|
33
|
+
if (!assetsBundler?.serve) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
this.#logger.info('compiling frontend assets', { suffix: assetsBundler.cmd });
|
|
38
|
+
await run(this.#cwd, {
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
script: assetsBundler.cmd,
|
|
41
|
+
scriptArgs: [],
|
|
42
|
+
});
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
31
49
|
async #runTsc(outDir) {
|
|
32
50
|
try {
|
|
33
|
-
await
|
|
34
|
-
cwd: this.#cwd,
|
|
35
|
-
preferLocal: true,
|
|
36
|
-
localDir: this.#cwd,
|
|
37
|
-
windowsHide: false,
|
|
38
|
-
buffer: false,
|
|
51
|
+
await run(this.#cwd, {
|
|
39
52
|
stdio: 'inherit',
|
|
53
|
+
script: 'tsc',
|
|
54
|
+
scriptArgs: ['--outDir', outDir],
|
|
40
55
|
});
|
|
41
56
|
return true;
|
|
42
57
|
}
|
|
@@ -93,23 +108,16 @@ export class Bundler {
|
|
|
93
108
|
return this;
|
|
94
109
|
}
|
|
95
110
|
async bundle(stopOnError = true, client = 'npm') {
|
|
96
|
-
const
|
|
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
|
-
}
|
|
111
|
+
const config = parseConfig(this.#cwd, this.#ts);
|
|
107
112
|
if (!config) {
|
|
108
113
|
return false;
|
|
109
114
|
}
|
|
110
115
|
const outDir = config.options.outDir || fileURLToPath(new URL('build/', this.#cwd));
|
|
111
116
|
this.#logger.info('cleaning up output directory', { suffix: this.#getRelativeName(outDir) });
|
|
112
117
|
await this.#cleanupBuildDirectory(outDir);
|
|
118
|
+
if (!(await this.#buildAssets())) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
113
121
|
this.#logger.info('compiling typescript source', { suffix: 'tsc' });
|
|
114
122
|
const buildCompleted = await this.#runTsc(outDir);
|
|
115
123
|
await this.#copyFiles(['ace.js'], outDir);
|
package/build/src/dev_server.js
CHANGED
|
@@ -52,6 +52,39 @@ export class DevServer {
|
|
|
52
52
|
process.stdout.write('\u001Bc');
|
|
53
53
|
}
|
|
54
54
|
}
|
|
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
|
+
}
|
|
55
88
|
async #getPort() {
|
|
56
89
|
if (process.env.PORT) {
|
|
57
90
|
return getPort({ port: Number(process.env.PORT) });
|
|
@@ -103,10 +136,27 @@ export class DevServer {
|
|
|
103
136
|
return;
|
|
104
137
|
}
|
|
105
138
|
this.#logger.info(`starting "${assetsBundler.driver}" dev server...`);
|
|
106
|
-
this.#assetsServerProcess = run(
|
|
107
|
-
script:
|
|
139
|
+
this.#assetsServerProcess = run(this.#cwd, {
|
|
140
|
+
script: assetsBundler.cmd,
|
|
141
|
+
stdio: 'pipe',
|
|
108
142
|
scriptArgs: this.#options.scriptArgs,
|
|
109
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
|
+
});
|
|
110
160
|
this.#assetsServerProcess
|
|
111
161
|
.then((result) => {
|
|
112
162
|
this.#logger.warning(`"${assetsBundler.driver}" dev server closed with status code "${result.exitCode}"`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConfigParser } from '@poppinss/chokidar-ts';
|
|
2
|
+
export function parseConfig(cwd, ts) {
|
|
3
|
+
const { config, error } = new ConfigParser(cwd, 'tsconfig.json', ts).parse();
|
|
4
|
+
if (error) {
|
|
5
|
+
const compilerHost = ts.createCompilerHost({});
|
|
6
|
+
console.log(ts.formatDiagnosticsWithColorAndContext([error], compilerHost));
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (config.errors.length) {
|
|
10
|
+
const compilerHost = ts.createCompilerHost({});
|
|
11
|
+
console.log(ts.formatDiagnosticsWithColorAndContext(config.errors, compilerHost));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return config;
|
|
15
|
+
}
|
package/build/src/run.js
CHANGED
|
@@ -5,27 +5,33 @@ const DEFAULT_NODE_ARGS = [
|
|
|
5
5
|
'--experimental-import-meta-resolve',
|
|
6
6
|
];
|
|
7
7
|
export function runNode(cwd, options) {
|
|
8
|
-
const
|
|
8
|
+
const childProcess = execaNode(options.script, options.scriptArgs, {
|
|
9
9
|
nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),
|
|
10
10
|
preferLocal: true,
|
|
11
11
|
windowsHide: false,
|
|
12
12
|
localDir: cwd,
|
|
13
13
|
cwd,
|
|
14
14
|
buffer: false,
|
|
15
|
-
stdio: 'inherit',
|
|
16
|
-
env:
|
|
15
|
+
stdio: options.stdio || 'inherit',
|
|
16
|
+
env: {
|
|
17
|
+
...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
|
|
18
|
+
...options.env,
|
|
19
|
+
},
|
|
17
20
|
});
|
|
18
|
-
return
|
|
21
|
+
return childProcess;
|
|
19
22
|
}
|
|
20
23
|
export function run(cwd, options) {
|
|
21
|
-
const
|
|
24
|
+
const childProcess = execa(options.script, options.scriptArgs, {
|
|
22
25
|
preferLocal: true,
|
|
23
26
|
windowsHide: false,
|
|
24
27
|
localDir: cwd,
|
|
25
28
|
cwd,
|
|
26
29
|
buffer: false,
|
|
27
|
-
stdio: 'inherit',
|
|
28
|
-
env:
|
|
30
|
+
stdio: options.stdio || 'inherit',
|
|
31
|
+
env: {
|
|
32
|
+
...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
|
|
33
|
+
...options.env,
|
|
34
|
+
},
|
|
29
35
|
});
|
|
30
|
-
return
|
|
36
|
+
return childProcess;
|
|
31
37
|
}
|
package/build/src/types.d.ts
CHANGED
|
@@ -3,33 +3,34 @@ export type RunOptions = {
|
|
|
3
3
|
script: string;
|
|
4
4
|
scriptArgs: string[];
|
|
5
5
|
nodeArgs: string[];
|
|
6
|
+
stdio?: 'pipe' | 'inherit';
|
|
6
7
|
env?: NodeJS.ProcessEnv;
|
|
7
8
|
};
|
|
8
9
|
export type WatchOptions = {
|
|
9
10
|
poll?: boolean;
|
|
10
11
|
};
|
|
12
|
+
export type MetaFile = {
|
|
13
|
+
pattern: string;
|
|
14
|
+
reloadServer: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type AssetsBundlerOptions = {
|
|
17
|
+
serve: false;
|
|
18
|
+
driver?: string;
|
|
19
|
+
cmd?: string;
|
|
20
|
+
} | {
|
|
21
|
+
serve: true;
|
|
22
|
+
driver: string;
|
|
23
|
+
cmd: string;
|
|
24
|
+
};
|
|
11
25
|
export type DevServerOptions = {
|
|
12
26
|
scriptArgs: string[];
|
|
13
27
|
nodeArgs: string[];
|
|
14
28
|
clearScreen?: boolean;
|
|
15
29
|
env?: NodeJS.ProcessEnv;
|
|
16
|
-
metaFiles?:
|
|
17
|
-
|
|
18
|
-
reloadServer: boolean;
|
|
19
|
-
}[];
|
|
20
|
-
assets?: {
|
|
21
|
-
serve: false;
|
|
22
|
-
driver?: string;
|
|
23
|
-
cmd?: string;
|
|
24
|
-
} | {
|
|
25
|
-
serve: true;
|
|
26
|
-
driver: string;
|
|
27
|
-
cmd: string;
|
|
28
|
-
};
|
|
30
|
+
metaFiles?: MetaFile[];
|
|
31
|
+
assets?: AssetsBundlerOptions;
|
|
29
32
|
};
|
|
30
33
|
export type BundlerOptions = {
|
|
31
|
-
metaFiles?:
|
|
32
|
-
|
|
33
|
-
reloadServer: boolean;
|
|
34
|
-
}[];
|
|
34
|
+
metaFiles?: MetaFile[];
|
|
35
|
+
assets?: AssetsBundlerOptions;
|
|
35
36
|
};
|
package/build/src/watch.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import {
|
|
2
|
+
import { Watcher } from '@poppinss/chokidar-ts';
|
|
3
|
+
import { parseConfig } from './parse_config.js';
|
|
3
4
|
export function watch(cwd, ts, options) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
const compilerHost = ts.createCompilerHost({});
|
|
7
|
-
console.log(ts.formatDiagnosticsWithColorAndContext([error], compilerHost));
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (config.errors.length) {
|
|
11
|
-
const compilerHost = ts.createCompilerHost({});
|
|
12
|
-
console.log(ts.formatDiagnosticsWithColorAndContext(config.errors, compilerHost));
|
|
5
|
+
const config = parseConfig(cwd, ts);
|
|
6
|
+
if (!config) {
|
|
13
7
|
return;
|
|
14
8
|
}
|
|
15
9
|
const watcher = new Watcher(typeof cwd === 'string' ? cwd : fileURLToPath(cwd), config);
|