Skip to content

Commit

Permalink
chore(monorepo): remove unnecessary build tooling from plugins; simpl…
Browse files Browse the repository at this point in the history
…ify peer-deps check CLOUDP-207383 (#5598)

* chore(scripts): update check-peer-deps to the new validation logic; add autofix support

* chore(scripts): update template in create-workspace to not bundle plugins

* chore(monorepo): autoupdate and autofix all packages

* chore(webpack-config): remove unused plugin webpack config

* chore(instance-model): remove nonexistent imports from d.ts

* chore(crud): replace classnames with cx

* fix(scripts): account for non semver versions in check-peer-deps autofix

* fix(schema): re-hoist leaflet package to monorepo root

* chore(monorepo): remove unused dependencies

* fix(monorepo): use compile as bootstrap script everywhere

* chore(compass): remove unused dependency
  • Loading branch information
gribnoysup authored Mar 21, 2024
1 parent 27f374a commit 4d93fa0
Show file tree
Hide file tree
Showing 88 changed files with 1,786 additions and 3,488 deletions.
104 changes: 1 addition & 103 deletions configs/webpack-config-compass/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from 'fs';
import type {
ResolveOptions,
WebpackPluginInstance,
Expand All @@ -13,7 +12,7 @@ import path from 'path';
import { builtinModules } from 'module';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { WebpackPluginStartElectron } from './webpack-plugin-start-electron';
import type { ConfigArgs, WebpackConfig, WebpackCLIArgs } from './args';
import type { ConfigArgs, WebpackConfig } from './args';
import { isServe, webpackArgsWithDefaults } from './args';
import {
sourceMapLoader,
Expand Down Expand Up @@ -356,107 +355,6 @@ export function createWebConfig(args: Partial<ConfigArgs>): WebpackConfig {
};
}

function findEntry(cwd: string) {
const files = fs.readdirSync(path.join(cwd, 'src'));
const entryFile = ['index.tsx', 'index.ts', 'index.jsx', 'index.js'].find(
(entry) => {
return files.includes(entry);
}
);
if (!entryFile) {
throw new Error(
`Can not find entry file for the package. Looking for index.{tsx,ts,jsx,js} in plugin src folder`
);
}
return path.join(cwd, 'src', entryFile);
}

export function compassPluginConfig(
_env: WebpackCLIArgs['env'],
_args: Partial<WebpackCLIArgs>
): WebpackConfig[] {
const args = webpackArgsWithDefaults(_args);
const opts = { ...args, hot: true };

process.env.NODE_ENV = opts.nodeEnv;

if (isServe(opts)) {
const sandboxMain = path.join(opts.cwd, 'electron', 'index.js');
const sandboxRenderer = path.join(
opts.cwd,
'electron',
'renderer',
'index.js'
);

try {
fs.statSync(sandboxMain);
fs.statSync(sandboxRenderer);
} catch (e) {
throw new Error(
`Compass plugin is missing sandbox entry points. To be able to run the plugin in a sandbox outside of Compass, please add ./electron/index.ts and ./electron/renderer/index.ts entry points`
);
}

return [
merge(
createElectronMainConfig({
...opts,
entry: sandboxMain,
}),
{ externals: toCommonJsExternal(pluginExternals) }
),
merge(
createElectronRendererConfig({
...opts,
entry: sandboxRenderer,
}),
{ externals: toCommonJsExternal(pluginExternals) }
),
];
}

const entry = findEntry(opts.cwd);

return [
merge(
createElectronRendererConfig({
...opts,
entry,
outputFilename: 'index.js',
}),
{
externals: toCommonJsExternal(pluginExternals),
plugins: [
// For plugins, clean up the dist folder first before proceeding
function (compiler) {
compiler.hooks.initialize.tap('CleanDistPlugin', () => {
try {
fs.rmSync(compiler.outputPath, {
recursive: true,
force: true,
});
} catch {
// noop
}
});
},
],
}
),
merge(
createWebConfig({
...opts,
entry,
outputFilename: 'browser.js',
}),
{
externals: toCommonJsExternal(pluginExternals),
}
),
];
}

export { sharedExternals, pluginExternals };
export { webpackArgsWithDefaults, isServe } from './args';
export { default as webpack } from 'webpack';
Expand Down
Loading

0 comments on commit 4d93fa0

Please sign in to comment.