Skip to content

Commit 81596fa

Browse files
authored
Merge pull request #71 from ggbecker/webextension
Test web extension.
2 parents 6551068 + b202ec9 commit 81596fa

File tree

9 files changed

+135
-18
lines changed

9 files changed

+135
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
out
2+
dist
23
node_modules
34
.vscode-test/
45
*.vsix

.vscode/extensions.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
// See http://go.microsoft.com/fwlink/?LinkId=827846
33
// for the documentation about the extensions.json format
4-
"recommendations": [
5-
"ms-vscode.vscode-typescript-tslint-plugin"
6-
]
7-
}
4+
"recommendations": ["dbaeumer.vscode-eslint", "amodio.tsl-problem-matcher"]
5+
}

.vscode/launch.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"--extensionDevelopmentPath=${workspaceFolder}"
1414
],
1515
"outFiles": [
16-
"${workspaceFolder}/out/**/*.js"
16+
"${workspaceFolder}/dist/web/**/*.js"
1717
],
1818
"preLaunchTask": "npm: watch"
1919
},
@@ -27,9 +27,23 @@
2727
"--extensionTestsPath=${workspaceFolder}/out/test"
2828
],
2929
"outFiles": [
30-
"${workspaceFolder}/out/test/**/*.js"
30+
"${workspaceFolder}/dist/web/test/**/*.js"
3131
],
3232
"preLaunchTask": "npm: watch"
33-
}
33+
},
34+
{
35+
"name": "Run Web Extension in VS Code",
36+
"type": "pwa-extensionHost",
37+
"debugWebWorkerHost": true,
38+
"request": "launch",
39+
"args": [
40+
"--extensionDevelopmentPath=${workspaceFolder}",
41+
"--extensionDevelopmentKind=web"
42+
],
43+
"outFiles": [
44+
"${workspaceFolder}/dist/web/**/*.js"
45+
],
46+
"preLaunchTask": "npm: watch-web"
47+
},
3448
]
3549
}

.vscode/tasks.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,28 @@
1515
"kind": "build",
1616
"isDefault": true
1717
}
18+
},
19+
{
20+
"type": "npm",
21+
"script": "compile-web",
22+
"group": {
23+
"kind": "build",
24+
"isDefault": true
25+
},
26+
"problemMatcher": [
27+
"$ts-webpack",
28+
"$tslint-webpack"
29+
]
30+
},
31+
{
32+
"type": "npm",
33+
"script": "watch-web",
34+
"group": "build",
35+
"isBackground": true,
36+
"problemMatcher": [
37+
"$ts-webpack-watch",
38+
"$tslint-webpack-watch"
39+
]
1840
}
1941
]
2042
}

.vscodeignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ vsc-extension-quickstart.md
1010
**/.eslintrc.json
1111
**/*.map
1212
**/*.ts
13+
14+
node_modules
15+
out/
16+
src/
17+
tsconfig.json
18+
webpack.config.js
19+
.github

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Change Log
2+
## [1.0.2] - 2022-07-19
3+
### Added
4+
- Enable web extension.
25
## [1.0.1] - 2022-07-18
36
### Fixed
47
- Open Built content: only the fallback (RHEL8) built content was being opened. The fallback option was removed.

package.json

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "Content Navigator",
55
"description": "Content Navigator helps security content authors to create content for https://github.com/ComplianceAsCode/content",
66
"icon": "icon.png",
7-
"version": "1.0.1",
7+
"version": "1.0.2",
88
"license": "BSD-3-Clause",
99
"engines": {
1010
"vscode": "^1.59.0"
@@ -41,9 +41,10 @@
4141
"onCommand:content-navigator.copyContentId",
4242
"onCommand:content-navigator.copyPrefixedContentId",
4343
"onCommand:content-navigator.getRuleId",
44-
"*"
44+
"onStartupFinished"
4545
],
46-
"main": "./out/content-navigator.js",
46+
"browser": "./dist/web/contentNavigator",
47+
"main": "./dist/web/contentNavigator",
4748
"contributes": {
4849
"snippets": [
4950
{
@@ -476,24 +477,28 @@
476477
}
477478
},
478479
"scripts": {
479-
"vscode:prepublish": "npm run compile",
480-
"compile": "tsc -p ./",
481-
"watch": "tsc -watch -p ./",
482-
"pretest": "npm run compile && npm run lint",
483-
"lint": "eslint src --ext ts",
484-
"test": "node ./out/test/runTest.js"
480+
"vscode:prepublish": "webpack --mode production",
481+
"webpack": "webpack --mode development",
482+
"webpack-dev": "webpack --mode development --watch",
483+
"test-compile": "tsc -p ./",
484+
"lint": "eslint . --ext .ts,.tsx"
485485
},
486486
"devDependencies": {
487487
"@types/glob": "^7.2.0",
488488
"@types/mocha": "^9.1.1",
489489
"@types/node": "18.x",
490490
"@types/vscode": "^1.59.0",
491+
"@types/webpack-env": "^1.16.2",
491492
"@typescript-eslint/eslint-plugin": "^5.30.6",
492493
"@typescript-eslint/parser": "^5.30.6",
494+
"@vscode/test-web": "^0.0.22",
493495
"eslint": "^8.19.0",
494496
"glob": "^8.0.3",
495497
"mocha": "^10.0.0",
498+
"ts-loader": "^9.3.1",
496499
"typescript": "^4.7.4",
497-
"vscode-test": "^1.5.2"
500+
"vscode-test": "^1.5.2",
501+
"webpack": "^5.73.0",
502+
"webpack-cli": "^4.10.0"
498503
}
499504
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"target": "es6",
55
"outDir": "out",
66
"lib": [
7-
"es6"
7+
"es6", "WebWorker"
88
],
99
"sourceMap": true,
1010
"rootDir": "src",

webpack.config.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
//@ts-check
7+
'use strict';
8+
9+
//@ts-check
10+
/** @typedef {import('webpack').Configuration} WebpackConfig **/
11+
12+
const path = require('path');
13+
const webpack = require('webpack');
14+
15+
/** @type WebpackConfig */
16+
const webExtensionConfig = {
17+
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
18+
target: 'webworker', // extensions run in a webworker context
19+
entry: {
20+
contentNavigator: './src/content-navigator.ts'
21+
},
22+
output: {
23+
filename: '[name].js',
24+
path: path.join(__dirname, './dist/web'),
25+
libraryTarget: 'commonjs',
26+
devtoolModuleFilenameTemplate: '../../[resource-path]'
27+
},
28+
resolve: {
29+
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
30+
extensions: ['.ts', '.js'], // support ts-files and js-files
31+
alias: {
32+
// provides alternate implementation for node module and source files
33+
},
34+
fallback: {
35+
// Webpack 5 no longer polyfills Node.js core modules automatically.
36+
// see https://webpack.js.org/configuration/resolve/#resolvefallback
37+
// for the list of Node.js core module polyfills.
38+
'assert': require.resolve('assert')
39+
}
40+
},
41+
module: {
42+
rules: [{
43+
test: /\.ts$/,
44+
exclude: /node_modules/,
45+
use: [{
46+
loader: 'ts-loader'
47+
}]
48+
}]
49+
},
50+
plugins: [
51+
new webpack.ProvidePlugin({
52+
process: 'process/browser', // provide a shim for the global `process` variable
53+
}),
54+
],
55+
externals: {
56+
'vscode': 'commonjs vscode', // ignored because it doesn't exist
57+
},
58+
performance: {
59+
hints: false
60+
},
61+
devtool: 'nosources-source-map', // create a source map that points to the original source file
62+
infrastructureLogging: {
63+
level: "log", // enables logging required for problem matchers
64+
},
65+
};
66+
67+
module.exports = [ webExtensionConfig ];

0 commit comments

Comments
 (0)