Skip to content

Commit d987489

Browse files
authored
Initial batch of changes to enable bundling of the extension (#3384)
For #3021 * Tests will be tracked here #3383 * Will need to update package.json seprately (for CD)
1 parent e2ad1cf commit d987489

32 files changed

+1908
-460
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ before_install: |
5656
install:
5757
- travis_wait 5 npm ci
5858
- npm run clean
59-
- npm run vscode:prepublish
59+
- npx gulp prePublishNonBundle
6060
- npx gulp hygiene-modified
6161
- python -m pip install --upgrade pip
6262
- python -m pip install --upgrade -r requirements.txt
@@ -113,6 +113,8 @@ script:
113113
npm run clean;
114114
vsce package;
115115
azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-insiders.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet;
116+
npm run package;
117+
azure storage blob upload python*.vsix $AZURE_STORAGE_CONTAINER ms-python-insiders-bundled.vsix --account-name $AZURE_STORAGE_ACCOUNT --account-key $AZURE_STORAGE_ACCESS_KEY --quiet;
116118
fi
117119
- if [[ $AZURE_STORAGE_ACCOUNT && "$TRAVIS_BRANCH" == release* && "$TRAVIS_PULL_REQUEST" == "false" ]]; then
118120
npm run clean;

.vscodeignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
!out/**/*.map
12
**/*.map
3+
*.vsix
24
.appveyor.yml
35
.editorconfig
46
.eslintrc
@@ -26,7 +28,7 @@ typings.json
2628
vsc-extension-quickstart.md
2729
vscode-python-signing.*
2830
webpack.config.js
29-
webpack.default.config.js
31+
webpack.datascience-ui.config.js
3032

3133
.github/**
3234
.mocha-reporter/**

build/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ function getListOfExcludedFiles() {
1111
return files.map(file => path.join(exports.ExtensionRootDir, file.replace(/\//g, path.sep)));
1212
}
1313
exports.filesNotToCheck = getListOfExcludedFiles();
14+
exports.isCI = process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined;

build/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ function getListOfExcludedFiles() {
1515
}
1616

1717
export const filesNotToCheck: string[] = getListOfExcludedFiles();
18+
19+
export const isCI = process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined;

build/datascience/inlinePlugin.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

build/webpack/common.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
6+
const constants_1 = require("../constants");
7+
exports.nodeModulesToExternalize = [
8+
'unicode/category/Lu',
9+
'unicode/category/Ll',
10+
'unicode/category/Lt',
11+
'unicode/category/Lo',
12+
'unicode/category/Lm',
13+
'unicode/category/Nl',
14+
'unicode/category/Mn',
15+
'unicode/category/Mc',
16+
'unicode/category/Nd',
17+
'unicode/category/Pc'
18+
];
19+
function getDefaultPlugins(name) {
20+
const plugins = [];
21+
if (!constants_1.isCI) {
22+
plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
23+
analyzerMode: 'static',
24+
reportFilename: `${name}.html`
25+
}));
26+
}
27+
return plugins;
28+
}
29+
exports.getDefaultPlugins = getDefaultPlugins;

build/webpack/common.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
5+
'use strict';
6+
7+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
8+
import { isCI } from '../constants';
9+
export const nodeModulesToExternalize = [
10+
'unicode/category/Lu',
11+
'unicode/category/Ll',
12+
'unicode/category/Lt',
13+
'unicode/category/Lo',
14+
'unicode/category/Lm',
15+
'unicode/category/Nl',
16+
'unicode/category/Mn',
17+
'unicode/category/Mc',
18+
'unicode/category/Nd',
19+
'unicode/category/Pc'
20+
];
21+
22+
export function getDefaultPlugins(name: 'extension' | 'debugger' | 'dependencies' | 'datascience-ui') {
23+
const plugins = [];
24+
if (!isCI) {
25+
plugins.push(
26+
new BundleAnalyzerPlugin({
27+
analyzerMode: 'static',
28+
reportFilename: `${name}.html`
29+
})
30+
);
31+
}
32+
return plugins;
33+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
const common_1 = require("../common");
6+
function replaceModule(contents, moduleName, quotes) {
7+
const stringToSearch = `${quotes}${moduleName}${quotes}`;
8+
const stringToReplaceWith = `${quotes}./node_modules/${moduleName}${quotes}`;
9+
return contents.replace(new RegExp(stringToSearch, 'gm'), stringToReplaceWith);
10+
}
11+
// tslint:disable:no-default-export no-invalid-this
12+
function default_1(source) {
13+
common_1.nodeModulesToExternalize.forEach(moduleName => {
14+
if (source.indexOf(moduleName) > 0) {
15+
source = replaceModule(source, moduleName, '"');
16+
source = replaceModule(source, moduleName, '\'');
17+
}
18+
});
19+
return source;
20+
}
21+
exports.default = default_1;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { nodeModulesToExternalize } from '../common';
7+
8+
function replaceModule(contents: string, moduleName: string, quotes: '"' | '\''): string {
9+
const stringToSearch = `${quotes}${moduleName}${quotes}`;
10+
const stringToReplaceWith = `${quotes}./node_modules/${moduleName}${quotes}`;
11+
return contents.replace(new RegExp(stringToSearch, 'gm'), stringToReplaceWith);
12+
}
13+
// tslint:disable:no-default-export no-invalid-this
14+
export default function (source: string) {
15+
nodeModulesToExternalize.forEach(moduleName => {
16+
if (source.indexOf(moduleName) > 0) {
17+
source = replaceModule(source, moduleName, '"');
18+
source = replaceModule(source, moduleName, '\'');
19+
}
20+
});
21+
return source;
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
// tslint:disable:no-default-export no-invalid-this
6+
function default_1(source) {
7+
if (source.indexOf('eval') > 0) {
8+
let matches = source.match(/eval\('require'\)\('.*'\)/gm) || [];
9+
matches.forEach(item => {
10+
const moduleName = item.split('\'')[3];
11+
const stringToReplaceWith = `require('${moduleName}')`;
12+
source = source.replace(item, stringToReplaceWith);
13+
});
14+
matches = source.match(/eval\("require"\)\(".*"\)/gm) || [];
15+
matches.forEach(item => {
16+
const moduleName = item.split('\'')[3];
17+
const stringToReplaceWith = `require("${moduleName}")`;
18+
source = source.replace(item, stringToReplaceWith);
19+
});
20+
}
21+
return source;
22+
}
23+
exports.default = default_1;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
// tslint:disable:no-default-export no-invalid-this
7+
export default function (source: string) {
8+
if (source.indexOf('eval') > 0) {
9+
let matches = source.match(/eval\('require'\)\('.*'\)/gm) || [];
10+
matches.forEach(item => {
11+
const moduleName = item.split('\'')[3];
12+
const stringToReplaceWith = `require('${moduleName}')`;
13+
source = source.replace(item, stringToReplaceWith);
14+
});
15+
matches = source.match(/eval\("require"\)\(".*"\)/gm) || [];
16+
matches.forEach(item => {
17+
const moduleName = item.split('\'')[3];
18+
const stringToReplaceWith = `require("${moduleName}")`;
19+
source = source.replace(item, stringToReplaceWith);
20+
});
21+
}
22+
return source;
23+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// For some reason this has to be in commonjs format
2-
3-
module.exports = function(source) {
4-
5-
// Just inline the source and fix up defaults so that they don't
6-
// mess up the logic in the setOptions.js file
7-
return `module.exports = ${source}\nmodule.exports.default = false`;
8-
}
1+
// For some reason this has to be in commonjs format
2+
3+
module.exports = function(source) {
4+
5+
// Just inline the source and fix up defaults so that they don't
6+
// mess up the logic in the setOptions.js file
7+
return `module.exports = ${source}\nmodule.exports.default = false`;
8+
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// For some reason this has to be in commonjs format
2-
3-
module.exports = function(source) {
4-
5-
// Just inline the source and fix up defaults so that they don't
6-
// mess up the logic in the setOptions.js file
7-
return `module.exports = ${source}\nmodule.exports.default = false`;
8-
}
1+
// For some reason this has to be in commonjs format
2+
3+
module.exports = function(source) {
4+
5+
// Just inline the source and fix up defaults so that they don't
6+
// mess up the logic in the setOptions.js file
7+
return `module.exports = ${source}\nmodule.exports.default = false`;
8+
9+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
'use strict';
4+
Object.defineProperty(exports, "__esModule", { value: true });
5+
const CopyWebpackPlugin = require("copy-webpack-plugin");
6+
const HtmlWebpackPlugin = require("html-webpack-plugin");
7+
const path = require("path");
8+
const common_1 = require("./common");
9+
// tslint:disable-next-line:no-var-requires no-require-imports
10+
const FixDefaultImportPlugin = require('webpack-fix-default-import-plugin');
11+
const configFileName = 'tsconfig.datascience-ui.json';
12+
const config = {
13+
entry: ['babel-polyfill', './src/datascience-ui/history-react/index.tsx'],
14+
output: {
15+
path: path.join(__dirname, '..', '..', 'out'),
16+
filename: 'datascience-ui/history-react/index_bundle.js',
17+
publicPath: path.join(__dirname, '..', '..')
18+
},
19+
mode: 'production',
20+
// Use 'eval' for release and `eval-source-map` for development.
21+
// We need to use one where source is embedded, due to webviews (they restrict resources to specific schemes,
22+
// this seems to prevent chrome from downloading the source maps)
23+
devtool: 'eval',
24+
node: {
25+
fs: 'empty'
26+
},
27+
plugins: [
28+
...common_1.getDefaultPlugins('datascience-ui'),
29+
new HtmlWebpackPlugin({ template: 'src/datascience-ui/history-react/index.html', filename: 'datascience-ui/history-react/index.html' }),
30+
new FixDefaultImportPlugin(),
31+
new CopyWebpackPlugin([
32+
{ from: './**/*.png', to: '.' },
33+
{ from: './**/*.svg', to: '.' },
34+
{ from: './**/*.css', to: '.' },
35+
{ from: './**/*theme*.json', to: '.' }
36+
])
37+
],
38+
resolve: {
39+
// Add '.ts' and '.tsx' as resolvable extensions.
40+
extensions: ['.ts', '.tsx', '.js', '.json']
41+
},
42+
module: {
43+
rules: [
44+
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
45+
{
46+
test: /\.tsx?$/,
47+
use: {
48+
loader: 'awesome-typescript-loader',
49+
options: {
50+
configFileName,
51+
reportFiles: [
52+
'src/datascience-ui/**/*.{ts,tsx}'
53+
]
54+
}
55+
}
56+
},
57+
{
58+
test: /\.css$/,
59+
use: [
60+
'style-loader',
61+
'css-loader'
62+
]
63+
},
64+
{
65+
test: /\.js$/,
66+
include: /node_modules.*remark.*default.*js/,
67+
use: [
68+
{
69+
loader: path.resolve('./build/datascience/remarkLoader.js'),
70+
options: {}
71+
}
72+
]
73+
},
74+
{
75+
test: /\.json$/,
76+
type: 'javascript/auto',
77+
include: /node_modules.*remark.*/,
78+
use: [
79+
{
80+
loader: path.resolve('./build/webpack/loaders/jsonloader.js'),
81+
options: {}
82+
}
83+
]
84+
}
85+
]
86+
}
87+
};
88+
// tslint:disable-next-line:no-default-export
89+
exports.default = config;

0 commit comments

Comments
 (0)