Skip to content

Commit

Permalink
Do not crash if extension has no package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Aug 8, 2024
1 parent acfee32 commit f3653e4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion programs/develop/commands/commands-lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function downloadingProjectPath(projectName: string) {

export function creatingProjectPath(projectName: string) {
return (
`${getLoggingPrefix('success')} Creating a new browser extension...\n\n` +
`\n${getLoggingPrefix('success')} Creating a new browser extension...\n\n` +
`${gray('PATH')} ${underline(`${process.cwd()}/${projectName}`)}`
)
}
Expand Down
3 changes: 3 additions & 0 deletions programs/develop/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export async function extensionDev(

await devServer(projectPath, {...devOptions})
} catch (error) {
if (process.env.EXTENSION_ENV === 'development') {
console.error(error)
}
process.exit(1)
}
}
4 changes: 4 additions & 0 deletions programs/develop/webpack/plugin-css/css-tools/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export function isUsingPostCss(projectPath: string): boolean {
const packageJsonPath = path.join(projectPath, 'package.json')
const manifestJsonPath = path.join(projectPath, 'manifest.json')

if (!fs.existsSync(packageJsonPath)) {
return false
}

const postCssConfigFiles = [
'.postcssrc',
'.postcssrc.json',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import path from 'path'
import type webpack from 'webpack'
import {
Expand All @@ -19,6 +20,11 @@ export class WebpackCommonErrorsPlugin {
path.dirname(this.manifestPath),
'package.json'
)

if (!fs.existsSync(packageJsonPath)) {
return
}

const packageName = require(packageJsonPath).name

compiler.hooks.compilation.tap('develop:common-errors', (compilation) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import webpack, {Compilation} from 'webpack'
import * as messages from '../../../lib/messages'
import {PluginInterface, FilepathList, Manifest} from '../../../webpack-types'
Expand All @@ -24,7 +25,14 @@ export class ThrowIfRecompileIsNeeded {
const files = compiler.modifiedFiles || new Set<string>()
if (files.has(this.manifestPath)) {
const context = compiler.options.context || ''
const projectName = require(`${context}/package.json`).name
const packageJsonPath = `${context}/package.json`

if (!fs.existsSync(packageJsonPath)) {
done()
return
}

const projectName = require(packageJsonPath).name
const manifest: Manifest = require(this.manifestPath)
const initialHtml = this.flattenAndSort(
Object.values(htmlFields(context, manifest))
Expand Down

0 comments on commit f3653e4

Please sign in to comment.