Skip to content

Commit

Permalink
Fix extension paths
Browse files Browse the repository at this point in the history
  • Loading branch information
yandeu committed Jan 2, 2024
1 parent 3b49e9b commit db2154d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 101 deletions.
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"semi": true
}
"semi": true,
"printWidth": 120
}
23 changes: 11 additions & 12 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { build } from 'esbuild';
import { cp } from 'fs/promises';

import { build } from "esbuild";
import { cp } from "fs/promises";

// "esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node",
await cp("./node_modules/five-server/public", "./dist/public", { recursive: true });
await cp("./node_modules/five-server/client", "./dist/client", { recursive: true });
await cp("./node_modules/five-server/public", "./dist/bundle/public", { recursive: true });
await cp("./node_modules/five-server/client", "./dist/bundle/client", { recursive: true });

await build({
entryPoints: ['src/extension.ts'],
entryPoints: ["src/extension.ts"],
bundle: true,
outfile: "dist/bundle/main.js",
outfile: "dist/bundle/subdir/main.js",
external: ["vscode", "@yandeu/open-cjs", "fsevents"],
format: "cjs",
platform: "node",
minify: true
minify: true,
});

await build({
entryPoints: ['node_modules/five-server/lib/workers/parseBody.js'],
entryPoints: ["node_modules/five-server/lib/workers/parseBody.js"],
bundle: true,
outfile: "dist/bundle/parseBody.js",
outfile: "dist/bundle/subdir/parseBody.js",
external: ["vscode"],
format: "cjs",
platform: "node",
minify: true
});
minify: true,
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"activationEvents": [
"onStartupFinished"
],
"main": "./dist/bundle/main.js",
"main": "./dist/bundle/subdir/main.js",
"contributes": {
"commands": [
{
Expand Down
16 changes: 4 additions & 12 deletions src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const decorate = (
text: string;
line: number;
}[],
color: string
color: string,
) => {
const hash = strToHash(fileName);

Expand All @@ -36,10 +36,7 @@ export const decorate = (

decorations[hash].push({
renderOptions: { after: { contentText: text, color } },
range: new Range(
new Position(line - 1, 1024),
new Position(line - 1, 1024)
),
range: new Range(new Position(line - 1, 1024), new Position(line - 1, 1024)),
});
});

Expand All @@ -50,10 +47,7 @@ const decorationType = window.createTextEditorDecorationType({
after: { margin: "0 0 0 1rem" },
});

export const refreshDecorations = (
fileName: string | undefined,
options: { delay?: number; force?: boolean } = {}
) => {
export const refreshDecorations = (fileName: string | undefined, options: { delay?: number; force?: boolean } = {}) => {
if (!fileName) return;

const { delay = 250, force = false } = options;
Expand All @@ -73,9 +67,7 @@ export const refreshDecorations = (
};

const getEditors = (fileName: string) => {
return window.visibleTextEditors.filter(
(editor) => editor.document.fileName === fileName
);
return window.visibleTextEditors.filter((editor) => editor.document.fileName === fileName);
};

export const clearDecorations = () => {
Expand Down
55 changes: 15 additions & 40 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import { message } from "five-server/lib/msg";
import { PTY } from "./pty";
import { join, extname, basename } from "path";
import { decorate, refreshDecorations } from "./decorator";
import {
assignVSCodeConfiguration,
colors,
getConfig,
namespace,
} from "./helpers";
import { assignVSCodeConfiguration, colors, getConfig, namespace } from "./helpers";

let openURL = "";
let pty: PTY;
Expand Down Expand Up @@ -187,7 +182,7 @@ export function activate(context: vscode.ExtensionContext) {
fileName,
page.current.text,
shouldHighlight(fileName),
vscode.window.activeTextEditor?.selection.active
vscode.window.activeTextEditor?.selection.active,
);
};

Expand Down Expand Up @@ -284,20 +279,15 @@ export function activate(context: vscode.ExtensionContext) {
rootAbsolute = join(workspace, root);

if (debug) {
pty.write(
"DEBUG:",
'"workspace", "root" and "open" will be passed to fiveServer.start()'
);
pty.write("DEBUG:", '"workspace", "root" and "open" will be passed to fiveServer.start()');
pty.write("Workspace:", workspace);
pty.write("Root:", root);
pty.write("Absolute (workspace + root):", rootAbsolute);
pty.write("File:", uri?.fsPath);
}

if (uri?.fsPath) {
let file = uri.fsPath
.replace(rootAbsolute, "")
.replace(/^\\|^\//gm, "");
let file = uri.fsPath.replace(rootAbsolute, "").replace(/^\\|^\//gm, "");

const isFile = extname(file) !== "";

Expand All @@ -323,8 +313,7 @@ export function activate(context: vscode.ExtensionContext) {

// get current open file
const fileName = vscode.window.activeTextEditor?.document.fileName;
if (fileName)
file = fileName.replace(rootAbsolute, "").replace(/^\\|^\//gm, "");
if (fileName) file = fileName.replace(rootAbsolute, "").replace(/^\\|^\//gm, "");

if (debug) pty.write("Open:", file);

Expand All @@ -342,10 +331,9 @@ export function activate(context: vscode.ExtensionContext) {
else if (!workspace) {
// no workspace?
// the user opened probably only a single file instead of a folder
message.pretty(
'No Workspace found! You probably opened a "single file" instead of a "folder".',
{ id: "vscode" }
);
message.pretty('No Workspace found! You probably opened a "single file" instead of a "folder".', {
id: "vscode",
});

// we get the path and filename from the window
const fileName = vscode.window.activeTextEditor?.document.fileName;
Expand Down Expand Up @@ -396,7 +384,7 @@ export function activate(context: vscode.ExtensionContext) {
htmlErrors.map((e: any) => {
return { text: `// ${e.message}`, line: e.line };
}),
colors.yellow
colors.yellow,
);
}
});
Expand Down Expand Up @@ -441,27 +429,14 @@ export function activate(context: vscode.ExtensionContext) {
else if (_state === "off") vscode.commands.executeCommand(startCommand);
};

context.subscriptions.push(
vscode.commands.registerCommand(startCommand, startServer)
);
context.subscriptions.push(
vscode.commands.registerCommand(openCommand, startServer)
);
context.subscriptions.push(
vscode.commands.registerCommand(openRootCommand, startServer)
);
context.subscriptions.push(
vscode.commands.registerCommand(closeCommand, closeServer)
);
context.subscriptions.push(
vscode.commands.registerCommand(statusBarItemCommand, toggleServer)
);
context.subscriptions.push(vscode.commands.registerCommand(startCommand, startServer));
context.subscriptions.push(vscode.commands.registerCommand(openCommand, startServer));
context.subscriptions.push(vscode.commands.registerCommand(openRootCommand, startServer));
context.subscriptions.push(vscode.commands.registerCommand(closeCommand, closeServer));
context.subscriptions.push(vscode.commands.registerCommand(statusBarItemCommand, toggleServer));

// create a new status bar item that we can now manage
myStatusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
0
);
myStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 0);
myStatusBarItem.command = statusBarItemCommand;
updateStatusBarItem("off");
context.subscriptions.push(myStatusBarItem);
Expand Down
3 changes: 1 addition & 2 deletions src/pty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export class PTY {
close: () => {
this.writeEmitter.dispose();
},
handleInput: (data) =>
this.writeEmitter.fire(data === "\r" ? "\r\n" : data + "\r\n"),
handleInput: (data) => this.writeEmitter.fire(data === "\r" ? "\r\n" : data + "\r\n"),
};

this.terminal = vscode.window.createTerminal({ name: "Five Server", pty });
Expand Down
39 changes: 10 additions & 29 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import * as path from "path";
import * as cp from "child_process";

import {
downloadAndUnzipVSCode,
resolveCliArgsFromVSCodeExecutablePath,
runTests,
} from "@vscode/test-electron";
import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath, runTests } from "@vscode/test-electron";
import { readFile } from "fs/promises";

async function main() {
try {
const extensionDevelopmentPath = path.resolve(__dirname, "../../");
const extensionTestsPath = path.resolve(__dirname, "./suite/index");
const testWorkspace = path.resolve(
__dirname,
"../../test-fixtures/workspace"
);
const testWorkspace = path.resolve(__dirname, "../../test-fixtures/workspace");
console.log(path.resolve(__dirname, "../../package.json"));
const pkg = await readFile(
path.resolve(__dirname, "../../package.json"),
"utf-8"
);
const pkg = await readFile(path.resolve(__dirname, "../../package.json"), "utf-8");
const version = JSON.parse(pkg).version;

// Test the vsix package
const vscodeExecutablePath = await downloadAndUnzipVSCode(undefined);
const [cliPath, ...args] =
resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
const [cliPath, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(cliPath, [...args, "--list-extensions"], {
Expand All @@ -35,27 +24,19 @@ async function main() {
});

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(
cliPath,
[...args, "--uninstall-extension", "yandeu.five-server"],
{
encoding: "utf-8",
stdio: "inherit",
}
);
cp.spawnSync(cliPath, [...args, "--uninstall-extension", "yandeu.five-server"], {
encoding: "utf-8",
stdio: "inherit",
});

// Use cp.spawn / cp.exec for custom setup
cp.spawnSync(
cliPath,
[
...args,
"--install-extension",
path.resolve(__dirname, `../../five-server-${version}.vsix`),
],
[...args, "--install-extension", path.resolve(__dirname, `../../five-server-${version}.vsix`)],
{
encoding: "utf-8",
stdio: "inherit",
}
},
);

// Run the extension test
Expand Down
4 changes: 1 addition & 3 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const pause = (ms: number): Promise<void> => {

suite("Extension Test Suite", () => {
test("init testing", async () => {
vscode.window.showInformationMessage(
"Start all tests. Wait for onStartupFinished event."
);
vscode.window.showInformationMessage("Start all tests. Wait for onStartupFinished event.");
return pause(5000);
});

Expand Down

0 comments on commit db2154d

Please sign in to comment.