serverless-plugin-typescript
serverless-plugin-typescript copied to clipboard
feat: make tsconfig include files complied into serverless too
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.
@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.
Is this repo unmaintained? I need this PR too!
I need this feature too!
Yikes. 49 pull requests just sitting. Time for a fork?
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
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?
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.
It's merged and released now