serverless-plugin-typescript icon indicating copy to clipboard operation
serverless-plugin-typescript copied to clipboard

feat: make tsconfig include files complied into serverless too

Open likeconan opened this issue 6 years ago • 5 comments

Hi,

This pr fixed issues that tsconfig include files to watch and compile. Please have a look at it and hope this obeys how to contribute.

Reference issues are Issue 188, Issue 105

likeconan avatar Nov 24 '19 09:11 likeconan

@JackCuthbert @divyenduz can this be merged? Are you looking for maintainers? So many great PRs coming in but the repo seems dead for 6+ months.

aalimovs avatar Feb 13 '20 14:02 aalimovs

Is this repo unmaintained? I need this PR too!

ekremkenter avatar May 07 '20 19:05 ekremkenter

I need this feature too!

jpbalarini avatar Dec 16 '20 15:12 jpbalarini

Yikes. 49 pull requests just sitting. Time for a fork?

bfaulk96 avatar Jul 19 '21 22:07 bfaulk96

still waiting on this feature, would be nice to be able to include files so they can be compiled without needing to manually import them as it defeats the purpose of having dynamic importing for ease of use

gobboo avatar Jun 24 '22 13:06 gobboo

Wow this saved the day for me! This seriously needs to be merged, but for now I looked at the commits and made my own local patch. Who is maintaining this repo?

colin-oos avatar May 19 '23 17:05 colin-oos

Applied this locally on the most recent version of this plugin and it fixed my issue with my dynamic import. Would be great to see this merged.

cc. @medikoo

If you're having this issue, as of v2.1.4, you can do the following:

Create a file patches/serverless-plugin-typescript-patch.diff

diff --git a/dist/src/index.js b/dist/src/index.js
index 0fd199c..0dd4460 100644
--- a/dist/src/index.js
+++ b/dist/src/index.js
@@ -107,7 +107,7 @@ class TypeScriptPlugin {
         return nodeFunctions;
     }
     get rootFileNames() {
-        return typescript.extractFileNames(this.originalServicePath, this.serverless.service.provider.name, this.functions);
+        return _.union(typescript.extractFileNames(this.originalServicePath, this.serverless.service.provider.name, this.functions), typescript.getTypescriptCompileFiles(this.originalServicePath));
     }
     prepare() {
         // exclude serverless-plugin-typescript
diff --git a/dist/src/typescript.js b/dist/src/typescript.js
index e8145b2..8c7fe7a 100644
--- a/dist/src/typescript.js
+++ b/dist/src/typescript.js
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
     });
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.getTypescriptConfig = exports.getSourceFiles = exports.run = exports.extractFileNames = exports.makeDefaultTypescriptConfig = void 0;
+exports.getTypescriptCompileFiles = exports.getTypescriptConfig = exports.getSourceFiles = exports.run = exports.extractFileNames = exports.makeDefaultTypescriptConfig = void 0;
 const ts = require("typescript");
 const fs = require("fs-extra");
 const _ = require("lodash");
@@ -136,4 +136,21 @@ function getTypescriptConfig(cwd, tsConfigFileLocation = 'tsconfig.json', logger
     return makeDefaultTypescriptConfig();
 }
 exports.getTypescriptConfig = getTypescriptConfig;
+function getTypescriptCompileFiles(cwd) {
+    const configFilePath = path.join(cwd, 'tsconfig.json');
+    if (fs.existsSync(configFilePath)) {
+        const configFileText = fs.readFileSync(configFilePath).toString();
+        const result = ts.parseConfigFileTextToJson(configFilePath, configFileText);
+        if (result.error) {
+            throw new Error(JSON.stringify(result.error));
+        }
+        const configParseResult = ts.parseJsonConfigFileContent(result.config, ts.sys, path.dirname(configFilePath));
+        if (configParseResult.errors.length > 0) {
+            throw new Error(JSON.stringify(configParseResult.errors));
+        }
+        return configParseResult.fileNames.map(f => f.replace(cwd + '/', ''));
+    }
+    return [];
+}
+exports.getTypescriptCompileFiles = getTypescriptCompileFiles;
 //# sourceMappingURL=typescript.js.map
\ No newline at end of file
-- 
2.38.1

In your project's package.json, you can add

"scripts": {
    "postinstall": "cd node_modules/serverless-plugin-typescript && patch -p1 < ../../patches/serverless-plugin-typescript-patch.diff"
}

This will patch the module during your npm/yarn install.

jsifuentes avatar Jun 05 '23 02:06 jsifuentes

It's merged and released now

medikoo avatar Jun 05 '23 10:06 medikoo