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: use listr2 for the package, make and publish commands #3043

Merged
merged 8 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
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
Comment on lines +38 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Any specific command devs can use to do this - is it LINK_FORGE_DEPENDENCIES_ON_INIT=true or running link:prepare? Just wondering if this is something we can document for future use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You run link:prepare and then when you call electron-forge-init.js manually you have this env var set so it links correctly

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