From a6c22f9c8cd5deeec7104f9bef4517ff280cf3f2 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 15 Jun 2024 11:12:43 +0200 Subject: [PATCH] Make the linking script work on windows --- .github/release.yaml | 25 ---------------- scripts/link-in-app.ts | 68 ++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 64 deletions(-) delete mode 100644 .github/release.yaml diff --git a/.github/release.yaml b/.github/release.yaml deleted file mode 100644 index ae38baa..0000000 --- a/.github/release.yaml +++ /dev/null @@ -1,25 +0,0 @@ -changelog: - exclude: - labels: - - ignore-for-release - authors: - - octocat - categories: - - title: Breaking Changes 🛠 - labels: - - breaking - - title: Exciting New Features 🎉 - labels: - - feature - - title: Fixes 🔧 - labels: - - fix - - title: Documentation 🔧 - labels: - - docs - - title: CI 👷 - labels: - - ci - - title: Other Changes - labels: - - '*' \ No newline at end of file diff --git a/scripts/link-in-app.ts b/scripts/link-in-app.ts index d04018b..b72f5ae 100644 --- a/scripts/link-in-app.ts +++ b/scripts/link-in-app.ts @@ -1,6 +1,7 @@ import { execSync } from "child_process"; import { join as pathJoin, relative as pathRelative } from "path"; import * as fs from "fs"; +import * as os from "os"; const singletonDependencies: string[] = [ //"react", @@ -10,44 +11,31 @@ const singletonDependencies: string[] = [ const rootDirPath = pathJoin(__dirname, ".."); //NOTE: This is only required because of: https://github.com/garronej/ts-ci/blob/c0e207b9677523d4ec97fe672ddd72ccbb3c1cc4/README.md?plain=1#L54-L58 -fs.writeFileSync( - pathJoin(rootDirPath, "dist", "package.json"), - Buffer.from( - JSON.stringify( - (() => { - const packageJsonParsed = JSON.parse( - fs.readFileSync(pathJoin(rootDirPath, "package.json")).toString("utf8") - ); +//If you change the outDir in tsconfig.json you must update this block. +{ + let modifiedPackageJsonContent = fs + .readFileSync(pathJoin(rootDirPath, "package.json")) + .toString("utf8"); - return { - ...packageJsonParsed, - "main": packageJsonParsed["main"]?.replace(/^dist\//, ""), - "types": packageJsonParsed["types"]?.replace(/^dist\//, ""), - "module": packageJsonParsed["module"]?.replace(/^dist\//, ""), - "bin": !("bin" in packageJsonParsed) - ? undefined - : Object.fromEntries( - Object.entries(packageJsonParsed["bin"]).map(([key, value]) => [ - key, - (value as string).replace(/^dist\//, "") - ]) - ), - "exports": !("exports" in packageJsonParsed) - ? undefined - : Object.fromEntries( - Object.entries(packageJsonParsed["exports"]).map(([key, value]) => [ - key, - (value as string).replace(/^\.\/dist\//, "./") - ]) - ) - }; - })(), - null, - 2 - ), - "utf8" - ) -); + modifiedPackageJsonContent = (() => { + const o = JSON.parse(modifiedPackageJsonContent); + + delete o.files; + + return JSON.stringify(o, null, 2); + })(); + + modifiedPackageJsonContent = modifiedPackageJsonContent + .replace(/"dist\//g, '"') + .replace(/"\.\/dist\//g, '"./') + .replace(/"!dist\//g, '"!') + .replace(/"!\.\/dist\//g, '"!./'); + + fs.writeFileSync( + pathJoin(rootDirPath, "dist", "package.json"), + Buffer.from(modifiedPackageJsonContent, "utf8") + ); +} const commonThirdPartyDeps = (() => { // For example [ "@emotion" ] it's more convenient than @@ -85,9 +73,11 @@ const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => { execSync(cmd, { cwd, - "env": { + env: { ...process.env, - "HOME": yarnGlobalDirPath + ...(os.platform() === "win32" + ? { USERPROFILE: yarnGlobalDirPath } + : { HOME: yarnGlobalDirPath }) } }); };