timocov / ts-transformer-properties-rename

TypeScript custom transformer to rename properties
MIT License
70 stars 3 forks source link

Improvde DX and migration from `ts-transformer-minify-privates` #33

Open timocov opened 1 year ago

timocov commented 1 year ago

@timocov I've tried to use https://github.com/timocov/ts-transformer-properties-rename but couldn't make it work.

How I use ts-transformer-minify-privates in webpack ts-loader:

import:

import minifyPrivatesTransformer from 'ts-transformer-minify-privates';

use in ts-loader rule:

    {
        loader: 'ts-loader',
        options: {
            transpileOnly,
            onlyCompileBundledFiles: true,
            compilerOptions: {
                target: `es${targetEsVersion}`,
                importHelpers: true,
                jsx: 'preserve',
                noUnusedLocals: false
            },
            getCustomTransformers: transpileOnly ?
                undefined :
                (program: ts.Program) => ({
                    before: [
                        minifyPrivatesTransformer(program)
                    ]
                })
        }
    }

How I try to use ts-transformer-properties-rename:

const propertiesRenameTransformer = require('ts-transformer-properties-rename').default;

First of all, It's weird ts-transformer-properties-rename doesn't include d.ts for types. Then I replace transform with the new one. Now I have to pass some entrySourceFiles (with ts-transformer-minify-privates I don't). Ok, I try to pass the same entry file as I pass to webpack entry:

propertiesRenameTransformer(program, { entrySourceFiles: [entryFile] })

And get an error: Error: Cannot find source file /Users/dfilatov/prjs/arcadia/maps/front/services/nmaps/src/client/pages/app-page/nk-app-page.ts

But file /Users/dfilatov/prjs/arcadia/maps/front/services/nmaps/src/client/pages/app-page/nk-app-page.ts actually exists:

❯ ls -la /Users/dfilatov/prjs/arcadia/maps/front/services/nmaps/src/client/pages/app-page/nk-app-page.ts
-rw-rw-r--  1 dfilatov  LD\Domain Users  904 Mar  9  2022 /Users/dfilatov/prjs/arcadia/maps/front/services/nmaps/src/client/pages/app-page/nk-app-page.ts

Have no idea how to make it work. Please help.

Originally posted by @dfilatov in https://github.com/timocov/ts-transformer-minify-privates/issues/25#issuecomment-1512790285