Commit 580c13a0 authored by Guy Bedford's avatar Guy Bedford Committed by Joe Haddad

cookie

parent 0adb310c
import { parse } from 'next/dist/compiled/content-type' import { parse } from 'next/dist/compiled/content-type'
import { CookieSerializeOptions } from 'cookie' import { CookieSerializeOptions } from 'next/dist/compiled/cookie'
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import { PageConfig } from 'next/types' import { PageConfig } from 'next/types'
import getRawBody from 'raw-body' import getRawBody from 'raw-body'
...@@ -181,7 +181,7 @@ export function getCookieParser(req: IncomingMessage) { ...@@ -181,7 +181,7 @@ export function getCookieParser(req: IncomingMessage) {
return {} return {}
} }
const { parse } = require('cookie') const { parse } = require('next/dist/compiled/cookie')
return parse(Array.isArray(header) ? header.join(';') : header) return parse(Array.isArray(header) ? header.join(';') : header)
} }
} }
...@@ -384,7 +384,9 @@ function setPreviewData<T>( ...@@ -384,7 +384,9 @@ function setPreviewData<T>(
) )
} }
const { serialize } = require('cookie') as typeof import('cookie') const {
serialize,
} = require('next/dist/compiled/cookie') as typeof import('cookie')
const previous = res.getHeader('Set-Cookie') const previous = res.getHeader('Set-Cookie')
res.setHeader(`Set-Cookie`, [ res.setHeader(`Set-Cookie`, [
...(typeof previous === 'string' ...(typeof previous === 'string'
...@@ -417,7 +419,9 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> { ...@@ -417,7 +419,9 @@ function clearPreviewData<T>(res: NextApiResponse<T>): NextApiResponse<T> {
return res return res
} }
const { serialize } = require('cookie') as typeof import('cookie') const {
serialize,
} = require('next/dist/compiled/cookie') as typeof import('cookie')
const previous = res.getHeader('Set-Cookie') const previous = res.getHeader('Set-Cookie')
res.setHeader(`Set-Cookie`, [ res.setHeader(`Set-Cookie`, [
...(typeof previous === 'string' ...(typeof previous === 'string'
......
...@@ -63,7 +63,6 @@ ...@@ -63,7 +63,6 @@
"autodll-webpack-plugin": "0.4.2", "autodll-webpack-plugin": "0.4.2",
"cache-loader": "4.1.0", "cache-loader": "4.1.0",
"conf": "5.0.0", "conf": "5.0.0",
"cookie": "0.4.0",
"css-loader": "3.3.0", "css-loader": "3.3.0",
"cssnano-simple": "1.0.0", "cssnano-simple": "1.0.0",
"devalue": "2.0.1", "devalue": "2.0.1",
...@@ -191,6 +190,7 @@ ...@@ -191,6 +190,7 @@
"ci-info": "2.0.0", "ci-info": "2.0.0",
"compression": "1.7.4", "compression": "1.7.4",
"content-type": "1.0.4", "content-type": "1.0.4",
"cookie": "0.4.0",
"dotenv": "8.2.0", "dotenv": "8.2.0",
"dotenv-expand": "5.1.0", "dotenv-expand": "5.1.0",
"nanoid": "2.0.3", "nanoid": "2.0.3",
......
...@@ -284,6 +284,13 @@ export async function ncc_content_type(task, opts) { ...@@ -284,6 +284,13 @@ export async function ncc_content_type(task, opts) {
.target('dist/compiled/content-type') .target('dist/compiled/content-type')
} }
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
export async function ncc_cookie(task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('cookie')))
.ncc({ packageName: 'cookie' })
.target('dist/compiled/cookie')
}
// eslint-disable-next-line camelcase
export async function ncc_dotenv(task, opts) { export async function ncc_dotenv(task, opts) {
await task await task
.source(opts.src || relative(__dirname, require.resolve('dotenv'))) .source(opts.src || relative(__dirname, require.resolve('dotenv')))
...@@ -357,6 +364,7 @@ export async function precompile(task) { ...@@ -357,6 +364,7 @@ export async function precompile(task) {
'ncc_ci_info', 'ncc_ci_info',
'ncc_compression', 'ncc_compression',
'ncc_content_type', 'ncc_content_type',
'ncc_cookie',
'ncc_dotenv', 'ncc_dotenv',
'ncc_dotenv_expand', 'ncc_dotenv_expand',
'ncc_nanoid', 'ncc_nanoid',
......
...@@ -71,6 +71,10 @@ declare module 'next/dist/compiled/content-type' { ...@@ -71,6 +71,10 @@ declare module 'next/dist/compiled/content-type' {
import m from 'content-type' import m from 'content-type'
export = m export = m
} }
declare module 'next/dist/compiled/cookie' {
import m from 'cookie'
export = m
}
declare module 'next/dist/compiled/dotenv' { declare module 'next/dist/compiled/dotenv' {
import m from 'dotenv' import m from 'dotenv'
export = m export = m
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment