Skip to content
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

Open
please-rewrite opened this issue Feb 24, 2022 · 1 comment
Open

Can't use with node 12 due to optional chaining #37

please-rewrite opened this issue Feb 24, 2022 · 1 comment

Comments

@please-rewrite
Copy link

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.

@eunchurn
Copy link

eunchurn commented Jun 30, 2022

I made this patch for node version under 14.

use patch-pacakge make patch file in patches/tsc-hooks+1.1.1.patch as below

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 package.json

"scripts": {
  "postinstall": "patch-package"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants