-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1258 from magelle/add-yarn-workspaces-support
Add yarn workspaces support
- Loading branch information
Showing
13 changed files
with
4,623 additions
and
19 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
examples/include-external-npm-packages-with-yarn-workspaces/_setup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
module.exports = async (originalFixturePath, fixturePath, utils) => { | ||
const pluginPath = path.resolve(originalFixturePath, '..', '..'); | ||
|
||
const SLS_CONFIG_PATH = path.join(fixturePath, 'packages', 'project', 'serverless.yml'); | ||
const WEBPACK_CONFIG_PATH = path.join(fixturePath, 'packages', 'project', 'webpack.config.js'); | ||
const PACKAGE_JSON_PATH = path.join(fixturePath, 'packages', 'project', 'package.json'); | ||
const LOCK_PATH = path.join(fixturePath, 'yarn.lock'); | ||
|
||
await Promise.all([ | ||
utils.replaceInFile(SLS_CONFIG_PATH, '- serverless-webpack', `- ${pluginPath}`), | ||
utils.replaceInFile(WEBPACK_CONFIG_PATH, "'serverless-webpack'", `'${pluginPath}'`), | ||
utils.replaceInFile(PACKAGE_JSON_PATH, 'file:../..', `file:${pluginPath}`), | ||
utils.replaceInFile(LOCK_PATH, '../..', `${pluginPath}`) | ||
]); | ||
|
||
const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn'; | ||
|
||
return utils.spawnProcess(command, ['install'], { cwd: __dirname }); | ||
}; |
21 changes: 21 additions & 0 deletions
21
examples/include-external-npm-packages-with-yarn-workspaces/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "include-external-npm-packages-with-yarn-workspaces", | ||
"version": "1.0.0", | ||
"description": "Serverless webpack example", | ||
"main": "handler.js", | ||
"private": true, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Tony Yuen <[email protected]>", | ||
"license": "MIT", | ||
"workspaces": { | ||
"packages": [ | ||
"./packages/*" | ||
] | ||
}, | ||
"devDependencies": { | ||
}, | ||
"dependencies": { | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/include-external-npm-packages-with-yarn-workspaces/packages/project/handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Should keep side-effects scripts | ||
import 'dotenv/config'; | ||
// Should be included as fbgraph is not marked as sideEffect free | ||
// Should keep named imports | ||
import { toUpper, isEqual } from 'lodash'; | ||
// Should keep default imports | ||
|
||
function getMessage() { | ||
return isEqual(true, false) ? 'noop' : toUpper('hello fb & aws'); | ||
} | ||
|
||
export const hello = function (event, context, cb) { | ||
const message = getMessage(); | ||
cb(null, { message, event }); | ||
}; |
26 changes: 26 additions & 0 deletions
26
examples/include-external-npm-packages-with-yarn-workspaces/packages/project/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "include-external-npm-packages-with-yarn-workspaces-subproject", | ||
"version": "1.0.0", | ||
"description": "Serverless webpack example", | ||
"main": "handler.js", | ||
"private": true, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Tony Yuen <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"aws-sdk": "^2.814.0", | ||
"serverless": "^3.7.4", | ||
"serverless-offline": "^8.8.1", | ||
"serverless-webpack": "file:../..", | ||
"webpack": "^5.74.0", | ||
"webpack-node-externals": "^2.5.0" | ||
}, | ||
"dependencies": { | ||
"dotenv": "^16.0.0", | ||
"fbgraph": "^1.4.4", | ||
"lodash": "^4.17.21", | ||
"lodash.isequal": "^4.5.0" | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/include-external-npm-packages-with-yarn-workspaces/packages/project/serverless.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
service: include-external-npm-packages-with-yarn-workspaces | ||
|
||
# Add the serverless-webpack plugin | ||
plugins: | ||
- serverless-webpack | ||
- serverless-offline | ||
|
||
provider: | ||
name: aws | ||
runtime: nodejs12.x | ||
|
||
custom: | ||
webpack: | ||
webpackConfig: 'webpack.config.js' | ||
packager: 'yarn' | ||
includeModules: | ||
forceInclude: | ||
- lodash | ||
|
||
functions: | ||
first: | ||
handler: handler.hello | ||
events: | ||
- http: | ||
method: GET | ||
path: first | ||
integration: lambda |
9 changes: 9 additions & 0 deletions
9
...les/include-external-npm-packages-with-yarn-workspaces/packages/project/webpack.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const slsw = require('serverless-webpack'); | ||
const nodeExternals = require('webpack-node-externals'); | ||
|
||
module.exports = { | ||
entry: slsw.lib.entries, | ||
mode: slsw.lib.webpack.isLocal ? 'development' : 'production', | ||
target: 'node', | ||
externals: [nodeExternals()] // exclude external modules | ||
}; |
Oops, something went wrong.