Skip to content

Commit

Permalink
[PFX-641] - create-gasket-app with NextJs preset and render app (#778)
Browse files Browse the repository at this point in the history
* @gasket/nextjs: add extensions to imports

* @gasket/plugin-nextjs: update generated _document file

* @gasket/nextjs: revert extensions additions

* @gasket/plugin-nextjs: adjust next-config to transpile package

* @gasket/plugin-nextjs: revert nextconfig option

* @gasket/nextjs: add extensions to imports to circumvent exports conflicts

* @gasket/plugin-nextjs: CHANGELOG

* @gasket/nextjs: CHANGELOG

* @gasket/plugin-nextjs: adjust logic of the server.js generation to include customServer

* @gasket/plugin-nextjs: add CHANGELOG entry
  • Loading branch information
mmason2-godaddy authored Jun 6, 2024
1 parent e95b683 commit 28c14e7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 18 deletions.
5 changes: 5 additions & 0 deletions packages/gasket-nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# `@gasket/nextjs`



- Add file extensions to imports, fix package exports conflict ([#778])

### 6.45.2

- Refactor tests to Jest, update test scripts, add `cross-env`, remove obsolete `devDeps` ([#670])
Expand Down Expand Up @@ -63,3 +67,4 @@
[#603]: https://github.com/godaddy/gasket/pull/603
[#614]: https://github.com/godaddy/gasket/pull/614
[#670]: https://github.com/godaddy/gasket/pull/670
[#778]: https://github.com/godaddy/gasket/pull/778
2 changes: 1 addition & 1 deletion packages/gasket-nextjs/lib/document/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="@gasket/plugin-data" />

import { Children, cloneElement, createElement } from 'react';
import { Main, NextScript } from 'next/document';
import { Main, NextScript } from 'next/document.js'; // Conflicts with package.json exports - extensions required
import { GasketDataScript } from '../gasket-data-script.js';

const reClass = /^class\s/;
Expand Down
4 changes: 2 additions & 2 deletions packages/gasket-nextjs/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './use-gasket-data';
export * from './with-gasket-data-provider';
export * from './use-gasket-data.js';
export * from './with-gasket-data-provider.js';
2 changes: 1 addition & 1 deletion packages/gasket-nextjs/lib/server/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { request } from './request';
export { request } from './request.js';
2 changes: 1 addition & 1 deletion packages/gasket-nextjs/lib/use-gasket-data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useContext } from 'react';
import { GasketDataContext } from './gasket-data-provider';
import { GasketDataContext } from './gasket-data-provider.js';

/**
* React that fetches GasketData in elements context and returns it
Expand Down
2 changes: 1 addition & 1 deletion packages/gasket-nextjs/lib/with-gasket-data-provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createElement } from 'react';
import { GasketDataProvider } from './gasket-data-provider';
import { GasketDataProvider } from './gasket-data-provider.js';
import PropTypes from 'prop-types';

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/gasket-plugin-nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# `@gasket/plugin-nextjs`

- Fix logic for `server.js` generation to include `customServer` ([#778])
- Update generated `_document.js` ([#778])
- Added redux optional flag ([#762])
- Add plugin import to gasket file ([#736])
- Add itself to the app package file ([#736])
Expand Down Expand Up @@ -283,3 +285,4 @@
[#736]: https://github.com/godaddy/gasket/pull/736
[#750]: https://github.com/godaddy/gasket/pull/750
[#762]: https://github.com/godaddy/gasket/pull/762
[#778]: https://github.com/godaddy/gasket/pull/778
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Document from 'next/document';
import { withGasketData } from '@gasket/nextjs';
export default withGasketData()(Document);
import { withGasketData } from '@gasket/nextjs/document';
import gasket from '../gasket.js';
export default withGasketData(gasket)(Document.default || Document);
21 changes: 11 additions & 10 deletions packages/gasket-plugin-nextjs/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ function createTestFiles({ files, generatorDir, testPlugins }) {
* @property {nextDevProxy} - Selected dev proxy from prompt
* @property {typescript} - Selected typescript from prompt
*/
function createNextFiles({ files, generatorDir, nextDevProxy, typescript }) {
function createNextFiles({ files, generatorDir, nextDevProxy, typescript, nextServerType }) {
let glob;
if (typescript || !nextDevProxy) glob = `${generatorDir}/next/*[!server].js`;
if (
typescript ||
(!nextDevProxy && nextServerType === 'defaultServer')
) glob = `${generatorDir}/next/*[!server].js`;
else glob = `${generatorDir}/next/*`;
files.add(glob);
}
Expand All @@ -70,7 +73,7 @@ function configureSitemap({ files, pkg, generatorDir }) {
* addDependencies
* @property {PackageJsonBuilder} pkg - The Gasket PackageJson API.
*/
function addDependencies({ pkg, nextDevProxy }) {
function addDependencies({ pkg }) {
pkg.add('dependencies', {
'@gasket/assets': devDependencies['@gasket/assets'],
'@gasket/nextjs': devDependencies['@gasket/nextjs'],
Expand All @@ -81,11 +84,9 @@ function addDependencies({ pkg, nextDevProxy }) {
'react-dom': devDependencies['react-dom']
});

if (nextDevProxy) {
pkg.add('devDependencies', {
nodemon: devDependencies.nodemon
});
}
pkg.add('devDependencies', {
nodemon: devDependencies.nodemon
});
}

/**
Expand Down Expand Up @@ -174,8 +175,8 @@ module.exports = {

createAppFiles({ files, generatorDir });
createTestFiles({ files, generatorDir, testPlugins });
createNextFiles({ files, generatorDir, nextDevProxy, typescript });
addDependencies({ pkg, nextDevProxy });
createNextFiles({ files, generatorDir, nextDevProxy, typescript, nextServerType });
addDependencies({ pkg });
addNpmScripts({ pkg, nextServerType, nextDevProxy, typescript });
addConfig(context);
if (addSitemap) configureSitemap({ files, pkg, generatorDir });
Expand Down

0 comments on commit 28c14e7

Please sign in to comment.