Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
Use Typescript project references (experiment).
Browse files Browse the repository at this point in the history
* introduce optional, parallel `tsc --build` based build system
* distribute ESM and CommonJS into separate folders in npm packages

Signed-off-by: Zbigniew Zagorski <ext-zbyszek.zagorski@here.com>
  • Loading branch information
Zbigniew Zagorski committed Dec 5, 2019
1 parent bfae429 commit 32edb51
Show file tree
Hide file tree
Showing 92 changed files with 1,508 additions and 321 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Expand Up @@ -3,7 +3,12 @@ dist/
doc/
test-npm-packages-app/
.vscode/
tsconfig-esm.json
tsconfig-cjs.json
.DS_Store
.nyc_output/

credentials.js
*.d.ts
*.js
*.js.map
tsconfig-build.tsbuildinfo
5 changes: 5 additions & 0 deletions .mocharc.json
@@ -0,0 +1,5 @@
{
"diff": true,
"spec": ["./test/**/*.js", "./@here/*/test/**/*.js"],
"exclude": ["./@here/harp-mapview/test/resources/testWorker.js"]
}
21 changes: 7 additions & 14 deletions @here/harp-atlas-tools/tsconfig.json
@@ -1,18 +1,11 @@
{
"extends": "../../tsconfig-common.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"rootDir": "src",
"outDir": "lib",
"sourceMap": true,
"declaration": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"downlevelIteration": true
"rootDir": ".",
"noEmit": true
},
"exclude": ["node_modules"],
"include": ["src/*.ts"]
"include": [
"lib/**/*.ts",
"index.ts"
]
}
12 changes: 12 additions & 0 deletions @here/harp-datasource-protocol/test/tsconfig-build.json
@@ -0,0 +1,12 @@
{
"extends": "../../../tsconfig.settings.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "."
},
"references": [
{ "path": "../tsconfig-build.json" },
{ "path": "../../harp-geoutils/tsconfig-build.json" },
{ "path": "../../harp-utils/tsconfig-build.json" }
]
}
12 changes: 12 additions & 0 deletions @here/harp-datasource-protocol/tsconfig-build.json
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"outDir": ".",
"rootDir": "."
},
"references": [
{ "path": "../harp-geoutils/tsconfig-build.json" },
{ "path": "../harp-utils/tsconfig-build.json" }
],
"exclude": ["test/**/*.ts"]
}
33 changes: 22 additions & 11 deletions @here/harp-datasource-protocol/tsconfig.json
@@ -1,14 +1,25 @@
{
"extends": "../../tsconfig-common.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"downlevelIteration": true
}
"rootDir": ".",
"noEmit": true
},
"include": [
"lib/**/*.ts",
"index.ts"
],
"references": [
{
"path": "../harp-geometry"
},
{
"path": "../harp-geoutils"
},
{
"path": "../harp-utils"
}
],
"exclude": [
"test/**/*.ts"
]
}
13 changes: 13 additions & 0 deletions @here/harp-debug-datasource/tsconfig-build.json
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "."
},
"references": [
{ "path": "../harp-lrucache/tsconfig-build.json" },
{ "path": "../harp-geoutils/tsconfig-build.json" },
{ "path": "../harp-mapview/tsconfig-build.json" }
],
"exclude": ["test/**/*.ts"]
}
36 changes: 25 additions & 11 deletions @here/harp-debug-datasource/tsconfig.json
@@ -1,14 +1,28 @@
{
"extends": "../../tsconfig-common.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"downlevelIteration": true
}
"rootDir": ".",
"noEmit": true
},
"include": [
"lib/**/*.ts",
"index.ts"
],
"references": [
{
"path": "../harp-geoutils"
},
{
"path": "../harp-lrucache"
},
{
"path": "../harp-mapview"
},
{
"path": "../harp-text-canvas"
}
],
"exclude": [
"test/**/*.ts"
]
}
3 changes: 2 additions & 1 deletion @here/harp-examples/package.json
Expand Up @@ -52,10 +52,11 @@
"highlight.js": "^9.15.8",
"html-webpack-plugin": "^3.2.0",
"ncp": "^2.0.0",
"source-map-loader": "^0.2.4",
"stats.js": "^0.17.0",
"style-loader": "^1.0.0",
"three": "^0.110.0",
"ts-loader": "^6.0.3",
"ts-loader": "^6.2.1",
"typescript": "^3.7.2",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4",
Expand Down
31 changes: 31 additions & 0 deletions @here/harp-examples/tsconfig-build.json
@@ -0,0 +1,31 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"rootDir": ".",
"outDir": ".",
"resolveJsonModule": true
},
"references": [
{ "path": "../harp-datasource-protocol/tsconfig-build.json" },
{ "path": "../harp-debug-datasource/tsconfig-build.json" },
{ "path": "../harp-features-datasource/tsconfig-build.json" },
{ "path": "../harp-geojson-datasource/tsconfig-build.json" },
{ "path": "../harp-geoutils/tsconfig-build.json" },
{ "path": "../harp-map-controls/tsconfig-build.json" },
{ "path": "../harp-mapview/tsconfig-build.json" },
{ "path": "../harp-omv-datasource/tsconfig-build.json" },
{ "path": "../harp-text-canvas/tsconfig-build.json" },
{ "path": "../harp-utils/tsconfig-build.json" },
{ "path": "../harp-webtile-datasource/tsconfig-build.json" }
],
"include": [
"./*.ts",
"./src/*.ts",
"./lib/*.ts",
"./resources/*.ts",
"./decoder/*.ts",
"./src/*.tsx",
"./resources/**/*.json"
],
"exclude": ["test/**/*.ts", "dist/**/*.ts"]
}
15 changes: 15 additions & 0 deletions @here/harp-examples/tsconfig-custom.json
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"resolveJsonModule": true
},
"include": [
"./*.ts",
"./src/*.ts",
"./lib/*.ts",
"./resources/*.ts",
"./decoder/*.ts",
"./src/*.tsx",
"./resources/**/*.json"
],
"exclude": ["test/**/*.ts", "dist/**/*.ts"]
}
23 changes: 8 additions & 15 deletions @here/harp-examples/tsconfig.json
@@ -1,18 +1,11 @@
{
"extends": "../../tsconfig-common.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"declaration": false,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"resolveJsonModule": true,
"downlevelIteration": true,
"jsx": "react",
"skipLibCheck": true,
"baseUrl": "../../"
}
"rootDir": ".",
"noEmit": true
},
"include": [
"lib/**/*.ts",
"index.ts"
]
}
44 changes: 44 additions & 0 deletions @here/harp-examples/webpack-build.config.js
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2017-2018 HERE Europe B.V.
* Licensed under Apache 2.0, see full license in LICENSE
* SPDX-License-Identifier: Apache-2.0
*/

