Skip to content

Commit

Permalink
Merge pull request #1258 from magelle/add-yarn-workspaces-support
Browse files Browse the repository at this point in the history
Add yarn workspaces support
  • Loading branch information
j0k3r authored Oct 21, 2022
2 parents f219462 + 7391ff8 commit 1a6c72f
Show file tree
Hide file tree
Showing 13 changed files with 4,623 additions and 19 deletions.
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 });
};
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": {
}
}
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 });
};
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"
}
}
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
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
};
Loading

0 comments on commit 1a6c72f

Please sign in to comment.