Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
974c429
docs: list relative imports of module code that miss its augmentations
danielroe Nov 22, 2026
3455a1d
docs: describe which paths point at sources and when to add tsconfig.…
danielroe Nov 23, 2026
5f80220
docs: make each upgrade step decidable
danielroe Nov 23, 2026
60176a5
docs: cover node10 self-imports, attw --pack, generic exports and nod…
danielroe Nov 23, 2026
d7cb43b
docs: make the upgrade defaults instructions and run the type check a…
danielroe Nov 23, 2026
17bf909
docs: keep the upgrade guide under 5,000 words
danielroe Nov 29, 2026
139a191
docs: describe the module code the app and server parts type check
danielroe Nov 29, 2026
5007012
test: cover module code in the parts that check it
danielroe Nov 29, 2026
167710d
docs: list the node10 problems of a module that supports node10
danielroe Nov 29, 2026
4d1b7a8
docs: run the attw script through a runner
danielroe Nov 29, 2026
e868f5d
docs: correct how TypeScript resolves an exports target
danielroe Nov 29, 2026
9253823
docs: keep the options that an extended tsconfig supplies
danielroe Nov 29, 2026
a23b50d
docs: say that the parts do not get `typeRoots`
danielroe Nov 29, 2026
9b6c88e
docs: keep an attw profile out of the node10 check
danielroe Nov 29, 2026
c7cc758
docs: keep attw ignore rules out of the node10 check
danielroe Nov 29, 2026
75a0016
docs: say that the node10 check needs its own row
danielroe Nov 29, 2026
5ad3acc
docs: drop a types entry along with its declarations
danielroe Nov 29, 2026
03c7d96
docs: say which parts read a declaration file in src
danielroe Nov 29, 2026
4f2103c
docs: keep module augmentations out of the script file
danielroe Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/1.project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Write paths into the runtime directory without an extension, as in the `addPlugi

The runtime directory holds the code that the module adds to the app: components, composables, plugins, server routes, stylesheets, and any other files. The module registers them from `setup()`, with `@nuxt/kit` utilities such as `addPlugin`, `addComponent`, `addImports`, and `addServerHandler`.

Put code for the app in `src/runtime/app/`, and code for the server in `src/runtime/server/`. In an app that installs the module, Nuxt type-checks `runtime/server/` in the server context, and the rest of `runtime/` in the app context. Your module's own `tsconfig.json` type-checks all of `src/runtime/` with one configuration. See [Augment Types](/docs/guide/modules/recipes-advanced#augment-types) in the Module Author Guide.
Put code for the app in `src/runtime/app/`, and code for the server in `src/runtime/server/`. In an app that installs the module, Nuxt type-checks `runtime/server/` in the server context, and the rest of `runtime/` in the app context. Your module's own `tsconfig.json` checks them in the same contexts, as described in [TypeScript](/docs/api/module-builder/typescript#the-modules-tsconfigjson). See [Augment Types](/docs/guide/modules/recipes-advanced#augment-types) in the Module Author Guide.

The build transpiles each file on its own into `dist/runtime/`, and keeps its name and its imports. [Build Output](/docs/api/module-builder/output#runtime-files) describes how each kind of file is emitted.

Expand Down
22 changes: 16 additions & 6 deletions docs/3.develop-and-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The playground has to resolve the module's name to the module directory itself,

The playground's type check includes your sources and the files that they import types from. [The playground's `tsconfig.json`](/docs/api/module-builder/typescript#with-source-exports) lists the errors that this can report.

Keep `typesVersions` at the top level, pointing at `dist`, with pnpm and with Yarn 4. TypeScript only reads it for a package whose `exports` it doesn't read, as under `node10` module resolution, which a playground doesn't use. pnpm also applies `publishConfig.typesVersions`, but Yarn 4 packs `typesVersions` as written.
A module that keeps `typesVersions` for `node10` consumers leaves it at the top level, pointing at `dist`, with pnpm and with Yarn 4. TypeScript only reads it for a package whose `exports` it doesn't read, as under `node10` module resolution, which a playground doesn't use. pnpm also applies `publishConfig.typesVersions`, but Yarn 4 packs `typesVersions` as written.

#### Code that reaches into `dist`

Expand Down Expand Up @@ -245,30 +245,40 @@ To check the package before you publish it, follow these steps:
npx publint ./my-module-1.0.0.tgz
```

3. List the imports in the declarations that don't resolve from the package alone, with [Are the Types Wrong?](https://arethetypeswrong.github.io). Write its report to a file, and read the file with `jq`:
3. List the imports in the declarations that don't resolve from the package alone, with [Are the Types Wrong?](https://arethetypeswrong.github.io), and the number of files that each appears in. Write its report to a file, and read the file with `jq`. The first command exits with 1 whenever the report lists a problem:

