@adonisjs/assembler 8.0.0-next.15 → 8.0.0-next.17

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.
@@ -26,6 +26,7 @@ import { importDefault } from "@poppinss/utils";
26
26
  import { copyFile, mkdir } from "fs/promises";
27
27
  import { EnvLoader, EnvParser } from "@adonisjs/env";
28
28
  import chokidar from "chokidar";
29
+ import { parseTsconfig } from "get-tsconfig";
29
30
  import { basename, dirname, isAbsolute, join, relative } from "path";
30
31
  var DEFAULT_NODE_ARGS = ["--import=@poppinss/ts-exec", "--enable-source-maps"];
31
32
  function parseConfig(cwd, ts) {
@@ -65,6 +66,29 @@ function parseConfig(cwd, ts) {
65
66
  }
66
67
  return parsedConfig;
67
68
  }
69
+ function readTsConfig(cwd) {
70
+ const tsConfigPath = join(cwd, "tsconfig.json");
71
+ debug_default('reading config file from location "%s"', tsConfigPath);
72
+ try {
73
+ const tsConfig = parseTsconfig(tsConfigPath);
74
+ if (tsConfig.include) {
75
+ tsConfig.include = tsConfig.include.map((resolvedPath) => {
76
+ return resolvedPath.replace(`${cwd}/`, "");
77
+ });
78
+ }
79
+ if (tsConfig.exclude) {
80
+ tsConfig.exclude = tsConfig.exclude.map((resolvedPath) => {
81
+ return resolvedPath.replace(`${cwd}/`, "");
82
+ });
83
+ }
84
+ return {
85
+ path: tsConfigPath,
86
+ config: tsConfig
87
+ };
88
+ } catch {
89
+ return null;
90
+ }
91
+ }
68
92
  function runNode(cwd, options) {
69
93
  const childProcess = execaNode(options.script, options.scriptArgs, {
70
94
  nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),
@@ -244,6 +268,30 @@ var VirtualFileSystem = class {
244
268
  };
245
269
  this.#matcher = picomatch(this.#options.glob ?? DEFAULT_GLOB, this.#picoMatchOptions);
246
270
  }
271
+ /**
272
+ * Currently the PathsResolver relies on a non-standard way of resolving
273
+ * absolute paths or paths with subpath imports. Because of which, the
274
+ * on-disk file could be TypeScript, while the resolved filepath is
275
+ * JavaScript.
276
+ *
277
+ * To overcome this limitation, we start by first looking for a `.ts` file
278
+ * (because of high probability) and then look for `.js` file
279
+ */
280
+ async #readTSOrJSFile(filePath) {
281
+ if (filePath.endsWith(".js")) {
282
+ try {
283
+ const contents = await readFile(filePath.replace(/\.js$/, ".ts"), "utf-8");
284
+ debug_default('read as TypeScript file "%s"', filePath);
285
+ return contents;
286
+ } catch (error) {
287
+ if (error.code === "ENOENT") {
288
+ return readFile(filePath, "utf-8");
289
+ }
290
+ throw error;
291
+ }
292
+ }
293
+ return readFile(filePath, "utf-8");
294
+ }
247
295
  /**
248
296
  * Scans the filesystem to collect the files. Newly files must
249
297
  * be added via the ".add" method.
@@ -358,7 +406,7 @@ var VirtualFileSystem = class {
358
406
  debug_default('returning AST nodes from cache "%s"', filePath);
359
407
  return cached;
360
408
  }
361
- const fileContents = await readFile(filePath, "utf-8");
409
+ const fileContents = await this.#readTSOrJSFile(filePath);
362
410
  debug_default('parsing "%s" file to AST', filePath);
363
411
  this.#astCache.set(filePath, parse(Lang.TypeScript, fileContents).root());
364
412
  return this.#astCache.get(filePath);
@@ -394,6 +442,7 @@ var VirtualFileSystem = class {
394
442
  export {
395
443
  debug_default,
396
444
  parseConfig,
445
+ readTsConfig,
397
446
  runNode,
398
447
  run,
399
448
  watch,
@@ -10,7 +10,7 @@ import {
10
10
  VirtualFileSystem,
11
11
  debug_default,
12
12
  isRelative
13
- } from "./chunk-3GYRM5Y2.js";
13
+ } from "./chunk-HRE5L24F.js";
14
14
 
15
15
  // src/code_scanners/routes_scanner/main.ts
16
16
  import { cliui } from "@poppinss/cliui";
@@ -20,6 +20,7 @@ import StringBuilder from "@poppinss/utils/string_builder";
20
20
 
21
21
  // src/paths_resolver.ts
22
22
  import { join } from "path";
23
+ import { resolve } from "import-meta-resolve";
23
24
  import { fileURLToPath, pathToFileURL } from "url";
24
25
  var PathsResolver = class {
25
26
  /**
@@ -34,7 +35,7 @@ var PathsResolver = class {
34
35
  /**
35
36
  * The resolver function used to resolve import specifiers
36
37
  */
