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

Draft: Move Most Linting Logic to Web Workers #1047

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import esbuild from 'esbuild';
import process from 'process';
import builtins from 'builtin-modules';
import importGlobPlugin from 'esbuild-plugin-import-glob';
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
import {replace} from 'esbuild-plugin-replace';

const banner =
Expand All @@ -11,15 +12,15 @@ if you want to view the source, please visit the github repository of this plugi
*/
`;

const dummyMocksForDocs = `
const dummyMocksForDocsAndWorker = `
document = {
createElement: function() {},
};
`;

const prod = (process.argv[2] === 'production');

const mockedBanner = banner + dummyMocksForDocs;
const mockedBanner = banner + dummyMocksForDocsAndWorker;
const mockedPlugins = [replace({
values: {
// update usage of moment from obsidian to the node implementation of moment we have
Expand All @@ -31,6 +32,21 @@ const mockedPlugins = [replace({
},
delimiters: ['', ''],
})];
const webWorkerIgnores = [replace({
values: {
// update usage of moment from obsidian to the node implementation of moment we have
'import {moment} from \'obsidian\';': '',
// remove the use of obsidian in the options to allow for docs.js to run
'import {Setting} from \'obsidian\';': '',
// remove the use of obsidian in settings helper to allow for docs.js to run
'import {Component, MarkdownRenderer} from \'obsidian\';': '',
},
delimiters: ['', ''],
})];

const externalPackages = [
'obsidian',
...builtins];

const createEsbuildArgs = function(banner, entryPoint, outfile, extraPlugins) {
return {
Expand All @@ -40,12 +56,19 @@ const createEsbuildArgs = function(banner, entryPoint, outfile, extraPlugins) {
entryPoints: [entryPoint],
plugins: [
importGlobPlugin.default(),
inlineWorkerPlugin({
banner:
{
js: dummyMocksForDocsAndWorker,
},
external: externalPackages,
format: 'cjs',
plugins: [...webWorkerIgnores],
}),
...extraPlugins,
],
bundle: true,
external: [
'obsidian',
...builtins],
external: externalPackages,
format: 'cjs',
target: 'es2020',
sourcemap: prod ? false : 'inline',
Expand Down
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const config: Config.InitialOptions = {
'**/?(*.)+(spec|test).[jt]s?(x)',
'!**/__tests__/common.ts',
'!**/__integration__/*.[jt]s?(x)',
'!**/test-vault/**/*.[jt]s?(x)',
],
};
export default config;
Loading