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

Incorrect path resolution causes not work with yarn workspace #5097

Closed
Akimotorakiyu opened this issue Jun 25, 2020 · 5 comments
Closed

Incorrect path resolution causes not work with yarn workspace #5097

Akimotorakiyu opened this issue Jun 25, 2020 · 5 comments
Labels

Comments

@Akimotorakiyu
Copy link

Akimotorakiyu commented Jun 25, 2020

what happened

when use yarn workspaces, it cause InvalidConfigurationError: Cannot compute electron version from installed node modules - none of the possible electron modules are installed and version ("^9.0.5") is not fixed in project.

why

export async function getElectronVersion(projectDir: string, config?: Configuration, projectMetadata: MetadataValue = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))): Promise<string> {
if (config == null) {
config = await getConfig(projectDir, null, null)
}
if (config.electronVersion != null) {
return config.electronVersion
}
return await computeElectronVersion(projectDir, projectMetadata)
}
export async function getElectronVersionFromInstalled(projectDir: string) {
for (const name of electronPackages) {
try {
return (await readJson(path.join(projectDir, "node_modules", name, "package.json"))).version
}
catch (e) {
if (e.code !== "ENOENT") {
log.warn({name, error: e}, `cannot read electron version package.json`)
}
}
}
return null
}
export async function getElectronPackage(projectDir: string) {
for (const name of electronPackages) {
try {
return (await readJson(path.join(projectDir, "node_modules", name, "package.json")))
}
catch (e) {
if (e.code !== "ENOENT") {
log.warn({name, error: e}, `cannot find electron in package.json`)
}
}
}
return null
}

// ...
return (await readJson(path.join(projectDir, "node_modules", name, "package.json"))).version
// ...

somet info

according to https://nodejs.org/dist/latest-v12.x/docs/api/modules.html#modules_require_resolve_request_options

it should be something like

// ...
return (await readJson(path.join(require.resolve(name), "..", "package.json")).version
// ...

but can't use require.resolve because of

"module": "esnext",

@Akimotorakiyu Akimotorakiyu changed the title not work with yarn workspace incorrect electron path resolved cause not work with yarn workspace Jun 25, 2020
@Akimotorakiyu Akimotorakiyu changed the title incorrect electron path resolved cause not work with yarn workspace Incorrect path resolution causes not work with yarn workspace Jun 25, 2020
@Akimotorakiyu
Copy link
Author

temp solution, work with build script
build.ts

// ...
import { getElectronVersion } from "./electronVersion";
async function build(){
  // ...
 const electronVersion = await getElectronVersion();

 builder.build({
      // ...
      config: {
        // ...
        electronVersion: electronVersion,
        // ...
    }
  })
}

build()

electronVersion.ts

const path = require.resolve("electron");
import { join } from "path";
import { readFile } from "fs-extra";

export async function getElectronVersion(): Promise<string> {
  const data = await readFile(join(path, "..", "package.json"));
  const version = JSON.parse(data.toString())?.version;
  console.log(version);
  return version;
}

@stale
Copy link

stale bot commented Aug 28, 2020

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Aug 28, 2020
@stale stale bot closed this as completed Sep 4, 2020
@nuochong
Copy link

me to

@jcc1997
Copy link

jcc1997 commented Dec 22, 2020

me too

@tajnymag
Copy link

This is still relevant as of 22.11.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants