Skip to content

Commit

Permalink
Merge pull request #1 from prisma/master
Browse files Browse the repository at this point in the history
rebase
  • Loading branch information
zjye authored Apr 29, 2019
2 parents 55aa82b + d6496ab commit c702a57
Show file tree
Hide file tree
Showing 7 changed files with 2,624 additions and 1,929 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '9'
- '10'
- '8'
- '6'

Expand Down
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Graphcool, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# serverless-plugin-typescript
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![npm version](https://badge.fury.io/js/serverless-plugin-typescript.svg)](https://badge.fury.io/js/serverless-plugin-typescript) [![Build Status](https://travis-ci.org/graphcool/serverless-plugin-typescript.svg?branch=master)](https://travis-ci.org/graphcool/serverless-plugin-typescript)
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) [![npm version](https://badge.fury.io/js/serverless-plugin-typescript.svg)](https://badge.fury.io/js/serverless-plugin-typescript) [![Build Status](https://travis-ci.org/prisma/serverless-plugin-typescript.svg?branch=master)](https://travis-ci.org/prisma/serverless-plugin-typescript)

Serverless plugin for zero-config Typescript support

Expand Down Expand Up @@ -163,8 +163,9 @@ module.exports = {
}
```

## Help & Community [![Slack Status](https://slack.graph.cool/badge.svg)](https://slack.graph.cool)
## Help & Community

Join our [Slack community](http://slack.graph.cool/) if you run into issues or have questions. We love talking to you!
Join our [Spectrum community](http://spectrum.chat/prisma) if you run into issues or have questions. We love talking to you!

<p align="center"><a href="https://oss.prisma.io"><img src="https://imgur.com/IMU2ERq.png" alt="Prisma" height="170px"></a></p>

![](http://i.imgur.com/5RHR6Ku.png)
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"devDependencies": {
"@types/lodash": "4.14.91",
"@types/node": "^11.13.0",
"serverless-plugin-typescript": "1.1.5"
}
}
37 changes: 20 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "serverless-plugin-typescript",
"version": "0.0.0-semantic-release",
"license": "MIT",
"main": "dist/src/index.js",
"files": [
"dist",
Expand All @@ -10,14 +11,14 @@
"scripts": {
"prepublish": "npm run build",
"precommit": "npm run test",
"build": "rm -rf dist && tsc",
"build": "rimraf dist && tsc",
"pretest": "npm run lint",
"test": "jest",
"lint": "tslint -c tslint.json 'src/**/*.ts'"
},
"repository": {
"type": "git",
"url": "git+https://github.com/graphcool/serverless-plugin-typescript.git"
"url": "git+https://github.com/prisma/serverless-plugin-typescript.git"
},
"keywords": [
"serverless",
Expand All @@ -26,25 +27,27 @@
"aws lambda"
],
"devDependencies": {
"@types/fs-extra": "5.0.0",
"@types/jest": "22.0.1",
"@types/lodash": "4.14.91",
"jest": "22.0.4",
"mock-fs": "4.4.2",
"ts-jest": "22.0.1",
"tslint": "5.8.0"
"@types/fs-extra": "5.0.5",
"@types/jest": "24.0.11",
"@types/lodash": "4.14.123",
"jest": "24.5.0",
"mock-fs": "4.8.0",
"rimraf": "^2.6.3",
"ts-jest": "24.0.1",
"tslint": "5.14.0",
"typescript": "^3.4.1"
},
"dependencies": {
"fs-extra": "^5.0.0",
"globby": "^7.0.0",
"lodash": "^4.17.4",
"typescript": "^2.2.2"
"fs-extra": "^7.0.1",
"globby": "^9.2.0",
"lodash": "^4.17.11"
},
"peerDependencies": {
"typescript": ">=2.2.2"
},
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"preset": "ts-jest",
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.ts$",
"moduleFileExtensions": [
"ts",
"tsx",
Expand Down
32 changes: 26 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,17 @@ export class TypeScriptPlugin {
}

async copyExtras() {
// include node_modules into build
if (!fs.existsSync(path.resolve(path.join(buildFolder, 'node_modules')))) {
fs.symlinkSync(path.resolve('node_modules'), path.resolve(path.join(buildFolder, 'node_modules')))
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')
}

// include package.json into build so Serverless can exlcude devDeps during packaging
if (!fs.existsSync(path.resolve(path.join(buildFolder, 'package.json')))) {
fs.symlinkSync(path.resolve('package.json'), path.resolve(path.join(buildFolder, 'package.json')))
if (!fs.existsSync(outPkgPath)) {
await this.linkOrCopy(path.resolve('package.json'), outPkgPath, 'file')
}

// include any "extras" from the "include" section
Expand Down Expand Up @@ -209,6 +212,23 @@ export class TypeScriptPlugin {
fs.removeSync(path.join(this.originalServicePath, buildFolder))
}

/**
* Attempt to symlink a given path or directory and copy if it fails with an
* `EPERM` error.
*/
private async linkOrCopy(
srcPath: string,
dstPath: string,
type?: 'dir' | 'junction' | 'file'
): Promise<void> {
return fs.symlink(srcPath, dstPath, type)
.catch(error => {
if (error.code === 'EPERM' && error.errno === -4048) {
return fs.copy(srcPath, dstPath)
}
throw error
})
}
}

module.exports = TypeScriptPlugin
Loading

0 comments on commit c702a57

Please sign in to comment.