Skip to content

Commit

Permalink
chore: cleanup after #221
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Nov 16, 2018
1 parent 88e4e3e commit ffe3b8f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 75 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"jest-junit": "^5.1.0",
"memory-fs": "^0.4.1",
"temp-file": "^3.1.3",
"terser-webpack-plugin": "^1.1.0",
"ts-babel": "^6.0.2",
"tslint": "^5.11.0",
"typescript": "^3.0.3",
"webpack": "^4.17.1",
"terser-webpack-plugin": "^1.1.0"
"webpack": "^4.17.1"
},
"workspaces": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-webpack",
"version": "2.3.1",
"version": "2.4.0",
"license": "MIT",
"author": "Vladimir Krivosheev <develar@gmail.com>",
"main": "out/main.js",
Expand Down Expand Up @@ -38,7 +38,7 @@
"lazy-val": "^1.0.3",
"mini-css-extract-plugin": "^0.4.4",
"node-loader": "^0.6.0",
"read-config-file": "^3.1.3",
"read-config-file": "^3.2.0",
"semver": "^5.6.0",
"source-map-support": "^0.5.9",
"style-loader": "^0.23.1",
Expand Down
31 changes: 21 additions & 10 deletions packages/electron-webpack/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { readJson } from "fs-extra-p"
import { Lazy } from "lazy-val"
import * as path from "path"
import { orNullIfFileNotExist } from "./util"
import { getConfig } from "read-config-file"
import { ElectronWebpackConfiguration } from "./core"
import { orNullIfFileNotExist } from "./util"

export { ElectronWebpackConfiguration } from "./core"
export function getPackageMetadata(projectDir: string) {
return new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))
}

