Ann: Working early version 0.0.3 of refapp:meteor-typescript, a brand new fast Typescript compiler with tsconfig.json support and diagnostics output

Announcing a newly written Typescript compiler that is a drop-in replacement for typescript and adornis:typescript.

Note that this is an early version, use at your own risk.

Source code here:

Key features:

  • Obeys your tsconfig.json settings, but has only been tested with a few variations, most notably only with target and module set to “ESNext”, and overwrites a few obvious settings like “incremental” and “emit”.
  • Uses the Typescript 3.6 createIncrementalProgram API to compile all ts sources at once, and keeps the incremental build support file in .meteor/local/.typescript-incremental so you can save it on your build server. That means that it’s pretty fast, unlike derivatives of barbatus:typescript.
  • Shows compilation progress and diagnostics (type errors etc) using bright green and red letters to make you happy.
  • Uses the core BabelCompiler for all the Babel stuff, just like the built-in typescript package.
  • SourceMaps are supported.
  • Written in Typescript (bootstrapped using the core typescript package)

I’ve tested the new compiler on a slightly modified meteor create --typescript sample and on our own app which is semi- large (>500 typescript files) and it seems to work just fine.

Here are some things it doesn’t do yet:

  • Filter out files from compilation based on meteor rules (.meteorignore etc) - you have to add these to the exclude filter in tsconfig.json
  • Abort the compilation if there are type errors that prevent some js from being emitted. That would be a trivial change.
  • The incremental compilation support seems a bit flaky - not sure if I’m using the API wrong or if there’s a bug. Sometimes it just recompiles everything from scratch.
  • No unit tests. Yeah - I know…
  • The “compiling” progress is actually “emit” progress. Does it matter?

I personally think it’s a good idea to keep this compiler outside of the meteor code package so it can be updated without locking it to a Meteor release - there really isn’t anything in there that uses any private Meteor internals (but it would be nice to use the Console package in meteor/tools if I could figure out how to access it).

I’d also be happy to put this under community ownership or if that doesn’t happen then get in touch and I can add you as a collaborator.

Install using
meteor add refapp:meteor-typescript

10 Likes

https://github.com/Meteor-Community-Packages/organization/issues/48 - proposal for moving to Meteor-Community

The packages are up at 0.1.0 now and we’ve been using them for our production builds for weeks now so please get onboard and try it out.

2 Likes

Sounds awesome!

I’ve added to our project that’s been using core’s typescript@3.7.6 but am hitting an error during the Typescript compilation for os.osx.x86_64 using Typescript 3.9.2 step.

Error is

/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:42526:40:
   Cannot read property 'valueDeclaration' of undefined

What’s interesting is that i’m running --exclude-archs web.browser.legacy,web.cordova

My tsconfig is also not really that crazy

{
  "compilerOptions": {
    /* Basic Options */
    "target": "es2018",
    "module": "esNext",
    "lib": ["esnext", "dom"],
    "allowJs": true,
    "checkJs": false,
    "jsx": "preserve",
    "incremental": true,
    "noEmit": true,

    /* Strict Type-Checking Options */
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    /* Additional Checks */
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": false,
    "noFallthroughCasesInSwitch": false,
    "typeRoots": ["../node_modules/@types"],
    /* Module Resolution Options */
    "baseUrl": ".",
    "paths": {
      "/*": ["*"],
      "animation": ["imports/ui/animation"],
      "animation*": ["imports/ui/animation*"],
      "elements": ["imports/ui/elements"],
      "elements*": ["imports/ui/elements*"],
      "hooks": ["imports/ui/hooks"],
      "hooks*": ["imports/ui/hooks*"],
      "state": ["imports/ui/globalState"],
      "state*": ["imports/ui/globalState*"],
      "ui": ["imports/ui"],
      "ui*": ["imports/ui*"],
      "utilities": ["imports/ui/utilities"],
      "utilities*": ["imports/ui/utilities*"]
    },
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "types": ["node", "mocha", "jest"],
    "esModuleInterop": true,
    "preserveSymlinks": true
  },
  "exclude": ["./.meteor/**", "./packages/**", "./.github/**"]
}

Re-ran without --exclude-archs web.browser.legacy,web.cordova", and am getting the same error.

Also. I just tried to drop this package into the meteor create --typescript template and it’s not working OOTB.

Typescript compilation for web.browser using Typescript 3.9.2
Compiling imports/api/links.ts
Compiling server/main.ts
Compiling tests/main.ts
Writing .meteor/local/.typescript-incremental/buildfile.tsbuildinfo
tests/main.ts (6,13): This syntax requires an imported helper but module 'tslib' cannot be found.
Compilation finished in 2.7 seconds
Typescript compilation for web.browser.legacy using Typescript 3.9.2
tests/main.ts (6,13): This syntax requires an imported helper but module 'tslib' cannot be found.
Compilation finished in 0.9 seconds
Typescript compilation for os.osx.x86_64 using Typescript 3.9.2
tests/main.ts (6,13): This syntax requires an imported helper but module 'tslib' cannot be found.
Compilation finished in 0.7 seconds

the page gives an error as well Uncaught SyntaxError: Unexpected token '<'

Hmm yeah I think I had to tweak the tsconfig.json from the vanilla version to get it to work (the one produced by meteor create didn’t work but I forget why).

