@@ -361,3 +361,99 @@ index a92bb3d29496a453f1714e5cd32d1800c94844be..68fd30e718f5493b426b88bc8e6aa137
361
361
- walkModule
362
362
+ mergeImportMap
363
363
};
364
+ diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js
365
+ index b0bad6bfd8f9331812ded9c266d51ea8bb2584f1..08ff1eb71aaf338075b66e55f008fbafc25b4b85 100644
366
+ --- a/src/config/rollup.config.js
367
+ +++ b/src/config/rollup.config.js
368
+ @@ -141,6 +141,7 @@ function greenwoodSyncPageResourceBundlesPlugin(compilation) {
369
+ }
370
+ }
371
+
372
+ + console.log({ resourceKey, facadeModuleId });
373
+ if (resourceKey === facadeModuleId) {
374
+ const { fileName } = bundles[bundle];
375
+ const { rawAttributes, contents } = resource;
376
+ @@ -587,6 +588,7 @@ function greenwoodSyncImportAttributes(compilation) {
377
+
378
+ const getRollupConfigForBrowserScripts = async (compilation) => {
379
+ const { outputDir } = compilation.context;
380
+ + console.log('?????', compilation.resources.values())
381
+ const input = [...compilation.resources.values()]
382
+ .filter(resource => resource.type === 'script')
383
+ .map(resource => normalizePathnameForWindows(resource.sourcePathURL));
384
+ diff --git a/src/lib/resource-utils.js b/src/lib/resource-utils.js
385
+ index 6a78e464785b6dc11e909acf64f66db975e77909..d4c5ac967a4dcf126b4cf9c85d5d3615ebde03d8 100644
386
+ --- a/src/lib/resource-utils.js
387
+ +++ b/src/lib/resource-utils.js
388
+ @@ -2,17 +2,39 @@ import fs from 'fs/promises';
389
+ import { hashString } from './hashing-utils.js';
390
+ import htmlparser from 'node-html-parser';
391
+
392
+ + function getPackageNameFromSrc(src) {
393
+ + const s = src.replace('/node_modules/', '');
394
+ + const pieces = s.split('/');
395
+ + let name;
396
+ +
397
+ + console.log({ pieces });
398
+ + if (s.startsWith('@')) {
399
+ + name = `${pieces[0]}/${pieces[1]}`;
400
+ + } else {
401
+ + name = pieces[0];
402
+ + }
403
+ +
404
+ + console.log({ name });
405
+ +
406
+ + return name;
407
+ + }
408
+ async function modelResource(context, type, src = undefined, contents = undefined, optimizationAttr = undefined, rawAttributes = undefined) {
409
+ const { projectDirectory, scratchDir, userWorkspace } = context;
410
+ const extension = type === 'script' ? 'js' : 'css';
411
+ let sourcePathURL;
412
+
413
+ if (src) {
414
+ - sourcePathURL = src.startsWith('/node_modules')
415
+ - ? new URL(`.${src}`, projectDirectory)
416
+ - : src.startsWith('/')
417
+ + if (src.startsWith('/node_modules')) {
418
+ + const name = getPackageNameFromSrc(src);
419
+ + const resolved = import.meta.resolve(name);
420
+ +
421
+ + sourcePathURL = new URL(resolved);
422
+ + console.log('modelResource', { name, resolved, sourcePathURL });
423
+ + } else {
424
+ + sourcePathURL = src.startsWith('/')
425
+ ? new URL(`.${src}`, userWorkspace)
426
+ : new URL(`./${src.replace(/\.\.\//g, '').replace('./', '')}`, userWorkspace);
427
+ + }
428
+
429
+ contents = await fs.readFile(sourcePathURL, 'utf-8');
430
+ } else {
431
+ @@ -112,6 +134,7 @@ async function resolveForRelativeUrl(url, rootUrl) {
432
+ }
433
+
434
+ async function trackResourcesForRoute(html, compilation, route) {
435
+ + console.log('trackResourcesForRoute', { route });
436
+ const { context } = compilation;
437
+ const root = htmlparser.parse(html, {
438
+ script: true,
439
+ @@ -163,6 +186,7 @@ async function trackResourcesForRoute(html, compilation, route) {
440
+
441
+ compilation.graph.find(page => page.route === route).resources = resources.map(resource => resource.sourcePathURL.pathname);
442
+
443
+ + console.log('$$$', { resources });
444
+ return resources;
445
+ }
446
+
447
+ diff --git a/src/lifecycles/bundle.js b/src/lifecycles/bundle.js
448
+ index 814d1b9462c02530f81a7bec1d393f6609c5a9b9..992f239c76643748119d53cef7b809b22623de8b 100644
449
+ --- a/src/lifecycles/bundle.js
450
+ +++ b/src/lifecycles/bundle.js
451
+ @@ -332,6 +332,8 @@ async function bundleScriptResources(compilation) {
452
+ // https://rollupjs.org/guide/en/#differences-to-the-javascript-api
453
+ const [rollupConfig] = await getRollupConfigForBrowserScripts(compilation);
454
+
455
+ + console.log({ rollupConfig });
456
+ +
457
+ if (rollupConfig.input.length !== 0) {
458
+ const bundle = await rollup(rollupConfig);
459
+ await bundle.write(rollupConfig.output);
0 commit comments