Skip to content

Commit

Permalink
Merge pull request #1322 from flexn-io/feat/update_next_14
Browse files Browse the repository at this point in the history
Update next 14
  • Loading branch information
pavjacko committed Jan 3, 2024
2 parents 975bec2 + b2aa250 commit 60a56e0
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 131 deletions.
2 changes: 1 addition & 1 deletion packages/app-harness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@lightningjs/sdk": "^5.4.1",
"@rnv/renative": "1.0.0-rc.7",
"next": "13.5.2",
"next": "14.0.4",
"raf": "3.4.1",
"react": "18.2.0",
"react-art": "18.2.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/app-harness/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"**/*.ts",
"**/*.tsx",
"platformBuilds/template_web/.next/types/**/*.ts",
"platformBuilds/harness_web/.next/types/**/*.ts"
"platformBuilds/harness_web/.next/types/**/*.ts",
".next/types/**/*.ts",
"platformBuilds/harness_web/output/types/**/*.ts"
]
}
2 changes: 1 addition & 1 deletion packages/engine-rn-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"peerDependencies": {
"@rnv/core": "^1.0.0-rc.7",
"next": "^13",
"next": "^14",
"react": "^18",
"react-native-web": "~0.18.0",
"webpack": "^5.64.4"
Expand Down
9 changes: 8 additions & 1 deletion packages/engine-rn-next/src/adapters/nextAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ export function withRNWNext(nextConfig: NextConfig = {}): NextConfig {

export const withRNVNext = (config: NextConfig) => {
const cnf = {
// can be overwritten by user
distDir: process.env.NEXT_DIST_DIR,
// end - can be overwritten by user
...config,
images: {
disableStaticImages: true,
...(config?.images || {}),
},
distDir: process.env.NEXT_DIST_DIR,
webpack: (cfg: Configuration, props: any) => {
const { isServer } = props;

Expand All @@ -78,6 +80,11 @@ export const withRNVNext = (config: NextConfig) => {
return cfg;
},
};

if (process.env.NEXT_EXPORT === 'true') {
cnf.output = 'export';
}

let transModules: string[] = [];

const cnf1 = withRNWNext(withFonts(withImages(cnf)));
Expand Down
19 changes: 7 additions & 12 deletions packages/engine-rn-next/src/env.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
chalk,
fsExistsSync,
getConfigProp,
getContext,
getPlatformOutputDir,
logWarning,
parsePlugins,
} from '@rnv/core';
import { chalk, fsExistsSync, getConfigProp, getContext, logWarning, parsePlugins } from '@rnv/core';
import path from 'path';
import { getExportDir } from './sdk';

export const EnvVars = {
RNV_NEXT_TRANSPILE_MODULES: () => {
Expand Down Expand Up @@ -58,7 +51,9 @@ const getTranspileModules = () => {
const _checkPagesDir = () => {
const c = getContext();
const pagesDir = getConfigProp(c, c.platform, 'pagesDir');
const distDir = getPlatformOutputDir(c);
const distDir = getExportDir(c);
const isExport = c._currentTask === 'export';

if (pagesDir) {
const pagesDirPath = path.join(c.paths.project.dir, pagesDir);
if (!fsExistsSync(pagesDirPath)) {
Expand All @@ -68,7 +63,7 @@ const _checkPagesDir = () => {
)} in your renative.json but it is missing at ${chalk().red(pagesDirPath)}`
);
}
return { NEXT_PAGES_DIR: pagesDir, NEXT_DIST_DIR: distDir };
return { NEXT_PAGES_DIR: pagesDir, NEXT_DIST_DIR: distDir, NEXT_EXPORT: isExport };
}
const fallbackPagesDir = 'src/app';
logWarning(`You're missing ${c.platform}.pagesDir config. Defaulting to '${fallbackPagesDir}'`);
Expand All @@ -80,5 +75,5 @@ const _checkPagesDir = () => {
)} is missing. make sure your entry code is located there in order for next to work correctly!
Alternatively you can configure custom entry folder via ${c.platform}.pagesDir in renative.json`);
}
return { NEXT_PAGES_DIR: 'src/app', NEXT_DIST_DIR: distDir };
return { NEXT_PAGES_DIR: 'src/app', NEXT_DIST_DIR: distDir, NEXT_EXPORT: isExport };
};
15 changes: 8 additions & 7 deletions packages/engine-rn-next/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ const getOutputDir = (c: RnvContext) => {
return distDir || `platformBuilds/${c.runtime.appId}_${c.platform}/.next`;
};

const getExportDir = (c: RnvContext) => {
export const getExportDir = (c: RnvContext) => {
const outputDir = getConfigProp(c, c.platform, 'exportDir');
return outputDir || path.join(getPlatformBuildDir(c)!, 'output');
const maybeAbsolutePath = outputDir || path.join(getPlatformBuildDir(c)!, 'output');

// if path is absolute, make it relative to project root. Next 14 doesn't seem to like absolute paths
if (path.isAbsolute(maybeAbsolutePath)) {
return path.relative(c.paths.project.dir, maybeAbsolutePath);
}
};

export const buildWebNext = async (c: RnvContext) => {
Expand Down Expand Up @@ -167,12 +172,10 @@ export const deployWebNext = () => {

export const exportWebNext = async (c: RnvContext) => {
logTask('exportWebNext');
// const { platform } = c;

logTask('_exportNext');
const exportDir = getExportDir(c);

await executeAsync(c, `npx next export --outdir ${exportDir}`, {
await executeAsync(c, `npx next build`, {
env: {
...CoreEnvVars.BASE(),
...CoreEnvVars.RNV_EXTENSIONS(),
Expand All @@ -183,7 +186,5 @@ export const exportWebNext = async (c: RnvContext) => {
});
logSuccess(`Your export is located in ${chalk().cyan(exportDir)} .`);

// DEPRECATED: custom deployers moved to external packages
// await selectWebToolAndExport(c, platform);
return true;
};
5 changes: 5 additions & 0 deletions packages/engine-rn-next/src/tasks/task.rnv.build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PARAMS,
executeOrSkipTask,
shouldSkipTask,
TASK_EXPORT,
} from '@rnv/core';
import { buildWebNext } from '../sdk';

Expand All @@ -23,6 +24,10 @@ export const taskRnvBuild: RnvTaskFn = async (c, parentTask, originTask) => {
switch (platform) {
case WEB:
case CHROMECAST:
if (parentTask === TASK_EXPORT) {
// build task is not necessary when exporting. They do the same thing, only difference is a next.config.js config flag
return true;
}
await buildWebNext(c);
return;
default:
Expand Down
4 changes: 2 additions & 2 deletions packages/engine-rn-next/src/tasks/task.rnv.export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
logTask,
WEB,
CHROMECAST,
TASK_BUILD,
TASK_EXPORT,
PARAMS,
executeOrSkipTask,
shouldSkipTask,
executeOrSkipTask,
TASK_BUILD,
} from '@rnv/core';
import { exportWebNext } from '../sdk';

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/pluginTemplates/renative.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@
}
},
"next": {
"version": "12.1.6"
"version": "14.0.4"
},
"next-seo": "4.28.1",
"RCTLinkingIOS": {
Expand Down
2 changes: 1 addition & 1 deletion packages/template-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"babel-loader": "9.1.3",
"detox": "18.20.2",
"jetifier": "2.0.0",
"next": "13.5.2",
"next": "14.0.4",
"raf": "3.4.1",
"react": "18.2.0",
"react-art": "18.2.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/template-starter/renative.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@
"minSdkVersion": 21,
"extendPlatform": "android",
"engine": "engine-rn-tvos",
"includedPermissions": [
"INTERNET"
]
"includedPermissions": ["INTERNET"]
},
"web": {
"engine": "engine-rn-next"
Expand Down Expand Up @@ -157,7 +155,7 @@
"version": "0.72.4"
},
"next": {
"version": "13.5.2",
"version": "14.0.4",
"disablePluginTemplateOverrides": true
},
"react-native-web": {
Expand Down
34 changes: 20 additions & 14 deletions packages/template-starter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"extends": "@flexn/typescript-config/tsconfig.app.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": ".",
"noImplicitAny": false,
// "resolveJsonModule": false
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "platformBuilds/template_web/.next/types/**/*.ts"]
"extends": "@flexn/typescript-config/tsconfig.app.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": ".",
"noImplicitAny": false,
// "resolveJsonModule": false
"plugins": [
{
"name": "next"
}
],
"strictNullChecks": true
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"platformBuilds/template_web/.next/types/**/*.ts",
".next/types/**/*.ts"
]
}
Loading

0 comments on commit 60a56e0

Please sign in to comment.