Created
September 29, 2022 21:02
-
-
Save UberMouse/edf8bede31c3a104b136fc0a47737d61 to your computer and use it in GitHub Desktop.
This file contains 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
const { promisify } = require("util"); | |
const { exec: _exec } = require("child_process"); | |
const { resolve } = require("path"); | |
const exec = promisify(_exec); | |
const PLUGIN_NAME = "FixTsconfigPathsPlugin"; | |
class FixTsconfigPathsPlugin { | |
pluginName = PLUGIN_NAME; | |
apply(heftSession, heftConfiguration) { | |
const logger = heftSession.requestScopedLogger("fix-tsconfig-paths"); | |
heftSession.hooks.build.tap(PLUGIN_NAME, (build) => { | |
build.hooks.compile.tap(PLUGIN_NAME, (compile) => { | |
compile.hooks.afterCompile.tapPromise(PLUGIN_NAME, async () => { | |
const fixerBin = resolve(__dirname, "node_modules", ".bin", "tsconfig-replace-paths"); | |
const tsconfigPath = resolve(heftConfiguration.buildFolder, "tsconfig.json"); | |
const args = [ | |
"--project", tsconfigPath, | |
"--out", resolve(heftConfiguration.buildFolder, "dist"), | |
"--src", resolve(heftConfiguration.buildFolder, "src") | |
]; | |
const tsconfig = require(tsconfigPath); | |
if (tsconfig && tsconfig.compilerOptions && tsconfig.compilerOptions.paths) { | |
await exec(`${fixerBin} ${args.join(" ")}`, { | |
cwd: __dirname, | |
}); | |
args[3] = resolve(heftConfiguration.buildFolder, "dist-cjs"); | |
await exec(`${fixerBin} ${args.join(" ")}`, { | |
cwd: __dirname, | |
}); | |
} | |
}); | |
}); | |
}); | |
} | |
} | |
module.exports = new FixTsconfigPathsPlugin(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment