Skip to content

Commit 25f9bae

Browse files
committed
♻️(typescript) move tokens sources to absolute import
Relatives import are quite ugly and reduces readability, but hard to say that Typescript handles it very well for compilation time, but nothing for runtime. That's why I had to add tsc-alias to the build script. Please see this issue for more details. microsoft/TypeScript#15479 Furthermore, some configuration was needed for Jest to work well.
1 parent fa46237 commit 25f9bae

File tree

9 files changed

+55
-16
lines changed

9 files changed

+55
-16
lines changed

packages/tokens/jest.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
export default {
1+
import type { JestConfigWithTsJest } from "ts-jest";
2+
3+
const jestConfig: JestConfigWithTsJest = {
24
preset: "ts-jest",
35
testEnvironment: "node",
6+
moduleDirectories: ["node_modules", "src/bin"],
47
};
8+
9+
export default jestConfig;

packages/tokens/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
"scripts": {
1616
"lint": "eslint . 'src/**/*.{ts,tsx}'",
1717
"dev": "nodemon --watch 'src/bin' --ext '*' --exec 'yarn build'",
18-
"build": "tsc -p tsconfig.json && cp src/bin/cunningham.dist.js dist/bin && chmod +x dist/bin/Main.js && yarn build-default-theme",
18+
"build": "tsc -p tsconfig.json && tsc-alias && cp src/bin/cunningham.dist.js dist/bin && chmod +x dist/bin/Main.js && yarn build-default-theme",
1919
"build-default-theme": "./dist/bin/Main.js -o dist -s html",
2020
"test": "FORCE_COLOR=1 jest --verbose src/bin/tests"
2121
},
2222
"dependencies": {
2323
"chalk": "4.1.2",
2424
"commander": "9.4.1",
2525
"deepmerge": "4.2.2",
26-
"figlet": "1.5.2"
26+
"figlet": "1.5.2",
27+
"tsc-alias": "^1.8.2"
2728
},
2829
"devDependencies": {
2930
"@types/figlet": "1.5.5",

packages/tokens/src/bin/ConfigLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from "path";
22
import * as fs from "fs";
33
import deepmerge from "deepmerge";
4+
import { ConfigShape } from "TokensGenerator";
5+
import { workPath } from "Paths";
46
import Config from "./Config";
5-
import { ConfigShape } from "./TokensGenerator";
6-
import { workPath } from "./Paths";
77

88
const getLocalConfig = async () => {
99
const filename = Config.configurationFilenames

packages/tokens/src/bin/CssGenerator.ts renamed to packages/tokens/src/bin/Generators/CssGenerator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as path from "path";
22
import * as fs from "fs";
33
import chalk from "chalk";
4-
import Config from "./Config";
5-
import { flatify } from "./Utils/Flatify";
4+
import { flatify } from "Utils/Flatify";
5+
import Config from "Config";
66

77
export const cssGenerator = async (
88
tokens: any,

packages/tokens/src/bin/Main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env node
22

3-
import { run } from "./ThemeGenerator";
3+
import { run } from "ThemeGenerator";
44

55
run(process.argv);

packages/tokens/src/bin/ThemeGenerator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { program } from "commander";
22
import chalk from "chalk";
33
import figlet from "figlet";
4-
import { getConfig } from "./ConfigLoader";
5-
import { tokensGenerator } from "./TokensGenerator";
6-
import { cssGenerator } from "./CssGenerator";
7-
import { workPath } from "./Paths";
4+
import { cssGenerator } from "Generators/CssGenerator";
5+
import { getConfig } from "ConfigLoader";
6+
import { tokensGenerator } from "TokensGenerator";
7+
import { workPath } from "Paths";
88

99
export const buildTheme = async () => {
1010
const options = program.opts();

packages/tokens/src/bin/tests/Cunningham.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from "fs";
22
import * as path from "path";
3-
import { run } from "../ThemeGenerator";
3+
import { run } from "ThemeGenerator";
44
import Config from "../Config";
55

66
jest.mock("../Paths", () => ({

packages/tokens/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
],
66
"compilerOptions": {
77
"baseUrl": "./src/bin",
8+
"paths": {
9+
"*": ["*"]
10+
},
11+
"resolveJsonModule": true,
812
"outDir": "./dist/bin",
913
}
1014
}

yarn.lock

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4871,7 +4871,7 @@ check-error@^1.0.2:
48714871
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
48724872
integrity sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==
48734873

4874-
"chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.1, chokidar@^3.4.2, chokidar@^3.5.2:
4874+
"chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.1, chokidar@^3.4.2, chokidar@^3.5.2, chokidar@^3.5.3:
48754875
version "3.5.3"
48764876
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
48774877
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
@@ -5090,7 +5090,7 @@ comma-separated-tokens@^1.0.0:
50905090
resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz#632b80b6117867a158f1080ad498b2fbe7e3f5ea"
50915091
integrity sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw==
50925092

5093-
[email protected], commander@^9.4.1:
5093+
[email protected], commander@^9.0.0, commander@^9.4.1:
50945094
version "9.4.1"
50955095
resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.1.tgz#d1dd8f2ce6faf93147295c0df13c7c21141cfbdd"
50965096
integrity sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==
@@ -7200,7 +7200,7 @@ [email protected]:
72007200
resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.0.tgz#cb76da79555669a1519d5a8edf093afaa0bf1465"
72017201
integrity sha512-40oNTM9UfG6aBmuKxk/giHn5nQ8RVz/SS4Ir6zgzOv9/qC3kKZ9v4etGTcJbEl/NyVQH7FGU7d+X1egr57Md2Q==
72027202

7203-
globby@^11.0.2, globby@^11.1.0:
7203+
globby@^11.0.2, globby@^11.0.4, globby@^11.1.0:
72047204
version "11.1.0"
72057205
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
72067206
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
@@ -9472,6 +9472,11 @@ [email protected], ms@^2.1.1:
94729472
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
94739473
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
94749474

9475+
mylas@^2.1.9:
9476+
version "2.1.13"
9477+
resolved "https://registry.yarnpkg.com/mylas/-/mylas-2.1.13.tgz#1e23b37d58fdcc76e15d8a5ed23f9ae9fc0cbdf4"
9478+
integrity sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==
9479+
94759480
nan@^2.12.1:
94769481
version "2.17.0"
94779482
resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb"
@@ -10236,6 +10241,13 @@ pkg-types@^1.0.0:
1023610241
mlly "^1.0.0"
1023710242
pathe "^1.0.0"
1023810243

10244+
plimit-lit@^1.2.6:
10245+
version "1.5.0"
10246+
resolved "https://registry.yarnpkg.com/plimit-lit/-/plimit-lit-1.5.0.tgz#f66df8a7041de1e965c4f1c0697ab486968a92a5"
10247+
integrity sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng==
10248+
dependencies:
10249+
queue-lit "^1.5.0"
10250+
1023910251
1024010252
version "1.6.4"
1024110253
resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.6.4.tgz#c9711ac4dc48a685dabafc86f8b6dd9f8df84149"
@@ -10584,6 +10596,11 @@ querystringify@^2.1.1:
1058410596
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6"
1058510597
integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==
1058610598

10599+
queue-lit@^1.5.0:
10600+
version "1.5.0"
10601+
resolved "https://registry.yarnpkg.com/queue-lit/-/queue-lit-1.5.0.tgz#8197fdafda1edd615c8a0fc14c48353626e5160a"
10602+
integrity sha512-IslToJ4eiCEE9xwMzq3viOO5nH8sUWUCwoElrhNMozzr9IIt2qqvB4I+uHu/zJTQVqc9R5DFwok4ijNK1pU3fA==
10603+
1058710604
queue-microtask@^1.2.2:
1058810605
version "1.2.3"
1058910606
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
@@ -12222,6 +12239,18 @@ ts-pnp@^1.1.6:
1222212239
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
1222312240
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
1222412241

12242+
tsc-alias@^1.8.2:
12243+
version "1.8.2"
12244+
resolved "https://registry.yarnpkg.com/tsc-alias/-/tsc-alias-1.8.2.tgz#3cd24bba7333a5e05cb7db3ac206d7bcec079630"
12245+
integrity sha512-ukBkcNekOgwtnSWYLD5QsMX3yQWg7JviAs8zg3qJGgu4LGtY3tsV4G6vnqvOXIDkbC+XL9vbhObWSpRA5/6wbg==
12246+
dependencies:
12247+
chokidar "^3.5.3"
12248+
commander "^9.0.0"
12249+
globby "^11.0.4"
12250+
mylas "^2.1.9"
12251+
normalize-path "^3.0.0"
12252+
plimit-lit "^1.2.6"
12253+
1222512254
tsconfig-paths@^3.14.1:
1222612255
version "3.14.1"
1222712256
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a"

0 commit comments

Comments
 (0)