Skip to content

Commit

Permalink
Revert "feat: Support mjs files for lifecycle operations (#7442)"
Browse files Browse the repository at this point in the history
This reverts commit 37d6db3.
  • Loading branch information
mmaietta authored Mar 4, 2023
1 parent 37d6db3 commit 926602d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 38 deletions.
5 changes: 0 additions & 5 deletions .changeset/real-toes-beam.md

This file was deleted.

4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/codeSign/windowsCodeSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { computeToolEnv, ToolInfo } from "../util/bundledTool"
import { rename } from "fs-extra"
import * as os from "os"
import * as path from "path"
import { importFunction } from "../platformPackager"
import { resolveFunction } from "../platformPackager"
import { isUseSystemSigncode } from "../util/flags"
import { VmManager } from "../vm/vm"
import { WinPackager } from "../winPackager"
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function sign(options: WindowsSignOptions, packager: WinPackager):
hashes = Array.isArray(hashes) ? hashes : [hashes]
}

const executor = (await importFunction(options.options.sign, "sign")) || doSign
const executor = resolveFunction(options.options.sign, "sign") || doSign
let isNest = false
for (const hash of hashes) {
const taskConfiguration: WindowsSignTaskConfiguration = { ...options, hash, isNest }
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { log, InvalidConfigurationError } from "builder-util"
import { asArray } from "builder-util-runtime"
import { Packager } from "./packager"
import { PackagerOptions } from "./packagerApi"
import { importFunction } from "./platformPackager"
import { resolveFunction } from "./platformPackager"
import { PublishManager } from "./publish/PublishManager"

export { Packager, BuildResult } from "./packager"
Expand Down Expand Up @@ -76,7 +76,7 @@ export function build(options: PackagerOptions & PublishOptions, packager: Packa
process.once("SIGINT", sigIntHandler)

const promise = packager.build().then(async buildResult => {
const afterAllArtifactBuild = await importFunction(buildResult.configuration.afterAllArtifactBuild, "afterAllArtifactBuild")
const afterAllArtifactBuild = resolveFunction(buildResult.configuration.afterAllArtifactBuild, "afterAllArtifactBuild")
if (afterAllArtifactBuild != null) {
const newArtifacts = asArray(await Promise.resolve(afterAllArtifactBuild(buildResult)))
if (newArtifacts.length === 0 || !publishManager.isPublish) {
Expand Down
14 changes: 7 additions & 7 deletions packages/app-builder-lib/src/packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Framework } from "./Framework"
import { LibUiFramework } from "./frameworks/LibUiFramework"
import { Metadata } from "./options/metadata"
import { ArtifactBuildStarted, ArtifactCreated, PackagerOptions } from "./packagerApi"
import { PlatformPackager, importFunction } from "./platformPackager"
import { PlatformPackager, resolveFunction } from "./platformPackager"
import { ProtonFramework } from "./ProtonFramework"
import { computeArchToTargetNamesMap, createTargets, NoOpTarget } from "./targets/targetFactory"
import { computeDefaultAppDirectory, getConfig, validateConfig } from "./util/config"
Expand Down Expand Up @@ -257,7 +257,7 @@ export class Packager {
},
"building"
)
const handler = await importFunction(this.config.artifactBuildStarted, "artifactBuildStarted")
const handler = resolveFunction(this.config.artifactBuildStarted, "artifactBuildStarted")
if (handler != null) {
await Promise.resolve(handler(event))
}
Expand All @@ -271,7 +271,7 @@ export class Packager {
}

async callArtifactBuildCompleted(event: ArtifactCreated): Promise<void> {
const handler = await importFunction(this.config.artifactBuildCompleted, "artifactBuildCompleted")
const handler = resolveFunction(this.config.artifactBuildCompleted, "artifactBuildCompleted")
if (handler != null) {
await Promise.resolve(handler(event))
}
Expand All @@ -280,14 +280,14 @@ export class Packager {
}

async callAppxManifestCreated(path: string): Promise<void> {
const handler = await importFunction(this.config.appxManifestCreated, "appxManifestCreated")
const handler = resolveFunction(this.config.appxManifestCreated, "appxManifestCreated")
if (handler != null) {
await Promise.resolve(handler(path))
}
}

async callMsiProjectCreated(path: string): Promise<void> {
const handler = await importFunction(this.config.msiProjectCreated, "msiProjectCreated")
const handler = resolveFunction(this.config.msiProjectCreated, "msiProjectCreated")
if (handler != null) {
await Promise.resolve(handler(path))
}
Expand Down Expand Up @@ -503,7 +503,7 @@ export class Packager {
return
}

const beforeBuild = await importFunction(config.beforeBuild, "beforeBuild")
const beforeBuild = resolveFunction(config.beforeBuild, "beforeBuild")
if (beforeBuild != null) {
const performDependenciesInstallOrRebuild = await beforeBuild({
appDir: this.appDir,
Expand Down Expand Up @@ -532,7 +532,7 @@ export class Packager {
}

async afterPack(context: AfterPackContext): Promise<any> {
const afterPack = await importFunction(this.config.afterPack, "afterPack")
const afterPack = resolveFunction(this.config.afterPack, "afterPack")
const handlers = this.afterPackHandlers.slice()
if (afterPack != null) {
// user handler should be last
Expand Down
25 changes: 5 additions & 20 deletions packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
// Due to node-gyp rewriting GYP_MSVS_VERSION when reused across the same session, we must reset the env var: https://github.com/electron-userland/electron-builder/issues/7256
delete process.env.GYP_MSVS_VERSION

const beforePack = await importFunction(this.config.beforePack, "beforePack")
const beforePack = resolveFunction(this.config.beforePack, "beforePack")
if (beforePack != null) {
await beforePack({
appOutDir,
Expand Down Expand Up @@ -330,7 +330,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
electronPlatformName: platformName,
}
const didSign = await this.signApp(packContext, isAsar)
const afterSign = await importFunction(this.config.afterSign, "afterSign")
const afterSign = resolveFunction(this.config.afterSign, "afterSign")
if (afterSign != null) {
if (didSign) {
await Promise.resolve(afterSign(packContext))
Expand Down Expand Up @@ -752,23 +752,7 @@ export function normalizeExt(ext: string) {
return ext.startsWith(".") ? ext.substring(1) : ext
}

/**
* NOTE: this is required because tsc converts the following:
*
* ```ts
* await import("path/to/some/module");
* ```
*
* to
*
* ```ts
* Promise.resolve().then(() => require("path/to/some/module"))
* ```
*/
/* eslint-disable @typescript-eslint/no-implied-eval */
const importDynamic = new Function("modulePath", "return import(modulePath)")

export async function importFunction<T>(executor: T | string, name: string): Promise<T> {
export function resolveFunction<T>(executor: T | string, name: string): T {
if (executor == null || typeof executor !== "string") {
return executor
}
Expand All @@ -785,7 +769,8 @@ export async function importFunction<T>(executor: T | string, name: string): Pro
p = path.resolve(p)
}

const m = await importDynamic(p)
// eslint-disable-next-line @typescript-eslint/no-var-requires
const m = require(p)
const namedExport = m[name]
if (namedExport == null) {
return m.default || m
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/util/NodeModuleCopyHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { lstat, readdir } from "fs-extra"
import * as path from "path"
import { excludedNames, FileMatcher } from "../fileMatcher"
import { Packager } from "../packager"
import { importFunction } from "../platformPackager"
import { resolveFunction } from "../platformPackager"
import { FileCopyHelper } from "./AppFileWalker"

const excludedFiles = new Set(
Expand Down Expand Up @@ -42,7 +42,7 @@ export class NodeModuleCopyHelper extends FileCopyHelper {
const filter = this.filter
const metadata = this.metadata

const onNodeModuleFile = await importFunction(this.packager.config.onNodeModuleFile, "onNodeModuleFile")
const onNodeModuleFile = resolveFunction(this.packager.config.onNodeModuleFile, "onNodeModuleFile")

const result: Array<string> = []
const queue: Array<string> = []
Expand Down

0 comments on commit 926602d

Please sign in to comment.