solved relative path bug and ran formatter
This commit is contained in:
Родитель
135c59b894
Коммит
c9abcf1ce3
15
.eslintrc.js
15
.eslintrc.js
|
@ -3,18 +3,13 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
],
|
||||
plugins: ['@typescript-eslint'],
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
||||
rules: {
|
||||
'semi': [2, "always"],
|
||||
semi: [2, 'always'],
|
||||
'@typescript-eslint/no-unused-vars': 0,
|
||||
'@typescript-eslint/no-explicit-any': 0,
|
||||
'@typescript-eslint/explicit-module-boundary-types': 0,
|
||||
'@typescript-eslint/no-non-null-assertion': 0,
|
||||
}
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
trailingComma: "es5"
|
||||
trailingComma: 'es5'
|
||||
useTabs: true
|
||||
semi: true
|
||||
endOfLine: auto
|
||||
printWidth: 80
|
||||
singleQuote: true
|
||||
singleQuote: true
|
||||
|
|
14
README.md
14
README.md
|
@ -9,23 +9,27 @@ The goal of the extension is to allow local previews of web projects (ie: HTML/C
|
|||
Based off of the webview template found [here](https://github.com/microsoft/vscode-extension-samples/tree/main/webview-sample).
|
||||
|
||||
Issues are currently being tracked on the [June Iteration Ticket](https://github.com/microsoft/vscode/issues/124608)
|
||||
|
||||
## Running the extension
|
||||
|
||||
- Open this example in VS Code 1.47+
|
||||
- `npm install`
|
||||
- `npm run compile`
|
||||
- <kbd>F5</kbd> to start debugging
|
||||
|
||||
## Using the extension
|
||||
|
||||
Run commands using the command palette using <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd>
|
||||
Action | Command
|
||||
:----- | :----
|
||||
Starting the server on port 3000 | `LiveServer v2: Start Development Server`
|
||||
Action | Command
|
||||
:----- | :----
|
||||
Starting the server on port 3000 | `LiveServer v2: Start Development Server`
|
||||
Closing the server | `LiveServer v2: Close Development Server`
|
||||
Viewing the embedded preview (does not require manually starting the server) | `LiveServer v2: Show Preview`
|
||||
Viewing the embedded preview (does not require manually starting the server) | `LiveServer v2: Show Preview`
|
||||
|
||||
[![Image from Gyazo](./release_notes/images/v0_1/live-server-v0_1-overview.gif)](https://gyazo.com/a3796821f5cc2ea2164725457d26f45c)
|
||||
|
||||
## Issue Tracking:
|
||||
|
||||
- [May Iteration](https://github.com/microsoft/vscode/issues/124607)
|
||||
- [June Iteration](https://github.com/microsoft/vscode/issues/124608)
|
||||
- [Backlog](https://github.com/microsoft/vscode/issues/125343)
|
||||
- [Backlog](https://github.com/microsoft/vscode/issues/125343)
|
||||
|
|
|
@ -4,10 +4,12 @@ const path = require('path');
|
|||
let outputRoot = __dirname;
|
||||
const outDir = path.join(outputRoot, 'media');
|
||||
|
||||
fs.copyFileSync (
|
||||
fs.copyFileSync(
|
||||
path.join(__dirname, 'node_modules/vscode-codicons/dist/codicon.css'),
|
||||
path.join(outDir, 'codicon.css'));
|
||||
path.join(outDir, 'codicon.css')
|
||||
);
|
||||
|
||||
fs.copyFileSync (
|
||||
fs.copyFileSync(
|
||||
path.join(__dirname, 'node_modules/vscode-codicons/dist/codicon.ttf'),
|
||||
path.join(outDir, 'codicon.ttf'));
|
||||
path.join(outDir, 'codicon.ttf')
|
||||
);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<!-- Script injected by VS Live Server -->
|
||||
|
||||
<!-- <base href="/test/" /> -->
|
||||
<script type="text/javascript" defer>
|
||||
|
||||
const url = 'ws://localhost:${WS_PORTNUM}';
|
||||
const connection = new WebSocket(url);
|
||||
|
||||
|
@ -15,7 +18,6 @@
|
|||
}
|
||||
}
|
||||
};
|
||||
console.log(window.location.pathname)
|
||||
window.parent.postMessage(
|
||||
{ command: 'update-path', text: window.location.pathname },
|
||||
'*'
|
||||
|
@ -32,6 +34,7 @@
|
|||
);
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(e) {
|
||||
|
||||
var l = document.getElementsByTagName('a');
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
l[i].onclick = (e) => {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "A simple live server hosting extension for static HTML/CSS Projects",
|
||||
"version": "0.0.2",
|
||||
"publisher": "andrea-mah",
|
||||
"icon" : "icon.png",
|
||||
"icon": "icon.png",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/andreamah/VS-Code-LiveServer-V2-Extension"
|
||||
|
|
|
@ -75,8 +75,6 @@ export class BrowserPreview extends Disposable {
|
|||
return;
|
||||
case 'open-browser':
|
||||
this.handleOpenBrowser(message.text);
|
||||
this.goToFile(this.currentAddress)
|
||||
this.updateForwardBackArrows()
|
||||
return;
|
||||
case 'add-history':
|
||||
// called from main.js in the case where the target is non-injectable
|
||||
|
@ -109,6 +107,9 @@ export class BrowserPreview extends Disposable {
|
|||
: givenURL;
|
||||
const url = vscode.Uri.parse(urlString);
|
||||
vscode.env.openExternal(url);
|
||||
vscode.window.showInformationMessage(`Externally hosted links are not supported in the embedded browser. ${urlString} opened in external browser.`)
|
||||
this.goToFile(this.currentAddress);
|
||||
this.updateForwardBackArrows();
|
||||
}
|
||||
private updateForwardBackArrows(): void {
|
||||
const navigationStatus = this._pageHistory.currentCommands;
|
||||
|
|
|
@ -159,6 +159,7 @@ export class Server extends Disposable {
|
|||
private start(basePath: string, extensionUri: vscode.Uri): boolean {
|
||||
return this.startMainServer(basePath) && this.startWSServer(basePath,extensionUri);
|
||||
}
|
||||
|
||||
private createServer(basePath: string) {
|
||||
return http
|
||||
.createServer((req, res) => {
|
||||
|
@ -167,20 +168,13 @@ export class Server extends Disposable {
|
|||
res.end();
|
||||
return;
|
||||
}
|
||||
console.log(req)
|
||||
|
||||
let referrerPath = ""
|
||||
if (req.headers.referer) {
|
||||
const referrerURL = new URL(req.headers.referer);
|
||||
referrerPath = referrerURL.pathname;
|
||||
// check if a file or directory and get referrer path accordingly.
|
||||
}
|
||||
|
||||
const endOfPath = req.url.lastIndexOf('?');
|
||||
const URLPathName =
|
||||
endOfPath == -1 ? req.url : req.url.substring(0, endOfPath);
|
||||
|
||||
let absoluteReadPath = path.join(basePath, referrerPath, URLPathName);
|
||||
|
||||
let absoluteReadPath = path.join(basePath, URLPathName);
|
||||
let stream;
|
||||
|
||||
if (!fs.existsSync(absoluteReadPath)) {
|
||||
|
@ -188,6 +182,13 @@ export class Server extends Disposable {
|
|||
absoluteReadPath
|
||||
);
|
||||
} else if (fs.statSync(absoluteReadPath).isDirectory()) {
|
||||
|
||||
if(!URLPathName.endsWith("/")){
|
||||
res.statusCode=302;// redirect to use slash
|
||||
const queries = endOfPath == -1 ? "" : `${req.url.substring(endOfPath)}`;
|
||||
res.setHeader('Location',URLPathName + '/' + queries);
|
||||
return res.end();
|
||||
}
|
||||
// Redirect to index.html if the request URL is a directory
|
||||
if (fs.existsSync(path.join(absoluteReadPath, 'index.html'))) {
|
||||
absoluteReadPath = path.join(absoluteReadPath, 'index.html');
|
||||
|
|
|
@ -7,54 +7,54 @@ const CopyPlugin = require('copy-webpack-plugin');
|
|||
|
||||
/**@type {import('webpack').Configuration}*/
|
||||
const config = {
|
||||
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
|
||||
target: 'node', // vscode extensions run in a Node.js-context 📖 -> https://webpack.js.org/configuration/node/
|
||||
|
||||
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
|
||||
output: {
|
||||
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
|
||||
entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/
|
||||
output: {
|
||||
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
|
||||
path: path.resolve(__dirname, 'media'),
|
||||
filename: 'extension.js',
|
||||
libraryTarget: 'commonjs2',
|
||||
devtoolModuleFilenameTemplate: '../[resource-path]'
|
||||
},
|
||||
devtool: 'source-map',
|
||||
externals: {
|
||||
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
|
||||
'utf-8-validate': 'commonjs utf-8-validate',
|
||||
bufferutil: 'commonjs bufferutil',
|
||||
},
|
||||
resolve: {
|
||||
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'ts-loader'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
libraryTarget: 'commonjs2',
|
||||
devtoolModuleFilenameTemplate: '../[resource-path]',
|
||||
},
|
||||
devtool: 'source-map',
|
||||
externals: {
|
||||
vscode: 'commonjs vscode', // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
|
||||
'utf-8-validate': 'commonjs utf-8-validate',
|
||||
bufferutil: 'commonjs bufferutil',
|
||||
},
|
||||
resolve: {
|
||||
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
|
||||
extensions: ['.ts', '.js'],
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [
|
||||
{
|
||||
loader: 'ts-loader',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
plugins: [
|
||||
// @ts-ignore
|
||||
new CopyPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: './node_modules/vscode-codicons/dist/codicon.css',
|
||||
to: 'codicon.css'
|
||||
to: 'codicon.css',
|
||||
},
|
||||
{
|
||||
from: './node_modules/vscode-codicons/dist/codicon.ttf',
|
||||
to: 'codicon.ttf'
|
||||
to: 'codicon.ttf',
|
||||
},
|
||||
],
|
||||
}),
|
||||
]
|
||||
],
|
||||
};
|
||||
module.exports = config;
|
||||
module.exports = config;
|
||||
|
|
Загрузка…
Ссылка в новой задаче