Skip to content
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

[Next.js] Fixes for nextjs-xmcloud Initializer Template #1657

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss-nextjs]` (Vercel/Sitecore) Deployment Protection Bypass support for editing integration. ([#1634](https://github.com/Sitecore/jss/pull/1634))
* `[sitecore-jss]` `[templates/nextjs]` Load environment-specific FEAAS theme stylesheets based on Sitecore Edge Platform URL ([#1645](https://github.com/Sitecore/jss/pull/1645))
* `[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))
* `[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))
* `[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))

### 🐛 Bug Fixes

Expand Down
7 changes: 5 additions & 2 deletions packages/create-sitecore-jss/src/init-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('initRunner', () => {
});

it('should process returned initializers', async () => {
const templates = ['foo', 'bar'];
const templates = ['foo', 'bar', 'zoo'];
const appName = 'test-app';
const args = {
silent: false,
Expand All @@ -87,19 +87,22 @@ describe('initRunner', () => {
const mockBar = mockInitializer(false, { appName, initializers: ['baz'] });
const mockBaz = mockInitializer(false, { appName, initializers: ['huh'] });
const mockHuh = mockInitializer(false, { appName, initializers: [] });
const mockZoo = mockInitializer(false, { appName, initializers: [] });
createStub = sinon.stub(InitializerFactory.prototype, 'create');
createStub.withArgs('foo').returns(mockFoo);
createStub.withArgs('bar').returns(mockBar);
createStub.withArgs('baz').returns(mockBaz);
createStub.withArgs('huh').returns(mockHuh);
createStub.withArgs('zoo').returns(mockZoo);

await initRunner(templates, args);

expect(mockFoo.init).to.be.calledOnceWith(args);
expect(mockBar.init).to.be.calledOnceWith(args);
expect(mockBaz.init).to.be.calledOnceWith(args);
expect(mockHuh.init).to.be.calledOnceWith(args);
expect(args.templates).to.deep.equal(['foo', 'bar', 'baz', 'huh']);
expect(mockZoo.init).to.be.calledOnceWith(args);
expect(args.templates).to.deep.equal(['foo', 'bar', 'zoo', 'baz', 'huh']);
});

it('should aggregate nextSteps', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-sitecore-jss/src/init-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const initRunner = async (initializers: string[], args: BaseArgs) => {

const initFactory = new InitializerFactory();
const runner = async (inits: string[]): Promise<void> => {
for (const init of inits) {
for (const init of [...inits]) {
const initializer = await initFactory.create(init);
if (!initializer) {
throw new RangeError(`Unknown template '${init}'`);
Expand All @@ -34,7 +34,7 @@ export const initRunner = async (initializers: string[], args: BaseArgs) => {
// add-ons will not have information about the initial
// list of templates, as it has `nextjs` initializer for example
args.templates.push(...response.initializers);
return await runner(response.initializers);
await runner(response.initializers);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
Initializer,
openPackageJson,
transform,
isDevEnvironment,
DEFAULT_APPNAME,
ClientAppArgs,
incompatibleAddonsMsg,
} from '../../common';
import { removeDevDependencies } from './remove-dev-dependencies';

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

await transform(templatePath, mergedArgs);

if (!isDevEnvironment(args.destination)) {
removeDevDependencies(args.destination);
}

if (
args.templates.includes('nextjs-styleguide-tracking') ||
pkg.config?.templates?.includes('nextjs-styleguide-tracking')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fs from 'fs';
import path from 'path';

export const removeDevDependencies = (projectPath: string) => {
// remove monorepo next.config.js plugin
const monorepoPlugin = path.join(projectPath, 'src/lib/next-config/plugins/monorepo-xmcloud.js');
if (fs.existsSync(monorepoPlugin)) {
fs.unlinkSync(monorepoPlugin);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ const CWD = process.cwd();
const monorepoPlugin = (nextConfig = {}) => {
return Object.assign({}, nextConfig, {
webpack: (config, options) => {
if (options.isServer) {
config.externals = ['react', 'vertx', ...config.externals];
}
// Monorepo support for @sitecore-feaas/clientside/react
config.resolve.alias['@sitecore-feaas/clientside/react'] = path.resolve(
CWD, options.isServer ?
Expand Down