37
- #resolver = (specifier, parentPath) => import.meta.resolve(specifier, parentPath);
38
+ #resolver = (specifier, parentPath) => resolve(specifier, parentPath);
38
39
  constructor(appRoot) {
39
40
  this.#appRoot = pathToFileURL(join(appRoot, "index.js")).href;
40
41
  }
@@ -296,7 +297,7 @@ var RoutesScanner = class {
296
297
  */
297
298
  #processRouteWithoutController(route) {
298
299
  if (!route.name) {
299
- debug_default(`skipping route "%s" as it does not have a name`, route.name);
300
+ debug_default(`skipping route "%s" as it does not have a name`, route.pattern);
300
301
  return;
301
302
  }
302
303
  const scannedRoute = {
@@ -315,7 +316,7 @@ var RoutesScanner = class {
315
316
  * Scans a route that is using a controller reference
316
317
  */
317
318
  async #processRouteWithController(route, vfs) {
318
- if (!route.handler.importExpression) {
319
+ if (!route.handler || !route.handler.importExpression) {
319
320
  return this.#processRouteWithoutController(route);
320
321
  }
321
322
  const controller = await this.#inspectControllerSpecifier(
@@ -3,7 +3,7 @@ import {
3
3
  debug_default,
4
4
  removeExtension,
5
5
  throttle
6
- } from "./chunk-3GYRM5Y2.js";
6
+ } from "./chunk-HRE5L24F.js";
7
7
 
8
8
  // src/index_generator/source.ts
9
9
  import string from "@poppinss/utils/string";
package/build/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  FileBuffer,
3
3
  IndexGenerator
4
- } from "./chunk-KAOPWBR3.js";
4
+ } from "./chunk-YFDLKKOA.js";
5
5
  import {
6
6
  RoutesScanner
7
- } from "./chunk-CX6VPELJ.js";
7
+ } from "./chunk-RSWZKA6F.js";
8
8
  import "./chunk-TIKQQRMX.js";
9
9
  import {
10
10
  VirtualFileSystem,
@@ -14,11 +14,12 @@ import {
14
14
  loadHooks,
15
15
  memoize,
16
16
  parseConfig,
17
+ readTsConfig,
17
18
  run,
18
19
  runNode,
19
20
  throttle,
20
21
  watch
21
- } from "./chunk-3GYRM5Y2.js";
22
+ } from "./chunk-HRE5L24F.js";
22
23
 
23
24
  // src/bundler.ts
24
25
  import dedent from "dedent";
