@adonisjs/assembler 8.0.0-next.8 → 8.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.
Files changed (34) hide show
  1. package/README.md +260 -0
  2. package/build/codemod_exception-CzQgXAAf.js +137 -0
  3. package/build/index.d.ts +3 -1
  4. package/build/index.js +927 -1720
  5. package/build/source-dVeugJ0e.js +166 -0
  6. package/build/src/bundler.d.ts +2 -0
  7. package/build/src/code_scanners/routes_scanner/main.d.ts +16 -2
  8. package/build/src/code_scanners/routes_scanner/main.js +168 -441
  9. package/build/src/code_transformer/main.d.ts +14 -1
  10. package/build/src/code_transformer/main.js +502 -622
  11. package/build/src/code_transformer/rc_file_transformer.d.ts +28 -2
  12. package/build/src/debug.d.ts +1 -1
  13. package/build/src/dev_server.d.ts +60 -12
  14. package/build/src/exceptions/codemod_exception.d.ts +178 -0
  15. package/build/src/file_buffer.d.ts +22 -2
  16. package/build/src/file_system.d.ts +2 -2
  17. package/build/src/helpers.js +72 -16
  18. package/build/src/index_generator/main.js +28 -6
  19. package/build/src/paths_resolver.d.ts +2 -1
  20. package/build/src/test_runner.d.ts +3 -2
  21. package/build/src/types/code_scanners.d.ts +29 -13
  22. package/build/src/types/code_transformer.d.ts +127 -0
  23. package/build/src/types/common.d.ts +98 -2
  24. package/build/src/types/hooks.d.ts +4 -1
  25. package/build/src/types/main.js +1 -0
  26. package/build/src/utils.d.ts +9 -3
  27. package/build/src/virtual_file_system.d.ts +1 -1
  28. package/build/validator_extractor-Ccio_Ndi.js +82 -0
  29. package/build/virtual_file_system-bGeoWsK-.js +285 -0
  30. package/package.json +41 -39
  31. package/build/chunk-N6H4XTTC.js +0 -405
  32. package/build/chunk-PORDZS62.js +0 -391
  33. package/build/chunk-TIKQQRMX.js +0 -116
  34. package/build/src/hooks.d.ts +0 -224
@@ -0,0 +1,285 @@
1
+ import { copyFile, mkdir, readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import string from "@poppinss/utils/string";
4
+ import { relative } from "node:path/posix";
5
+ import Cache from "tmp-cache";
6
+ import { isJunk } from "junk";
7
+ import fastGlob from "fast-glob";
8
+ import Hooks from "@poppinss/hooks";
9
+ import { existsSync } from "node:fs";
10
+ import getRandomPort from "get-port";
11
+ import { execa, execaNode } from "execa";
12
+ import { importDefault, naturalSort } from "@poppinss/utils";
13
+ import { EnvLoader, EnvParser } from "@adonisjs/env";
14
+ import chokidar from "chokidar";
15
+ import { parseTsconfig } from "get-tsconfig";
16
+ import { basename, dirname as dirname$1, isAbsolute, join as join$1, relative as relative$1 } from "node:path";
17
+ import { debuglog } from "node:util";
18
+ import { fdir } from "fdir";
19
+ import lodash from "@poppinss/utils/lodash";
20
+ import { Lang, parse } from "@ast-grep/napi";
21
+ import picomatch from "picomatch";
22
+ var debug_default = debuglog("adonisjs:assembler");
23
+ const DEFAULT_NODE_ARGS = ["--import=@poppinss/ts-exec", "--enable-source-maps"];
24
+ function parseConfig(cwd, ts) {
25
+ const cwdPath = typeof cwd === "string" ? cwd : fileURLToPath(cwd);
26
+ const configFile = join$1(cwdPath, "tsconfig.json");
27
+ debug_default("parsing config file \"%s\"", configFile);
28
+ let hardException = null;
29
+ const parsedConfig = ts.getParsedCommandLineOfConfigFile(configFile, {}, {
30
+ ...ts.sys,
31
+ useCaseSensitiveFileNames: true,
32
+ getCurrentDirectory: () => cwdPath,
33
+ onUnRecoverableConfigFileDiagnostic: (error) => hardException = error
34
+ });
35
+ if (hardException) {
36
+ const compilerHost = ts.createCompilerHost({});
37
+ console.log(ts.formatDiagnosticsWithColorAndContext([hardException], compilerHost));
38
+ return;
39
+ }
40
+ if (parsedConfig.errors.length) {
41
+ const compilerHost = ts.createCompilerHost({});
42
+ console.log(ts.formatDiagnosticsWithColorAndContext(parsedConfig.errors, compilerHost));
43
+ return;
44
+ }
45
+ if (parsedConfig.raw.include) parsedConfig.raw.include = parsedConfig.raw.include.map((includePath) => {
46
+ return includePath.replace("${configDir}/", "");
47
+ });
48
+ if (parsedConfig.raw.exclude) parsedConfig.raw.exclude = parsedConfig.raw.exclude.map((excludePath) => {
49
+ return excludePath.replace("${configDir}/", "");
50
+ });
51
+ return parsedConfig;
52
+ }
53
+ function readTsConfig(cwd) {
54
+ const tsConfigPath = join$1(cwd, "tsconfig.json");
55
+ debug_default("reading config file from location \"%s\"", tsConfigPath);
56
+ try {
57
+ const tsConfig = parseTsconfig(tsConfigPath);
58
+ if (tsConfig.include) tsConfig.include = tsConfig.include.map((resolvedPath) => {
59
+ return resolvedPath.replace(cwd, "");
60
+ });
61
+ if (tsConfig.exclude) tsConfig.exclude = tsConfig.exclude.map((resolvedPath) => {
62
+ return resolvedPath.replace(cwd, "");
63
+ });
64
+ debug_default("read tsconfig %O", tsConfig);
65
+ return {
66
+ path: tsConfigPath,
67
+ config: tsConfig
68
+ };
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+ function runNode(cwd, options) {
74
+ return execaNode(options.script, options.scriptArgs, {
75
+ nodeOptions: DEFAULT_NODE_ARGS.concat(options.nodeArgs),
76
+ preferLocal: true,
77
+ windowsHide: false,
78
+ localDir: cwd,
79
+ cwd,
80
+ reject: options.reject ?? false,
81
+ buffer: false,
82
+ stdio: options.stdio || "inherit",
83
+ env: {
84
+ ...options.stdio === "pipe" ? { FORCE_COLOR: "true" } : {},
85
+ ...options.env
86
+ }
87
+ });
88
+ }
89
+ function run(cwd, options) {
90
+ return execa(options.script, options.scriptArgs, {
91
+ preferLocal: true,
92
+ windowsHide: false,
93
+ localDir: cwd,
94
+ cwd,
95
+ buffer: false,
96
+ stdio: options.stdio || "inherit",
97
+ env: {
98
+ ...options.stdio === "pipe" ? { FORCE_COLOR: "true" } : {},
99
+ ...options.env
100
+ }
101
+ });
102
+ }
103
+ function watch(options) {
104
+ return chokidar.watch(["."], options);
105
+ }
106
+ async function getPort(cwd) {
107
+ if (process.env.PORT) return getRandomPort({ port: Number(process.env.PORT) });
108
+ const files = await new EnvLoader(cwd).load();
109
+ for (let file of files) {
110
+ const envVariables = await new EnvParser(file.contents, cwd).parse();
111
+ if (envVariables.PORT) return getRandomPort({ port: Number(envVariables.PORT) });
112
+ }
113
+ return getRandomPort({ port: 3333 });
114
+ }
115
+ async function copyFiles(files, cwd, outDir) {
116
+ const { paths, patterns } = files.reduce((result, file) => {
117
+ if (fastGlob.isDynamicPattern(file)) {
118
+ result.patterns.push(file);
119
+ return result;
120
+ }
121
+ if (existsSync(join$1(cwd, file))) result.paths.push(file);
122
+ return result;
123
+ }, {
124
+ patterns: [],
125
+ paths: []
126
+ });
127
+ debug_default("copyFiles inputs: %O, paths: %O, patterns: %O", files, paths, patterns);
128
+ const filePaths = paths.concat(await fastGlob(patterns, {
129
+ cwd,
130
+ dot: true
131
+ })).filter((file) => {
132
+ return !isJunk(basename(file));
133
+ });
134
+ debug_default("copying files %O to destination \"%s\"", filePaths, outDir);
135
+ const copyPromises = filePaths.map(async (file) => {
136
+ const src = isAbsolute(file) ? file : join$1(cwd, file);
137
+ const dest = join$1(outDir, relative$1(cwd, src));
138
+ await mkdir(dirname$1(dest), { recursive: true });
139
+ return copyFile(src, dest);
140
+ });
141
+ return await Promise.all(copyPromises);
142
+ }
143
+ function memoize(fn, maxKeys) {
144
+ const cache = new Cache({ max: maxKeys });
145
+ return (input, ...args) => {
146
+ if (cache.has(input)) return cache.get(input);
147
+ return fn(input, ...args);
148
+ };
149
+ }
150
+ function isRelative(pathValue) {
151
+ return pathValue.startsWith("./") || pathValue.startsWith("../");
152
+ }
153
+ async function loadHooks(rcFileHooks, names) {
154
+ const groups = names.map((name) => {
155
+ return {
156
+ group: name,
157
+ hooks: rcFileHooks?.[name] ?? []
158
+ };
159
+ });
160
+ const hooks = new Hooks();
161
+ for (const { group, hooks: collection } of groups) for (const item of collection) if ("run" in item) hooks.add(group, item.run);
162
+ else hooks.add(group, await importDefault(item));
163
+ return hooks;
164
+ }
165
+ function throttle(fn, name) {
166
+ name = name || "throttled";
167
+ let isBusy = false;
168
+ let hasQueuedCalls = false;
169
+ let lastCallArgs;
170
+ async function throttled(...args) {
171
+ if (isBusy) {
172
+ debug_default("ignoring \"%s\" invocation as current execution is in progress", name);
173
+ hasQueuedCalls = true;
174
+ lastCallArgs = args;
175
+ return;
176
+ }
177
+ isBusy = true;
178
+ debug_default("executing throttled function \"%s\"", name);
179
+ await fn(...args);
180
+ debug_default("executed throttled function \"%s\"", name);
181
+ isBusy = false;
182
+ if (hasQueuedCalls) {
183
+ hasQueuedCalls = false;
184
+ debug_default("resuming and running latest \"%s\" invocation", name);
185
+ await throttled(...lastCallArgs);
186
+ }
187
+ }
188
+ return throttled;
189
+ }
190
+ function removeExtension(filePath) {
191
+ return filePath.substring(0, filePath.lastIndexOf("."));
192
+ }
193
+ const BYPASS_FN = (input) => input;
194
+ const DEFAULT_GLOB = [
195
+ "**/!(*.d).ts",
196
+ "**/*.tsx",
197
+ "**/*.js"
198
+ ];
199
+ var VirtualFileSystem = class {
200
+ #source;
201
+ #options;
202
+ #files = /* @__PURE__ */ new Map();
203
+ #astCache = new Cache({ max: 60 });
204
+ #matcher;
205
+ #picoMatchOptions;
206
+ constructor(source, options) {
207
+ this.#source = source;
208
+ this.#options = options ?? {};
209
+ this.#picoMatchOptions = { cwd: this.#source };
210
+ this.#matcher = picomatch(this.#options.glob ?? DEFAULT_GLOB, this.#picoMatchOptions);
211
+ }
212
+ async scan() {
213
+ debug_default("fetching entities from source \"%s\"", this.#source);
214
+ const crawler = new fdir().globWithOptions(this.#options.glob ?? DEFAULT_GLOB, this.#picoMatchOptions).withFullPaths();
215
+ if (this.#options.filter) crawler.filter(this.#options.filter);
216
+ const filesList = await crawler.crawl(this.#source).withPromise();
217
+ debug_default("scanned files %O", filesList);
218
+ const sortedFiles = filesList.sort(naturalSort);
219
+ this.#files.clear();
220
+ for (let filePath of sortedFiles) {
221
+ filePath = string.toUnixSlash(filePath);
222
+ const relativePath = removeExtension(relative(this.#source, filePath));
223
+ this.#files.set(filePath, relativePath);
224
+ }
225
+ }
226
+ has(filePath) {
227
+ if (this.#files.has(filePath)) return true;
228
+ if (!filePath.startsWith(this.#source)) return false;
229
+ return this.#matcher(filePath);
230
+ }
231
+ asList(options) {
232
+ const list = {};
233
+ const transformKey = options?.transformKey ?? BYPASS_FN;
234
+ const transformValue = options?.transformValue ?? BYPASS_FN;
235
+ for (const [filePath, relativePath] of this.#files) list[transformKey(relativePath)] = transformValue(filePath);
236
+ return list;
237
+ }
238
+ asTree(options) {
239
+ const list = {};
240
+ const transformKey = options?.transformKey ?? BYPASS_FN;
241
+ const transformValue = options?.transformValue ?? BYPASS_FN;
242
+ for (const [filePath, relativePath] of this.#files) {
243
+ const key = transformKey(relativePath);
244
+ lodash.set(list, key.split("/"), transformValue(filePath, key));
245
+ }
246
+ return list;
247
+ }
248
+ add(filePath) {
249
+ if (this.has(filePath)) {
250
+ debug_default("adding new \"%s\" file to the virtual file system", filePath);
251
+ const relativePath = removeExtension(relative(this.#source, filePath));
252
+ this.#files.set(filePath, relativePath);
253
+ return true;
254
+ }
255
+ return false;
256
+ }
257
+ remove(filePath) {
258
+ debug_default("removing \"%s\" file from virtual file system", filePath);
259
+ return this.#files.delete(filePath);
260
+ }
261
+ async get(filePath) {
262
+ const cached = this.#astCache.get(filePath);
263
+ if (cached) {
264
+ debug_default("returning AST nodes from cache \"%s\"", filePath);
265
+ return cached;
266
+ }
267
+ const fileContents = await readFile(filePath, "utf-8");
268
+ debug_default("parsing \"%s\" file to AST", filePath);
269
+ this.#astCache.set(filePath, parse(Lang.TypeScript, fileContents).root());
270
+ return this.#astCache.get(filePath);
271
+ }
272
+ invalidate(filePath) {
273
+ if (filePath) {
274
+ debug_default("invalidate AST cache \"%s\"", filePath);
275
+ this.#astCache.delete(filePath);
276
+ } else {
277
+ debug_default("clear AST cache");
278
+ this.#astCache.clear();
279
+ }
280
+ }
281
+ clear() {
282
+ this.#files.clear();
283
+ }
284
+ };
285
+ export { loadHooks as a, readTsConfig as c, runNode as d, throttle as f, isRelative as i, removeExtension as l, debug_default as m, copyFiles as n, memoize as o, watch as p, getPort as r, parseConfig as s, VirtualFileSystem as t, run as u };
package/package.json CHANGED
@@ -1,13 +1,10 @@
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.8",
4
+ "version": "8.0.0",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
8
- "imports": {
9
- "#tests/*": "./tests/*.ts"
10
- },
11
8
  "main": "build/index.js",
12
9
  "type": "module",
13
10
  "files": [
@@ -25,65 +22,67 @@
25
22
  },
26
23
  "scripts": {
27
24
  "pretest": "npm run lint",
28
- "test": "c8 npm run quick:test",
25
+ "test": "npm run quick:test",
29
26
  "lint": "eslint .",
30
27
  "format": "prettier --write .",
31
28
  "clean": "del-cli build",
32
29
  "typecheck": "tsc --noEmit",
33
30
  "precompile": "npm run lint && npm run clean",
34
- "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
31
+ "compile": "tsdown && tsc --emitDeclarationOnly --declaration",
35
32
  "build": "npm run compile",
36
33
  "docs": "typedoc",
37
34
  "release": "release-it",
38
35
  "version": "npm run build",
39
36
  "prepublishOnly": "npm run build",
40
- "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"
41
38
  },
42
39
  "devDependencies": {
43
- "@adonisjs/eslint-config": "^3.0.0-next.0",
40
+ "@adonisjs/eslint-config": "^3.0.0",
44
41
  "@adonisjs/prettier-config": "^1.4.5",
45
- "@adonisjs/tsconfig": "^2.0.0-next.0",
46
- "@japa/assert": "^4.1.1",
47
- "@japa/file-system": "^2.3.2",
48
- "@japa/runner": "^4.4.0",
49
- "@japa/snapshot": "^2.0.9",
50
- "@poppinss/ts-exec": "^1.4.1",
51
- "@release-it/conventional-changelog": "^10.0.1",
52
- "@types/node": "^24.3.1",
42
+ "@adonisjs/tsconfig": "^2.0.0",
43
+ "@japa/assert": "^4.2.0",
44
+ "@japa/file-system": "^3.0.0",
45
+ "@japa/runner": "^5.3.0",
46
+ "@japa/snapshot": "^2.0.10",
47
+ "@poppinss/ts-exec": "^1.4.4",
48
+ "@release-it/conventional-changelog": "^10.0.5",
49
+ "@types/node": "^25.3.0",
53
50
  "@types/picomatch": "^4.0.2",
54
51
  "@types/pretty-hrtime": "^1.0.3",
55
- "c8": "^10.1.3",
56
- "cross-env": "^10.0.0",
57
- "del-cli": "^6.0.0",
58
- "eslint": "^9.35.0",
59
- "hot-hook": "^0.4.1-next.0",
60
- "p-event": "^6.0.1",
61
- "prettier": "^3.6.2",
62
- "release-it": "^19.0.4",
63
- "tsup": "^8.5.0",
64
- "typedoc": "^0.28.12",
65
- "typescript": "^5.9.2"
52
+ "c8": "^11.0.0",
53
+ "cross-env": "^10.1.0",
54
+ "del-cli": "^7.0.0",
55
+ "eslint": "^10.0.2",
56
+ "hot-hook": "^0.4.1-next.2",
57
+ "p-event": "^7.1.0",
58
+ "prettier": "^3.8.1",
59
+ "release-it": "^19.2.4",
60
+ "tsdown": "^0.20.3",
61
+ "typedoc": "^0.28.17",
62
+ "typescript": "^5.9.3"
66
63
  },
67
64
  "dependencies": {
68
- "@adonisjs/env": "^7.0.0-next.1",
65
+ "@adonisjs/env": "^7.0.0",
69
66
  "@antfu/install-pkg": "^1.1.0",
70
- "@ast-grep/napi": "^0.39.4",
71
- "@poppinss/cliui": "^6.4.4",
72
- "@poppinss/hooks": "^7.2.6",
73
- "@poppinss/utils": "^7.0.0-next.3",
74
- "chokidar": "^4.0.3",
75
- "dedent": "^1.7.0",
76
- "execa": "^9.6.0",
67
+ "@ast-grep/napi": "^0.41.0",
68
+ "@poppinss/cliui": "^6.7.0",
69
+ "@poppinss/hooks": "^7.3.0",
70
+ "@poppinss/utils": "^7.0.0",
71
+ "chokidar": "^5.0.0",
72
+ "dedent": "^1.7.1",
73
+ "execa": "^9.6.1",
77
74
  "fast-glob": "^3.3.3",
78
75
  "fdir": "^6.5.0",
79
76
  "get-port": "^7.1.0",
77
+ "get-tsconfig": "^4.13.6",
78
+ "import-meta-resolve": "^4.2.0",
80
79
  "junk": "^4.0.1",
81
- "open": "^10.2.0",
80
+ "open": "^11.0.0",
82
81
  "parse-imports": "^3.0.0",
83
82
  "picomatch": "^4.0.3",
84
83
  "pretty-hrtime": "^1.0.3",
85
84
  "tmp-cache": "^1.1.0",
86
- "ts-morph": "^26.0.0"
85
+ "ts-morph": "^27.0.2"
87
86
  },
88
87
  "peerDependencies": {
89
88
  "typescript": "^4.0.0 || ^5.0.0"
@@ -106,7 +105,7 @@
106
105
  "publishConfig": {
107
106
  "provenance": true
108
107
  },
109
- "tsup": {
108
+ "tsdown": {
110
109
  "entry": [
111
110
  "./index.ts",
112
111
  "./src/types/main.ts",
@@ -118,8 +117,11 @@
118
117
  "outDir": "./build",
119
118
  "clean": true,
120
119
  "format": "esm",
120
+ "minify": "dce-only",
121
+ "fixedExtension": false,
121
122
  "dts": false,
122
- "sourcemap": false,
123
+ "treeshake": false,
124
+ "sourcemaps": false,
123
125
  "target": "esnext"
124
126
  },
125
127
  "release-it": {