From a182c351475696b89f0694c2b1407a9660e4f2bb Mon Sep 17 00:00:00 2001 From: Aral Roca Gomez Date: Tue, 24 Mar 2020 09:51:08 +0100 Subject: [PATCH] Fix specialMethod detection (#95) --- cli/builder.js | 12 +++++++----- examples/static-site/pages_/index.tsx | 6 +++--- package.json | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cli/builder.js b/cli/builder.js index 89243168..5c961d4e 100755 --- a/cli/builder.js +++ b/cli/builder.js @@ -17,7 +17,7 @@ const { function readDirR(dir) { return fs.statSync(dir).isDirectory() ? Array.prototype.concat( - ...fs.readdirSync(dir).map(f => readDirR(path.join(dir, f))) + ...fs.readdirSync(dir).map((f) => readDirR(path.join(dir, f))) ) : dir } @@ -32,7 +32,7 @@ createPagesDir(allLanguages) async function createPagesDir(langs = []) { execSync(`rm -rf ${finalPagesDir} && mkdir ${finalPagesDir}`) - langs.forEach(async lang => { + langs.forEach(async (lang) => { execSync(`mkdir ${finalPagesDir}/${lang}`) }) @@ -62,7 +62,7 @@ function clearPageExt(page) { * STEP 2: Read each page namespaces */ function readPageNamespaces(langs) { - readDirR(currentPagesDir).forEach(async page => { + readDirR(currentPagesDir).forEach(async (page) => { const pageId = clearPageExt(page.replace(currentPagesDir, '')) || '/' const namespaces = await getPageNamespaces({ pages }, pageId) @@ -75,7 +75,9 @@ function readPageNamespaces(langs) { } function hasSpecialMethod(data, name) { - return data.match(new RegExp(`export (const|var|let|function) ${name}`)) + return data.match( + new RegExp(`export (const|var|let|async function|function) ${name}`) + ) } function specialMethod(name, lang) { @@ -160,7 +162,7 @@ function buildPageInAllLocales(pagePath, namespaces, langs) { } // For each lang - langs.forEach(lang => { + langs.forEach((lang) => { buildPageLocale({ lang, namespaces, diff --git a/examples/static-site/pages_/index.tsx b/examples/static-site/pages_/index.tsx index 540f80e2..b106c744 100644 --- a/examples/static-site/pages_/index.tsx +++ b/examples/static-site/pages_/index.tsx @@ -28,6 +28,6 @@ export default function Home(props) { } // @ts-ignore -export const getStaticProps = async ({ lang }) => ({ - props: { getStaticPropsWorks: true, lang }, -}) +export async function getStaticProps({ lang }) { + return { props: { getStaticPropsWorks: true, lang } } +} diff --git a/package.json b/package.json index f4a1eb4e..441224db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-translate", - "version": "0.13.0-canary.1", + "version": "0.13.0-canary.2", "description": "Next.js utility to translate pages without the need of a server (static i18n pages generator).", "license": "MIT", "keywords": [