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: typescript projects & docs generation #2804

Merged
merged 26 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b2b29f5
remove use of now
clavin Mar 2, 2022
5b4729d
fix: scoped package typings
clavin Mar 2, 2022
d2dcc36
modernize typescript projects
clavin Apr 13, 2022
78fb575
add script to generate docs
clavin Apr 13, 2022
66e2dab
ignore .swc dir in packages
clavin Apr 18, 2022
433c364
fix testing
clavin Apr 18, 2022
175b708
rename test tsconfig to be more clear
clavin Apr 18, 2022
6a3648d
make tsconfig.test.json prettier
clavin Apr 18, 2022
bc3d645
turn off some lints on non-published code
clavin Apr 18, 2022
d7fe64e
fix package manifest typing
clavin Apr 18, 2022
8670e1f
fix linting with glue
clavin Apr 20, 2022
815597c
async iife error catching
clavin Apr 20, 2022
aba2536
Merge branch 'master' into clavin/fix-docs-deploy
clavin Apr 21, 2022
a75285d
fix yarn.lock
clavin Apr 21, 2022
55bb7b7
fix quick build
clavin Apr 21, 2022
00b9eb3
restore old eslintrc
clavin Apr 21, 2022
72ed3e9
fix coverage commands
clavin Apr 21, 2022
1789a99
fix coverage & repurpose glue
clavin Apr 21, 2022
3776b56
nope nvm do not restore the old eslintrc
clavin Apr 21, 2022
6fa4324
build on slow ci tests
clavin Apr 21, 2022
d99640a
Merge branch 'master' of github.com:electron-userland/electron-forge …
clavin Apr 21, 2022
33a5384
fix ts glue for windows
clavin Apr 21, 2022
7eaed08
make ts glue import target relative
clavin Apr 21, 2022
32e71c1
don't re-enable WIP docs CI
clavin Apr 22, 2022
43cf0f1
build: add Action for GitHub Pages deploy (#2827)
erickzhao Apr 29, 2022
1f056b0
remove prototype docs ci workflow
clavin May 2, 2022
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
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"files": ["packages/*/*/test/**/*_spec*.ts"],
"rules": {
"global-require": "off",
"import/no-dynamic-require": "off"
"import/no-dynamic-require": "off",
"node/no-unpublished-import": "off",
"node/no-unpublished-require": "off"
}
},
{
Expand Down
25 changes: 10 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ jobs:
npm install -g bolt@$BOLT_VERSION
- name: Install
run: bolt
- name: Build
run: bolt build
- name: Test
run: bolt coverage:slow
env:
Expand Down Expand Up @@ -160,21 +162,14 @@ jobs:
# needs: [fast-tests, slow-tests]
clavin marked this conversation as resolved.
Show resolved Hide resolved
# runs-on: [ubuntu-latest]
# steps:
# - uses: actions/checkout@v1
# - name: Use Node.js 12.x
# uses: actions/setup-node@v2.5.1
# - name: Checkout
# uses: actions/checkout@v1
# - name: Use Node.js 16
# uses: actions/setup-node@v3.1.1
# with:
# node-version: 12.x
# node-version: '16'
# cache: yarn
# - name: Install bolt
# shell: bash
# run: |
# case "$(uname -s)" in
# Windows*|CYGWIN*|MINGW*|MSYS*) BOLT_VERSION=0.21.2 ;;
# *) BOLT_VERSION=latest ;;
# esac
# npm install -g bolt@$BOLT_VERSION
# - name: Deploy docs
# run: ci/docs.sh
# env:
# NOW_TOKEN: ${{ secrets.NOW_TOKEN }}
# run: npm install -g bolt
# - name: Generate docs
# run: bolt docs:deploy:build
45 changes: 45 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: GitHub Pages

on:
push:
branches:
- master
pull_request:

jobs:
deploy:
runs-on: ubuntu-20.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Use Node.js LTS
uses: actions/setup-node@v2.5.1
with:
node-version: 16.x
cache: yarn

- name: Install Bolt CLI
shell: bash
run: |
case "$(uname -s)" in
Windows*|CYGWIN*|MINGW*|MSYS*) BOLT_VERSION=0.21.2 ;;
*) BOLT_VERSION=latest ;;
esac
npm install -g bolt@$BOLT_VERSION

- name: Build
shell: bash
run: |
bolt
bolt docs

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
14 changes: 6 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ docs
doc
node_modules
yarn-error.log
**/.npmignore
!/.npmignore
**/tsconfig.json
!/tsconfig.json
packages/**/.npmignore
packages/**/tsconfig.json
!packages/template/*/tmpl/tsconfig.json
**/tslint.json
!/tslint.json
**/yarn.lock
!/yarn.lock
packages/**/tslint.json
packages/**/yarn.lock
packages/*/*/index.ts
packages/.old
packages/utils/types/index.d.ts
Expand All @@ -25,4 +21,6 @@ packages/plugin/**/README.md
packages/api/cli/README.md
!packages/**/base/README.md
!/README.md
packages/**/tsconfig.tsbuildinfo
packages/**/.swc
.webpack
3 changes: 1 addition & 2 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const path = require('path');

