Skip to content
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

fix(cli): handle both single and double quotes during dbAuth setup #11534

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions packages/cli-helpers/src/auth/authTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ export const addApiConfig = ({
}

const hasCurrentUserImport =
/(^import {.*?getCurrentUser(?!getCurrentUser).*?} from 'src\/lib\/auth')/s.test(
/(^import {.*?getCurrentUser(?!getCurrentUser).*?} from ['"]src\/lib\/auth['"])/s.test(
newContent,
)

if (!hasCurrentUserImport) {
// add import statement
newContent = newContent.replace(
/^(import { db } from 'src\/lib\/db')$/m,
/^(import { db } from ['"]src\/lib\/db['"])$/m,
`import { getCurrentUser } from 'src/lib/auth'\n$1`,
)

Expand All @@ -140,7 +140,7 @@ const addAuthImportToApp = (content: string) => {
const contentLines = content.split('\n')
// Find the last import line that's not a .css or .scss import
const importIndex = contentLines.findLastIndex((line: string) =>
/^\s*import (?!.*(?:.css'|.scss'))/.test(line),
/^\s*import (?!.*(?:.css['"]|.scss['"]))/.test(line),
)

// After the import found above, insert a blank line followed by the
Expand All @@ -154,7 +154,7 @@ const addAuthImportToRoutes = (content: string) => {
const contentLines = content.split('\n')
// Find the last import line that's not a .css or .scss import
const importIndex = contentLines.findLastIndex((line: string) =>
/^\s*import (?!.*(?:.css'|.scss'))/.test(line),
/^\s*import (?!.*(?:.css['"]|.scss['"]))/.test(line),
Tobbe marked this conversation as resolved.
Show resolved Hide resolved
)

// After the import found above, insert a blank line followed by the
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export const addScaffoldImport = () => {
}

appJsContents = appJsContents.replace(
"import './index.css'",
/import ['"]\.\/index\.css['"]/,
"import './index.css'\nimport './scaffold.css'\n",
)
writeFile(appJsPath, appJsContents, { overwriteExisting: true })
Expand Down
Loading