Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bundles extension code #57

Merged
merged 14 commits into from
Mar 6, 2020
8 changes: 0 additions & 8 deletions .azure-pipelines/common/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@ steps:

- task: Npm@1
displayName: 'Install Dependencies'

- script: |
sudo cp .azure-pipelines/linux/xvfb.init /etc/init.d/xvfb
sudo chmod +x /etc/init.d/xvfb
sudo update-rc.d xvfb defaults
sudo service xvfb start
displayName: 'Start X Virtual Frame Buffer'
condition: eq(variables['Agent.OS'], 'Linux')
17 changes: 17 additions & 0 deletions .azure-pipelines/common/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
steps:
- script: |
sudo cp .azure-pipelines/linux/xvfb.init /etc/init.d/xvfb
sudo chmod +x /etc/init.d/xvfb
sudo update-rc.d xvfb defaults
sudo service xvfb start
displayName: 'Start X Virtual Frame Buffer'
condition: eq(variables['Agent.OS'], 'Linux')

- task: Npm@1
displayName: 'Test'
inputs:
command: custom
customCommand: run test
env:
DISPLAY: :10 # Only necessary for linux tests
VSCODE_DAPR_IGNORE_BUNDLE: true
3 changes: 3 additions & 0 deletions .azure-pipelines/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
- template: common/setup.yml
- template: common/governance.yml # Force governance before test to avoid false-positives.
- template: common/build.yml
- template: common/test.yml

- job: Linux
pool:
Expand All @@ -14,6 +15,7 @@ jobs:
- template: common/setup.yml
- template: common/governance.yml # Force governance before test to avoid false-positives.
- template: common/publish-vsix.yml # Only publish vsix from linux build since we use this to release and want to stay consistent
- template: common/test.yml

- job: macOS
pool:
Expand All @@ -22,3 +24,4 @@ jobs:
- template: common/setup.yml
- template: common/governance.yml # Force governance before test to avoid false-positives.
- template: common/build.yml
- template: common/test.yml
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
gulpfile.ts
main.js
webpack.config.ts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
out
node_modules
.vscode-test/
Expand Down
28 changes: 27 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,30 @@
"--extensionDevelopmentPath=${workspaceFolder}"
],
"env": {
"DEBUGTELEMETRY": "v"
"DEBUGTELEMETRY": "v",
"VSCODE_DAPR_IGNORE_BUNDLE": "true"
},
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Run Extension (Packed)",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"env": {
"DEBUGTELEMETRY": "v"
},
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "build-packed"
},
{
"name": "Run Extension (Pseudo)",
"type": "extensionHost",
Expand All @@ -31,6 +48,7 @@
],
"env": {
"DEBUGTELEMETRY": "v",
"VSCODE_DAPR_IGNORE_BUNDLE": "true",
"VSCODE_DAPR_LOCALE": "pseudo"
},
"sourceMaps": true,
Expand All @@ -49,6 +67,10 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/allTests"
],
"env": {
"DEBUGTELEMETRY": "v",
"VSCODE_DAPR_IGNORE_BUNDLE": "true"
},
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
Expand All @@ -63,6 +85,10 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/unitTests"
],
"env": {
"DEBUGTELEMETRY": "v",
"VSCODE_DAPR_IGNORE_BUNDLE": "true"
},
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
Expand Down
9 changes: 9 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
"kind": "build",
"isDefault": true
}
},
{
"label": "build-packed",
"type": "npm",
"script": "build-packed",
"problemMatcher": "$gulp-tsc",
"presentation": {
"reveal": "never"
}
}
]
}
4 changes: 3 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
.eslintignore
.vscode/**
.vscode-test/**
out/test/**
node_modules/**
out/**
samples/**
src/**
.gitignore
vsc-extension-quickstart.md
webpack.config.ts
**/tsconfig.json
**/tslint.json
**/*.map
Expand Down
49 changes: 46 additions & 3 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ import * as nls from 'vscode-nls-dev';
import * as sourcemaps from 'gulp-sourcemaps';
import * as ts from 'gulp-typescript';
import * as vsce from 'vsce';
import * as webpack from 'webpack';

import { config as webpackConfig } from './webpack.config';

const languages: nls.Language[] = [
{ folderName: 'jpn', id: 'ja' }
];

const tsProject = ts.createProject('./tsconfig.json');

function getDistDir(): string {
if (!webpackConfig.output?.path) {
throw new Error('path is not defined in webpack.config.ts');
}

return webpackConfig.output.path;
}

function getOutDir(): string {
if (!tsProject.options.outDir) {
if (!tsProject.options?.outDir) {
throw new Error('outDir is not defined in tsconfig.json.');
}

Expand All @@ -29,7 +40,7 @@ function wrapThroughStream(stream: nls.ThroughStream): NodeJS.ReadWriteStream {
}

function cleanTask(): Promise<string[]> {
return del([getOutDir(), 'package.nls.*.json', 'vscode-dapr-*.vsix']);
return del([getDistDir(), getOutDir(), 'package.nls.*.json', 'vscode-dapr-*.vsix']);
}

function lintTaskFactory(warningsAsErrors?: boolean) {
Expand Down Expand Up @@ -65,6 +76,36 @@ function compileTask(): NodeJS.ReadWriteStream {
.pipe(gulp.dest(outDir));
}

function compilePackedTaskFactory(mode: 'production' | 'development'): () => Promise<void> {
return function compilePackedTask() {
return new Promise(
(resolve, reject) => {
webpack(
{
...webpackConfig,
mode
},
(err, stats) => {
if (err) {
return reject(err);
}

const info = stats.toJson();

if (stats.hasErrors()) {
return reject(new Error(info.errors.join('\n')));
}

if (stats.hasWarnings()) {
info.warnings.forEach(warning => console.warn(warning));
}

return resolve();
});
});
}
}

function addI18nTask() {
return gulp.src(['package.nls.json'])
.pipe(wrapThroughStream(nls.createAdditionalLanguageFiles(languages, 'i18n')))
Expand All @@ -85,14 +126,16 @@ function vscePackageTask() {

const buildTask = gulp.series(cleanTask, compileTask, addI18nTask);

const ciBuildTask = gulp.series(buildTask, lintTaskFactory(/* warningsAsErrors: */ true), testTask);
const ciBuildTask = gulp.series(cleanTask, compilePackedTaskFactory('production'), lintTaskFactory(/* warningsAsErrors: */ true));

gulp.task('clean', cleanTask);

gulp.task('lint', lintTaskFactory());

gulp.task('build', buildTask);

gulp.task('build-packed', gulp.series(cleanTask, compilePackedTaskFactory('development')));

gulp.task('unit-test', gulp.series(buildTask, unitTestTask));

gulp.task('test', gulp.series(buildTask, testTask));
Expand Down
21 changes: 21 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });

const ignoreBundle = !/^(false|0)?$/i.test(process.env.VSCODE_DAPR_IGNORE_BUNDLE || '');
const extensionPath = ignoreBundle ? "./out/src/extension" : "./dist/extension";
const extension = require(extensionPath);

function activate(ctx) {
return extension.activate(ctx);
}

function deactivate(ctx) {
return extension.deactivate(ctx);
}

exports.activate = activate;
exports.deactivate = deactivate;
Loading