-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use with node 12 due to optional chaining #37
Comments
I made this patch for node version under 14. use diff --git a/node_modules/tsc-hooks/hooks/copy-files/copy-files.hook.js b/node_modules/tsc-hooks/hooks/copy-files/copy-files.hook.js
index 74fa992..69621b3 100644
--- a/node_modules/tsc-hooks/hooks/copy-files/copy-files.hook.js
+++ b/node_modules/tsc-hooks/hooks/copy-files/copy-files.hook.js
@@ -8,9 +8,9 @@ module.exports = {
const path = require('path');
const fs = require('fs');
const glob = require('glob');
- const cwd = api.tsconfig?.compilerOptions?.rootDir || api.tsconfig.directory;
+ const cwd = api.tsconfig && api.tsconfig.compilerOptions && api.tsconfig.compilerOptions.rootDir || api.tsconfig.directory;
const rootRegex = /^([^\/|\\])+/;
- const outDir = api.tsconfig?.compilerOptions?.outDir;
+ const outDir = api.tsconfig && api.tsconfig.compilerOptions && api.tsconfig.compilerOptions.outDir;
// Add included files from config
const includedFiles = new Set();
@@ -34,7 +34,7 @@ module.exports = {
const outFile = outDir ? file.replace(rootRegex, outDir) : file;
if (fs.lstatSync(file).isDirectory()) {
fs.mkdirSync(outFile, { recursive: true });
- } else if (!file.endsWith('js') || !(file.endsWith('ts') && !api.tsconfig?.compilerOptions?.allowTs)) {
+ } else if (!file.endsWith('js') || !(file.endsWith('ts') && !(api.tsconfig && api.tsconfig.compilerOptions && api.tsconfig.compilerOptions.allowTs))) {
fs.copyFileSync(file, outFile);
}
}
diff --git a/node_modules/tsc-hooks/lib/injection.js b/node_modules/tsc-hooks/lib/injection.js
index 1eadf17..680527c 100644
--- a/node_modules/tsc-hooks/lib/injection.js
+++ b/node_modules/tsc-hooks/lib/injection.js
@@ -50,8 +50,8 @@ if (fs.existsSync(tsconfigPath)) {
// Call each hook
for (const hookModule of hookModules || []) {
- hookModule?.onInitCompilation?.(api);
- process.on('exit', () => hookModule?.onPostCompilation?.(api));
+ hookModule && hookModule.onInitCompilation && hookModule.onInitCompilation(api);
+ process.on('exit', () => hookModule && hookModule.onInitCompilation && hookModule.onInitCompilation(api));
}
// Hooks may mutate the config, so write the original config back in "scripts": {
"postinstall": "patch-package"
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there any chance you could transpile this down to cjs?
Currently only works for node 14+ due to using optional chaining throughout the code.
The text was updated successfully, but these errors were encountered: