Skip to content

Commit 7593d1c

Browse files
ambrauerart-alexeyenko
authored and
art-alexeyenko
committed
[Next.js] Fixes for nextjs-xmcloud Initializer Template (#1657)
* Fix issue where nextjs-xmcloud template's /src/lib/next-config/plugins/monorepo.js wasn't being cleaned up properly. Use dedicated monorepo-xmcloud.js instead. * Fix issue with init-runner where response.initializers would prevent any following initializers to be skipped (return statement caused early exit) * updated CHANGELOG (cherry picked from commit b691251)
1 parent 9aa7d80 commit 7593d1c

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Our versioning strategy is as follows:
2424
* `[sitecore-jss-nextjs]` (Vercel/Sitecore) Deployment Protection Bypass support for editing integration. ([#1634](https://github.com/Sitecore/jss/pull/1634))
2525
* `[sitecore-jss]` `[templates/nextjs]` Load environment-specific FEAAS theme stylesheets based on Sitecore Edge Platform URL ([#1645](https://github.com/Sitecore/jss/pull/1645))
2626
* `[sitecore-jss-nextjs]` The _GraphQLRequestClient_ import from _@sitecore-jss/sitecore-jss-nextjs_ is deprecated, use import from _@sitecore-jss/sitecore-jss-nextjs/graphql_ submodule instead ([#1650](https://github.com/Sitecore/jss/pull/1650) [#1648](https://github.com/Sitecore/jss/pull/1648))
27-
* `[create-sitecore-jss]` Introduced `nextjs-xmcloud` initializer template. This will include all base XM Cloud features, including Personalize, FEaaS, BYOC, Sitecore Edge Platform and Context support. ([#1653](https://github.com/Sitecore/jss/pull/1653))
27+
* `[create-sitecore-jss]` Introduced `nextjs-xmcloud` initializer template. This will include all base XM Cloud features, including Personalize, FEaaS, BYOC, Sitecore Edge Platform and Context support. ([#1653](https://github.com/Sitecore/jss/pull/1653)) ([#1657](https://github.com/Sitecore/jss/pull/1657))
2828

2929
### 🐛 Bug Fixes
3030

packages/create-sitecore-jss/src/init-runner.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('initRunner', () => {
7575
});
7676

7777
it('should process returned initializers', async () => {
78-
const templates = ['foo', 'bar'];
78+
const templates = ['foo', 'bar', 'zoo'];
7979
const appName = 'test-app';
8080
const args = {
8181
silent: false,
@@ -87,19 +87,22 @@ describe('initRunner', () => {
8787
const mockBar = mockInitializer(false, { appName, initializers: ['baz'] });
8888
const mockBaz = mockInitializer(false, { appName, initializers: ['huh'] });
8989
const mockHuh = mockInitializer(false, { appName, initializers: [] });
90+
const mockZoo = mockInitializer(false, { appName, initializers: [] });
9091
createStub = sinon.stub(InitializerFactory.prototype, 'create');
9192
createStub.withArgs('foo').returns(mockFoo);
9293
createStub.withArgs('bar').returns(mockBar);
9394
createStub.withArgs('baz').returns(mockBaz);
9495
createStub.withArgs('huh').returns(mockHuh);
96+
createStub.withArgs('zoo').returns(mockZoo);
9597

9698
await initRunner(templates, args);
9799

98100
expect(mockFoo.init).to.be.calledOnceWith(args);
99101
expect(mockBar.init).to.be.calledOnceWith(args);
100102
expect(mockBaz.init).to.be.calledOnceWith(args);
101103
expect(mockHuh.init).to.be.calledOnceWith(args);
102-
expect(args.templates).to.deep.equal(['foo', 'bar', 'baz', 'huh']);
104+
expect(mockZoo.init).to.be.calledOnceWith(args);
105+
expect(args.templates).to.deep.equal(['foo', 'bar', 'zoo', 'baz', 'huh']);
103106
});
104107

105108
it('should aggregate nextSteps', async () => {

packages/create-sitecore-jss/src/init-runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const initRunner = async (initializers: string[], args: BaseArgs) => {
1616

1717
const initFactory = new InitializerFactory();
1818
const runner = async (inits: string[]): Promise<void> => {
19-
for (const init of inits) {
19+
for (const init of [...inits]) {
2020
const initializer = await initFactory.create(init);
2121
if (!initializer) {
2222
throw new RangeError(`Unknown template '${init}'`);
@@ -34,7 +34,7 @@ export const initRunner = async (initializers: string[], args: BaseArgs) => {
3434
// add-ons will not have information about the initial
3535
// list of templates, as it has `nextjs` initializer for example
3636
args.templates.push(...response.initializers);
37-
return await runner(response.initializers);
37+
await runner(response.initializers);
3838
}
3939
}
4040
};

packages/create-sitecore-jss/src/initializers/nextjs-xmcloud/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {
33
Initializer,
44
openPackageJson,
55
transform,
6+
isDevEnvironment,
67
DEFAULT_APPNAME,
78
ClientAppArgs,
89
incompatibleAddonsMsg,
910
} from '../../common';
11+
import { removeDevDependencies } from './remove-dev-dependencies';
1012

1113
export default class NextjsXMCloudInitializer implements Initializer {
1214
get isBase(): boolean {
@@ -26,6 +28,10 @@ export default class NextjsXMCloudInitializer implements Initializer {
2628

2729
await transform(templatePath, mergedArgs);
2830

31+
if (!isDevEnvironment(args.destination)) {
32+
removeDevDependencies(args.destination);
33+
}
34+
2935
if (
3036
args.templates.includes('nextjs-styleguide-tracking') ||
3137
pkg.config?.templates?.includes('nextjs-styleguide-tracking')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
4+
export const removeDevDependencies = (projectPath: string) => {
5+
// remove monorepo next.config.js plugin
6+
const monorepoPlugin = path.join(projectPath, 'src/lib/next-config/plugins/monorepo-xmcloud.js');
7+
if (fs.existsSync(monorepoPlugin)) {
8+
fs.unlinkSync(monorepoPlugin);
9+
}
10+
};

packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/next-config/plugins/monorepo.js packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/next-config/plugins/monorepo-xmcloud.js

-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ const CWD = process.cwd();
77
const monorepoPlugin = (nextConfig = {}) => {
88
return Object.assign({}, nextConfig, {
99
webpack: (config, options) => {
10-
if (options.isServer) {
11-
config.externals = ['react', 'vertx', ...config.externals];
12-
}
1310
// Monorepo support for @sitecore-feaas/clientside/react
1411
config.resolve.alias['@sitecore-feaas/clientside/react'] = path.resolve(
1512
CWD, options.isServer ?

0 commit comments

Comments
 (0)