export async function getPackageMetadata(projectDir?: string | null) {
return await orNullIfFileNotExist(readJson(path.join(projectDir || process.cwd(), "package.json")))
export interface ConfigurationRequest {
projectDir: string
packageMetadata: Lazy<{ [key: string]: any } | null> | null
}

export async function getElectronWebpackConfig(projectDir?: string | null) {
const packageMetadata = await getPackageMetadata(projectDir)
return ((await getConfig({
export async function getElectronWebpackConfiguration(context: ConfigurationRequest): Promise<ElectronWebpackConfiguration> {
const result = await getConfig({
packageKey: "electronWebpack",
configFilename: "electron-webpack",
projectDir: projectDir || process.cwd(),
packageMetadata: new Lazy(() => Promise.resolve(packageMetadata))
})) || {} as any).result || {}
projectDir: context.projectDir,
packageMetadata: context.packageMetadata
})
const configuration: ElectronWebpackConfiguration = result == null || result.result == null ? {} : result.result
if (configuration.commonDistDirectory == null) {
configuration.commonDistDirectory = "dist"
}
if (configuration.commonSourceDirectory == null) {
configuration.commonSourceDirectory = "src/common"
}
return configuration
}
9 changes: 6 additions & 3 deletions packages/electron-webpack/src/dev/dev-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { readdir, remove } from "fs-extra-p"
import * as path from "path"
import "source-map-support/register"
import webpack, { Compiler } from "webpack"
import { getElectronWebpackConfiguration, getPackageMetadata } from "../config"
import { HmrServer } from "../electron-main-hmr/HmrServer"
import { configure } from "../main"
import { getFreePort, orNullIfFileNotExist } from "../util"
import { DelayedFunction, getCommonEnv, logError, logProcess, logProcessErrorOutput } from "./devUtil"
import { startRenderer } from "./WebpackDevServerManager"
import { getElectronWebpackConfig } from "../config"

const projectDir = process.cwd()

Expand All @@ -20,8 +20,11 @@ const debug = require("debug")("electron-webpack")

// do not remove main.js to allow IDE to keep breakpoints
async function emptyMainOutput() {
const electronWebpackConfig = await getElectronWebpackConfig()
const outDir = path.join(projectDir, electronWebpackConfig.commonDistDirectory || "dist", "main")
const electronWebpackConfig = await getElectronWebpackConfiguration({
projectDir,
packageMetadata: getPackageMetadata(projectDir),
})
const outDir = path.join(projectDir, electronWebpackConfig.commonDistDirectory!!, "main")
const files = await orNullIfFileNotExist(readdir(outDir))
if (files == null) {
return
Expand Down
18 changes: 12 additions & 6 deletions packages/electron-webpack/src/electron-builder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { getElectronWebpackConfig } from "./config"
import { Lazy } from "lazy-val"
import { getElectronWebpackConfiguration } from "./config"

export default async function() {
const electronWebpackConfig = await getElectronWebpackConfig()
interface Context {
projectDir: string
packageMetadata: Lazy<{ [key: string]: any } | null> | null
}

export default async function(context: Context) {
const electronWebpackConfig = await getElectronWebpackConfiguration(context)
return {
extraMetadata: {
main: "main.js"
Expand All @@ -12,13 +18,13 @@ export default async function() {
filter: ["package.json"]
},
{
from: electronWebpackConfig.commonDistDirectory + "/main"
from: `${electronWebpackConfig.commonDistDirectory}/main`
},
{
from: electronWebpackConfig.commonDistDirectory + "/renderer"
from: `${electronWebpackConfig.commonDistDirectory}/renderer`
},
{
from: electronWebpackConfig.commonDistDirectory + "/renderer-dll"
from: `${electronWebpackConfig.commonDistDirectory}/renderer-dll`
}
],
extraResources: [
Expand Down
23 changes: 13 additions & 10 deletions packages/electron-webpack/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { deepAssign } from "read-config-file/out/deepAssign"
import "source-map-support/register"
import { Configuration, Plugin, RuleSetRule } from "webpack"
import merge from "webpack-merge"
import { getElectronWebpackConfiguration, getPackageMetadata } from "./config"
import { configureTypescript } from "./configurators/ts"
import { configureVue } from "./configurators/vue/vue"
import { ConfigurationEnv, ConfigurationType, ElectronWebpackConfiguration, PackageMetadata, PartConfiguration } from "./core"
import { BaseTarget } from "./targets/BaseTarget"
import { MainTarget } from "./targets/MainTarget"
import { BaseRendererTarget, RendererTarget } from "./targets/RendererTarget"
import { getFirstExistingFile } from "./util"
import { getElectronWebpackConfig, getPackageMetadata } from "./config"

export { ElectronWebpackConfiguration } from "./core"

Expand Down Expand Up @@ -109,9 +109,8 @@ export class WebpackConfigurator {

this.sourceDir = this.getSourceDirectory(this.type)!!

const commonSourceDirectory = this.electronWebpackConfiguration.commonSourceDirectory
this.commonSourceDirectory = commonSourceDirectory == null ? path.join(this.projectDir, "src", "common") : path.resolve(this.projectDir, commonSourceDirectory)
this.commonDistDirectory = path.resolve(this.projectDir, this.electronWebpackConfiguration.commonDistDirectory || "dist")
this.commonSourceDirectory = path.resolve(this.projectDir, this.electronWebpackConfiguration.commonSourceDirectory!!)
this.commonDistDirectory = path.resolve(this.projectDir, this.electronWebpackConfiguration.commonDistDirectory!!)
}

/**
Expand Down Expand Up @@ -302,10 +301,15 @@ export async function createConfigurator(type: ConfigurationType, env: Configura
}

if (env == null) {
env = {}
}
const projectDir = (env.configuration || {}).projectDir
const electronWebpackConfig = await getElectronWebpackConfig(projectDir)
env = {}
}

const projectDir = (env.configuration || {}).projectDir || process.cwd()
const packageMetadata = getPackageMetadata(projectDir)
const electronWebpackConfig = await getElectronWebpackConfiguration({
packageMetadata,
projectDir,
})
if (env.configuration != null) {
deepAssign(electronWebpackConfig, env.configuration)
}
Expand All @@ -320,8 +324,7 @@ How to fix:
* Found? Check that the option in the appropriate place. e.g. "sourceDirectory" only in the "main" or "renderer", not in the root.
`
})
const packageMetadata = await getPackageMetadata(projectDir)
return new WebpackConfigurator(type, env, electronWebpackConfig, packageMetadata)
return new WebpackConfigurator(type, env, electronWebpackConfig, await packageMetadata.value)
}

export async function configure(type: ConfigurationType, env: ConfigurationEnv | null): Promise<Configuration | null> {
Expand Down
84 changes: 42 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,9 @@ acorn@^5.0.0, acorn@^5.5.3, acorn@^5.6.2:
integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==

acorn@^6.0.1, acorn@^6.0.2:
version "6.0.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.2.tgz#6a459041c320ab17592c6317abbfdf4bbaa98ca4"
integrity sha512-GXmKIvbrN3TV7aVqAzVFaMW8F8wzVX7voEBRO3bDA64+EX37YSayggRJP5Xig6HYHBkWKpFg9W5gg6orklubhg==
version "6.0.4"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.0.4.tgz#77377e7353b72ec5104550aa2d2097a2fd40b754"
integrity sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg==

ajv-errors@^1.0.0:
version "1.0.0"
Expand All @@ -919,10 +919,10 @@ ajv@^5.3.0:
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

ajv@^6.1.0, ajv@^6.5.3, ajv@^6.5.4:
version "6.5.4"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.5.4.tgz#247d5274110db653706b550fcc2b797ca28cfc59"
integrity sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==
ajv@^6.1.0, ajv@^6.5.3, ajv@^6.5.5:
version "6.5.5"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.5.5.tgz#cf97cdade71c6399a92c6d6c4177381291b781a1"
integrity sha512-7q7gtRQDJSyuEHjuVgHoUa2VuemFiCMrfQc9Tc08XTAc4Zj/5U1buQJ0HU6i7fKjXU09SVgSmxa4sLvuvS8Iyg==
dependencies:
fast-deep-equal "^2.0.1"
fast-json-stable-stringify "^2.0.0"
Expand Down Expand Up @@ -1790,9 +1790,9 @@ cacache@^10.0.4:
y18n "^4.0.0"

cacache@^11.0.2:
version "11.2.0"
resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.2.0.tgz#617bdc0b02844af56310e411c0878941d5739965"
integrity sha512-IFWl6lfK6wSeYCHUXh+N1lY72UDrpyrYQJNIVQf48paDuWbv5RbAtJYf/4gUQFObTCHZwdZ5sI8Iw7nqwP6nlQ==
version "11.3.1"
resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.3.1.tgz#d09d25f6c4aca7a6d305d141ae332613aa1d515f"
integrity sha512-2PEw4cRRDu+iQvBTTuttQifacYjLPhET+SYO/gEFMy8uhi+jlJREDAjSF5FWSdV/Aw5h18caHA7vMTw2c+wDzA==
dependencies:
bluebird "^3.5.1"
chownr "^1.0.1"
Expand Down Expand Up @@ -1870,14 +1870,14 @@ caniuse-api@^1.5.2:
lodash.uniq "^4.5.0"

caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639:
version "1.0.30000904"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000904.tgz#04bed67e344339f66ac4fb502d2047346959849b"
integrity sha512-iZ36AxtEx7ZiCBKhF2qFL8ED6u9zJGPU7Aq6HwZQYUbetBgYkGZfoPHq9z38jahV2kr8BgDYfXvftA35Ng2AaA==
version "1.0.30000906"
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000906.tgz#9a9e43b8690f9a0937c9fdf5e4699eee8516b982"
integrity sha512-PrxbTWezapS26wYU+lgGKLW7QTr5QrUWDunjlHOQ1qBoHDJruHGb9pdDKFOI1nUnkudSDPhNoan2FW0vMlwFvA==

caniuse-lite@^1.0.30000899:
version "1.0.30000904"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000904.tgz#4445d00da859a0e0ae6dbb2876c545f3324f6c74"
integrity sha512-M4sXvogCoY5Fp6fuXIaQG/MIexlEFQ3Lgwban+KlqiQUbUIkSmjAB8ZJIP79aj2cdqz2F1Lb+Z+5GwHvCrbLtg==
version "1.0.30000906"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000906.tgz#7c44e498a2504f7a5db3b4f91285bbc821157a77"
integrity sha512-ME7JFX6h0402om/nC/8Lw+q23QvPe2ust9U0ntLmkX9F2zaGwq47fZkjlyHKirFBuq1EM+T/LXBcDdW4bvkCTA==

capture-exit@^1.2.0:
version "1.2.0"
Expand Down Expand Up @@ -1968,7 +1968,7 @@ chokidar@^2.0.0, chokidar@^2.0.2, chokidar@^2.0.4:
optionalDependencies:
fsevents "^1.2.2"

chownr@^1.0.1:
chownr@^1.0.1, chownr@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.1.tgz#54726b8b8fff4df053c42187e801fb4412df1494"
integrity sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==
Expand Down Expand Up @@ -3909,9 +3909,9 @@ globby@^6.1.0:
pinkie-promise "^2.0.0"

graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
version "4.1.14"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.14.tgz#1b6e8362ef8c5ecb5da799901f39297e3054773a"
integrity sha512-ns/IGcSmmGNPP085JCheg0Nombh1QPvSCnlx+2V+byQWRQEIL4ZB5jXJMNIHOFVS1roi85HIi5Ka0h43iWXfcQ==
version "4.1.15"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==

"graceful-readlink@>= 1.0.0":
version "1.0.1"
Expand Down Expand Up @@ -5750,15 +5750,15 @@ minimist@~0.0.1:
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=

minipass@^2.2.1, minipass@^2.3.3:
minipass@^2.2.1, minipass@^2.3.4:
version "2.3.5"
resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.3.5.tgz#cacebe492022497f656b0f0f51e2682a9ed2d848"
integrity sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==
dependencies:
safe-buffer "^5.1.2"
yallist "^3.0.0"

minizlib@^1.1.0:
minizlib@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-1.1.1.tgz#6734acc045a46e61d596a43bb9d9cd326e19cc42"
integrity sha512-TrfjCjk4jLhcJyGMYymBH6oTXcWjYbUAXTHDbtnWHjZC25h0cdajHuPE1zxb4DVmu8crfh+HwH/WMuyLG0nHBg==
Expand Down Expand Up @@ -7084,12 +7084,12 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

read-config-file@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/read-config-file/-/read-config-file-3.1.3.tgz#8eae6e6688d5a4721c473cf47f2ea8727aa0501a"
integrity sha512-KVrZEmKOntnHqQFk69rw45A4oQ2npIMdKga4CcD8Yr38FQeYlE4S1JLFY9cll+vf0kVtSXDPperuQWEQto1jgQ==
read-config-file@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/read-config-file/-/read-config-file-3.2.0.tgz#50a2756a9a128ab9dcbe087e2724c512e3d0ccd1"
integrity sha512-i1QRc5jy4sHm9YBGb6ArA5SU1mDrc5wu2mnm3r9gPnm+LVZhBGbpTCKqAXyvV4TJHnBR3Yaaww+9b3DyRZcfww==
dependencies:
ajv "^6.5.4"
ajv "^6.5.5"
ajv-keywords "^3.2.0"
bluebird-lst "^1.0.6"
dotenv "^6.1.0"
Expand Down Expand Up @@ -8127,14 +8127,14 @@ tapable@^1.0.0, tapable@^1.1.0:
integrity sha512-IlqtmLVaZA2qab8epUXbVWRn3aB1imbDMJtjB3nu4X0NqPkcY/JH9ZtCBWKHWPxs8Svi9tyo8w2dBoi07qZbBA==

tar@^4:
version "4.4.6"
resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.6.tgz#63110f09c00b4e60ac8bcfe1bf3c8660235fbc9b"
integrity sha512-tMkTnh9EdzxyfW+6GK6fCahagXsnYk6kE6S9Gr9pjVdys769+laCTbodXDhPAjzVtEBazRgP0gYqOjnk9dQzLg==
version "4.4.7"
resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.7.tgz#14df45023ffdcd0c233befa2fc01ebb76ee39e7c"
integrity sha512-mR3MzsCdN0IEWjZRuF/J9gaWHnTwOvzjqPTcvi1xXgfKTDQRp39gRETPQEfPByAdEOGmZfx1HrRsn8estaEvtA==
dependencies:
chownr "^1.0.1"
chownr "^1.1.1"
fs-minipass "^1.2.5"
minipass "^2.3.3"
minizlib "^1.1.0"
minipass "^2.3.4"
minizlib "^1.1.1"
mkdirp "^0.5.0"
safe-buffer "^5.1.2"
yallist "^3.0.2"
Expand Down Expand Up @@ -8304,9 +8304,9 @@ trim-right@^1.0.1:
integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=

ts-babel@^6.0.2:
version "6.1.0"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-6.1.0.tgz#e9c57ddcea08e22e55a4feceadf6f32bf39d698e"
integrity sha512-OBJAYn0Hhfdk6xcPhsxRK7ySqMikrHP1G81jRcQGx06wlau8VgzoDt/X0ZDr8SmshfEYsLlWIfh1YHEXtc0b7A==
version "6.1.2"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-6.1.2.tgz#e3f91512159533f99713580b3a5e42c8b32b012e"
integrity sha512-bqa2rON0e797OUSHJ3NNkd/NTgb5fmqs4t/0/Ni2KM3atjAV36LSP8Cw+SpxH1C1ui7toGFei1sLQRqQ5BhhJw==
dependencies:
"@babel/core" "^7.1.2"
bluebird-lst "^1.0.6"
Expand Down Expand Up @@ -8578,9 +8578,9 @@ url-loader@^1.1.2:
schema-utils "^1.0.0"

url-parse@^1.4.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.3.tgz#bfaee455c889023219d757e045fa6a684ec36c15"
integrity sha512-rh+KuAW36YKo0vClhQzLLveoj8FwPJNu65xLb7Mrt+eZht0IPT0IXgSv8gcMegZ6NvjJUALf6Mf25POlMwD1Fw==
version "1.4.4"
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.4.tgz#cac1556e95faa0303691fec5cf9d5a1bc34648f8"
integrity sha512-/92DTTorg4JjktLNLe6GPS2/RvAd/RGr6LuktmWSMLEOa6rjnlrFXNgSbSmkNvCoL2T028A0a1JaJLzRMlFoHg==
dependencies:
querystringify "^2.0.0"
requires-port "^1.0.0"
Expand Down Expand Up @@ -8859,9 +8859,9 @@ webpack-sources@^1.1.0, webpack-sources@^1.3.0:
source-map "~0.6.1"

webpack@^4.17.1:
version "4.24.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.24.0.tgz#d9822c91eeb595f7351aa5dd785a1952f9c4340a"
integrity sha512-Xur0l8nBETnW+DjpFqSGME1jNXxEPVETl30k1lWAsbnukVJdq330/i3PDOLPUtVl/E/cciiOp5uW098hFfQLQA==
version "4.25.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.25.1.tgz#4f459fbaea0f93440dc86c89f771bb3a837cfb6d"
integrity sha512-T0GU/3NRtO4tMfNzsvpdhUr8HnzA4LTdP2zd+e5zd6CdOH5vNKHnAlO+DvzccfhPdzqRrALOFcjYxx7K5DWmvA==
dependencies:
"@webassemblyjs/ast" "1.7.11"
"@webassemblyjs/helper-module-context" "1.7.11"
Expand Down

0 comments on commit ffe3b8f

Please sign in to comment.