Skip to content

Commit

Permalink
♻️(typescript) move tokens sources to absolute import
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NathanVss committed Jan 11, 2023
1 parent 7a61402 commit 3e98429
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 16 deletions.
7 changes: 6 additions & 1 deletion packages/tokens/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export default {
import type { JestConfigWithTsJest } from "ts-jest";

const jestConfig: JestConfigWithTsJest = {
preset: "ts-jest",
testEnvironment: "node",
moduleDirectories: ["node_modules", "src/bin"],
};

export default jestConfig;
5 changes: 3 additions & 2 deletions packages/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"scripts": {
"lint": "eslint . 'src/**/*.{ts,tsx}'",
"dev": "nodemon --watch 'src/bin' --ext '*' --exec 'yarn build'",
"build": "tsc -p tsconfig.json && cp src/bin/cunningham.dist.js dist/bin && chmod +x dist/bin/Main.js && yarn build-default-theme",
"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",
"build-default-theme": "./dist/bin/Main.js -o dist -s html",
"test": "FORCE_COLOR=1 jest --verbose src/bin/tests"
},
"dependencies": {
"chalk": "4.1.2",
"commander": "9.4.1",
"deepmerge": "4.2.2",
"figlet": "1.5.2"
"figlet": "1.5.2",
"tsc-alias": "^1.8.2"
},
"devDependencies": {
"@types/figlet": "1.5.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/tokens/src/bin/ConfigLoader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from "path";
import * as fs from "fs";
import deepmerge from "deepmerge";
import { ConfigShape } from "TokensGenerator";
import { workPath } from "Paths";
import Config from "./Config";
import { ConfigShape } from "./TokensGenerator";
import { workPath } from "./Paths";

const getLocalConfig = async () => {
const filename = Config.configurationFilenames
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as path from "path";
import * as fs from "fs";
import chalk from "chalk";
import Config from "./Config";
import { flatify } from "./Utils/Flatify";
import { flatify } from "Utils/Flatify";
import Config from "Config";

export const cssGenerator = async (
tokens: any,
Expand Down
2 changes: 1 addition & 1 deletion packages/tokens/src/bin/Main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

import { run } from "./ThemeGenerator";
import { run } from "ThemeGenerator";

run(process.argv);
8 changes: 4 additions & 4 deletions packages/tokens/src/bin/ThemeGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { program } from "commander";
import chalk from "chalk";
import figlet from "figlet";
import { getConfig } from "./ConfigLoader";
import { tokensGenerator } from "./TokensGenerator";
import { cssGenerator } from "./CssGenerator";
import { workPath } from "./Paths";
import { cssGenerator } from "Generators/CssGenerator";
import { getConfig } from "ConfigLoader";
import { tokensGenerator } from "TokensGenerator";
import { workPath } from "Paths";

export const buildTheme = async () => {
const options = program.opts();
Expand Down
2 changes: 1 addition & 1 deletion packages/tokens/src/bin/tests/Cunningham.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs";
import * as path from "path";
import { run } from "../ThemeGenerator";
import { run } from "ThemeGenerator";
import Config from "../Config";

jest.mock("../Paths", () => ({
Expand Down
4 changes: 4 additions & 0 deletions packages/tokens/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
],
"compilerOptions": {
"baseUrl": "./src/bin",
"paths": {
"*": ["*"]
},
"resolveJsonModule": true,
"outDir": "./dist/bin",
}
}
35 changes: 32 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4871,7 +4871,7 @@ check-error@^1.0.2:
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
integrity sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==

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

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

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

mylas@^2.1.9:
version "2.1.13"
resolved "https://registry.yarnpkg.com/mylas/-/mylas-2.1.13.tgz#1e23b37d58fdcc76e15d8a5ed23f9ae9fc0cbdf4"
integrity sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==

nan@^2.12.1:
version "2.17.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb"
Expand Down Expand Up @@ -10236,6 +10241,13 @@ pkg-types@^1.0.0:
mlly "^1.0.0"
pathe "^1.0.0"

plimit-lit@^1.2.6:
version "1.5.0"
resolved "https://registry.yarnpkg.com/plimit-lit/-/plimit-lit-1.5.0.tgz#f66df8a7041de1e965c4f1c0697ab486968a92a5"
integrity sha512-Eb/MqCb1Iv/ok4m1FqIXqvUKPISufcjZ605hl3KM/n8GaX8zfhtgdLwZU3vKjuHGh2O9Rjog/bHTq8ofIShdng==
dependencies:
queue-lit "^1.5.0"

[email protected]:
version "1.6.4"
resolved "https://registry.yarnpkg.com/pnp-webpack-plugin/-/pnp-webpack-plugin-1.6.4.tgz#c9711ac4dc48a685dabafc86f8b6dd9f8df84149"
Expand Down Expand Up @@ -10584,6 +10596,11 @@ querystringify@^2.1.1:
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6"
integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==

queue-lit@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/queue-lit/-/queue-lit-1.5.0.tgz#8197fdafda1edd615c8a0fc14c48353626e5160a"
integrity sha512-IslToJ4eiCEE9xwMzq3viOO5nH8sUWUCwoElrhNMozzr9IIt2qqvB4I+uHu/zJTQVqc9R5DFwok4ijNK1pU3fA==

queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
Expand Down Expand Up @@ -12222,6 +12239,18 @@ ts-pnp@^1.1.6:
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==

tsc-alias@^1.8.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/tsc-alias/-/tsc-alias-1.8.2.tgz#3cd24bba7333a5e05cb7db3ac206d7bcec079630"
integrity sha512-ukBkcNekOgwtnSWYLD5QsMX3yQWg7JviAs8zg3qJGgu4LGtY3tsV4G6vnqvOXIDkbC+XL9vbhObWSpRA5/6wbg==
dependencies:
chokidar "^3.5.3"
commander "^9.0.0"
globby "^11.0.4"
mylas "^2.1.9"
normalize-path "^3.0.0"
plimit-lit "^1.2.6"

tsconfig-paths@^3.14.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a"
Expand Down

0 comments on commit 3e98429

Please sign in to comment.