/**
* This basically downgrades original webpack.config.js to compile
* only JS created by `tsc -b .` (in current folder).
*
* This is much faster in bigger build process as Typescript runs only once.
*
* Usage:
* - Development
* tsc --build tsconfig-build.json --watch --verbose --listEmittedFiles
* webpack-dev-server --config webpack-build.config.js
*
* - CI
* tsc --build tsconfig-build.json
* webpack --config webpack-build.config.js
*/
const configs = require('./webpack.config');

module.exports = configs.map(config => {
config.resolve.extensions = [".webpack.js", ".web.js", ".js"]
config.module.rules = config.module.rules.filter(rule => rule.loader !== "ts-loader")
config.module.rules.push({
rules: [
{
test: /\.js$/,
use: ["source-map-loader"],
enforce: "pre"
}
]
})
for(const entry in config.entries) {
config.entries[entry] = config.entries[entry].replace(/.ts$/, ".js");
}
return config;
})

throw new Foo();
16 changes: 5 additions & 11 deletions @here/harp-examples/webpack.config.js
Expand Up @@ -40,10 +40,7 @@ const commonConfig = {
}
],
resolve: {
extensions: [".webpack.js", ".web.ts", ".ts", ".tsx", ".web.js", ".js"],
alias: {
"react-native": "react-native-web"
}
extensions: [".webpack.js", ".web.ts", ".ts", ".tsx", ".web.js", ".js"]
},
module: {
rules: [
Expand All @@ -52,13 +49,9 @@ const commonConfig = {
loader: "ts-loader",
exclude: /node_modules/,
options: {
configFile: path.join(process.cwd(), "tsconfig.json"),
configFile: path.join(__dirname, "tsconfig-build.json"),
onlyCompileBundledFiles: true,
transpileOnly: prepareOnly,
compilerOptions: {
sourceMap: !prepareOnly,
declaration: false
}
projectReferences: true
}
}
]
Expand All @@ -84,12 +77,13 @@ const commonConfig = {
const decoderConfig = merge(commonConfig, {
target: "webworker",
entry: {
decoder: "./decoder/decoder.ts"
decoder: "./decoder/decoder"
}
});

const webpackEntries = glob
.sync(path.join(__dirname, "./src/*.{ts,tsx}"))
.filter(name => !name.includes(".d.ts"))
.reduce((result, entry) => {
const name = path.basename(entry).replace(/.tsx?$/, "");
if (name.startsWith("common")) {
Expand Down
14 changes: 14 additions & 0 deletions @here/harp-features-datasource/tsconfig-build.json
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.settings.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "."
},
"references": [
{ "path": "../harp-datasource-protocol/tsconfig-build.json" },
{ "path": "../harp-geojson-datasource/tsconfig-build.json" },
{ "path": "../harp-mapview/tsconfig-build.json" },
{ "path": "../harp-omv-datasource/tsconfig-build.json" }
],
"exclude": ["test/**/*.ts"]
}
36 changes: 25 additions & 11 deletions @here/harp-features-datasource/tsconfig.json
@@ -1,14 +1,28 @@
{
"extends": "../../tsconfig-common.json",
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"declaration": true,
"strictNullChecks": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"downlevelIteration": true
}
"rootDir": ".",
"noEmit": true
},
"include": [
"lib/**/*.ts",
"index.ts"
],
"references": [
{
"path": "../harp-datasource-protocol"
},
{
"path": "../harp-geojson-datasource"
},
{
"path": "../harp-mapview"
},
{
"path": "../harp-omv-datasource"
},
{
"path": "../harp-utils"
}
]
}

0 comments on commit 32edb51

Please sign in to comment.