diff --git a/packages/osd-optimizer/src/optimizer/bundle_cache.ts b/packages/osd-optimizer/src/optimizer/bundle_cache.ts index 6976606e1c4b..fe987a0078c8 100644 --- a/packages/osd-optimizer/src/optimizer/bundle_cache.ts +++ b/packages/osd-optimizer/src/optimizer/bundle_cache.ts @@ -121,7 +121,7 @@ export function getBundleCacheEvent$( const bundleRefsDiff = diffCacheKey( refs.map((r) => r.exportId).sort((a, b) => a.localeCompare(b)), - bundleRefExportIds + bundleRefExportIds.sort((a, b) => a.localeCompare(b)) ); if (bundleRefsDiff) { events.push({ diff --git a/packages/osd-optimizer/src/worker/bundle_refs_plugin.ts b/packages/osd-optimizer/src/worker/bundle_refs_plugin.ts index 1eb2cd55eeb5..eed7bed26768 100644 --- a/packages/osd-optimizer/src/worker/bundle_refs_plugin.ts +++ b/packages/osd-optimizer/src/worker/bundle_refs_plugin.ts @@ -56,6 +56,7 @@ export class BundleRefsPlugin { private readonly resolvedRequestCache = new Map>(); private readonly ignorePrefix = Path.resolve(this.bundle.contextDir) + Path.sep; private allowedBundleIds = new Set(); + // private virtualModules: Record = {}; constructor(private readonly bundle: Bundle, private readonly bundleRefs: BundleRefs) {} @@ -63,6 +64,28 @@ export class BundleRefsPlugin { * Called by webpack when the plugin is passed in the webpack config */ public apply(compiler: webpack.Compiler) { + /* compiler.hooks.normalModuleFactory.tap('BundleRefsPlugin/test', (normalModuleFactory) => { + normalModuleFactory.hooks.beforeResolve.tapAsync( + 'BundleRefsPlugin/test', + (resolveData, callback) => { + if (!resolveData || !resolveData.request.startsWith('@/core/public')) { + return callback(); + } + // const pluginPath = resolveData.request.replace('@/', ''); + const virtualModulePath = `/@/virtual-modules/core/public.js`; + + // TODO: replace plugin path with bundle export id + const virtualModuleContent = ` + const ns = __osdBundles__.get('entry/core/public'); + module.exports = ns; + `; + resolveData.request = virtualModulePath; + this.virtualModules[virtualModulePath] = virtualModuleContent; + + return callback(null, resolveData); + } + ); + });*/ // called whenever the compiler starts to compile, passed the params // that will be used to create the compilation compiler.hooks.compile.tap('BundleRefsPlugin', (compilationParams: any) => { @@ -201,6 +224,9 @@ export class BundleRefsPlugin { * undefined is returned. Otherwise it returns the referenced bundleRef. */ private async maybeReplaceImport(context: string, request: string) { + // if (request.startsWith('@/core')) { + // console.log(request); + // } // ignore imports that have loaders defined or are not relative seeming if (request.includes('!') || !request.startsWith('.')) { return; diff --git a/packages/osd-plugin-helpers/src/tasks/create_archive.ts b/packages/osd-plugin-helpers/src/tasks/create_archive.ts index 9d0ee1be278d..4819b9873ae7 100644 --- a/packages/osd-plugin-helpers/src/tasks/create_archive.ts +++ b/packages/osd-plugin-helpers/src/tasks/create_archive.ts @@ -57,6 +57,7 @@ export async function createArchive({ opensearchDashboardsVersion, plugin, log } cwd: buildDir, base: buildDir, dot: true, + ignore: ['**/.osd-optimizer-cache'], }), zip(zipName), vfs.dest(buildDir) diff --git a/packages/osd-plugin-helpers/src/tasks/optimize.ts b/packages/osd-plugin-helpers/src/tasks/optimize.ts index 97da34cba52d..9aeae7a04084 100644 --- a/packages/osd-plugin-helpers/src/tasks/optimize.ts +++ b/packages/osd-plugin-helpers/src/tasks/optimize.ts @@ -48,17 +48,21 @@ export async function optimize({ log, plugin, sourceDir, buildDir }: BuildContex log.indent(2); // build bundles into target + const outputRoot = Path.resolve(REPO_ROOT, 'build/opensearch-dashboards'); const config = OptimizerConfig.create({ repoRoot: REPO_ROOT, pluginPaths: [sourceDir], - cache: false, + cache: true, dist: true, - pluginScanDirs: [], + // pluginScanDirs: [Path.resolve(REPO_ROOT, 'build/opensearch-dashboards')], + includeCoreBundle: true, + outputRoot, }); + const pluginOutputDir = Path.resolve(outputRoot, Path.relative(REPO_ROOT, sourceDir)); await runOptimizer(config).pipe(logOptimizerState(log, config)).toPromise(); // move target into buildDir - await asyncRename(Path.resolve(sourceDir, 'target'), Path.resolve(buildDir, 'target')); + await asyncRename(Path.resolve(pluginOutputDir, 'target'), Path.resolve(buildDir, 'target')); log.indent(-2); } diff --git a/src/dev/build/tasks/build_opensearch_dashboards_platform_plugins.ts b/src/dev/build/tasks/build_opensearch_dashboards_platform_plugins.ts index f9c102310239..b5b7daf5eb07 100644 --- a/src/dev/build/tasks/build_opensearch_dashboards_platform_plugins.ts +++ b/src/dev/build/tasks/build_opensearch_dashboards_platform_plugins.ts @@ -58,6 +58,6 @@ export const BuildOpenSearchDashboardsPlatformPlugins: Task = { .pipe(reportOptimizerStats(reporter, config, log), logOptimizerState(log, config)) .toPromise(); - await Promise.all(config.bundles.map((b) => b.cache.clear())); + // await Promise.all(config.bundles.map((b) => b.cache.clear())); }, };