Skip to content

Commit

Permalink
fix(nextjs-component): serverless-patched binary should include @serv…
Browse files Browse the repository at this point in the history
…erless/cli and find serverless binary in closest node_modules (#1661)
  • Loading branch information
dphang committed Sep 9, 2021
1 parent 3a4fd5d commit d7057ba
Show file tree
Hide file tree
Showing 13 changed files with 4,545 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"babel.config.js",
"jest.config.js",
"<rootDir>/packages/serverless-components/aws-s3",
"<rootDir>/packages/serverless-components/nextjs-component/bin"
"<rootDir>/packages/libs/serverless-patched"
],
"watchPathIgnorePatterns": [
"/fixture/",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/test-utils/scripts/run-e2e-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async function runEndToEndTest(): Promise<boolean> {
// Deploy
console.info("Deploying serverless-next.js app.");
execSync(
"node ../../serverless-components/nextjs-component/dist/bin/serverless-patched.js --debug",
"node ../../libs/serverless-patched/dist/serverless-patched.js --debug",
{ stdio: "inherit" }
);

Expand Down
1 change: 1 addition & 0 deletions packages/libs/serverless-patched/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry "https://registry.npmjs.org"
1 change: 1 addition & 0 deletions packages/libs/serverless-patched/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Patched serverless binary
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/usr/bin/env node

import { execSync } from "child_process";
const findUpSync = require("find-up").sync;

console.info("Note: running patched serverless binary.");

const args = process.argv.slice(2).join(" ");
// This executes package-local serverless which uses a patched @serverless/cli
execSync(`${__dirname}/../../node_modules/.bin/serverless ${args}`, {
// Try to find the closest serverless binary which should be patched
const serverlessBin = findUpSync("node_modules/.bin/serverless", {
cwd: __dirname
});

execSync(`${serverlessBin} ${args}`, {
stdio: "inherit"
});
50 changes: 50 additions & 0 deletions packages/libs/serverless-patched/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@sls-next/serverless-patched",
"version": "3.4.0-alpha.2",
"description": "Patched serverless package",
"publishConfig": {
"access": "public"
},
"main": "dist/serverless-patched.js",
"directories": {
"dist": "dist"
},
"repository": {
"type": "git",
"url": "git+https://github.com/serverless-nextjs/serverless-next.js.git",
"directory": "packages/libs/serverless-patched"
},
"scripts": {
"prepare": "yarn clean && yarn build",
"build": "tsc -p tsconfig.build.json",
"clean": "yarn rimraf dist",
"postinstall": "patch-package"
},
"keywords": [
"AWS",
"S3",
"Next.js",
"Serverless"
],
"author": "Daniel Phang <serverlessnextjs@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/serverless-nextjs/serverless-next.js/issues"
},
"homepage": "https://github.com/serverless-nextjs/serverless-next.js#readme",
"dependencies": {
"@serverless/cli": "^1.5.2",
"find-up": "^5.0.0",
"patch-package": "^6.4.7",
"postinstall-postinstall": "^2.1.0",
"serverless": "^2.57.0"
},
"devDependencies": {
"@types/node": "^16.9.1",
"rimraf": "^3.0.2",
"typescript": "^4.4.2"
},
"bin": {
"serverless-patched": "./dist/serverless-patched.js"
}
}
8 changes: 8 additions & 0 deletions packages/libs/serverless-patched/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"sourceMap": false,
"removeComments": true
},
"include": ["./bin/"]
}
17 changes: 17 additions & 0 deletions packages/libs/serverless-patched/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"resolveJsonModule": true,
"esModuleInterop": true,
"declaration": true,
"target": "ES2015",
"module": "CommonJS",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "dist",
"sourceMap": true,
"strict": true,
"allowJs": true
},
"exclude": ["node_modules"],
"include": ["**/*.ts"]
}

0 comments on commit d7057ba

Please sign in to comment.