@@ -405,3 +405,99 @@ index a92bb3d29496a453f1714e5cd32d1800c94844be..ded1034c929edc462ab547dc9b16ca8c
405
405
- walkModule
406
406
+ mergeImportMap
407
407
};
408
+ diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js
409
+ index b0bad6bfd8f9331812ded9c266d51ea8bb2584f1..08ff1eb71aaf338075b66e55f008fbafc25b4b85 100644
410
+ --- a/src/config/rollup.config.js
411
+ +++ b/src/config/rollup.config.js
412
+ @@ -141,6 +141,7 @@ function greenwoodSyncPageResourceBundlesPlugin(compilation) {
413
+ }
414
+ }
415
+
416
+ + console.log({ resourceKey, facadeModuleId });
417
+ if (resourceKey === facadeModuleId) {
418
+ const { fileName } = bundles[bundle];
419
+ const { rawAttributes, contents } = resource;
420
+ @@ -587,6 +588,7 @@ function greenwoodSyncImportAttributes(compilation) {
421
+
422
+ const getRollupConfigForBrowserScripts = async (compilation) => {
423
+ const { outputDir } = compilation.context;
424
+ + console.log('?????', compilation.resources.values())
425
+ const input = [...compilation.resources.values()]
426
+ .filter(resource => resource.type === 'script')
427
+ .map(resource => normalizePathnameForWindows(resource.sourcePathURL));
428
+ diff --git a/src/lib/resource-utils.js b/src/lib/resource-utils.js
429
+ index 6a78e464785b6dc11e909acf64f66db975e77909..d4c5ac967a4dcf126b4cf9c85d5d3615ebde03d8 100644
430
+ --- a/src/lib/resource-utils.js
431
+ +++ b/src/lib/resource-utils.js
432
+ @@ -2,17 +2,39 @@ import fs from 'fs/promises';
433
+ import { hashString } from './hashing-utils.js';
434
+ import htmlparser from 'node-html-parser';
435
+
436
+ + function getPackageNameFromSrc(src) {
437
+ + const s = src.replace('/node_modules/', '');
438
+ + const pieces = s.split('/');
439
+ + let name;
440
+ +
441
+ + console.log({ pieces });
442
+ + if (s.startsWith('@')) {
443
+ + name = `${pieces[0]}/${pieces[1]}`;
444
+ + } else {
445
+ + name = pieces[0];
446
+ + }
447
+ +
448
+ + console.log({ name });
449
+ +
450
+ + return name;
451
+ + }
452
+ async function modelResource(context, type, src = undefined, contents = undefined, optimizationAttr = undefined, rawAttributes = undefined) {
453
+ const { projectDirectory, scratchDir, userWorkspace } = context;
454
+ const extension = type === 'script' ? 'js' : 'css';
455
+ let sourcePathURL;
456
+
457
+ if (src) {
458
+ - sourcePathURL = src.startsWith('/node_modules')
459
+ - ? new URL(`.${src}`, projectDirectory)
460
+ - : src.startsWith('/')
461
+ + if (src.startsWith('/node_modules')) {
462
+ + const name = getPackageNameFromSrc(src);
463
+ + const resolved = import.meta.resolve(name);
464
+ +
465
+ + sourcePathURL = new URL(resolved);
466
+ + console.log('modelResource', { name, resolved, sourcePathURL });
467
+ + } else {
468
+ + sourcePathURL = src.startsWith('/')
469
+ ? new URL(`.${src}`, userWorkspace)
470
+ : new URL(`./${src.replace(/\.\.\//g, '').replace('./', '')}`, userWorkspace);
471
+ + }
472
+
473
+ contents = await fs.readFile(sourcePathURL, 'utf-8');
474
+ } else {
475
+ @@ -112,6 +134,7 @@ async function resolveForRelativeUrl(url, rootUrl) {
476
+ }
477
+
478
+ async function trackResourcesForRoute(html, compilation, route) {
479
+ + console.log('trackResourcesForRoute', { route });
480
+ const { context } = compilation;
481
+ const root = htmlparser.parse(html, {
482
+ script: true,
483
+ @@ -163,6 +186,7 @@ async function trackResourcesForRoute(html, compilation, route) {
484
+
485
+ compilation.graph.find(page => page.route === route).resources = resources.map(resource => resource.sourcePathURL.pathname);
486
+
487
+ + console.log('$$$', { resources });
488
+ return resources;
489
+ }
490
+
491
+ diff --git a/src/lifecycles/bundle.js b/src/lifecycles/bundle.js
492
+ index 814d1b9462c02530f81a7bec1d393f6609c5a9b9..992f239c76643748119d53cef7b809b22623de8b 100644
493
+ --- a/src/lifecycles/bundle.js
494
+ +++ b/src/lifecycles/bundle.js
495
+ @@ -332,6 +332,8 @@ async function bundleScriptResources(compilation) {
496
+ // https://rollupjs.org/guide/en/#differences-to-the-javascript-api
497
+ const [rollupConfig] = await getRollupConfigForBrowserScripts(compilation);
498
+
499
+ + console.log({ rollupConfig });
500
+ +
501
+ if (rollupConfig.input.length !== 0) {
502
+ const bundle = await rollup(rollupConfig);
503
+ await bundle.write(rollupConfig.output);
0 commit comments