Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

WIP: Get extension working in vscode.dev #124

Closed
wants to merge 16 commits into from
5 changes: 3 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionDevelopmentKind=web"
]
}
]
}
}
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,24 @@
"devDependencies": {
"@types/node": "^15.12.4",
"@types/vscode": "1.30.0",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"eslint": "^7.5.0",
"https-browserify": "^1.0.0",
"net-browserify": "^0.2.4",
"node-loader": "^2.0.0",
"path-browserify": "^1.0.1",
"prettier": "^2.0.5",
"process": "^0.11.10",
"querystring-es3": "^0.2.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"ts-loader": "^9.2.3",
"typescript": "^4.3.4",
"url": "^0.11.0",
"util": "^0.12.4",
"webpack": "^5.40.0",
"webpack-cli": "^4.7.2"
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
VSCODE_SEVERITY,
HUBL_TAG_DEFINITION_REGEX,
} = require('./constants');
const fs = require('fs');
const path = require('path');

const getRange = (document, error) => {
Expand All @@ -40,7 +39,7 @@ const isFileInWorkspace = (error) => {
filePath = filePath + '.module';
}

return fs.existsSync(path.resolve(dirToActiveFile, filePath));
return vscode.workspace.fs.stat(path.resolve(dirToActiveFile, filePath));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Roughly how to address fs, however this extension relies on cli-lib which uses fs directly

};

const clearValidation = (document, collection) => {
Expand Down
70 changes: 69 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';

const path = require('path');
const webpack = require('webpack');

/**@type {import('webpack').Configuration}*/
const config = {
Expand Down Expand Up @@ -40,4 +41,71 @@ const config = {
],
},
};
module.exports = config;

/** @typedef {import('webpack').Configuration} WebpackConfig **/
/** @type WebpackConfig */
const webExtensionConfig = {
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
target: 'webworker', // extensions run in a webworker context
entry: {
extension: './src/index.ts', // source of the web extension main file
},
output: {
filename: '[name].js',
path: path.join(__dirname, './dist/web'),
libraryTarget: 'commonjs',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
resolve: {
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
extensions: ['.ts', '.js'], // support ts-files and js-files
alias: {
// provides alternate implementation for node module and source files
},
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.
assert: require.resolve('assert'),
crypto: require.resolve('crypto-browserify'),
path: require.resolve('path-browserify'),
util: require.resolve('util'),
process: require.resolve('process/browser'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
stream: require.resolve('stream-browserify'),
net: require.resolve('net-browserify'),
url: require.resolve('url'),
zlib: require.resolve('browserify-zlib'),
buffer: require.resolve('buffer'),
querystring: require.resolve('querystring-es3'),
},
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: 'process/browser', // provide a shim for the global `process` variable
}),
],
externals: {
vscode: 'commonjs vscode', // ignored because it doesn't exist
},
performance: {
hints: false,
},
devtool: 'nosources-source-map', // create a source map that points to the original source file
};

module.exports = [webExtensionConfig];