Skip to content

typescript-transform-paths does not run on .d.ts files after upgrade to Rollup 4 #466

Closed
@SimmeNilsson

Description

@SimmeNilsson

Troubleshooting

  1. Does tsc have the same output? If so, please explain why this is incorrect behavior
    No, tsc alone works as expected as long as ts-patch successfully ran.
    @rollup/plugin-typescript as well, but it has other issues so want rollup-plugin-typescript2 to work.

  2. Does your Rollup plugin order match this plugin's compatibility? If not, please elaborate
    Only got one plugin in example.

  3. Can you create a minimal example that reproduces this behavior? Preferably, use this environment for your reproduction
    https://github.com/SimmeNilsson/rollup_relative_path_repro

What happens and why it is incorrect

I'm using ts-patch to support typescript-transform-paths in order to transform my imports paths into relative paths.
Prior to rollup 4 it was working well for both the generated .js and .d.ts files.
But after upgrading to rollup 4, the imports of the .d.ts files are not updated.

Comparing logs with verbosity 3 this part is missing in rollup 4 compared to rollup 3 after line:

rpt2: generated declarations for 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts

Missing lines:

rpt2: dependency 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts'
rpt2:     imported by 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts'
rpt2: resolving 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts' imported by 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts'
rpt2:     to 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts'
rpt2: transpiling '

Environment

Windows 11, VS Code, node 20.9.0, yarn 1.22.21

Versions

  System:
    OS: Windows 11 10.0.22621
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 5.85 GB / 31.80 GB
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    rollup: ^4.6.0 => 4.6.0
    rollup-plugin-typescript2: ^0.36.0 => 0.36.0
    typescript: ^5.3.2 => 5.3.2

rollup.config.mjs

:
import typescript from "rollup-plugin-typescript2";

export default {
    input: ["src/index.ts"],
    output: {
        format: "es",
        dir: "dist",
        preserveModules: true
    },

    plugins: [typescript()]
};

tsconfig.json

:
{
    "compileOnSave": false,
    "compilerOptions": {
        "alwaysStrict": true,
        "baseUrl": "./",
        "declaration": true,
        "forceConsistentCasingInFileNames": true,
        "module": "ESNext",
        "moduleResolution": "node",
        "outDir": "dist",
        "paths": {
            "@/*": ["src/*"]
        },
        "plugins": [
            // Transform paths in output .js files
            { "transform": "typescript-transform-paths", "exclude": ["**/node_modules/**"] },

            // Transform paths in output .d.ts files (Include this line if you output declarations files)
            { "transform": "typescript-transform-paths", "afterDeclarations": true, "exclude": ["**/node_modules/**"] }
        ],
        "skipLibCheck": true,
        "target": "ESNext"
    },
    "include": ["src/**/*.ts"],
    "exclude": []
}

package.json

:
{
    "name": "rollup_relative_path_repro",
    "version": "1.0.0",
    "main": "index.js",
    "license": "MIT",
    "devDependencies": {
        "@rollup/plugin-typescript": "^11.1.5",
        "rimraf": "^5.0.5",
        "rollup": "^4.6.0",
        "rollup-plugin-typescript2": "^0.36.0",
        "ts-patch": "^3.0.2",
        "tslib": "^2.6.2",
        "typescript": "^5.3.2",
        "typescript-transform-paths": "^3.4.6"
    },
    "scripts": {
        "prepare": "ts-patch install -s",
        "clean": "rimraf dist",
        "prebuild": "yarn clean",
        "build": "rollup --config rollup.config.mjs"
    }
}

plugin output with verbosity 3

