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: reading package.json in monorepo setup #386

Merged
merged 1 commit into from
Jan 6, 2023
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 packages/parcel-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-config",
"version": "0.28.7",
"version": "0.28.8",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/parcel-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@plasmohq/parcel-runtime",
"version": "0.15.4",
"version": "0.15.5",
"description": "Plasmo Parcel Runtime",
"files": [
"dist"
Expand Down
31 changes: 16 additions & 15 deletions packages/parcel-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import { PlasmoRuntime, RuntimeData, plasmoRuntimeList } from "./types"
const devRuntimeMap = plasmoRuntimeList.reduce(
(accumulatedRuntimeMap, currentRuntime) => ({
...accumulatedRuntimeMap,
[currentRuntime]: fs.readFileSync(path.join(__dirname, `./runtimes/${currentRuntime}.js`), "utf8")
[currentRuntime]: fs.readFileSync(
path.join(__dirname, `./runtimes/${currentRuntime}.js`),
"utf8"
)
}),
{} as Record<PlasmoRuntime, string>
)

export default new Runtime({
async loadConfig({ config }) {
const pkg =
(await config.getPackage()) ||
(await config
.getConfigFrom<{
dependencies: Record<string, string>
devDependencies: Record<string, string>
}>(
join(process.env.PLASMO_PROJECT_DIR, "lab"), // parcel only look up
["package.json"],
{
exclude: true
}
)
.then((cfg) => cfg?.contents))
const pkg = await config
.getConfigFrom<{
dependencies: Record<string, string>
devDependencies: Record<string, string>
}>(
join(process.env.PLASMO_PROJECT_DIR, "lab"), // parcel only look up
["package.json"],
{
exclude: true
}
)
.then((cfg) => cfg?.contents)

const hasReact = !!pkg?.dependencies?.react || !!pkg?.devDependencies?.react

Expand Down
1 change: 1 addition & 0 deletions packages/parcel-runtime/src/runtimes/page-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ if (!parent || !parent.isParcelRequire) {
}
}
} else {
vLog("Page runtime - Reloading")
await triggerReload()
}
})
Expand Down
4 changes: 2 additions & 2 deletions packages/parcel-runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export interface ParcelBundle {
}

export type RuntimeData = {
isReact: boolean
isBackground: boolean
isContentScript: boolean
isBackground: boolean
isReact: boolean

runtimes: PlasmoRuntime[]

Expand Down
4 changes: 1 addition & 3 deletions packages/parcel-runtime/src/utils/inject-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ export function injectHmrSocket(
if (data.type === "error") {
// Log parcel errors to console
for (const ansiDiagnostic of data.diagnostics.ansi) {
const stack = ansiDiagnostic.codeframe
? ansiDiagnostic.codeframe
: ansiDiagnostic.stack
const stack = ansiDiagnostic.codeframe || ansiDiagnostic.stack

wLog(
"[plasmo/parcel-runtime]: " +
Expand Down