Issue/2593 Upgrade Typescript Project to Use Project References#2641
Closed
Issue/2593 Upgrade Typescript Project to Use Project References#2641
Conversation
increase the cache key
- remove noEmitOnError from global as it's not appropriate for project reference setup - add tsbuildinfo to gitignore
Contributor
|
I think I'm OK with this as long as it solves @kring 's problems 👍 |
Contributor
Author
|
@AlexGilleran |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Fixes #2593
Upgraded the followings:
typescript: to 3.7.2ts-node: to 8.5.2tsconfig-paths: to 3.9.0webpack: to 4.41.2ts-loaderwhich supportproject referencestsconfig-paths-webpack-pluginfor betterproject referencessupport as wellChanges Summary:
tsconfig-global.json:by default(i.e. when this option off) when meeting any errors. However, if set this option totrue, ts will stop emit for dependent projects and leave you ano emiterror.@magda/typescript-common/distwithmagda-typescript-common/src@magda/minion-framework/distwithmagda-minion-framework/src--esModuleInteropis turned on by default for new version TS. so replace import commonJs mouldeimport * as foo from "foo"with import foo from foo (it will work even the module has no default export). see hereimport * as--- es6 module with no default export can still import all export in that way.nock--- it's against ECMAScript spec as a namespace import can't be a callable)magda-typescript-common/src/express/status.ts:nextStateis undefinedmagda-typescript-common/src/tenant-api/AuthorizedTenantClient.ts:getTenants: make exception not all muted so it matches other code.Limitation on typescript & Other consideration:
Typescript compiler won't allow you to have two different
compile-time module path&runtime module path, which make it difficult to deploy compiled commonJS module code.e.g. if you put
import x from "magda-typescipt-common/src"; in your code, thetscbuild result will outputrequire("magda-typescipt-common/src")in the built code.And typescript won't allow you to map it to a runtime path (e.g.
@magda/typescript-common/distormagda-typescipt-common/distlike the feature that babel, webpack & rollup all provides). I think this is not gonna be changed in short-term as Microsoft team believe mapping the runtime module path altersimportstatement's behaviour. Thus it's against typescript's design goal 7. See here.project references feature won't help this either.
There are solutions like tsconfig-paths available. But it's for ts-node (works well for our test cases with project references) and our runtime env in docker is quite different (can't be figured out from
tsconfig.json).Thus, my current solution is to use Babel's
babel-plugin-module-resolvermodule to replace module alias in TS build result - The current build script istsc -b && babel dist -d dist;https://issue-2593.dev.magda.io/@AlexGilleran @kring
You probably won't like it. Thus, create a draft PR to collect feedback, ideas and decide where we go 😄
Other solutions I can think of:
tsconfig-paths/register) to overriderequire. We will need to alter the way we run our code. e.g.node -r ourModuleAlias.register dist/index.js. Will need to update our helm charts.magda-typescript-common&magda-minion-framework:magda-typescript-common/ormagda-minion-framework/(nosrc)import addJwtSecretFromEnvVar from "magda-typescript-common/session/addJwtSecretFromEnvVar";prepend optionto includemagda-typescript-common&magda-minion-frameworkin build file. e.g."references": [{ "path": "../magda-typescript-common", "prepend": true }]will include AMD module build output at beginning of the built file.@AlexGilleran @kring
Please let me know your idea~
Test Site:
https://issue-2593.dev.magda.io/
Checklist