Skip to content

Commit

Permalink
Merge pull request #12 from tat3/reduce-built-package
Browse files Browse the repository at this point in the history
use esbuild to remove node_modules from vsix
  • Loading branch information
tat3 authored Sep 4, 2022
2 parents 1965b03 + c0622ae commit aa76949
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ jobs:
- run: xvfb-run -a yarn test
if: runner.os == 'Linux'
- run: yarn test
shell: bash
if: runner.os != 'Linux'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ work/**
*.vsix
*.bat
.eslintrc.json
*.min.js
.local-chromium
data/emoji-images/
data/highlight.js/
4 changes: 3 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ jsconfig.json
work/**
*.bat
.eslintrc.json
sample/**
sample/**
node_modules
.local-chromium
8 changes: 3 additions & 5 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const extension = 'markdown-pdf-2';
function activate(context) {
init();

const commandPrefix = `extension.${extension}`;

var commands = ['settings', 'pdf', 'html', 'png', 'jpeg', 'all']
.map(type => vscode.commands.registerCommand(
`extension.${extension}.${type}`,
Expand Down Expand Up @@ -235,7 +233,7 @@ function convertMarkdownToHtml(filename, type, text) {
md.use(require('markdown-it-emoji'), options);
md.renderer.rules.emoji = function (token, idx) {
var emoji = token[idx].markup;
var emojipath = path.join(__dirname, 'node_modules', 'emoji-images', 'pngs', emoji + '.png');
var emojipath = path.join(__dirname, 'data', 'emoji-images', emoji + '.png');
var emojidata = readFile(emojipath, null).toString('base64');
if (emojidata) {
return '<img class="emoji" alt="' + emoji + '" src="data:image/png;base64,' + emojidata + '" />';
Expand Down Expand Up @@ -691,7 +689,7 @@ function readStyles(uri) {
if (ishighlight) {
if (highlightStyle) {
var css = vscode.workspace.getConfiguration(extension)['highlightStyle'] || 'github.css';
filename = path.join(__dirname, 'node_modules', 'highlight.js', 'styles', css);
filename = path.join(__dirname, 'data', 'highlight.js', css);
style += makeCss(filename);
} else {
filename = path.join(__dirname, 'styles', 'tomorrow.css');
Expand Down Expand Up @@ -800,7 +798,7 @@ function installChromium() {
var StatusbarMessageTimeout = vscode.workspace.getConfiguration(extension)['StatusbarMessageTimeout'];
const puppeteer = require('puppeteer-core');
const browserFetcher = puppeteer.createBrowserFetcher();
const revision = require(path.join(__dirname, 'node_modules', 'puppeteer-core', 'package.json')).puppeteer.chromium_revision;
const revision = require('puppeteer-core/package.json').puppeteer.chromium_revision;
const revisionInfo = browserFetcher.revisionInfo(revision);

// download Chromium
Expand Down
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES5",
"target": "ES6",
"noLib": true
},
"exclude": [
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"onCommand:extension.markdown-pdf-2.all",
"onLanguage:markdown"
],
"main": "./extension",
"main": "./extension.min.js",
"contributes": {
"commands": [
{
Expand Down Expand Up @@ -480,12 +480,14 @@
}
},
"scripts": {
"vscode:prepublish": "node ./src/compile",
"test": "node ./test/runTest.js",
"build": "vsce package"
"vscode:prepublish": "./scripts/build.sh",
"test": "bash ./scripts/build.sh && node ./test/runTest.js",
"build": "vsce package",
"esbuild": "esbuild ./extension.js --bundle --outfile=extension.min.js --external:vscode --format=cjs --platform=node"
},
"devDependencies": {
"@vscode/test-electron": "^2.1.5",
"esbuild": "^0.15.6",
"glob": "^7.1.6",
"mocha": "^7.1.1",
"removeNPMAbsolutePaths": "^2.0.0"
Expand Down
4 changes: 4 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
yarn run esbuild

cp -r node_modules/highlight.js/styles data/highlight.js/
cp -r node_modules/emoji-images/pngs data/emoji-images/
27 changes: 0 additions & 27 deletions src/compile.js

This file was deleted.

7 changes: 6 additions & 1 deletion test/suite/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ suite('Extension Test Suite', () => {
this.timeout(60 * 1000);
const revision = require('puppeteer-core/package.json').puppeteer.chromium_revision;
const puppeteer = require('puppeteer-core');
const bf = puppeteer.createBrowserFetcher();
const bf = puppeteer.createBrowserFetcher({
/* Specify chrome location of test runner.
By default, the test runner downloads and uses chrome in node_modules/puppeteer-core/.local-chromium.
The emurated vscode does it in <project dir>/.local-chromium because puppeteer is bundled and not in node_modules. */
path: path.resolve(__dirname, '../../.local-chromium'),
});
await bf.download(revision);
vscode.window.showInformationMessage('Start all tests.');
});
Expand Down
132 changes: 132 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@esbuild/[email protected]":
version "0.15.6"
resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.15.6.tgz#45be4184f00e505411bc265a05e709764114acd8"
integrity sha512-hqmVU2mUjH6J2ZivHphJ/Pdse2ZD+uGCHK0uvsiLDk/JnSedEVj77CiVUnbMKuU4tih1TZZL8tG9DExQg/GZsw==

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
Expand Down Expand Up @@ -892,6 +897,133 @@ es-to-primitive@^1.2.1:
is-date-object "^1.0.1"
is-symbol "^1.0.2"

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-android-64/-/esbuild-android-64-0.15.6.tgz#baaed943ca510c2ad546e116728132e76d1d2044"
integrity sha512-Z1CHSgB1crVQi2LKSBwSkpaGtaloVz0ZIYcRMsvHc3uSXcR/x5/bv9wcZspvH/25lIGTaViosciS/NS09ERmVA==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-android-arm64/-/esbuild-android-arm64-0.15.6.tgz#1c33c73d4c074969e014e31958116460c8e75a7a"
integrity sha512-mvM+gqNxqKm2pCa3dnjdRzl7gIowuc4ga7P7c3yHzs58Im8v/Lfk1ixSgQ2USgIywT48QWaACRa3F4MG7djpSw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-darwin-64/-/esbuild-darwin-64-0.15.6.tgz#388592ba61bf31993d79f6311f7452aa1ef255b9"
integrity sha512-BsfVt3usScAfGlXJiGtGamwVEOTM8AiYiw1zqDWhGv6BncLXCnTg1As+90mxWewdTZKq3iIy8s9g8CKkrrAXVw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.15.6.tgz#194e987849dc4688654008a1792f26e948f52e74"
integrity sha512-CnrAeJaEpPakUobhqO4wVSA4Zm6TPaI5UY4EsI62j9mTrjIyQPXA1n4Ju6Iu5TVZRnEqV6q8blodgYJ6CJuwCA==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-64/-/esbuild-freebsd-64-0.15.6.tgz#daa72faee585ec2ec27cc65e86a6ce0786373e66"
integrity sha512-+qFdmqi+jkAsxsNJkaWVrnxEUUI50nu6c3MBVarv3RCDCbz7ZS1a4ZrdkwEYFnKcVWu6UUE0Kkb1SQ1yGEG6sg==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.15.6.tgz#70c8a2a30bf6bb9d547a0d8dc93aa015ec4f77f9"
integrity sha512-KtQkQOhnNciXm2yrTYZMD3MOm2zBiiwFSU+dkwNbcfDumzzUprr1x70ClTdGuZwieBS1BM/k0KajRQX7r504Xw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-32/-/esbuild-linux-32-0.15.6.tgz#d69ed2335b2d68c00b3248254b432172077b7ced"
integrity sha512-IAkDNz3TpxwISTGVdQijwyHBZrbFgLlRi5YXcvaEHtgbmayLSDcJmH5nV1MFgo/x2QdKcHBkOYHdjhKxUAcPwg==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-64/-/esbuild-linux-64-0.15.6.tgz#dca821e8f129cccde23ac947fd0d4bea3b333808"
integrity sha512-gQPksyrEYfA4LJwyfTQWAZaVZCx4wpaLrSzo2+Xc9QLC+i/sMWmX31jBjrn4nLJCd79KvwCinto36QC7BEIU/A==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm64/-/esbuild-linux-arm64-0.15.6.tgz#c9e8bc86f3c58a7c8ff1ded5880c6a39ade7621b"
integrity sha512-aovDkclFa6C9EdZVBuOXxqZx83fuoq8097xZKhEPSygwuy4Lxs8J4anHG7kojAsR+31lfUuxzOo2tHxv7EiNHA==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-arm/-/esbuild-linux-arm-0.15.6.tgz#354ecad0223f5b176995cf4462560eec2633de24"
integrity sha512-xZ0Bq2aivsthDjA/ytQZzxrxIZbG0ATJYMJxNeOIBc1zUjpbVpzBKgllOZMsTSXMHFHGrow6TnCcgwqY0+oEoQ==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.15.6.tgz#f4fb941a4ff0af437deed69a2e0712983c8fff3e"
integrity sha512-wVpW8wkWOGizsCqCwOR/G3SHwhaecpGy3fic9BF1r7vq4djLjUcA8KunDaBCjJ6TgLQFhJ98RjDuyEf8AGjAvw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.15.6.tgz#19774a8b52c77173f2d4f171b8a8cf839b12e686"
integrity sha512-z6w6gsPH/Y77uchocluDC8tkCg9rfkcPTePzZKNr879bF4tu7j9t255wuNOCE396IYEGxY7y8u2HJ9i7kjCLVw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.15.6.tgz#66bd83b065c4a1e623df02c122bc7e4e15fd8486"
integrity sha512-pfK/3MJcmbfU399TnXW5RTPS1S+ID6ra+CVj9TFZ2s0q9Ja1F5A1VirUUvViPkjiw+Kq3zveyn6U09Wg1zJXrw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-linux-s390x/-/esbuild-linux-s390x-0.15.6.tgz#1e024bddc75afe8dc70ed48fc9627af770d7f34b"
integrity sha512-OZeeDu32liefcwAE63FhVqM4heWTC8E3MglOC7SK0KYocDdY/6jyApw0UDkDHlcEK9mW6alX/SH9r3PDjcCo/Q==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-netbsd-64/-/esbuild-netbsd-64-0.15.6.tgz#c11477d197f059c8794ee1691e3399201f7c4b9a"
integrity sha512-kaxw61wcHMyiEsSsi5ut1YYs/hvTC2QkxJwyRvC2Cnsz3lfMLEu8zAjpBKWh9aU/N0O/gsRap4wTur5GRuSvBA==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-openbsd-64/-/esbuild-openbsd-64-0.15.6.tgz#b29e7faed5b8d2aeaf3884c47c1a96b1cba8e263"
integrity sha512-CuoY60alzYfIZapUHqFXqXbj88bbRJu8Fp9okCSHRX2zWIcGz4BXAHXiG7dlCye5nFVrY72psesLuWdusyf2qw==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-sunos-64/-/esbuild-sunos-64-0.15.6.tgz#9668f39e47179f50c0435040904b9c6e10e84a70"
integrity sha512-1ceefLdPWcd1nW/ZLruPEYxeUEAVX0YHbG7w+BB4aYgfknaLGotI/ZvPWUZpzhC8l1EybrVlz++lm3E6ODIJOg==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-windows-32/-/esbuild-windows-32-0.15.6.tgz#9ddcd56e3c4fb9729a218c713c4e76bdbc1678b4"
integrity sha512-pBqdOsKqCD5LRYiwF29PJRDJZi7/Wgkz46u3d17MRFmrLFcAZDke3nbdDa1c8YgY78RiemudfCeAemN8EBlIpA==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-windows-64/-/esbuild-windows-64-0.15.6.tgz#1eaadeadfd995e9d065d35cb3e9f02607202f339"
integrity sha512-KpPOh4aTOo//g9Pk2oVAzXMpc9Sz9n5A9sZTmWqDSXCiiachfFhbuFlsKBGATYCVitXfmBIJ4nNYYWSOdz4hQg==

[email protected]:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild-windows-arm64/-/esbuild-windows-arm64-0.15.6.tgz#e18a778d354fc2ca2306688f3fedad8a3e57819e"
integrity sha512-DB3G2x9OvFEa00jV+OkDBYpufq5x/K7a6VW6E2iM896DG4ZnAvJKQksOsCPiM1DUaa+DrijXAQ/ZOcKAqf/3Hg==

esbuild@^0.15.6:
version "0.15.6"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.15.6.tgz#626e5941b98de506b862047be3c4b33f89278923"
integrity sha512-sgLOv3l4xklvXzzczhRwKRotyrfyZ2i1fCS6PTOLPd9wevDPArGU8HFtHrHCOcsMwTjLjzGm15gvC8uxVzQf+w==
optionalDependencies:
"@esbuild/linux-loong64" "0.15.6"
esbuild-android-64 "0.15.6"
esbuild-android-arm64 "0.15.6"
esbuild-darwin-64 "0.15.6"
esbuild-darwin-arm64 "0.15.6"
esbuild-freebsd-64 "0.15.6"
esbuild-freebsd-arm64 "0.15.6"
esbuild-linux-32 "0.15.6"
esbuild-linux-64 "0.15.6"
esbuild-linux-arm "0.15.6"
esbuild-linux-arm64 "0.15.6"
esbuild-linux-mips64le "0.15.6"
esbuild-linux-ppc64le "0.15.6"
esbuild-linux-riscv64 "0.15.6"
esbuild-linux-s390x "0.15.6"
esbuild-netbsd-64 "0.15.6"
esbuild-openbsd-64 "0.15.6"
esbuild-sunos-64 "0.15.6"
esbuild-windows-32 "0.15.6"
esbuild-windows-64 "0.15.6"
esbuild-windows-arm64 "0.15.6"

[email protected], escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
Expand Down

0 comments on commit aa76949

Please sign in to comment.