Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
.serverless
dist
*.log
.vscode
package-lock.json
16 changes: 13 additions & 3 deletions src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k
const packageFile = JSON.parse(fs.readFileSync(packageFilePath).toString())

// Either grab the package.json:main field, or use the index.ts file.
// (This will be transpiled to index.js).
const main = packageFile.main ? packageFile.main.replace(/\.js$/, '.ts') : 'index.ts'
// (This will be transpiled to index.js or index.mjs).
const main = packageFile.main ? packageFile.main.replace(/\.mjs$/, '.mts').replace(/\.js$/, '.ts') : 'index.ts'

// Check that the file indeed exists.
if (!fs.existsSync(path.join(cwd, main))) {
Expand Down Expand Up @@ -64,9 +64,19 @@ export function extractFileNames(cwd: string, provider: string, functions?: { [k
return fileName + 'js'
}

// Check if the .mts files exists. If so return that to watch
if (fs.existsSync(path.join(cwd, fileName + 'mts'))) {
return fileName + 'mts'
}

// Check if the .mjs files exist. If so return that to watch
if (fs.existsSync(path.join(cwd, fileName + 'mjs'))) {
return fileName + 'mjs'
}

// Can't find the files. Watch will have an exception anyway. So throw one with error.
console.log(`Cannot locate handler - ${fileName} not found`)
throw new Error('Typescript compilation failed. Please ensure handlers exists with ext .ts or .js')
throw new Error('Typescript compilation failed. Please ensure handlers exists with ext .ts/.mts or .js/.mjs')
})
}

Expand Down