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

refactor(maker-squirrel): ensure Squirrel.Windows name doesn't contain hyphens #3004

Merged
merged 4 commits into from
Oct 27, 2022
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
5 changes: 0 additions & 5 deletions packages/api/core/src/api/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import fs from 'fs-extra';
import { merge } from 'lodash';

import { updateElectronDependency } from '../util/electron-version';
import { setInitialForgeConfig } from '../util/forge-config';
import installDepList, { DepType, DepVersionRestriction } from '../util/install-dependencies';
import { info, warn } from '../util/messages';
import { readRawPackageJson } from '../util/read-package-json';
Expand Down Expand Up @@ -204,10 +203,6 @@ export default async ({
packageJSON.config.forge = templatePackageJSON.config.forge;
}

if (typeof packageJSON.config.forge !== 'string') {
setInitialForgeConfig(packageJSON);
}

await writeChanges();

await asyncOra('Fixing .gitignore', async () => {
Expand Down
5 changes: 0 additions & 5 deletions packages/api/core/src/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import path from 'path';
import { asyncOra } from '@electron-forge/async-ora';
import { ForgeTemplate } from '@electron-forge/shared-types';
import debug from 'debug';
import fs from 'fs-extra';
import semver from 'semver';

import { setInitialForgeConfig } from '../util/forge-config';
import installDepList, { DepType } from '../util/install-dependencies';
import { readRawPackageJson } from '../util/read-package-json';

Expand Down Expand Up @@ -66,9 +64,6 @@ export default async ({ dir = process.cwd(), interactive = false, copyCIFiles =

if (typeof templateModule.initializeTemplate === 'function') {
await templateModule.initializeTemplate(dir, { copyCIFiles });
const packageJSON = await readRawPackageJson(dir);
setInitialForgeConfig(packageJSON);
await fs.writeJson(path.join(dir, 'package.json'), packageJSON, { spaces: 2 });
}

await asyncOra('Installing Template Dependencies', async () => {
Expand Down
9 changes: 0 additions & 9 deletions packages/api/core/src/util/forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@ const proxify = <T extends ProxiedObject>(buildIdentifier: string | (() => strin
};
/* eslint-enable @typescript-eslint/no-explicit-any */

/**
* Sets sensible defaults for the `config.forge` object.
*/
export function setInitialForgeConfig(packageJSON: PackageJSONForInitialForgeConfig): void {
const { name = '' } = packageJSON;

((packageJSON.config.forge as ForgeConfig).makers as IForgeResolvableMaker[])[0].config.name = name.replace(/-/g, '_');
}

export type BuildIdentifierMap<T> = Record<string, T | undefined>;
export type BuildIdentifierConfig<T> = {
map: BuildIdentifierMap<T>;
Expand Down
48 changes: 1 addition & 47 deletions packages/api/core/test/fast/forge-config_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import path from 'path';
import { ResolvedForgeConfig } from '@electron-forge/shared-types';
import { expect } from 'chai';

import findConfig, {
forgeConfigIsValidFilePath,
PackageJSONForInitialForgeConfig,
renderConfigTemplate,
setInitialForgeConfig,
} from '../../src/util/forge-config';
import findConfig, { forgeConfigIsValidFilePath, renderConfigTemplate } from '../../src/util/forge-config';

const defaults = {
packagerConfig: {},
Expand Down Expand Up @@ -219,45 +214,4 @@ describe('forge-config', () => {
});
});
});

describe('setInitialForgeConfig', () => {
it('should normalize hyphens in maker names to underscores', () => {
const packageJSON: PackageJSONForInitialForgeConfig = {
name: 'foo-bar',
config: {
forge: {
makers: [
{
name: '@electron-forge/maker-test',
config: {
name: 'will be overwritten',
},
},
],
},
},
};
setInitialForgeConfig(packageJSON);
expect(packageJSON.config.forge.makers[0].config.name).to.equal('foo_bar');
});

it('should handle when package.json name is not set', () => {
const packageJSON = {
config: {
forge: {
makers: [
{
name: '@electron-forge/maker-test',
config: {
name: 'will be overwritten',
},
},
],
},
},
};
setInitialForgeConfig(packageJSON);
expect(packageJSON.config.forge.makers[0].config.name).to.equal('');
});
});
});
14 changes: 1 addition & 13 deletions packages/api/core/test/slow/api_spec_slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,8 @@ for (const nodeInstaller of ['npm', 'yarn']) {

await forge.import({ dir });

const {
config: {
forge: {
makers: [
{
config: { name: winstallerName },
},
],
},
},
customProp,
} = await readRawPackageJson(dir);
const { customProp } = await readRawPackageJson(dir);

expect(winstallerName).to.equal('Name');
expect(customProp).to.equal('propVal');
});

Expand Down
2 changes: 1 addition & 1 deletion packages/maker/squirrel/src/MakerSquirrel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class MakerSquirrel extends MakerBase<MakerSquirrelConfig> {
await this.ensureDirectory(outPath);

const winstallerConfig: ElectronWinstallerOptions = {
name: packageJSON.name,
name: typeof packageJSON.name === 'string' ? packageJSON.name.replace(/-/g, '_') : undefined, // squirrel hates hyphens
title: appName,
noMsi: true,
exe: `${forgeConfig.packagerConfig.executableName || appName}.exe`,
Expand Down
4 changes: 1 addition & 3 deletions packages/template/base/tmpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
"makers": [
{
"name": "@electron-forge/maker-squirrel",
"config": {
"name": ""
}
"config": {}
},
{
"name": "@electron-forge/maker-zip",
Expand Down