Here’s the one used in the test project I used while developing the compiler:

I decided to enforce use of importHelpers because I needed that when using adornis:typescript so you do need to add that npm package. Maybe it can become optional (requires a source code change).

Cool, so adding tslib as a dep fixed the issues tslib issue. Changing "jsx": "preserve", to "jsx": "react", fixed the build issues. (this is on the meteor create app). I’ll try some of these changes on my own project and see if I can get it to build.

So I’ve modified my project to use a tsconfig more like yours

{
  "compilerOptions": {
    /* Basic Options */
    "target": "ESNext",
    "module": "ESNext",
    "lib": ["esnext", "dom"],
    "allowJs": true,
    "checkJs": false,
    "jsx": "react",
    "importHelpers": true,
    "allowSyntheticDefaultImports": true,

    /* Strict Type-Checking Options */
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,

    /* Additional Checks */
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": false,
    "noFallthroughCasesInSwitch": false,

    /* Module Resolution Options */
    "baseUrl": ".",
    "paths": {
      "/*": ["*"],
      "animation": ["imports/ui/animation"],
      "animation*": ["imports/ui/animation*"],
      "elements": ["imports/ui/elements"],
      "elements*": ["imports/ui/elements*"],
      "hooks": ["imports/ui/hooks"],
      "hooks*": ["imports/ui/hooks*"],
      "state": ["imports/ui/globalState"],
      "state*": ["imports/ui/globalState*"],
      "ui": ["imports/ui"],
      "ui*": ["imports/ui*"],
      "utilities": ["imports/ui/utilities"],
      "utilities*": ["imports/ui/utilities*"]
    },
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "types": ["node", "mocha", "jest"],
    "esModuleInterop": true,
    "preserveSymlinks": true
  },
  "exclude": ["./.meteor/**", "./packages/**", "./.github/**"]
}

and have included tslib as a dep but am still seeing a failed build

While processing files with refapp:meteor-typescript (for target web.browser):

   /Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:15674:53:
   Cannot read property 'heritageClauses' of undefined
   at getClassExtendsHeritageElement
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:15674:53)
   at Object.getEffectiveBaseTypeNode
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:15662:24)
   at getBaseConstructorTypeOfClass
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:42527:35)
   at serializeAsClass
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:40547:42)
   at serializeSymbolWorker
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:40270:29)
   at serializeSymbol
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:40211:38)
   at
   /Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:40193:29
   at Map.forEach (<anonymous>)
   at visitSymbolTable
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:40192:42)
   at symbolTableToDeclarationStatements
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:40056:17)
   at
   /Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:38606:106
   at withContext
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:38632:37)
   at Object.symbolTableToDeclarationStatements
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:38606:28)
   at Object.getDeclarationStatementsForSourceFile
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:67998:60)
   at transformDeclarationsForJS
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:92738:35)
   at transformRoot
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:92815:57)
   at transformation
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94060:24)
   at transformRoot
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94081:82)
   at Object.map
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:551:29)
   at Object.transformNodes
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94067:30)
   at emitDeclarationFileOrBundle
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94702:43)
   at emitSourceFileOrBundle
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94608:13)
   at forEachEmittedFile
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94359:34)
   at Object.emitFiles
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:94588:9)
   at emitWorker
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:100792:33)
   at
   /Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:100771:66
   at runWithCancellationToken
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:100867:24)
   at Object.emit
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:100771:20)
   at getFileEmitOutput
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:102635:26)
   at updateShapeSignature
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:102876:36)
   at getFilesAffectedByUpdatedShapeWhenModuleEmit
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:103082:46)
   at Object.getFilesAffectedBy
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:102831:144)
   at getNextAffectedFile
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:103313:51)
   at getSemanticDiagnosticsOfNextAffectedFile
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:103849:32)
   at Object.getSemanticDiagnostics
   (/Users/scotttolinski/.meteor/packages/refapp_meteor-typescript/.0.1.0.f13mj.r33wjl++os+web.browser+web.browser.legacy+web.cordova/plugin.meteor-typescript.os/npm/node_modules/meteor/refapp_meteor-typescript-compiler/node_modules/typescript/lib/typescript.js:103893:20)
   at MeteorTypescriptCompilerImpl.startIncrementalCompilation
   (packages/refapp:meteor-typescript-compiler/meteor-typescript-compiler.ts:161:23)
   at MeteorTypescriptCompilerImpl.processFilesForTarget
   (packages/refapp:meteor-typescript-compiler/meteor-typescript-compiler.ts:294:10)

FWIW heritageClauses is only used via node.heritageClauses in typescript.js. I doubt that’s helpful, but may be a clue. My project is fairly large and complex, but I’ll try and compare with meteor create --typescript to see what’s different about them both. LMK if you have anything else for me to try in the meantime. Also interested to see if others hit this same issue.

I published v 0.1.1 where I removed the importHelpers hardcoded setting. I also found a new class callback to report how many files were sent on for Meteor bundling after the lazyCompilation is done.

I have no clue what problem you’ve run into, sorry.

That one’s a clear bug in the meteor sample.

No worries. The app compiles fine with the core TS package, so I’d assume I wouldn’t be the only one who might hit something like this.

I’m in the process of moving things over from my project to the blank starter in an attempt to break and troubleshoot it. So far it’s not my babel config, or my tsconfig.