ivogabe / gulp-typescript

A TypeScript compiler for gulp with incremental compilation support.
MIT License
831 stars 129 forks source link

[Doubt] Best practices for gulp-typescript and monerepo #588

Closed gfrancischini closed 4 years ago

gfrancischini commented 5 years ago

Hi, sorry if this is not the right place to it but I would like know what are the best practices for gulp-typescript and monorepo.

How I should configure my project ? Is TS3.0 supported? Should I use gulp-typescript + TS3.0

Do you have any samples of a monorepo project?

Thanks

ivogabe commented 5 years ago

I personally have no experience with monorepos in TypeScript. TypeScript 3.0 is supported (and advised). In that version, project references were added. You can find information about that in the TypeScript handbook.

I'm not aware of material on the combination of gulp-typescript and project references. @rbuckton implemented it in gulp-typescript in #579, so he might be able to help if you have further questions.

ciddan commented 5 years ago

@rbuckton Are project references that are not configured with outFile/prepend supposed to work?

I have this structure:

- platform/
-- shared/
--- libs/
---- ui/
----- tsconfig.json
-- web/
--- app1/
---- tsconfig.json

The tsconfig.json file in wab/app1 points to the tsconfig in shared/libs/ui. Compiling with tsc -b works, compiling with gulp-typescript does not. Output from gulp-typescript:

app\main.ts(6,14): error TS2307: Cannot find module '@shared/localization-store'.
TypeScript: 1 semantic error
TypeScript: emit succeeded (with errors)
[10:56:12] Error: TypeScript: Compilation failed
    at Output.mightFinish (C:\Development\Project\platform\web\news\node_modules\gulp-typescript\release\output.js:130:43)
    at applySourceMap.then.appliedSourceMap (C:\Development\Project\platform\web\news\node_modules\gulp-typescript\release\output.js:43:22)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
rbuckton commented 5 years ago

They should work, as I am using them in another project which uses modules and does not use outFile or prepend.

Are you also using baseUrl/paths in your tsconfig.json to redirect @shared to shared?

ciddan commented 5 years ago

Yes, I am. This is the tsconfig of the project:

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": ".",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "importHelpers": true,
        "inlineSourceMap": true,
        "module": "system",
        "moduleResolution": "node",
        "noUnusedLocals": true,
        "outDir": "./dist/app",
        "paths": {
            "@shared/*": ["../../shared/libs/ui/*"]
        },
        "strict": true,
        "target": "es2017",
        "types": []
    },
    "exclude": [
        "node_modules"
    ],
    "references": [
        { "path": "../../shared/libs/ui/localization-store" }
    ]
}

When I compile with tsc --build, files are emitted in the referenced project (.d.ts, .js) but not when I use gulp-typescript.

I'm guessing the referenced files have to be pre-compiled for this to work, i.e. gulp-typescript won't emit files in the referenced project folder structure? That would make sense, given the fact that gulp controls file emit with .dest().

rbuckton commented 5 years ago

I'm guessing the referenced files have to be pre-compiled for this to work, […]

That is correct. The support for project references in gulp-typescript is currently very rudimentary. Its main benefit is to avoid reparsing full .ts files from referenced projects when a minimal parse of the output .d.ts would be faster/more efficient.

dayrim commented 4 years ago

Still there is a problem of building a project with gulp-typescript that uses references.