Skip to content

Commit

Permalink
Use Webpack to reduce loading times. (#607)
Browse files Browse the repository at this point in the history
* Bootstrap Webpack

* webpack builds

* Ignore dist output

* Update version

* Webpack optimizations

* bump version

* Fixup Webpack

* Add tslib
  • Loading branch information
ooeygui authored Jul 28, 2022
1 parent dd64090 commit 941adac
Show file tree
Hide file tree
Showing 11 changed files with 6,743 additions and 466 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# node.js
out
dist/**
node_modules

# vscode-test
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "npm: watch"
"outFiles": ["${workspaceRoot}/dist/**/*.js"],
"preLaunchTask": "npm: webpack"
},
{
"name": "Debugger",
Expand Down
5 changes: 3 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.vscode/**
.vscode-test/**
out/test/**
out/**
test/**
src/**
**/*.map
node_modules/**
.gitignore
tsconfig.json
vsc-extension-quickstart.md
webpack.config.js
7,082 changes: 6,639 additions & 443 deletions package-lock.json

Large diffs are not rendered by default.

49 changes: 39 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vscode-ros",
"version": "0.8.3",
"version": "0.9.0",
"publisher": "ms-iot",
"engines": {
"vscode": "^1.68.0"
Expand Down Expand Up @@ -36,9 +36,17 @@
"url": "https://github.com/ms-iot/vscode-ros/issues"
},
"preview": true,
"main": "./out/src/extension",
"main": "./dist/extension",
"activationEvents": [
"*",
"onLanguage:cpp",
"onLanguage:python",
"onLanguage:csharp",
"onCommand",
"workspaceContains:**/package.xml",
"onWebviewPanel:ros2Status",
"onWebviewPanel:ros2Status",
"onWebviewPanel:urdfPreview",
"onDebug",
"onDebugResolve:ros",
"onDebugDynamicConfigurations:ros"
],
Expand Down Expand Up @@ -381,22 +389,40 @@
]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"package:dev": "vsce package -o vscode-ros-dev.vsix",
"compile": "tsc -p ./",
"lint": "tslint -p ./",
"watch": "tsc -watch -p ./",
"lint": "eslint -p ./",
"pretest": "npm run compile",
"test": "node ./out/src/test/runTest.js"
"test": "node ./out/src/test/runTest.js",
"vscode:prepublish": "npm run package",
"webpack": "webpack --mode development",
"watch": "webpack --mode development --watch",
"package": "webpack --mode production --devtool hidden-source-map",
"test-compile": "tsc -p ./"
},
"dependencies": {
"@vscode/debugadapter": "^1.51.0",
"@vscode/extension-telemetry": "^0.6.2",
"assert": "^2.0.0",
"buffer": "^6.0.3",
"console-browserify": "^1.2.0",
"constants-browserify": "^1.0.0",
"crypto-browserify": "^3.12.0",
"domain-browser": "^4.22.0",
"https-browserify": "^1.0.0",
"js-yaml": "^4.1.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"portfinder": "^1.0.28",
"querystring-es3": "^0.2.1",
"shell-quote": "^1.7.3",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"string_decoder": "^1.3.0",
"sudo-prompt": "^9.2.1",
"timers-browserify": "^2.0.12",
"tmp": "^0.2.1",
"vscode-debugadapter": "^1.51.0",
"vscode-extension-telemetry": "^0.4.5",
"tslib": "^2.4.0",
"xmlrpc": "^1.3.2"
},
"devDependencies": {
Expand All @@ -410,9 +436,12 @@
"@types/xmlrpc": "^1.3.7",
"glob": "^8.0.1",
"mocha": "^9.2.2",
"ts-loader": "^9.3.1",
"tslint": "^6.1.3",
"typescript": "^4.6.3",
"vscode-test": "^1.6.1"
"vscode-test": "^1.6.1",
"webpack": "^5.63.0",
"webpack-cli": "^4.9.1"
},
"extensionDependencies": [
"ms-python.python",
Expand Down
4 changes: 2 additions & 2 deletions src/debugger/debug-session.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Andrew Short. All rights reserved.
// Licensed under the MIT License.

import * as adapter from "vscode-debugadapter";
import * as protocol from "vscode-debugprotocol";
import * as adapter from "@vscode/debugadapter";
import * as protocol from "@vscode/debugprotocol";

import * as requests from "./requests";

Expand Down
2 changes: 1 addition & 1 deletion src/debugger/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as vscode from "vscode";
import * as debug_protocol from "vscode-debugprotocol";
import * as debug_protocol from "@vscode/debugprotocol";

// tslint:disable-next-line: max-line-length
export interface IAttachRequest extends vscode.DebugConfiguration, debug_protocol.DebugProtocol.AttachRequestArguments {
Expand Down
11 changes: 6 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ export async function activate(context: vscode.ExtensionContext) {
outputChannel = vscode_utils.createOutputChannel();
context.subscriptions.push(outputChannel);

// Determine if we're in a catkin workspace.
let buildToolDetected = await buildtool.determineBuildTool(vscode.workspace.rootPath);

// Activate components when the ROS env is changed.
context.subscriptions.push(onDidChangeEnv(activateEnvironment.bind(null, context, buildToolDetected)));
context.subscriptions.push(onDidChangeEnv(activateEnvironment.bind(null, context)));

// Activate components which don't require the ROS env.
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(
Expand Down Expand Up @@ -145,7 +142,7 @@ async function ensureErrorMessageOnException(callback: (...args: any[]) => any)
/**
* Activates components which require a ROS env.
*/
function activateEnvironment(context: vscode.ExtensionContext, buildToolDetected: boolean) {
async function activateEnvironment(context: vscode.ExtensionContext) {
// Clear existing disposables.
while (subscriptions.length > 0) {
subscriptions.pop().dispose();
Expand All @@ -159,6 +156,9 @@ function activateEnvironment(context: vscode.ExtensionContext, buildToolDetected
return;
}

// Determine if we're in a catkin workspace.
let buildToolDetected = await buildtool.determineBuildTool(vscode.workspace.rootPath);

// http://www.ros.org/reps/rep-0149.html#environment-variables
// Learn more about ROS_VERSION definition.
selectROSApi(env.ROS_VERSION);
Expand Down Expand Up @@ -320,6 +320,7 @@ async function sourceRosAndWorkspace(): Promise<void> {
if (!installedDistros.length) {
throw new Error("ROS has not been found on this system.");
} else if (installedDistros.length === 1) {

// if there is only one distro installed, directly choose it
config.update("distro", installedDistros[0]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/telemetry-helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import TelemetryReporter from "vscode-extension-telemetry";
import TelemetryReporter from "@vscode/extension-telemetry";

import * as vscode_utils from "./vscode-utils";

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution":"Node",
"target": "es6",
"outDir": "out",
"lib": [
Expand Down
48 changes: 48 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//@ts-check

'use strict';

const path = require('path');

/**@type {import('webpack').Configuration}*/
const config = {
target: '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/
path: path.resolve(__dirname, 'dist'),
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/
'applicationinsights-native-metrics': 'commonjs applicationinsights-native-metrics' // ignored because we don't ship native module
},
resolve: {
extensions: ['.ts', '.js'],
// preferRelative: true,
fallback: {
// Webpack 5 no longer polyfills Node.js core modules automatically.
// see https://webpack.js.org/configuration/resolve/#resolvefallback
// for the list of Node.js core module polyfills.
} },
module: {
rules: [{
test: /\.ts$/,
exclude: /node_modules/,
use: [{
loader: 'ts-loader',
options: {
compilerOptions: {
"module": "es6" // override `tsconfig.json` so that TypeScript emits native JavaScript modules.
}
}
}]
}]
},
};

module.exports = config;

0 comments on commit 941adac

Please sign in to comment.