Skip to content

Commit

Permalink
Add support for tsx files
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Oct 20, 2022
1 parent de811f4 commit 6d0fef7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Serverless Plugin Neo Changelog

## 0.2.1 - October 20, 2022

- Add support for tsx files

## 0.2.0 - April 25, 2022

- Improve error handling when linking dependencies
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "serverless-plugin-neo",
"description": "Serverless plugin that compiles TypeScript code and bundles dependencies with node-file-trace",
"version": "0.2.0",
"version": "0.2.1",
"author": "Neo Financial Engineering <[email protected]>",
"license": "MIT",
"repository": {
Expand Down
20 changes: 19 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,41 +77,57 @@ export class NeoPlugin {

this.hooks = {
'before:run:run': async (): Promise<void> => {
this.log.debug('before:run:run');

await this.compileTypeScript();
await this.copyExtras();
await this.copyDependencies();
},
'before:offline:start': async (): Promise<void> => {
this.log.debug('before:offline:start');

await this.compileTypeScript();
await this.copyExtras();
await this.copyDependencies();
this.watchAll();
},
'before:offline:start:init': async (): Promise<void> => {
this.log.debug('before:offline:start:init');

await this.compileTypeScript();
await this.copyExtras();
await this.copyDependencies();
this.watchAll();
},
'before:package:createDeploymentArtifacts': async (): Promise<void> => {
this.log.debug('before:package:createDeploymentArtifacts');

await this.compileTypeScript();
await this.copyExtras();
await this.copyDependencies();
},
'after:package:createDeploymentArtifacts': async (): Promise<void> => {
this.log.debug('after:package:createDeploymentArtifacts');

await this.moveArtifacts();
await this.cleanup();
},
'before:deploy:function:packageFunction': async (): Promise<void> => {
this.log.debug('before:deploy:function:packageFunction');

await this.compileTypeScript();
await this.copyExtras();
await this.copyDependencies();
},
'after:deploy:function:packageFunction': async (): Promise<void> => {
this.log.debug('after:deploy:function:packageFunction');

await this.moveArtifacts();
await this.cleanup();
},
'before:invoke:local:invoke': async (): Promise<void> => {
this.log.debug('before:invoke:local:invoke');

const emittedFiles = await this.compileTypeScript();

await this.copyExtras();
Expand All @@ -126,6 +142,8 @@ export class NeoPlugin {
}
},
'after:invoke:local:invoke': async (): Promise<void> => {
this.log.debug('after:invoke:local:invoke');

if (this.options.watch) {
await this.watchFunction();
}
Expand Down Expand Up @@ -172,7 +190,7 @@ export class NeoPlugin {
return;
}

this.log.info(`Watching TypeScript files...`);
this.log.info('Watching TypeScript files...');

this.isWatching = true;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const addDirectory = async (
const files = await recursiveReaddir(path.join(baseDir, path.dirname(dependency), dirname));

for (const file of files) {
if (file.endsWith('.ts') || file.endsWith('.map')) {
if (file.endsWith('.ts') || file.endsWith('.tsx') || file.endsWith('.map')) {
continue;
}

Expand Down
15 changes: 13 additions & 2 deletions src/lib/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const extractFilenames = (
continue;
}

// Check if the .tsx files exists. If so return that to watch
if (fs.existsSync(path.join(cwd, `${fileName}tsx`))) {
files.push(`${fileName}tsx`);

continue;
}

// Check if the .js files exists. If so return that to watch
if (fs.existsSync(path.join(cwd, `${fileName}js`))) {
files.push(`${fileName}js`);
Expand All @@ -41,13 +48,17 @@ const extractFilenames = (
// Can't find the files. Watch will have an exception anyway. So throw one with error.
log?.error(`Cannot locate handler: ${fileName} not found`);

throw new Error('TypeScript compilation failed. Please ensure handlers exist with a .ts or .js extension');
throw new Error(
'TypeScript compilation failed. Please ensure handlers exist with a .ts, .tsx or .js extension'
);
}

// Can't find the files. Watch will have an exception anyway. So throw one with error.
log?.error('Cannot locate handler');

throw new Error('TypeScript compilation failed. Please ensure handlers exist with a ext .ts or .js extension');
throw new Error(
'TypeScript compilation failed. Please ensure handlers exist with a ext .ts, .tsx or .js extension'
);
}
}

Expand Down

0 comments on commit 6d0fef7

Please sign in to comment.