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

merge queue: embarking main (e500574) and #4107 together #4179

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 7 additions & 0 deletions docs/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "docs",
"private": true,
"volta": {
"extends": "../../../package.json"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"devDependencies": {
"bump-pack": "workspace:^",
"generate-workspace": "workspace:^",
"turbo": "^1.10.13"
},
"scripts": {
Expand All @@ -14,7 +15,7 @@
"test:ci": "turbo default --color --concurrency 1 && turbo compile post-compile lint eslint test test:playwright --color --filter=!hangar",
"docs": "./scripts/docsite.sh",
"install": "bash scripts/setup_wasi.sh",
"postinstall": "link-bundles",
"postinstall": "link-bundles && generate-workspace",
"wing": "turbo compile --filter=winglang --output-logs=errors-only && ./apps/wing/bin/wing"
},
"volta": {
Expand Down
44 changes: 44 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ packages:
- "apps/*"
- "libs/*"
- "tools/*"
- "docs/docs"
- "apps/wing-console/packages/*"
- "apps/wing-console/console/*"
- "apps/wing-console/tools/*"
Expand Down
18 changes: 18 additions & 0 deletions tools/generate-workspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generate-Workspace CLI

The `generate-workspace` CLI is a tool that generates a Visual Studio Code [multi-root](https://code.visualstudio.com/docs/editor/multi-root-workspaces) workspace file based on the configuration of a pnpm [workspace](https://pnpm.io/workspaces).

![screenshot](./screenshot.png)

## How it works

The CLI scans the pnpm workspace configuration and creates a `wing.code-workspace` file that Visual Studio Code can use to open multiple projects in the same window. This is particularly useful in a monorepo setup where you might have multiple packages that you want to work with at the same time.

The generated workspace file includes all the packages in the pnpm workspace, except for those specified in the `ignoreList` in `cli.ts`. The names of the packages in the workspace file are either their actual package names or the names specified in the `nameMapping` in `cli.ts`, if present.

## Usage

To use the `generate-workspace` CLI, run the following command in your terminal in the this directory: `npx generate-workspace`



10 changes: 10 additions & 0 deletions tools/generate-workspace/bin/generate-workspace.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env -S node
const { execSync } = require("node:child_process");
const { resolve, relative } = require("node:path");

const which = require("npm-which")(__dirname);
const tsx = relative(process.cwd(), which.sync("tsx"));
const cliSource = relative(process.cwd(), resolve(__dirname, "../src/cli.ts"));
execSync(`${tsx} ${cliSource} ${process.argv.slice(2).join(" ")}`, {
stdio: "inherit",
});
30 changes: 30 additions & 0 deletions tools/generate-workspace/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "generate-workspace",
"version": "0.0.0",
"private": true,
"bin": {
"generate-workspace": "./bin/generate-workspace.cjs"
},
"exports": null,
"sideEffects": false,
"files": [
"dist"
],
"type": "module",
"scripts": {},
"devDependencies": {
"@types/fs-extra": "^11",
"@types/node": "^18.16.18",
"@types/semver": "^7.5.0",
"typescript": "^5.1.3"
},
"dependencies": {
"@pnpm/find-workspace-dir": "^6.0.2",
"@pnpm/workspace.find-packages": "^1.0.1",
"tsx": "^3.12.7",
"npm-which": "^3.0.1"
},
"volta": {
"extends": "../../package.json"
}
}
Binary file added tools/generate-workspace/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions tools/generate-workspace/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { findWorkspacePackages } from "@pnpm/workspace.find-packages";
import { findWorkspaceDir } from "@pnpm/find-workspace-dir";
import { writeFileSync } from "fs";
import { join } from "path";

// Define ignore list and name mapping
const ignoreList = [
"construct-library",
"@wingconsole/eslint-plugin",
"generate-workspace",
"bump-pack",
"@winglang/wingii",
"@winglang/wingc",
"@winglang/tree-sitter-wing",
"@wingconsole/error-message",
"@wingconsole/use-loading",
"@wingconsole/tsconfig",
"hangar",
"@wingconsole/design-system",
];

const nameMapping: Record<string, string> = {
"@winglang/monorepo": "ROOT",
"winglang": "CLI",
"@winglang/compiler": "Compiler",
"@winglang/sdk": "SDK",
"examples-sdk": "SDK Tests",
"docs": "Docs",
"@wingconsole/app": "Console App",
"@wingconsole/server": "Console Server",
"@wingconsole/ui": "Console UI",
"vscode-wing": "VSCode",
"@winglang/jsii-docgen": "API Docs Generator",
"wing-api-checker": "API Checker",
"examples-valid": "Tests: Valid",
"examples-invalid": "Tests: Invalid",
"examples-error": "Tests: Error",
};

async function getWorkspaceDir() {
const workspaceDir = await findWorkspaceDir(process.cwd());
if (!workspaceDir) {
throw new Error("No workspace found");
}
return workspaceDir;
}

async function getWorkspacePackages(workspaceDir: string) {
const workspacePackages = await findWorkspacePackages(workspaceDir);
return workspacePackages;
}

function getFolders(workspacePackages: any[], workspaceDir: string) {
const folders: Record<string, string>[] = [];
for (const pkg of workspacePackages) {
const pkgName = pkg.manifest.name;
// Skip unwanted packages
if (pkgName == undefined) throw new Error("Package name is undefined");
if (ignoreList.includes(pkgName)) continue;

// Use name mapping if present, else use the package name
const name = nameMapping[pkgName] || pkgName;
const path = pkg.dir.replace(workspaceDir, "").substring(1); // Remove workspaceDir from the path

folders.push({ name, path: `./${path}` });
}
return folders;
}

function sortFolders(folders: any[]) {
let sortedFolders = Object.keys(nameMapping).map(key => {
return folders.find(folder => folder.name === key || folder.name === nameMapping[key]);
}).filter(Boolean);
return sortedFolders;
}

function warnAboutPackages(workspacePackages: any[]) {
workspacePackages.forEach(pkg => {
const pkgName = pkg.manifest.name;
if (pkgName && (!ignoreList.includes(pkgName) && !Object.keys(nameMapping).includes(pkgName))) {
console.warn(`Warning: Package ${pkgName} is not present in ignore list or name mappings. Please check ./tools/generate-workspace/src/cli.ts`);
}
});
}

function checkIgnoreListAndNameMapping(workspacePackages: any[]) {
ignoreList.forEach(ignoreItem => {
if (!workspacePackages.some(pkg => pkg.manifest.name === ignoreItem)) {
console.error(`Error: ${ignoreItem} from ignore list is not present as a workspace package. Please check ./tools/generate-workspace/src/cli.ts`);
process.exit(1);
}
});

Object.keys(nameMapping).forEach(mappingItem => {
if (!workspacePackages.some(pkg => pkg.manifest.name === mappingItem)) {
console.error(`Error: ${mappingItem} from name mapping is not present as a workspace package. Please check ./tools/generate-workspace/src/cli.ts`);
process.exit(1);
}
});
}

function writeWorkspaceFile(workspaceDir: string, sortedFolders: any[]) {
const workspaceFilePath = join(workspaceDir, "wing.code-workspace");
writeFileSync(workspaceFilePath, JSON.stringify({ folders: sortedFolders, settings: {}}, null, 2));
console.log(`Workspace file written to ${workspaceFilePath}`);
}

async function main() {
const workspaceDir = await getWorkspaceDir();
const workspacePackages = await getWorkspacePackages(workspaceDir);
const folders = getFolders(workspacePackages, workspaceDir);
const sortedFolders = sortFolders(folders);
warnAboutPackages(workspacePackages);
checkIgnoreListAndNameMapping(workspacePackages);
writeWorkspaceFile(workspaceDir, sortedFolders);
}

main();
9 changes: 9 additions & 0 deletions tools/generate-workspace/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"module": "ES2022",
"target": "ES2022",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"strict": true
}
}
65 changes: 65 additions & 0 deletions wing.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"folders": [
{
"name": "ROOT",
"path": "./"
},
{
"name": "CLI",
"path": "./apps/wing"
},
{
"name": "Compiler",
"path": "./libs/wingcompiler"
},
{
"name": "SDK",
"path": "./libs/wingsdk"
},
{
"name": "SDK Tests",
"path": "./examples/tests/sdk_tests"
},
{
"name": "Docs",
"path": "./docs/docs"
},
{
"name": "Console App",
"path": "./apps/wing-console/console/app"
},
{
"name": "Console Server",
"path": "./apps/wing-console/console/server"
},
{
"name": "Console UI",
"path": "./apps/wing-console/console/ui"
},
{
"name": "VSCode",
"path": "./apps/vscode-wing"
},
{
"name": "API Docs Generator",
"path": "./apps/jsii-docgen"
},
{
"name": "API Checker",
"path": "./apps/wing-api-checker"
},
{
"name": "Tests: Valid",
"path": "./examples/tests/valid"
},
{
"name": "Tests: Invalid",
"path": "./examples/tests/invalid"
},
{
"name": "Tests: Error",
"path": "./examples/tests/error"
}
],
"settings": {}
}
Loading