🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

create-payload-app

Package Overview
Dependencies
Maintainers
2
Versions
753
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-payload-app - npm Package Compare versions

Comparing version

to
3.0.0-beta.4

4

dist/lib/packages.js

@@ -7,3 +7,3 @@ const mongodbReplacement = {

' db: mongooseAdapter({',
' url: process.env.DATABASE_URI,',
" url: process.env.DATABASE_URI || '',",
' }),'

@@ -16,3 +16,3 @@ ]

' pool: {',
' connectionString: process.env.DATABASE_URI,',
" connectionString: process.env.DATABASE_URI || '',",
' },',

@@ -19,0 +19,0 @@ ' }),'

import chalk from 'chalk';
import { parseModule } from 'esprima';
import { Syntax, parseModule } from 'esprima-next';
import fs from 'fs';

@@ -23,8 +23,20 @@ import { warning } from '../utils/log.js';

content = withPayloadStatement[configType] + content;
const ast = parseModule(content, {
loc: true
});
let ast;
try {
ast = parseModule(content, {
loc: true
});
} catch (error) {
if (error instanceof Error) {
warning(`Unable to parse Next config. Error: ${error.message} `);
warnUserWrapNotSuccessful(configType);
}
return {
modifiedConfigContent: content,
success: false
};
}
if (configType === 'esm') {
const exportDefaultDeclaration = ast.body.find((p)=>p.type === 'ExportDefaultDeclaration');
const exportNamedDeclaration = ast.body.find((p)=>p.type === 'ExportNamedDeclaration');
const exportDefaultDeclaration = ast.body.find((p)=>p.type === Syntax.ExportDefaultDeclaration);
const exportNamedDeclaration = ast.body.find((p)=>p.type === Syntax.ExportNamedDeclaration);
if (!exportDefaultDeclaration && !exportNamedDeclaration) {

@@ -34,3 +46,3 @@ throw new Error('Could not find ExportDefaultDeclaration in next.config.js');

if (exportDefaultDeclaration && exportDefaultDeclaration.declaration?.loc) {
const modifiedConfigContent = insertBeforeAndAfter(content, exportDefaultDeclaration.declaration.loc, configType);
const modifiedConfigContent = insertBeforeAndAfter(content, exportDefaultDeclaration.declaration.loc);
return {

@@ -60,5 +72,5 @@ modifiedConfigContent,

// Find `module.exports = X`
const moduleExports = ast.body.find((p)=>p.type === 'ExpressionStatement' && p.expression?.type === 'AssignmentExpression' && p.expression.left?.type === 'MemberExpression' && p.expression.left.object?.type === 'Identifier' && p.expression.left.object.name === 'module' && p.expression.left.property?.type === 'Identifier' && p.expression.left.property.name === 'exports');
const moduleExports = ast.body.find((p)=>p.type === Syntax.ExpressionStatement && p.expression?.type === Syntax.AssignmentExpression && p.expression.left?.type === Syntax.MemberExpression && p.expression.left.object?.type === Syntax.Identifier && p.expression.left.object.name === 'module' && p.expression.left.property?.type === Syntax.Identifier && p.expression.left.property.name === 'exports');
if (moduleExports && moduleExports.expression.right?.loc) {
const modifiedConfigContent = insertBeforeAndAfter(content, moduleExports.expression.right.loc, configType);
const modifiedConfigContent = insertBeforeAndAfter(content, moduleExports.expression.right.loc);
return {

@@ -98,3 +110,3 @@ modifiedConfigContent,

}
function insertBeforeAndAfter(content, loc, configType) {
function insertBeforeAndAfter(content, loc) {
const { end, start } = loc;

@@ -101,0 +113,0 @@ const lines = content.split('\n');

@@ -19,2 +19,7 @@ import { parseAndModifyConfigContent, withPayloadStatement } from './wrap-next-config.js';

export { wrapped as default };
`,
nextConfigWithSpread: `const nextConfig = {
...someConfig,
};
export default nextConfig;
`

@@ -40,2 +45,5 @@ };

module.exports = wrapped;
`,
nextConfigWithSpread: `const nextConfig = { ...someConfig };
module.exports = nextConfig;
`

@@ -61,2 +69,7 @@ };

});
it('should parse the config with a spread', ()=>{
const { modifiedConfigContent } = parseAndModifyConfigContent(esmConfigs.nextConfigWithSpread, configType);
expect(modifiedConfigContent).toContain(importStatement);
expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
});
// Unsupported: export { wrapped as default }

@@ -98,2 +111,7 @@ it('should give warning with a named export as default', ()=>{

});
it('should parse the config with a spread', ()=>{
const { modifiedConfigContent } = parseAndModifyConfigContent(cjsConfigs.nextConfigWithSpread, configType);
expect(modifiedConfigContent).toContain(requireStatement);
expect(modifiedConfigContent).toContain('withPayload(nextConfig)');
});
});

@@ -100,0 +118,0 @@ });

{
"name": "create-payload-app",
"version": "3.0.0-beta.3",
"version": "3.0.0-beta.4",
"license": "MIT",

@@ -29,3 +29,3 @@ "type": "module",

"detect-package-manager": "^3.0.1",
"esprima": "^4.0.1",
"esprima-next": "^6.0.3",
"execa": "^5.0.0",

@@ -32,0 +32,0 @@ "figures": "^6.1.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet