prepare-types
Write the type-check configuration and the auto-import declarations of frontend modules to a directory that stays, for a module's tsconfig.json to extend.
ajs dms prepare-types writes what a type-aware linter, such as oxlint with tsgolint, needs to resolve a frontend module: a tsconfig.json that knows the #layer/* aliases and the declarations of the auto-imports. It writes them to a directory you name, which stays after the run, and every path in it points at the sources of the modules, not at a copy. A module's own tsconfig.json extends it. The command needs no backend and builds no bundle.
$ ajs dms prepare-types --help
Usage: ajs dms prepare-types [options]
Write a tsconfig.json and the auto-import declarations of DMS frontend modules
to a directory that stays, with every path pointing at the module sources, for a
module's tsconfig.json to extend. Starts no backend and builds no bundle.
Options:
--out <dir> Directory to write; one this command wrote is
replaced once the run succeeds, any other must be
empty or new
-l, --layer <path> Root of an unpublished DMS core layer instead of
the installed one
-m, --module <path> Root of a frontend module (repeatable); without
-l or -m, the current directory or ./frontend-vue
--local-package <name=path> Bind a local package into the generated workspace
(repeatable)
-h, --help Show help for a command
A run
The modules are chosen as verify-source chooses them: the core layer of the installed @antelopejs/dms, plus the current directory or ./frontend-vue, or the modules named with -l, -m and --local-package.
$ ajs dms prepare-types --out .dms-types
ajs dms prepare-types 2 modules
✔ Materialized 2 modules
✔ Installed 442 packages 3.3s
✔ Generated the type declarations
✔ Pointed the types at the sources
✔ Declared the .vue files 9.6s
Wrote the types of 2 modules → .dms-types · 4.8s
Next steps
{ "extends": "./.dms-types/tsconfig.json" } in ./tsconfig.json
The run writes a sibling of --out, <out>.next, and renames it into the place of --out once it succeeds, so a type check or a linter running beside it reads the previous output or the new one, never a half-written one. The previous output is first renamed to <out>.previous, so --out is missing for the instant between the two renames. When --out is a symlink, the directory it links to is replaced and the link stays: <out>.next first moves beside that directory, copied when it sits on another filesystem. A run that fails leaves --out as it was, and <out>.next, or its copy beside the linked directory, until the next run. The run materializes the modules into that sibling, installs their dependencies without running scripts, and generates the type declarations. It then rewrites the output so that nothing refers to the copies of the modules, and removes the copied sources, keeping the dependencies each module installed. Last, it runs vue-tsc to emit a declaration for each .vue file of the sources, so that a .ts file can import the named types of a component. The run fails with exit code 1 when any .vue file of the sources, outside the exclude globs, is left without a declaration, and lists each of those files above the vue-tsc diagnostics.
What it writes
| File | Content |
|---|---|
tsconfig.json | The compiler options of the generated workspace, with paths written out. Each #layer/* alias and each @frontend/<module>/* entry points at the source tree of its module, then at its place under vue-declarations/. Each package in the dependencies of the workspace or of a module, other than a module, has paths entries aimed at where the run installed it, so the sources and the generated declarations share one copy of it: those of the workspace under node_modules, and the other dependencies of a module under frontend-modules/<module>/node_modules. See Dependencies. rootDirs lists the directory vue-declarations/ mirrors and vue-declarations/ itself, which resolves a relative import of a .vue file. The include and exclude globs cover the sources. types is empty, and files lists types.d.ts only. |
types.d.ts | The entry declaration: a /// <reference> to globals.d.ts, auto-imports.d.ts, the generated module and app-config tables, the Vite client types and vue-shims.d.ts. |
vue-declarations/ | One <component>.vue.d.ts per .vue file of the sources, each at the path of its component from the deepest directory that holds every module source, every component a declaration was written for and every file they reach by relative imports and references, as vue-tsc --explainFiles lists them, so with one module at /home/me/shop, vue-declarations/app/Cart.vue.d.ts declares /home/me/shop/app/Cart.vue. A component whose declaration vue-tsc cannot write, because its props or emits name a type the declaration cannot reach, fails the run. vue-tsc writes nothing outside --out: the declaration of a .ts file a component imports from another drive is refused, not written beside that file. |
vue-global-types.d.ts | The global types the .vue declarations reference. |
auto-imports.d.ts | The auto-import declarations, with every import of a module aimed at its sources. |
vue-shims.d.ts | A declaration of the *.vue modules, for linters that cannot read single-file components, and the fallback of a component with no declaration in vue-declarations/. Where vue-tsc can resolve the file, it uses the file. |
dms-types.json | Marks the directory as one this command wrote. |
node_modules | The dependencies of the workspace, which the type declarations resolve against. |
frontend-modules/<module>/node_modules | The other dependencies of each module. The copy of the module's sources beside it is removed. |
All paths are POSIX and relative to --out, and no file outside node_modules holds an absolute path unless a module source or a --local-package lies on another drive. A project moved or checked out elsewhere together with its module sources and the files they import type-checks without a new run.
Add the extends of the summary to the tsconfig.json of each module. Its own include and compilerOptions then apply over the generated ones. The summary names no module whose source lies under node_modules, such as an installed core layer, since that tsconfig.json is not yours to edit.
The sources of every module are named by their real path, with symlinks resolved, because TypeScript reports a file it reaches through a symlink, such as a package pnpm installed, under its real path.
Dependencies
paths entries bypass the exports of a package, so each dependency gets one entry per subpath of its exports, <name> for . and <name>/<subpath> for the others, aimed at the file the types, import and default conditions pick, in that order. A JavaScript target is preceded by its declaration file (.d.ts, .d.mts or .d.cts), and that of . also by the package's top-level types: a config that sets allowJs would otherwise read the JavaScript file. A subpath or target with more than one * is left out. <name> and <name>/* point at the package directory when exports maps neither.
A package that no dependencies field names has no paths entry. TypeScript looks it up as usual, from the file that imports it and up through the directories above. This applies to a package a source imports without declaring it, such as @vue/runtime-core, and to an optional peer of a dependency that the run does not install, such as vue-router for @nuxt/ui. Such a lookup can reach a copy outside --out, such as one in the node_modules of the project.
A config outside the module
A config outside the module, such as that of a test directory which imports the composables of a module, extends the output after its own base config and lists types.d.ts among its files. A config that sets files or include replaces those of the output, and types.d.ts brings back every declaration they listed. Set the types the tests need: the output's is empty. When the base config sets a rootDir, set one that holds the tests and the module sources they import.
{
"extends": ["../tsconfig.json", "../.dms-types/tsconfig.json"],
"compilerOptions": { "noEmit": true, "rootDir": "..", "types": ["node"] },
"include": ["./**/*.ts"],
"files": ["../.dms-types/types.d.ts"]
}
Every dependency of the modules then resolves from the output, so the tests type-check without installing the dependencies of the DMS frontend runtime.
The output directory
Run the command again to refresh the types after the modules change. A directory it wrote is replaced, and each run installs the dependencies again from the store. --out refuses:
- a directory that is not empty and holds no
dms-types.json, so the command never empties a directory it did not write; - a path with a
node_modulessegment, which the auto-importers skip; - a path on another drive than the project.
Each is a usage error with exit code 2, reported before anything is written. A directory that is or holds the source of a module or a --local-package, with symlinks resolved on both sides, stops the run with exit code 1 before it writes, since replacing it would delete the source. A <out>.next or <out>.previous that is not empty and holds no dms-types.json stops the run with exit code 1, so the command never removes a directory it did not write. A directory inside the source of a module is allowed, and the generated tsconfig.json excludes it from that source.
Add the directory, <out>.next and <out>.previous to .gitignore: they are generated.