:
rpt2: built-in options overrides: {
    "noEmitHelpers": false,
    "importHelpers": true,
    "noResolve": false,
    "noEmit": false,
    "noEmitOnError": false,
    "inlineSourceMap": false,
    "outDir": "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/node_modules/.cache/rollup-plugin-typescript2/placeholder",
    "allowNonTsExtensions": true
}
rpt2: parsed tsconfig: {
    "options": {
        "alwaysStrict": true,
        "baseUrl": "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro",
        "declaration": true,
        "forceConsistentCasingInFileNames": true,
        "module": 99,
        "moduleResolution": 2,
        "outDir": "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/node_modules/.cache/rollup-plugin-typescript2/placeholder",
        "paths": {
            "@/*": [
                "src/*"
            ]
        },
        "plugins": [
            {
                "transform": "typescript-transform-paths",
                "exclude": [
                    "**/node_modules/**"
                ]
            },
            {
                "transform": "typescript-transform-paths",
                "afterDeclarations": true,
                "exclude": [
                    "**/node_modules/**"
                ]
            }
        ],
        "skipLibCheck": true,
        "target": 99,
        "configFilePath": "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/tsconfig.json",
        "pathsBasePath": "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro",
        "noEmitHelpers": false,
        "importHelpers": true,
        "noResolve": false,
        "noEmit": false,
        "noEmitOnError": false,
        "inlineSourceMap": false,
        "allowNonTsExtensions": true
    },
    "fileNames": [
        "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts",
        "C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts"
    ],
    "typeAcquisition": {
        "enable": false,
        "include": [],
        "exclude": []
    },
    "raw": {
        "compileOnSave": false,
        "compilerOptions": {
            "alwaysStrict": true,
            "baseUrl": "./",
            "declaration": true,
            "forceConsistentCasingInFileNames": true,
            "module": "ESNext",
            "moduleResolution": "node",
            "outDir": "dist",
            "paths": {
                "@/*": [
                    "src/*"
                ]
            },
            "plugins": [
                {
                    "transform": "typescript-transform-paths",
                    "exclude": [
                        "**/node_modules/**"
                    ]
                },
                {
                    "transform": "typescript-transform-paths",
                    "afterDeclarations": true,
                    "exclude": [
                        "**/node_modules/**"
                    ]
                }
            ],
            "skipLibCheck": true,
            "target": "ESNext"
        },
        "include": [
            "src/**/*.ts"
        ],
        "exclude": []
    },
    "errors": [],
    "wildcardDirectories": {
        "c:/developerarea/troubleshooting/rollup_relative_path_repro/src": 1
    },
    "compileOnSave": false
}
rpt2: typescript version: 5.3.2
rpt2: tslib version: 2.6.2
rpt2: rollup version: 4.6.0
rpt2: rollup-plugin-typescript2 version: 0.36.0
rpt2: plugin options:
{
    "check": true,
    "verbosity": 3,
    "clean": false,
    "cacheRoot": "C:\\DeveloperArea\\Troubleshooting\\rollup_relative_path_repro\\node_modules\\.cache\\rollup-plugin-typescript2",
    "include": [
        "*.ts+(|x)",
        "**/*.ts+(|x)",
        "**/*.cts",
        "**/*.mts"
    ],
    "exclude": [
        "*.d.ts",
        "**/*.d.ts",
        "**/*.d.cts",
        "**/*.d.mts"
    ],
    "abortOnError": true,
    "rollupCommonJSResolveHack": false,
    "useTsconfigDeclarationDir": false,
    "tsconfigOverride": {},
    "transformers": [],
    "tsconfigDefaults": {},
    "objectHashIgnoreUnknownHack": false,
    "cwd": "C:\\DeveloperArea\\Troubleshooting\\rollup_relative_path_repro",
    "typescript": "version 5.3.2"
}
rpt2: rollup config:
{
    "external": [],
    "input": [
        "src/index.ts"
    ],
    "plugins": [
        {
            "name": "rpt2"
        },
        {
            "name": "stdin"
        }
    ],
    "output": [
        {
            "dir": "dist",
            "format": "es",
            "plugins": [],
            "preserveModules": true
        }
    ]
}
rpt2: tsconfig path: C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/tsconfig.json
rpt2: included:
[
    "*.ts+(|x)",
    "**/*.ts+(|x)",
    "**/*.cts",
    "**/*.mts"
]
rpt2: excluded:
[
    "*.d.ts",
    "**/*.d.ts",
    "**/*.d.cts",
    "**/*.d.mts"
]
rpt2: Ambient types:
rpt2:     C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/node_modules/@types/estree/index.d.ts
rpt2: transpiling 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\src\index.ts'
rpt2:     cache: 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\node_modules\.cache\rollup-plugin-typescript2/rpt2_0a69b19586e5d8bec6386b448d0a542c0e27d0ee/code/cache/48695b338c4cbedb3e73a531f32fc02244a4adba'
rpt2:     cache hit
rpt2:     cache: 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\node_modules\.cache\rollup-plugin-typescript2/rpt2_0a69b19586e5d8bec6386b448d0a542c0e27d0ee/syntacticDiagnostics/cache/f5704ba76695d1d71abc2edf3685bb735f949b9a'
rpt2:     cache hit
rpt2:     cache: 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\node_modules\.cache\rollup-plugin-typescript2/rpt2_0a69b19586e5d8bec6386b448d0a542c0e27d0ee/semanticDiagnostics/cache/f5704ba76695d1d71abc2edf3685bb735f949b9a'
rpt2:     cache hit
rpt2: generated declarations for 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts'
																						 
																								
																																											   
																					 
rpt2: transpiling 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\src\dep.ts'
rpt2:     cache: 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\node_modules\.cache\rollup-plugin-typescript2/rpt2_0a69b19586e5d8bec6386b448d0a542c0e27d0ee/code/cache/f1b786e531223aa87a70d8d21829932f5be42e1a'
rpt2:     cache hit
rpt2:     cache: 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\node_modules\.cache\rollup-plugin-typescript2/rpt2_0a69b19586e5d8bec6386b448d0a542c0e27d0ee/syntacticDiagnostics/cache/a5404b1a8021cd8bc29e53d56a6fb0f5b47a4c36'
rpt2:     cache hit
rpt2:     cache: 'C:\DeveloperArea\Troubleshooting\rollup_relative_path_repro\node_modules\.cache\rollup-plugin-typescript2/rpt2_0a69b19586e5d8bec6386b448d0a542c0e27d0ee/semanticDiagnostics/cache/a5404b1a8021cd8bc29e53d56a6fb0f5b47a4c36'
rpt2:     cache hit
rpt2: generated declarations for 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts'
rpt2: dependency 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts'
rpt2:     imported by 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts'
rpt2: resolving '@/dep' imported by 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts'
rpt2:     to 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts'
rpt2: rolling caches
rpt2: generating target 1
rpt2: emitting declarations for 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/index.ts' to 'index.d.ts'
rpt2: emitting declarations for 'C:/DeveloperArea/Troubleshooting/rollup_relative_path_repro/src/dep.ts' to 'dep.d.ts'
created dist in 665ms
Done in 1.83s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: supportAsking for support with something or a specific use casescope: integrationRelated to an integration, not necessarily to core (but could influence core)solution: can't reproAn attempt to reproduce has been tried and failed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions