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

Prod proxy support #993

Merged
merged 10 commits into from
Dec 17, 2024
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
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions packages/gasket-plugin-data/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ async function create(gasket, {
pkg,
files,
gasketConfig,
typescript,
nextServerType,
apiApp
typescript
}) {
pkg.add('dependencies', {
[name]: `^${version}`,
Expand All @@ -27,15 +25,8 @@ async function create(gasket, {
gasketConfig
.addPlugin('pluginData', name);

// Default server TS use .ts
// Else use .js
let importFile = './gasket-data.js';
if (typescript && nextServerType !== 'customServer' && !apiApp) {
importFile = './gasket-data.ts';
}

gasketConfig
.addImport('gasketData', `${importFile}`)
.addImport('gasketData', `./gasket-data.js`)
.injectValue('data', 'gasketData');
}

Expand Down
10 changes: 2 additions & 8 deletions packages/gasket-plugin-data/test/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,9 @@ describe('create', function () {
expect(mockContext.gasketConfig.addImport).toHaveBeenCalledWith('gasketData', './gasket-data.js');
});

it('adds TS data file import to the gasket file', async function () {
it('adds .js import', async function () {
mockContext.typescript = true;
await plugin.hooks.create({}, mockContext);
expect(mockContext.gasketConfig.addImport).toHaveBeenCalledWith('gasketData', './gasket-data.ts');
});

it('adds .js import for customServer', async function () {
mockContext.typescript = true;
mockContext.nextServerType = 'customServer';
mockContext.nextServerType = 'appRouter';
await plugin.hooks.create({}, mockContext);
expect(mockContext.gasketConfig.addImport).toHaveBeenCalledWith('gasketData', './gasket-data.js');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import gasket from '../gasket';
import gasket from '@/gasket'; // tsconfig alias
import { withGasketData } from '@gasket/nextjs/layout';

function RootLayout({ children }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import Document from 'next/document';
import { withGasketData } from '@gasket/nextjs/document';
{{#if (eq nextServerType 'customServer')}}
import gasket from '@/gasket'; // tsconfig path alias
{{else}}
import gasket from '../gasket';
{{/if}}

export default withGasketData(gasket)(Document);
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
9 changes: 6 additions & 3 deletions packages/gasket-plugin-nextjs/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,22 @@ function addNpmScripts({ pkg, nextServerType, nextDevProxy, typescript, hasGaske
scripts.local = `GASKET_DEV=1 ${watcher} server.${fileExtension}`;
if (typescript) {
scripts['build:tsc'] = 'tsc -p ./tsconfig.server.json';
scripts['build:tsc:watch'] = 'tsc -p ./tsconfig.server.json --watch';
scripts.build = 'npm run build:tsc && next build';
scripts.start = 'node dist/server.js';
scripts.local = `npm run build:tsc && GASKET_DEV=1 ${watcher} server.${fileExtension}`;
scripts.local = `concurrently "npm run build:tsc:watch" "GASKET_DEV=1 ${watcher} server.${fileExtension}"`;
}
} else if (nextDevProxy) {
scripts['start:https'] = `node server.js`;
scripts['local:https'] = `${watcher} server.${fileExtension}`;
scripts.start = `next start & npm run start:https`;
scripts.local = `next dev & npm run local:https`;
scripts.start = `npm run start:https & next start`;
scripts.local = `npm run local:https & next dev`;
if (typescript) {
scripts['build:tsc:watch'] = 'tsc -p ./tsconfig.server.json --watch';
scripts['build:tsc'] = 'tsc -p ./tsconfig.server.json';
scripts.build = 'npm run build:tsc && next build';
scripts['start:https'] = `node dist/server.js`;
scripts.local = 'concurrently "npm run build:tsc:watch" "npm run local:https" "next dev"';
}
}

Expand Down
20 changes: 11 additions & 9 deletions packages/gasket-plugin-nextjs/test/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ describe('create hook', () => {
mockContext.nextDevProxy = true;
await create.handler({}, mockContext);
expect(mockContext.pkg.add).toHaveBeenCalledWith('scripts', {
'start:https': 'node server.js',
'local:https': 'nodemon server.js',
'start': 'next start & npm run start:https',
'local': 'next dev & npm run local:https',
'build': 'next build',
'start': 'npm run start:https & next start',
'local': 'npm run local:https & next dev',
'preview': 'npm run build && npm run start',
'build': 'next build'
'start:https': 'node server.js',
'local:https': 'nodemon server.js'
});
});

Expand All @@ -318,15 +318,16 @@ describe('create hook', () => {
await create.handler({}, mockContext);
expect(mockContext.pkg.add).toHaveBeenCalledWith('scripts', {
'build:tsc': 'tsc -p ./tsconfig.server.json',
'build:tsc:watch': 'tsc -p ./tsconfig.server.json --watch',
'build': 'npm run build:tsc && next build',
'start': 'node dist/server.js',
'preview': 'npm run build && npm run start',
'local': 'npm run build:tsc && GASKET_DEV=1 tsx watch server.ts',
'local': 'concurrently "npm run build:tsc:watch" "GASKET_DEV=1 tsx watch server.ts"',
'prebuild': 'tsx gasket.ts build'
});
});

it('adjusts scripts for devProxy & typescript', async function () {
it('adjusts scripts for nextDevProxy & typescript', async function () {
mockContext.nextServerType = 'appRouter';
mockContext.nextDevProxy = true;
mockContext.typescript = true;
Expand All @@ -335,9 +336,10 @@ describe('create hook', () => {
expect(mockContext.pkg.add).toHaveBeenCalledWith('scripts', {
'start:https': 'node dist/server.js',
'local:https': 'tsx watch server.ts',
'start': 'next start & npm run start:https',
'local': 'next dev & npm run local:https',
'start': 'npm run start:https & next start',
'local': 'concurrently "npm run build:tsc:watch" "npm run local:https" "next dev"',
'build:tsc': 'tsc -p ./tsconfig.server.json',
'build:tsc:watch': 'tsc -p ./tsconfig.server.json --watch',
'build': 'npm run build:tsc && next build',
'preview': 'npm run build && npm run start',
'prebuild': 'tsx gasket.ts build'
Expand Down
8 changes: 8 additions & 0 deletions packages/gasket-plugin-typescript/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module.exports = async function create(gasket, context) {
typescript: devDependencies.typescript
});

// Add devDependencies for non-API apps
if (!apiApp) {
pkg.add('devDependencies', {
concurrently: devDependencies.concurrently
});
}

// Shared add TS links
readme
.link('tsx', 'https://tsx.is/')
Expand Down Expand Up @@ -55,6 +62,7 @@ module.exports = async function create(gasket, context) {
}

// Files for Next.js default server w/ https proxy
// Also add concurrently for running multiple scripts
if (nextDevProxy) {
files.add(`${generatorDir}/next/*`, `${generatorDir}/shared/*`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/gasket-plugin-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.12.5",
"concurrently": "^9.1.0",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"eslint-config-godaddy": "^7.1.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/gasket-plugin-typescript/test/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,13 @@ describe('create hook', () => {
expect.stringMatching(/generator\/shared\/\*$/)
);
});

it('adds concurrently for non-API apps', () => {
mockContext.apiApp = false;
create({}, mockContext);
expect(mockContext.pkg.add).toHaveBeenCalledWith('devDependencies', {
concurrently: devDependencies.concurrently
});
});
});
});
Loading