Skip to content

Fix: Don't packaging devDependencies. #157

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

Closed
wants to merge 2 commits into from
Closed
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
27 changes: 19 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ export class TypeScriptPlugin {
await this.compileTs()
this.watchAll()
},
'before:package:createDeploymentArtifacts': this.compileTs.bind(this),
'before:package:createDeploymentArtifacts': async () => {
await this.compileTs(true)
},
'after:package:createDeploymentArtifacts': this.cleanup.bind(this),
'before:deploy:function:packageFunction': this.compileTs.bind(this),
'before:deploy:function:packageFunction': async () => {
await this.compileTs(true)
},
'after:deploy:function:packageFunction': this.cleanup.bind(this),
'before:invoke:local:invoke': async () => {
const emitedFiles = await this.compileTs()
Expand Down Expand Up @@ -111,7 +115,7 @@ export class TypeScriptPlugin {
})
}

async compileTs(): Promise<string[]> {
async compileTs(packaging = false): Promise<string[]> {
this.prepare()
this.serverless.cli.log('Compiling with Typescript...')

Expand All @@ -130,19 +134,26 @@ export class TypeScriptPlugin {
tsconfig.outDir = buildFolder

const emitedFiles = await typescript.run(this.rootFileNames, tsconfig)
await this.copyExtras()
await this.copyExtras(packaging)
this.serverless.cli.log('Typescript compiled.')
return emitedFiles
}

async copyExtras() {
async copyExtras(packaging = false) {
const outPkgPath = path.resolve(path.join(buildFolder, 'package.json'))
const outModulesPath = path.resolve(path.join(buildFolder, 'node_modules'))

// Link or copy node_modules and package.json to .build so Serverless can
// exlcude devDeps during packaging
if (!fs.existsSync(outModulesPath)) {
await this.linkOrCopy(path.resolve('node_modules'), outModulesPath, 'junction')
// exclude devDeps during packaging
if (packaging) {
if (fs.existsSync(path.resolve(path.join(buildFolder, 'node_modules')))) {
fs.unlinkSync(path.resolve(path.join(buildFolder, 'node_modules')))
}
fs.copySync(path.resolve('node_modules'), path.resolve(path.join(buildFolder, 'node_modules')))
} else {
if (!fs.existsSync(outModulesPath)) {
await this.linkOrCopy(path.resolve('node_modules'), outModulesPath, 'junction')
}
}

if (!fs.existsSync(outPkgPath)) {
Expand Down