Skip to content

Commit db2bf9c

Browse files
authored
Merge pull request #63 from discoveryjs/esbuild
Esbuild
2 parents 3cb967f + 15bcf84 commit db2bf9c

File tree

65 files changed

+1746
-16478
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1746
-16478
lines changed

.babelrc

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

.eslintignore

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

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ module.exports = {
293293
],
294294
'quote-props': [2, 'as-needed'],
295295
quotes: [2, 'single'],
296-
'require-jsdoc': 1,
297296
'semi-spacing': 2,
298297
'semi-style': [2, 'last'],
299298
semi: 2,

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
node_modules
22
npm-debug.log
33
build*
4-
!build.sh
4+
!build.js
5+
xcuserdata
6+
*.xcuserstate
7+
*.xcworkspace
58
safari/JsonDiscovery/JsonDiscovery Extension/js
69
safari/JsonDiscovery/JsonDiscovery Extension/css

.postcssrc.js

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

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.10.0 (09-02-2020)
2+
3+
* Build system reworked using `esbuild`
4+
* Fixed bug with darkmode styles applied to the part of the page in Chrome
5+
* Fixed darkmode "blinking" issue
6+
* Disabled "inspector" when you press `Alt` button
7+
* Fixed bug when you have to reload page to apply settings
8+
* Increased performance by splitting code loading into two stages (Chrome & Safari only)
9+
* Style isolation via ShadowDOM
10+
* Fixed issues when CSP blocked some images and icons
11+
* Updated `discovery` to `1.0.0-beta.53`
12+
113
## 1.9.2 (12-11-2020)
214

315
* Updated `discovery` to `1.0.0-beta.50`

core/build.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const csstree = require('css-tree');
4+
const mime = require('mime');
5+
const crypto = require('crypto');
6+
const bundleJs = require('esbuild').build;
7+
const manifest = require('../src/manifest.js');
8+
9+
const { NODE_ENV } = process.env;
10+
const watch = NODE_ENV !== 'production';
11+
12+
const indir = path.join(__dirname, '/../src');
13+
14+
const browsers = [
15+
'chrome',
16+
'firefox',
17+
'safari'
18+
];
19+
20+
async function build(browser) {
21+
const outdir = path.join(__dirname, `/../build-${browser}`);
22+
23+
fs.rmdirSync(outdir, { recursive: true });
24+
fs.mkdirSync(outdir, { recursive: true });
25+
fs.writeFileSync(outdir + '/manifest.json', manifest(browser));
26+
27+
copyFiles(path.join(indir, 'icons'), outdir);
28+
29+
bundleJs({
30+
entryPoints: [
31+
path.join(indir, 'content/index.css'),
32+
path.join(indir, browser === 'firefox' ? 'content/loader-firefox.js' : 'content/loader.js'),
33+
path.join(indir, 'content/init-discovery.js')
34+
],
35+
bundle: true,
36+
// minify: true,
37+
format: 'esm',
38+
outdir,
39+
define: {
40+
global: 'window'
41+
}
42+
})
43+
.then(() => {
44+
const css = fs.readFileSync(path.join(outdir, 'index.css'), 'utf8');
45+
const ast = csstree.parse(css);
46+
47+
csstree.walk(ast, {
48+
enter(node) {
49+
if (node.type === 'Url') {
50+
const value = getValueFromStringOrRaw(node.value);
51+
const [, mimeType, content] = value.match(/^data:(.*);base64,(.*)$/);
52+
const filename = crypto
53+
.createHash('sha1')
54+
.update(content)
55+
.digest('hex') + '.' + mime.getExtension(mimeType);
56+
57+
fs.writeFileSync(path.join(outdir, 'icons', filename), Buffer.from(content, 'base64'));
58+
59+
node.value = {
60+
type: 'Raw',
61+
value: `icons/${filename}`
62+
};
63+
}
64+
}
65+
});
66+
67+
fs.writeFileSync(path.join(outdir, 'index.css'), csstree.generate(ast));
68+
})
69+
.catch((error) => {
70+
console.error(error); // eslint-disable-line no-console
71+
process.exit(1);
72+
});
73+
}
74+
75+
const buildAll = async function() {
76+
console.log('Building bundles...'); // eslint-disable-line no-console
77+
for (const browser of browsers) {
78+
await build(browser);
79+
}
80+
};
81+
82+
(async function() {
83+
await buildAll();
84+
85+
if (watch) {
86+
fs.watch(indir, { recursive: true }, async function() {
87+
await buildAll();
88+
});
89+
}
90+
})();
91+
92+
function copyFiles(src, dest) {
93+
fs.mkdirSync(dest, { recursive: true });
94+
95+
if (fs.statSync(src).isDirectory()) {
96+
fs.readdirSync(src).forEach(p =>
97+
copyFiles(path.join(src, p), path.join(dest, path.basename(src)))
98+
);
99+
} else {
100+
fs.copyFileSync(src, path.join(dest, path.basename(src)));
101+
}
102+
}
103+
104+
function getValueFromStringOrRaw(node) {
105+
switch (node.type) {
106+
case 'String':
107+
return node.value.substring(1, node.value.length - 1);
108+
109+
case 'Raw':
110+
return node.value;
111+
}
112+
113+
return null;
114+
}

core/build.sh

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

core/css-loader.js

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

core/webpack.base.js

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

core/webpack.dev.js

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

0 commit comments

Comments
 (0)