```bash [Terminal]
npx @arethetypeswrong/cli ./my-module-1.0.0.tgz --profile esm-only --format json > attw.json
jq -r '.analysis.problems[] | select(.kind == "InternalResolutionError") | "\(.resolutionOption) \(.moduleSpecifier) \(.fileName)"' attw.json | sort -u
jq -r '.analysis.problems[] | select(.kind == "InternalResolutionError" and .resolutionOption != "node10") | "\(.moduleSpecifier) \(.fileName)"' attw.json | sort -u | cut -d' ' -f1 | uniq -c
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
```

Each one has to be an alias that only a Nuxt app provides, such as `#app`, `#imports`, `#build/my-module/options`, or an alias that the module adds to the app, or, under `node10` for a module without `node10` consumers, one of the package's own `imports`. A module that supports `node10` consumers imports those files by relative path in the code that the declarations come from. Fix any other, such as a relative import of a file that the package doesn't contain. An app's `nuxt.config.ts` context reads the module's options type without the app's aliases, and types an alias that doesn't resolve as `any`, so move a type that the options type takes from such a file into one that doesn't import the aliases.
Each one has to be an alias that only a Nuxt app provides, such as `#app`, `#imports`, `#build/my-module/options`, or an alias that the module adds to the app. The command leaves out `node10`, which the `esm-only` profile doesn't check either. Under `node10`, a module without `typesVersions` also can't resolve its own `imports` and subpaths, such as `my-module/utils` in `dist/runtime/types.d.ts`. A module that supports `node10` consumers imports those files by relative path in the code that the declarations come from. To list the `node10` problems of such a module, run the command with `== "node10"` in place of `!= "node10"`: an import of the module's own `imports` entry, such as `#internal`, appears only there. Fix any other, such as a relative import of a file that the package doesn't contain. An app's `nuxt.config.ts` context reads the module's options type without the app's aliases, and types an alias that doesn't resolve as `any`, so move a type that the options type takes from such a file into one that doesn't import the aliases.

4. Run Are the Types Wrong? with those imports ignored:

```bash [Terminal]
npx @arethetypeswrong/cli ./my-module-1.0.0.tgz --profile esm-only --ignore-rules internal-resolution-error
```

The `esm-only` profile leaves out `node10` resolution, and `require` under `node16`, which can't load an ES module. A module that sets `types` and `typesVersions` for `node10` consumers checks `node10` too, with `--ignore-rules cjs-resolves-to-esm internal-resolution-error` and no `--profile`.
The `esm-only` profile leaves out `node10` resolution, and `require` under `node16`, which can't load an ES module. A module that sets `types` and `typesVersions` for `node10` consumers checks `node10` too, with `--ignore-rules cjs-resolves-to-esm internal-resolution-error`, no `--profile`, and no `.attw.json` that sets `profile` or `ignoreRules`: every profile but `strict` marks the `node10` resolutions ignored, and a config's `ignoreRules` are added to the command's, so either one hides a `node10` failure from both the table and the exit code. Read the `node10` row too: with the types and the imports inside an `import` condition, `require` resolves nothing, so the `node16 (from CJS)` row reports `NoResolution`, and the only rule that hides it, `no-resolution`, hides `node10` as well.

For a module that is correct, Are the Types Wrong? reports three kinds of problem, which these steps leave out:

- `CJSResolvesToESM`, under `node16` from CommonJS. The module is an ES module, which `require` can't load.
- `NoResolution`, under `node10`, for each subpath export of a module without `typesVersions`.
- `InternalResolutionError`, for an import in a declaration file that only a Nuxt app resolves. It appears under every resolution for aliases such as `#imports` and `#build/*`, and under `node10` for the package's own `imports`. The `esm-only` profile doesn't leave it out, so step 4 ignores the rule.

`attw --pack .` packs with npm, which fails on a package with `devEngines`, so pack the module with its own package manager first.
`attw --pack .` packs with npm, which fails on a package with `devEngines`, and on source exports with `NUXT_MB_C0104`. Pack the module with its own package manager first, as in this script:

```json [package.json]
{
"scripts": {
"test:attw": "pnpm pack --out node_modules/.cache/attw.tgz && pnpm dlx @arethetypeswrong/cli node_modules/.cache/attw.tgz --profile esm-only --ignore-rules internal-resolution-error"
}
}
```

With `@arethetypeswrong/cli` in `devDependencies`, write `attw` in place of `pnpm dlx @arethetypeswrong/cli`.

tsdown's own `attw` option packs the module with its package manager and checks the tarball after each build. It needs `@arethetypeswrong/core` in the module's `devDependencies`:

Expand Down
Loading
Loading