@adonisjs/assembler 6.1.2-0 → 6.1.3-1

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.
@@ -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 { ConfigParser } from '@poppinss/chokidar-ts';
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 execa('tsc', ['--outDir', outDir], {
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 { 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
- }
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);
@@ -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(assetsBundler.cmd, {
107
- script: this.#scriptFile,
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,3 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type tsStatic from 'typescript';
3
+ export declare function parseConfig(cwd: string | URL, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
@@ -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 childProces = execaNode(options.script, options.scriptArgs, {
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: options.env,
15
+ stdio: options.stdio || 'inherit',
16
+ env: {
17
+ ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
18
+ ...options.env,
19
+ },
17
20
  });
18
- return childProces;
21
+ return childProcess;
19
22
  }
20
23
  export function run(cwd, options) {
21
- const childProces = execa(options.script, options.scriptArgs, {
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: options.env,
30
+ stdio: options.stdio || 'inherit',
31
+ env: {
32
+ ...(options.stdio === 'pipe' ? { FORCE_COLOR: 'true' } : {}),
33
+ ...options.env,
34
+ },
29
35
  });
30
- return childProces;
36
+ return childProcess;
31
37
  }
@@ -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
- pattern: string;
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
- pattern: string;
33
- reloadServer: boolean;
34
- }[];
34
+ metaFiles?: MetaFile[];
35
+ assets?: AssetsBundlerOptions;
35
36
  };
@@ -1,15 +1,9 @@
1
1
  import { fileURLToPath } from 'node:url';
2
- import { ConfigParser, Watcher } from '@poppinss/chokidar-ts';
2
+ import { Watcher } from '@poppinss/chokidar-ts';
3
+ import { parseConfig } from './parse_config.js';
3
4
  export function watch(cwd, ts, options) {
4
- const { config, error } = new ConfigParser(cwd, 'tsconfig.json', ts).parse();
5
- if (error) {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
- "version": "6.1.2-0",
3
+ "version": "6.1.3-1",
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",
@@ -42,16 +42,16 @@
42
42
  "@japa/run-failed-tests": "^1.1.1",
43
43
  "@japa/runner": "^2.5.1",
44
44
  "@japa/spec-reporter": "^1.3.3",
45
- "@swc/core": "^1.3.36",
46
- "@types/node": "^18.14.3",
45
+ "@swc/core": "^1.3.39",
46
+ "@types/node": "^18.15.0",
47
47
  "c8": "^7.13.0",
48
48
  "cross-env": "^7.0.3",
49
49
  "del-cli": "^5.0.0",
50
- "eslint": "^8.34.0",
51
- "eslint-config-prettier": "^8.6.0",
50
+ "eslint": "^8.36.0",
51
+ "eslint-config-prettier": "^8.7.0",
52
52
  "eslint-plugin-adonis": "^3.0.3",
53
53
  "eslint-plugin-prettier": "^4.2.1",
54
- "github-label-sync": "^2.2.0",
54
+ "github-label-sync": "^2.3.1",
55
55
  "husky": "^8.0.3",
56
56
  "np": "^7.6.3",
57
57
  "p-event": "^5.0.1",
@@ -61,8 +61,8 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@adonisjs/env": "^4.2.0-0",
64
- "@poppinss/chokidar-ts": "^4.1.0-0",
65
- "@poppinss/cliui": "^6.1.1-0",
64
+ "@poppinss/chokidar-ts": "^4.1.0-1",
65
+ "@poppinss/cliui": "^6.1.1-1",
66
66
  "@types/fs-extra": "^11.0.1",
67
67
  "@types/picomatch": "^2.3.0",
68
68
  "cpy": "^9.0.1",