Skip to content

Typings directory when in-lining project references #454

@lavcraft

Description

@lavcraft

Troubleshooting

My reproducible example - https://github.com/lavcraft/rollup-typescript-project-references-example-problems

You need

  1. clone
  2. npm run ci

Follow to next instructions

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior

Run npm run -w @project/sdk build - tsc variant works fine and generate d.ts files into correct directories

  1. Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate

I guess order is correct:

        nodeResolve(),
        typescript2()
  1. Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction

My example - https://github.com/lavcraft/rollup-typescript-project-references-example-problems
Follow to README or read next lines:

Two commands for feel difference between tsc and rollup in my case:

TSC baseline

  1. npm run -w @project/sdk build - tsc variant
  2. And see d.ts files in dirs
tree packages/sdk/build
packages/sdk/build
├── actions
│   ├── create.d.ts
│   ├── create.d.ts.map
│   └── create.js
├── models
│   ├── user.d.ts
│   ├── user.d.ts.map
│   └── user.js
└── tsconfig.tsbuildinfo

All d.ts files existed in right location (except d.ts from project from project reference, but it is ok for tsc i guess)

Rollup variant

  1. rm -rf packages/sdk/build && npm run -w @project/sdk rollup
  2. And see d.ts files in dirs
tree packages/sdk/build
packages/sdk/build
├── actions
│   ├── create.js
│   └── create.js.map
├── models
│   ├── user.js
│   └── user.js.map
├── sdk      <------------------------ THIS DIR SUSPICIOUS
│   └── src
│       ├── actions
│       │   ├── create.d.ts
│       │   └── create.d.ts.map
│       └── models
│           ├── user.d.ts
│           └── user.d.ts.map
└── shared <------------------------ THIS DIR SUSPICIOUS
    └── src
        └── test
            ├── util.d.ts
            └── util.d.ts.map

Created to excess directories with typings - sdk and shared

Please help me to explain right behaviour or workaround. Because my next step is apply dts plugin for obtain valid d.ts files without internal paths. But some difficulties happened when all this d.ts located in strange directories :)

Environment

Versions

  System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 52.64 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
    pnpm: 8.6.1 - /opt/homebrew/bin/pnpm
  npmPackages:
    typescript: ^5.1.5 => 5.1.5

rollup.config.js

:
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import typescript2 from 'rollup-plugin-typescript2';
import fs from 'fs';
import path from 'path';
import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
/**
 * @type {import('rollup').RollupOptions}
 */
const config = {
    input: {
        ...files('actions'),
        ...files('models'),
    },
    output: {
        sourcemap: true,
        dir: 'build',
        preserveModules: false,
        format: 'esm'
    },
    plugins: [
        nodeResolve(),
        typescript2({
            // build: true,
            // useTsconfigDeclarationDir: true,
            // declarationDir: './types',
        }),
        // commonjs(),
    ],
    external: [
        'undici',
        'querystring',

        'mobx',
        'mobx-react-lite',
        'mobx-utils',
        'react',
    ],
    watch: {
        chokidar: true,
        exclude: ['build/**', '**/*.d.ts', '**/*.js']
    }
};

function files(dir = '.', exclude = ['__tests__']) {
    return fs
        .readdirSync(path.resolve(__dirname, `src/${dir}`))
        .reduce((prev, current) => {
            if (exclude.includes(current)) return prev;
            const targetName = current.replace('.ts', '');
            prev[`${dir}/${targetName}`] = `./src/${dir}/${current}`;
            return prev;
        }, {});
}
export default [config];

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: supportAsking for support with something or a specific use casesolution: workaround availableThere is a workaround available for this issuetopic: monorepo / symlinksRelated to monorepos and/or symlinks (Lerna, Yarn, PNPM, Rush, etc)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions