11import fs from 'fs';
22import path from 'path';
33import { fileURLToPath } from 'url';
4- import { resolveEntry } from './resolve-entry.js';
54
65// Set up dirname equivalent for ES modules
76const __filename = fileURLToPath(import.meta.url);
@@ -12,6 +11,9 @@ const coreVersion = process.env.CORE_VERSION;
1211const version = process.env.VERSION;
1312const litVersion = process.env.LIT_VERSION || '3.2.1';
1413
14+ // Import the entry resolver
15+ import { resolveEntry } from './resolve-entry.js';
16+
1517// Create the importmap object
1618const importmap = {
1719 imports: {
@@ -52,24 +54,61 @@ try {
5254
5355// Add Lit dependencies to importmap
5456try {
57+ // Get Lit dependencies directly from node_modules directory contents
58+ const litDepsDirPath = './node_modules/lit/node_modules';
59+ if (fs.existsSync(litDepsDirPath)) {
60+ const potentialDeps = fs.readdirSync(litDepsDirPath)
61+ .filter(dir => fs.statSync(path.join(litDepsDirPath, dir)).isDirectory())
62+ .filter(dir => !dir.startsWith('.'));
63+
64+ console.log(`Found potential direct Lit dependencies: ${potentialDeps.join(', ')}`);
65+
66+ for (const dep of potentialDeps) {
67+ try {
68+ const depPath = path.join(litDepsDirPath, dep, 'package.json');
69+ if (fs.existsSync(depPath)) {
70+ const depPkgText = fs.readFileSync(depPath, 'utf8');
71+ const depPkg = JSON.parse(depPkgText);
72+
73+ const depVersion = depPkg.version;
74+ const depEntry = resolveEntry(depPkg);
75+
76+ importmap.imports[dep] = `https://cdn.semantic-ui.com/${dep}/${depVersion}/${depEntry}`;
77+ console.log(`Added direct Lit dependency: ${dep}@${depVersion} (${depEntry}) to importmap`);
78+ }
79+ } catch (err) {
80+ console.error(`Error processing direct dependency ${dep}:`, err.message);
81+ }
82+ }
83+ } else {
84+ console.log('Lit dependencies not found in node_modules subdirectory, trying package.json');
85+ }
86+
87+ // Also check package.json in case dependencies are hoisted
5588 const litPkgPath = './node_modules/lit/package.json';
5689 if (fs.existsSync(litPkgPath)) {
5790 const litPkgText = fs.readFileSync(litPkgPath, 'utf8');
5891 const litPkg = JSON.parse(litPkgText);
5992
6093 if (litPkg.dependencies) {
94+ console.log(`Found dependencies in lit package.json: ${Object.keys(litPkg.dependencies).join(', ')}`);
95+
6196 for (const [dep, depVersionReq] of Object.entries(litPkg.dependencies)) {
6297 try {
63- const depPath = path.join('./node_modules', dep, 'package.json');
64- if (fs.existsSync(depPath)) {
65- const depPkgText = fs.readFileSync(depPath, 'utf8');
98+ // Try to find at root node_modules first (hoisted dependencies)
99+ const depRootPath = path.join('./node_modules', dep, 'package.json');
100+ if (fs.existsSync(depRootPath)) {
101+ const depPkgText = fs.readFileSync(depRootPath, 'utf8');
66102 const depPkg = JSON.parse(depPkgText);
67103
68104 const depVersion = depPkg.version;
69105 const depEntry = resolveEntry(depPkg);
70106
71- importmap.imports[dep] = `https://cdn.semantic-ui.com/${dep}/${depVersion}/${depEntry}`;
72- console.log(`Added Lit dependency: ${dep}@${depVersion} (${depEntry}) to importmap`);
107+ // Only add if not already in importmap
108+ if (!importmap.imports[dep]) {
109+ importmap.imports[dep] = `https://cdn.semantic-ui.com/${dep}/${depVersion}/${depEntry}`;
110+ console.log(`Added hoisted Lit dependency: ${dep}@${depVersion} (${depEntry}) to importmap`);
111+ }
73112 }
74113 } catch (err) {
75114 console.error(`Error processing dependency ${dep}:`, err.message);
@@ -85,6 +124,10 @@ try {
85124fs.writeFileSync(`cdn/importmap-${version}.json`, JSON.stringify(importmap, null, 2));
86125console.log(`Created importmap-${version}.json`);
87126
127+ // Log the final imports for verification
128+ console.log('Final importmap imports:');
129+ console.log(JSON.stringify(importmap.imports, null, 2));
130+
88131// Optionally update the latest importmap if this is a release version (not a test/pre-release)
89132if (!version.includes('-')) {
90133 console.log('This is a release version, updating latest importmap');
0 commit comments