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

feat: make tsconfig include files complied into serverless too #190

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

likeconan
Copy link
Contributor

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

@aalimovs
Copy link

@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.

@ekremkenter
Copy link

Is this repo unmaintained? I need this PR too!

@likeconan likeconan changed the title make tsconfig include files complied into serverless too feat: make tsconfig include files complied into serverless too May 7, 2020
@jpbalarini
Copy link

I need this feature too!

@bfaulk96
Copy link

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

@gobboo
Copy link

gobboo commented Jun 24, 2022

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

@colin-oos
Copy link

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?

@jsifuentes
Copy link

jsifuentes commented Jun 5, 2023

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.

@medikoo medikoo added the bug label Jun 5, 2023
@medikoo medikoo merged commit 663cb2a into serverless:master Jun 5, 2023
@medikoo
Copy link
Contributor

medikoo commented Jun 5, 2023

It's merged and released now

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

Successfully merging this pull request may close these issues.

10 participants