-
Notifications
You must be signed in to change notification settings - Fork 77
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
[feat] include gasket-nextjs-plugin in monorepo #12
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bffd4d2
Adding nextjs-plugin
dsanudovacas 6e7420a
[fix] only load next in app lifecycles
agerard-godaddy 268399e
[doc] update descriptions
agerard-godaddy 61c5aa9
[merge] master
agerard-godaddy c227e17
[test] fix for hoisted modules
agerard-godaddy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,3 @@ | ||
{ | ||
"extends": "godaddy" | ||
} |
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 @@ | ||
package-lock.json binary |
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,69 @@ | ||
# Logs (npm-debug.log, yarn-error.log, etc) | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# OSX Finder cache files | ||
.DS_Store | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# Editor files | ||
.idea | ||
*.iml | ||
|
||
### ▲ .gitignore contents above | ||
### ▼ additional ignore files for publishing | ||
|
||
test/* | ||
.eslintrc | ||
.gitattributes |
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,11 @@ | ||
# CHANGELOG | ||
|
||
### 1.1.1 | ||
|
||
- Fix for missing dependency during create command | ||
|
||
### 1.1.0 | ||
|
||
- Renaming hooks and removing the `webpack` hook | ||
- Separate next plugins from core | ||
- Initial release. |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 GoDaddy Operating Company, LLC. | ||
|
||
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. |
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,129 @@ | ||
# @gasket/nextjs-plugin | ||
|
||
The `nextjs-plugin` adds `next` to your application. | ||
|
||
## Installation | ||
|
||
``` | ||
npm install --save @gasket/nextjs-plugin | ||
``` | ||
|
||
## Configuration | ||
|
||
The nextjs plugin is configured using the `gasket.config.js` file. | ||
|
||
- First, add it to the `plugins` section of your `gasket.config.js`: | ||
|
||
```js | ||
{ | ||
"plugins": [ | ||
"add": ["nextjs"] | ||
] | ||
} | ||
``` | ||
|
||
- Instead of adding a dedicated `next.config.js`, the `next` property within `gasket.config.js` is used. Everything you can configure in the [next.config][next.config] can be added here. | ||
|
||
#### Example configuration | ||
|
||
```js | ||
module.exports = { | ||
plugins: { | ||
add: ['nextjs'] | ||
}, | ||
next: { | ||
poweredByHeader: false, | ||
useFileSystemPublicRoutes: false, | ||
generateBuildId: () => Date.now() | ||
} | ||
} | ||
``` | ||
|
||
## Hooks | ||
|
||
`nextjs` hooks into the following lifecycles in order to work. | ||
|
||
#### nextCreate | ||
|
||
```js | ||
module.exports = { | ||
name: 'nextjs', | ||
hooks: { | ||
/** | ||
* Creates the next app | ||
* @param {Gasket} gasket The Gasket API | ||
* @param {Servers} devServer true or false | ||
* @return {Promise<Object>} next app | ||
*/ | ||
'nextCreate': async function createNext(gasket, devServer) { | ||
return nextApp; | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
#### nextBuild | ||
|
||
```js | ||
module.exports = { | ||
name: 'nextjs', | ||
hooks: { | ||
/** | ||
* Builds next app | ||
* @param {Gasket} gasket The Gasket API | ||
* @return {Promise<Object>} next build | ||
*/ | ||
'nextBuild': async function createBuild(gasket) { | ||
return build; | ||
} | ||
} | ||
}; | ||
``` | ||
|
||
## Lifecycles | ||
|
||
#### next | ||
|
||
Executed when the `next` server has been created. It will receive a reference to | ||
the created `next` instance. | ||
|
||
```js | ||
module.exports = { | ||
hooks: { | ||
/** | ||
* Modify the Next app instance | ||
* @param {Gasket} gasket The Gasket API | ||
* @param {Next} next Next app instance | ||
*/ | ||
next: function next(gasket, next) { | ||
next.setAssetPrefix('https://my.cdn.com/dir/'); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
#### nextConfig | ||
|
||
Executed before the `next` server has been created. It will receive a reference to the `next` config. | ||
This will allow you to modify the `next` config before the `next` server is created. | ||
|
||
```js | ||
module.exports = { | ||
hooks: { | ||
/** | ||
* Modify the Next config | ||
* @param {Gasket} gasket The Gasket API | ||
* @param {Object} config Next config | ||
* @returns {Object} config | ||
*/ | ||
nextConfig(gasket, config) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like you did with the hooks, add |
||
return { | ||
...config, | ||
modification: 'newValue' | ||
}; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
[next.config]: https://nextjs.org/docs#custom-configuration |
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,34 @@ | ||
const { initWebpack } = require('@gasket/webpack-plugin'); | ||
|
||
/** | ||
* Small helper function that creates nextjs configuration from the gasket | ||
* configuration. | ||
* | ||
* @param {Gasket} gasket The gasket API. | ||
* @param {Boolean} includeWebpackConfig `true` to generate webpack config | ||
* @returns {Promise<Object>} The configuration data for Nextjs | ||
* @private | ||
*/ | ||
function createConfig(gasket, includeWebpackConfig = true) { | ||
const { config } = gasket; | ||
|
||
let nextConfig; | ||
if (!includeWebpackConfig) { | ||
nextConfig = config.next || {}; | ||
} else { | ||
nextConfig = { | ||
...config.next, | ||
webpack: (webpackConfig, data) => { | ||
return initWebpack(gasket, webpackConfig, data); | ||
} | ||
}; | ||
} | ||
|
||
nextConfig.poweredByHeader = false; | ||
|
||
return gasket.execWaterfall('nextConfig', nextConfig); | ||
} | ||
|
||
module.exports = { | ||
createConfig | ||
}; |
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,44 @@ | ||
const { resolve } = require('path'); | ||
const { createConfig } = require('./config'); | ||
|
||
module.exports = { | ||
dependencies: ['webpack'], | ||
name: 'nextjs', | ||
hooks: { | ||
nextCreate: async function createNext(gasket, devServer) { | ||
const { exec } = gasket; | ||
const nextApp = require('next'); | ||
|
||
const app = nextApp({ | ||
dev: devServer, | ||
conf: await createConfig(gasket, devServer) | ||
}); | ||
|
||
// | ||
// We need to call the `next` lifecycle before we prepare the application | ||
// as the prepare step initializes all the routes that a next app can have. | ||
// If we wait later, it's possible that our added routes/pages are not | ||
// recognized. | ||
// | ||
await exec('next', app); | ||
await app.prepare(); | ||
|
||
return app; | ||
}, | ||
nextBuild: async function createBuild(gasket) { | ||
// | ||
// Different versions of Nextjs, have different ways of exporting the builder. | ||
// In order to support canary, and other versions of next we need to detect | ||
// the different locations. | ||
// | ||
let builder; | ||
try { | ||
builder = require('next/dist/server/build').default; | ||
} catch (e) { | ||
builder = require('next/dist/build').default; | ||
} | ||
|
||
return await builder(resolve('.'), await createConfig(gasket, true)); | ||
} | ||
} | ||
}; |
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,51 @@ | ||
{ | ||
"name": "@gasket/nextjs-plugin", | ||
"version": "1.1.0", | ||
"description": "Adds Next support to your application", | ||
"author": "GoDaddy Operating Company, LLC", | ||
"homepage": "https://github.com/godaddy/gasket/tree/master/packages/gasket-nextjs-plugin", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint './**/*.js' 'test/**/*.js'", | ||
"lint:fix": "npm run lint -- --fix", | ||
"report": "nyc report --reporter=lcov", | ||
"pretest": "npm run lint", | ||
"test": "nyc --reporter=text --reporter=json-summary npm run test:runner", | ||
"test:runner": "mocha --require ./setup.js 'test/**/*.test.js'" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/godaddy/gasket" | ||
}, | ||
"keywords": [ | ||
"next", | ||
"nextjs", | ||
"gasket", | ||
"plugin" | ||
], | ||
"dependencies": { | ||
"@gasket/webpack-plugin": "^1.0.1" | ||
}, | ||
"peerDependencies": { | ||
"next": "^7.0.0 || ^8.0.0", | ||
"react": "^16.6.0", | ||
"react-dom": "^16.6.0" | ||
}, | ||
"devDependencies": { | ||
"@gasket/plugin-engine": "^1.0.0", | ||
"assume": "^2.1.0", | ||
"assume-sinon": "^1.0.0", | ||
"eslint": "^5.13.0", | ||
"eslint-config-godaddy": "^3.0.0", | ||
"eslint-plugin-json": "^1.3.2", | ||
"eslint-plugin-mocha": "^5.2.1", | ||
"mocha": "^5.2.0", | ||
"next": "^8.1.0", | ||
"nyc": "^13.1.0", | ||
"proxyquire": "^2.1.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"sinon": "^7.2.3" | ||
} | ||
} |
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,4 @@ | ||
const assumeSinonPlugin = require('assume-sinon'); | ||
const assume = require('assume'); | ||
|
||
assume.use(assumeSinonPlugin); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: could be just
Date.now