@@ -9,7 +9,6 @@ const __dirname = path.dirname(__filename);
99// Access environment variables
1010const coreVersion = process.env.CORE_VERSION;
1111const version = process.env.VERSION;
12- const litVersion = process.env.LIT_VERSION;
1312const mode = process.env.BUILD_ENV || 'production';
1413
1514// Import the entry resolver
@@ -19,8 +18,7 @@ import { resolveEntry } from './resolve-entry.js';
1918// Since we're rewriting imports directly in files, we only need top-level package mappings
2019const importmap = {
2120 imports: {
22- '@semantic-ui/core': `https://cdn.semantic-ui.com/@semantic-ui/core/${coreVersion}/index.js`,
23- 'lit': `https://cdn.semantic-ui.com/lit/${litVersion}/index.js`
21+ '@semantic-ui/core': `https://cdn.semantic-ui.com/@semantic-ui/core/${coreVersion}/index.js`
2422 }
2523};
2624
5452 console.error('Error reading packages directory:', err.message);
5553}
5654
57- // Add Lit dependencies to importmap
58- try {
59- // Get Lit dependencies directly from node_modules directory contents
60- const litDepsDirPath = './node_modules/lit/node_modules';
61- if (fs.existsSync(litDepsDirPath)) {
62- const potentialDeps = fs.readdirSync(litDepsDirPath)
63- .filter(dir => fs.statSync(path.join(litDepsDirPath, dir)).isDirectory())
64- .filter(dir => !dir.startsWith('.'));
65-
66- console.log(`Found potential direct Lit dependencies: ${potentialDeps.join(', ')}`);
67-
68- for (const dep of potentialDeps) {
69- try {
70- const depPath = path.join(litDepsDirPath, dep, 'package.json');
71- if (fs.existsSync(depPath)) {
72- const depPkgText = fs.readFileSync(depPath, 'utf8');
73- const depPkg = JSON.parse(depPkgText);
74-
75- const depVersion = depPkg.version;
76- const depEntry = resolveEntry(depPkg, mode);
77-
78- importmap.imports[dep] = `https://cdn.semantic-ui.com/${dep}/${depVersion}/${depEntry}`;
79- console.log(`Added direct Lit dependency: ${dep}@${depVersion} (${depEntry}) to importmap`);
80- }
81- } catch (err) {
82- console.error(`Error processing direct dependency ${dep}:`, err.message);
83- }
84- }
85- } else {
86- console.log('Lit dependencies not found in node_modules subdirectory, trying package.json');
87- }
88-
89- // Also check package.json in case dependencies are hoisted
90- const litPkgPath = './node_modules/lit/package.json';
91- if (fs.existsSync(litPkgPath)) {
92- const litPkgText = fs.readFileSync(litPkgPath, 'utf8');
93- const litPkg = JSON.parse(litPkgText);
94-
95- if (litPkg.dependencies) {
96- console.log(`Found dependencies in lit package.json: ${Object.keys(litPkg.dependencies).join(', ')}`);
97-
98- for (const [dep, depVersionReq] of Object.entries(litPkg.dependencies)) {
99- try {
100- // Try to find at root node_modules first (hoisted dependencies)
101- const depRootPath = path.join('./node_modules', dep, 'package.json');
102- if (fs.existsSync(depRootPath)) {
103- const depPkgText = fs.readFileSync(depRootPath, 'utf8');
104- const depPkg = JSON.parse(depPkgText);
105-
106- const depVersion = depPkg.version;
107- const depEntry = resolveEntry(depPkg, mode);
108-
109- // Only add if not already in importmap
110- if (!importmap.imports[dep]) {
111- importmap.imports[dep] = `https://cdn.semantic-ui.com/${dep}/${depVersion}/${depEntry}`;
112- console.log(`Added hoisted Lit dependency: ${dep}@${depVersion} (${depEntry}) to importmap`);
113- }
114- }
115- } catch (err) {
116- console.error(`Error processing dependency ${dep}:`, err.message);
117- }
118- }
119- }
120- }
121- } catch (err) {
122- console.error('Error processing Lit dependencies:', err.message);
123- }
124-
12555// Write the importmap to the version-specific file
12656fs.writeFileSync(`cdn/importmap-${version}.json`, JSON.stringify(importmap, null, 2));
12757console.log(`Created importmap-${version}.json`);
0 commit comments