@@ -393,16 +394,16 @@ var FileSystem = class {
393
394
  constructor(cwd, tsConfig, rcFile) {
394
395
  this.#cwd = cwd;
395
396
  this.#tsConfig = tsConfig;
396
- const files = tsConfig.fileNames;
397
+ const files = tsConfig.config.files ?? [];
397
398
  const metaFiles = rcFile.metaFiles ?? [];
398
399
  const testSuites = rcFile.suites ?? [];
399
- const outDir = tsConfig.raw.compilerOptions?.outDir;
400
+ const outDir = tsConfig.config.compilerOptions?.outDir;
400
401
  for (const file of files) {
401
402
  this.#scannedTypeScriptFiles.add(string2.toUnixSlash(file));
402
403
  }
403
- this.#includes = tsConfig.raw.include || DEFAULT_INCLUDES;
404
+ this.#includes = tsConfig.config.include || DEFAULT_INCLUDES;
404
405
  this.#excludes = ALWAYS_EXCLUDE.concat(
405
- tsConfig.raw.exclude || (outDir ? DEFAULT_EXCLUDES.concat(outDir) : DEFAULT_EXCLUDES)
406
+ tsConfig.config.exclude || (outDir ? DEFAULT_EXCLUDES.concat(outDir) : DEFAULT_EXCLUDES)
406
407
  );
407
408
  const metaFilesWithReloads = [];
408
409
  const metaFilesWithoutReloads = [];
@@ -444,10 +445,10 @@ var FileSystem = class {
444
445
  if ((relativePath.endsWith(".ts") || relativePath.endsWith(".tsx")) && !relativePath.endsWith(".d.ts")) {
445
446
  return true;
446
447
  }
447
- if (this.#tsConfig.options.allowJs && relativePath.endsWith(".js")) {
448
+ if (this.#tsConfig.config.compilerOptions?.allowJs && relativePath.endsWith(".js")) {
448
449
  return true;
449
450
  }
450
- if (this.#tsConfig.options.resolveJsonModule && relativePath.endsWith(".json")) {
451
+ if (this.#tsConfig.config.compilerOptions?.resolveJsonModule && relativePath.endsWith(".json")) {
451
452
  return true;
452
453
  }
453
454
  return false;
@@ -930,9 +931,14 @@ var DevServer = class _DevServer {
930
931
  if (!this.#routesScanner) {
931
932
  return;
932
933
  }
933
- const invalidated = await this.#routesScanner.invalidate(filePath);
934
- if (invalidated) {
935
- await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
934
+ try {
935
+ const invalidated = await this.#routesScanner.invalidate(filePath);
936
+ if (invalidated) {
937
+ await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
938
+ }
939
+ } catch (error) {
940
+ this.ui.logger.error("Unable to rescan routes because of the following error");
941
+ this.ui.logger.fatal(error);
936
942
  }
937
943
  }
938
944
  /**
@@ -952,27 +958,32 @@ var DevServer = class _DevServer {
952
958
  * })
953
959
  */
954
960
  #processRoutes = throttle(async (routesFileLocation) => {
955
- const scanRoutes = this.#hooks.has("routesScanning") || this.#hooks.has("routesScanned");
956
- const shareRoutes = this.#hooks.has("routesCommitted");
957
- if (!scanRoutes && !shareRoutes) {
961
+ try {
962
+ const scanRoutes = this.#hooks.has("routesScanning") || this.#hooks.has("routesScanned");
963
+ const shareRoutes = this.#hooks.has("routesCommitted");
964
+ if (!scanRoutes && !shareRoutes) {
965
+ unlink(routesFileLocation).catch(() => {
966
+ });
967
+ return;
968
+ }
969
+ const routesJSON = await readFile(routesFileLocation, "utf-8");
970
+ const routesList = JSON.parse(routesJSON);
958
971
  unlink(routesFileLocation).catch(() => {
959
972
  });
960
- return;
961
- }
962
- const routesJSON = await readFile(routesFileLocation, "utf-8");
963
- const routesList = JSON.parse(routesJSON);
964
- unlink(routesFileLocation).catch(() => {
965
- });
966
- if (shareRoutes) {
967
- await this.#hooks.runner("routesCommitted").run(this, routesList);
968
- }
969
- if (scanRoutes) {
970
- this.#routesScanner = new RoutesScanner(this.cwdPath, []);
971
- await this.#hooks.runner("routesScanning").run(this, this.#routesScanner);
972
- for (const domain of Object.keys(routesList)) {
973
- await this.#routesScanner.scan(routesList[domain]);
973
+ if (shareRoutes) {
974
+ await this.#hooks.runner("routesCommitted").run(this, routesList);
974
975
  }
975
- await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
976
+ if (scanRoutes) {
977
+ this.#routesScanner = new RoutesScanner(this.cwdPath, []);
978
+ await this.#hooks.runner("routesScanning").run(this, this.#routesScanner);
979
+ for (const domain of Object.keys(routesList)) {
980
+ await this.#routesScanner.scan(routesList[domain]);
981
+ }
982
+ await this.#hooks.runner("routesScanned").run(this, this.#routesScanner);
983
+ }
984
+ } catch (error) {
985
+ this.ui.logger.error("Unable to process and scan routes because of the following error");
986
+ this.ui.logger.fatal(error);
976
987
  }
977
988
  }, "processRoutes");
978
989
  /**
@@ -1014,8 +1025,8 @@ var DevServer = class _DevServer {
1014
1025
  * console.error('Failed to initialize dev server')
1015
1026
  * }
1016
1027
  */
1017
- async #init(ts, mode) {
1018
- const tsConfig = parseConfig(this.cwd, ts);
1028
+ async #init(mode) {
1029
+ const tsConfig = readTsConfig(this.cwdPath);
1019
1030
  if (!tsConfig) {
1020
1031
  this.#onError?.(new RuntimeException("Unable to parse tsconfig file"));
1021
1032
  return false;
@@ -1182,8 +1193,8 @@ var DevServer = class _DevServer {
1182
1193
  * const devServer = new DevServer(cwd, { hmr: true, hooks: [] })
1183
1194
  * await devServer.start(ts)
1184
1195
  */
1185
- async start(ts) {
1186
- const initiated = await this.#init(ts, this.options.hmr ? "hmr" : "static");
1196
+ async start() {
1197
+ const initiated = await this.#init(this.options.hmr ? "hmr" : "static");
1187
1198
  if (!initiated) {
1188
1199
  return;
1189
1200
  }
@@ -1214,8 +1225,8 @@ var DevServer = class _DevServer {
1214
1225
  * const devServer = new DevServer(cwd, { hooks: [] })
1215
1226
  * await devServer.startAndWatch(ts, { poll: false })
1216
1227
  */
1217
- async startAndWatch(ts, options) {
1218
- const initiated = await this.#init(ts, "watch");
1228
+ async startAndWatch(options) {
1229
+ const initiated = await this.#init("watch");
1219
1230
  if (!initiated) {
1220
1231
  return;
1221
1232
  }
@@ -1579,8 +1590,8 @@ var TestRunner = class {
1579
1590
  * @param ts - TypeScript module reference for parsing configuration
1580
1591
  * @param options - Watch options including polling mode for file system monitoring
1581
1592
  */
1582
- async runAndWatch(ts, options) {
1583
- const tsConfig = parseConfig(this.cwd, ts);
1593
+ async runAndWatch(options) {
1594
+ const tsConfig = readTsConfig(this.cwdPath);
1584
1595
  if (!tsConfig) {
1585
1596
  this.#onError?.(new RuntimeException2("Unable to parse tsconfig file"));
1586
1597
  return;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  RoutesScanner
3
- } from "../../../chunk-CX6VPELJ.js";
3
+ } from "../../../chunk-RSWZKA6F.js";
4
4
  import "../../../chunk-TIKQQRMX.js";
5
- import "../../../chunk-3GYRM5Y2.js";
5
+ import "../../../chunk-HRE5L24F.js";
6
6
  export {
7
7
  RoutesScanner
8
8
  };
@@ -1,4 +1,3 @@
1
- import type tsStatic from 'typescript';
2
1
  import type { DevServerOptions } from './types/common.ts';
3
2
  /**
4
3
  * Exposes the API to start the development server in HMR, watch or static mode
@@ -128,7 +127,7 @@ export declare class DevServer {
128
127
  * const devServer = new DevServer(cwd, { hmr: true, hooks: [] })
129
128
  * await devServer.start(ts)
130
129
  */
131
- start(ts: typeof tsStatic): Promise<void>;
130
+ start(): Promise<void>;
132
131
  /**
133
132
  * Starts the development server in watch mode and restarts on file changes
134
133
  *
@@ -144,7 +143,7 @@ export declare class DevServer {
144
143
  * const devServer = new DevServer(cwd, { hooks: [] })
145
144
  * await devServer.startAndWatch(ts, { poll: false })
146
145
  */
147
- startAndWatch(ts: typeof tsStatic, options?: {
146
+ startAndWatch(options?: {
148
147
  poll: boolean;
149
148
  }): Promise<void>;
150
149
  }
@@ -1,4 +1,4 @@
1
- import type tsStatic from 'typescript';
1
+ import { type TsConfigResult } from 'get-tsconfig';
2
2
  import { type InspectedFile, type AssemblerRcFile } from './types/common.ts';
3
3
  /**
4
4
  * Exposes an intutive API to run actions when different kind of files
@@ -83,7 +83,7 @@ export declare class FileSystem {
83
83
  * @param tsConfig - Parsed TypeScript configuration
84
84
  * @param rcFile - AdonisJS RC file configuration
85
85
  */
86
- constructor(cwd: string, tsConfig: tsStatic.ParsedCommandLine, rcFile: AssemblerRcFile);
86
+ constructor(cwd: string, tsConfig: TsConfigResult, rcFile: AssemblerRcFile);
87
87
  /**
88
88
  * Returns true if the file should be watched. Chokidar sends
89
89
  * absolute unix paths to the ignored callback.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  IndexGenerator
3
- } from "../../chunk-KAOPWBR3.js";
4
- import "../../chunk-3GYRM5Y2.js";
3
+ } from "../../chunk-YFDLKKOA.js";
4
+ import "../../chunk-HRE5L24F.js";
5
5
  export {
6
6
  IndexGenerator
7
7
  };
@@ -1,4 +1,3 @@
1
- import type tsStatic from 'typescript';
2
1
  import type { TestRunnerOptions } from './types/common.ts';
3
2
  /**
4
3
  * Exposes the API to run Japa tests and optionally watch for file
@@ -111,7 +110,7 @@ export declare class TestRunner {
111
110
  * @param ts - TypeScript module reference for parsing configuration
112
111
  * @param options - Watch options including polling mode for file system monitoring
113
112
  */
114
- runAndWatch(ts: typeof tsStatic, options?: {
113
+ runAndWatch(options?: {
115
114
  poll: boolean;
116
115
  }): Promise<void>;
117
116
  }
@@ -174,7 +174,7 @@ export type RoutesListItem = {
174
174
  domain: string;
175
175
  /** HTTP methods accepted by this route */
176
176
  methods: string[];
177
- handler: Function | {
177
+ handler?: {
178
178
  method: string;
179
179
  importExpression: string | null;
180
180
  };
@@ -1,6 +1,7 @@
1
1
  import Hooks from '@poppinss/hooks';
2
2
  import type tsStatic from 'typescript';
3
3
  import { type ChokidarOptions } from 'chokidar';
4
+ import { type TsConfigResult } from 'get-tsconfig';
4
5
  import type { RunScriptOptions } from './types/common.ts';
5
6
  import { type AllHooks, type HookParams } from './types/hooks.ts';
6
7
  /**
@@ -10,11 +11,14 @@ import { type AllHooks, type HookParams } from './types/hooks.ts';
10
11
  * handling diagnostic errors and returning a parsed configuration that can be
11
12
  * used by other TypeScript operations.
12
13
  *
14
+ * @deprecated While we are experimenting with the readTsConfig method
15
+ *
13
16
  * @param cwd - The current working directory URL or string path
14
17
  * @param ts - TypeScript module reference
15
18
  * @returns Parsed TypeScript configuration or undefined if parsing failed
16
19
  */
17
20
  export declare function parseConfig(cwd: URL | string, ts: typeof tsStatic): tsStatic.ParsedCommandLine | undefined;
21
+ export declare function readTsConfig(cwd: string): TsConfigResult | null;
18
22
  /**
19
23
  * Runs a Node.js script as a child process and inherits the stdio streams
20
24
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
3
  "description": "Provides utilities to run AdonisJS development server and build project for production",
4
- "version": "8.0.0-next.15",
4
+ "version": "8.0.0-next.17",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -34,7 +34,7 @@
34
34
  "release": "release-it",
35
35
  "version": "npm run build",
36
36
  "prepublishOnly": "npm run build",
37
- "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --import=@poppinss/ts-exec --experimental-import-meta-resolve bin/test.ts"
37
+ "quick:test": "cross-env NODE_DEBUG=adonisjs:assembler node --enable-source-maps --import=@poppinss/ts-exec bin/test.ts"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@adonisjs/eslint-config": "^3.0.0-next.0",
@@ -74,6 +74,8 @@
74
74
  "fast-glob": "^3.3.3",
75
75
  "fdir": "^6.5.0",
76
76
  "get-port": "^7.1.0",
77
+ "get-tsconfig": "^4.13.0",
78
+ "import-meta-resolve": "^4.2.0",
77
79
  "junk": "^4.0.1",
78
80
  "open": "^10.2.0",
79
81
  "parse-imports": "^3.0.0",