module.exports = {
extension: ['ts'],
loader: 'ts-node/esm',
require: [path.join(__dirname, 'tools', 'test-setup.ts')],
require: ['ts-node/register', path.join(__dirname, 'tools', 'test-setup.ts')],
timeout: 800000,
recursive: true,
};
5 changes: 0 additions & 5 deletions .now.json

This file was deleted.

7 changes: 0 additions & 7 deletions ci/docs.sh

This file was deleted.

29 changes: 13 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
]
},
"scripts": {
"clean": "rimraf dist && bolt ws exec -- rimraf dist",
"prebuild": "bolt clean && ts-node tools/link-ts.ts && ts-node tools/copy-shared-types.ts && tsc --project ./tsconfig.packages.json --emitDeclarationOnly && ts-node tools/copy-types.ts",
"build": "yarn build:quick",
"build:quick": "bolt ws exec -- swc src --out-dir dist --quiet --extensions \".ts\" --config-file ../../../.swcrc",
"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:full": "bolt ws exec -- tsc -b",
Copy link
Member Author

@clavin clavin Apr 15, 2022

Choose a reason for hiding this comment

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

I changed the set of build commands from build:quick and build (which just calls the former) to build (same as build:quick before) and build:full which makes a full typescript build, along with generated types, which I think should be in the distributed packages.

"postbuild": "ts-node tools/test-dist",
"coverage:fast": "xvfb-maybe cross-env INTEGRATION_TESTS=0 TS_NODE_FILES=true nyc mocha './tools/test-globber.ts' && nyc report --reporter=text-lcov > coverage.lcov",
"coverage:slow": "xvfb-maybe cross-env TS_NODE_FILES=true nyc mocha './tools/test-globber.ts' --integration && nyc report --reporter=text-lcov > coverage.lcov",
"docs": "bolt docs:generate && bolt docs:position",
"docs:generate": "bolt ws exec -- node_modules/.bin/typedoc --out doc --excludeExternals --ignoreCompilerErrors --mode file --excludePrivate --excludeProtected --hideGenerator",
"docs:position": "ts-node tools/position-docs.ts",
"docs:deploy": "ts-node tools/sync-readmes.ts && bolt docs && ts-node tools/copy-now.ts && cd docs && now && now alias",
"docs:deploy:ci": "ts-node tools/sync-readmes.ts && bolt docs && ts-node tools/copy-now.ts && cd docs && now --token $NOW_TOKEN && now alias --token $NOW_TOKEN",
"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",
"coverage:slow": "xvfb-maybe cross-env TS_NODE_PROJECT='./tsconfig.test.json' TS_NODE_FILES=1 nyc mocha './tools/test-globber.ts' --integration && nyc report --reporter=text-lcov > coverage.lcov",
"docs": "bolt build:full && bolt docs:generate",
"docs:generate": "node --max-old-space-size=8192 -r ts-node/register ./tools/gen-docs.ts",
"docs:deploy:build": "ts-node tools/sync-readmes.ts && bolt docs",
"lint": "prettier --check . && eslint .",
"test": "xvfb-maybe cross-env TS_NODE_FILES=true mocha './tools/test-globber.ts'",
"test:fast": "xvfb-maybe cross-env TEST_FAST_ONLY=1 TS_NODE_FILES=true mocha './tools/test-globber.ts'",
"postinstall": "rimraf node_modules/.bin/*.ps1 && ts-node tools/link-ts.ts"
"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'",
"postinstall": "rimraf node_modules/.bin/*.ps1 && ts-node ./tools/gen-tsconfigs.ts && ts-node ./tools/gen-ts-glue.ts"
},
"dependencies": {
"@aws-sdk/abort-controller": "^3.29.0",
Expand Down Expand Up @@ -141,8 +138,8 @@
"sinon": "^13.0.1",
"sinon-chai": "^3.6.0",
"ts-node": "^10.0.0",
"typedoc": "^0.22.0",
"typescript": "^4.5.4",
"typedoc": "^0.22.15",
"typescript": "^4.6.3",
"xvfb-maybe": "^0.2.1"
},
"optionalDependencies": {
Expand Down
1 change: 0 additions & 1 deletion packages/api/core/typings

This file was deleted.

2 changes: 1 addition & 1 deletion packages/installer/darwin/src/InstallerDarwin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default abstract class InstallerDarwin extends InstallerBase {
if (writeAccess) {
await promisify(exec)(moveCommand);
} else {
await promisify(sudo.exec)(moveCommand, {
await (promisify(sudo.exec) as (cmd: string, opts: unknown) => Promise<unknown>)(moveCommand, {
erickzhao marked this conversation as resolved.
Show resolved Hide resolved
name: 'Electron Forge',
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Samuel Attard",
"license": "MIT",
"main": "dist/index.js",
"typings": "index.d.ts",
"typings": "dist/index.d.ts",
"dependencies": {
"@electron-forge/async-ora": "6.0.0-beta.63",
"electron-packager": "^15.4.0",
Expand Down
9 changes: 0 additions & 9 deletions tools/copy-now.ts

This file was deleted.

10 changes: 0 additions & 10 deletions tools/copy-shared-types.ts

This file was deleted.

22 changes: 0 additions & 22 deletions tools/copy-types.ts

This file was deleted.

24 changes: 24 additions & 0 deletions tools/gen-docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as path from 'path';
import { getPackageInfo } from './utils';
import * as typedoc from 'typedoc';

(async () => {
const packages = await getPackageInfo();

const typedocApp = new typedoc.Application();
typedocApp.bootstrap({
entryPointStrategy: 'packages',
entryPoints: packages.map((pkg) => pkg.path),
excludeExternals: true,
excludePrivate: true,
excludeProtected: true,
hideGenerator: true,
});

const projReflection = typedocApp.convert();
if (projReflection === undefined) {
throw new Error('Failed to find package sources');
}

await typedocApp.generateDocs(projReflection, path.resolve(__dirname, '..', 'docs'));
})().catch(console.error);
68 changes: 68 additions & 0 deletions tools/gen-ts-glue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Mixing glue with lint is probably something you never want to do in real
* life, but in this project it helps the linter do its job. And sometimes the
* test suite too.
*
* This script creates `index.ts` files in each package directory that simply
* re-export the exports of the real main file. This is necessary for when all
* the packages are run under a common context (instead of each individually).
* This is because the symlinks bolt makes for each package are descendants of
Copy link
Member

@erickzhao erickzhao May 2, 2022

Choose a reason for hiding this comment

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

question(non-blocking): Interesting. So in theory when we move away from bolt in the future this would be unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think other tools will still have this issue. The issue stems from when we run a command on "all packages" (run from the project root and have it traverse into everything including the packages), which is in contrast to running a command "per-package" (running the command in every package with that package as the root).

This difference is significant because if you start in root/ and traverse down to root/packages/my-package/node_modules/symlink-to-my-other-package (a symlink) and that takes you to root/packages/my-other-package, you're still under the root context root/ which means that tooling will not look for a package.json file because it does not think you're checking a dependency. That is why the index file solution works, because the index file will be automatically checked when the dependency resolution thinks it's still under the root context (which is true because we chose the root to be the project, rather than a specific package).

Does that make more sense?

* the context node is running in and therefore aren't treated as modules, only
* as directories. Therefore package.json isn't considered and we need an index
* file (like index.ts) to redirect to the right file.
*/

import { promises as fs } from 'fs';
import path from 'path';
import { getPackageInfo } from './utils';

// NOTE: this interface only defines the fields in the package.json that are
// used in this script
interface PartialPackageManifest {
main?: string;
}

/**
* A heuristic to convert the `main` value from the package.json from its output
* location to the source location (e.g. dist/ to src/ & .js to .ts).
*/
function convertMainToSrc(main: string): string {
return main.replace(/^dist\//, 'src/').replace(/\.js$/, '.ts');
}

(async () => {
const pkgs = await getPackageInfo();

// Run each package in parallel
await Promise.all(
pkgs.map(async (pkg) => {
// Extract the `main` field from the package.json
const { main } = pkg.manifest as PartialPackageManifest;

// Skip packages that have no main (e.g. the cli as of writing)
if (main === undefined) {
return;
}

// Read the main file
const srcMain = convertMainToSrc(main);
const srcMainFull = path.resolve(pkg.path, srcMain);
const srcMainContents = await fs.readFile(srcMainFull, { encoding: 'utf8' });

// Detect if the package has a default export
const hasDefault = /export\s+default/i.test(srcMainContents);

// Write the facade entry-point file
const importTarget = './' + srcMain.replace(/\.ts$/, '');
const facadeFilePath = path.resolve(pkg.path, 'index.ts');
let facadeFileContents =
'// ⚠️ AUTOGENERATED ⚠️ AUTOGENERATED ⚠️ AUTOGENERATED ⚠️\n' +
'// This file was automatically generated by `tools/gen-ts-glue.ts`. Do not modify directly if you want to keep your changes.\n' +
`export * from "${importTarget}";\n`;
if (hasDefault) {
facadeFileContents += `import defaultExport from "${importTarget}";\n` + `export default defaultExport;\n`;
}
await fs.writeFile(facadeFilePath, facadeFileContents);
})
);
})().catch(console.error);
Loading