Skip to content

Commit

Permalink
refactor: use listr2 for the package, make and publish commands (#3043)
Browse files Browse the repository at this point in the history
* refactor: use listr2 for the package command

* chore: fix tests

* refactor: use listr2 for the make command

* refactor: use listr2 for the publish command

* refactor: remove actualTargetPlatform because it is silly

* build: shared-types should not depend on ora

* spec: fix tests

* chore: remove dead code in publish
  • Loading branch information
MarshallOfSound committed Nov 3, 2022
1 parent 55b37ca commit aca89f4
Show file tree
Hide file tree
Showing 45 changed files with 1,277 additions and 800 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ packages/**/.swc
.webpack
packages/api/core/test/fixture/app-with-scoped-name/out/make
packages/plugin/webpack/test/fixtures/apps/native-modules/package-lock.json
.links
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ packages/*/*/README.md
packages/*/*/tsconfig.json
packages/api/core/test/fixture/bad_external_forge_config/bad.js
packages/plugin/webpack/test/**/.webpack
.links
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"scripts": {
"clean": "rimraf dist && bolt ws exec -- rimraf dist tsconfig.tsbuildinfo",
"build": "bolt ws exec -- tsc --emitDeclarationOnly && bolt ws exec -- swc src --out-dir dist --quiet --extensions \".ts\" --config-file ../../../.swcrc",
"build": "bolt ws exec -- tsc --emitDeclarationOnly && bolt build:fast",
"build:fast": "bolt ws exec -- swc src --out-dir dist --quiet --extensions \".ts\" --config-file ../../../.swcrc",
"build:full": "bolt ws exec -- tsc -b",
"postbuild": "ts-node tools/test-dist",
"coverage:fast": "xvfb-maybe cross-env INTEGRATION_TESTS=0 TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 nyc mocha './tools/test-globber.ts' && nyc report --reporter=text-lcov > coverage.lcov",
Expand All @@ -30,6 +31,7 @@
"docs:deploy:build": "bolt docs",
"lint": "prettier --check . && eslint .",
"lint:fix": "prettier --write .",
"link:prepare": "bolt ws exec -- node ../../../tools/silent.js yarn link --link-folder ../../../.links --silent --no-bin-links",
"test": "xvfb-maybe cross-env TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 mocha './tools/test-globber.ts'",
"test:fast": "xvfb-maybe cross-env TS_NODE_PROJECT='./tsconfig.test.json' TEST_FAST_ONLY=1 TS_NODE_FILES=1 mocha './tools/test-globber.ts'",
"preinstall": "node ./tools/maybe-shim-windows.js",
Expand Down
1 change: 0 additions & 1 deletion packages/api/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"mocha": "^9.0.1"
},
"dependencies": {
"@electron-forge/async-ora": "6.0.0",
"@electron-forge/core": "6.0.0",
"@electron-forge/shared-types": "6.0.0",
"@electron/get": "^2.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/api/core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class ForgeAPI {
/**
* Resolves hooks if they are a path to a file (instead of a `Function`)
*/
package(opts: PackageOptions): Promise<void> {
return _package(opts);
async package(opts: PackageOptions): Promise<void> {
await _package(opts);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/api/core/src/api/init-scripts/find-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const findTemplate = async (dir: string, template: string): Promise<Forge
throw new Error(`Failed to locate custom template: "${template}"\n\nTry \`npm install -g @electron-forge/template-${template}\``);
}

d(`found template module at: ${templateModulePath}`);

// eslint-disable-next-line @typescript-eslint/no-var-requires
const templateModule: PossibleModule<ForgeTemplate> = require(templateModulePath);

Expand Down
18 changes: 17 additions & 1 deletion packages/api/core/src/api/init-scripts/init-npm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from 'path';

import { safeYarnOrNpm } from '@electron-forge/core-utils';
import { safeYarnOrNpm, yarnOrNpmSpawn } from '@electron-forge/core-utils';
import { ForgeListrTask } from '@electron-forge/shared-types';
import debug from 'debug';
import fs from 'fs-extra';

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

const d = debug('electron-forge:init:npm');
const corePackage = fs.readJsonSync(path.resolve(__dirname, '../../../package.json'));
Expand Down Expand Up @@ -33,4 +34,19 @@ export const initNPM = async (dir: string, task: ForgeListrTask<any>): Promise<v
task.output = `${packageManager} install --dev --exact ${packageName}`;
await installDepList(dir, [packageName], DepType.DEV, DepVersionRestriction.EXACT);
}

// This logic allows developers working on forge itself to easily init
// a local template and have it use their local plugins / core / cli packages
if (process.env.LINK_FORGE_DEPENDENCIES_ON_INIT) {
const packageJson = await readRawPackageJson(dir);
const linkFolder = path.resolve(__dirname, '..', '..', '..', '..', '..', '..', '.links');
for (const packageName of Object.keys(packageJson.devDependencies)) {
if (packageName.startsWith('@electron-forge/')) {
task.output = `${packageManager} link --link-folder ${linkFolder} ${packageName}`;
await yarnOrNpmSpawn(['link', '--link-folder', linkFolder, packageName], {
cwd: dir,
});
}
}
}
};
Loading

0 comments on commit aca89f4

Please sign in to comment.