Skip to content

chore: don't use esbuild by default #562

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

Merged
merged 1 commit into from
Jul 28, 2021
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 src/lib/helpers/setupNetlifyFunctionForPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const setupNetlifyFunctionForPage = async ({ filePath, functionsPath, isApiPage,
}

// Write entry point to function directory
const entryPointPath = join(functionDirectory, `${functionName}.ts`)
const entryPointPath = join(functionDirectory, `${functionName}.js`)
await writeFile(entryPointPath, getTemplate({ filePath, isISR }))

// Copy function helper
Expand Down
10 changes: 5 additions & 5 deletions src/lib/templates/getTemplate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const getTemplate = ({ filePath, isISR }) => {
if (isISR) {
return `// Auto-generated file. DO NOT MODIFY.
import { getHandlerFunction } from './getHandlerFunction'
import { builder } from '@netlify/functions'
export const handler = builder(getHandlerFunction(require("./nextPage/${filePath}")))
const { getHandlerFunction } = require('./getHandlerFunction')
const { builder } = require('@netlify/functions')
exports.handler = builder(getHandlerFunction(require("./nextPage/${filePath}")))
`
}
return `// Auto-generated file. DO NOT MODIFY.
import { getHandlerFunction } from './getHandlerFunction'
export const handler = getHandlerFunction(require("./nextPage/${filePath}"))
const { getHandlerFunction } = require('./getHandlerFunction')
exports.handler = getHandlerFunction(require("./nextPage/${filePath}"))
`
}

Expand Down
10 changes: 5 additions & 5 deletions src/tests/configurableDirs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ describe('next-on-netlify', () => {
})

test('creates a Netlify Function for each SSR page', () => {
expect(existsSync(join(functionsDir, 'next_index', 'next_index.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_id', 'next_shows_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_params', 'next_shows_params.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_static', 'next_getServerSideProps_static.ts'))).toBe(
expect(existsSync(join(functionsDir, 'next_index', 'next_index.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_id', 'next_shows_id.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_params', 'next_shows_params.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_static', 'next_getServerSideProps_static.js'))).toBe(
true,
)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.js'))).toBe(true)
})

test('copies static pages to output directory', () => {
Expand Down
28 changes: 14 additions & 14 deletions src/tests/defaults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ describe('SSR Pages', () => {
const functionsDir = join(PROJECT_PATH, 'out_functions')

test('creates a Netlify Function for each SSR page', () => {
expect(existsSync(join(functionsDir, 'next_index', 'next_index.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_id', 'next_shows_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_params', 'next_shows_params.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_static', 'next_getServerSideProps_static.ts'))).toBe(
expect(existsSync(join(functionsDir, 'next_index', 'next_index.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_id', 'next_shows_id.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_params', 'next_shows_params.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_static', 'next_getServerSideProps_static.js'))).toBe(
true,
)
expect(
readFileSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.ts'), 'utf-8'),
readFileSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.js'), 'utf-8'),
).toMatch(`require("./nextPage/pages/getServerSideProps/[id].js")`)
})
})
Expand All @@ -77,10 +77,10 @@ describe('API Pages', () => {
const functionsDir = join(PROJECT_PATH, 'out_functions')

test('creates a Netlify Function for each API endpoint', () => {
expect(existsSync(join(functionsDir, 'next_api_static', 'next_api_static.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_id', 'next_api_shows_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_params', 'next_api_shows_params.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_hello-background', 'next_api_hello-background.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_static', 'next_api_static.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_id', 'next_api_shows_id.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_params', 'next_api_shows_params.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_hello-background', 'next_api_hello-background.js'))).toBe(true)
})
})

Expand Down Expand Up @@ -126,10 +126,10 @@ describe('SSG Pages with getStaticProps', () => {
})

test('creates Netlify Functions for pages with fallback', () => {
const functionPath1 = 'next_getStaticProps_withFallback_id/next_getStaticProps_withFallback_id.ts'
const functionPath1 = 'next_getStaticProps_withFallback_id/next_getStaticProps_withFallback_id.js'
expect(existsSync(join(PROJECT_PATH, 'out_functions', functionPath1))).toBe(true)

const functionPath2 = 'next_getStaticProps_withFallback_slug/next_getStaticProps_withFallback_slug.ts'
const functionPath2 = 'next_getStaticProps_withFallback_slug/next_getStaticProps_withFallback_slug.js'
expect(existsSync(join(PROJECT_PATH, 'out_functions', functionPath2))).toBe(true)
})
})
Expand All @@ -139,19 +139,19 @@ describe('SSG Pages with getStaticProps and revalidate', () => {

test('creates a Netlify Function for each page', () => {
expect(
existsSync(join(functionsDir, 'next_getStaticProps_withrevalidate', 'next_getStaticProps_withrevalidate.ts')),
existsSync(join(functionsDir, 'next_getStaticProps_withrevalidate', 'next_getStaticProps_withrevalidate.js')),
).toBe(true)
expect(
existsSync(
join(functionsDir, 'next_getStaticProps_withRevalidate_id', 'next_getStaticProps_withRevalidate_id.ts'),
join(functionsDir, 'next_getStaticProps_withRevalidate_id', 'next_getStaticProps_withRevalidate_id.js'),
),
).toBe(true)
expect(
existsSync(
join(
functionsDir,
'next_getStaticProps_withRevalidate_withFallback_id',
'next_getStaticProps_withRevalidate_withFallback_id.ts',
'next_getStaticProps_withRevalidate_withFallback_id.js',
),
),
).toBe(true)
Expand Down
26 changes: 13 additions & 13 deletions src/tests/i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ describe('SSR Pages', () => {
const functionsDir = join(PROJECT_PATH, 'out_functions')

test('creates a Netlify Function for each SSR page', () => {
expect(existsSync(join(functionsDir, 'next_index', 'next_index.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_id', 'next_shows_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_params', 'next_shows_params.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_static', 'next_getServerSideProps_static.ts'))).toBe(
expect(existsSync(join(functionsDir, 'next_index', 'next_index.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_id', 'next_shows_id.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_shows_params', 'next_shows_params.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_static', 'next_getServerSideProps_static.js'))).toBe(
true,
)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_getServerSideProps_id', 'next_getServerSideProps_id.js'))).toBe(true)
})
})

describe('API Pages', () => {
const functionsDir = join(PROJECT_PATH, 'out_functions')

test('creates a Netlify Function for each API endpoint', () => {
expect(existsSync(join(functionsDir, 'next_api_static', 'next_api_static.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_id', 'next_api_shows_id.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_params', 'next_api_shows_params.ts'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_static', 'next_api_static.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_id', 'next_api_shows_id.js'))).toBe(true)
expect(existsSync(join(functionsDir, 'next_api_shows_params', 'next_api_shows_params.js'))).toBe(true)
})
})

Expand Down Expand Up @@ -110,10 +110,10 @@ describe('SSG Pages with getStaticProps', () => {
})

test('creates Netlify Functions for pages with fallback', () => {
const functionPath1 = 'next_getStaticProps_withFallback_id/next_getStaticProps_withFallback_id.ts'
const functionPath1 = 'next_getStaticProps_withFallback_id/next_getStaticProps_withFallback_id.js'
expect(existsSync(join(PROJECT_PATH, 'out_functions', functionPath1))).toBe(true)

const functionPath2 = 'next_getStaticProps_withFallback_slug/next_getStaticProps_withFallback_slug.ts'
const functionPath2 = 'next_getStaticProps_withFallback_slug/next_getStaticProps_withFallback_slug.js'
expect(existsSync(join(PROJECT_PATH, 'out_functions', functionPath2))).toBe(true)
})
})
Expand All @@ -123,19 +123,19 @@ describe('SSG Pages with getStaticProps and revalidate', () => {

test('creates a Netlify Function for each page', () => {
expect(
existsSync(join(functionsDir, 'next_getStaticProps_withrevalidate', 'next_getStaticProps_withrevalidate.ts')),
existsSync(join(functionsDir, 'next_getStaticProps_withrevalidate', 'next_getStaticProps_withrevalidate.js')),
).toBe(true)
expect(
existsSync(
join(functionsDir, 'next_getStaticProps_withRevalidate_id', 'next_getStaticProps_withRevalidate_id.ts'),
join(functionsDir, 'next_getStaticProps_withRevalidate_id', 'next_getStaticProps_withRevalidate_id.js'),
),
).toBe(true)
expect(
existsSync(
join(
functionsDir,
'next_getStaticProps_withRevalidate_withFallback_id',
'next_getStaticProps_withRevalidate_withFallback_id.ts',
'next_getStaticProps_withRevalidate_withFallback_id.js',
),
),
).toBe(true)
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('onBuild()', () => {
utils,
})

expect(await pathExists(`${resolvedFunctions}/next_api_test/next_api_test.ts`)).toBeTruthy()
expect(await pathExists(`${resolvedFunctions}/next_api_test/next_api_test.js`)).toBeTruthy()
})
})

Expand Down